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



$num_rows= mysql_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="" 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 ></th>

      

    </tr>

  </thead> 

            <tbody>

    <?php

    if($num_rows>0){

    while($dt1 = mysql_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'];

	  

	  

	  $dtvp = $oVentapago->filtrar($_POST['venid']);

      $dtv = mysql_fetch_array($dtvp); 

        $monto = $dtv['tb_ventapago_mon']; 

        $vping = $dtv['tb_ventapagoingresos_id']; 

        

		$abonos=0;



        $mod_id=3;

        $est1=1;

        $est2=2;

       $dts3 = $oIngreso->mostrar_por_modulo($mod_id,$vping,$est1,$est2);

        while($dt3 = mysql_fetch_array($dts3))

        {

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

        } 

        mysql_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="label label-success" style="cursor:pointer;" title="SE EMITIRA UNA NOTA DE CREDITO CON ESTE DOCUMENTO">DISPONIBLE</small>

			<?php 

		}else{

			?>

			<small class="label label-danger" style="cursor:pointer;" title="YA ESTA ANULADA" >ANULADA</small>

			<?php 

		}

	  ?>

	  </td>

     

    </tr>

    <?php

  }

  mysql_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>

<?php if($_POST['motid']==3){?>

<div id="fieldset_producto" style="position: relative;padding:0px;" class="col-lg-12 col-md-12 col-xs-12 ">

 									<div class="box box-default box-solid box-danger ">

 										<div class="box-body">

 											<div class="row">

		<div class="col-lg-8 col-sm-3 col-xs-6">

						<label for="txt_notdeb_asun">Asunto:</label>

						<input name="txt_notdeb_asun" type="text"  class="form-control" id="txt_notdeb_asun" value="<?php echo ''?>" > 

		</div>

					

		<div class="col-lg-3 col-sm-3 col-xs-6">

						<label for="txt_notdeb_mon">Monto:</label>

						<input name="txt_notdeb_mon" type="text"  class="form-control" id="txt_notdeb_mon" value="<?php echo ''?>" > 

		</div>			

</div> 	

</div> 	

</div> 	

</div> 	



<div id="div_notadebito_tabladet" >

																												

</div>



<?php }?>







		

		<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>Total:</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_notdeb_tot" class="form-control" type="text" id="txt_notdeb_tot" style="text-align:right;font-weight: bold;" autocomplete="off" value="0" > 

								</td>

							</tr>							

						</tbody>

						</table>

					</div>

				</div>

			</div>

		

<script type="text/javascript">





	function notadebito_tablaitem()

	{

		$.ajax({

			type: "POST",

			url: '../notadebito/notadebito_tabla_item.php',

			async:true,

			dataType: "html",                      

			data: ({

			

			}),

			beforeSend: function(){

				

				$('#div_notadebito_tabladet').addClass("ui-state-disabled");

			},

			success: function(html){

				$('#div_notadebito_tabladet').html(html);

			},

			complete: function(){			

				$('#div_notadebito_tabladet').removeClass("ui-state-disabled");

			

			}

		});     

	}



	

	

	function agregar_asunto(act,asun, mon)

{

	

	$.ajax({

		type: "POST",

		url: "../notadebito/agregar_asunto.php",

		async:true,

		dataType: "json",                  

		data: ({

			action:	 act,

			asu : asun,

			mon: mon

		}),

		beforeSend: function() {



		},

		success: function(data){

			

			if(data.est == true){

				toastr["info"](data.msj);

				notadebito_tablaitem();

			}

			if(data.est == false){

				toastr["error"](data.msj);

				$('#txt_notdeb_asun').focus();

			}

			

		},

		complete: function(data)

		{

			$('#txt_notdeb_asun').val('');

			$('#txt_notdeb_mon').val('');

		}

	});  

}





$(function(){

			agregar_asunto('restablecer');

			notadebito_tablaitem();

					

		<?php if($_POST['motid']==3){?>

			$("#txt_notdeb_tot").attr('readonly','readonly');

		<?php }?>

	

	$('#txt_notdeb_asun').change(function(){

		$(this).val($(this).val().toUpperCase());

	});



	

		$("#txt_notdeb_asun").keydown(function(e){

			if(e.which==13)

			{

				$("#txt_notdeb_mon").focus();

				return false;

			}

		});

		

		$("#txt_notdeb_mon").keydown(function(e){

			if(e.which==13)

			{

				agregar_asunto('agregar',$("#txt_notdeb_asun").val(),$("#txt_notdeb_mon").val());

				return false;

			}

		});



});

</script>		

	

