<?php
/*-------------------------
	Autor: Jose Luis Robles
	Mail: jrobleso@gmail.com
	---------------------------*/
	session_start();
	if (!isset($_SESSION['user_login_status']) AND $_SESSION['user_login_status'] != 1) {
        header("location: login.php");
		exit;
        }
	
   /* Connect To Database*/
   require_once ("config/db.php");//Contiene las variables de configuracion para conectar a la base de datos
   require_once ("config/conexion.php");//Contiene funcion que conecta a la base de datos
   require_once ("config/database.php");//Contiene funcion que conecta a la base de datos
	
	$active_rep_gral_lineal_anio = "active";
	$active_nueva_facturas = "";
	$active_productos = "";
	$active_clientes = "";
	$active_usuarios = "";
	$title = "Reporte General";
	$anio = '';

    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
        if(isset($_POST['Anio']))
        {
            //print_r($_POST);
            	

             /* Realizar la conexión a la base de datos y llamar al procedimiento almacenado
             $servername = "localhost";
             $username = "cloudbs_bonifica";
             $password = "Torua223.0";
             $dbname = "cloudbs__mhwmadsystem";*/
 
             $conn = new mysqli($server, $username, $password, $database);
                             
 
             if ($conn->connect_error) {
                 die("Error de conexión: " . $conn->connect_error);
             }
            
            
            // Consultar info
            $anio = trim($_POST['Anio']);
         
            $sql = "CALL ReporteFull_lineal_anio('{$anio}');";

            $result = $conn->query($sql);
        }
        

    }

   
?>
<!DOCTYPE html>
<?php /*var_dump($bimestre);*/   ?>
<html lang="en">
     <head>
    <meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
	<!-- El CSS de DataTables -->
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jszip-2.5.0/pdfmake-0.1.18/dt-1.10.12/af-2.1.2/b-1.2.2/b-colvis-1.2.2/b-flash-1.2.2/b-html5-1.2.2/b-print-1.2.2/cr-1.3.2/fc-3.2.2/fh-3.1.2/kt-2.1.3/r-2.1.0/rr-1.1.2/sc-1.4.2/se-1.2.0/datatables.min.css"/>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://cdn.datatables.net/1.13.7/css/dataTables.bootstrap.min.css">
        <link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.bootstrap.min.css">
	<!-- El CSS de Bootstrap -->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
	<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.2/dist/umd/popper.min.js" integrity="sha384-q9CRHqZndzlxGLOj+xrdLDJa9ittGte1NksRmgJKeCV9DrM7Kz868XYqsKWPpAmn" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>

    <?php include("head.php");  include("navbar.php");?>
    
  </head>

  
  <body>
      
	
	<?php 

    
    
    ?>
	
    <div class="container">
	<div class="panel panel-info">
	
		<div class="panel-heading">
	
    	<h4><i class='glyphicon glyphicon-search'></i> Consulta lineal bonificaciones en costo/caja/botella por año acumulado </h4>
		</div>
		<div class="panel-body">

        <form method="post" class="mb-20">
            <div class="row">
                <div class="col-md-2">
                    
                    <label for="Ano" class="form-label">Seleccionar Año:</label>
                    <select class="form-control"  name="Anio" id="Anio" required>
                        <?php
									            $sql_anio = mysqli_query($con, "select * from anio where status_anio = 1 ");
									            while ($rw = mysqli_fetch_array($sql_anio)) {
										     
										        $anio = $rw["nombre_anio"];
									            ?>
										        <option value="<?php echo $anio?>"><?php echo $anio?></option>
									            <?php
									            }
									            ?>
                    
                    </select>
                </div>
 
            </div>
            <p> 
            <div>
            <p> 
            <button type="submit" class="btn btn-primary mt-3">Filtrar</button>
            </div>
        </form>
        
        
        
        
       
        
           <!-- <form role="form" class="form-horizontal" action="repGeneral_Excel.php" target="_blank">
          <div class="box-body">

          </div>
          
         <div class="box-footer">
            <div class="form-group">
              <div class="col-sm-offset-1 col-sm-11">
                
				
				   <button type="submit" class="btn btn-primary btn-social btn-submit" style="width: 160px;">
                 <i class="fa fa-file-excel-o" aria-hidden="true"></i> Download XLS
                </button>
              </div>
            </div>
          </div>
        </form>-->
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        <div class="table-responsive">  
        
        <!--<table id="dataTables" class="table table-bordered table-striped table-hover">-->
            <table id="dataTables" class="display nowrap" style="width:100%">  
            <thead>
                <tr>
                    <th class="center" style="color: #ffffff; background-color: #4682B4"># Bonificacion</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Estatus</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Fecha</th>
                    <th class="center" style="color: #ffffff; background-color: #4682B4; text-align: left;">Partida</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Factura</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">NC</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Promotor</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">mescaptura</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Año de aplicacion</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Zona</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Poblacion</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">CDC</th>
                    <th class="center" style="color: #ffffff; background-color: #4682B4">Negocio</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Mayorista</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Producto</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Botellas</th>
					<th class="center"style="color: #ffffff; background-color: #4682B4">Cajas</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Costo unitario</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Cantidad</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Total adquirido</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Marca a bonificar</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">% de bonificacion</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Bonificacion correspondiente</th>
                    <th class="center"style="color: #ffffff; background-color: #4682B4">Botellas/ Cajas a bonificar</th>
					
                    
                    
                    
                
                    <!-- Añade más encabezados según la estructura de tu procedimiento almacenado -->
                </tr>
            </thead>
            <tbody>
                <?php if($result->num_rows > 0) { ?>
                
                    <?php while($obj = $result->fetch_object()) { ?>
                        <tr>
                            <td class="center"style="color: #ffffff; background-color: #4682B4"><?php echo $obj->{'# Bonificacion'};  ?></td>
                            <td width='80' class='center'><?php echo $obj->Estatus;  ?></td>
                            <td width='80' class='center'><?php echo $obj->Fecha;  ?></td>
                            <td width='80' class='center'><?php echo $obj->Partida;  ?></td>
                            <td width='80' class='center'><?php echo $obj->Factura;  ?></td>
                            <td width='80' class='center'><?php echo $obj->{'Notas de Credito'};  ?></td>
                            <td width='80' class='center'><?php echo $obj->Promotor;  ?></td>
                            <td width='80' class='center'><?php echo $obj->MESCAPTURA;  ?></td>
                            <td width='80' class='center'><?php echo $obj->{'Anio de Aplicacion'};  ?></td>
                            <td width='80' class='center'><?php echo $obj->Zona;  ?></td>
                            <td width='80' class='center'><?php echo $obj->Poblacion;  ?></td>
                            <td width='80' class='center'><?php echo $obj->{'Centro de Consumo'};  ?></td>
                            <td width='80' class='center'><?php echo $obj->Negocio;  ?></td>
                            <td width='80' class='center'><?php echo $obj->Mayorista;  ?></td>
                            <td width='80' class='center'><?php echo $obj->Producto;  ?></td>
                            <td width='80' class='center'><?php echo $obj->Botellas;  ?></td>
							<td width='80' class='center'><?php echo $obj->Cajas;  ?></td>
                            <td width='80' class='center'>$<?php echo number_format($obj->Costo, 2, '.', ','); ?></td>
                            <td width='80' class='center'><?php echo round($obj->Cantidad);  ?></td>
                            <td width='80' class='center'>$<?php echo number_format($obj->TotalBonificacion, 2, '.', ','); ?></td>
                            <td width='80' class='center'><?php echo $obj->marca_bon;  ?></td>
                            <td width='80' class='center'><?php echo ($obj->{'A bonificar'} * 100).'%';  ?></td>
                            <td width='80' class='center'>$<?php echo number_format($obj->Bonificacion, 2, '.', ','); ?></td>
                            <td width='80' class='center'><?php echo round($obj->botellas_bon);  ?></td>
                            
                            
                            
                           
                        </tr>
                    <?php } ?>
                <?php } else { ?>
                    <tr>
                        <td colspan="7">No se encontraron resultados.</td>
                    </tr>
                <?php } ?>
            </tbody>
            </div>
        </table>
    </div>
			
		
	
			
			
			
  </div>
</div>
	<hr>
	<?php
	//var_dump($result);
	include("footer.php");
	?>
	<script type="text/javascript" src="js/VentanaCentrada.js"></script>
	<script type="text/javascript" src="js/nueva_factura.js"></script>
	<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
	<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
	<script type="text/javascript" src="js/select2.min.js"></script>
	<!-- El JavaScript de DataTables -->
	<script language="javascript" type="text/javascript" src="https://cdn.datatables.net/v/dt/jszip-2.5.0/pdfmake-0.1.18/dt-1.10.12/af-2.1.2/b-1.2.2/b-colvis-1.2.2/b-flash-1.2.2/b-html5-1.2.2/b-print-1.2.2/cr-1.3.2/fc-3.2.2/fh-3.1.2/kt-2.1.3/r-2.1.0/rr-1.1.2/sc-1.4.2/se-1.2.0/datatables.min.js"></script>
    <script language="javascript" type="text/javascript" src="https://code.jquery.com/jquery-3.7.0.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/1.13.7/js/dataTables.bootstrap.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.bootstrap.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.print.min.js" type="text/javascript" ></script>		
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.colVis.min.js" type="text/javascript" ></script>
<script type="text/javascript" >

        
    $("#dataTables").dataTable().fnDestroy();
    $('#dataTables').dataTable( {
    dom: 'Bfrtip',
    buttons: [
        {
            extend: 'copy',
            filename: 'Reporte_Estadistico_copy_' + obtenerFecha(),
            customize: function(win) {
                if (window.confirm('Deseas copiar al portapapeles la informacion para llevarla a un archivo?')) {
                    return true;
                } else {
                    return false;
                }
            }
        },
        {
            extend: 'csv',
            filename: 'Reporte_Estadistico_csv_' + obtenerFecha(),
            customize: function(win) {
                if (window.confirm('¿Desea descargar el archivo estadistico en formato CSV?')) {
                    return true;
                } else {
                    return false;
                }
            }
        },
        {
            extend: 'excel',
            filename: 'Reporte_Estadistico_excel_' + obtenerFecha(),
            customize: function(win) {
                if (window.confirm('¿Desea descargar el archivo estadistico en formato Excel?')) {
                    return true;
                } else {
                    return false;
                }
            }
        },
        {
            extend: 'print',
            filename: 'Reporte_Estadistico_print_' + obtenerFecha(),
            customize: function(win) {
                if (window.confirm('¿Desea imprimir el archivo, recuerda que se ajustara a una sola hoja elcual te brindara la informacion a escala de 45%?')) {
                    // Establecer la escala de impresión al 45%
                    $(win.document.body).find('table').css('transform', 'scale(0.45)');
                    $(win.document.body).find('table').css('transform-origin', 'top center');
                    return true;
                } else {
                    return false;
                }
            }
        }
    ]
} );

function obtenerFecha() {
    var fecha = new Date();
    return fecha.toLocaleDateString().replace(/\//g, '_');
}


  /*  $('#dataTables').dataTable( {
    dom: 'Bfrtip',
    buttons: [
        {
            extend: 'copy',
            filename: 'Reporte_Estadistico_copy_' + obtenerFecha(),
        },
        {
            extend: 'csv',
            filename: 'Reporte_Estadistico_csv_' + obtenerFecha(),
        },
        {
            extend: 'excel',
            filename: 'Reporte_Estadistico_excel_' + obtenerFecha(),
        },
        {
            extend: 'print',
            filename: 'Reporte_Estadistico_print_' + obtenerFecha(),
        }
    ]
} );

function obtenerFecha() {
    var fecha = new Date();
    return fecha.toLocaleDateString().replace(/\//g, '_'); // Reemplaza las barras (/) con guiones bajos (_)
}*/

 /*$('#dataTables').dataTable( 
        {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'print'
        ]
} );*/
</script>    
<script>
    // $('#categorias').dataTable().destroy();
    $('#dataTables').dataTable().destroy();
    $('#dataTables').dataTable( {
        "drawCallback": function( settings ) {
             $('ul.pagination').addClass("pagination-sm");
        }

    });
	</script>


</html>
