<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("../compra/cComprapago.php");
$oComprapago = new cComprapago();
require_once ("../egreso/cEgreso.php");
$oEgreso = new cEgreso();
require_once ("../formatos/formato.php");


$dts1=$oComprapago->filtrar($_POST['com_id']);
$num_rows= mysqli_num_rows($dts1);

$contadorpro = 0;
$xtotal = 0;

?>

<div class="table-responsive">	 	
	
	<table class="table table-bordered table-striped"> 
	<thead>
		<tr>
			<th>FORMA</th>
			<th>DETALLE</th>
			<th align="right" nowrap="nowrap">MONTO</th>
			<th align="right" nowrap="nowrap">ABONO</th>
			<th align="right" nowrap="nowrap">SALDO</th>
			<th>ESTADO</th>
			<th></th>
		</tr>
	</thead>
	<tbody>
	<?php while($dt1 = mysqli_fetch_array($dts1))
	{
		$monto = $dt1['tb_comprapago_mon'];	
		$abonos=0;

		$mod_id=4;
		$est=1;
		$dts3 = $oEgreso->mostrar_por_modulo($mod_id,$dt1['tb_comprapago_id'],$est);
		$num_rows3= mysqli_num_rows($dts3);
		while($dt3 = mysqli_fetch_array($dts3))
		{
			$abonos+= $dt3['tb_egreso_imp'];
		} 
		mysqli_free_result($dts3);

		$saldo = ($monto - $abonos);
		$total+=$monto;

		?>
		<tr class="even">
			<td><?php 
					if($dt1['tb_formapago_id']==1)echo 'CONTADO ';
					if($dt1['tb_formapago_id']==2)echo 'CREDITO';
				
				?>
			</td>
			<td><?php 
			
			if($dt1['tb_formapago_id']==2){
				echo 'A '.$dt1['tb_comprapago_numdia'].' días | Vencimiento: '.mostrarFecha($dt1['tb_comprapago_fecven']);
				
			}
		 if($dt1['tb_formapago_id']==1){
			  if($dt1['tb_modopago_id']==1) echo 'EFECTIVO';
			  if($dt1['tb_modopago_id']==2) echo 'DEPOSITO';
			  if($dt1['tb_modopago_id']==3) echo 'TRANSFERENCIA';
			  if($dt1['tb_modopago_id']==4) echo 'CHEQUE';
			  if($dt1['tb_modopago_id']==5) echo 'TARJETA';
			
		}

		 ?>
		 
		
			
			
			
			<td align="right" nowrap="nowrap"><?php echo formato_money($dt1['tb_comprapago_mon'])?></td>
			<td align="right" nowrap="nowrap"><?php echo formato_money($abonos);?></td>
			<td align="right" nowrap="nowrap"><?php echo formato_money($saldo)?></td>
			<td><?php 
					if($dt1['tb_comprapago_est']==1)echo '<span class="badge badge-success" >CANCELADO<span>';
					if($dt1['tb_comprapago_est']==2)echo '<span class="badge badge-danger" >POR PAGAR<span>';
					if($dt1['tb_comprapago_est']==3)echo '<span class="badge badge-warning" >CANJEADO / CANCELADO<span>';
					
				?>
				
			</td>
			<td>
			
			<?php
			if ($_SESSION['usuariogrupo_id']=='6'){
			?>
			
			<?php 
			}else if ($_SESSION['usuariogrupo_id']=='4'){}else{
			if($dt1['tb_comprapago_est']==1){
				?>
				<span style="cursor:pointer;" class="badge badge-warning" onclick="pagos_form('<?php echo $dt1['tb_comprapago_id']?>')" >Ver pagos<span>
				<?php 
			}else if($dt1['tb_comprapago_est']==3) { }else{ ?>
			<span class="btn btn-xs btn-danger" style="cursor:pointer;" onclick="eliminar_formpago('<?php echo $dt1['tb_comprapago_id']?>');" >
			<i class="fas fa-trash"></i></span>
			<?php }
			}?>
			</td>
		</tr>
	<?php
		//$t +=$dt1['tb_comprapago_mon'];
	} mysqli_free_result($dts1); ?>
	</tbody>

	<tr>
				<td></td>
				<td colspan="1" style="text-align:right;font-weight: bold;border:0px" >TOTAL </td> 
				<td align="right" nowrap="nowrap" style="text-align:right;font-weight: bold;border:0px"><?php echo formato_money($total);?></td>				
				<td align="right" nowrap="nowrap">
				<input name="hdd_compag_tot" id="hdd_compag_tot" type="hidden" value="<?php echo formato_money($total)?>">
				&nbsp;</td>
				<td></td>
				<td></td>
				<td></td>
	</tr>
	<?php  //echo $_POST['com_tot'];
				$com_tot=moneda_mysql($_POST['com_tot']);
				$diferencia=moneda_mysql($com_tot)-moneda_mysql($total);
				//echo $diferencia;
		if($diferencia>0){				
		?>		
			<tr>
				<td>&nbsp;</td>
				<td colspan="" style="text-align:right;font-weight: bold;border:0px" ><?php if(formato_money($diferencia)!='0.00') echo 'DIFERENCIA ';?></td> 
				<td align="right" nowrap="nowrap" style="text-align:right;font-weight: bold;border:0px">
				<?php if(formato_money($diferencia)!='0.00') echo formato_money($diferencia);?>					
				</td>
				<td align="right" >
				 </td>
				 <td></td>
				<td></td>
				<td></td> 
			</tr>
		<?php } ?>
		
<input name="txt_compag_mon" id="txt_compag_mon" type="hidden" value="<?php echo $total; ?>">
				
</table>
<script type="text/javascript">
	$(function() { 

});
</script>

</div>



