<?php



// ini_set('display_errors',1);



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



date_default_timezone_set('America/Lima');



session_start();

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

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

$oCompra = new cCompra();



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

$oEmpresa = new cEmpresa();



require_once ("../../app/venta/cVenta.php");

$oVenta = new cVenta();



require_once ("../../app/notacredito/cNotacredito.php");

$oNotacredito = new cNotacredito();



require_once("../../app/tipocambio/cTipocambio.php");

$oTipocambio = new ctipocambio();



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



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

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





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

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



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

	

	

	

	

	$tot = 0;

	

	$dts1 =	$oCompra->mostrar_xperiodo($_GET['mes'],$_GET['anio'],'2');

	while($dt = mysql_fetch_array($dts1)){

				

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

	$rs = $oTipocambio->consultar(fecha_mysql($dt['tb_compra_fec']));  

	$r = mysql_fetch_array($rs);	

	$tipcam = formato_money3($r['tb_tipocambio_dolsun']);

	}

	else{

	$tipcam = '1.00';	

	}

	

	$tot += $dt['tb_compra_tot'] * $tipcam;

	

	}

	

	$totvf = $tot;

	$totvalvenvf = $totvf/1.18;

	$totigvvf = $totvalvenvf * 0.18;

	



 

	

	

	//NOTAS DE CREDITOO

	$tot = 0;

	 

	$dts1 =	$oNotacredito->mostrar_xperiodo($_GET['mes'],$_GET['anio'],'2');

	while($dt = mysql_fetch_array($dts1)){

				

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

	$rs = $oTipocambio->consultar(fecha_mysql($dt['tb_notacredito_fec']));  

	$r = mysql_fetch_array($rs);	

	$tipcam = formato_money3($r['tb_tipocambio_dolsun']);

	}

	else{

	$tipcam = '1.00';	

	}

	

	$tot += $dt['tb_notacredito_tot'] * $tipcam;

	

	}

	

	$totvfnc = $tot;

	$totvalvenvfnc = $totvfnc / 1.18;

	$totigvvfnc = $totvalvenvfnc * 0.18;	

	

	

	//// VENTAAAAAAAS

	

	$tot = 0;

	

	$dts1 =	$oVenta->mostrar_xperiodo($_GET['mes'],$_GET['anio'],'2');

	while($dt = mysql_fetch_array($dts1)){

				

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

	$rs = $oTipocambio->consultar(fecha_mysql($dt['tb_venta_fec']));  

	$r = mysql_fetch_array($rs);	

	$tipcam = formato_money3($r['tb_tipocambio_dolsun']);

	}

	else{

	$tipcam = '1.00';	

	}

	

	$tot += $dt['tb_venta_tot'] * $tipcam;

	

	}

	

	$totvfv = $tot - $totvfnc;

	$totvalvenvfv = $totvfv / 1.18;

	$totigvvfv = $totvalvenvfv * 0.18;

	

	

 

 $difvfvalven = $totvalvenvf - $totvalvenvfv;

 $difvfigv = $totigvvf - $totigvvfv;

 $difvftot = $totvf - $totvfv;



 $i = $_GET['mes'];

    	                                                if($i=='01'){

															$lblmes = 'Enero';

														}else if($i=='02'){

															$lblmes = 'Febrero';

														}else if($i=='03'){

															$lblmes = 'Marzo';

														}else if($i=='04'){

															$lblmes = 'Abril';

														}else if($i=='05'){

															$lblmes = 'Mayo';

														}else if($i=='06'){

															$lblmes = 'Junio';

														}else if($i=='07'){

															$lblmes = 'Julio';

														}else if($i=='08'){

															$lblmes = 'Agosto';

														}else if($i=='09'){

															$lblmes = 'Septiembre';

														}else if($i=='10'){

															$lblmes = 'Octubre';

														}else if($i=='11'){

															$lblmes = 'Noviembre';

														}else if($i=='12'){

															$lblmes = 'Diciembre';

														}	

	

	

$title = "REPORTE | CONTABLE IGV COOLING - ".$fec;

$nombre_archivo = 'REPORTE | CONTABLE IGV COOLING '.$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, 'www.radiadorespenarrieta.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.infosispe.com');

$pdf->SetTitle($title);



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

$pdf->SetKeywords('www.infosispe.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:25px; }

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

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

	

</style>



<style media="print">

    .oculto{

        display: none;

    }



</style>

<body>





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

	<tr>

	<td width="22%">

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

	</td>

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

	

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

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

        <br />

        <br />

       

        </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">CONTABLE IGV<br>'.$lblmes.' | '.$_GET['anio'].'</strong>

        </td>

    </tr>

</table>



<br />

<br />		

';





 

	$html.='

	<div id="div_tabla">

		<table id="tabla_resumen_todos" width="100%" style="font-size:11px;" class="">

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

				<th class="bg-info" style="background-color:#b2ebf2;" ></th>

				<th class="bg-yellow"  style="background-color:#ffca28;"  colspan = "3" >COMPRAS</th>

				<th class="bg-green"   style="background-color:#26a69a;" colspan = "3"  >VENTAS</th>

				<th class="bg-blue"  style="background-color:#29b6f6;"  colspan = "3" >DIFERENCIAS</th>

			</tr>

			

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

				<th class="bg-info" style="background-color:#b2ebf2;" >EMPRESA</th>

				<th>VAL. IMP. GRAB.</th>

				<th>IGV</th>

				<th>TOTAL</th>

				<th>VAL. IMP. GRAB.</th>

				<th>IGV</th>

				<th>TOTAL</th>

				<th>VAL. IMP. GRAB.</th>

				<th>IGV</th>

				<th>TOTAL</th>

			</tr>

		  

		  

		  

		  <tr  class="header_row" >

			<td class="bg-info" style="background-color:#b2ebf2;" >SAC</td>			

			<td nowrap align="right" >'.formato_money($totvalvenvf).'</td>			

			<td nowrap align="right" >'.formato_money($totigvvf) .'</td>			

			<td nowrap align="right" >'.formato_money($totvf) .'</td>	

			<td nowrap align="right" >'.formato_money($totvalvenvfv) .'</td>			

			<td nowrap align="right" >'.formato_money($totigvvfv) .'</td>			

			<td nowrap align="right" >'.formato_money($totvfv) .'</td>

			<td nowrap align="right" >'.formato_money($difvfvalven) .'</td>			

			<td nowrap align="right" >'.formato_money($difvfigv) .'</td>			

			<td nowrap align="right" >'.formato_money($difvftot) .'</td>							

			</tr>

					

		</table> 

	  </div> ';





	  

	  if($_GET['vista']==1){

		  

		$html.='

		<div id="div_tabla">

			<table>

		<tr class="header_row">

		<th colspan="8" style="background-color:#4285F4;color:#fff;"  >DETALLES DE COMPRAS</th>

		</tr>

		

		 <tr class="header_row" >

                <th width="60" >FECHA</th>

                <th width="98" >DOCUMENTO</th>                    

                <th width="65" >RUC</th> 

				<th width="273" >PROVEEDOR</th>       

                <th width="52" NOWRAP class="" align="right">VALOR</th>

                <th width="52" NOWRAP class="" align="right">IGV</th>

                <th width="52" NOWRAP class="" align="right">TOTAL</th>

        </tr>

		';

		

		 

		$dtc1 = $oCompra->mostrar_detalle_agru($_GET['mes'],$_GET['anio'],'2');

		while($dtc = mysql_fetch_array($dtc1)){

		

		$dtc1d = $oCompra->mostrar_detalle_des($_GET['mes'],$_GET['anio'],$dtc['empid']);

		while($dt = mysql_fetch_array($dtc1d)){



		

		 $i = $dt['tb_compra_permes'];

    	                                                if($i=='01'){

															$lblmes = 'Enero';

														}else if($i=='02'){

															$lblmes = 'Febrero';

														}else if($i=='03'){

															$lblmes = 'Marzo';

														}else if($i=='04'){

															$lblmes = 'Abril';

														}else if($i=='05'){

															$lblmes = 'Mayo';

														}else if($i=='06'){

															$lblmes = 'Junio';

														}else if($i=='07'){

															$lblmes = 'Julio';

														}else if($i=='08'){

															$lblmes = 'Agosto';

														}else if($i=='09'){

															$lblmes = 'Septiembre';

														}else if($i=='10'){

															$lblmes = 'Octubre';

														}else if($i=='11'){

															$lblmes = 'Noviembre';

														}else if($i=='12'){

															$lblmes = 'Diciembre';

														}

														

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

				$rs = $oTipocambio->consultar(fecha_mysql($dt['tb_compra_fec']));  

				$r = mysql_fetch_array($rs);	

				$tipcam = formato_money3($r['tb_tipocambio_dolsun']);

		}

		else{

				$tipcam = '1.00';	

		}

		

		$valvenc = 0;

		$igvc = 0;

		$totc = 0;

		

		

		$valvenc = $dt['tb_compra_valven'] * $tipcam;

		$igvc = $dt['tb_compra_igv'] * $tipcam;

		$totc = $dt['tb_compra_tot'] * $tipcam;

		

		//if($dt['tb_empresa_id'] == 2){

			//echo $totc;

		//}

		

		

		$totalc  += $totc; 

		$igvtotalc  += $igvc; 

		$valventotalc  += $valvenc; 

		

		$html .='

		<tr>

		<td width="60" nowrap="nowrap">'. mostrarFecha($dt['tb_compra_fec']).'</td>

        <td width="98" >  '. $dt['tb_documento_abr'].' - '.$dt['tb_compra_numdoc'].'</td>

		

		<td width="65" nowrap="nowrap">'. $dt['tb_proveedor_doc'].'</td>

        <td width="273" NOWRAP >'. $dt['tb_proveedor_nom'].'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($valvenc).'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($igvc).'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($totc).'</td>

		</tr>

		';

		

		

		} 

		$html.='

		<tr class="bg-blue" style="background-color:#b2dfdb;" >

		<td colspan="4" align="left">'.$dtc['emp'].'</td>

		<td NOWRAP align="right" >'.formato_money($valventotalc).'</td>

		<td NOWRAP align="right" >'.formato_money($igvtotalc).'</td>

		<td NOWRAP align="right" >'.formato_money($totalc).'</td>

		</tr>

		';

				

		$totalc  = 0;

		$igvtotalc  = 0;

		$valventotalc  = 0;

		}

		

		

		mysql_free_result($dtc1);

		$html .='</table>

		</div>

		' ; 		  

	  }

	  	  

	    

	  if($_GET['vista']==1){

		  

		$html.='

		<div id="div_tabla">

		<table>

		<tr class="header_row" >

		<th colspan="8" style="background-color:#4285F4;color:#fff;" >DETALLES DE VENTAS</th>

		</tr>

		

		 <tr class="header_row" >

               <th width="60" >FECHA</th>

                <th width="98" >DOCUMENTO</th>                    

                <th width="65" >RUC</th> 

				<th width="273" >PROVEEDOR</th>             

                              

                <th width="52" NOWRAP class="" align="right">VALOR</th>

                <th width="52" NOWRAP class="" align="right">IGV</th>

                <th width="52" NOWRAP class="" align="right">TOTAL</th>

        </tr>

		';

		

		$dtc1 = $oVenta->mostrar_detalle_agru($_GET['mes'],$_GET['anio'],'2'); 

		while($dtc = mysql_fetch_array($dtc1)){

		

		$dtc1d = $oVenta->mostrar_detalle_des($_GET['mes'],$_GET['anio'],$dtc['empid']);

		while($dt = mysql_fetch_array($dtc1d)){



		

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

				$rs = $oTipocambio->consultar(fecha_mysql($dt['tb_venta_fec']));  

				$r = mysql_fetch_array($rs);	

				$tipcam = formato_money3($r['tb_tipocambio_dolsun']);

		}

		else{

				$tipcam = '1.00';	

		}

		

		

		$valvenv = 0;

		$igvv = 0;

		$totv = 0;

		

		$valvenv = $dt['tb_venta_valven'] * $tipcam;

		$igvv = $dt['tb_venta_igv'] * $tipcam;

		$totv = $dt['tb_venta_tot'] * $tipcam;

		

		$totalv  += $totv; 

		$igvtotalv  += $igvv; 

		$valventotalv  += $valvenv; 

		

		

		$html .='

		<tr>

		<td width="60" nowrap="nowrap">'. mostrarFecha($dt['tb_venta_fec']).'</td>

        <td width="98" >  '. $dt['tb_documento_abr'].' - '.$dt['tb_venta_numdoc'].'</td>

        <td width="65" nowrap="nowrap">'. $dt['tb_cliente_doc'].'</td>

		<td width="273" NOWRAP >'. $dt['tb_cliente_nom'].'</td>		

		 <td width="52" NOWRAP align="right">'.''.formato_money($valvenv).'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($igvv).'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($totv).'</td>

		</tr>

		';

		

		

		} 

		$html.='

		<tr class="bg-blue" style="background-color:#b2dfdb;" >

		<td colspan="4" align="left">'.$dtc['emp'].'</td>

		<td NOWRAP align="right" >'.formato_money($valventotalv).'</td>

		<td NOWRAP align="right" >'.formato_money($igvtotalv).'</td>

		<td NOWRAP align="right" >'.formato_money($totalv).'</td>

		</tr>

		';

				

		$totalv  = 0;

		$igvtotalv  = 0;

		$valventotalv  = 0;

		}

		

		

		mysql_free_result($dtc1);

		$html .='</table>

		

		

		

		

		

		

		

		

		

		

		</div>

		' ; 		  

	  }

	  

	  

	  

	  

	  

	  

	    if($_GET['vista']==1){

		  

		$html.='

		<div id="div_tabla">

		<table>

		<tr class="header_row" >

		<th colspan="8" style="background-color:#FF8800;color:#fff;" >DETALLES DE NOTAS DE CREDITO</th>

		</tr>

		

		 <tr class="header_row" >

                <th width="60" >FECHA</th>

                <th width="98" >DOCUMENTO</th>                    

                <th width="65" >RUC</th> 

				<th width="273" >PROVEEDOR</th>                                    

                <th width="52" NOWRAP class="" align="right">VALOR</th>

                <th width="52" NOWRAP class="" align="right">IGV</th>

                <th width="52" NOWRAP class="" align="right">TOTAL</th>

        </tr>

		';

		

		$dtc1 = $oNotacredito->mostrar_detalle_agru($_GET['mes'],$_GET['anio'],'2'); 

		while($dtc = mysql_fetch_array($dtc1)){

		

		$dtc1d = $oNotacredito->mostrar_detalle_des($_GET['mes'],$_GET['anio'],$dtc['tb_empresa_id']);

		while($dt = mysql_fetch_array($dtc1d)){



		

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

				$rs = $oTipocambio->consultar(fecha_mysql($dt['tb_notacredito_fec']));  

				$r = mysql_fetch_array($rs);	

				$tipcam = formato_money3($r['tb_tipocambio_dolsun']);

		}

		else{

				$tipcam = '1.00';	

		}

		

		

		$valvenv = 0;

		$igvv = 0;

		$totv = 0;

		

		$totv = $dt['tb_notacredito_tot'] * $tipcam;	

		$valvenv = $totv/1.18;

		$igvv = $valvenv* 0.18;

		

		$totalv  += $totv; 

		$igvtotalv  += $igvv; 

		$valventotalv  += $valvenv; 

		

		

		$html .='

		<tr>

		<td width="60" nowrap="nowrap">'. mostrarFecha($dt['tb_notacredito_fec']).'</td>

        <td width="98" >  '. $dt['tb_documento_abr'].' - '.$dt['tb_notacredito_numdoc'].'</td>

		<td width="65" nowrap="nowrap">'. $dt['tb_cliente_doc'].'</td>

        <td width="273" NOWRAP >'. $dt['tb_cliente_nom'].'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($valvenv).'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($igvv).'</td>

		 <td width="52" NOWRAP align="right">'.''.formato_money($totv).'</td>

		</tr>

		';

		

		

		} 

		$html.='

		<tr class="bg-blue" style="background-color:#b2dfdb;" >

		<td colspan="4" align="left">'.$dtc['tb_empresa_razsoc'].'</td>

		<td NOWRAP align="right" >'.formato_money($valventotalv).'</td>

		<td NOWRAP align="right" >'.formato_money($igvtotalv).'</td>

		<td NOWRAP align="right" >'.formato_money($totalv).'</td>

		</tr>

		';

				

		$totalv  = 0;

		$igvtotalv  = 0;

		$valventotalv  = 0;

		}

		

		

		mysql_free_result($dtc1);

		$html .='</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');



?>



