
 <page backcolor="#FEFEFE" backimg="./res/bas_page.png" backimgx="center" backimgy="bottom" backimgw="100%" backtop="0" backbottom="30mm" footer="date;heure;page" style="font-size: 12pt">
    <bookmark title="Lettre" level="0" ></bookmark>
   <!--
    <table cellspacing="0" border="0"   style="width: 95%; text-align: center; font-size: 14px">
    <tr>
    
        <Td valign="top"  style="width: 50%;" align="LEFT">
       
        </Td>
    
     
        <td valign="top"  align="right" style="width: 50%; color: #444444;">

         </td>
    </tr>
        
    </table>
-->

   
    <table cellspacing="0"   style="width: 95%; text-align: center; font-size: 14px">
        <tr>
            <td valign="top"    style="width: 40%;" align="LEFT">
            
             <img src="../../_documentos/28c8edde3d61a0411511d3b1866f0636/c6b20bcb93196b3f5c1913dc92e583d2/empresa/dushi.jpg" style="width:200px" >
            <strong  style="font-weight: bold;font-size:20px;color:grey;"  > <?php   $XML_Hacienda->electronica_nombre  ;   ?></strong>
            <p><b  >DUSHI SALON  </b>  </p>
            
            
 <?php    $XML_Hacienda->electronica_nombre_comercial;  ?><br>          
<?php echo  $XML_Hacienda->direccion_PDF;  ?>   <br>
 Email:&nbsp;&nbsp; <?php echo $XML_Hacienda->electronico_correo; ?>  <br>
Cédula: <?php echo $XML_Hacienda->electronica_identificacion_numero  ; ?> <br>
Teléfono: (506) <?php echo $XML_Hacienda->electronica_telefono; ?>  <br>
             </td>
            <td style="width: 20%;"> </td>
            <td valign="top"  align="right" style="width: 40%; color: #444444;">
            <br><Br>
                       <span style="font-weight: bold;font-size:20px;color:black;"><?php echo  $tipo.' '.$factura->referencia; ?></span>
           <br>
           <strong> Clave <?php echo $XML_Hacienda->documento_consecutivo; ?></strong>
           
           
            <?php if ($factura2->estado==3){ echo "<b style='color:red'>Factura <b><ins> NULA </ins></b>";}  ?>

          
            
            
<?php
 if ($factura->estado==0){$estado='<span class="label label-warning">Borrador</span>';}
   if  ($factura->electronica_enviada==1){ $estado='<span class="label label-success">Enviada </span>';}
      if  ($factura->electronica_resultado==1 and $factura->electronica_error== 1 ){ $estado='<span style="color:red;">Rechazada</span>';}
          if  ($factura->electronica_resultado==1 and $factura->electronica_error== 0  ){ $estado='<span class="label label-success">Aceptada</span>';}
                if ($factura->estado==1 and $factura->electronica_enviada==0) {  $estado='<span class="label label-success">Enviando ...</span>';}
                
                
     ?>       
            <br>
            <?php 
            echo "Fecha            :". date('d-m-Y',strtotime($factura->fecha))."<br>";
            echo "Fecha Vencimiento:". date('d-m-Y',strtotime($factura->fecha_vencimiento))."<br>";
            echo "Estado           :". $estado."<br>";


            $cliente->fetch($factura->tercero);
            echo $cliente->nombre;
            echo $cliente->apellidos;
            echo "<br>".$cliente->cedula;
            echo "<br>".$cliente->email;



            ?>
            </td>
        </tr>
    </table>
    <br>
    <br>
 <?php
    $sql="Select * from fi_facturas_detalle where fk_factura = ? ";
                 $db=$dbh->prepare($sql);
                 $db->bindValue(1,$id  ,PDO::PARAM_INT);
                 $db->execute();

                  //   print_r($dbh->errorInfo());           
                $contado=0;
                $tr="";

$subtotal=0;
$impuesto=0;
$total=0;
$eliminar="";
$conteo=0;
while($obj=$db->fetch(PDO::FETCH_ASSOC)){ 
$conteo++;

if ($obj['tipo_impuesto'] > 0)
 { $obj['impuestot']='<span class="label label-warning">Con Impuesto '.$obj['tipo_impuesto'].'</span>';}
                   else { $obj['impuestot']='<span class="label label-warning">Sin Impuesto</span>';}

//-------------------
$subtotal +=($obj['subtotal']*$obj['cantidad']);
$impuesto +=$obj['impuesto'];
$total    +=$obj['total'];
$descuento_aplicado+=$obj['descuento_valor_final']*$obj['cantidad'];
 

if ($obj['fk_producto']>0){   $simbolo=''.$obj['label'].'';'  ';}
 else {$simbolo=''.$obj['label'].''; } 


 if ($obj['descuento_aplicado'] > 0){

      if ($obj['descuento_tipo'] === "porcentual"  ){  $descuento_txt= "(". $obj['descuento_aplicado']."%) ";   }
         else {   $descuento_txt= "";  }

      $descuento="  <td style='width: 15%; text-align: center'> ".($factura->moneda_simbolo)."  ". numero_simple(($obj['descuento_valor_final']), 2, ',', ' ') ." $descuento_txt  </td>";
     
 } else {
     
     $descuento= "<td  style='width:15%;'  ></td>";
     
 }
 

 $tr.="<tr    >
  <td style='width: 30%; text-align: left' >".$simbolo."</td> 
  <td style='width: 5%; text-align: center' > ".$obj['cantidad']."</td> 
   
 
  <td style='width: 15%; text-align: center'> ".($factura->moneda_simbolo)."  ". numero_simple(($obj['precio_original']), 2, ',', ' ') ."</td>
  
   $descuento


   <td style='width: 15%; text-align: center'>  ".($factura->moneda_simbolo)." ".numero_simple(($obj['impuesto']), 2, ',', ' ')."</td>
  <td  style='width: 20%; text-align: right'>   ".($factura->moneda_simbolo)."  ".numero_simple(($obj['total']), 2, ',', ' ')." </td>
  </tr>";
                                   
       
                                    
                                   
                                   
                 
                                    }// fin del While---

$total_tr=45;
if ($conf->configuracion['mostrar_forma_pago_ticket'] and ($factura->pagado > 0 )){$total_tr=40; }


$conteo=$total_tr-$conteo;

for ($i = 1; $i <= $conteo; $i++) {
    $tr.="<tr><td colspan='5'></td></tr>";
}

?>

<?php if ($factura->moneda==2){ $moneda='Tipo Cambio  &cent; '.numero_simple($factura->moneda_tipo_cambio); } else { $moneda=""; } ?> 
 
<br><span style='font-size: 10pt;'><?php echo "Factura emitida en ".$factura->moneda_text." ".$moneda; ?> </span>
    <table cellspacing="1pt" border="0" style="width: 100%; border: solid 1px black; background: #E7E7E7; text-align: center; font-size: 10pt;">
   <tr>
           <th style="width: 30%;text-align: left">Descripción Item</th>
           <th style="width: 5%">Cant.</th>
            <th style="width: 15%">P.U</th>
            <th style="width: 15%">Descuento</th>
            <th style="width: 15%">Impuesto</th>
            <th style="width: 20%;text-align: right "  >Total</th>
         </tr>
    </table>
    

    <table  border="0"   cellspacing="5pt" style="width: 100%; border: solid 1px black; background: #F7F7F7; text-align: center; font-size: 10pt;">
        

   <?php echo $tr; ?>

   </table>

 <page_footer>
     
     <a href="<?php echo ENLACE_WEB."comprobante/".md5($factura->id)."/".$clave; ?>" style='color:grey'>Descargar Comprobante</a><br>
     <a href="<?php echo ENLACE_WEB."factura/".md5($factura->id)."/".$clave; ?>" style='color:grey' >Descargar Factura</a><br>
     

    <table style="width:100%">
        <tr>
            <td>    <qrcode value="<?php echo ENLACE_WEB."factura/".md5($factura->id)."/".$clave; ?>" style="width: 30mm;"></qrcode> </td>
            
            <td>
                 
    <table cellspacing="3" style="width:170mm; border: solid 1px black; background: #E7E7E7; text-align: center; font-size: 11pt;">
       <?php if ($descuento_aplicado> 0 ){ ?>
        <tr>
            <th style="width: 50%; text-align: right;">SubTotal : </th>
            <th style="width: 50%; text-align: right;"><?php echo ($factura->moneda_simbolo)." ". number_format($subtotal + $descuento_aplicado  , 2, ',', ' '); ?></th>
        </tr>


        
        <tr>
            <th style="width: 50%; text-align: right;">Descuento : </th>
            <th style="width: 50%; text-align: right;"> <?php echo ($factura->moneda_simbolo)." ".number_format($descuento_aplicado , 2, ',', ' '); ?></th>
        </tr>
    <?php }  ?> 
    
   
        <tr>
            <th style="width: 50%; text-align: right;">SubTotal : </th>
            <th style="width: 50%; text-align: right;"><?php echo ($factura->moneda_simbolo)." ".number_format($subtotal, 2, ',', ' '); ?></th>
        </tr>


         <tr>
            <th style="width: 50%; text-align: right;">Impuesto : </th>
            <th style="width: 50%; text-align: right;"><?php echo ($factura->moneda_simbolo)." ".number_format($impuesto, 2, ',', ' '); ?></th>
        </tr>


  <tr style="font-size: 12pt;">
            <th style="width: 50%; text-align: right;">Total : </th>
            <th style="width: 50%; text-align: right;"><?php echo ($factura->moneda_simbolo)." ". number_format($total, 2, ',', ' '); ?>  </th>
        </tr>

     </table>
 
 </td></tr>
        
    </table>
    
<br>
 




<?php   

if ($conf->configuracion['mostrar_forma_pago_ticket'] and ($factura->pagado > 0 )){ 

              $sql="select 
              dp.label as forma ,
              p.monto 
              from fi_facturas_pagos p  
              left join diccionario_formas_pago dp on dp.rowid = p.forma_pago
           
              where p.fk_factura = ".$factura->id." ";

              $db=$dbh->prepare($sql);
              $db->execute();
              echo '
                <table cellspacing="1pt" border="0" style="width: 50%; border: solid 1px black; background: #E7E7E7; text-align: center; font-size: 10pt;">

              <tr><td style="width:100%;text-align:left;"  align="left" colspan="2">Pago(s) Recibido(s)</td></tr>';       

              while($pagos=$db->fetch(PDO::FETCH_ASSOC)){

              echo '<tr><td  style="width:50%;text-align:left;" >'.$pagos['forma'].'</td><td style="width:50%"  align="right" >'.numero_simple($pagos['monto'], 2, ',', ' ').'</td></tr>';       

              }

echo '</table>';
 } ?>
         <br>

        <span style="font-size:8pt;text-align: center;">
<a href="http://facturacionpymes.com/files/DGT-R-48-2016.pdf"><?php echo RESOLUCION_DGT; ?></a></span> <br> 
<span style="float:right;font-size:8pt;"><div><?php echo version_dgt; ?></div></span>       
</page_footer>
        
</page>