 <?php
 if($_SESSION['Entidad'] == 497){
     $cotizacion_txt = 'Proforma';
            $id_coti = $_GET['id'];
            $sql = "Select apodo from fi_cotizaciones where rowid = $id_coti AND entidad = " . $entidadGeneral;
            $datos = $dbh->prepare($sql);
            $datos->execute();
            $datos_extra = $datos->fetch(PDO::FETCH_OBJ);
            
            $label_apodo_extra = '<br><br><span style="font-weight: bold;font-size:15px;color:black;">'.$datos_extra->apodo.'</span><br>';
 }else{
     $label_apodo_extra = '';
     $cotizacion_txt = 'Cotización';
 }

            ?>



<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" style="width: 100%; text-align: center; font-size: 14px">
        <tr>
            <?php
 //$logo_pyme = ENLACE_SERVIDOR."_documentos/logos/".$entidadGeneral."/logo_pyme.png";
            
            $sql = "Select * from fi_configuracion_empresa where entidad = " . $entidadGeneral;
            $datos = $dbh->prepare($sql);
            $datos->execute();
            $datosEmpresa = $datos->fetch(PDO::FETCH_OBJ);

            ?>
            <Td valign="top" style="width: 50%;" align="LEFT">
                <?php
                if ($_GET['ad'] == 1) {
                    $textoImagen = ENLACE_SERVIDOR . "_documentos/logos/" . $entidadGeneral . "/logo.png";
                } else {
                    $textoImagen = ENLACE_SERVIDOR . "_documentos/logos/" . $entidadGeneral . "/logo.png";
                }


                if (file_exists($textoImagen)) { ?>
                    <img src="<?php echo $textoImagen ?>" style="width:150px">
                    
                       <br>
                    <strong style="font-weight: bold;font-size:20px;color:grey;"></strong>
                <?php
                } else {

                ?>
                    <strong style="font-weight: bold;font-size:20px;color:grey;"> <?php echo $datosEmpresa->nombre_empresa ?></strong><br>
                <?php
                }
                ?>




            </Td>


            <td valign="top" align="right" style="width: 50%; color: #444444;">
                <span style="font-weight: bold;font-size:20px;color:black;"><?=$cotizacion_txt?> <?php echo $factura->referencia ?></span>
                <?=$label_apodo_extra?>
                <br>
           
            </td>
        </tr>

    </table>

    <table cellspacing="0" border='0' style="width: 100%; text-align: center; font-size: 10px">
        <tr>
            <td valign="top" style="width: 50%;font-size: 12px;" align="LEFT">



                <strong>
           <?php 
           if($_SESSION['Entidad'] == 497){
               echo '<p>JOHNNY MORERA</p>';
           }else{
                      echo  "<p>$datosEmpresa->electronica_nombre_comercial</p>";
           }
           ?>
                    Cédula: <?php echo $datosEmpresa->electronica_identificacion_numero; ?>
                    <p>Email: <?php echo $datosEmpresa->electronico_correo; ?> </p>
                    Teléfono: (506) <?php echo $datosEmpresa->electronica_telefono; ?>
                </strong>

                <?php
                $sql = "SELECT
    fu.nombre,
    fu.apellidos,
    fc.fecha,
    fc.fecha_vencimiento
FROM
    fi_cotizaciones fc
    INNER JOIN fi_usuarios fu ON fu.rowid = fc.fk_usuario_crear
WHERE
    fc.rowid = ? ";
                $db = $dbh->prepare($sql);
                $db->bindValue(1, $id, PDO::PARAM_INT);
                $db->execute();
                $data = $db->fetch(PDO::FETCH_OBJ);
                $cotizador = "$data->nombre $data->apellidos";
                echo "<p>Cotizador     : " . $cotizador . "</p>";
                echo "Emisión          : " . date('d-m-Y', strtotime($data->fecha));
                echo "<p>Vencimiento   : " . date('d-m-Y', strtotime($data->fecha_vencimiento)) . "</p>";

                ?>



            </td>
            <td valign="top" align="right" style="width: 50%;font-size: 12px;">
                <?php


                if ($factura->txt_cliente != '' && $factura->tercero == 0) {






                    $sql = "Select txt_cliente from fi_cotizaciones where rowid = " . $_GET['id'];
                    $ter = $dbh->prepare($sql);
                    $ter->execute();
                    $tercero = $ter->fetch(PDO::FETCH_OBJ);

                ?>


                    <strong>

                        <p><?php echo $tercero->txt_cliente ?></p>
                    </strong>

                <?php } else {

                    //var_dump($factura);
                    //echo $sql = "Select * from fi_tercero where fk_tercero = ".$factura->tercero;
                    $sql = "Select * from fi_terceros where rowid = " . $factura->tercero;
                    $ter = $dbh->prepare($sql);
                    $ter->execute();
                    $tercero = $ter->fetch(PDO::FETCH_OBJ);

                    $cedula_txt = "<p> Ced: $tercero->cedula</p>";
                    $email_txt = "<p> Email: $tercero->email</p>";
                    $tel_txt = "<p> Tel: $tercero->telefono</p>";
                ?>

                    <strong>
                        <p><?php echo $tercero->nombre . " " . $tercero->apellidos ?></p>
                    </strong>
<?php if ($tercero->cedula > 0) { echo $cedula_txt; } ?>

<?php if ($tercero->email != '') { echo $email_txt; } ?>
<?php if ($tercero->telefono != '') { echo $tel_txt; } ?>
   





                <?php
                }

                ?>

            </td>

        </tr>
    </table>
    <br>
    <br>
    <?php

    $cantidadExoneraciones = 0;
    $sql = "Select * from fi_cotizaciones_detalle where fk_compra = ? ";
    $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;
    $iterador = 0;

    while ($obj = $db->fetch(PDO::FETCH_ASSOC)) {
        $conteo++;

        if ($factura->moneda == 1) {
            $monedita = "¢";
        } else if ($factura->moneda == 2) {
            $monedita = "$";
        } else {
            $monedita = "¢";
        }

        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 ($entidadGeneral == 89) {
            $simbolo = '' . $obj['label'] . " - " . $obj['ref'] . '';
        }

        $iterador++;


        $tr .= "<tr style='background: #F7F7F7'   >
 
  <td  style='width: 4%;' ><small> $iterador </small> </td>
  <td style='width: 25%; text-align: left; word-wrap: break-all;' >" . $simbolo . "<br><i>" . $obj['label_extra'] . "</i></td> 
  <td style='width: 10%; nowrap = 'nowrap' valign='top'  >" . $moneda . " " . numero_simple($obj['precio_original']) . "  </td>
  <td style='width: 5%; text-align: center' > " . $obj['cantidad'] . "</td> 
  <td style='width: 14%; >  " . numero_simple($obj['descuento_valor_final']) . "</td>

  <td style='width: 14%; text-align: center'> " . $monedita . " " . numero_simple(($obj['subtotal']), 2, ',', ' ') . "</td>
  
   <td style='width: 14%; text-align: center' > " . $monedita . " " . numero_simple(($obj['impuesto']), 2, ',', ' ') . "</td>
  <td  style='width: 14%;text-align: right '>  " . ($monedita) . "  " . 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='7'></td></tr>";
    }

    ?>



    <table cellspacing="1pt" border="0" style="width: 100%; border: solid 1px black; background: #E7E7E7; text-align: center; font-size: 9pt;">
        <tr>
            <th style="width: 4%"><small>Item</small></th>
            <th style="width: 25%;text-align: left">Descripción Item</th>
            <th style="width: 10%">PU</th>
            <th style="width: 5%">Cant.</th>

            <th style="width: 14%">Des.</th>
            <th style="width: 14%">Subt</th>
            <th style="width: 14%">Impuesto</th>
            <th style="width: 14%;text-align: right ">Total</th>
        </tr>


        <?php echo $tr; ?>
    </table>





    <page_footer>
        <b>NOTA:</b>
        <?php

        echo $factura->detalle_publico;

        ?>
        <table style="width:100%">
            <tr>
                <td>

                    <table cellspacing="3" style="width:100%; border: solid 1px black; background: #E7E7E7; text-align: center; font-size: 11pt;">
                        <tr>
                            <th style="width: 50%; text-align: right;">SubTotal : </th>
                            <th style="width: 50%; text-align: right;"><?php echo $monedita . " " . numero_simple($factura->subtotal) ?></th>
                        </tr>


                        <tr>
                            <th style="width: 50%; text-align: right;">Impuesto : </th>
                            <th style="width: 50%; text-align: right;"><?php echo $monedita . " " . numero_simple($factura->impuesto) ?></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 $monedita . " " . numero_simple($factura->total) ?></th>
                        </tr>

                    </table>

                </td>
            </tr>

        </table>

        <br>



        <br>


    </page_footer>

</page>