You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
9.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. var path_pedidos = "../prgdmug/pedidos_vta.php";
  2. var path_alta = "../prgdmug/alta_ped.php";
  3. var path_detalles = "../prgdmug/detalles_pedesp.php";
  4. /* VARIABLES GLOBALES PARA FUNCIONAMIENTO DE SCRIPT*************************************************************************/
  5. var lista_de_pedidos = [];
  6. var ped;
  7. function menuTogle(){
  8. $("#myMenuIcon").toggleClass("menuIcon");
  9. $("#myMenuIcon").toggleClass("cancelIcon");
  10. $("#myNavy").toggle();
  11. $("#myMenuDiv").toggleClass("backBlack");
  12. }
  13. $("#myMenuDiv").click(function(){
  14. menuTogle();
  15. });
  16. $(".nav-item").click(function(){
  17. menuTogle();
  18. });
  19. /* FORMATO PARA NUMEROS*************************************************************************/
  20. function number_format(amount, decimals) {
  21. amount += ''; // por si pasan un numero en vez de un string
  22. amount = parseFloat(amount.replace(/[^0-9\.]/g, '')); // elimino cualquier cosa que no sea numero o punto
  23. decimals = decimals || 0; // por si la variable no fue fue pasada
  24. // si no es un numero o es igual a cero retorno el mismo cero
  25. if (isNaN(amount) || amount === 0)
  26. return parseFloat(0).toFixed(decimals);
  27. // si es mayor o menor que cero retorno el valor formateado como numero
  28. amount = '' + amount.toFixed(decimals);
  29. var amount_parts = amount.split('.'),
  30. regexp = /(\d+)(\d{3})/;
  31. while (regexp.test(amount_parts[0]))
  32. amount_parts[0] = amount_parts[0].replace(regexp, '$1' + '.' + '$2');
  33. return amount_parts.join('.');
  34. }
  35. function crear_detalles_pedido(nro,ido){
  36. $.ajax({url: path_detalles,
  37. type: 'POST',
  38. data: nro,
  39. dataType: 'json',
  40. success: function(response)
  41. {
  42. console.log(response.document.pedido.detped[0]);
  43. var nodos = document.getElementsByClassName("salir");
  44. if(nodos.length>0){
  45. for(var i = 0 ; i < nodos.length ; i++){
  46. nodos[i].remove();
  47. }
  48. }
  49. /*ARMO PANTALLA*/
  50. //var detallesList = '<div class="col-12 salir"> ';
  51. var detallesList ='<div class="col-12 salir"> <table class="table table-sm col-sm-12 col-md-12 col-mb-12 col-lg-12 text-center "><thead class="thead-dark"><tr><th scope="col">cod art</th><th scope="col">Descripcion</th><th scope="col">Cant</th><th scope="col">UxB</th><th scope="col">Precio</th><th scope="col">Total Item</th><th scope="col">Renta</th><th scope="col">P.Lista</th></th></thead>';
  52. for (var i = 0; i < response.document.pedido.detped.length ; i++)
  53. {
  54. detallesList +='<tbody><tr><th scope="row"><small style="color: #6c757d;">'+response.document.pedido.detped[i].dep_art+'</small></th><td><small style="color: #6c757d;">'+response.document.pedido.detped[i].dep_des+'</small></td><td><small style="color: #6c757d;">'+response.document.pedido.detped[i].dep_cant+'</small></td><td><small style="color: #6c757d;">'+response.document.pedido.detped[i].dep_udad+'</small></td><td><small style="color: #6c757d;">$'+response.document.pedido.detped[i].dep_prec+'</small></td><td><small style="color: #6c757d;">'+response.document.pedido.detped[i].totitem+'</small></td><td><small style="color: #6c757d;">'+response.document.pedido.detped[i].rentaitem+'</small></td><td><small style="color: #6c757d;">'+response.document.pedido.detped[i].dep_plista+'</small></td></tr>';
  55. /*
  56. ---VERSION ANTIGUA---
  57. detallesList += '<div class="row ">';
  58. detallesList += '<div class="col-12 col-sm-12">';
  59. detallesList += '<small style="color: #6c757d;">cod art: '+response.document.pedido.detped[i].dep_art+ ' Descripcion: '+response.document.pedido.detped[i].dep_des+'&nbsp;&nbsp;&nbsp;</small></div>';
  60. detallesList += '<div class="col-12 col-sm-12">';
  61. detallesList += '<small style="color: #6c757d;">cant pedido: '+response.document.pedido.detped[i].dep_cant+' UxB: '+response.document.pedido.detped[i].dep_udad+' Precio: $'+response.document.pedido.detped[i].dep_prec+' &nbsp;&nbsp;&nbsp;</small></div>';
  62. detallesList += '<div class="col-12 col-sm-12">';
  63. detallesList += '<small style="color: #6c757d;">Stock:'+response.document.pedido.detped[i].totitem+' Renta:'+response.document.pedido.detped[i].rentaitem+'&nbsp;</small></div>';
  64. detallesList += '</div><hr>';*/
  65. }
  66. detallesList+='</tbody></table >';
  67. detallesList += '<button type="button" id='+response.document.pedido.cap_ped+' class="btn btn-primary btn-lg btn-block alta">Confirmar Pedido</button></div>';
  68. ido.parent().parent().after(detallesList);
  69. $('#tplista').text("total precio lista :"+response.document.pedido.tplista);
  70. $('#trenta').text(" Total renta obtenida :"+response.document.pedido.trenta);
  71. $('#difpre').text("Diferencia de total precio lista :"+response.document.pedido.difpre);
  72. $( ".alta" ).click(function() {
  73. //var suc = document.getElementById("sucursal").value;
  74. var ped = $(this).attr("id");
  75. var parametros={"n_ped":ped};
  76. if (confirm('Seguro desea confirmar el pedido :'+ped)) {
  77. $.ajax({url: path_alta,
  78. type: 'POST',
  79. data: parametros,
  80. dataType: 'json',
  81. success: function(response){
  82. alert("Grabado correctamente!");
  83. location.reload();
  84. }
  85. });
  86. console.log('confirmo pedido');
  87. }
  88. else {
  89. console.log('No confirmo pedido');
  90. }
  91. });
  92. }
  93. });
  94. }
  95. function llenar_lista_pedido()
  96. {
  97. $('#pedido').text(" ");
  98. $('#cliente').text(" ");
  99. $('#total').text(" ");
  100. var suc = document.getElementById("sucursal").value;
  101. var parametros = {"suc": suc};
  102. $('.list-group').empty();
  103. $.ajax({url: path_pedidos,
  104. type: 'POST',
  105. data: parametros,
  106. dataType: 'json',
  107. success: function(response){
  108. for (var i = 0; i < response.CLIENTE.length ; i++){
  109. var math=parseInt(response.CLIENTE[i].total)/100;
  110. $('.lista-pedido').append("<li class='col-sm-12 col-md-12 col-mb-12 col-lg-12 text-center list-group-item list-group-item-secondary consulta' style='border: 3px solid ;' id="+response.CLIENTE[i].pedido+" ><div> Pedido nª : <p style='display: inline;' id='ped_"+response.CLIENTE[i].pedido+"'>"+response.CLIENTE[i].pedido+"</p> CLIENTE : <p style='display: inline;'id='numcli_"+response.CLIENTE[i].pedido+"'>"+response.CLIENTE[i].cliente+" "+response.CLIENTE[i].nomcli+"</p > Total:$ <p style='display: inline;' id='total_"+response.CLIENTE[i].pedido+"'>"+parseInt(response.CLIENTE[i].total)/100+"</p></div><br><div id=hide_"+response.CLIENTE[i].pedido+" class='oculto'><u>ver mas</u></div></li><br>");
  111. }
  112. $(".oculto").click(function() {
  113. var suc = document.getElementById("sucursal").value;
  114. var oID = $(this).attr("id");
  115. var res = oID.split("_");
  116. $(".oculto").show();
  117. $(this).hide();
  118. var parametros = {
  119. "suc" : suc,
  120. "ped" : res[1]
  121. };
  122. crear_detalles_pedido(parametros, $(this));
  123. });
  124. $(".consulta").click(function() {
  125. var oID = $(this).attr("id");
  126. $(".consulta").removeClass("border-success");
  127. $( '#'+oID+'' ).addClass( "border-success" );
  128. v_ped="ped_"+oID;
  129. v_numcli="numcli_"+oID;
  130. v_nomcli="nomcli_"+oID;
  131. v_total="total_"+oID;
  132. ped=$('#'+v_ped+'').text();
  133. var n_cli = $('#'+v_numcli+'').text();
  134. var nom_cli = $('#'+v_nomcli+'').text();
  135. var total = $('#'+v_total+'').text();
  136. $('#pedido').text("#"+ped);
  137. $('#cliente').text("Cliente: "+n_cli);
  138. $('#total').text("Total $ :"+total);
  139. $('#tplista').text("total precio lista :"+tplista);
  140. $('#trenta').text(" Total renta obtenida :"+trenta);
  141. $('#difpre').text("Diferencia de total precio lista :"+difpre);
  142. // "PVE_" + "Suc" + <"+suc+"> + "_" + <Tipo Comp> + <Operacion> + "_" + <Nro.Comprobante> + ".pdf"
  143. //var _href = $('#descarga').attr("href");
  144. $('#descarga').attr("href",'../pdf/PVE_Suc'+suc+'_PE40_'+ped+'.pdf');
  145. $('#descarga').attr("download", 'PVE_Suc'+suc+'_PE40_'+ped+'.pdf');
  146. });
  147. $( "#pedido_i" ).click(function() {
  148. alert("ped");
  149. });
  150. }
  151. });
  152. }
  153. $(document).ready(function() {
  154. $("#myNavy").removeClass("invisible");
  155. $("#myNavy").hide();
  156. llenar_lista_pedido();
  157. $("#sucursal").change(function() {
  158. llenar_lista_pedido();
  159. });
  160. $( "button" ).click(function() {
  161. var parametros={"n_ped":ped};
  162. if (confirm('Seguro desea confirmar el pedido :'+ped)) {
  163. $.ajax({url: path_alta,
  164. type: 'POST',
  165. data: parametros,
  166. dataType: 'json',
  167. success: function(response){
  168. alert("Grabado correctamente!");
  169. location.reload();
  170. }
  171. });
  172. console.log('confirmo pedido');
  173. } else {
  174. console.log('No confirmo pedido');
  175. }
  176. });
  177. });