<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("../caja/cCaja.php");
$oCaja = new cCaja();
require_once ("../formatos/formato.php");
if(isset($_SESSION['canpag_mon']))
{
	$num_rows=count($_SESSION['canpag_mon']);
	if($num_rows==0)$num_rows="";
}
else
{
	$num_rows="";
}
?>
<div class="table-responsive">		
<div class="col-lg-12 col-md-12 col-xs-12 no-padding" >
<input name="hdd_com_pag_numite" id="hdd_com_pag_numite" type="hidden" value="<?php echo $num_rows?>">
	<strong class="text-md" >GENERACION DE LETRAS A CAJEAR</strong>
	<table class="table table-bordered table-striped">
		<thead>
			<tr>
				<th nowrap>FECHA GIRO</th>
				<th nowrap>NRO LETRA</th>
				<th nowrap>DETALLE</th>
				<th align="right" nowrap="nowrap">IMPORTE</th>
				<th align="right" nowrap="nowrap">&nbsp;</th>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach($_SESSION['canpag_mon'] as $indice=>$valor)
			{
				$total+=$valor;
			?>
			<tr>
				<td nowrap>
					<?php 
					echo $_SESSION['canpag_fecemi'][$indice];
					?>
				</td>
				<td nowrap>
					<?php 
					echo $_SESSION['canpag_numlet'][$indice];
					?>
				</td>
				<td nowrap>
					<?php 
					
					echo 'Vence: '.mostrarFecha($_SESSION['canpag_fecven'][$indice]);
	
					?>
				</td>
				<td align="right"><?php echo formato_money($valor)?></td>
				
				<td align="right">
					<a class="btn btn-danger btn-xs" href="javascript:void(0)"  title="Eliminar forma de pago" onClick="canje_pago_agregar('quitar','<?php echo $indice?>')"><i class="fa fa-times"></i> </a>
				</td>
			</tr>
			<?php						
			}
			?>
		</tbody>
		<tr>
				<td><a class="btn btn-danger btn-xs" title="Vaciar formas de pago" href="javascript:void(0)" onClick="canje_pago_agregar('restablecer')"><i class="fa fa-trash"></i> Vaciar</a></td>
				<td colspan="2" 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_canpag_tot" id="hdd_canpag_tot" type="hidden" value="<?php echo formato_money($total)?>">
				&nbsp;</td>
			</tr>
			
				<?php 
				$can_tot=moneda_mysql($_POST['can_tot']);
				$diferencia=$can_tot-$total;
		if($diferencia>0){				
		?>		
			<tr>
				<td>&nbsp;</td>
				<td colspan="2" 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> 
			</tr>
		<?php } ?>
		<input name="hdd_canpag_dif" id="hdd_canpag_dif" type="hidden" value="<?php echo formato_money($diferencia) ?>">
		
	</table>
</div>
</div>
<script type="text/javascript">
	
$(function() {
if($("#hdd_canpag_dif").val()<=0){
	$("#save_form").attr('disabled', false);
	$("#save_form").attr('readonly', false);
	$("#save_form").attr('onclick', 'guardar_letras()');
	
}else {
	
	$("#save_form").attr('disabled', true);
	$("#save_form").attr('readonly', true);
	$("#save_form").attr('onclick', '');
	
}
});
</script>