<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Factura</title>

<style type="text/css">
    * {
        font-family: "Times New Roman", Times, serif;
    }
    table{
        font-size: x-small;
    }
    tfoot tr td{
        font-weight: bold;
        font-size: x-small;
    }
    .gray {
        background-color: lightgray
    }
    .titlePrincipal{
        font-size: 13px;
    }
    p{
        line-height: 3px;
    }
    .spacemiddle{
        margin-top: 0%;
    }
    .spacemiddle2{
        margin-top: 0%;
    }
    .titleFranjaSupLeft{
        background: #8e8e8e;
        color: #fff;
        font-size: 12px;
        padding: 12px;
        text-align: center;
    }
    .titleFranjaSupRight{
        color: #000;
        font-size: 22px;
        margin: 1% 0px -2% 0px;
    }
    .titleFranjaBajRight{
        color: red;
        font-size: 22px;
    }
    .titleDiv{
        font-weight: bold;
    }
    .subtitleDiv{
        font-weight: 400;
    }
    .titleDivEnd{
        background: #d3d3d3;
        color: #333;
        font-weight: bold;
        padding: 12px;
    }
    footer {
        position: fixed; 
        bottom: -60px; 
        left: 0px; 
        right: 0px;
        height: 50px; 

        /** Extra personal styles **/
        background-color: #d3d3d3;
        color: white;
        text-align: center;
        line-height: 35px;
    }
    footer .pagenum:before {
      content: counter(page);
      color: #000;
      font-weight: bold;
    }
</style>

</head>
<body>

  <table width="100%">
    <tr>
        <td align="left" style="width:70%">
            <h3 class="titlePrincipal">HYB APARATOLOGIA Y SUMINISTROS S.A</h3>
            <p>Cédula Jurídica 3-101-680497</p>
            <p>Dirección: Del Peaje de Escazú 600 metros al oeste Edificio DUO Medical. Piso 3</p>
            <p>San Rafael de Escazú</p>
            <p>Correo electrónico: nelson@hybequipos.com</p>
            <p>Teléfono: 506 22481717</p>
        </td>
        <!-- image logo -->
        <?php
            if($_GET['ad']==1){
                $textoImagen = ENLACE_SERVIDOR."_documentos/logos/".$entidadGeneral."/logo.png";
            }else{
                $textoImagen = ENLACE_SERVIDOR."_documentos/logos/".$entidadGeneral."/logo.png";
            }
        ?>
        <td align="right" valign="top" style="width:30%"><img src="<?php echo $textoImagen; ?>" alt="" width="150"/></td>
    </tr>

  </table>

    <!-- validate data -->
    <?php if ($factura->version=="4.2"    ) { ?> 

    <?php } else { 
           
        $sql = "select clave from fi_facturas where rowid =   ".$factura->id ;
        $DATOS= $dbh->prepare($sql);
        $DATOS->execute();
        $DATOS_CLAVE =  $DATOS->fetch(PDO::FETCH_OBJ);
        //var_dump($XML_Hacienda);
                
    ?> 
    
    <?php } ?>

  <table width="100%" class="spacemiddle">

    <tr>
        <td align="left" style="width:60%">
            <h4 class="titleFranjaSupLeft">FACTURAR A:</h4>
        </td>
        <td align="right" valign="top" style="width:40%">
            <h4 class="titleFranjaSupRight">FACTURA</h4>
            <h4 class="titleFranjaBajRight"><?php echo $factura->referencia; ?></h4>
        </td>
    </tr>

  </table>

  <?php $cliente->fetch($factura->tercero); ?>

  <table width="100%" class="spacemiddle2">

<tr>
    <td align="left" style="width:60%">
        <p class="titleDiv">Receptor: <span class="subtitleDiv"><?php echo  $XML_Hacienda->electronica_nombre_comercial;  ?></span></p>
        <p class="titleDiv">Identificación: <span class="subtitleDiv"><?php echo $XML_Hacienda->electronica_identificacion_numero  ; ?></span></p>
        <p class="titleDiv">Teléfono: <span class="subtitleDiv">(506) <?php echo $XML_Hacienda->electronica_telefono; ?></span></p>
        <p class="titleDiv">Correo electrónico: <span class="subtitleDiv"><?php echo $XML_Hacienda->electronico_correo; ?></span></p>
        <p class="titleDiv" style="line-height: 15px;margin-top:-10px;">Dirección: <span class="subtitleDiv"><?php echo  $XML_Hacienda->direccion_PDF;  ?></span></p>
        <p class="titleDiv">Atención: <span class="subtitleDiv"> </span></p>
    </td>
    <td align="left" valign="top" style="width:40%">
        <p class="titleDiv">Fecha de emisión: <span class="subtitleDiv"><?php echo date('d-m-Y h:i A',strtotime($factura->fecha_creacion_server)); ?></span></p>
        <p class="titleDiv">N° de cliente: <span class="subtitleDiv"> </span><?php echo $cliente->id; ?></p>
        <p class="titleDiv" style="line-height: 15px;margin-top:-10px;">Nombre del cliente: <span class="subtitleDiv"><?php echo $cliente->nombre.' '.$cliente->apellidos; ?></span></p>
        <p class="titleDiv">Cédula del cliente: <span class="subtitleDiv"><?php echo $cliente->cedula; ?></span></p>
        <p class="titleDiv">Condición de venta: <span class="subtitleDiv"> </span></p>
        <p class="titleDiv">Medio de pago: <span class="subtitleDiv"> </span></p>
    </td>
</tr>

</table>

  <br/>

  <table width="100%">
    <thead style="background-color: #8e8e8e;color: #fff;">
      <tr>
        <th>CANTIDAD</th>
        <th>DESCRIPCIÓN</th>
        <th>UNIDAD</th>
        <th>PRECIO UNIT</th>
        <th>DESCUENTO</th>
        <th>IVA</th>
        <th>TOTAL</th>
      </tr>
    </thead>
    <tbody>
        <?php echo $tr; ?>

        <?php
            if($nota->tipo == 'credito'){
                $tipoNota = "3";
            }
            
            if($nota->tipo == 'debito'){
                $tipoNota = "2";
            }
        ?>
    </tbody>

    <tfoot>
       <?php if ($descuento_aplicado> 0 ){ ?>
       
        <tr>
            <td colspan="5"></td>
            <td align="left">SUBTOTAL</td>
            <td align="right"><?php echo ($nota->moneda_simbolo)." ". number_format($subtotal + $descuento_aplicado  , 2, ',', ' '); ?></td>
        </tr>
        <tr>
            <td colspan="5"></td>
            <td align="left">DESCUENTOS</td>
            <td align="right"><?php echo ($nota->moneda_simbolo)." ".number_format($descuento_aplicado , 2, ',', ' '); ?></td>
        </tr>
       
       <?php } ?>
       
        <tr>
            <td colspan="5"></td>
            <td align="left">SUBTOTAL</td>
            <td align="right"><?php echo ($nota->moneda_simbolo)." ".number_format($subtotal, 2, ',', ' '); ?></td>
        </tr>
        <tr>
            <td colspan="5"></td>
            <td align="left">DESCUENTOS</td>
            <td align="right"></td>
        </tr>
        <tr>
            <td colspan="5"></td>
            <td align="left">IMPUESTO</td>
            <td align="right"><?php echo ($nota->moneda_simbolo)." ".number_format($impuesto, 2, ',', ' '); ?></td>
        </tr>
        <tr>
            <td colspan="5"></td>
            <td align="left">OTRO</td>
            <td align="right"></td>
        </tr>
        <tr>
            <td colspan="5"></td>
            <td align="left">TOTAL</td>
            <td align="right" class="gray"><?php echo ($nota->moneda_simbolo)." ". number_format($total, 2, ',', ' '); ?>  </td>
        </tr>       
       
    </tfoot>
  </table>

  <br>
  <br>
  <br>

    <?php if (!empty($factura->notageneral)){ ?>

  <table width="100%" class="spacemiddle2" style="margin-bottom: 0px;">

    <tr>
        <td align="left" style="width:10%">
            <p class="titleDivEnd">COMENTARIOS</p>
        </td>
    </tr>

   </table>

    <?php } ?>

   <table width="100%" class="spacemiddle2">

    <tr>
        <td>

    <?php if (!empty($factura->notageneral)){ ?>

        <textarea style="width:100%;height: 20%;">
            <?php
                $sql = "Select cuentaBanco from fi_configuracion_empresa where entidad = ".$entidadGeneral;
                $dbCuentas = $dbh->prepare($sql);
                $dbCuentas->execute();
                $cuenta = $dbCuentas->fetch(PDO::FETCH_OBJ);
                if($cuenta->cuentaBanco != "" or $cuenta->cuentaBanco != null){
            ?>
            <!--<hr style="color:blue">-->
            <?php echo $cuenta->cuentaBanco ?>
            
            <?php
                }
            ?>
            
            
            <?php 
            
                echo "Nota General: ". $factura->notageneral;
            
            ?>
            
        </textarea>
        
    <?php } ?>
        
            <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>
        </td>
    </tr>

   </table>

<footer>
    <div class="pagenum-container"><span class="pagenum"></span></div>
</footer>

</body>
</html>