<?php
include_once("../../../php/sessionStart.php"); 
include_once("../../../php/db/dbExec.php");
include_once("../../../php/fpdf/functions.php");
include_once("../../../php/ntol/CifrasEnLetras.php");
include_once('../../../php/functions.php');
include_once('../../../php/timezone.php');
include_once('../../../php/maxExecTime.php');

$empCod=utf8_decode($_SESSION["empCod"]);
$empNom=utf8_decode($_SESSION["empNom"]);

$numNum=$_GET["numNum"];
$selTipoCod="012";
$selTabo=$_GET["selTabo"];
$selTaboNom=$_GET["selTaboNom"];


# QUERYS

$sAbonosc = "SELECT *,
               TRIM(ab.abo_con) AS abo_con,
               TRIM(cl.cli_nom) AS pro_nom 
             FROM abonosc ab
             LEFT JOIN cliencc cl ON cl.cli_emp=ab.abo_emp AND cl.cli_cod=ab.abo_codp 
             WHERE abo_emp='$empCod' AND abo_tipo='$selTabo' AND abo_num='$numNum'";

//$sAbo_detc = "SELECT * FROM abo_detc WHERE abd_emp='$empCod' AND abd_tipo='$selTabo' AND abd_num='$numNum'";


# EJECUCION DE QUERYS
$db = new dbExec();
$fa["abonosc"] = $db->sFetchAssoc($sAbonosc);
//$select["abo_detc"] = $db->query($sAbo_detc);

$func = new functions();
//$dtGrabado=(empty($_GET["dtGrabado"])) ? strftime("%d/%m/%Y %T") : $_GET["dtGrabado"];
//$btn=utf8_decode($_GET["btn"]);

class generatePDF extends PDF_MC_Table {
    function Header() {
    }
    
    function Footer() {
        $this->SetY(-2.5);
    }
}


# GENERAR PDF
    $pdf = new generatePDF("P","cm", "Letter");
    $pdf->AddPage();
    $pdf->SetMargins(2, 1, 2.5);
    $pdf->SetFont("Arial","B",20);

    $lineWidth=17;
    $lineHeight=0.6;

    $pdf->SetFont("","",10);
    //$pdf->SetX(4.5);
    //$pdf->Ln();
    $pdf->MultiAlignCell($lineWidth/5, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/4, $lineHeight, utf8_decode(trim($selTaboNom))."-".trim($numNum));
    $pdf->Ln(2);
    //$pdf->SetX(4.5);
    $pdf->MultiAlignCell($lineWidth/1.2, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/8, $lineHeight, strftime("%d/%m/%Y", strtotime($fa["abonosc"]["abo_fec"])));
    $pdf->Ln(1);
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/1, $lineHeight, utf8_decode((trim($fa["abonosc"]["abo_codp"]))."-".trim($fa["abonosc"]["cli_nom"])));
    $pdf->Ln();
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, $fa["abonosc"]["abo_efec"],0,0,"R");
    $pdf->Ln();
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, $fa["abonosc"]["abo_ntarj"]);
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, $fa["abonosc"]["abo_vtarj"],0,0,"R");
    $pdf->Ln();
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, $fa["abonosc"]["abo_nch"]);
    $pdf->MultiAlignCell($lineWidth/8, $lineHeight, $fa["abonosc"]["abo_vch"],0,0,"R");
    $pdf->Ln();
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, $fa["abonosc"]["abo_ndepo"]);
    $pdf->MultiAlignCell($lineWidth/8, $lineHeight, strftime("%d/%m/%Y", strtotime($fa["abonosc"]["abo_fdepo"])));
    $pdf->MultiAlignCell($lineWidth/8, $lineHeight, $fa["abonosc"]["abo_vdepo"],0,0,"R");
    $pdf->Ln();
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, $fa["abonosc"]["abo_ndepo2"]);
    $pdf->MultiAlignCell($lineWidth/8, $lineHeight, strftime("%d/%m/%Y", strtotime($fa["abonosc"]["abo_fdepo2"])));
    $pdf->MultiAlignCell($lineWidth/8, $lineHeight, $fa["abonosc"]["abo_vdepo2"],0,0,"R");
    $pdf->Ln();
    $pdf->MultiAlignCell($lineWidth/6, $lineHeight, "");
    $pdf->MultiAlignCell($lineWidth/1, $lineHeight, $fa["abonosc"]["abo_con"]);
    $pdf->Ln($lineHeight*2);
    $pdf->Output(utf8_decode("Documento ").$selTabo."-".$numNum.".pdf","I");

$db->close();

?>