<?php
//ini_set("error_reporting",E_ALL);
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 Header2($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(-25);
        //Arial italic 8
        $this->SetFont('Arial','I',8);
        $this->Cell(90,5,date("d-m-Y"),0,0,"L");
        $this->Cell(60,5,date("H:i:s"),0,0,"R");
        //Page number
//        $this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C');
}
}

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

$pdf=new PDF('P','mm','Letter');
$pdf->SetMargins(10,10,10);
$pdf->AddPage();
$pdf->Encabezado($nombre_colegio,"BOLETAS DE DEPOSITO OPERADAS POR FECHAS");
$pdf->SetFont('Arial','',11);
$pdf->Ln(15);
$pdf->cell(60,5,"FECHA INICIAL: $txtfi FECHA FINAL: $txtff");
$pdf->Ln();

$fi=fechabd($txtfi);
$ff=fechabd($txtff);

$cl[1]=23;
$cl[2]=28;
$cl[3]=97;
$cl[4]=23;
$cl[5]=25;

$pdf->setstyle("B",true);
$pdf->cell($cl[1],5,"FECHA",1,0,"C");
$pdf->cell($cl[2],5,"DOCUMENTO",1,0,"C");
$pdf->cell($cl[3],5,"NOMBRE DEL DOCUMENTO",1,0,"C");
$pdf->cell($cl[4],5,"VALOR",1,0,"C");
$pdf->cell($cl[5],5,"BOLETA",1,1,"C");
$pdf->setstyle("B",false);

$qinfo=mysql_query("select * from cp_recibos where fecha >= '$fi 00:00:00' and fecha <='$ff 23:59:00' and dp<>'' and anulado <>'S' and tipo = 4 order by fecha, tipo, numero");

$totalr=0;
$i=0;
while($info=mysql_fetch_array($qinfo)){
 $i++; 
 $totalr+=$info[total];
 $pdf->SetFillColor(255,255,255);
 $pdf->cell($cl[1],5,fecha($info[fecha]),1,0,"C",1);
 $pdf->cell($cl[2],5,get_talonariodc($info[tipo])." ".$info[numero],1,0,"L",1);
 $pdf->cell($cl[3],5,$info[nombre],1,0,"L",1);
 $pdf->cell($cl[4],5,moneda($info[total]),1,0,"R",1);
 $pdf->cell($cl[5],5,$info[dp],1,1,"L",1);
}

$pdf->setstyle("B",true);
$pdf->cell(23+28+97,5,"TOTAL...   $i documento(s)",1,0,"L",1);
$pdf->cell($cl[4],5,moneda($totalr),1,0,"R",1);
$pdf->cell($cl[5],5,"",1,1,"R",1);
$pdf->setstyle("B",false);

$pdf->Output();
exit();
?>
