<?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']; 

$dts1=$oVenta->mostrarUno($_POST['txt_fil_ven_id']);

$num_rows= mysqli_num_rows($dts1);
?>


<section class="content" id="table" style="min-height:0px;padding-bottom:0px;margin-bottom:-30px;">
  <div class="row">
    <div class="col-xs-12">
      <div class="box">
        <div class="box-body">
          <table id="tabla_venta" class="table table-bordered table-striped">
		  
<?php 
/* 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>&nbsp;</th>
    </tr>
  </thead> 
            <tbody>
    <?php
    if($num_rows>0){
    while($dt1 = mysqli_fetch_array($dts1))
    {
     
      $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'];

      $dts2=$oVentapago->filtrar($dt1['tb_venta_id']);
      while($dt2 = mysqli_fetch_array($dts2))
      {
        $monto = $dt2['tb_ventapago_mon']; 
        $abonos=0;

        $mod_id=3;
        $est=1;
       /* $dts3 = $oIngreso->mostrar_por_modulo($mod_id,$dt2['tb_ventapago_id'],$est);
        while($dt3 = mysqli_fetch_array($dts3))
        {
          $abonos+= $dt3['tb_ingreso_imp'];
        } 
        mysqli_free_result($dts3);*/

        $saldo = ($monto - $abonos);

        $total_abono+=$abonos;
        $total_saldo+=$saldo;
      }
    
  /*   $filas=0;
    $rw1=$oVenta->mostrar_venta_detalle($dt1['tb_venta_id']);
    $filas= mysqli_num_rows($rw1);
    $detalle="";
    
    if(!$filas>0)
    {
      $detalle="Vacío";
    } */

    ?>
    <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="left" nowrap="nowrap">
      <span  title="EMITIR NOTA DE CREDITO" class="btn btn-primary" onclick="notacredito_form('insertar','<?php echo $dt1['tb_venta_id'];?>','<?php echo $dt1['tb_documento_abr'];?>');"  >Emitir NC</span>
      </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>
			<td align="right">&nbsp;</td>
			</tr>
</tbody> 

        </table>
		 
		
		
			
      </div>
    </div>
  </div>
</div>
</section>


 <script type="text/javascript">
  $(function() {  
    $("#tabla_venta").DataTable({
      "columnDefs": [
      { "orderable": false, "targets": [5,6,7,8] }
      ],
      "searching": false,
      "order":[[0,"asc"]]
    });
  }); 
</script>  