<!DOCTYPE html>









<html lang="en" class="fa-events-icons-ready"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?php

$bodega=$_POST["bodega"];
include("datosimpresion.php");

?> 

<?php
use PhpParser\Node\Expr\Isset_;

$idc=$_POST["idc"];
$nombrec=$_POST["nombrec"];
$direc=$_POST["direc"];
$nombrev=$_POST["nombrev"];
$fecha=$_POST["fecha"];
$factura=$_POST["numf"];
$devol=$_POST["devol"];
if(isset($_POST["reimpreDv"])){
   $reimpreDv=$_POST["reimpreDv"];
}else{
   $reimpreDv=0;
}


$todev=0;



// $correo=$_POST["correo"];
// $detalleFa=$_POST["detallef"];
// $tipofactura=$_POST["tipofactura"];
// $descuento=$_POST["descuento"];
// $regimen=$_POST["regimen"];
// $telclien=$_POST["telcli"];







?>
   
   <link href="facturacion/fact/bootstrap.min.css" rel="stylesheet">
    
    <link href="facturacion/fact/style.css" rel="stylesheet">


      <style>
        /* Custom styles for better presentation */
        body {
            font-family: Arial, sans-serif;
            padding: 20px; /* Add some padding around the entire document */
        }
        #logo {
            max-width: 150px; /* Adjust logo size as needed */
            height: auto;
        }
        .table-bordered th,
        .table-bordered td {
            border: 1px solid #dee2e6; /* Ensure borders are visible */
            padding: 8px; /* Add some padding to table cells */
            vertical-align: top;
        }
        .table-bordered thead th {
            background-color: #f8f9fa; /* Light background for table header */
            border-bottom-width: 2px;
        }
        .header-info address {
            margin-bottom: 0; /* Remove extra margin from address */
        }
        .client-info address {
            margin-bottom: 0;
        }
    </style>

   </head>
   <body class="" id="cuerpo" data-new-gr-c-s-check-loaded="" data-gr-ext-installed=""   >
      
         <!-- Container --> 
         <!--  container-fluid Billig-container -->
         <div class=" shadow-sm">
            <!-- Header -->
            <header>
               <div class="row align-items-center ">

               <?php
   if($logo!=""){
      echo(" 
      <div class='col-4 '>
      <img id='logo'  src='facturacion/$logo'.jpg' title='Billig' alt='Billig'>
   </div>

     
      ");

   }
   ?>
                  

                  <div class="col-4 order-sm-0  ">
                     
                     <strong><?php print($nombreNegocio); ?></strong>
                     <address>
                     <?php print($representante ); ?><br>
                     <?php print($nit ); ?><br>
                      <?php print($tel); ?>
                      <?php print($direccion); ?>
                     </address>
                  </div>

                  <div class="col-4 text-end ">
                     <h4 class="mb-0 text-uppercase">DEVOLUCION  </h4>
                     <h5 class="mb-0"><strong>No: <?php print($devol); ?></strong></h5>
                     <p class="mb-0"><strong>Fecha:</strong> <?php print($fecha); ?></p>
                     <p class="mb-0"><strong>Asesor:</strong> <?php print($nombrev); ?></p>
                     <p class="mb-0"><strong>Factura:</strong> <?php print($factura); ?></p>
                     
                  </div>
               </div>
               


              
              
            </header>
            _______________________________________________________________________________________________________________________
            <!-- Main Content -->
            <main>
             

            

               <div class="row">
              
                  <div class="col-12 order-sm-0">
                      
                     <div class="row ">
                        <div class="col  " >
                        CLIENTE: <strong> <?php print( $idc."  ". $nombrec ); ?><br></strong>
                        
                           <address>
                           Direccion: <strong> <?php print($direc ); ?><br></strong> 
                        
                           <!-- Telefono:  <strong> ?><br></strong> -->
                          <!-- Correo: <strong>  ?></strong> -->
                           </address>

                        </div>

                        <div class="col ">

                        <!-- <address><strong>Comentario :</strong></address>  -->

                     </div>
                     
 



</div>
                  </div>


                        <?php
                              if(isset($_POST["Datos"])){
                                 $total=$_POST["total"];       
                              }else{
                                 $produc=$_POST["factura"];
                                 $fila = json_decode($produc,true);  
                                 $total=$_POST["total"];
                              }
                        ?>



               </div>
            
               
           
              
           
               <div class="card" >
                  <div class="card-body p-0">
                     <div class="">
                        <table class="table-bordered " id="tablap" >
                           <thead>
                           <tr>
                     

                              <td class="col-1 border-1"><strong>Codigo</strong></td>
                              <td class="col-7 border-1"><strong>Nombre</strong></td>
                              <td class="col-1 border-1"><strong>V.Antes.Iva</strong></td>
                              <td class="col-1 border-1 text-"><strong>Caja</strong></td>
                              <td class="col-1  border-1"><strong>Frcc</strong></td>
                              <td class="col-1  border-1"><strong>Base</strong></td>
                              <td class="col-1 border-1"><strong>iva</strong></td>
                              <td class="col-1 border-1"><strong>tipo.Iva</strong></td>
                              <td class="col-1  border-1"><strong>Descu</strong></td>
                              <td class="col-1 border-1"><strong>Total</strong></td>
                           </tr>
                        </thead>
                           <tbody>
                        
                           <?php


      if(isset($_POST["Datos"])){
                 $valor=json_decode($_POST["Datos"],true);
                  $codigo=$valor["codigo"];
                  $nombre=$valor["nombre"];
                  $caja=$valor["caja"];
                  $frcc=$valor["frcc"];
                  $valot=($precio=$valor["precio"]);
                  $tipoiva=$valor["tipo"];
                  $Base=($valor["base"]);
                  $iva=number_format($valor["iva"]);
                  $Descu=0;
                  
                            


                  if(!is_numeric($frcc)){
                     $frcc=0;
                     }
                     if(!is_numeric($caja)){
                        $caja=0;
                     }
                  
                  
                  if($Base==0){
                     
                  if($frcc==0 and $caja>0){
                     $totalunida=$valot/$caja;
                  }elseif($frcc>0 and $caja==0){
                     $totalunida=$valot/$frcc;

                  }elseif($frcc>0 and $caja>0){

                     $totalunida=($valot/$caja);
                     


                  }   
                     
                  }else{
               
                  if($frcc==0 and $caja>0){
                     $totalunida=$Base/$caja;
                  }elseif($frcc>0 and $caja==0){
                     $totalunida=$Base/$frcc;

                  }elseif($frcc>0 and $caja>0){

                     $totalunida=($Base/$caja);
                     


                  }
                  
                  }
                  $Base=number_format($Base);
               $valot =number_format($valot);
               $totalunida=number_format($totalunida);
            
             echo("
             <tr>  
             
             <td class='col-1'>$codigo 
             <td class='col-7 border-1'>$nombre 
             <td class='col-1'>$totalunida 
             <td class='col-1'>$caja
             <td class='col-1'>$frcc
             <td class='col-1'>$Base
             <td class='col-1'>$iva
             <td class='col-1'>$tipoiva
             <td class='col-1'>$Descu
             <td class='col-1'>$valot
             </tr>
             ");
             
  

         
         }else{
               foreach($fila as $valor) {
                  $codigo=$valor["Codigo"];
                  $nombre=$valor["Nombre"];
                  $caja=$valor["Cantida_caja"];
                  $frcc=$valor["Cantida_frcc"];
                  $valot=($precio=$valor["precio"]);
                  $tipoiva=$valor["tipo"];
                  $Base=($valor["Base"]);
                  $iva=number_format($valor["iva"]);
                  $Descu=number_format($valor["Descu"]);
                  
                            


                  if(!is_numeric($frcc)){
                     $frcc=0;
                     }
                     if(!is_numeric($caja)){
                        $caja=0;
                     }
                  
                  
                  if($Base==0){
                     
                  if($frcc==0 and $caja>0){
                     $totalunida=$valot/$caja;
                  }elseif($frcc>0 and $caja==0){
                     $totalunida=$valot/$frcc;

                  }elseif($frcc>0 and $caja>0){

                     $totalunida=($valot/$caja);
                     


                  }   
                     
                  }else{
               
                  if($frcc==0 and $caja>0){
                     $totalunida=$Base/$caja;
                  }elseif($frcc>0 and $caja==0){
                     $totalunida=$Base/$frcc;

                  }elseif($frcc>0 and $caja>0){

                     $totalunida=($Base/$caja);
                     


                  }
                  
                  }
                  $Base=number_format($Base);
               $valot =number_format($valot);
               $totalunida=number_format($totalunida);

                       


               if($valor["devolucionEstado"]==0 || $reimpreDv==1){
         echo("
               <tr>  
               
               <td class='col-1'>$codigo 
               <td class='col-7 border-1'>$nombre 
               <td class='col-1'>$totalunida 
               <td class='col-1'>$caja
               <td class='col-1'>$frcc
               <td class='col-1'>$Base
               <td class='col-1'>$iva
               <td class='col-1'>$tipoiva
               <td class='col-1'>$Descu
               <td class='col-1'>$valot
               </tr>
               ");
               }else{
              
                  $todev=$todev+$valor["precio"];
               
               }
            }
     		
         }




?>





                            






                              <!-- <tr>
                                 <td colspan="9" class="bg-light-2 text-end"><strong>Sub Total:</strong></td>
                                
                              </tr> -->
                              <?php
                              // if($regimen==1){
                              //    echo("
                              //    <tr>
                              //    <td colspan='9' class='bg-light-2 text-end'><strong>Iva</strong></td>
                              //    <td class='bg-light-2 text-end'> <strong> ". number_format($totaliva) ."</strong> </td>
                              // </tr>
                              //    ");
                              // }

                              ?>
                             
                              
                       
                              <tr>
                                 
                             
                                <td colspan="<?php echo($col2); ?>" class="bg-light-2 text-end border-0"><strong>Total:</strong></td>
                                 <td class="bg-light-2 text-end border-0"><strong><?php echo(number_format($total-$todev)); ?></strong></td>
                                 

                              </tr>
                           
                           </tbody>
                        </table>




            <div class="col-7 d-flex">
        

            </div>
 </div>

                     </div>
                  </div>
               </div>
            </main>
            <!-- Footer -->
            <footer class="text-center mt-4">
              
   

               <!-- <p class="text-1"><strong>NOTA :</strong> </p> -->
               
            </footer>
         </div>
        
   
         <script type='text/javascript'>


function imprimir(){
    window.print()
   //  
     let navegador = navigator.userAgent;
     if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) {
     
        } else{
         setTimeout(window.close, 300);
        }
 

    }

    setTimeout(imprimir,300);




 
</script>
   
</body></html>