<?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/cuentacobrar_cst/cCuentacobrar_cst.php");

$oCuentacobrar_cst = new cCuentacobrar_cst();



 

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

$oIngreso = new cIngreso();

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

$oEmpresa = new cEmpresa();





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

$oMysql = new cMysql(); 



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

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





$dtsedi =  $oCuentacobrar_cst->mostrarUnoEdi($_GET['ediid']);



	$dts = mysql_fetch_array($dtsedi);

	$punven_id=$dts['tb_puntoventa_id'];

	$edi_nom=$dts['tb_edificio_nom'];

	$edi_diafec=$dts['tb_edificio_fecven'];

	$edi_mor=$dts['tb_edificio_mor'];

	$pptfla=$dts['tb_edificio_pptfla'];

	$pptpor=$dts['tb_edificio_pptpor'];

	$pptmanasc=$dts['tb_edificio_pptmanasc'];

	$tipcob=$dts['tb_edificio_tipcob'];

	$monigu=$dts['tb_edificio_monigu'];

	mysql_free_result($dtsedi);

	 



 $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); 



	$dts1 = $oCuentacobrar_cst->cuentas_por_cobrar($_GET['ediid']);

	$num_rows= mysql_num_rows($dts1); 





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

	

$title = "CUENTAS POR COBRAR EDIFICIO ".$edi_nom;

$nombre_archivo = 'CUENTASPORCOBRAR_EDIFICIO_'.$edi_nom.'_'.$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('L', '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="15%">

	<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">CUENTAS POR COBRAR <br/> EDIFICIO <br/>'.$edi_nom.' <br/></strong>

        </td>

    </tr>

</table>



<br />

<br />		

';

 

 

	$html.='

	<div id="div_tabla">

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

           <thead>

						

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

				<th width="6%" align="left">DEP.</th>

				<th width="25%" align="left">CLIENTE</th>

				<th width="8%" nowrap align="right">CUOTA ORD.</th>

				<th width="6%" align="right">LUZ</th>

				<th width="6%" align="right">AGUA</th>

				<th width="8%" nowrap align="right">AGUA COM.</th>

				<th width="10%" align="right">DEUDA / SALDO FAV.</th>

				<th width="7%" align="right">TOTAL</th>										

				<th width="8%" align="right">FECHA PAGO</th>										

				<th width="8%" align="right">MONTO PAGADO</th>										

				<th width="8%" align="right">FIRMA</th>										

			</tr>



			</thead>

			<tbody>	

		

		';

		

	

       if($num_rows>0){

		while($dt1 = mysql_fetch_array($dts1))

		{ 



			

			$montotot = $dt1['monto'];		

			$abonos = 0;

			$mone_id = $dt1['tb_moneda_id'];	

			//echo $dt1['tb_edificio_id'].'--'.$dt1['tb_departamento_id'];

			

			//echo $montotot.'-';

			$dts2 = $oCuentacobrar_cst->cuentas_por_cobrar_por_cliente10($dt1['tb_edificio_id'],$dt1['tb_departamento_id'],'1');

					

			while($dt2 = mysql_fetch_array($dts2))

			{

				

				$monto = $dt2['tb_ventapago_mon'];						

				$abonos = 0;

				$mone_id = $dt2['tb_moneda_id'];

				$mod_id=3;

				$est1=1;

				$est2=2;

								

				$dts3 = $oIngreso->mostrar_por_modulo($mod_id,$dt2['tb_ventapagoingresos_id'],$est1,$est2);

				$num_rows3= mysql_num_rows($dts3);

				while($dt3 = mysql_fetch_array($dts3))

				{

					$abonos+= $dt3['tb_ingreso_imp'];

				}

				

				mysql_free_result($dts3);

							

				$saldo = ($monto - $abonos);			

				

				$mora = 0;

				

				if($dt2['tb_edificio_mor']>0){

					$fecven = $dt2['tb_ventapago_fecven'];

					

					$dias	= (strtotime($fec)-strtotime(mostrarFecha($fecven)))/86400;

						if($dias<0){

							$dias=0;

						}

					$mora = $dias * $dt2['tb_edificio_mor'];

				}

				

				$dueda = $saldo + $mora;

				$totaldeuda += $dueda;

				

				

			$cuoord = $dt2['tb_venta_cuoord'];

			$luz = $dt2['tb_venta_luzcom'];

			$agua = $dt2['tb_venta_cosdep'];

			$cosagucom = $dt2['tb_venta_agucom'];

				

				

				

			} 

			mysql_free_result($dts2);

						

			if($mone_id==1){

					$lbl_mone = 'S/. ';

					$montototsol += $montotot;

			}else if($mone_id==2){

					$lbl_mone = 'US$. ';

					$montototdol += $montotot;

			}

			 

			 

			 $deu =  $montotot-$dueda;

			$salfav = $dt1['tb_departamento_salfav'];

	   

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

				<td width="6%" class="text-blue" align="left" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;"  > <strong> '. $dt1['tb_departamento_nom'].'</strong> </td>

				<td width="25%" class="text-blue" align="left" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" > <strong>'. $dt1['tb_cliente_nom'].'</strong> </td>				

				<td width="8%" nowrap align="right" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" ><strong>'.formato_money($cuoord) .'</strong></td>

				<td width="6%" nowrap align="right" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" ><strong>'.formato_money($luz).'</strong></td>

				<td width="6%" nowrap align="right" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" ><strong>'.formato_money($agua).'</strong></td>

				<td width="8%" nowrap align="right" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" ><strong>'.formato_money($cosagucom).'</strong></td>

				<td width="10%" nowrap align="right" style=" border-bottom: 0.9px solid #CC0000;border-right: 0.9px solid #CC0000;border-left: 0.9px solid #CC0000;border-top: 0.9px solid #CC0000;background-color:#CC0000;color:#fff;" ><strong>'.formato_money($deu).' / '.formato_money($salfav).'</strong></td>

				<td width="7%" nowrap align="right" style=" border-bottom: 0.9px solid #FF8800;border-right: 0.9px solid #FF8800;border-left: 0.9px solid #FF8800;border-top: 0.9px solid #FF8800;background-color:#FF8800;color:#fff;" ><strong>'.formato_money($montotot).'</strong></td>

				<td width="8%" nowrap align="right" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" ></td>

				<td width="8%" nowrap align="right" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" ></td>

				<td width="8%" nowrap align="right" style=" border-bottom: 0.9px solid #010101;border-right: 0.9px solid #010101;border-left: 0.9px solid #010101;border-top: 0.9px solid #010101;" ></td>



				

			</tr>'; 

			

		 }

		mysql_free_result($dts1);

		

		

    }else{ 

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

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

			</tr>'; 

	}

 	

		$html.='</tbody>

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

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

			</tr>

      </table> 

	  </div> ';



	



$html.='



</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');



