<?php
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,5,"Colegio Mundo de Juguete - Alianza Educativa",0,1,"C");
        $this->Cell(80,5);
        $this->Cell(30,5,$texto,0,0,'C');
        //Line break
        $this->Ln(20);
}

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

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

$qalm=mysql_query("select * from alumnos where carnet='$idalumno'");
$ial=mysql_fetch_array($qalm);

$pdf=new PDF('P','mm','Letter');
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Header2("Cargos Cancelados");
$pdf->SetFont('Times','',12);
$pdf->Ln(10);
$borde=0;
$pdf->Cell(30,5,"Carnet:",$borde,0);
$pdf->Cell(100,5,"$idalumno",$borde,0);
$pdf->Cell(60,5,"Del: $fechai al $fechaf",$borde,1,"R");
$pdf->Cell(30,5,"Apellido(s):",$borde,0);
$pdf->Cell(100,5,$ial[apellido],$borde,1);
$pdf->Cell(30,5,"Nombre(s):",$borde,0);
$pdf->Cell(100,5,$ial[nombre],$borde,1);
$pdf->Cell(30,5,"Grado:",$borde,0);
$pdf->Cell(100,5,ggrado(enc($ial[grado_estudio]))." ".gnivel(enc($ial[nivel_estudio])),$borde,1);
$pdf->Ln();

$borde=1;

$pdf->SetStyle("B",true);
$pdf->Cell(30,5,"Fecha de pago",$borde,0);
$pdf->Cell(135,5,"Descripción del cargo",$borde,0);
$pdf->Cell(25,5,"Valor",$borde,1,"C");
$pdf->SetStyle("B",false);
$borde=0;

$tmpf=explode("/",$fechai);
$fecha1=$tmpf[2]."-".$tmpf[1]."-".$tmpf[0];
$tmpf=explode("/",$fechaf);
$fecha2=$tmpf[2]."-".$tmpf[1]."-".$tmpf[0];

//$qdet=mysql_query("select * from cp_cargos where carnet='$idalumno' and fecha_cargo >= '$fecha1 00:00:00' and saldo > 0 order by fecha_cargo");
$qdet=mysql_query("select dr.*, r.fecha
                   from cp_recibos r inner join cp_detalle_recibos dr
                      ON dr.numero_doc = r.numero and dr.tipo_doc = r.tipo
                   where r.carnet='$idalumno'
                   and fecha >= '$fecha1 00:00:00'
                   and fecha <= '$fecha2 23:59:59'
                   and anulado <>'S'
                   order by fecha");
//$pdf->cell(0,5,mysql_error());
$total=0.00;
while($idet=mysql_fetch_array($qdet)){
 $total+=$idet[valor];
 $pdf->Cell(30,5,fecha($idet[fecha]),$borde,0);
 $pdf->Cell(135,5,$idet[descripcion],$borde,0);
 $pdf->Cell(25,5,moneda($idet[valor],"Q"),$borde,1,"R");
}
 $pdf->Cell(190,0.01,"",1,1);
 $pdf->SetStyle("B",true);
 $pdf->Cell(30,5,"TOTAL",$borde,0);
 $pdf->Cell(135,5,"",$borde,0);
 $pdf->Cell(25,5,moneda($total,"Q"),$borde,1,"R");
 $pdf->SetStyle("B",false);
 $pdf->Cell(190,0.01,"",1,1);
 $pdf->Cell(190,0.2,"",1,1);
 $pdf->Output("Cargos_Pagados_$idalumno.pdf","I");
 //$pdf->Output();
 exit();
?>
