<?php
session_start();
require_once ("../../config/Cado.php");
require_once ("../venta/cVenta.php");
$oVenta = new cVenta();
require_once ("../venta/cVentapago.php");
$oVentapago = new cVentapago();
require_once ("../ingreso/cIngreso.php");
$oIngreso = new cIngreso();
require_once ("../formatos/formato.php");
$fecha1 = $_POST['txt_fil_ven_fec1']; 
$fecha2 = $_POST['txt_fil_ven_fec2']; 
$dts2=$oVenta->mostrarUno($_POST['venid']);
$dtv = mysqli_fetch_array($dts2);
$docven = $dtv['tb_documento_abr'];
// echo $docven;
if($docven=='B'){
	$docid_not = 13;
}else if($docven=='F')
{
	$docid_not = 31;
}
$dts1=$oVenta->mostrarUno($_POST['venid']);
$num_rows= mysqli_num_rows($dts1);
?>
<div class="tab-content col-lg-12 col-md-12 col-sm-12 col-xs-12" id="">
				<div class="row">
					<div class="table-responsive">
          <table id="tabla_venta" class="table table-bordered table-striped">
		  
<?php 
// echo $docven;
/* echo fecha_mysql($fecha1).'-'.fecha_mysql($fecha2).'-'.$_POST['cmb_fil_doc_id'].'-'.$_POST['hdd_fil_cli_id'].'-'.$_POST['cmb_fil_ven_est'].'-'.$_SESSION['usuario_id'].'-p'. */
/* $_SESSION['puntoventa_id'].'-'.$_POST['chk_fil_ven_may'].'-'.$_POST['cmb_fil_moz_id']; */
/* echo $_POST['txt_fil_docnum']; */
?>
		  
           <thead>
    <tr>
      <th>FECHA</th>
      <th>DOCUMENTO</th>
      <th>CLIENTE</th>
      <th>RUC/DNI</th>
      <th>VENDEDOR</th>
      <th align="right">TOTAL</th>
      <th align="right">PAGOS</th>
      <th align="right">SALDO</th>
      <th ></th>
      
    </tr>
  </thead> 
            <tbody>
    <?php
    if($num_rows>0){
    while($dt1 = mysqli_fetch_array($dts1))
    {
     $ven_igvval=$dt1['tb_venta_igvval'];
      $total_valven+=$dt1['tb_venta_valven'];
      $total_igv+=$dt1['tb_venta_igv'];
      $total_ventas +=$dt1['tb_venta_tot'];
	  $reg = mostrarFechaHora($dt1['tb_venta_reg']);
 
      $total_pagar += $dt1['tb_venta_tot'];
	  
	 // echo $ven_igvval.'----';
	  
	  $dtvp = $oVentapago->filtrar($dt1['tb_venta_id']);
      $dtv = mysqli_fetch_array($dtvp); 
        $monto = $dtv['tb_ventapago_mon']; 
        $vping = $dtv['tb_ventapagoingresos_id']; 
        
		//echo '--'.$vping;
		
		$abonos=0;
        $mod_id=3;
        $est1=1;
        $est2=2;
       $dts3 = $oIngreso->mostrar_por_modulo($mod_id,$vping,$est1,$est2);
        while($dt3 = mysqli_fetch_array($dts3))
        {
          $abonos+= $dt3['tb_ingreso_imp'];
        } 
        mysqli_free_result($dts3);
        $saldo = ($monto - $abonos);
        $total_abono+=$abonos;
        $total_saldo+=$saldo; 
    ?>
    <tr >
      <td title="FECHA DE REGISTRO : <?php echo "$reg";  ?>" nowrap="nowrap"><?php echo mostrarFecha($dt1['tb_venta_fec'])?></td>
      <td nowrap="nowrap"><?php echo $dt1['tb_documento_abr'].' '.$dt1['tb_venta_numdoc']?></td>
      <td><?php echo $dt1['tb_cliente_nom'];?></td>
      <td><?php echo $dt1['tb_cliente_doc'];?></td>
      <td align="right"><?php echo $dt1['tb_usuario_nom'].' '.$dt1['tb_usuario_ape']?></td>
      <td align="right"><?php echo formato_money($dt1['tb_venta_tot'])?></td>
      <td align="right"><?php echo formato_money($abonos);?></td>
      <td align="right"><?php echo formato_money($saldo);?></td>
      <td align="right">
	   <?php
		if($dt1['tb_venta_est']==1){
			?>
			<small class="badge badge-success" style="cursor:pointer;" title="SE EMITIRA UNA NOTA DE CREDITO CON ESTE DOCUMENTO">DISPONIBLE</small>
			<?php 
		}else{
			?>
			<small class="badge badge-danger" style="cursor:pointer;" title="YA ESTA ANULADA" >ANULADA</small>
			<?php 
		}
	  ?>
	  </td>
     
    </tr>
    <?php
  }
  mysqli_free_result($dts1);
  }
  ?> 
			<tr class="even">
			<td colspan="">TOTAL</td>
			<td colspan=""></td>
			<td colspan=""></td>
			<td colspan=""></td>
			<td colspan=""></td>
			<td align="right"><strong><?php echo formato_money($total_pagar)?></strong></td>
			<td align="right"><strong><?php echo formato_money($total_abono)?></strong></td>
			<td align="right"><strong><?php echo formato_money($total_saldo)?></strong></td>
			
			</tr>
		</tbody>
        </table>
		
		</div>
	</div>
</div>
		
		<div class="tab-content col-lg-6 col-md-4 col-sm-4 col-xs-12" id="">
				<div class="row">
					<div class="table-responsive">
						<table class="table">
							<tbody>
							<tr>
								<th>Monto:</th>
								<td>
									<input type="hidden" name="txt_docrel_mon" id="txt_docrel_mon" value="<?php echo moneda_mysql(formato_money($total_pagar));?>" />
									<input name="txt_notcre_mon" class="form-control" type="text" id="txt_notcre_mon" style="text-align:right;font-weight: bold;" autocomplete="off" value="0" > 
								</td>
							</tr>							
						</tbody>
						</table>
					</div>
				</div>
			</div>
		
<script type="text/javascript">
$(function(){
			
			
		cmb_doc_id(<?php echo $docid_not; ?>);
			
		if($("#txt_notcre_tip").val()==1 || $("#txt_notcre_tip").val()==6){
			$("#txt_notcre_mon").val($("#txt_docrel_mon").val());
			$("#txt_notcre_mon").attr('readonly','readonly');
		}
		
			
		$("#txt_notcre_mon").keydown(function(e){
			if(e.which==13)
			{
				
				return false;
			}
		});
});
</script>		
	