<?php
include_once("../../../php/sessionStart.php"); 
include_once("../../../php/db/dbExec.php");
include_once('../../../php/functions.php');
include_once("../../../php/fpdf/functions.php");
include_once('../../../php/timezone.php');
include_once('../../../php/maxExecTime.php');
//include_once('../ws/COFIDI/wsExec.php');

$empCod=utf8_decode($_SESSION["empCod"]);
$empNom=TRIM(utf8_decode($_SESSION["empNom"]));
$empNomc=utf8_decode($_SESSION["empNomc"]);
//$empDir=utf8_decode($_SESSION["empDir"]);
$empNit=$_SESSION["empNit"];
$usuNom = utf8_decode($_SESSION['usuNom']);
$pCaja=utf8_decode($_SESSION["pCaja"]);

$numdoc=$_GET["numdoc"];
$seriedoc=$_GET["selTipoCod"];
$TdocNom=$_GET["TdocNom"];
$totLetras=$_GET["totLetras"];
$vuelto=$_GET["vuelto"];
$idinterno=$_GET["idinterno"];

$arrayError=array();

# QUERYS
$sFactura = "SELECT *, 
    TRIM(fac.fact_nom) AS fact_nom,
    TRIM(fac.fact_dir) AS fact_dir,
    TRIM(fac.fact_tel) AS fact_tel,
    TRIM(fac.fact_nit) AS fact_nit,
    TRIM(ca.caj_resolu) AS caj_resolu,
    TRIM(ca.caj_nomt) AS caj_nomt,
    TRIM(ca.caj_dirt) AS caj_dirt,
    TRIM(ca.caj_telt) AS caj_telt,
    TRIM(ca.caj_mailt) AS caj_mailt,
    TRIM(ca.caj_leyen1) AS caj_leyen1,
    TRIM(ca.caj_leyen2) AS caj_leyen2,
    TRIM(res.res_num) AS res_num,
    TRIM(res.res_serie) AS res_serie,
    TRIM(vend.vend_nom) AS vend_serie
    FROM facturas fac
    LEFT JOIN caja ca ON ca.caj_emp='$empCod' AND ca.caj_cod='$pCaja'
    LEFT JOIN resolu res ON res.res_emp='$empCod' AND res.res_num=ca.caj_resolu
    LEFT JOIN vendedor vend ON fac.fact_vend=vend.vend_cod 
    WHERE fact_emp='$empCod' AND fact_transac='$idinterno'";

$sFact_det = "SELECT * FROM fact_det WHERE factd_emp='$empCod' AND factd_transac='$idinterno'";

# EJECUCION DE QUERYS
$db = new dbExec();

$func = new functions();

$select["facturas"] = $db->query($sFactura);
$select["fact_det"] = $db->query($sFact_det);

$rec = $db->fetchAssoc($select["facturas"]);

$lineWidth=19.5;
$lineHeight=0.4;

class generatePDF extends PDF_MC_Table {
    function Header() {
    }
    
    function Footer() { 
        // Posición: a 1,5 cm del final
    /*    $func = new functions();
        $this->SetY(-2);
        $this->SetFont("Arial","I",7);
        $this->Cell(0,1,strftime("%d/%m/%Y %T"),0,0,"L");   */
    }
}

# GENERAR PDF
//$pdf = new generatePDF("P", "cm", "A4");
$pdf = new generatePDF("P", "cm", "Letter");

include('../felPrint/FEL.php');

$pdf->Output(utf8_decode("Factura").".pdf","I");

//$emailAttachment = $pdf->Output('','I');
$db->close();
?>