<?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);
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Temposatis</title>
	<!-- <link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/> -->
	<style>
		.text-center{text-align: center; }
		.text-left{text-align: left; }
		.text-right{text-align: right; }
	</style>
</head>
<body>
	<div class="datos">
		<?php 
include_once "../controller/cVentas.php";
$cVentas = new cVentas();
$datos = $cVentas->getVentas($_GET['user'], $_GET['sucursal'], $_GET['fecha_inicio'], $_GET['fecha_fin'], $_GET['estatus']);
?>
			<table class="table table-hover table-bordered table-striped" id="tabla" border="1" cellpadding="10" cellspacing="0">
				<thead>
					<tr>
						<th> Folio</th>
						<th> Fecha </th>
						<th> Referencia/serie</th>
						<th> Incentivos por venta(comisiones) </th>
						<th> Estatus</th>
						<th> Observacion</th>
					</tr>
				</thead>
				<tbody>
					<?php 
	<meta charset="UTF-8">
	<title>Temposatis</title>
	<!-- <link href="../assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/> -->
	<style>
		.text-center{text-align: center; }
		.text-left{text-align: left; }
		.text-right{text-align: right; }
	</style>
</head>
<body>
	<div class="datos">
		<?php 
include_once "../controller/cVentas.php";
include_once '../controller/cLibreria.php';
$cLibreria = new cLibreria();
$cVentas = new cVentas();
$datos = $cVentas->getVentasExistentes($_GET['id_cliente'], $_GET['vendedor'], $_GET['sucursal'], $_GET['fecha_inicio'], $_GET['fecha_fin'], $_GET['estatus']);
?>
			<table class="table table-hover table-bordered table-striped" id="tabla" border="1" cellpadding="10" cellspacing="0">
				<thead>
					<tr>
						<th> Folio</th>
						<th> Sucursal </th>
						<th> Vendedor </th>
						<th> Fecha </th>
						<th> Referencia/serie</th>
						<th> Incentivos por venta(comisiones) </th>
						<th> Estatus</th>
						<th> Observacion</th>
					</tr>
				</thead>