Skip to content

Commit

Permalink
Grouping products in J-Son data
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev1nByte committed Jul 14, 2023
1 parent cc0965a commit 16af910
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 50 deletions.
73 changes: 60 additions & 13 deletions views/js/ventas.js
Expand Up @@ -101,7 +101,7 @@ $(".tablaVentas tbody").on("click", "button.agregarProducto", function(){

'<span class="input-group-addon"><button type="button" class="btn btn-danger btn-xs quitarProducto" idProducto="'+idProducto+'"><i class="fa fa-times"></i></button></span>'+

'<input type="text" class="form-control nuevaDescripcionProducto" idProducto="'+idProducto+'" name="agregarProducto" value="'+descripcion+'" readonly required>'+
'<input type="text" class="form-control nuevaDescripcionProducto agregarProducto" idProducto="'+idProducto+'" name="agregarProducto" value="'+descripcion+'" readonly required>'+

'</div>'+

Expand Down Expand Up @@ -139,6 +139,10 @@ $(".tablaVentas tbody").on("click", "button.agregarProducto", function(){

agregarImpuesto()

// AGRUPAR PRODUCTOS EN FORMATO JSON

listarProductos()

// PONER FORMATO AL PRECIO DE LOS PRODUCTOS

$(".nuevoPrecioProducto").number(true, 2);
Expand Down Expand Up @@ -216,6 +220,10 @@ $(".formularioVenta").on("click", "button.quitarProducto", function(){

agregarImpuesto()

// AGRUPAR PRODUCTOS EN FORMATO JSON

listarProductos()

}

})
Expand Down Expand Up @@ -307,13 +315,13 @@ $(".btnAgregarProducto").click(function(){

// SUMAR TOTAL DE PRECIOS

sumarTotalPrecios()
sumarTotalPrecios()

// AGREGAR IMPUESTO
// AGREGAR IMPUESTO

agregarImpuesto()

// PONER FORMATO AL PRECIO DE LOS PRODUCTOS
// AGRUPAR PRODUCTOS EN FORMATO JSON

$(".nuevoPrecioProducto").number(true, 2);

Expand Down Expand Up @@ -350,7 +358,10 @@ $(".formularioVenta").on("change", "select.nuevaDescripcionProducto", function()
$(nuevaCantidadProducto).attr("stock", respuesta["stock"]);
$(nuevoPrecioProducto).val(respuesta["precio_venta"]);
$(nuevoPrecioProducto).attr("precioReal", respuesta["precio_venta"]);

// AGRUPAR PRODUCTOS EN FORMATO JSON

listarProductos()
}

})
Expand All @@ -367,6 +378,10 @@ $(".formularioVenta").on("change", "input.nuevaCantidadProducto", function(){

precio.val(precioFinal);

var nuevoStock = Number($(this).attr("stock")) - $(this).val();

$(this).attr("nuevoStock", nuevoStock);

if(Number($(this).val()) > Number($(this).attr("stock"))){

// SI LA CANTIDAD ES SUPERIOR AL STOCK REGRESAR VALORES INICIALES
Expand All @@ -378,15 +393,15 @@ $(".formularioVenta").on("change", "input.nuevaCantidadProducto", function(){
precio.val(precioFinal);

sumarTotalPrecios();

swal({

title: "La cantidad supera el Stock",
text: "¡Sólo hay "+$(this).attr("stock")+" unidades!",
type: "error",
confirmButtonText: "¡Cerrar!"
swal({

});
title: "La cantidad supera el Stock",
text: "¡Sólo hay "+$(this).attr("stock")+" unidades!",
type: "error",
confirmButtonText: "¡Cerrar!"

});

return;

Expand All @@ -398,7 +413,11 @@ $(".formularioVenta").on("change", "input.nuevaCantidadProducto", function(){

// AGREGAR IMPUESTO

agregarImpuesto()
agregarImpuesto()

// AGRUPAR PRODUCTOS EN FORMATO JSON

listarProductos()

})

Expand Down Expand Up @@ -539,4 +558,32 @@ $(".formularioVenta").on("change", "input#nuevoValorEfectivo", function(){

nuevoCambioEfectivo.val(cambio);

})
})

// LISTAR TODOS LOS PRODUCTOS

function listarProductos(){

var listaProductos = [];

var descripcion = $(".nuevaDescripcionProducto");

var cantidad = $(".nuevaCantidadProducto");

var precio = $(".nuevoPrecioProducto");

for(var i = 0; i < descripcion.length; i++){

listaProductos.push({ "id" : $(descripcion[i]).attr("idProducto"),
"descripcion" : $(descripcion[i]).val(),
"cantidad" : $(cantidad[i]).val(),
"stock" : $(cantidad[i]).attr("nuevoStock"),
"precio" : $(precio[i]).attr("precioReal"),
"total" : $(precio[i]).val()})

}

console.log("listaProductos", listaProductos)
// $("#listaProductos").val(JSON.stringify(listaProductos));

}
41 changes: 4 additions & 37 deletions views/modulos/crear-venta.php
Expand Up @@ -126,45 +126,12 @@
<!-- ENTRADA PARA AGREGAR PRODUCTO -->

<div class="form-group row nuevoProducto">

<!-- DESCRIPCION DEL PRODUCTO -->

<!-- <div class="col-xs-6" style="padding-right:0px">
<div class="input-group">
<span class="input-group-addon"><button type="button" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></span></button></span>
<input type="text" class="form-control" id="agregarProducto" name="agregarProducto" placeholder="Descripción del producto" required>
</div>
</div> -->

<!-- CANTIDAD DEL PRODUCTO -->

<!-- <div class="col-xs-3">
<input type="number" class="form-control" id="nuevaCantidadProducto" name="nuevaCantidadProducto" min="1" placeholder ="0" required>
</div> -->

<!-- PRECIO DEL PRODUCTO -->

<!-- <div class="col-xs-3" style="padding-left:0px">
<div class="input-group">
<span class="input-group-addon"><i class="ion ion-social-usd"></i></span>
<input type="number" class="form-control" id="nuevaPrecioProducto" name="nuevaPrecioProducto" min="1" placeholder="000000" readonly required>
</div>
</div> -->



</div>

<input type="hidden" id="listaProducto" name="listaProducto">

<!-- BOTON PARA AGREGAR PRODUCTO -->

<button type="button" class="btn btn-default hidden-lg btnAgregarProducto">Agregar producto</button>
Expand Down

0 comments on commit 16af910

Please sign in to comment.