<?php
// DESCONTINUADO
// FORMATO DE IMPRESION PARA RECIBO CONTINUO POR OTROS INGRESOS

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);
        $this->Ln();
}

//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("../num2letras.php");

if(!$txtfi || !$txtff || !$tipodoc){
  alert("Parámetros incorrectos","$goback");
  exit();
}

$txtfi=explode("/",$txtfi);
$txtff=explode("/",$txtff);
$fi=$txtfi[2]."-".$txtfi[1]."-".$txtfi[0];
$ff=$txtff[2]."-".$txtff[1]."-".$txtff[0];

$qtl=mysql_query("select * from cp_talonarios where id = $tipodoc");
$itl=mysql_fetch_array($qtl);

$pdf=new PDF('P','mm','Letter');
$pdf->SetMargins(10,10.00,0.00);
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->Header2("CORTE DE CAJA");
$pdf->SetFont('Times','',12);
$pdf->Cell(190,5,"Reporte de ingresos del ".fecha($fi)." al ".fecha($ff),0,1,"C");
$pdf->Cell(190,5,"Talonario: ".$itl[nombre],0,1,"C");
$pdf->Ln(10);

             $sql="select *
                   from cp_recibos
                   where tipo = $tipodoc
                   and fecha>='$fi 00:00:00'
                   and fecha<='$ff 23:59:00'
                   order by fecha, numero";

$qdoc=mysql_query($sql);
$pdf->Ln();

$pdf->SetFont('Times','',10);
$pdf->Setstyle("B",true);
$border=1;

$celdas=Array();
$celdas[0]=15;
$celdas[1]=20;
$celdas[2]=18;
$celdas[3]=78;
$celdas[4]=17;
$celdas[5]=32;

$ttdepositos=$ttcheques=$tttarjetas=$ttefectivo=$ttnotacredito=0.00;
$depositos=Array();
$cheques=Array();
$tarjetas=Array();
$notascredito=Array();

$pdf->Cell($celdas[0],5,"# DOC.",$border,0,"C");
$pdf->Cell($celdas[1],5,"FECHA",$border,0,"C");
$pdf->Cell($celdas[2],5,"CARNET",$border,0,"C");
$pdf->Cell($celdas[3],5,"DOCUMENTO A NOMBRE DE",$border,0,"C");
$pdf->Cell($celdas[4],5,"TOTAL",$border,0,"C");
$pdf->Cell($celdas[5],5,"FRM. PAGO",$border,1,"C");
$pdf->Setstyle("B",false);
$total=0;
$ln=0;
$cont_trn=0;
$det_new_p=false;

if(mysql_num_rows($qdoc)>=20){
  $det_new_p=true;
}
while($idoc=mysql_fetch_array($qdoc)){
  $ln++;
  $cont_trn++;
  $border=0;
  $forma_pago="";
  $total+=$idoc[total];

  if($idoc[anulado]=="S"){$idoc[nombre]="A N U L A D O";}

  if ($idoc[vdp]>0){
    $forma_pago="DP-".$idoc[dp];
    $depositos[]=$idoc[fecha]."||".$idoc[dp]."||".$idoc[vdp];
    $ttdepositos+=$idoc[vdp];
  }

  if ($idoc[ef]>0){
    if($tipodoc==5){
        $ttnotacredito+=$idoc[ef];
    }else{
        $forma_pago="EFECTIVO";
        $ttefectivo+=$idoc[ef];
    }
  }

  if ($idoc[vchq]>0){
    $forma_pago="CHQ-".$idoc[chq];
    $cheques[]=$idoc[fecha]."||".$idoc[chq]."||".$idoc[vchq];
    $ttcheques+=$idoc[vchq];
  }

  if ($idoc[vtc]>0){
    $forma_pago="TC-".substr($idoc[tc],-8);
    $tarjetas[]=$idoc[fecha]."||XX".$idoc[dp]."||".$idoc[vtc];
    $tttarjetas+=$idoc[vtc];
  }

  $pdf->Cell($celdas[0],5,$idoc[numero],$border,0);
  $pdf->Cell($celdas[1],5,fecha($idoc[fecha]),$border,0);
  $pdf->Cell($celdas[2],5,$idoc[carnet],$border,0,"C");
  $pdf->Cell($celdas[3],5,substr($idoc[nombre],0,50),$border,0);
  $pdf->Cell($celdas[4],5,moneda($idoc[total]),$border,0,"R");
  $pdf->Cell($celdas[5],5,$forma_pago,$border,1,"R");

  if($ln>40){
    $ln=0;
    $pdf->AddPage();
    $pdf->Header2("CORTE DE CAJA");
    $pdf->SetFont('Times','',12);
    $pdf->Cell(190,5,"Reporte de ingresos del ".fecha($fi)." al ".fecha($ff),0,1,"C");
    $pdf->Cell(190,5,"Talonario: ".$itl[nombre],0,1,"C");
    $pdf->Ln(15);
    $border=1;
    $pdf->Setstyle("B",true);
    $pdf->Cell($celdas[0],5,"# DOC.",0,0,"C");
    $pdf->Cell($celdas[1],5,"FECHA",0,0,"C");
    $pdf->Cell($celdas[2],5,"CARNET",0,0,"C");
    $pdf->Cell($celdas[3],5,"DOCUMENTO A NOMBRE DE",0,0,"C");
    $pdf->Cell($celdas[4],5,"TOTAL",0,0,"C");
    $pdf->Cell($celdas[5],5,"FRM. PAGO",$border,1,"C");
    $pdf->Setstyle("B",false);
  }
}

$border=1;
$pdf->Setstyle("B",true);
$pdf->Cell(148,5,"TOTAL:  $cont_trn documento(s)",$border,0);
$pdf->Cell(32,5,moneda($total),$border,1,"R");
$pdf->Setstyle("B",false);
$pdf->Ln(3);
$pdf->Cell(180,0.1,"",1,1);


if($det_new_p==true){
 $pdf->AddPage();
}

$maxd=0;

// RESUMEN DEPOSITOS
$pdf->Ln(5);
$pdf->Setstyle("B",true);
$pdf->Cell(58,5,"DEPOSITOS",$border,1,"C");
$pdf->Cell(18,5,"Fecha",$border,0,"C");
$pdf->Cell(20,5,"No. Depósito",$border,0,"C");
$pdf->Cell(20,5,"Valor",$border,1,"C");
$pdf->Setstyle("B",false);

for($i=0;$i<count($depositos);$i++){
 $tmpinfo=explode("||",$depositos[$i]);

 $pdf->Cell(18,5,fecha($tmpinfo[0]),$border,0,"C");
 $pdf->Cell(20,5,$tmpinfo[1],$border,0,"C");
 $pdf->Cell(20,5,moneda($tmpinfo[2]),$border,1,"R");
}
$pdf->Setstyle("B",true);
$pdf->Cell(38,5,"TOTAL: $i Depósito(s)",$border,0);
$pdf->Cell(20,5,moneda($ttdepositos),$border,1,"R");
$pdf->Setstyle("B",false);
//FIN DEL RESUMEN

// RESUMEN DE CHEQUES
$maxd=($i*5*-1)-15;
$pdf->Ln(($i*5*-1)-15);
$tab=60;
$pdf->Cell($tab,5,"",0,0);
$pdf->Setstyle("B",true);
$pdf->Cell(58,5,"CHEQUES",$border,1,"C");
$pdf->Cell($tab,5,"",0,0);
$pdf->Cell(18,5,"Fecha",$border,0,"C");
$pdf->Cell(20,5,"No. Cheque",$border,0,"C");
$pdf->Cell(20,5,"Valor",$border,1,"C");
$pdf->Setstyle("B",false);

for($j=0;$j<count($cheques);$j++){
 $tmpinfo=explode("||",$cheques[$j]);
 $pdf->Cell($tab,5,"",0,0);
 $pdf->Cell(18,5,fecha($tmpinfo[0]),$border,0,"C");
 $pdf->Cell(20,5,$tmpinfo[1],$border,0,"C");
 $pdf->Cell(20,5,moneda($tmpinfo[2]),$border,1,"R");
}

$pdf->Setstyle("B",true);
$pdf->Cell($tab,5,"",0,0);
$pdf->Cell(38,5,"TOTAL: $j Cheque(s)",$border,0);
$pdf->Cell(20,5,moneda($ttcheques),$border,1,"R");
$pdf->Setstyle("B",false);
unset($cheques);
//FIN RESUMEN DE CHEQUES

//TARJETAS DE CREDITO
if($maxd > (($j*5*-1)-15)){ $maxd=(($j*5*-1)-15); }
$pdf->Ln(($j*5*-1)-15);

$tab=60+60;
$pdf->Cell($tab,5,"",0,0);
$pdf->Setstyle("B",true);
$pdf->Cell(60,5,"TARJETAS DE CRÉDITO",$border,1,"C");
$pdf->Cell($tab,5,"",0,0);
$pdf->Cell(20,5,"Fecha",$border,0,"C");
$pdf->Cell(20,5,"No. Tarjeta",$border,0,"C");
$pdf->Cell(20,5,"Valor",$border,1,"C");
$pdf->Setstyle("B",false);

for($j=0;$j<count($tarjetas);$j++){
 $tmpinfo=explode("||",$tarjetas[$j]);
 $pdf->Cell($tab,5,"",0,0);
 $pdf->Cell(20,5,fecha($tmpinfo[0]),$border,0,"C");
 $pdf->Cell(20,5,substr($tmpinfo[1],-8),$border,0,"C");
 $pdf->Cell(20,5,moneda($tmpinfo[2]),$border,1,"R");
}

$pdf->Setstyle("B",true);
$pdf->Cell($tab,5,"",0,0);
$pdf->Cell(40,5,"TOTAL: $j Tarjeta(s)",$border,0);
$pdf->Cell(20,5,moneda($tttarjetas),$border,1,"R");
$pdf->Setstyle("B",false);
//FIN DE TARJETAS DE CREDITO

//RESUMEN GENERAL
$pdf->Ln(($maxd*-1)-10);
$pdf->Setstyle("B",true);
$pdf->Cell(20,5,"RESUMEN ",$border,0);
$pdf->Cell(40,5,"EFECTIVO: ".moneda($ttefectivo),$border,0);
$pdf->Setstyle("B",false);
//FIN RESUMEN GENERAL
$pdf->Output();
exit();
?>