<?php 
    session_start();
    include('../../validadores/validarSession.php');
    include('../StoGlobal/include/conexion.php');
    include('../StoGlobal/include/conexion1.php');
    include('../StoGlobal/include/conexion3.php');
    error_reporting(0);
?>

<!DOCTYPE html>
<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.0">

    <link rel="shortcut icon" href="../../img/LogoBG.png">
    <title>StoGlobal - DTE</title>
    
    <!-- CSS -->
        <!-- Css - NavBar Boostrap 5 -->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">

        <!-- Css - Body -->
        <link rel="stylesheet" href="../../styles/principal.css" type="text/css">

        <!-- Css - DataTable  -->
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.css"/>  

        <!-- Css - extension responsive DataTable  -->
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.2.3/css/responsive.dataTables.min.css">

        <!-- Css - DataTable -->
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.13.1/datatables.min.css"/>
        
        <style>
            table thead{
                background-color: #fff;        
            }
        
        </style>
    <!-- FIN CSS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/js/all.min.js" crossorigin="anonymous"></script>
</head>
<body>
    <?php
        include('../../NavBar.php');
    ?>

    <div class="cssContainer mt-5">
        <div class="mb-3 pt-5" style="text-align:center;">
            <h2>DTE - StoGlobal - Año <?php $fechasa=date("Y"); echo $fechasa;?></h2>
        </div>
        <div class="row" >
            <div class="col-lg-1 3" style="margin:auto;width:98%;background-color:#fff;padding: 8px">
                <table id="Tablas" class="table table-bordered  display nowrap" cellspacing="0" width="100%" >
                    <thead>
                        <tr>
                            <th>N°</th>
                            <th>Año</th>
                            <th>Mes</th>
                            <th>Compras Neto</th>
                            <th>Compras Excentas</th>
                            <th>Compras Nta Crédito</th>
                            <th>Ventas Netas</th>
                            <th>Ventas Boletas</th>
                            <th>Ventas Nta Crédito</th>                                 
                            <th>Honorarios</th>
                            <th>PPM</th>
                            <th>IVA</th>
                            <th>Ver Detalle</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 

                            date_default_timezone_set('America/Santiago');
                            $fecha=date("Y-m-d");


                            date_default_timezone_set('America/Santiago');
                            $ano=date("Y");

                            $meses = array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");

                            $fecha22=date("m");


                        $balance_compras_netas=0;
                        $balance_excentas_netas=0;
                        $balance_ntacred_netas=0;
                    
                        $balance_ventas_netas=0;
                        $balance_ventas_boletas_netas=0;
                        $balance_ntadeb_netas=0;
                        $balance_honorio_neto=0;
                        $balance_hono_retencion=0;

                        $iva_pagado=0;
                        $ppm_pagado=0;

                        for ($i = 1; $i <= $fecha22; $i++) {
                        ?>
                        
                            <tr>
                                <td class="center"><?php echo $i; ?></td>   
                                <td><?php echo $ano; ?></td>
                                <td><?php echo $meses[$i-1];?></td>
                                <td>
                                    <!-- Compras Netas 1 -->
                                    <?php  

                                        $query = "select COUNT(id_dte_compra) AS 'Count_proyectos12', id_dte_compra from sto_dte_compra where comp_tipo_documento='33' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'";
                                        $stmt12 = $DBcon->prepare( $query );
                                        $stmt12->execute();

                                        if($stmt12->rowCount() > 0) {
                                            while($row12=$stmt12->fetch(PDO::FETCH_ASSOC)) {
                                                extract($row12);
                                                
                                                if($Count_proyectos12==0){
                                                    // echo "None";
                                                }else{
                                                    $Cantidad_proyectoss=$Count_proyectos12;    

                                    ?>
                                                    <a href="javascript:popUp('detalle_docs.php?id_detalle=1&mes=<?php echo $i;?>')"><?php echo "(".$Cantidad_proyectoss.")"; ?></a>
                                    <?php
                                                }                                                
                                            }
                                        }

                                         $sqlBencina=mysqli_query($con,"select SUM(comp_neto) as comp_neto from sto_dte_compra where comp_tipo_documento='33' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                         while($row7=mysqli_fetch_array($sqlBencina))
                                         { 
                                             $ValorTotalHerramientas=$row7['comp_neto'];  
                                             echo " $";echo number_format($ValorTotalHerramientas,0,",",".");
                                            $balance_compras_netas=$balance_compras_netas+$ValorTotalHerramientas;
                                         }
                                    ?>
                                </td>
                                <td>
                                    <!-- Compras Excentas 2 -->
                                    <?php  

                                        $query = "select COUNT(id_dte_compra) AS 'Count_proyectos12', id_dte_compra from sto_dte_compra where comp_tipo_documento='34' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'";
                                        $stmt12 = $DBcon->prepare( $query );
                                        $stmt12->execute();

                                        if($stmt12->rowCount() > 0) {
                                            while($row12=$stmt12->fetch(PDO::FETCH_ASSOC)) {
                                                extract($row12);
                                                
                                                if($Count_proyectos12==0){
                                                    // echo "None";
                                                }else{
                                                    $Cantidad_proyectoss=$Count_proyectos12;    

                                    ?>
                                                    <a href="javascript:popUp('detalle_docs.php?id_detalle=2&mes=<?php echo $i;?>')"><?php echo "(".$Cantidad_proyectoss.")"; ?></a>
                                    <?php
                                                    

                                                }                                                
                                            }
                                        }

                                         $sqlBencina=mysqli_query($con,"select SUM(comp_neto) as comp_neto from sto_dte_compra where comp_tipo_documento='34' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                         while($row7=mysqli_fetch_array($sqlBencina))
                                         { 
                                             $ValorTotalHerramientas=$row7['comp_neto'];  
                                             echo " $";echo number_format($ValorTotalHerramientas,0,",",".");
                                             $balance_excentas_netas=$balance_excentas_netas+$ValorTotalHerramientas;
                                         }
                                    ?>
                                </td>

                                <td>
                                    <!-- Compras Nta Créditos 3 -->
                                    <?php  

                                        $query = "select COUNT(id_dte_compra) AS 'Count_proyectos12', id_dte_compra from sto_dte_compra where comp_tipo_documento='61' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'";
                                        $stmt12 = $DBcon->prepare( $query );
                                        $stmt12->execute();

                                        if($stmt12->rowCount() > 0) {
                                            while($row12=$stmt12->fetch(PDO::FETCH_ASSOC)) {
                                                extract($row12);
                                                
                                                if($Count_proyectos12==0){
                                                    // echo "None";
                                                }else{
                                                    $Cantidad_proyectoss=$Count_proyectos12;    

                                    ?>
                                                    <a href="javascript:popUp('detalle_docs.php?id_detalle=3&mes=<?php echo $i;?>')"><?php echo "(".$Cantidad_proyectoss.")"; ?></a>
                                    <?php
                                                }                                                
                                            }
                                        }

                                         $sqlBencina=mysqli_query($con,"select SUM(comp_neto) as comp_neto from sto_dte_compra where comp_tipo_documento='61' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                         while($row7=mysqli_fetch_array($sqlBencina))
                                         { 
                                             $ValorTotalHerramientas=$row7['comp_neto'];  
                                             echo " $";echo number_format($ValorTotalHerramientas,0,",",".");
                                             $balance_ntacred_netas=$balance_ntacred_netas+$ValorTotalHerramientas;
                                         }
                                    ?>
                                </td>

                                <!-- Ventas Netas 4 -->
                                <td>
                                    <?php  

                                        $query = "select COUNT(id_dte_venta) AS 'Count_proyectos12', id_dte_venta from sto_dte_venta where vent_tipo_documento='33' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'";
                                        $stmt12 = $DBcon->prepare( $query );
                                        $stmt12->execute();

                                        if($stmt12->rowCount() > 0) {
                                            while($row12=$stmt12->fetch(PDO::FETCH_ASSOC)) {
                                                extract($row12);
                                                
                                                if($Count_proyectos12==0){
                                                    // echo "None";
                                                }else{
                                                    $Cantidad_proyectoss=$Count_proyectos12;    
                                    ?>
                                                    <a href="javascript:popUp('detalle_docs.php?id_detalle=4&mes=<?php echo $i;?>')"><?php echo "(".$Cantidad_proyectoss.")"; ?></a>
                                    <?php
                                                }                                                
                                            }
                                        }

                                         $sqlBencina=mysqli_query($con,"select SUM(vent_neto) as vent_neto from sto_dte_venta where vent_tipo_documento='33' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                         while($row7=mysqli_fetch_array($sqlBencina))
                                         { 
                                             $ValorTotalHerramientas1=$row7['vent_neto'];  
                                             echo " $";echo number_format($ValorTotalHerramientas1,0,",",".");
                                             $balance_ventas_netas=$balance_ventas_netas+$ValorTotalHerramientas1;
                                         }
                                         
                                    ?>
                                </td>

                                <!-- Ventas Netas Boletas -->
                                <td>
                                    <?php  

                                        $query = "select COUNT(id_dte_venta) AS 'Count_proyectos12', id_dte_venta from sto_dte_venta where vent_tipo_documento='39' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'";
                                        $stmt12 = $DBcon->prepare( $query );
                                        $stmt12->execute();

                                        if($stmt12->rowCount() > 0) {
                                            while($row12=$stmt12->fetch(PDO::FETCH_ASSOC)) {
                                                extract($row12);
                                                
                                                if($Count_proyectos12==0){
                                                    // echo "None";
                                                }else{
                                                    $Cantidad_proyectoss=$Count_proyectos12;    
                                    ?>
                                                    <a href="javascript:popUp('detalle_docs.php?id_detalle=8&mes=<?php echo $i;?>')"><?php echo "(".$Cantidad_proyectoss.")"; ?></a>
                                    <?php
                                                }                                                
                                            }
                                        }

                                         $sqlBencina=mysqli_query($con,"select SUM(vent_neto) as vent_neto from sto_dte_venta where vent_tipo_documento='39' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                         while($row7=mysqli_fetch_array($sqlBencina))
                                         { 
                                             $ValorTotalHerramientas1=$row7['vent_neto'];  
                                             echo " $";echo number_format($ValorTotalHerramientas1,0,",",".");
                                             $balance_ventas_boletas_netas=$balance_ventas_boletas_netas+$ValorTotalHerramientas1;
                                         }
                                         
                                    ?>
                                </td>

                                <!-- Ventas Nta Débito 5   -->
                                <td>
                                    <?php  

                                        $query = "select COUNT(id_dte_venta) AS 'Count_proyectos12', id_dte_venta from sto_dte_venta where vent_tipo_documento='61' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'";
                                        $stmt12 = $DBcon->prepare( $query );
                                        $stmt12->execute();

                                        if($stmt12->rowCount() > 0) {
                                            while($row12=$stmt12->fetch(PDO::FETCH_ASSOC)) {
                                                extract($row12);
                                                
                                                if($Count_proyectos12==0){
                                                    // echo "None";
                                                }else{
                                                    $Cantidad_proyectoss=$Count_proyectos12;    
                                    ?>
                                                    <a href="javascript:popUp('detalle_docs.php?id_detalle=5&mes=<?php echo $i;?>')"><?php echo "(".$Cantidad_proyectoss.")"; ?></a>
                                    <?php
                                                    
                                                }                                                
                                            }
                                        }

                                         $sqlBencina=mysqli_query($con,"select SUM(vent_neto) as vent_neto from sto_dte_venta where vent_tipo_documento='61' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                         while($row7=mysqli_fetch_array($sqlBencina))
                                         { 
                                             $ValorTotalHerramientas=$row7['vent_neto'];  
                                             echo " $";echo number_format($ValorTotalHerramientas,0,",",".");
                                             $balance_ntadeb_netas=$balance_ntadeb_netas+$ValorTotalHerramientas;
                                         }
                                    ?>
                                </td>

                                <!-- Honorarios 6 -->
                                <td>
                                    <?php  

                                    $query = "select COUNT(id_hono) AS 'Count_proyectos12', id_hono from sto_dte_honorarios where hono_fecha BETWEEN '2024-$i-01' and '2024-$i-31'";
                                    $stmt12 = $DBcon->prepare( $query );
                                    $stmt12->execute();

                                    if($stmt12->rowCount() > 0) {
                                        while($row12=$stmt12->fetch(PDO::FETCH_ASSOC)) {
                                            extract($row12);
                                            
                                            if($Count_proyectos12==0){
                                                // echo "None";
                                            }else{
                                                $Cantidad_proyectoss=$Count_proyectos12;    
                                    ?>
                                                <a href="javascript:popUp('detalle_docs.php?id_detalle=6&mes=<?php echo $i;?>')"><?php echo "(".$Cantidad_proyectoss.")"; ?></a>
                                    <?php
                                                
                                            }                                                
                                        }
                                    }

                                    $sqlBencina=mysqli_query($con,"select SUM(hono_neto) as hono_neto from sto_dte_honorarios where hono_fecha BETWEEN '2024-$i-01' and '2024-$i-31'");
                                    while($row7=mysqli_fetch_array($sqlBencina))
                                    { 
                                        $ValorTotalHerramientas=$row7['hono_neto'];  
                                        echo " $";echo number_format($ValorTotalHerramientas,0,",",".");
                                        $balance_honorio_neto=$balance_honorio_neto+$ValorTotalHerramientas;
                                    }
    
                                    ?>
                                </td>

                                <!-- PPM 7 -->
                                <td>
                                    <?php  
                                        $ppm_monto=0;

                                            if($i<=9){
                                                $query = "select * from sto_dte_ppm where ppm_fecha='2024-0$i'";
                                                $stmt1 = $DBcon->prepare( $query );
                                                $stmt1->execute();
                                                
                                                if($stmt1->rowCount() > 0) {
                                                    while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
                                                        extract($row);
        
                                                        echo "$";echo number_format($ppm_monto,0,",",".");
                                                    } 
                                                }
                                            }

                                            if($i>=10){
                                                $query = "select * from sto_dte_ppm where ppm_fecha='2024-$i'";
                                                $stmt1 = $DBcon->prepare( $query );
                                                $stmt1->execute();
                                                
                                                if($stmt1->rowCount() > 0) {
                                                    while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
                                                        extract($row);
        
                                                        echo "$";echo number_format($ppm_monto,0,",",".");
                                                    } 
                                                }
                                            }

                                        $ppm_pagado=$ppm_pagado+$ppm_monto;
                                    ?>
                                </td>

                                <!-- Pago IVA 8 -->
                                <td>
                                    <?php 

                                        //   IVA Compras
                                        $sqlBencina=mysqli_query($con,"select SUM(comp_iva) as comp_iva from sto_dte_compra where comp_tipo_documento='33' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                        while($row7=mysqli_fetch_array($sqlBencina))
                                        { 
                                            $IVACompra=$row7['comp_iva'];  
                                        }
                                        // IVA Compras - Nta Crédito
                                        $sqlBencina=mysqli_query($con,"select SUM(comp_iva) as comp_iva from sto_dte_compra where comp_tipo_documento='61' and comp_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                        while($row7=mysqli_fetch_array($sqlBencina))
                                        { 
                                            $IVACompra_NtaCred=-$row7['comp_iva'];  
                                        }

                                        //  IVA Ventas
                                        $sqlBencina=mysqli_query($con,"select SUM(vent_iva) as vent_iva from sto_dte_venta where vent_tipo_documento='33' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                        while($row7=mysqli_fetch_array($sqlBencina))
                                        { 
                                            $IVAVenta=-$row7['vent_iva'];  
                                        }

                                        //  IVA Ventas en Boletas
                                        $sqlBencina=mysqli_query($con,"select SUM(vent_iva) as vent_iva from sto_dte_venta where vent_tipo_documento='39' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                        while($row7=mysqli_fetch_array($sqlBencina))
                                        { 
                                            $IVAVenta_boletas=-$row7['vent_iva'];  
                                        }

                                        //  IVA Nta Debito
                                        $sqlBencina=mysqli_query($con,"select SUM(vent_iva) as vent_iva from sto_dte_venta where vent_tipo_documento='61' and vent_fecha_recepcion BETWEEN '2024-$i-01' and '2024-$i-31'");
                                        while($row7=mysqli_fetch_array($sqlBencina))
                                        { 
                                            $IVAVenta_NtaDeb=-$row7['vent_iva'];  
                                        }


                                        // Suma monto Honorarios
                                        $sqlBencina=mysqli_query($con,"select SUM(hono_retencion) as hono_retencion from sto_dte_honorarios where hono_fecha BETWEEN '2024-$i-01' and '2024-$i-31'");
                                        while($row7=mysqli_fetch_array($sqlBencina))
                                        { 
                                            $imp_hono_retencion=-$row7['hono_retencion'];
                                            $balance_hono_retencion=$balance_hono_retencion+$imp_hono_retencion;  
                                        }

                                        // Suma monto PPM
                                        if($i<=9){
                                            $query = "select * from sto_dte_ppm where ppm_fecha='2024-0$i'";
                                            $stmt1 = $DBcon->prepare( $query );
                                            $stmt1->execute();
                                            
                                            if($stmt1->rowCount() > 0) {
                                                while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
                                                    extract($row);
    
                                                    $ppm_mes=-$ppm_monto;
                                                } 
                                            }
                                        }

                                        if($i>=10){
                                            $query = "select * from sto_dte_ppm where ppm_fecha='2024-$i'";
                                            $stmt1 = $DBcon->prepare( $query );
                                            $stmt1->execute();
                                            
                                            if($stmt1->rowCount() > 0) {
                                                while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
                                                    extract($row);
    
                                                    $ppm_mes=-$ppm_monto;
                                                } 
                                            }
                                        }


                                        $total_iva=$IVACompra+$IVAVenta+$IVACompra_NtaCred+$imp_hono_retencion+$ppm_mes+$IVAVenta_NtaDeb+$IVAVenta_boletas;
                                          
                                        $iva_pagado=$iva_pagado+$total_iva;
                                    ?>  
                                    <a href="javascript:popUp('detalle_docs.php?id_detalle=7&mes=<?php echo $i;?>')"><?php echo " $";echo number_format($total_iva,0,",","."); ?></a>

                                </td>
                                
                                <td>
                                    <a href="index1.php?idCliente=<?php  ?>">
                                        <svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 576 512"><path d="M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4C142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32zM144 256a144 144 0 1 1 288 0 144 144 0 1 1 -288 0zm144-64c0 35.3-28.7 64-64 64c-7.1 0-13.9-1.2-20.3-3.3c-5.5-1.8-11.9 1.6-11.7 7.4c.3 6.9 1.3 13.8 3.2 20.7c13.7 51.2 66.4 81.6 117.6 67.9s81.6-66.4 67.9-117.6c-11.1-41.5-47.8-69.4-88.6-71.1c-5.8-.2-9.2 6.1-7.4 11.7c2.1 6.4 3.3 13.2 3.3 20.3z"/></svg>
                                    </a>    
                                </td>
                            </tr>

                        <?php 
                            $ppm_mes=0;
                        }
                        ?>
                    </tbody>
                </table>  
            </div>
        </div> 

        <a href="javascript:popUp('index1.php?año=2023')">2023</a>
    </div>

        <div class="w-100" >
            <div class="container display:flex " style="padding-top:60px; max-width:90%; max-height:100%;">

                <div class="row w-100 mt-1 text-center">
                    

                    <div class="col-md-3 w-50 p-2 ShowUp" >
                        <div class="card text-whitebg-gradient"  >
                            <div class="card-header fs-6 ">Resumen Costos</div>
                            <div class="card-body d-flex">


                                <div class="card text-white bg-warning bg-gradient w-50 m-1" >
                                    <div class="card-header fs-6 text-dark fw-bolder">Tot_Comporas Netas<?php echo $balance_ntacred_netas;?></div>
                                    <div class="card-body">
                                        <h5 class="card-title fw-normal">
                                            <?php 
                                            // $fecha22=date("m");
                                            //     $sqlBencina=mysqli_query($con,"select SUM(comp_neto) as comp_neto from sto_dte_compra where comp_tipo_documento='33' and comp_fecha_recepcion BETWEEN '2024-01-01' and '2024-$fecha22-31'");
                                            //     while($row7=mysqli_fetch_array($sqlBencina))
                                            //     { 
                                            //         $tot_compras=$row7['comp_neto'];  
                                            //         echo " $";echo number_format($tot_compras,0,",",".");
                                            //     }
                                                $tot_compras=$balance_compras_netas+$balance_excentas_netas+$balance_honorio_neto-$balance_hono_retencion-$balance_ntacred_netas;
                                                echo " $";echo number_format($tot_compras,0,",",".");
                                            ?>    
                                        </h5>
                                    
                                    </div>
                                </div>

                                <div class="card text-white bg-warning bg-gradient w-50 m-1" >
                                    <div class="card-header fs-6 text-dark fw-bolder">Tot_Ventas Netas</div>
                                    <div class="card-body">
                                        <h5 class="card-title fw-normal">
                                            <?php 
                                                
                                                    // $sqlBencina=mysqli_query($con,"select SUM(vent_neto) as vent_neto from sto_dte_venta where vent_tipo_documento='33' and vent_fecha_recepcion BETWEEN '2024-01-01' and '2024-$fecha22-31'");
                                                    // while($row7=mysqli_fetch_array($sqlBencina))
                                                    // { 
                                                    //     $tot_ventas=$row7['vent_neto'];  
                                                    //     echo " $";echo number_format($tot_ventas,0,",",".");
                                                    // }
                                                    $tot_ventas=$balance_ventas_netas-$balance_ntadeb_netas+$balance_ventas_boletas_netas;
                                                    echo " $";echo number_format($tot_ventas,0,",",".");
                                            ?>
                                        </h5>
                                    
                                    </div>
                                </div>
                                

                                <div class="card text-white bg-danger bg-gradient  w-50 m-1"  >
                                    <div class="card-header fs-6 text-dark fw-bolder text-dark fw-bolder"> Utilidad Neta</div>
                                    <div class="card-body">
                                        <h5 class="card-title fw-normal">
                                                    <?php 
                                                    $TotalUtilidad=$tot_ventas-$tot_compras;

                                                    function porcentaje($tot_ventas, $tot_compras, $redondear = 2) {
                                                        return round($tot_compras / $tot_ventas * 100, $redondear);
                                                    }
                                                    $n2 = $tot_ventas;
                                                    $n1 = $tot_compras;
                                                    
                                                     
                                                    $total = $n2+$n1;
                                                    $Resultado=100-porcentaje($total, $n2, 2);
                                                    echo " $";echo number_format($TotalUtilidad,0,",",".")." / ".$Resultado.'%';

                                                    ?>

                                        
                                        </h5>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>

                    <div class="col-md-3 w-50 m-auto p-2 ShowUp " >
                        <div class="card text-black "  >
                            <div class="card-header w-100 d-flex">
                                <div class="fs-6  w-100">Impuestos
                                </div>
                            <div>
                           
                            </div>
                            </div>
                            
                            <div class="card-body d-flex ">

                                <div class="card text-white bg-success bg-gradient w-50 m-1" >
                                    <div class="card-header fs-6 text-dark fw-bolder">IVA pagado</div>
                                    <div class="card-body">
                                        <h5 class="card-title fw-normal">
                                                    <?php
                                                        echo " $";echo number_format($iva_pagado,0,",",".");
                                                    
                                                    // $tot_iva_ventas=0;
                                                    // $tot_iva_compras=0;
                                                    // $sqlBencina=mysqli_query($con,"select SUM(vent_iva) as vent_iva from sto_dte_venta where vent_tipo_documento='33' and vent_fecha_recepcion BETWEEN '2024-01-01' and '2024-$fecha22-31'");
                                                    // while($row7=mysqli_fetch_array($sqlBencina))
                                                    // { 
                                                    //     $tot_iva_venta1=$row7['vent_iva'];  
                                                    //     $tot_iva_ventas=$tot_iva_ventas+$tot_iva_venta1;
                                                    // }

                                                    // $sqlBencina=mysqli_query($con,"select SUM(comp_iva) as comp_iva from sto_dte_compra where comp_tipo_documento='33' and comp_fecha_recepcion BETWEEN '2024-01-01' and '2024-$fecha22-31'");
                                                    // while($row7=mysqli_fetch_array($sqlBencina))
                                                    // { 
                                                    //     $tot_iva_compra1=$row7['comp_iva'];  
                                                    //     $tot_iva_compras=$tot_iva_compras+$tot_iva_compra1;
                                                    // }

                                                    // $tot_result_IVA=$tot_iva_compras+$tot_iva_ventas;

                                                    // echo " $";echo number_format($tot_result_IVA,0,",",".");


                                              
                                            ?>
                                        </h5>
                                    
                                    </div>
                                </div>

                                <div class="card text-white bg-success bg-gradient w-50 m-1" >
                                    <div class="card-header fs-6 text-dark fw-bolder">PPM Pagado</div>
                                    <div class="card-body">
                                        <h5 class="card-title fw-normal">
                                            <?php
                                                echo " $";echo number_format($ppm_pagado,0,",",".");
                                            ?>
                                        </h5>
                                    
                                    </div>
                                </div>

                                <div class="card text-white bg-success bg-gradient  w-50 m-1"  >
                                    <div class="card-header fs-6 text-dark fw-bolder">Honorarios Neto</div>
                                    <div class="card-body">
                                        <h5 class="card-title fw-normal">
                                        <?php
                                                echo " $";echo number_format($balance_honorio_neto,0,",",".");
                                            ?>
                                        </h5>
                                    </div>
                                </div>
                                

                            </div>
                            
                        </div>
                    </div>

                    <div class=" row m-auto  w-100 ShowBottom"  >
                        <!-- <div class="col-xl-7 m-auto">
                            <div class="card mb-4">
                                <div class="card-header">
                                <i class="fas fa-chart-area mr-1"></i>
                                Area Chart Example
                                </div>
                                <div class="card-body"><canvas id="myAreaChart" width="100%" height="40"></canvas></div>
                            </div>
                        </div> -->

                        <div class=" col-xl-12 "  >
                            <div class="card mb-4">
                                <div class="card-header">
                                <i class="fas fa-chart-bar mr-1"></i>
                                Balance Mensual
                                </div>
                                <div class="card-body"><canvas id="myBarChart" height="65" ></canvas></div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>



                                        <script type="text/javascript">
                                            function popUp(URL) {
                                                window.open(URL, 'Nombre de la ventana', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=1200,height=700,left = 390,top = 50');
                                            }
                                        </script> 
    <!-- JS -->
        <!-- Js - importante para Funcionalidad DataTable -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>

        <!-- Js -Funcionalidad DataTable-->
        <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.20/datatables.min.js"></script>  
        
        <!-- Js - extension DataTable responsive -->
        <script src="https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js"></script>

        <!-- Js - NavBar -->
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>

        <!-- Js - español DataTable -->
        <script>
            $(document).ready(function() {
                $('#Tablas').DataTable({
                    responsive: true,
                    "language": 
                    {
                        "aria": {
                            "sortAscending": ": orden ascendente",
                            "sortDescending": ": orden descendente"
                        },
                        "autoFill": {
                            "cancel": "Cancelar",
                            "fill": "Llenar todas las celdas con <i>%d&lt;\\\/i&gt;<\/i>",
                            "fillHorizontal": "Llenar celdas horizontalmente",
                            "fillVertical": "Llenar celdas verticalmente"
                        },
                        "buttons": {
                            "collection": "Colección <span class=\"ui-button-icon-primary ui-icon ui-icon-triangle-1-s\"><\/span>",
                            "colvis": "Visibilidad de la columna",
                            "colvisRestore": "Restaurar visibilidad",
                            "copy": "Copiar",
                            "copyKeys": "Presiona ctrl or u2318 + C para copiar los datos de la tabla al portapapeles.<br \/><br \/>Para cancelar, haz click en este mensaje o presiona esc.",
                            "copySuccess": {
                                "_": "Copió %ds registros al portapapeles",
                                "1": "Copió un registro al portapapeles"
                            },
                            "copyTitle": "Copiado al portapapeles",
                            "csv": "CSV",
                            "excel": "Excel",
                            "pageLength": {
                                "_": "Mostrar %ds registros",
                                "-1": "Mostrar todos los registros"
                            },
                            "pdf": "PDF",
                            "print": "Imprimir"
                        },
                        "datetime": {
                            "amPm": [
                                "AM",
                                "PM"
                            ],
                            "hours": "Horas",
                            "minutes": "Minutos",
                            "months": {
                                "0": "Enero",
                                "1": "Febrero",
                                "10": "Noviembre",
                                "11": "Diciembre",
                                "2": "Marzo",
                                "3": "Abril",
                                "4": "Mayo",
                                "5": "Junio",
                                "6": "Julio",
                                "7": "Agosto",
                                "8": "Septiembre",
                                "9": "Octubre"
                            },
                            "next": "Siguiente",
                            "previous": "Anterior",
                            "seconds": "Segundos",
                            "weekdays": [
                                "Dom",
                                "Lun",
                                "Mar",
                                "Mie",
                                "Jue",
                                "Vie",
                                "Sab"
                            ]
                        },
                        "decimal": ",",
                        "editor": {
                            "close": "Cerrar",
                            "create": {
                                "button": "Nuevo",
                                "submit": "Crear",
                                "title": "Crear nuevo registro"
                            },
                            "edit": {
                                "button": "Editar",
                                "submit": "Actualizar",
                                "title": "Editar registro"
                            },
                            "error": {
                                "system": "Ocurrió un error de sistema (&lt;a target=\"\\\" rel=\"nofollow\" href=\"\\\"&gt;Más información)."
                            },
                            "multi": {
                                "info": "Los elementos seleccionados contienen diferentes valores para esta entrada. Para editar y configurar todos los elementos de esta entrada con el mismo valor, haga clic o toque aquí, de lo contrario, conservarán sus valores individuales.",
                                "noMulti": "Esta entrada se puede editar individualmente, pero no como parte de un grupo.",
                                "restore": "Deshacer cambios",
                                "title": "Múltiples valores"
                            },
                            "remove": {
                                "button": "Eliminar",
                                "confirm": {
                                    "_": "¿Está seguro de que desea eliminar %d registros?",
                                    "1": "¿Está seguro de que desea eliminar 1 registro?"
                                },
                                "submit": "Eliminar",
                                "title": "Eliminar registro"
                            }
                        },
                        "emptyTable": "Sin registros",
                        "info": "Mostrando _START_ a _END_ de _TOTAL_ registros",
                        "infoEmpty": "Mostrando 0 a 0 de 0 registros",
                        "infoFiltered": "(filtrado de _MAX_ registros)",
                        "infoThousands": ".",
                        "lengthMenu": "Mostrar _MENU_ registros",
                        "loadingRecords": "Cargando...",
                        "paginate": {
                            "first": "Primero",
                            "last": "Último",
                            "next": "Siguiente",
                            "previous": "Anterior"
                        },
                        "processing": "Procesando...",
                        "search": "Buscar:",
                        "searchBuilder": {
                            "add": "Agregar Condición",
                            "button": {
                                "_": "Filtros (%d)",
                                "0": "Filtrar"
                            },
                            "clearAll": "Limpiar Todo",
                            "condition": "Condición",
                            "conditions": {
                                "array": {
                                    "contains": "Contiene",
                                    "empty": "Vacío",
                                    "equals": "Igual",
                                    "not": "Distinto",
                                    "notEmpty": "No vacío",
                                    "without": "Sin"
                                },
                                "date": {
                                    "after": "Mayor",
                                    "before": "Menor",
                                    "between": "Entre",
                                    "empty": "Vacío",
                                    "equals": "Igual",
                                    "not": "Distinto",
                                    "notBetween": "No entre",
                                    "notEmpty": "No vacío"
                                },
                                "number": {
                                    "between": "Entre",
                                    "empty": "Vacío",
                                    "equals": "Igual",
                                    "gt": "Mayor",
                                    "gte": "Mayor o igual",
                                    "lt": "Menor",
                                    "lte": "Menor o igual",
                                    "not": "Distinto",
                                    "notBetween": "No entre",
                                    "notEmpty": "No vacío"
                                },
                                "string": {
                                    "contains": "Contiene",
                                    "empty": "Vacío",
                                    "endsWith": "Termina con",
                                    "equals": "Igual",
                                    "not": "Distinto",
                                    "notEmpty": "No vacío",
                                    "startsWith": "Comienza con"
                                }
                            },
                            "data": "Datos",
                            "deleteTitle": "Eliminar regla de filtrado",
                            "leftTitle": "Filtros anulados",
                            "logicAnd": "Y",
                            "logicOr": "O",
                            "rightTitle": "Filtro",
                            "title": {
                                "_": "Filtros (%d)",
                                "0": "Filtrar"
                            },
                            "value": "Valor"
                        },
                        "searchPanes": {
                            "clearMessage": "Limpiar todo",
                            "collapse": {
                                "_": "Paneles de búsqueda (%d)",
                                "0": "Paneles de búsqueda"
                            },
                            "count": "{total}",
                            "countFiltered": "{shown} ({total})",
                            "emptyPanes": "Sin paneles de búsqueda",
                            "loadMessage": "Cargando paneles de búsqueda...",
                            "title": "Filtros activos - %d"
                        },
                        "select": {
                            "cells": {
                                "_": "%d celdas seleccionadas",
                                "1": "Una celda seleccionada"
                            },
                            "columns": {
                                "_": "%d columnas seleccionadas",
                                "1": "Una columna seleccionada"
                            },
                            "rows": {
                                "1": "Una fila seleccionada",
                                "_": "%d filas seleccionadas"
                            }
                        },
                        "thousands": ".",
                        "zeroRecords": "No se encontraron registros"
                    }
                    
                });
            } );  
        </script>
    <!-- FIN JS -->
</body>
</html>


