<?php

session_start();

date_default_timezone_set('America/Lima');

require_once ("../../config/Cado.php");

require_once ("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");



$dts1=$oVenta->mostrar_filtro(fecha_mysql($_POST['txt_fil_ven_fec1']),fecha_mysql($_POST['txt_fil_ven_fec2']),$_POST['cmb_fil_ven_doc'],$_POST['hdd_fil_cli_id'],$_POST['cmb_fil_ven_est'],$_POST['cmb_fil_ven_id'],$_POST['cmb_fil_usu_id'],$_POST['cmb_fil_punven_id'],$_SESSION['empresa_id']);



$num_rows= mysql_num_rows($dts1);



$id_usuario = $_SESSION['usuariogrupo_id'];



?>



<script type="text/javascript">

  $(function() {  

   

 }); 

</script>



<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 cellspacing="1" id="tabla_venta"  class="table table-bordered table-striped" >

  <thead>

    <tr>

      <th>FECHA</th>

      <th>DOCUMENTO</th>

      <th>CLIENTE</th>

      <th>RUC/DNI</th>

      <th align="right">TOTAL</th>

      <th align="right">PAGOS</th>

      <th align="right">SALDO</th>

      <th>VENDEDOR</th>

      <th align="center">ESTADO</th>

      <th>&nbsp;</th>

    </tr>

  </thead>

  <?php

  if($num_rows>0){

   ?>

   <tbody>

    <?php

    while($dt1 = mysql_fetch_array($dts1))

    {

     

      $total_valven+=$dt1['tb_venta_valven'];

      $total_igv+=$dt1['tb_venta_igv'];

      $total_ventas +=$dt1['tb_venta_tot'];



      $total_pagar += $dt1['tb_venta_tot'];



      $dts2=$oVentapago->filtrar($dt1['tb_venta_id']);

      while($dt2 = mysql_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 = mysql_fetch_array($dts3))

        {

          $abonos+= $dt3['tb_ingreso_imp'];

        } 

        mysql_free_result($dts3);



        $saldo = ($monto - $abonos);



        $total_abono+=$abonos;

        $total_saldo+=$saldo;

      }

    

    $filas=0;

    $rw1=$oVenta->mostrar_venta_detalle($dt1['tb_venta_id']);

    $filas= mysql_num_rows($rw1);

    $detalle="";

    

    if(!$filas>0)

    {

      $detalle="Vacío";

    }



    ?>

    <tr>

      <td 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 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"><?php echo $dt1['tb_usuario_nom'].' '.$dt1['tb_usuario_ape']?></td>

      <td align="center">

        <?php 

          if($dt1['tb_venta_est']==1)echo 'REGISTRADA';

          if($dt1['tb_venta_est']==2)echo 'ANULADA';

        ?>

      </td>

	

	

      <td align="left" nowrap="nowrap">

        <a class="btn btn-primary btn-sm glyphicon glyphicon-pencil" href="#update" onClick="venta_form_vista('editar','<?php echo $dt1['tb_venta_id']?>')"></a> 

        <?php 

        if($dt1['tb_venta_est']!='2'){

         if ($id_usuario=='2') {

        ?>



       <!--     <span class="btn btn-warning btn-sm glyphicon glyphicon-trash" 

			onClick="venta_anular('<?php echo $dt1['tb_venta_id']?>','<?php echo $dt1['tb_documento_abr'].' '.$dt1['tb_venta_numdoc']?>')"></span> 

		-->

			<?php }}?>

      </td>

    

	

	

	</tr>

    <?php

  }

  mysql_free_result($dts1);

  ?>

</tbody>

<?php

}

?>

<?php if($_SESSION['usuariogrupo_id']==2){?>

<tr class="even">

  <td colspan="4">TOTAL</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>

  <td align="right">&nbsp;</td>

  <td align="right">&nbsp;</td>

</tr>

<?php }?>



<tr class="even">

  <td colspan="10"><?php echo $num_rows.' registros'?></td>

</tr>

</table>



				</div>

			</div>

		</div>

	</div>

</section>



