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.
 
 
 
 
 
 

195 lines
9.2 KiB

var path_pedidos = "../prgdmug/pedidos_vta.php";
var path_alta = "../prgdmug/alta_ped.php";
var path_detalles = "../prgdmug/detalles_pedesp.php";
/* VARIABLES GLOBALES PARA FUNCIONAMIENTO DE SCRIPT*************************************************************************/
var lista_de_pedidos = [];
var ped;
function menuTogle(){
$("#myMenuIcon").toggleClass("menuIcon");
$("#myMenuIcon").toggleClass("cancelIcon");
$("#myNavy").toggle();
$("#myMenuDiv").toggleClass("backBlack");
}
$("#myMenuDiv").click(function(){
menuTogle();
});
$(".nav-item").click(function(){
menuTogle();
});
/* FORMATO PARA NUMEROS*************************************************************************/
function number_format(amount, decimals) {
amount += ''; // por si pasan un numero en vez de un string
amount = parseFloat(amount.replace(/[^0-9\.]/g, '')); // elimino cualquier cosa que no sea numero o punto
decimals = decimals || 0; // por si la variable no fue fue pasada
// si no es un numero o es igual a cero retorno el mismo cero
if (isNaN(amount) || amount === 0)
return parseFloat(0).toFixed(decimals);
// si es mayor o menor que cero retorno el valor formateado como numero
amount = '' + amount.toFixed(decimals);
var amount_parts = amount.split('.'),
regexp = /(\d+)(\d{3})/;
while (regexp.test(amount_parts[0]))
amount_parts[0] = amount_parts[0].replace(regexp, '$1' + '.' + '$2');
return amount_parts.join('.');
}
function crear_detalles_pedido(nro,ido){
$.ajax({url: path_detalles,
type: 'POST',
data: nro,
dataType: 'json',
success: function(response)
{
console.log(response.document.pedido.detped[0]);
var nodos = document.getElementsByClassName("salir");
if(nodos.length>0){
for(var i = 0 ; i < nodos.length ; i++){
nodos[i].remove();
}
}
/*ARMO PANTALLA*/
//var detallesList = '<div class="col-12 salir"> ';
var detallesList ='<tr class="salir table-responsive"><td colspan="4" class="p-0 pb-4"><table class="table table-sm"><thead><tr><th scope="col">COD ART</th><th scope="col">Descripción</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></tr></thead>';
for (var i = 0; i < response.document.pedido.detped.length ; i++)
{
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>';
/*
---VERSION ANTIGUA---
detallesList += '<div class="row ">';
detallesList += '<div class="col-12 col-sm-12">';
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>';
detallesList += '<div class="col-12 col-sm-12">';
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>';
detallesList += '<div class="col-12 col-sm-12">';
detallesList += '<small style="color: #6c757d;">Stock:'+response.document.pedido.detped[i].totitem+' Renta:'+response.document.pedido.detped[i].rentaitem+'&nbsp;</small></div>';
detallesList += '</div><hr>';*/
}
detallesList+='</tbody></table >';
detallesList += '<button type="button" id='+response.document.pedido.cap_ped+' class="btn btn-outline-success btn-block col-sm-2 font-weight-bold my-4 alta">Confirmar pedido</button></td></tr>';
ido.parent().after(detallesList);
$( ".alta" ).click(function() {
//var suc = document.getElementById("sucursal").value;
var ped = $(this).attr("id");
var parametros={"n_ped":ped};
if (confirm('Seguro desea confirmar el pedido :'+ped)) {
$.ajax({url: path_alta,
type: 'POST',
data: parametros,
dataType: 'json',
success: function(response){
alert("Grabado correctamente!");
location.reload();
}
});
console.log('confirmo pedido');
}
else {
console.log('No confirmo pedido');
}
});
}
});
}
function llenar_lista_pedido()
{
$('#pedido').text(" ");
$('#cliente').text(" ");
$('#total').text(" ");
var suc = document.getElementById("sucursal").value;
var parametros = {"suc": suc};
$('.list-group').empty();
$.ajax({url: path_pedidos,
type: 'POST',
data: parametros,
dataType: 'json',
success: function(response){
for (var i = 0; i < response.CLIENTE.length ; i++){
var math=parseInt(response.CLIENTE[i].total)/100;
$('.lista-pedido').append("<tr class='consulta' id="+response.CLIENTE[i].pedido+"><th class='border-right py-4' scope='row'>"+response.CLIENTE[i].pedido+"</th><td class='border-right py-4'>"+response.CLIENTE[i].cliente+" "+response.CLIENTE[i].nomcli+"</td><td class='border-right py-4'>$"+parseInt(response.CLIENTE[i].total)/100+"</td><td class='py-4 text-center'><div id=hide_"+response.CLIENTE[i].pedido+" class='oculto'><span class='fa-stack fa-lg'><i class='fa fa-circle fa-stack-2x'></i><i class='fa fa-plus fa-stack-1x fa-inverse'></i></span></div></td></tr>");
}
$(".oculto").click(function() {
var suc = document.getElementById("sucursal").value;
var oID = $(this).attr("id");
var res = oID.split("_");
$(".oculto").show();
$(this).hide();
var parametros = {
"suc" : suc,
"ped" : res[1]
};
crear_detalles_pedido(parametros, $(this));
});
$(".consulta").click(function() {
var oID = $(this).attr("id");
v_ped="ped_"+oID;
v_numcli="numcli_"+oID;
v_nomcli="nomcli_"+oID;
v_total="total_"+oID;
ped=$('#'+v_ped+'').text();
var n_cli = $('#'+v_numcli+'').text();
var nom_cli = $('#'+v_nomcli+'').text();
var total = $('#'+v_total+'').text();
$('#pedido').text("# "+ped);
$('#cliente').text("Cliente: "+n_cli);
$('#total').text("Total: $"+total);
// "PVE_" + "Suc" + <"+suc+"> + "_" + <Tipo Comp> + <Operacion> + "_" + <Nro.Comprobante> + ".pdf"
//var _href = $('#descarga').attr("href");
$('#descarga').attr("href",'../pdf/PVE_Suc'+suc+'_PE40_'+ped+'.pdf');
$('#descarga').attr("download", 'PVE_Suc'+suc+'_PE40_'+ped+'.pdf');
});
$( "#pedido_i" ).click(function() {
alert("ped");
});
}
});
}
$(document).ready(function() {
$("#myNavy").removeClass("invisible");
$("#myNavy").hide();
llenar_lista_pedido();
$("#sucursal").change(function() {
llenar_lista_pedido();
});
$( "button" ).click(function() {
var parametros={"n_ped":ped};
if (confirm('Seguro desea confirmar el pedido :'+ped)) {
$.ajax({url: path_alta,
type: 'POST',
data: parametros,
dataType: 'json',
success: function(response){
alert("Grabado correctamente!");
location.reload();
}
});
console.log('confirmo pedido');
} else {
console.log('No confirmo pedido');
}
});
});