<div class="col-lg-12 col-md-12 col-xs-12" >
<form id="for_canjeletras" >
	
		<div class="modal-header">
        	<h5 class="modal-title"> Selecione documentos <span class="pull-right"> </span> </h5>
      	</div>
<?php
// ini_set('display_errors',1);
session_start();
require_once ("../../config/Cado.php");
require_once ("../canjeproveedor/cCanjeproveedor.php");
$oCanjeproveedor = new cCanjeproveedor();
require_once ("../egreso/cEgreso.php");
$oEgreso = new cEgreso();
require_once ("../compra/cComprapago.php");
$oComprapago = new cComprapago();
require_once ("../formatos/formato.php");
$contadorpro = 0;
$total_soles = 0;
$total_dolares = 0;
$dts1 = $oCanjeproveedor->mostrar_documentos($_POST['provid'],$_POST['empid']);
$num_rows= mysqli_num_rows($dts1);
if($_POST['cmb_fil_mon_id']==1){
	$lbl_filmon = 'S/';
}else if($_POST['cmb_fil_mon_id']==2){
	$lbl_filmon = 'US$';
}
?>
		<input type="hidden" name="hdd_action" value="insertar" id="hdd_action">
<div class="table-responsive">
        <table id="tabla_canje" class="table table-bordered table-striped">
           <thead>
			<tr >
				<th  nowrap="" align="left">OPCIONES</th>	
				<th nowrap="" align="left">FECHA</th>
				<th nowrap="" align="left">DOCUMENTO</th>	
			<!--	<th align="left">PROVEEDOR</th>	
				<th align="left">EMPRESA</th>
			-->	<th nowrap="" align="right">FECHA VEN.</th>
				<th nowrap="" align="right">MONTO TOTAL</th>
				<th nowrap="" align="right">SALDO A CANJEAR</th>
			</tr>
		</thead>
         <tbody>	
		<?php
		if($num_rows>0){
		while($dt1 = mysqli_fetch_array($dts1))
		{ 
		if($dt1['tb_documento_abr']!='L' ){
		$entra = true;
		foreach($_SESSION['cancom_id'] as $comid)
		{
		if($comid==$dt1['tb_comprapago_id']){
			$entra = false;
			 break;
		}
		}
		$total_abonos = 0;
		$saldo = 0;
		$total_monto = 0;
	 
	  /*  $dts2=$oComprapago->filtrar($dt1['tb_comprapago_id']);
       while($dt2 = mysqli_fetch_array($dts2))
       { */
        $monto = $dt1['tb_comprapago_mon']; 
        $abonos=0;
        $mod_id=4;
        $est=1;
        $dts3 = $oEgreso->mostrar_por_modulo($mod_id,$dt1['tb_comprapago_id'],$est);
        while($dt3 = mysqli_fetch_array($dts3))
        {
          $abonos+= $dt3['tb_egreso_imp'];
		} 
        mysqli_free_result($dts3);
		$total_abonos += $abonos; 
		$total_monto += $monto; 
     // }
	    
		$saldo = $total_monto - $total_abonos;
		if($dt1['tb_moneda_id']==1){
			$lbl_mone = 'S/ ';
		}else if($dt1['tb_moneda_id']==2){
			$lbl_mone = 'US$ ';
		}
	if($dt1['tb_documento_nom']=="LETRA"){
		$fec = $dt1['tb_comprapago_fecven'];
	}else{
		$fec = $dt1['tb_compra_fec'];
	}		
	
		if($saldo!=0 ){
		?>
		<tr>
		<td>
					<div class="div_checkbox_<?php echo $dt1['tb_comprapago_id']; ?>" >
					<input type="checkbox" onclick="vertot('<?php echo $dt1['tb_comprapago_mon']; ?>','<?php echo $dt1['tb_comprapago_id']; ?>','<?php echo $dt1['tb_compra_numdoc']; ?>')"  
					id="chk_imprimir_<?php echo $dt1['tb_comprapago_id']; ?>" name="chk_documento[]" value="<?php echo $dt1['tb_comprapago_id']; ?>"  
					<?php 
					if($entra)
						{
						}else{
							echo 'checked="true"';
						}
					?>
					
					/>
					<label class="lbl_chk_<?php echo $dt1['tb_comprapago_id']; ?>" for="chk_imprimir_<?php echo $dt1['tb_comprapago_id']; ?>"></label>
					</div>
<style type="text/css">
input[type=checkbox] {
 cursor:pointer;
}
#chk_imprimir_<?php echo $dt1['tb_comprapago_id']; ?> {
  visibility: hidden;
}
.div_checkbox_<?php echo $dt1['tb_comprapago_id']; ?> {
    width: 60px;
    height: 20px;
    /* background: #FF8800; */
    
    border:1px solid #FF8800;
    margin-left: 0px;
    border-radius: 50px;
    position: relative;
  font-family: 'Aldrich', sans-serif; 
}
.div_checkbox_<?php echo $dt1['tb_comprapago_id']; ?>:before {
    content: 'Sí';
    position: absolute;
    top: 2px;
    left: 12px;
    color: #00C851;
    font-size: 13px;
  line-height: 15px;
  text-shadow: 0 0 2px #00C851;
}
.div_checkbox_<?php echo $dt1['tb_comprapago_id']; ?>:after {
    content: 'No';
  color: #00695c;
    position: absolute;
    top: 2px;
    right: 5px;
    font-size: 13px;
  line-height: 15px;
  text-shadow: 0 0 1px #00695c;
}
.div_checkbox_<?php echo $dt1['tb_comprapago_id']; ?> .lbl_chk_<?php echo $dt1['tb_comprapago_id']; ?> { 
    background: #00695c;
    display: block;
    width: 25px;
    height: 15px;
    border-radius: 50px;
    transition: all .7s ease;
    cursor: pointer;
    position: absolute;
    top: 1.5px;
    z-index: 1;
    left: 5px;
}
.div_checkbox_<?php echo $dt1['tb_comprapago_id']; ?> #chk_imprimir_<?php echo $dt1['tb_comprapago_id']; ?>:checked + .lbl_chk_<?php echo $dt1['tb_comprapago_id']; ?> {
    left: 30px;
    background: #00C851;
}
</style>
		</td>     
				<td nowrap="" ><?php echo mostrarFecha($fec); ?> </td> 
              	<td nowrap="" ><?php echo $dt1['tb_documento_nom'].' '.$dt1['tb_compra_numdoc'] ?> </td> 
				<td nowrap="" align="right"><?php echo mostrarFecha($dt1['tb_comprapago_fecven']);?></td>
				<td nowrap="" align="right"><?php echo $lbl_mone.'<strong>'.formato_money($dt1['tb_comprapago_mon']).'</strong>';?></td>
				<td nowrap="" align="right">
				<?php echo'<strong class="text-orange" >'. $lbl_mone.' '.formato_money($saldo).'</strong>';?>
				<?php if($saldo!=0){?>
				<?php }else{
				?>
				<span class="label label-success" style="cursor:pointer" title="YA SE HA ANCELADO TODA LA CUENTA" >CANCELADO<span>
				<?php 
				}?>
				</td>
		</tr>
		<?php 
			$total_soles += $dt1['tb_comprapago_mon'];
			$total_saldo += $saldo;
			$contadorpro ++; 
		}
		}
		}
		mysqli_free_result($dts1); 
		}else{
			?>
			<tr>
			<td colspan="7" align="center" >No hay facturas.</td>
			</tr>	
	<?php 			
		}
	?>
	</tbody>
			<tr class="even">
				<td align="left"><?php echo $contadorpro.' registros'?></td>
				<td>TOTAL</td>
				<td></td>
				<td></td>
				<td align="right" ><?php echo $lbl_mone.' '.formato_money($total_soles); ?></td>
				<td align="right" ><?php echo $lbl_mone.' <strong>'.formato_money($total_saldo).'</strong> '?></td>
			</tr>
    </table>
	
	
	</div>
	
<script type="text/javascript" src="../cotizacion/NumberFormat.js"></script>
<script type="text/javascript">
  var tot = 0;
function vertot(mon,compag_id,numdoc){
if($("#chk_imprimir_"+compag_id).is(':checked')){
agregar_documento('agregarnumdoc',numdoc,compag_id);
canje_documentos_tabla('',<?php echo $_POST['provid'] ?>,<?php echo $_POST['empid'] ?>,'','<?php echo $_POST['monid']?>');
canje_pago_tabla();
}else{
agregar_documento('quitarnumdoc',numdoc,compag_id);
}
}
function canjeardocumentos()
	{
	$.ajax({
		type: "POST",
		url: "../canjeproveedor/canjeproveedor_reg.php",
		async:true,
		dataType: "html", 
		data: $("#for_canje").serialize(),                    
		beforeSend: function() {
		},
		success: function(html){
		},
		complete: function(){			
		}
	});     
	}
	  </script>
</form>
	
	
	<div class="box-footer float-right ">
		<button title="CERRAR VENTANA" type="button" data-dismiss="modal" class="btn btn-danger"><i class="fas fa-times"></i></button>
		<button class="btn btn-primary" style="display: none" id="save_form" >Guardar</button>			
	</div>
</div>	