<?php



// ini_set('display_errors',1);



session_start();

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

require_once ("../cuentapagada/cCuentapagada.php");

$oCuentapagada = new cCuentapagada();

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

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

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



?>



<style>

	div#div_tabla { margin: 0 0; }

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

	div#div_tabla table td, div#div_tabla table th { border: 1px solid #eee; padding: 2px 3px; font-size:15px; }

	div#div_tabla table th { height:18px }

	div#div_tabla table td { height:17px }

</style>



<section class="content" id="table" style="min-height:0px;padding-bottom:0px;margin-bottom:-30px;">

  <div class="row">

    <div class="col-xs-12">

      <div class="box">

        <div class="box-body" id="div_tabla_proveedores">

		

		<a  class="btn btn-sm" style="background-color:#00897b;color:#fff;text-align:left" 

		href="../../files/cuentapagada/cuentapagadaconsolidadasfecha_impcpe_doc.php?com=<?php echo $_POST['com'] ?>&comope=<?php echo $_POST['comope']?>

		&comven=<?php echo $_POST['comven'] ?>&comfec1=<?php echo $_POST['comfec1'] ?>&comfec2=<?php echo $_POST['comfec2']?>&comasc=<?php echo $_POST['comasc']?>

		&comdesc=<?php echo $_POST['comdesc'] ?>&letra=<?php echo $_POST['letra'] ?>&letraope=<?php echo $_POST['letraope']?>&letraven=<?php echo $_POST['letraven']?>

		&letrafec1=<?php echo $_POST['letrafec1'] ?>&letrafec2=<?php echo $_POST['letrafec2'] ?>&letraasc=<?php echo $_POST['letraasc']?>&letradesc=<?php echo $_POST['letradesc'] ?>" 

		target="_blank"><i class="fa fa-file-pdf-o"></i>  DESCARGAR E IMPRIMIR PDF</a>	



	

	<?php 



 if($_POST['com']==1){

	

$tip = 1;



if($_POST['comope']!==""){

	$por = '1';

}else if($_POST['comven']!==""){

	$por = '2';

}



if($_POST['comasc']!==""){

	$ord = '1';

}else if($_POST['comdesc']!==""){

	$ord = '2';

}



$dtsa = $oCuentapagada->cuentas_pagada_reporte_agru('','',$tip,$por,fecha_mysql($_POST['comfec1']),fecha_mysql($_POST['comfec2']),$ord);

$num_rows= mysql_num_rows($dtsa);

 

?>



        	<div class="table-responsive" id="div_tabla">

			 

			<div class="col-lg-12 col-xs-12" style="height:10px;"></div>

			 

          <table id="tabla_resumen_todos" class="table table-bordered table-striped">

           <thead>

			

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

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

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

				<th colspan="3" >UBICACION</th>

				<th nowrap ></th>

				<th nowrap >TOTAL</th>

				<th nowrap colspan="12" class="bg-yellow" >DETALLES DEL PAGO</th>

			</tr>

				

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

				<th>PROVEEDOR</th>

				<th>EMPRESA</th>

				<th>TIPO</th>

				<th>NUMERO</th>

				<th>EMISION</th>

				<th>VENCIMIENTO</th>						

				<th>BANCO</th>				

				<th>NUM. UNI.</th>	

				<th>CONDICION</th>	

				<th>MONEDA</th>	

				<th>IMPORTE</th>					

				

				<th>MODO</th>

				<th>DIAS</th>				

				<th>OPERACION</th>						

				<th>BANCO ORIGEN</th>					

				<th>CUENTA</th>					

				<th>BANCO DESTINO</th>					

				<th>CUENTA</th>					

				<th>CUENTA PROVEEDOR</th>										

				<th>NRO OPERACION</th>					

				<th>GASTOS OPERACION</th>					

				<th>PAGADO</th>					

				<th>RESPONSABLE</th>					

			</tr>



		</thead>

         <tbody>	

		<?php

		if($num_rows>0){

		

		while($dta = mysql_fetch_array($dtsa))

		{ 			

		

		$dts1 = $oCuentapagada->cuentas_pagada_reporte('','',$tip,$por,fecha_mysql($dta['fecha']),fecha_mysql($dta['fechaven']),$ord,$dta['con']);

		$num_rowsf= mysql_num_rows($dts1);

		while($dt1 = mysql_fetch_array($dts1))

		{

		

			$mone_id = $dt1['mon'];	

			

			$total = $dt1['tb_comprapago_mon'];

			if($mone_id==1){

					$lbl_mone = 'S/ ';

			}else if($mone_id==2){

					$lbl_mone = 'US$ ';

			}

						

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

				$fecven = mostrarFecha($dt1['tb_comprapago_fecven']);

				$dias = dias_transcurridos($dt1['tb_egreso_fec'],$dt1['tb_comprapago_fecven']);

				if($dias<0){

					$dias = 0;

				}else{

					$dias = $dias ;

				}

			}else{

				$fecven='E/CONTADO';

				$dias = '';

			}

			

					if($dt1['tb_comprapago_con']==1){

			$con = 'COBRANZAS';

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

			$con = 'DESCUENTOS';

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

			$con = 'CARTERAS';

		}else if($dt1['tb_comprapago_con']==0){

			$con = 'SIN CONDICION';

		}

		

			

			

			if($dt1['tb_banco_ori']==1){

			$banori = 'BCP';

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

			$banori = 'BBVA';

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

			$banori = 'SCT';

		}else if($dt1['tb_banco_ori']==4){

			$banori = 'CMA TRUJILLO';

		}else if($dt1['tb_banco_ori']==5){

			$banori = 'CMA PIURA';

		}



		if($dt1['tb_banco_des']==1){

			$bandes = 'BCP';

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

			$bandes = 'BBVA';

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

			$bandes = 'SCT';

		}else if($dt1['tb_banco_des']==4){

			$bandes = 'CMA TRUJILLO';

		}else if($dt1['tb_banco_des']==5){

			$bandes = 'CMA PIURA';

		}

		

		if($dt1['tb_egreso_modo']==1){

			$mod = 'EFECTIVO';

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

			$mod = 'DEPOSITO';

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

			$mod = 'TRANSFERENCIA';

		}else if($dt1['tb_egreso_modo']==4){

			$mod = 'CHEQUE';

		}

			

			

			

		?>

			<tr class="even" data-dat = "<?php echo $dt1['tb_proveedor_id'].'- E'.$dt1['tb_empresa_id']; ?>"  data-comid ="<?php echo $dt1['tb_compra_id']?>" >

				<td align="left" nowrap ><?php echo $dt1['tb_proveedor_alias']?></td>

				<td align="left"><?php echo $dt1['tb_empresa_nomcom']?></td>

				<td align="left"><?php echo $dt1['tb_documento_abr']?></td>

				<td align="left" nowrap ><?php echo $dt1['tb_compra_numdoc']?></td>					

				<td nowrap align="left"><?php echo mostrarFecha($dt1['tb_compra_fec']) ?></td>	

				<td align="left"><?php echo $fecven ?></td>	

									

								

																

				<td align="left"><?php echo ''; ?></td>					

				<td align="left" nowrap ><?php echo $dt1['tb_comprapago_numuni']; ?></td>

				<td align="left" nowrap ><?php echo $con; ?></td>

				<td align="left"> <strong> <?php echo $lbl_mone; ?> </strong> </td>					

				<td align="right"><strong> <?php echo formato_money($dt1['tb_comprapago_mon']); ?> </strong> </td>					

				

				<td align="left"><?php echo $mod ; ?></td>

				<td align="left"><?php echo $dias ; ?></td>

				<td align="left"><?php echo mostrarFecha($dt1['tb_egreso_fec']); ?></td>

				<td align="left"><?php echo $banori ; ?></td>							

				<td align="left"><?php echo $dt1['tb_cuenta_ori'] ; ?></td>							

				<td align="left"><?php echo $bandes ; ?></td>							

				<td align="left"><?php echo $dt1['tb_cuenta_des'] ; ?></td>							

				<td align="left" nowrap ><?php echo $dt1['tb_proveedorcuenta_nrocue'] ; ?></td>							

											

				<td align="right" nowrap ><?php echo $dt1['tb_egreso_nroope'] ; ?></td>							

				<td align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_gasope']) ; ?></td>							

				<td align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_val']) ; ?></td>							

				<td align="left" nowrap ><?php echo $dt1['tb_egreso_cob'] ; ?></td>									           

			</tr>

		<?php 	

		

		} 

			

		

		if($por==1){

			$lbl = 'TOTAL DE PAGOS SEGUN FECHA DE OPERACION : ';

			$fe = mostrarFecha($dta['fecha']);

		}else if($por==2){

			$fe = mostrarFecha($dta['fechaven']);

			$lbl = 'TOTAL DE PAGOS SEGUN FECHA DE VENCIMIENTO : ';

		}

		

		

		?>

		<tr class="" style="background-color:#80cbc4;" >

		<td colspan="7" align="right" ><?php echo $lbl; ?> <strong><?php echo $fe ?></strong> </td>

		<td colspan="16" align="right" > <strong><?php echo 'S/ '.formato_money($dta['soles'])?></strong> <span> | </span> <strong><?php echo 'US$ '.formato_money($dta['dolares'])?></strong> </td>

		</tr>

		<?php 

		}

		$con = '';

		mysql_free_result($dts1); 

		

		}else{

			?>

			

			<tr>

			<td colspan="21" align="center" >No hay cuentas pagadas.</td>

			</tr>

			

			<?php 			

		}

		

	?>

		</tbody>



      </table>

	  	

	    </div>

 <?php 

 }

 ?>

   

	

	<?php 

	

 if($_POST['letra']==1){

	

$tiplet = 2;



if($_POST['letraope']!==""){

	$porlet = '1';

}else if($_POST['letraven']!==""){

	$porlet = '2';

}



if($_POST['letraasc']!==""){

	$ordlet = '1';

}else if($_POST['letradesc']!==""){

	$ordlet = '2';

}

 

 //echo fecha_mysql($_POST['letrafec1']).'--'.fecha_mysql($_POST['letrafec2']);

 

$dtsa = $oCuentapagada->cuentas_pagada_reporte_agru('','',$tiplet,$porlet,fecha_mysql($_POST['letrafec1']),fecha_mysql($_POST['letrafec2']),$ordlet);

$num_rows= mysql_num_rows($dtsa);

 

?>



        	 <div class="table-responsive" style="" id="div_tabla">

			 

			  <div class="col-lg-12 col-xs-12" style="height:10px;"></div>

			  

          <table id="tabla_resumen_todos" class="table table-bordered table-striped">

           <thead>

			

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

				<th nowrap colspan="8" align="center" >DETALLES DOCUMENTO</th>

				<th nowrap colspan="3" align="center" >UBICACION</th>

				<th nowrap colspan="4" align="center" >PAGO</th>

				<th nowrap colspan="9" align="center" >GASTOS INTERESES</th>

				<th nowrap colspan="3" align="center" >RENOVACION</th>

				<th nowrap colspan="4" align="center" >TOTAL</th>				

			</tr>

				

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

				<th nowrap align="center" >PROVEEDOR</th>

				<th nowrap align="center" >E</th>

				<th nowrap align="center" >T.D.</th>

				<th nowrap align="center" >NUMERO</th>

				<th nowrap align="center" >EMISION</th>

				<th nowrap align="center" >VCTO</th>				

				<th nowrap align="center" >M</th>								

				<th nowrap align="center" >IMPORTE</th>

				

				<th nowrap align="center" >BAN</th>

				<th nowrap align="center" >CONDICION</th>

				<th nowrap align="center" >NUM. UNI.</th>

				

				<th nowrap align="center" >MODO</th>

				<th nowrap align="center" >FECHA OP.</th>

				<th nowrap align="center" >a)</th>

				<th nowrap align="center" >Nº OP.</th>

				

				<th nowrap align="center" >b)</th>

				<th nowrap align="center" >c)</th>

				<th nowrap align="center" >d)</th>

				<th nowrap align="center" >e)</th>

				<th nowrap align="center" >f)</th>

				<th nowrap align="center" >j)</th>

				<th nowrap align="center" >h)</th>

				<th nowrap align="center" >i)</th>

				<th nowrap align="center" >j)</th>

				

				<th nowrap align="center" >NUEVO IMPORTE)</th>

				<th nowrap align="center" >NUEVA FECHA</th>

				<th nowrap align="center" >k)</th>

				

				<th nowrap align="center" >TASA</th>

				<th nowrap align="center" >ITF</th>

				<th nowrap align="center" >AMORT.</th>

				<th nowrap align="center" >IMPORTE PAGADO</th>								

			</tr>



		</thead>

         <tbody>	

		<?php

		if($num_rows>0){

			

		while($dta = mysql_fetch_array($dtsa))

		{ 			

	

		 $dts1 = $oCuentapagada->cuentas_pagada_reporte('','',$tiplet,$porlet,fecha_mysql($dta['fecha']),fecha_mysql($dta['fechaven']),$ordlet,$dta['con']);

		 $num_rowsf= mysql_num_rows($dts1);

		 while($dt1 = mysql_fetch_array($dts1))

		{

			

			$mone_id = $dt1['mon'];	

		

			$total = $dt1['tb_comprapago_mon'];

			

			if($mone_id==1){

					$lbl_mone = 'S/ ';

			}else if($mone_id==2){

					$lbl_mone = 'US$ ';

			}

		

			

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

				$ban = '';

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

				$ban = 'BCP';

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

				$ban = 'BBVA';

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

				$ban = 'SCT';

			}



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

				$fecven = mostrarFecha($dt1['tb_comprapago_fecven']);

				$dias = dias_transcurridos($dt1['tb_egreso_fec'],$dt1['tb_comprapago_fecven']);

				if($dias<0){

					$dias = 0;

				}else{

					$dias = $dias ;

				}

			}else{

				$fecven='E/CONTADO';

				$dias = '';

			}

			

			

  if($dt1['tb_egreso_modo']==1){

    $egretip = 'CANCELACION';

	$nvofec = '';

	$diapro = '';

	

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

    $egretip = 'AMORTIZACION';

	$nvofec = mostrarFecha($dt1['tb_egreso_nvofecven']);

	$diapro = $dt1['tb_egreso_diapro'];

  }

  

		if($dt1['tb_comprapago_con']==1){

			$con = 'COBRANZAS';

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

			$con = 'DESCUENTOS';

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

			$con = 'CARTERAS';

		}else if($dt1['tb_comprapago_con']==0){

			$con = 'SIN CONDICION';

		}



			?>

			<tr class="even" data-dat = "<?php echo $dt1['tb_proveedor_id'].'- E'.$dt1['tb_empresa_id']; ?>"  data-comid ="<?php echo $dt1['tb_compra_id']?>" >

				

				<td align="left" nowrap ><?php echo $dt1['tb_proveedor_alias']?></td>

				<td align="left" nowrap ><?php echo $dt1['tb_empresa_nomcom']?></td>

				<td align="left" nowrap ><?php echo $dt1['tb_documento_abr']?></td>

				<td align="left" nowrap ><?php echo $dt1['tb_compra_numdoc']?></td>	

				<td align="left" nowrap ><?php echo mostrarFecha($dt1['tb_compra_fec']); ?></td>					

				<td align="left" nowrap ><?php echo $fecven; ?></td>

				<td align="left" nowrap > <strong> <?php echo $lbl_mone; ?> </strong> </td>				

				<td align="right" nowrap ><strong> <?php echo formato_money($dt1['tb_comprapago_mon']); ?> </strong> </td>								

				

				<td align="left" nowrap ><?php echo $ban; ?></td>

				<td align="left" nowrap ><?php echo $con; ?></td>

				<td align="left" nowrap ><?php echo $dt1['tb_comprapago_numuni']; ?></td>

				

				<td nowrap align="left"><?php echo $egretip; ?></td>

				<td nowrap align="left"><?php echo mostrarFecha($dt1['tb_egreso_fec'])?></td>				

				<td nowrap align="left"><?php echo $dt1['tb_egreso_diamora']; ?></td>

				<td nowrap align="left"><?php echo $dt1['tb_egreso_nroope'];?></td>

				

				<td nowrap align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_intven']); ?></td>

				<td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_intmora']); ?></td>			

				<td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_intcom']); ?></td>			

				<td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_gaspro']); ?></td>			

				<td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_compro']); ?></td>

				<td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_intade']); ?></td>							

				<td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_gasope']); ?></td>

				<td nowrap align="right"><?php echo formato_money($dt1['tb_egreso_por']); ?></td>

				<td align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_comdeval']); ?></td>	

						

				<td align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_nvoimp']); ?></td>			

				<td align="left" nowrap ><?php echo $nvofec; ?></td>

				<td align="left" nowrap ><?php echo $diapro; ?></td>

				<td align="left" nowrap ><?php echo formato_money($dt1['tb_egreso_tas']) .' %'; ?></td>	

				<td align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_itf']); ?></td>

				<td align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_amor']); ?></td>					

				<td align="right" nowrap ><?php echo formato_money($dt1['tb_egreso_val']); ?></td>			

				        

			</tr>

		<?php 

			

		}

		

		

		if($porlet==1){

			$lbl = 'TOTAL DE PAGOS SEGUN FECHA DE OPERACION : ';

			$fe = mostrarFecha($dta['fecha']);

		}else if($porlet==2){

			$fe = mostrarFecha($dta['fechaven']);

			$lbl = 'TOTAL DE PAGOS SEGUN FECHA DE VENCIMIENTO : ';

		}

		

		

		?>

		<tr class="" style="background-color:#80cbc4;" >

		<td colspan="7" align="right" ><?php echo $lbl ?> <strong><?php echo $fe ?></strong></td>

		<td colspan="24" align="right" > <strong><?php echo 'S/ '.formato_money($dta['soles'])?></strong> <span> | </span> <strong><?php echo 'US$ '.formato_money($dta['dolares'])?></strong> </td>

		</tr>

		<?php 

		$con = '';

		}

		mysql_free_result($dts1); 

		

		}else{

			?>

			

			<tr>

			<td colspan="30" align="center" >No hay cuentas pagadas.</td>

			</tr>

			

			<?php 			

		}

		

	?>

		</tbody>

			

      </table>

	   



	   </div>

 <?php 

 }

 ?>

	

	

	

	</div>

  </div>

</div>

</div>

</section>