0

I'm developing a POS using JQuery and AdoDB, i have this loop

function actualizarVentaProducto() {

    var idProducto = $(".idProducto");
    var statusVenta = $('#statusVenta').val();
    var cantidad = $(".nuevaCantidadProducto");
    var tipoPrecio = $('#tipoPrecio').val();
    var precioMayoreo = $(".precioMayoreo");
    var precioMenudeo = $(".precioMenudeo");
    var existencia = $(".existencia");

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

        var data = new FormData();
        data.append('opc', 3);
        data.append('statusVenta', statusVenta);
        data.append('idProducto', idProducto[i].value);
        data.append('cantidad', cantidad[i].value);
        data.append('tipoPrecio', tipoPrecio);
        data.append('precioMayoreo', precioMayoreo[i].value);
        data.append('precioMenudeo', precioMenudeo[i].value);
        data.append('existencia', existencia[i].value);
        var url = "../controlador/ventas.controlador.php";
        $.ajax({
            type: "POST",
            url: url,
            data: data,
            cache: false,
            processData: false,
            contentType: false,
            success: function (data) {
                $('#debug').append(data);
            },
            error: function (ts) {
                alert(ts.responseText)
            }
        });
    }
    $('#debug').append('--------------------------------------------------------------------------------------------------------------------------------------------');
}

and a php funtion.

public function mdlActualizarDetalleVentaProductos($statusVenta, $idProducto, $cantidad, $tipoPrecio, $precioMayoreo, $precioMenudeo, $existencia) {
        $nuevaExistencia = $existencia - $cantidad;
        if ($tipoPrecio == 'Mayoreo') {
            $precioProducto = $precioMayoreo;
        } else {
            $precioProducto = $precioMenudeo;
        }

        $total = $cantidad * $precioProducto;

        $sql = "UPDATE detalle_venta_productos SET cantidad = ?, precio_producto_venta = ?, total = ? WHERE id_venta = ? AND id_producto = ?";
        $prp = $this->db->Prepare($sql);
        $this->db->Execute($prp, array($cantidad, $precioProducto, $total, $statusVenta, $idProducto));
        $afectados = $this->db->affected_rows();

        $sql2 = "UPDATE productos SET existencia = ? WHERE id_producto = ?";
        $prp2 = $this->db->Prepare($sql2);
        $this->db->Execute($prp2, array($nuevaExistencia, $idProducto));
//        echo 'UPDATE detalle_venta_productos SET cantidad = ?, precio_producto_venta = ?, total = ? WHERE id_venta = ? AND id_producto = ?<br>';
//        echo $cantidad . '-' . $precioProducto . '-' . $total . '-' . $statusVenta . '-' . $idProducto;
//        return "UPDATE detalle_venta_productos SET cantidad = $cantidad, precio_producto_venta = $precioProducto, total = $total WHERE id_venta = $statusVenta AND id_producto = $idProducto;<br>$tipoPrecio<br>";
        print $afectados . '<br>';
    }

I returned the query to check if it is correct, and all are correct, but checked in database and not all where updated successfully. My table has InnoDB engine and SELECT @@autocommit returns 1, Can you help me find my error?

4

0 回答 0