예제 #1
0
<?php

if ($_POST) {
    include_once "../controller/cVentas.php";
    include_once '../controller/cLibreria.php';
    $cVentas = new cVentas();
    $cLibreria = new cLibreria();
    switch ($_POST['opcion']) {
        case 'setVentas':
            try {
                $id_ventas = $cVentas->setVentas($_POST['id_sucursal'], $_POST['id_usuario'], $_POST['comision_total']);
                //guardo la venta
                $cVentas->setVentasProductos($id_ventas, $_POST['id_producto'], $_POST['comision_total'], $_POST['num_serie']);
                //guardo la relacion de la venta con los productos
                $cVentas->notificacion($_POST['id_usuario'], $id_ventas);
                //envio un mensaje de notificacion
                $respuesta = array('resultado' => 1);
                echo json_encode($respuesta);
            } catch (Exception $e) {
                include_once '../controller/cFallidos.php';
                include_once '../controller/cProductos.php';
                $cFallidos = new cFallidos();
                $cProductos = new cProductos();
                $datos = $cProductos->getProducto($_POST['id_producto']);
                while ($row = $datos->fetch_array(MYSQLI_ASSOC)) {
                    $producto = $row['clave'] . "/" . $row['descripcion'];
                }
                $descripcion = "<h4>EL REGISTRO DE LA VENTA NO SE REALIZO CON EXITO.</h4>EL PRODUCTO A REGISTRAR ES: <b>" . strtoupper($producto . "/" . $_POST['num_serie']) . "</b> CON UNA COMISIÓN TOTAL DE: <b>" . $_POST['comision_total'] . "</b>";
                $cFallidos->setFallido($_POST['id_usuario'], $_POST['id_sucursal'], $descripcion, 1);
                $respuesta = array('error' => $e->getMessage());
                echo json_encode($respuesta);