<?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/canjeproveedor/cCanjeproveedor.php");

$oCanjeproveedor = new cCanjeproveedor();



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

$oEgreso = new cEgreso();



require_once ("../../app/compra/cComprapago.php");

$oComprapago = new cComprapago();



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

$oEmpresa = new cEmpresa();





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

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



	$dts=$oCanjeproveedor->mostrar_uno($_GET['canproid']);

	$dt = mysqli_fetch_array($dts);

	$emp=$dt['tb_empresa_id'];

	$rucemp=$dt['tb_empresa_ruc'];

	$nomcom=$dt['tb_empresa_nomcom'];

	$nompro=$dt['tb_proveedor_nom'];

	$doc=$dt['tb_proveedor_doc'];

	$rep = $dt['tb_canjeproveedor_aval'];

	$fecgiro = $dt['tb_canjeproveedor_fec'];

	$mon =  $dt['tb_canjeproveedor_mon'];

	

	if($dt['tb_moneda_id']==1){

	$lblmon = 'S/';

	}else if($dt['tb_moneda_id']==2){

	$lblmon = 'US$';

	}





mysqli_free_result($dts);



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

$dt = mysqli_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'];		

mysqli_free_result($dts);



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

	

$title = "REPORTE | CANJE DE LETRAS PROVEEDORES - ".$fec;

$nombre_archivo = 'REPORTE | CANJE DE LETRAS PROVEEDORES '.$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->write1DBarcode('', 'C128', '', 273, '', 6, 0.3, $style, 'N');

      $this->Cell(0, 0, 'www.grupovyf.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(12, 15, 12);// 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;

    }

    .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: left" width="50%">

		<br />

		<br />

		<br />

            <strong style="font-size:35px">'.$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 />

		<br />

		   <strong style="font-size: 40px">FINANCIAMIENTO<br>

			<br></strong>

        </td>

    </tr>

</table>



<br />

<br />	



<table width="100%">

    <tr>

        <td style="text-align: left;font-weight:bold;" width="10%">GIRADOR</td>

        <td style="text-align: left" width="1%">:</td>

        <td style="text-align: left" width="49%">'.$doc.' | '.$nompro.'</td>



        <td style="text-align: left;font-weight:bold;" width="10%">FECHA GIRO</td>

        <td style="text-align: left" width="1%">:</td>

        <td style="text-align: left" width="19%">'.mostrarFecha($fecgiro).'</td>

    </tr>

    <tr>

        <td style="text-align: left;font-weight:bold;" width="10%">ACEPTANTE</td>

        <td style="text-align: left" width="1%">:</td>

        <td style="text-align: left" width="49%">'.$rucemp.' | '.$nomcom.'</td>



        <td style="text-align: left;font-weight:bold;" width="10%">AVAL</td>

        <td style="text-align: left" width="1%">:</td>

        <td style="text-align: left" width="30%">'.$rep.'</td>

    </tr>

    <tr>

        <td style="text-align: left;font-weight:bold;vertical-align:top;" width="10%">MONTO</td>

        <td style="text-align: left; vertical-align:top;" width="1%">:</td>

        <td style="text-align: left" width="59%">'.formato_money($mon).'</td>

    </tr>

</table>





<br />	

<br />	

	

';





$dts1 = $oCanjeproveedor->mostrar_filtro_documento($_GET['canproid']);

$num_rows= mysqli_num_rows($dts1);

		

	$html.='

	<div id="div_tabla">

	<table width="85.5%" id="tabla_resumen_todos" class="table table-bordered table-striped">

           <thead>

			

			<tr class="" style="font-weight:bold;font-size:35px;background-color:red;color:#fff;">

				<th  >DOCUMENTOS CANJEADOS</th>

			</tr>

			

			<tr class="" style="font-weight:bold;font-size:30px;background-color:#eee;">

				<th width="100" align="center" >DOCUMENTO</th>

				<th width="80" align="center" >NUMERO</th>

				<th width="80" align="center" >EMISION</th>

				<th width="80" align="center" >VENCIMIENTO</th>					

				<th width="35" align="center" >BAN</th>				

				<th width="72" align="center" >NUM. UNI.</th>	

				<th width="38" align="center" >MO</th>	

				<th width="73" align="center" >FINANCIADO</th>					

			</tr>



			</thead>

			<tbody>	

		

		';

		

		if($num_rows>0){

			

		while($dt = mysqli_fetch_array($dts1))

		{ 			

	

			$fec	= mostrarFecha($dt['tb_compra_fec']);

			$numdoc	= $dt['tb_compra_numdoc'];

			$docnom = $dt['tb_documento_abr'];

			$tot = $dt['tb_compra_tot'];

			



			$total_abonos = 0;

			$saldo = 0;

			$total_monto = 0;

	   		$dts2=$oComprapago->filtrar($dt['tb_compra_id']);

       

       		



			$saldo = $dt['tb_comprapago_mon'];

			

			if($dt['tb_comprapago_fecven']!='0000-00-00'){

				$fecven = $dt['tb_comprapago_fecven'];

			}else{

				$fecven='';

			}	

			

			if($dt['tb_banco_id']==0){

				$ban = '';

			}else if($dt['tb_banco_id']==1){

				$ban = 'BCP';

			}else if($dt['tb_banco_id']==2){

				$ban = 'BBVA';

			}else if($dt['tb_banco_id']==3){

				$ban = 'SCT';

			}

			

			

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

				<td width="100" align="left">'. $dt['tb_documento_nom'].'</td>

				<td width="80" align="right">'. $dt['tb_compra_numdoc'].'</td>					

				<td width="80" align="center">'. mostrarFecha($fec).'</td>					

				<td width="80" align="center">'. mostrarFecha($fecven) .'</td>																	

				<td width="35" align="center" >'. $ban.'</td>					

				<td width="72" align="center" >'. $dt['tb_comprapago_numuni'].'</td>

				<td width="38" align="center" ><strong>'.$lblmon.'</strong></td>				

				<td width="72" align="right" ><strong>'.formato_money($dt['tb_comprapago_mon']).'</strong></td>				           

			</tr>';

		

		$total_saldo += $saldo; 

		} 

		mysqli_free_result($dts1); 

		

		}else{		

		$html.='<tr>

			<td colspan="12" align="center" >No hay datos.</td>

			</tr>';

		}

		

		$html.='</tbody>

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

			

				<td align="left">'.$num_rows.' registros</td>

				<td colspan="6" >IMPORTE CANJEADO</td>

				<td nowrap colspan="2" align="right" >'.$lblmon.'<strong>'.formato_money($total_saldo).'</strong> 

				</td>

			</tr>

      </table> 

	  </div> ';





	  

	  

	  



 

$dts1 = $oCanjeproveedor->mostrar_filtro_letra($_GET['canproid']);

$num_rows= mysqli_num_rows($dts1);

 

	$html.='

	<div id="div_tabla"  >

	<table width="82.3%" id="tabla_resumen_todos" class="table table-bordered table-striped">

           <thead>

			

			<tr class="" style="font-weight:bold;font-size:35px;background-color:red;;color:#fff;">

				<th colspan="13" >LETRAS DE CAMBIO</th>

			</tr>

			<!--

			<tr class="" style="font-weight:bold;font-size:30px;background-color:#eee;">

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

				<th colspan="2" align="center" >FECHAS</th>

				<th >M</th>

				<th colspan="2" align="center" >UBICACION</th>

				<th width="40" align="center" nowrap ></th>

				<th nowrap >TOTAL</th>

				<th nowrap >A RE.</th>

				<th nowrap >SALDO</th>

			</tr>

				-->

			<tr class="" style="font-weight:bold;font-size:30px;background-color:#eee;">

				<th width="100" align="center" >DOCUMENTO</th>

				<th width="70" align="center" >NUMERO</th>

				<th width="70" align="center" >EMISION</th>

				<th width="75" align="center" >VENC</th>					

				<th width="38" align="center" >BAN</th>				

				<th width="75" align="center" >NUM. UNI.</th>	

				<th width="38" align="center" >MO</th>					

				<th width="70" align="center" >IMPORTE</th>										

			</tr>



			</thead>

			<tbody>	

		

		';

		

		if($num_rows>0){

			

		while($dt1 = mysqli_fetch_array($dts1))

		{ 			

			$mone_id = $dt1['tb_moneda_id'];	

		

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

			$totalapagar += $dt1['tb_comprapago_mon']-$dt1['tb_comprapago_liq'];

			

			

			if($dt1['tb_banco_id']==0){

				$ban = '';

			}else if($dt1['tb_banco_id']==1){

				$ban = 'BCP';

			}else if($dt1['tb_banco_id']==2){

				$ban = 'BBVA';

			}else if($dt1['tb_banco_id']==3){

				$ban = 'SCT';

			}

			

			if($dt1['tb_comprapago_fecven']!='0000-00-00'){

				$fecven = $dt1['tb_comprapago_fecven'];

			}else{

				$fecven='';

			}

			

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

				<td width="100" align="left">'. $dt1['tb_documento_nom'].'</td>

				<td width="70" align="right">'. $dt1['tb_compra_numdoc'].'</td>					

				<td width="70" align="center">'. mostrarFecha($dt1['tb_compra_fec']).'</td>					

				<td width="75" align="center">'. mostrarFecha($fecven) .'</td>																

				<td width="38" align="center" >'. $ban.'</td>					

				<td width="75" align="center" >'. $dt1['tb_comprapago_numuni'].'</td>

				<td width="38" align="center" ><strong>'.$lblmon.'</strong></td>					

				<td width="70" align="right" ><strong>'.formato_money($dt1['tb_comprapago_mon']).'</strong></td>								           								           

			</tr>';

		

		

		

		} 

		mysqli_free_result($dts1); 

		

		}else{		

		$html.='<tr>

			<td colspan="13" align="center" >No hay cuentas por pagar.</td>

			</tr>';

		}

		

		$html.='</tbody>

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

			

				<td colspan = "2"align="left">'. $num_rows.' registros</td>

				<td colspan="4" >TOTAL</td>

				<td nowrap colspan="2" align="right" >'.$lblmon.' <strong>'.formato_money($total).'</strong> 

				</td>

				

			</tr>

      </table> 

	  </div> ';



	  

	  

	  

	  

	  

	  

 

	  

	  

$html.='

<br />

<br />

<br />



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



