<?php
//FORMATO DE IMPRESION RECIBO DE CAJA
include("../fnc.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 footer
function Footer()
{
        //Position at 1.5 cm from bottom
        $this->SetY(-25);
        //Arial italic 8
        $this->SetFont('Arial','I',8);
        //Page number
        $this->Cell(0,10,'Página '.$this->PageNo().'/{nb}',0,0,'C');
}
}

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

$pdf=new PDF('P','mm','Letter');
$pdf->SetMargins(10,10.00,0.00);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFillColor(255,255,255);
$pdf->Encabezado($nombre_colegio,"INGRESOS POR TIPO DE CARGO");
$pdf->SetFont('Times','',12);
$pdf->SetStyle("B",true);
$pdf->Cell(190,5,"Tipo de cargo: ".get_tipo_cargo($codigocargo),0,1,"C");
$pdf->SetStyle("B",false);
$pdf->Cell(190,5,"Cobrados del: $fechai al: $fechaf",0,1,"C");
$pdf->SetFont('Times','',10);
$pdf->Ln(1);

$columna=Array();
$columna[1]=16;
$columna[2]=18;
$columna[3]=60;
$columna[4]=65;
$columna[5]=16;
$columna[6]=20;
$borde=1;
$pdf->SetStyle("B",true);
$pdf->Cell($columna[1],5,"# Doc.",$borde,0,"C");
$pdf->Cell($columna[2],5,"Fecha Pago",$borde,0,"C");
$pdf->Cell($columna[3],5,"Concepto",$borde,0,"C");
$pdf->Cell($columna[4],5,"Alumno",$borde,0,"C");
$pdf->Cell($columna[5],5,"Carnet",$borde,0,"C");
$pdf->Cell($columna[6],5,"Monto",$borde,1,"C");
$pdf->cell(0,0.2,"",0,1);
$pdf->SetStyle("B",false);

$tmpfi=explode("/",$fechai);
$tmpff=explode("/",$fechaf);
$fi=$tmpfi[2]."-".$tmpfi[1]."-".$tmpfi[0];
$ff=$tmpff[2]."-".$tmpff[1]."-".$tmpff[0];

          $sql="select dr.*, rec.fecha, rec.carnet
                from cp_cargos cr inner join cp_detalle_recibos dr ON dr.id_cargo = cr.id
                inner join cp_recibos rec on rec.numero = dr.numero_doc and rec.tipo = dr.tipo_doc
                where cr.tipo='$codigocargo'
                and rec.fecha between '$fi 00:00:00' and '$ff 23:59:59'
                order by rec.fecha, rec.tipo, rec.numero";

$q=mysql_query(trim($sql));
//$pdf->multicell(0,5,mysql_error(),1,1);
$total=0.00;
$linea=0;
while($idet=mysql_fetch_array($q)){
  $borde=0;
  $linea++;
  $total+=$idet[valor];
  $pdf->Cell($columna[1],5,get_talonariodc($idet[tipo_doc])."-".$idet[numero_doc],$borde,0,"C");
  $pdf->Cell($columna[2],5,fecha($idet[fecha]),$borde,0,"C");
  $pdf->Cell($columna[3],5,$idet[descripcion],$borde,0,"L");
  $pdf->Cell($columna[4],5,galumno(enc($idet[carnet])),$borde,0,"L",1);
  $pdf->Cell($columna[5],5,$idet[carnet],$borde,0,"C",1);
  $pdf->Cell($columna[6],5,moneda($idet[valor]),$borde,1,"R",1);
  if($linea>38){
     $pdf->AddPage();
     $pdf->Encabezado($nombre_colegio,"INGRESOS POR TIPO DE CARGO");
     $pdf->SetFont('Times','',12);
     $pdf->SetStyle("B",true);
     $pdf->Cell(190,5,"Tipo de cargo: ".get_tipo_cargo($codigocargo),0,1,"C");
     $pdf->SetStyle("B",false);
     $pdf->Cell(190,5,"Cobrados del: $fechai al: $fechaf",0,1,"C");
     $pdf->SetFont('Times','',10);

     $pdf->Ln(6);

     $borde=1;
     $pdf->SetStyle("B",true);
     $pdf->Cell($columna[1],5,"# Doc.",$borde,0,"C");
     $pdf->Cell($columna[2],5,"Fecha Pago",$borde,0,"C");
     $pdf->Cell($columna[3],5,"Concepto",$borde,0,"C");
     $pdf->Cell($columna[4],5,"Alumno",$borde,0,"C");
     $pdf->Cell($columna[5],5,"Carnet",$borde,0,"C");
     $pdf->Cell($columna[6],5,"Monto",$borde,1,"C");
     $pdf->cell(0,0.3,"",0,1);

     $pdf->SetStyle("B",false);
     $linea=0;
  }
}
$pdf->Cell(195,0.2,"",1,1);
$pdf->SetStyle("B",true);
$pdf->Cell(25,5,"TOTAL...",0,0,"L");
$pdf->Cell(170,5,moneda($total),0,1,"R");
$pdf->SetStyle("B",false);
$pdf->Cell(195,0.2,"",1,1);
$pdf->Output();
exit();
?>
