<?php
//FORMATO DE IMPRESION RECIBO DE CAJA
require('../fpdf.php');

class PDF extends FPDF
{
var $B;
var $I;
var $U;
var $HREF;


function WriteHTML($html)
{
        //HTML parser
        $html=str_replace("\n",' ',$html);
        $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
        foreach($a as $i=>$e)
        {
                if($i%2==0)
                {
                        //Text
                        if($this->HREF)
                                $this->PutLink($this->HREF,$e);
                        else
                                $this->Write(5,$e);
//                              $this->Cell(180,5,$e,1,2,'J');
                }
                else
                {
                        //Tag
                        if($e{0}=='/')
                                $this->CloseTag(strtoupper(substr($e,1)));
                        else
                        {
                                //Extract attributes
                                $a2=explode(' ',$e);
                                $tag=strtoupper(array_shift($a2));
                                $attr=array();
                                foreach($a2 as $v)
                                        if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
                                                $attr[strtoupper($a3[1])]=$a3[2];
                                $this->OpenTag($tag,$attr);
                        }
                }
        }
}

function OpenTag($tag,$attr)
{
        //Opening tag
        if($tag=='B' or $tag=='I' or $tag=='U')
                $this->SetStyle($tag,true);
        if($tag=='A')
                $this->HREF=$attr['HREF'];
        if($tag=='BR')
                $this->Ln(5);
}

function CloseTag($tag)
{
        //Closing tag
        if($tag=='B' or $tag=='I' or $tag=='U')
                $this->SetStyle($tag,false);
        if($tag=='A')
                $this->HREF='';
}

function SetStyle($tag,$enable)
{
        //Modify style and select corresponding font
        $this->$tag+=($enable ? 1 : -1);
        $style='';
        foreach(array('B','I','U') as $s)
                if($this->$s>0)
                        $style.=$s;
        $this->SetFont('',$style);
}

function PutLink($URL,$txt)
{
        //Put a hyperlink
        $this->SetTextColor(0,0,255);
        $this->SetStyle('U',true);
        $this->Write(5,$txt,$URL);
        $this->SetStyle('U',false);
        $this->SetTextColor(0);
}
//Page header
function Header($texto)
{
        //Logo
        $this->Image('../logo_colegio.png',10,8,20);
        //$this->Image('../logo_colegio2.png',180,8,18);
        //Arial bold 15
        //$this->SetFont('Arial','B',15);
        //Move to the right
        //$this->Cell(80);
        //Title
        //$this->Cell(30,10,$texto,0,0,'C');
        //Line break
        //$this->Ln(20);
}

//Page footer
function Footer2()
{
        //Position at 1.5 cm from bottom
        $this->SetY(-15);
        //Arial italic 8
        $this->SetFont('Arial','I',8);
        //Page number
//        $this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C');
}
}

include("../fnc.php");
include("../n2l.php");


$sql2="select cp_recibos.*, alumnos.nombre, alumnos.apellido, alumnos.factura_nombre, alumnos.grado_estudio, alumnos.nivel_estudio, alumnos.seccion
      from cp_recibos inner join alumnos on cp_recibos.carnet = alumnos.carnet
      where cp_recibos.numero = $idr and tipo=$tipo";
      
$qinfoa=mysql_query($sql2);
$infoa=mysql_fetch_array($qinfoa);

$sql="select * from cp_recibos 
      where cp_recibos.numero = $idr and tipo=$tipo";
$qrec=mysql_query($sql);
$infor=mysql_fetch_array($qrec);

$qdet=mysql_query("select dr.*
                    from cp_detalle_recibos dr
                    where dr.numero_doc='$idr' and dr.tipo_doc='$tipo'");

$tamano_doc=Array();
$tamano_doc[0]=215.9;
$tamano_doc[1]=139.7;


$pdf=new PDF('P','mm',$tamano_doc);
$pdf->SetMargins(15,5,15);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetAutoPageBreak(false);
$pdf->SetFont('Arial','',14);
$pdf->SetStyle("B",true);
$pdf->cell(0,5,$pdf->nombre_institucion,0,1,"C");
$pdf->SetStyle("B",false);
$pdf->SetFont('Arial','',12);
$pdf->cell(0,5,get_dir_institucion(),0,1,"C");
$pdf->cell(0,5,"Tel. ".get_tel_institucion(),0,1,"C");
$pdf->ln(-5);
$pdf->SetStyle("B",true);
$pdf->cell(0,5,"RECIBO No. ".rellenar($idr,5),0,1,"R");
$pdf->SetStyle("B",false);
$pdf->SetFont('Arial','',10);
$pdf->Cell(0,5,"http://www.colegiomundodejuguete.com            e-mail: info@colegiomundodejuguete.com",0,1,"C");
$pdf->Ln(6);
$pdf->cell(0,5,"",1,1);
$pdf->Ln(-5);
$pdf->cell(50,5,"FECHA: ".fechalarga($infor[fecha]),1,0,"L");
//$pdf->Cell(5,5,"",0,0);
$pdf->cell(35,5," CARNET: ".$infor[carnet],1,0,"L");
$pdf->cell(15,5,ggrado_completo(enc($infoa[grado_estudio]),$infoa[seccion]),0,0,"L");
$pdf->Cell(5,5,"",0,0);

$pdf->Ln(5);
$pdf->cell(0,8,"RECIBI DE: ".$infor[nombre],1,1);
$pdf->Ln(3);

$pdf->cell(20,5,"CANTIDAD",1,0,"C");
$pdf->cell(106,5,"CONCEPTO",1,0,"C");
$pdf->cell(30,5,"PRECIO UNIT.",1,0,"C");
$pdf->cell(30,5,"TOTAL",1,1,"C");

$lineas=0;
while($infod=mysql_fetch_array($qdet)){
 $lineas++;
 $pdf->cell(20,4,$infod[cantidad],0,0,"L");
 $pdf->cell(106,4,$infod[descripcion],0,0,"L");
 $pdf->cell(30,4,moneda($infod[valor]),0,0,"R");
 $pdf->cell(30,4,moneda($infod[cantidad]*$infod[valor]),0,1,"R");
}
$pdf->cell(0,5,"---------------------------- ULTIMA LINEA ----------------------------",0,1,"C");
//$pdf->cell(156,5,"EN LETRAS: ".enletras($infor[total]),1,1);
$espacio=4*(10-$lineas);
$pdf->Ln($espacio);
$pdf->SetFont('Arial',"B",13);
$pdf->cell(126,5,"SON: ".pmayuscula(enletras($infor[total])));
$pdf->cell(30,5,"TOTAL: ",0,0,"R");
$pdf->cell(30,5,moneda($infor[total],"Q"),0,1,"R");
$pdf->SetStyle("B",false);
$pdf->SetFont('Arial',"",10);
if(!empty($infor[carnet])){
  $pdf->cell(0,5,"Alumno: ".galumno(enc($infor[carnet])),0,1,"L");
}else{
  $pdf->cell(0,5,"",0,1);
}

$forma_pago="";
if($infor[vtc]>0){
 $forma_pago.="TC:".$infor[vtc];
}
if($infor[vdp]>0){
 $forma_pago.=" DP:#".$infor[dp]."/".$infor[vdp];
}
if($infor[ef]>0){
 $forma_pago.="EF: ".$infor[ef];
}
if($infor[vchq]>0){
 $forma_pago.=" CHQ:".$infor[chq]."/".$infor[vchq];
}

if($infor[vvale]>0){
 $forma_pago.=" VALE:".$infor[vale]."/".$infor[vvale];
}


$pdf->cell(126,5,$forma_pago,0,1);
$pdf->cell(186,5,"_______________________________ ",0,1,"R");
$pdf->cell(186,5,"Cajero (Firma y Sello)              ",0,1,"R");
$pdf->Output();
exit();
?>
