<?php 
session_start();
require_once ("../../config/Cado.php");
require_once ("../producto/cCatalogo.php");
$oCatalogo = new cCatalogo();
require_once ("../formatos/formato.php");
?>
	
<div class="table-responsive">
		
<div class="col-lg-12 col-md-12 col-xs-12 " >
<strong style="font-size:2rem;" >ITEMS A DEVOLVER </strong>
		
<?php 
if(isset($_SESSION['devol_car']))
{
	$num_rows=count($_SESSION['devol_car']);
	if($num_rows==0)$num_rows="";
	
	foreach($_SESSION['devol_car'] as $indice=>$cantidad){
		$total_cantidad+=$cantidad;
	}
}
else
{
	$num_rows="0";
}
?>
		
<table cellspacing="1" id="tabla_compra_detalle" class="table table-bordered table-striped"> 
    <thead>
	<tr>
	<th><span class="btn btn-danger btn-xs" style="cursor:pointer" onclick="agregar_producto('restablecer')" > vaciar selecciones</span></th>
	<th colspan="5"></th>
	</tr>
        <tr >
        
		<th class="" >CANTIDAD</th>
        <th style="white-space: nowrap;">ARTÍCULO</th>
        <th class="hidden-xs" style="white-space: nowrap;" >MARCA</th>
        <th>UNIDAD</th>
		<th align="right" >PRE. UNI.</th>		
		<th align="right" >PRECIO TOTAL</th>     
		<th align="right" ></th>     
        </tr>
    </thead>
    <tbody>
    <?php
	
	if($num_rows>0){
	
	foreach($_SESSION['devol_car'] as $indice=>$cantidad)
	{
    
		$dts1=$oCatalogo->mostrarUno($_SESSION['devol_catid'][$indice],$_SESSION['devol_marid'][$indice]);
		$dt1 = mysqli_fetch_array($dts1);
		
		$pre_uni=$_SESSION['devol_preuni'][$indice];
		$icbper=$_SESSION['devol_icbper'][$indice];
		
		$pretot= $pre_uni* $cantidad
		
		
	?>
	
      <tr >
       
		  <td class="" ><strong class="text-primary"> <?php echo $cantidad ;?> </strong></td>
          <td style="white-space: nowrap;"><?php  echo '<strong>'.$dt1['tb_producto_nom'].'</strong>';?></td>
          <td class="" style="white-space: nowrap;"><?php echo $dt1['tb_marca_nom'];?></td>
          <td><?php echo $dt1['tb_unidad_nom']?></td>
          <td class="" align="right"><?php echo formato_money($pre_uni);?></td>
          <td class="" align="right"><?php echo formato_money($pretot);?></td>
          <td class="" align="right">  <span data-indi="<?php echo $indice; ?>" style="cursor:pointer" class="btn_eliminar btn btn-xs btn-danger"><i class="fas fa-times"></i></span> </td>
          
         
      </tr>
    <?php
    $tot += $pretot;
	}
	
	}else{
	?>
		<tr>
		<td COLSPAN="7">NO HAY ITEMS SELECCIONADOS</td>
		</tr>
	<?php 
	}  
    ?>
	<tr>
		<td colspan="5"></td>
		<td colspan="" style="text-align:right;"> 
		<input type="text" name="txt_dev_tot" autocomplete="off" class="form-control" id="txt_dev_tot" value="<?php echo formato_money($tot)?>"  style="text-align:right;font-weight: bold;" readonly >
		</td>
		<td></td>
	</tr>
	
	
  </tbody>
</table>
	
<script> 
<?php if($num_rows>0){
?>	
	$("#btn_generar").show(100);
<?php 
}else{
?>	
	$("#btn_generar").hide(100);
<?php	
}?>
$('.btn_eliminar').click(function(event) {
	
				var indice = $(this).attr('data-indi');
					
				if(confirm('¿Seguro de quitar el item?')){
					agregar_producto('quitar', indice);
				}
			});
</script>
			
          </div>
        </div>
		
	