Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.51 KB | None | 0 0
  1. var tabla;
  2.  
  3. //Función que se ejecuta al inicio
  4. function init(){
  5. //mostrarform(false);
  6.  
  7. listar();
  8.  
  9. /*$("#frmestablecimiento").on("submit",function(e)
  10. {
  11. guardaryeditar(e);
  12. });*/
  13.  
  14. /*$("#frmestablecimiento").submit(function(e){
  15. guardaryeditar(e);
  16. });*/
  17.  
  18. //$('#mTablas').addClass("treeview active");
  19. //$('#lEstablecimientos').addClass("active");
  20.  
  21. }
  22. //Función limpiar_modal_local
  23. //Función limpiar
  24.  
  25. function open_new_tabla(idtabla,nameinput,tpl_name,titulo) {
  26. $("#descripcion").val('');
  27. $("#abreviado").val('');
  28.  
  29. $('#modaltablas').modal('show');
  30. $("#idtabla").val(idtabla);
  31. $("#nameinput").val(nameinput);
  32. $("#tpl_name").val(tpl_name);
  33. $("#modalItems").html('Agregar a ' + titulo);
  34.  
  35. }
  36. function insert_tabla() {
  37. var idtabla = $("#idtabla").val();
  38. var nameinput =$("#nameinput").val();
  39. var tpl_name =$("#tpl_name").val();
  40. var descripcion =$("#descripcion").val();
  41. var abreviado =$("#abreviado").val();
  42.  
  43.  
  44. var message = "";
  45. if (descripcion == "") {message = "Ingresa Descripción";}
  46. else if (abreviado === "") {message = "Ingresa Abreviatura";}
  47. if (message) return showMessage(message, "error");// return false;
  48. var parametros = {"idtabla":idtabla,"descripcion":descripcion,"abreviado":abreviado};
  49. $.ajax( {
  50. url: '../ajax/tabla.php?op=insert_tabla',
  51. data: parametros,
  52. dataType: 'html',
  53. type: "POST",
  54. success: function ( result ) {
  55. //alert(result);return false;
  56. if (result == "Opción registrada") {
  57. $('#modaltablas').modal('hide');
  58. showMessage("Guardado correctamente", "success");
  59. loadtabla(idtabla,nameinput,tpl_name);
  60. //$("#cbx_instituciones").val(result);
  61.  
  62. } else {
  63. showMessage(result.error, "error", true);
  64. }
  65. },
  66. timeout: 10000, // sets timeout to 10 seconds
  67. error: function (request, status, err) {
  68.  
  69. if (status == "timeout") {
  70. showMessage("Su petición demoro mas de lo permitido", "error");
  71. } else {
  72. // another error occured
  73. showMessage("ocurrio un error.", "error");
  74. }
  75. }
  76. } );
  77. }
  78.  
  79. function loadtabla(idtabla,valtabla,tpl_name) {
  80.  
  81. $.getJSON('../ajax/tabla.php?op=list&id_tabla='+idtabla, function(data) {
  82. loadDataToTemplate(tpl_name,valtabla,data)
  83. });
  84.  
  85.  
  86.  
  87. }
  88.  
  89.  
  90. function limpiar_local()
  91. {
  92. $("#modalLocalTitle").html('Nuevo registro');
  93. $("#id_local").val("");
  94. $("#nombre_local").val("");
  95. $("#direccion_local").val("");
  96. $('#id_ubigeo_local').val('').trigger('change.select2');
  97. $("#celular_local").val("");
  98. $("#telefono_fijo_local").val("");
  99.  
  100. }
  101.  
  102. function limpiar()
  103. {
  104. $("#modalTitle").html('Nuevo registro');
  105. $("#id_catalogo").val("");
  106. $("#nombre").val("");
  107. $("#id_categoria").val("");
  108. //$("#maneja_lotes").iCheck('uncheck');
  109.  
  110. }
  111.  
  112.  
  113. //Función mostrar formulario
  114. function mostrarform(flag)
  115. {
  116. limpiar();
  117. if (flag)
  118. {
  119. $("#listadoregistros").hide();
  120. $("#formularioregistros").show();
  121. $("#btnGuardar").prop("disabled",false);
  122. $("#btnagregar").hide();
  123. }
  124. else
  125. {
  126. $("#listadoregistros").show();
  127. $("#formularioregistros").hide();
  128. $("#btnagregar").show();
  129. }
  130. }
  131.  
  132. //Función cancelarform
  133. function cancelarform()
  134. {
  135. limpiar();
  136. mostrarform(false);
  137. }
  138. //Actualiza child row
  139. function update_child(row){
  140. var parametros = {"id_empresa":row};
  141. $.ajax( {
  142. url: '../ajax/empresa.php?op=tableLocales',
  143. data: parametros,
  144. dataType: 'html',
  145. success: function ( json ) {
  146. $("#row_"+row).html( json );
  147. }
  148. } );
  149. }
  150.  
  151. //Función Listar
  152. function listar()
  153. {
  154. function format ( rowData ) {
  155. var parametros = {"id_empresa":rowData[0]};
  156. var div = $("<div id='row_"+rowData[0]+"' >")
  157. .addClass( 'Cargando' )
  158. .text( 'Cargando...' );
  159. $.ajax( {
  160. url: '../ajax/items.php?op=tableLocales',
  161. data: parametros,
  162. dataType: 'html',
  163. success: function ( json ) {
  164. div
  165. .html( json )
  166. .removeClass( 'loading' );
  167. }
  168. } );
  169.  
  170. return div;
  171. //alert('hola');
  172. }
  173.  
  174. $('#tbllistado thead tr').clone(true).appendTo( '#tbllistado thead' );
  175. $('#tbllistado thead tr:eq(1) th').each( function (i) {
  176. var title = $(this).text();
  177. if (title!='' && $.trim(title)!='Acciones' && title!='Estado'){
  178. $(this).html( '<input style="width:100%;" type="text" class="form-control input-sm" placeholder="Buscar '+title+'" />' );
  179. }else{
  180. $(this).html('');
  181. }
  182. $( 'input', this ).on( 'keyup change', function () {
  183. if ( table.column(i).search() !== this.value ) {
  184. table
  185. .column(i)
  186. .search( this.value )
  187. .draw();
  188. }
  189. } );
  190. } );
  191.  
  192.  
  193. table=$('#tbllistado').DataTable(
  194. {
  195. dom: "Bltip",
  196.  
  197. "buttons": [
  198. {
  199. text: '<i class="glyphicon glyphicon-plus"></i> Nuevo',
  200. className: "btn btn-success btn-sm",
  201. action: function ( e, dt, node, config ) {
  202. ver();
  203. }
  204.  
  205. }
  206. ],
  207. orderCellsTop: true,
  208. fixedHeader: true,
  209. fixedColumns: true,
  210.  
  211. "lengthMenu": [ 5, 10, 25, 75, 100],//mostramos el menú de registros a revisar
  212. "bProcessing": true,//Activamos el procesamiento del datatables
  213. "bJQueryUI": false,
  214. "responsive": true,
  215. "bInfo": true,
  216. "bFilter": true,
  217. "bServerSide": true,//Paginación y filtrado realizados por el servidor
  218. "sServerMethod": "GET",
  219. //dom: '<Bl<f>rtip>',//Definimos los elementos del control de tabla
  220. /*buttons: [
  221. {
  222. text: 'Nuevo',
  223. //className: "btn",
  224. action: function ( e, dt, node, config ) {
  225. ver();
  226. }
  227. } ,
  228.  
  229. {
  230. extend: 'copyHtml5',
  231. text: '<i class="fa fa-files-o"></i>',
  232. titleAttr: 'Copy'
  233. },
  234. {
  235. extend: 'excelHtml5',
  236. text: '<i class="fa fa-file-excel-o"></i>',
  237. titleAttr: 'Excel'
  238. },
  239. {
  240. extend: 'csvHtml5',
  241. text: '<i class="fa fa-file-text-o"></i>',
  242. titleAttr: 'CSV'
  243. },
  244. {
  245. extend: 'pdfHtml5',
  246. text: '<i class="fa fa-file-pdf-o"></i>',
  247. titleAttr: 'PDF'
  248. }
  249.  
  250.  
  251.  
  252. ],*/
  253. "sAjaxSource": "../ajax/catalogo.php?op=listar", // Load Data
  254. /*"ajax":
  255. {
  256. url: '../ajax/establecimiento.php?op=listar',
  257. type : "get",
  258. dataType : "json",
  259. error: function(e){
  260. console.log(e.responseText);
  261. }
  262. },*/
  263. "language": {
  264. "url": "../public/datatables.net.languages/Spanish.json",
  265. "lengthMenu": "Mostrar : _MENU_ registros",
  266. "search": '<i class="fa fa-search"></i>',
  267. "paginate": {
  268. "previous": '<i class="fa fa-angle-left"></i>',
  269. "next": '<i class="fa fa-angle-right"></i>'
  270. },
  271.  
  272. "buttons": {
  273. "copyTitle": "Tabla Copiada",
  274. "copySuccess": {
  275. _: '%d líneas copiadas',
  276. 1: '1 línea copiada'
  277. }
  278. }
  279. },
  280. "bDestroy": true,
  281.  
  282. "columnDefs": [
  283. { "orderable": false, "targets": 0, "searchable": false },
  284. { "orderable": false, "targets": 1, "searchable": true },
  285. { "orderable": true, "targets": 2, "searchable": true },
  286. { "orderable": true, "targets": 3, "searchable": false },
  287. { "orderable": true, "targets": 4, "searchable": true }
  288. ],
  289.  
  290. "createdRow": function( row, data, dataIndex){
  291. if( data[8] == '0'){
  292. //$(row).addClass('alert alert-warning');
  293. //$(row).css('background-color', 'rgb(250, 235, 204)');
  294. //$(row).css('background-color', '#F39B9B');
  295. }
  296.  
  297. },
  298.  
  299. columns: [
  300. {
  301. className: 'details-control',
  302. defaultContent: '',
  303. data: null,
  304. orderable: false,
  305. defaultContent: '' },
  306.  
  307. //{ aTargets: null },
  308. { aTargets: 'i.id' },
  309. { aTargets: '' },
  310. { aTargets: 'i.nombre' },
  311. { aTargets: 'i.id' },
  312. { aTargets: 'g.descripcion' },
  313. { aTargets: 'r.descripcion' },
  314. { aTargets: 'p.descripcion' },
  315.  
  316. ],
  317.  
  318. "pagingType": 'full_numbers',
  319. "iDisplayLength": 10,//Paginación
  320. "order": [[ 2, "asc" ]]//Ordenar (columna,orden)
  321.  
  322. });
  323.  
  324.  
  325. $('#tbllistado tbody').on('click', 'td.details-control', function () {
  326. var tr = $(this).closest('tr');
  327. var row = table.row( tr );
  328.  
  329. if ( row.child.isShown() ) {
  330. row.child.hide();
  331. tr.removeClass('shown');
  332. //tr.find('svg').attr('data-icon', 'plus-circle');
  333. }
  334. else {
  335. row.child( format(row.data()) ).show();
  336. tr.addClass('shown');
  337. //tr.find('svg').attr('data-icon', 'minus-circle');
  338. }
  339. } );
  340.  
  341.  
  342. /*$('.buttons-excel, .buttons-print').each(function() {
  343. $(this).removeClass('btn-default').addClass('btn-primary')
  344. })*/
  345.  
  346.  
  347. }
  348. //Función para guardar o editar
  349.  
  350. function guardaryeditar()
  351. {
  352. //
  353. var msj='';
  354. if ($("#id_categoria").val()==''){
  355. var msj="Selecciona una categoria...!";
  356. }else if($("#nombre").val()==''){
  357. var msj="Ingresa una Descripción..!";
  358. }
  359.  
  360. if(msj==''){
  361. var msj="Esta seguro de guardar los cambios?";
  362. bootbox.confirm({
  363. title: "Mensaje",
  364. message: msj,
  365. buttons: {
  366. cancel: {
  367. label: '<i class="fa fa-times"></i> Cancelar'
  368. },
  369. confirm: {
  370. label: '<i class="fa fa-check"></i> Aceptar'
  371. }
  372. },
  373. callback: function (result) {
  374.  
  375. if (result){
  376.  
  377. var parametros = {
  378. "id_catalogo":$('#id_catalogo').val(),
  379. "nombre":$('#nombre').val().toUpperCase(),
  380. "id_categoria":$('#id_categoria').val(),
  381. "id_tipo_rotacion":$('#id_tipo_rotacion').val(),
  382. "id_tipo_precio":$('#id_tipo_precio').val()
  383. };
  384.  
  385.  
  386. $.ajax({
  387. url: "../ajax/catalogo.php?op=guardaryeditar",
  388. type: "POST",
  389. data: parametros,
  390. success: function(datos)
  391. {
  392. bootbox.alert(datos);
  393. $('#modalNew').modal('toggle')
  394. table.ajax.reload();
  395. }
  396.  
  397. });
  398.  
  399.  
  400. }
  401. }
  402. });
  403.  
  404. }else{
  405. bootbox.alert(msj);
  406. }
  407.  
  408. }
  409.  
  410. function guardaryeditar_local()
  411. {
  412. if ($("#id_local").val()==''){
  413. var msj="Esta seguro de guardar el nuevo registro?";
  414. }else{
  415. var msj="Esta seguro de guardar los cambios?";
  416. }
  417.  
  418. bootbox.confirm({
  419. title: "Mensaje",
  420. message: msj,
  421. buttons: {
  422. cancel: {
  423. label: '<i class="fa fa-times"></i> Cancelar'
  424. },
  425. confirm: {
  426. label: '<i class="fa fa-check"></i> Aceptar'
  427. }
  428. },
  429. callback: function (result) {
  430. //console.log('This was logged in the callback: ' + result);
  431. if (result){
  432. //Grabar
  433. //var formData = new FormData($("#frmestablecimiento")[0]);
  434.  
  435. var parametros = {
  436. "id_local":$('#id_local').val(),
  437. "id_empresa":$('#id_empresa_local').val(),
  438. "nombre":$('#nombre_local').val().toUpperCase(),
  439. "direccion": $('#direccion_local').val().toUpperCase(),
  440. "celular": $('#celular_local').val().toUpperCase(),
  441. "telefono_fijo": $('#telefono_fijo_local').val(),
  442. "id_ubigeo": $("#id_ubigeo_local").val()
  443. };
  444.  
  445.  
  446. $.ajax({
  447. url: "../ajax/local.php?op=guardaryeditar",
  448. type: "POST",
  449. data: parametros,
  450. //contentType: false,
  451. //processData: false,
  452.  
  453. success: function(datos)
  454. {
  455.  
  456. //mostrarform(false);
  457. $('#modalLocal').modal('toggle')
  458. update_child($('#id_empresa_local').val());
  459. bootbox.alert(datos);
  460.  
  461. //table.ajax.reload();
  462. }
  463.  
  464. });
  465.  
  466.  
  467. }
  468. }
  469. });
  470.  
  471.  
  472. //e.preventDefault(); //No se activará la acción predeterminada del evento
  473. /*$("#btnGuardar").prop("disabled",true);*/
  474.  
  475.  
  476.  
  477. /*
  478. limpiar();*/
  479. }
  480.  
  481. function mostrar_item(id_catalogo)
  482. {
  483. $.post("../ajax/catalogo.php?op=mostrar",{id_catalogo : id_catalogo}, function(data, status)
  484. {
  485. data = JSON.parse(data);
  486. $("#id_catalogo").val(id_catalogo);
  487. $("#nombre").val(data.nombre);
  488.  
  489. $("#id_categoria").val(data.id_grupo);
  490. $("#id_tipo_rotacion").val(data.id_tipo_rotacion);
  491. $("#id_tipo_precio").val(data.id_tipo_precio);
  492.  
  493.  
  494. /*if (data.maneja_lote=='1'){
  495. $("#maneja_lotes").iCheck('check')
  496. }else{
  497. $("#maneja_lotes").iCheck('uncheck')
  498. }*/
  499.  
  500. /*$("#direccion").val(data.direccion);
  501. $("#ruc").val(data.ruc);
  502. $("#telefono_fijo").val(data.telefono_fijo);
  503. $('#ubigeo').append("<option value='"+data.id_ubigeo+"' selected='selected'>"+data.distrito+"</option>");
  504. $("#ubigeo").trigger('change');*/
  505.  
  506. $("#modalTitle").html('Edicion de registro');
  507. $('#modalNew').modal('show');
  508. })
  509. }
  510.  
  511. function mostrar_local(id_empresa,id_local){
  512. //alert(id_empresa);
  513. $("#id_empresa_local").val(id_empresa);
  514.  
  515. $.post("../ajax/local.php?op=mostrar",{id_local : id_local}, function(data, status)
  516. {
  517. data = JSON.parse(data);
  518. $("#nombre_local").val(data.nombre);
  519. $("#id_local").val(id_local);
  520. $("#direccion_local").val(data.direccion);
  521. $("#celular_local").val(data.celular);
  522. $("#telefono_fijo_local").val(data.telefono_fijo);
  523. $('#id_ubigeo_local').append("<option value='"+data.id_ubigeo+"' selected='selected'>"+data.distrito+"</option>");
  524. $("#id_ubigeo_local").trigger('change');
  525. $("#modalLocalTitle").html('Edicion de local');
  526. $('#modalLocal').modal('show');
  527. })
  528.  
  529. }
  530.  
  531.  
  532.  
  533. //Función para desactivar registros
  534. function desactivar(id_item)
  535. {
  536. bootbox.confirm("¿Está Seguro de desactivar el registro?", function(result){
  537. if(result)
  538. {
  539. $.post("../ajax/catalogo.php?op=desactivar", {id_catalogo : id_item}, function(e){
  540. bootbox.alert(e);
  541. table.ajax.reload();
  542. });
  543. }
  544. })
  545. }
  546.  
  547. //Función para activar registros
  548. function activar(id_item)
  549. {
  550. bootbox.confirm("¿Está Seguro de activar el registro?", function(result){
  551. if(result)
  552. {
  553. $.post("../ajax/catalogo.php?op=activar", {id_catalogo : id_item}, function(e){
  554. bootbox.alert(e);
  555. table.ajax.reload();
  556. });
  557. }
  558. })
  559. }
  560. function open_local(id_empresa){
  561. limpiar_local();
  562. $('#id_empresa_local').val(id_empresa)
  563. $('#modalLocal').modal('show')
  564. }
  565.  
  566. //Función para activar local
  567. function activar_local(id_empresa,id_local)
  568. {
  569. bootbox.confirm("¿Está Seguro de activar el registro?", function(result){
  570. if(result)
  571. {
  572. $.post("../ajax/local.php?op=activar", {id_local : id_local}, function(e){
  573. bootbox.alert(e);
  574. update_child(id_empresa);
  575. });
  576. }
  577. })
  578. }
  579.  
  580. //Función para desactivar registros
  581. function desactivar_local(id_empresa,id_local)
  582. {
  583. bootbox.confirm("¿Está Seguro de desactivar el registro?", function(result){
  584. if(result)
  585. {
  586. $.post("../ajax/local.php?op=desactivar", {id_local : id_local}, function(e){
  587. bootbox.alert(e);
  588. update_child(id_empresa);
  589. });
  590. }
  591. })
  592. }
  593.  
  594. init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement