<?php


require_once ("../../config/Cado.php");
require_once ("../venta/cVenta.php");
$oVenta = new cVenta();

require_once ("../formatos/formato.php");

$dts= $oVenta->mostrarUno($_POST['ven_id']);
$dt = mysqli_fetch_array($dts);
  $fec	=mostrarFecha($dt['tb_venta_fec']);
  $doc_id	=$dt['tb_documento_id'];
  $numdoc	=$dt['tb_venta_numdoc'];
  $cli_id	=$dt['tb_cliente_id'];

  $valven	=$dt['tb_venta_valven'];
  $igv	=$dt['tb_venta_igv'];
  $des	=$dt['tb_venta_des'];
  $tot	=$dt['tb_venta_tot'];
  $des	=$dt['tb_venta_des'];
mysqli_free_result($dts);

$dts1=$oVenta->mostrar_venta_detalle($_POST['ven_id']);
$num_rows= mysqli_num_rows($dts1);

?>
 
<div class="table-responsive">
<table cellspacing="1" id="tabla_venta_detalle" class="table table-bordered table-striped"> 
 
    <thead>
        <tr>
        <th class="" >CÓDIGO</th>
      <!--  <th class="" >ESTADO</th>
        -->
		<th style="white-space: nowrap;">ARTÍCULO</th>
        <th class="" style="white-space: nowrap;" >CATEGORÍA | LABORATORIO</th>
        <th>UNIDAD</th>
        <th align="right">CANT</th>
		<th align="right" >V. UNI.</th>		
		<th align="right" >DES. UNI.</th>
		<th align="right" >IGV UNI.</th>
		<th align="right" >P. UNI.</th>
		<th align="right" >VAL. TOTAL</th>
		<th align="right" >DESC. TOTAL</th>
		<th align="right" >IGV TOTAL.</th>
		<th align="right" >PRECIO TOTAL.</th>
		
        </tr>
    </thead>
    <tbody>
    <?php
		while($dt1 = mysqli_fetch_array($dts1))
    {
		$can = $dt1['tb_ventadetalle_can'];
		$precio_uni=$dt1['tb_ventadetalle_preuni'];
		$des_uni = $dt1['tb_ventadetalle_des'];
		
			$pre_unicondes = $precio_uni-$des_uni;
			$pre_uni=$pre_unicondes;
			$valor_uni = $pre_uni/ 1.18;
			$igv_uni = $pre_uni - $valor_uni;
			
		$val_tot = $valor_uni * $can;
		$des_tot = $des_uni * $can;
		$igv_tot = $igv_uni * $can;
		$pre_tot = $pre_uni * $can;
		
		
		$est = $dt1['tb_ventadetalle_est'];
			
			
			
		?>
        <tr>
          <td><?php echo $dt1['tb_catalogo_cod'];?></td>
        <!--  <td>
		  <?php if($est==1){
			echo '<strong class="text-blue">ENTREGADO</strong>';  
		  }else{?>
		  <select class="form-control cmb_estado text-red" onchange="cambiar_estado('<?php echo $dt1['tb_ventadetalle_id']; ?>');" >
		  <option value="1">ENTREGADO</option>
		  <option value="2" selected >POR ENTREGAR</option>		  
		  </select>
		  <?php } ?>
		  </td>-->
          <td><?php  echo '<strong>'.$dt1['tb_ventadetalle_nom'].'</strong>';?></td>
          <td><?php echo $dt1['tb_categoria_nom'].' | '.$dt1['tb_marca_nom'];?></td>
          <td><?php echo $dt1['tb_unidad_nom']?></td>
		  <td align="right"><?php echo $can;?></td>
		  
          <td class="" align="right"><?php echo formato_money($valor_uni);?></td>
          <td class="" align="right"><?php echo formato_money($des_uni);?></td>
          <td class="" align="right"><?php echo formato_money($igv_uni);?></td>
          <td class="" align="right"><?php echo formato_money($pre_uni);?></td>
          <td class="" align="right"><?php echo formato_money($val_tot);?></td>
          <td class="" align="right"><?php echo formato_money($des_tot);?></td>
          <td class="" align="right"><?php echo formato_money($igv_tot);?></td>
          <td class="" align="right"><?php echo formato_money($pre_tot);?></td>
        </tr>
    <?php						
    }
    mysqli_free_result($dts1);
    ?>
    </tbody>
</table>

<?php 
  if($num_rows=="" or $num_rows==0)echo $num_rows.' Ningún registro';
  if($num_rows==1)echo $num_rows.' registro';
  if($num_rows>=2)echo $num_rows.' registros';
?>

<br/>
</div> 
  
  
<div class="table-responsive">


<table>
		<tr>
		<td>
				<div style="width:150px;" >
								<label>Operacion Gravada:</label>
								<input type="text"  autocomplete="off"  class="form-control text-red" value="<?php echo formato_money($valven); ?>" style="text-align:right;font-weight: bold;" readonly >				
							</div>
						</td>	
						<td style="width:5%">
						</td>
						<td>
							<div >
								<label>IGV:</label>
						<input type="text" autocomplete="off" class="form-control text-red" value="<?php echo formato_money($igv)?>"  style="text-align:right;font-weight: bold;" readonly> 
							</div>
							</td>
					<td style="width:5%">
						</td>							
							<td>
							<div >
								<label>TOTAL:</label>
								<input type="text"  autocomplete="off" class="form-control text-red" value="<?php echo formato_money($tot)?>"  style="text-align:right;font-weight: bold;" readonly >
							</div>
							
						</td>	
							</tr>
			</table>
</div>			


<script type="text/javascript">
  
  function cambiar_estado(detid){
  
		$.ajax({
			type: "POST",
			url: "../venta/venta_reg.php",
			async:true,
			dataType: "json",                      
			data: ({
				action_venta:	'cambiar_estado',
				detid:	detid
			}),
			beforeSend: function() {
				
			},
			success: function(data){
				toastr["success"](data.msj);	
			},
			complete: function(){			
				venta_detalle_tabla_vis(<?php echo $_POST["ven_id"]?>);
			}
		});     
  
  }
  
  </script>
  
  
  
  
  
  
  
  
  
  
  