<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("../caja/cCaja.php");
$oCaja = new cCaja();

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


if(isset($_SESSION['compag_mon']))
{
	$num_rows=count($_SESSION['compag_mon']);
	if($num_rows==0)$num_rows="";
}
else
{
	$num_rows="";
}
?>

<script type="text/javascript">
	$("#msj_igualpago , #msj_numpagos").hide();
</script>

<input name="hdd_com_pag_numite" id="hdd_com_pag_numite" type="hidden" value="<?php echo $num_rows?>">
  
<div class="table-responsive">	 	
	
	<table class="table table-bordered table-striped">
		<thead>
			<tr>
				<th>FORMA</th>
				<!--<th>MODO</th>-->
				<th>DETALLE</th>
				<th align="right" nowrap="nowrap">MONTO</th>
				<th align="right" nowrap="nowrap"></th>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach($_SESSION['compag_mon'] as $indice=>$valor)
			{
				
				//echo '--'.$_SESSION['compag_nroope'][$indice];
				
				$total+=$valor;
			?>
			<tr>
				<td>
					<?php 
					if($_SESSION['compag_for'][$indice]==1)echo 'CONTADO';
					if($_SESSION['compag_for'][$indice]==2)echo 'CREDITO';
					if($_SESSION['compag_for'][$indice]==3)echo 'CHEQUE';
					?>
				</td>
			<!--	<td>
					<?php 
					if($_SESSION['compag_mod'][$indice]==1)echo 'EFECTIVO';
					?>
				</td>
			-->
				<td>
					<?php 
					
					if($_SESSION['compag_for'][$indice]==1){
						if($_SESSION['compag_mod'][$indice]==1) echo 'EFECTIVO';
						if($_SESSION['compag_mod'][$indice]==2) echo 'DEPOSITO'.' | '.$_SESSION['compag_nroope'][$indice];;
						if($_SESSION['compag_mod'][$indice]==3) echo 'TRANSFERENCIA'.' | '.$_SESSION['compag_nroope'][$indice];;
						if($_SESSION['compag_mod'][$indice]==4) echo 'CHEQUE'.' | '.$_SESSION['compag_nroope'][$indice];;
						if($_SESSION['compag_mod'][$indice]==5) echo 'TARJETA'.' | '.$_SESSION['compag_nroope'][$indice];;
						
						//echo '--'.$_SESSION['compag_nroope'][$indice];
					}
					
					
					if($_SESSION['compag_for'][$indice]==2){
						echo 'A '.$_SESSION['compag_numdia'][$indice].' días | Vencimiento: '.mostrarFecha($_SESSION['compag_fecven'][$indice]);
					}
					
					
					
					
						$dtsx=$oCaja->mostrarUno($_SESSION['compag_caj'][$indice]);
						$dta = mysqli_fetch_array($dtsx);
							echo $dta['tb_caja_nom'];
						mysqli_free_result($dtsx);
	
					?>
				</td>
				<td align="right"><?php echo formato_money($valor)?></td>
				<td align="right">
					<span class="btn btn-danger btn-xs" href="javascript:void(0)"  title="Eliminar forma de pago" onClick="pago_compra_agregar('quitar','<?php echo $indice?>')"><i class="fas fa-trash"></i></span>
				</td>
			</tr>
			<?php						
			}
			?>
		</tbody>
		<tr>
				<td><a class="btn btn-dark btn-xs" title="Vaciar formas de pago" href="javascript:void(0)" onClick="pago_compra_agregar('restablecer')"><i class="fa fa-remove"></i> Vaciar</a></td>
				
				<td colspan="1" style="text-align:right;font-weight: bold;border:0px" >TOTAL S/</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)?>">
				</td>
			</tr>
			
				<?php 
				$com_tot=moneda_mysql($_POST['com_tot']);
				$diferencia=$com_tot-$total;
				if($diferencia>0){		
				?>		
			<tr>
				<td>&nbsp;</td>
				<td colspan="1" style="text-align:right;font-weight: bold;border:0px" ><?php if(formato_money($diferencia)!='0.00') echo 'DIFERENCIA S/';?></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> 
			</tr>
		<?php } ?>
		<input name="hdd_compag_dif" id="hdd_compag_dif" type="hidden" value="<?php echo formato_money($diferencia)?>">
		
	</table>
</div>
