Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.41 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. function imprimir(){
  25. document.getElementById('aDwn').setAttribute('href',"../reportes/pdfItems.php");
  26. document.getElementById('aDwn').click();
  27. }
  28. function open_new_tabla(idtabla,nameinput,tpl_name,titulo) {
  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_item").val("");
  106. //$("#nombre").val("");
  107. //$("#id_empresa").val("");
  108. //$('#ubigeo').val('').trigger('change.select2');
  109. $("#categoria").val("");
  110. $('#id_catalogo').val('').trigger('change.select2');
  111. $("#id_marca").val("");
  112. $("#id_laboratorio").val("");
  113. $("#id_ums").val("");
  114. $("#id_umi").val("");
  115. $("#Factor").val("1");
  116. $("#precio_compra").val("0.00");
  117. $("#stock_real").val("0.00");
  118. $("#stock_minimo").val("0.00");
  119. $("#stock_maximo").val("0.00");
  120.  
  121. $("#maneja_lotes").iCheck('uncheck');
  122.  
  123. }
  124.  
  125.  
  126. //Función mostrar formulario
  127. function mostrarform(flag)
  128. {
  129. limpiar();
  130. if (flag)
  131. {
  132. $("#listadoregistros").hide();
  133. $("#formularioregistros").show();
  134. $("#btnGuardar").prop("disabled",false);
  135. $("#btnagregar").hide();
  136. }
  137. else
  138. {
  139. $("#listadoregistros").show();
  140. $("#formularioregistros").hide();
  141. $("#btnagregar").show();
  142. }
  143. }
  144.  
  145. //Función cancelarform
  146. function cancelarform()
  147. {
  148. limpiar();
  149. mostrarform(false);
  150. }
  151. //Actualiza child row
  152. function update_child(row){
  153. var parametros = {"id_empresa":row};
  154. $.ajax( {
  155. url: '../ajax/empresa.php?op=tableLocales',
  156. data: parametros,
  157. dataType: 'html',
  158. success: function ( json ) {
  159. $("#row_"+row).html( json );
  160. }
  161. } );
  162. }
  163.  
  164. //Función Listar
  165. function listar()
  166. {
  167. function format ( rowData ) {
  168. var parametros = {"id_item":rowData[0]};
  169. var div = $("<div id='row_"+rowData[0]+"' >")
  170. .addClass( 'Cargando' )
  171. .text( 'Cargando...' );
  172. $.ajax( {
  173. url: '../ajax/items.php?op=tableLotes',
  174. data: parametros,
  175. dataType: 'html',
  176. success: function ( json ) {
  177. div
  178. .html( json )
  179. .removeClass( 'loading' );
  180. }
  181. } );
  182.  
  183. return div;
  184. //alert('hola');
  185. }
  186.  
  187.  
  188. $('#tbllistado thead tr').clone(true).appendTo( '#tbllistado thead' );
  189. $('#tbllistado thead tr:eq(1) th').each( function (i) {
  190. var title = $(this).text();
  191. if (title!='' && $.trim(title)!='Acciones' && title!='Estado' && title!='Maneja Lote'){
  192. $(this).html( '<input style="width:100%;" type="text" class="form-control input-sm" placeholder="Buscar '+title+'" />' );
  193. }else{
  194. if(title=='Maneja Lote'){
  195. $(this).html("<select id='cbolote' class='form-control ' onchange='table.column(11).search( this.value ).draw();' style='width: 100%;' ><option value='*'>--Todos--</option><option value='1'>Maneja</option><option value='0'>No maneja</option></select>")
  196.  
  197. }else{
  198. $(this).html('');
  199. }
  200. }
  201. $( 'input', this ).on( 'keyup change', function () {
  202. if ( table.column(i).search() !== this.value ) {
  203. table
  204. .column(i)
  205. .search( this.value )
  206. .draw();
  207. }
  208. } );
  209. } );
  210.  
  211.  
  212. table=$('#tbllistado').DataTable(
  213. {
  214. dom: "Bltip",
  215.  
  216. "buttons": [
  217. {
  218. text: '<i class="glyphicon glyphicon-plus"></i> Nuevo',
  219. className: "btn btn-success btn-sm",
  220. action: function ( e, dt, node, config ) {
  221. ver();
  222. }
  223.  
  224. },
  225. {
  226. text: '<i class="glyphicon glyphicon-print"></i> Imprimir',
  227. className: "btn btn-success btn-sm",
  228. action: function ( e, dt, node, config ) {
  229. imprimir();
  230. }
  231.  
  232. },
  233.  
  234. ],
  235. orderCellsTop: true,
  236. fixedHeader: true,
  237. fixedColumns: true,
  238.  
  239. "lengthMenu": [ 5, 10, 25, 75, 100],//mostramos el menú de registros a revisar
  240. "bProcessing": true,//Activamos el procesamiento del datatables
  241. "bJQueryUI": false,
  242. "responsive": true,
  243. "bInfo": true,
  244. "bFilter": true,
  245. "bServerSide": true,//Paginación y filtrado realizados por el servidor
  246. "sServerMethod": "GET",
  247. //dom: '<Bl<f>rtip>',//Definimos los elementos del control de tabla
  248. /*buttons: [
  249. {
  250. text: 'Nuevo',
  251. //className: "btn",
  252. action: function ( e, dt, node, config ) {
  253. ver();
  254. }
  255. } ,
  256.  
  257. {
  258. extend: 'copyHtml5',
  259. text: '<i class="fa fa-files-o"></i>',
  260. titleAttr: 'Copy'
  261. },
  262. {
  263. extend: 'excelHtml5',
  264. text: '<i class="fa fa-file-excel-o"></i>',
  265. titleAttr: 'Excel'
  266. },
  267. {
  268. extend: 'csvHtml5',
  269. text: '<i class="fa fa-file-text-o"></i>',
  270. titleAttr: 'CSV'
  271. },
  272. {
  273. extend: 'pdfHtml5',
  274. text: '<i class="fa fa-file-pdf-o"></i>',
  275. titleAttr: 'PDF'
  276. }
  277.  
  278.  
  279.  
  280. ],*/
  281. "sAjaxSource": "../ajax/items.php?op=listar", // Load Data
  282. /*"ajax":
  283. {
  284. url: '../ajax/establecimiento.php?op=listar',
  285. type : "get",
  286. dataType : "json",
  287. error: function(e){
  288. console.log(e.responseText);
  289. }
  290. },*/
  291. "language": {
  292. "url": "../public/datatables.net.languages/Spanish.json",
  293. "lengthMenu": "Mostrar : _MENU_ registros",
  294. "search": '<i class="fa fa-search"></i>',
  295. "paginate": {
  296. "previous": '<i class="fa fa-angle-left"></i>',
  297. "next": '<i class="fa fa-angle-right"></i>'
  298. },
  299.  
  300. "buttons": {
  301. "copyTitle": "Tabla Copiada",
  302. "copySuccess": {
  303. _: '%d líneas copiadas',
  304. 1: '1 línea copiada'
  305. }
  306. }
  307. },
  308. "bDestroy": true,
  309.  
  310. "columnDefs": [
  311. { "orderable": false, "targets": 0, "searchable": false },
  312. { "orderable": true, "targets": 1, "searchable": true },
  313. { "orderable": true, "targets": 2, "searchable": true },
  314. { "orderable": false, "targets": 3, "searchable": true },
  315. { "orderable": false, "targets": 11, "searchable": true }
  316. ],
  317.  
  318. "createdRow": function( row, data, dataIndex){
  319. if( data[8] == '0'){
  320. //$(row).addClass('alert alert-warning');
  321. //$(row).css('background-color', 'rgb(250, 235, 204)');
  322. //$(row).css('background-color', '#F39B9B');
  323. }
  324.  
  325. },
  326.  
  327. columns: [
  328. {
  329. className: 'details-control',
  330. defaultContent: '',
  331. data: null,
  332. orderable: false,
  333. defaultContent: '' },
  334.  
  335. //{ aTargets: null },
  336. { aTargets: 'i.id' },
  337. { aTargets: '' },
  338. { aTargets: 'cat.nombre' },
  339. { aTargets: 'i.id' },
  340. { aTargets: 'c.descripcion' },
  341. { aTargets: 'm.descripcion' },
  342. { aTargets: 'ums.descripcion' },
  343. { aTargets: 'umi.descripcion' },
  344. { aTargets: 'factor' },
  345. { aTargets: 'precio_compra' },
  346. { aTargets: 'stock_real' },
  347. { aTargets: 'maneja_lote' }
  348.  
  349. ],
  350.  
  351. "pagingType": 'full_numbers',
  352. "iDisplayLength": 10,//Paginación
  353. "order": [[ 2, "asc" ]]//Ordenar (columna,orden)
  354.  
  355. });
  356.  
  357.  
  358. $('#tbllistado tbody').on('click', 'td.details-control', function () {
  359. var tr = $(this).closest('tr');
  360. var row = table.row( tr );
  361.  
  362. if ( row.child.isShown() ) {
  363. row.child.hide();
  364. tr.removeClass('shown');
  365. //tr.find('svg').attr('data-icon', 'plus-circle');
  366. }
  367. else {
  368. row.child( format(row.data()) ).show();
  369. tr.addClass('shown');
  370. //tr.find('svg').attr('data-icon', 'minus-circle');
  371. }
  372. } );
  373.  
  374.  
  375. /*$('.buttons-excel, .buttons-print').each(function() {
  376. $(this).removeClass('btn-default').addClass('btn-primary')
  377. })*/
  378.  
  379.  
  380. }
  381. //Función para guardar o editar
  382.  
  383. function guardaryeditar()
  384. {
  385. var msj='';
  386. if ($("#id_catalogo").val()==''){
  387. var msj="Selecciona una plantilla...!";
  388. }else if($("#id_ums").val()==''){
  389. var msj="Selecciona Unida de Medida Salida..!";
  390. }else if($("#id_marca").val()==''){
  391. var msj="Selecciona una marca o el valor SIN MARCA..!";
  392. }else if($("#id_umi").val()==''){
  393. var msj="Selecciona Unida de Medida Ingreso..!";
  394. }else if($("#factor").val()==''){
  395. var msj="Ingresa Factor..!";
  396. }else if($("#precio_compra").val()==''){
  397. var msj="Ingresa Precio compra..!";
  398. }else if($("#stock_real").val()==''){
  399. var msj="Ingrese un valor para stock real..!";
  400. }else if($("#stock_minimo").val()==''){
  401. var msj="Ingresa un valor para stock minimo..!";
  402. }else if($("#stock_maximo").val()==''){
  403. var msj="Ingresa un valor para stock maximo..!";
  404. }
  405. //alert(msj);return false;
  406. if(msj==''){
  407. var msj="Esta seguro de guardar los cambios?";
  408. bootbox.confirm({
  409. title: "Mensaje",
  410. message: msj,
  411. buttons: {
  412. cancel: {
  413. label: '<i class="fa fa-times"></i> Cancelar'
  414. },
  415. confirm: {
  416. label: '<i class="fa fa-check"></i> Aceptar'
  417. }
  418. },
  419. callback: function (result) {
  420. //console.log('This was logged in the callback: ' + result);
  421. if (result){
  422. //Grabar
  423. //var formData = new FormData($("#frmestablecimiento")[0]);
  424. if ($('#maneja_lotes').is(':checked')){
  425. var maneja_lote='1';
  426. }else{
  427. var maneja_lote='0';
  428. }
  429.  
  430. var parametros = {
  431. "id_item":$('#id_item').val(),
  432. "id_catalogo": $("#id_catalogo option:selected").val(),
  433. "id_marca": $('#id_marca').val(),
  434. //"id_categoria": $('#id_categoria').val(),
  435. "id_ums": $("#id_ums").val(),
  436. "id_umi": $("#id_umi").val(),
  437. "factor": $("#factor").val(),
  438. "precio_compra": $("#precio_compra").val(),
  439. "maneja_lote": maneja_lote,
  440. "id_laboratorio":$("#id_laboratorio").val(),
  441.  
  442. "stock_real": $("#stock_real").val(),
  443. "stock_minimo": $("#stock_minimo").val(),
  444. "stock_maximo": $("#stock_maximo").val()
  445.  
  446. };
  447.  
  448.  
  449. $.ajax({
  450. url: "../ajax/items.php?op=guardaryeditar",
  451. type: "POST",
  452. data: parametros,
  453. //contentType: false,
  454. //processData: false,
  455.  
  456. success: function(datos)
  457. {
  458. bootbox.alert(datos);
  459. //mostrarform(false);
  460. $('#modalNew').modal('toggle')
  461. table.ajax.reload();
  462. }
  463.  
  464. });
  465.  
  466.  
  467. }
  468. }
  469. });
  470.  
  471. }else{
  472. bootbox.alert(msj);
  473. }
  474.  
  475. }
  476.  
  477. function guardaryeditar_local()
  478. {
  479. if ($("#id_local").val()==''){
  480. var msj="Esta seguro de guardar el nuevo registro?";
  481. }else{
  482. var msj="Esta seguro de guardar los cambios?";
  483. }
  484.  
  485. bootbox.confirm({
  486. title: "Mensaje",
  487. message: msj,
  488. buttons: {
  489. cancel: {
  490. label: '<i class="fa fa-times"></i> Cancelar'
  491. },
  492. confirm: {
  493. label: '<i class="fa fa-check"></i> Aceptar'
  494. }
  495. },
  496. callback: function (result) {
  497. //console.log('This was logged in the callback: ' + result);
  498. if (result){
  499. //Grabar
  500. //var formData = new FormData($("#frmestablecimiento")[0]);
  501.  
  502. var parametros = {
  503. "id_local":$('#id_local').val(),
  504. "id_empresa":$('#id_empresa_local').val(),
  505. "nombre":$('#nombre_local').val().toUpperCase(),
  506. "direccion": $('#direccion_local').val().toUpperCase(),
  507. "celular": $('#celular_local').val().toUpperCase(),
  508. "telefono_fijo": $('#telefono_fijo_local').val(),
  509. "id_ubigeo": $("#id_ubigeo_local").val()
  510. };
  511.  
  512.  
  513. $.ajax({
  514. url: "../ajax/local.php?op=guardaryeditar",
  515. type: "POST",
  516. data: parametros,
  517. //contentType: false,
  518. //processData: false,
  519.  
  520. success: function(datos)
  521. {
  522.  
  523. //mostrarform(false);
  524. $('#modalLocal').modal('toggle')
  525. update_child($('#id_empresa_local').val());
  526. bootbox.alert(datos);
  527.  
  528. //table.ajax.reload();
  529. }
  530.  
  531. });
  532.  
  533.  
  534. }
  535. }
  536. });
  537.  
  538.  
  539. //e.preventDefault(); //No se activará la acción predeterminada del evento
  540. /*$("#btnGuardar").prop("disabled",true);*/
  541.  
  542.  
  543.  
  544. /*
  545. limpiar();*/
  546. }
  547.  
  548. function mostrar_item(id_item)
  549. {
  550. $.post("../ajax/items.php?op=mostrar",{id_item : id_item}, function(data, status)
  551. {
  552. data = JSON.parse(data);
  553. $("#id_item").val(id_item);
  554.  
  555. //$("#nombre").val(data.nombre);
  556. //$("#id_empresa").val(data.id_empresa);
  557.  
  558. $("#id_ums").val(data.id_medida_sal);
  559. $("#id_umi").val(data.id_medida_ing);
  560. $("#factor").val(data.factor);
  561. $("#categoria").val(data.categoria);
  562. $("#id_laboratorio").val(data.id_laboratorio);
  563. $("#id_marca").val(data.id_marca);
  564. $("#precio_compra").val(data.precio_compra);
  565.  
  566. $("#stock_real").val(data.stock_real);
  567. $("#stock_minimo").val(data.stock_minimo);
  568. $("#stock_maximo").val(data.stock_maximo);
  569.  
  570. $('#id_catalogo').append("<option value='"+data.id_catalogo+"' selected='selected'>"+data.nombre_catalogo+"</option>");
  571. $("#id_catalogo").trigger('change');
  572.  
  573. if (data.maneja_lote=='1'){
  574. $("#maneja_lotes").iCheck('check')
  575. }else{
  576. $("#maneja_lotes").iCheck('uncheck')
  577. }
  578.  
  579. /*$("#direccion").val(data.direccion);
  580. $("#ruc").val(data.ruc);
  581. $("#telefono_fijo").val(data.telefono_fijo);
  582. $('#ubigeo').append("<option value='"+data.id_ubigeo+"' selected='selected'>"+data.distrito+"</option>");
  583. $("#ubigeo").trigger('change');*/
  584.  
  585. $("#modalTitle").html('Edicion de registro');
  586. $('#modalNew').modal('show');
  587. })
  588. }
  589.  
  590. function mostrar_local(id_empresa,id_local){
  591. //alert(id_empresa);
  592. $("#id_empresa_local").val(id_empresa);
  593.  
  594. $.post("../ajax/local.php?op=mostrar",{id_local : id_local}, function(data, status)
  595. {
  596. data = JSON.parse(data);
  597. $("#nombre_local").val(data.nombre);
  598. $("#id_local").val(id_local);
  599. $("#direccion_local").val(data.direccion);
  600. $("#celular_local").val(data.celular);
  601. $("#telefono_fijo_local").val(data.telefono_fijo);
  602. $('#id_ubigeo_local').append("<option value='"+data.id_ubigeo+"' selected='selected'>"+data.distrito+"</option>");
  603. $("#id_ubigeo_local").trigger('change');
  604. $("#modalLocalTitle").html('Edicion de local');
  605. $('#modalLocal').modal('show');
  606. })
  607.  
  608. }
  609.  
  610.  
  611.  
  612. //Función para desactivar registros
  613. function desactivar(id_item)
  614. {
  615. bootbox.confirm("¿Está Seguro de desactivar el registro?", function(result){
  616. if(result)
  617. {
  618. $.post("../ajax/items.php?op=desactivar", {id_item : id_item}, function(e){
  619. bootbox.alert(e);
  620. table.ajax.reload();
  621. });
  622. }
  623. })
  624. }
  625.  
  626. //Función para activar registros
  627. function activar(id_item)
  628. {
  629. bootbox.confirm("¿Está Seguro de activar el registro?", function(result){
  630. if(result)
  631. {
  632. $.post("../ajax/items.php?op=activar", {id_item : id_item}, function(e){
  633. bootbox.alert(e);
  634. table.ajax.reload();
  635. });
  636. }
  637. })
  638. }
  639. function open_local(id_empresa){
  640. limpiar_local();
  641. $('#id_empresa_local').val(id_empresa)
  642. $('#modalLocal').modal('show')
  643. }
  644.  
  645. //Función para activar local
  646. function activar_local(id_empresa,id_local)
  647. {
  648. bootbox.confirm("¿Está Seguro de activar el registro?", function(result){
  649. if(result)
  650. {
  651. $.post("../ajax/local.php?op=activar", {id_local : id_local}, function(e){
  652. bootbox.alert(e);
  653. update_child(id_empresa);
  654. });
  655. }
  656. })
  657. }
  658.  
  659. //Función para desactivar registros
  660. function desactivar_local(id_empresa,id_local)
  661. {
  662. bootbox.confirm("¿Está Seguro de desactivar el registro?", function(result){
  663. if(result)
  664. {
  665. $.post("../ajax/local.php?op=desactivar", {id_local : id_local}, function(e){
  666. bootbox.alert(e);
  667. update_child(id_empresa);
  668. });
  669. }
  670. })
  671. }
  672.  
  673. init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement