<?php



// ini_set('display_errors',1);



require_once('../../libreriasphp/html2pdf/_tcpdf_5.9.206/tcpdf.php');



session_start();



require_once ("../../config/Cado.php");



require_once ("../../app/cajageneral_cst/cCajageneral_cst.php");

$oCajageneral_cst = new cCajageneral_cst();



require_once ("../../app/empresa/cEmpresa.php");

$oEmpresa = new cEmpresa();

require_once ("../../app/caja/cCaja.php");

$oCaja = new cCaja();



require_once ("../../app/ingreso/cIngreso.php");

$oIngreso = new cIngreso();

require_once ("../../app/egreso/cEgreso.php");

$oEgreso = new cEgreso();



require_once("../../app/formatos/mysql.php");

$oMysql = new cMysql();



require_once ("../../app/formatos/formato.php");

require_once ("../../app/formatos/fechas.php");



$dts=$oEmpresa->mostrarUno(1);

$dt = mysql_fetch_array($dts);

	$emp_ruc=$dt['tb_empresa_ruc'];

	$emp_nomcom=$dt['tb_empresa_nomcom'];

	$emp_razsoc=$dt['tb_empresa_razsoc'];

	$emp_dir=$dt['tb_empresa_dir'];

	$emp_dir2=$dt['tb_empresa_dir2'];

	$emp_tel=$dt['tb_empresa_tel'];

	$emp_ema=$dt['tb_empresa_ema'];

	$emp_fir=$dt['tb_empresa_fir'];		

mysql_free_result($dts);



$dtsc=$oCaja->mostrarUno($_GET['cajid']);

$dtc = mysql_fetch_array($dtsc);

	$ban_nom=$dtc['tb_banco_nom'];

	$mon_abr=$dtc['tb_moneda_sim'];

	$caj_nom=$dtc['tb_caja_nom'];

	$edi_nom=$dtc['tb_edificio_nom'];

mysql_free_result($dtsc);





$fec_ini='01-01-2014';

$fec_fin=$oMysql->DATE_ADD(fecha_mysql($_GET['fec1']),'-1','DAY');



$dts10=$oIngreso->mostrar_suma($_GET['cajid'],fecha_mysql($fec_ini),fecha_mysql($fec_fin),$_GET['cueid'],$_GET['subcueid']);

$dt10 = mysql_fetch_array($dts10);

$sa_ingreso_sol	= $dt10['total'];

mysql_free_result($dts10);



$dts20=$oEgreso->mostrar_suma($_GET['cajid'],fecha_mysql($fec_ini),fecha_mysql($fec_fin),$_GET['cueid'],$_GET['subcueid']);

$dt20 = mysql_fetch_array($dts20);

$sa_egreso_sol	= $dt20['total'];

mysql_free_result($dts20);



$saldo_anterior_sol=$sa_ingreso_sol-$sa_egreso_sol;







$caj_nom = $ban_nom.' <br> '.$caj_nom;



$fec=date('d-m-Y');

	

$title = "REPORTE | CAJA CONSOLIDADAS - ".$fec;

$nombre_archivo = 'REPORTE | CAJA CONSOLIDADAS '.$fec.'.pdf';



// $file_name = 'FA-'.$serie.'-'.$numero.'-code.png';

// $path = 'temp/'.$file_name;

// $type = pathinfo($path, PATHINFO_EXTENSION);

// $data = file_get_contents($path);

// $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);





class MYPDF extends TCPDF

{



    public function Header() {	

      //$image_file = K_PATH_IMAGES.'logo.jpg';

      //$this->Image($image_file, 20, 10, 71, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);

      // Set font

      //$this->SetFont('helvetica', 'B', 20);

      // Title

      //$this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');

    }



    public function Footer() 

    {

       $style = array(

        'position' => 'L',

        'align' => 'L',

        'stretch' => false,

        'fitwidth' => true,

        'cellfitalign' => '',

        'border' => false,

        'padding' => 0,

        'fgcolor' => array(0,0,0),

        'bgcolor' => false,

        'text' => false

      //     'font' => 'helvetica',

      //     'fontsize' => 8,

      //     'stretchtext' => 4

      );



      $this -> SetY(-12);

      // Page number

      $this->SetFont('helvetica', '', 9);

      //$this->SetTextColor(0,0,0);

      $this->Cell(0, 0, 'Página '.$this->getAliasNumPage().' de '.$this->getAliasNbPages(), 'T', 1, 'R', 0, '', 0, false, 'T', 'M');

      

      $codigo='CAV-'.str_pad($_GET['d1'], 4, "0", STR_PAD_LEFT);

      

    

      $this->Cell(0, 0, 'infosispe.com', 0, 1, 'C', 0, '', 0, false, 'T', 'M');      

    }

}



// create new PDF document

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);



$pdf->SetCreator(PDF_CREATOR);

$pdf->SetAuthor('www.infosisperu.com');

$pdf->SetTitle($title);



$pdf->SetSubject('www.infosisperu.com');

$pdf->SetKeywords('www.infosisperu.com');



// set header and footer fonts

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));



// set default monospaced font

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);



//set margins

$pdf->SetMargins(5, 15, 5);// left top right

$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

//$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);



//set auto page breaks

$pdf->SetAutoPageBreak(TRUE, 15);



//set image scale factor

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);



//set some language-dependent strings

$pdf->setLanguageArray($l);



// ---------------------------------------------------------



// add a page

$pdf->AddPage('P', 'A4');



//font-family: Consolas, monaco, monospace;

//helvetica, monaco, monospace;



// Introducimos HTML de prueba

$html = '

<!DOCTYPE html>

<html lang="es">

<head>

    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

	<link rel="shortcut icon" href="../../admin/bootstrap/images/favicon.png">

	

</head>

<style type="text/css">

    body {

        color: black;

        font-family: Verdana, Arial, Consolas;

        font-size: 7.5pt;

    }

    .header_row th {

		font-size:28px;

		background-color:#eee;

        border-bottom: 0.9px solid #010101;

        border-right: 0.9px solid #010101;

        border-left: 0.9px solid #010101;

        border-top: 0.9px solid #010101;

    }.header th {

		font-size:28px;

		background-color:red;

		color:#fff;

        border-bottom: 0.9px solid #010101;

        border-right: 0.9px solid #010101;

        border-left: 0.9px solid #010101;

        border-top: 0.9px solid #010101;

    }

    .odd_row td {

        background-color: transparent;

        border-bottom: 0.9px solid #010101;

        padding-top: 5px;

        padding-bottom: 5px;

    }

    .even_row td {

        padding-top: 5px;

        padding-bottom: 5px;

        background-color: #f6f6f6;

        border-bottom: 0.9px solid #010101;

    }

    .row td{

        border-right: 0.9px solid #010101;

        border-left: 0.9px solid #010101;

    }

	

	

	

	div#div_tabla {  }

	div#div_tabla table { border-collapse: collapse; width: 100%; }

	div#div_tabla table td, div#div_tabla table th { border: 1px solid #eee;font-family:arial; font-size:28px; }

	div#div_tabla table th { height:18px;font-size:35px; }

	div#div_tabla table td { height:17px;font-size:35px; }

	

</style>



<style media="print">

    .oculto{

        display: none;

    }



</style>

<body>





<table style="width: 100%; margin-bottom: 10px">

	<tr>

	<td width="25%">

	<img src="../../imagenes/logo.png" alt="" />

	</td>

        <td style="text-align: center" width="45%">

	

            <strong style="font-size:38px">'.$emp_razsoc.'</strong><br>

            '.$emp_dir.'<br />   <strong>Telf.: '.$emp_tel.'  E-mail.: '.$emp_ema.'</strong> 	

        </td>  		

	    <td style="text-align: center;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;padding:2px;" width="30%">

		<br />

        <br />

		   <strong style="font-size: 40px">CAJA CONSOLIDADAS <br/> '.$edi_nom.'<br/>'.mostrarFecha($_GET['fec1']).' | '.mostrarFecha($_GET['fec2']).'</strong>

        </td>

    </tr>

</table>



<br />

<br />		

';



$dts1=$oCajageneral_cst->mostrar_filtroingresos_agrupado($_GET['cajid'],$_GET['fec1'],$_GET['fec2'],$_GET['cueid'],$_GET['subcueid']);

$num_rows= mysql_num_rows($dts1);

 

 

	$html.='

	<div id="div_tabla">

	<table id="tabla_resumen_todos" width="100%" class="">

           <thead>

			

			<tr class="header" >

				<th align="center" colspan="4" >INGRESOS</th>

			</tr>

			

			<tr class="header_row" style="font-weight:bold;font-size:16px;">

				<th align="center" width="10%" >FECHA</th>

				<th align="center" width="15%" >DOCUMENTO</th>

				<th align="center" width="15%" >CUENTA</th>

				<th align="center" width="15%" >SUBCUENTA</th>

				<th align="center" width="35%" >DETALLE</th>				

				<th align="center" width="10%" >IMPORTE</th>					

						

			</tr>



			</thead>

			<tbody>	

		

		';

		

	

       if($num_rows>0){

		   

		   

		   

      while($dt1 = mysql_fetch_array($dts1))

	  {				

			

		$dts1des=$oCajageneral_cst->mostrar_filtroingresos_desagrupado($_GET['cajid'],fecha_mysql($_GET['fec1']),fecha_mysql($_GET['fec2']),$dt1['tb_cuenta_id']);

		$num_rowsdes= mysql_num_rows($dts1des);

		while($dt1des = mysql_fetch_array($dts1des))

		{

			$reg = mostrarFechaHora($dt1des['tb_ingreso_fecreg']);	

	  

		$html.='<tr class="" >

				<td width="10%" nowrap align="left" >'.mostrarFecha($dt1des['tb_ingreso_fec']).'</td>	

				<td width="15%" align="left"  >'.$dt1des['tb_documento_abr'].' '.$dt1des['tb_ingreso_numdoc'].'</td>

				<td width="15%" align="left" nowrap >'.$dt1des['tb_cuenta_nom'].'</td>		

				<td width="15%" align="left" nowrap >'.$dt1des['tb_subcuenta_nom'].'</td>		

				<td width="35%" align="left" nowrap >'.$dt1des['tb_ingreso_det'].'</td>		

				<td width="10%" align="right"  >'.formato_money($dt1des['tb_ingreso_imp']).'</td>												

			</tr>';

			

		}

		

		if($dt1['tb_cuenta_nom']==""){ 

		$cuen = 'OTROS'; 

		} else {  

		$cuen = $dt1['tb_cuenta_nom'];

		}

		

		$html.='<tr class="" style="background-color:#e3f2fd;color:#212121;font-weight:bold;" >

				<td width="90%" align="center" nowrap >'.$cuen.'</td>		

				<td width="10%" align="right"  >'.formato_money($dt1['total']).'</td>												

			</tr>';

	

	

	

			$toting += $dt1['total'];

		}

		mysql_free_result($dts1);

    }else{

		$html.='<tr class="" >

				<td nowrap align="center" width="100%" >NO HAY REGISTROS</td>												

			</tr>';

	}

 

 $html.='<tr class="" >										

				<td nowrap align="right" width="100%" >'.$mon_abr.' '.formato_money($toting).'</td>												

			</tr>';

 

	

		$html.='</tbody>

			<tr class="even" style="background-color:#eee;">

				<td width="100%" ></td>

			</tr>

      </table> 

	  </div> ';



$dts=$oCajageneral_cst->mostrar_filtroegresos_agrupado($_GET['cajid'],$_GET['fec1'],$_GET['fec2'],$_GET['cueid'],$_GET['subcueid']);

$num_row= mysql_num_rows($dts);

 

 

	$html.='

	<div id="div_tabla">

	<table id="tabla_resumen_todos" width="100%" class="">

           <thead>

			

			<tr class="header" >

				<th align="center" colspan="4" >EGRESOS</th>

			</tr>

			

			<tr class="header_row" style="font-weight:bold;font-size:16px;">

				<th align="center" width="10%" >FECHA</th>

				<th align="center" width="10%" >DOCUMENTO</th>

				<th align="center" width="15%" >CUENTA</th>

				<th align="center" width="15%" >SUBCUENTA</th>

				<th align="center" width="40%" >DETALLE</th>				

				<th align="center" width="10%" >IMPORTE</th>					

						

			</tr>



			</thead>

			<tbody>	

		

		';

		

	

       if($num_row>0){

      while($dt = mysql_fetch_array($dts))

	  {				

		

		

		$dts2des=$oCajageneral_cst->mostrar_filtroegresos_desagrupado($_GET['cajid'],fecha_mysql($_GET['fec1']),fecha_mysql($_GET['fec2']),

		$dt['tb_cuenta_id']);

		

	   while($dt2des = mysql_fetch_array($dts2des))

		{

		$reg = mostrarFechaHora($dt2des['tb_egreso_fecreg']);	

		

			$html.='<tr class="" >

				<td width="10%" nowrap align="left" >'.mostrarFecha($dt2des['tb_egreso_fec']).'</td>	

				<td width="10%" align="left"  >'.$dt2des['tb_documento_abr'].' '.$dt2des['tb_egreso_numdoc'].'</td>

				<td width="15%" align="left" nowrap >'.$dt2des['tb_cuenta_nom'].'</td>		

				<td width="15%" align="left" nowrap >'.$dt2des['tb_subcuenta_nom'].'</td>		

				<td width="40%" align="left" nowrap >'.$dt2des['tb_egreso_det'].'</td>		

				<td width="10%" align="right"  >'.formato_money($dt2des['tb_egreso_imp']).'</td>												

			</tr>';

			

		}

		

		

		if($dt['tb_cuenta_nom']==""){ 

		$cuen = 'OTROS'; 

		} else {  

		$cuen = $dt['tb_cuenta_nom'];

		}

		

		$html.='<tr class="" style="background-color:#e3f2fd;color:#212121;font-weight:bold;" >

				

				<td width="90%" align="center" nowrap >'.$cuen.'</td>		

				<td width="10%" align="right"  >'.formato_money($dt['total']).'</td>												

			</tr>';

	

			$totegr += $dt['total'];

		}

		mysql_free_result($dts);

    }else{

		$html.='<tr class="" >

				<td nowrap align="center" width="100%" >NO HAY REGISTROS</td>												

			</tr>';

	}

 

 

	$html.='<tr class="" >										

				<td nowrap align="right" width="100%" >'.$mon_abr.' '.formato_money($totegr).'</td>												

			</tr>';

 



	

		$html.='</tbody>

			<tr class="even" style="background-color:#eee;">

				<td width="100%" ></td>

			</tr>

      </table> 

	  </div> ';

	  

$saldo = $saldo_anterior_sol + $toting - $totegr;



$html.='

<br />

<br />

<br />







<div id="div_tabla">

	<table id="tabla_resumen_todos" width="100%" class="">

           <thead>

			

			<tr class="" style="background-color:#3F729B;color:#fff" >

				<th align="center" colspan="6" >SALDOS FINALES</th>

			</tr>

			

			<tr class="header_row" style="font-weight:bold;font-size:16px;">

				<th align="center" width="25%" >SALDO ANTERIOR</th>

				<th align="center" width="25%" >INGRESOS TOTALES</th>

				<th align="center" width="25%" >EGRESOS TOTALES</th>

				<th align="center" width="25%" >SALDO FINAL</th>

			</tr>



			</thead>

			<tbody>	

			

			<tr class="" style="font-weight:bold;" >				

				<td width="25%" align="right" style="font-size:38px;" >'.formato_money($saldo_anterior_sol).'</td>												

				<td width="25%" align="right" style="font-size:38px;" >'.formato_money($toting).'</td>												

				<td width="25%" align="right" style="font-size:38px;" >'.formato_money($totegr).'</td>												

				<td width="25%" align="right" style="font-size:42px;" >'.formato_money($saldo).'</td>												

			</tr>

			

			</tbody>

			<tr class="even" style="background-color:#eee;">

				<td width="100%" ></td>

			</tr>

      </table>









</body>

</html>';



$pdf->writeHTML($html, true, 0, true, true);



//$pdf->write2DBarcode($ruc_empresa.'|'.$idcomprobante.'|'.$serie.'|'.$numero.'|'.$toigv.'|'.$importetotal.'|'.fecha_mysql($fecha).'|'.$idtipodni.'|'.$ruc.'|', 'QRCODE,Q', 157, 99, 40, 40, $style, 'N');



$pdf->Output($nombre_archivo, 'I');



