<?php 
// error_reporting(E_ALL);
// ini_set('display_errors',1);
session_start();
date_default_timezone_set('America/Lima');
require_once ("../../config/Cado.php");
require_once ("cDevolucionproveedor.php");
$oDevolucionproveedor = new cDevolucionproveedor();
require_once ("../compra/cCompra.php");
$oCompra = new cCompra();
require_once ("../producto/cCatalogo.php");
$oCatalogo = new cCatalogo();
require_once("../formatos/formato.php");
	$dts= $oDevolucionproveedor->mostrarUno($_POST['devid']);
	$dt = mysqli_fetch_array($dts);
	$fec	=mostrarFecha($dt['tb_compra_fec']);
	$empid = $dt['tb_empresa_id'];
	$emp = $dt['tb_empresa_nomcom'];
	$prov = $dt['tb_proveedor_nom'];
	$doc_id	=$dt['tb_documento_id'];
	$monid	=$dt['tb_moneda_id'];
	$numdoc	=$dt['tb_compra_numdoc'];
	$fec	=$dt['tb_devolucionproveedor_fec'];
	$tranom	=$dt['tb_devolucionproveedor_tranom'];
	$tracom	=$dt['tb_devolucionproveedor_tracom'];
	$obs1	=$dt['tb_devolucionproveedor_obs1'];
		
	if($monid==1){
		$lbl = 'S/ ';
	}else if($monid==2){
		$lbl = 'US$ ';
	}
	
	
	$dts1= $oDevolucionproveedor->mostrarDetalles($_POST['devid']);
	$num_rows = mysqli_num_rows($dts1);
	
?>
<div class="col-lg-12 col-md-12 col-xs-12 " >
	<form  id="for_dev"  > 
		<div class="box-header with-border">
			<h3 class="box-title">Informacion de la Devolucion</h3>
		</div>
		
		<input type="hidden" name="hdd_emp_id" id="hdd_emp_id" value="<?php echo $empid; ?>" />
		<input type="hidden" name="txt_dev_id" id="txt_dev_id" value="<?php echo $_POST['devid']; ?>" />
		<input type="hidden" name="txt_dev_comid" id="txt_dev_comid" value="<?php echo $_POST['comid']; ?>" />
		<input type="hidden" name="action" id="action" value="<?php echo $_POST['action']; ?>" />
		<div class="row"> 
		
		<div class="col-lg-3 col-sm-6 col-xs-12"> 
			<label for="txt_dev_empid">Empresa :</label></br>
			<input name="txt_dev_empid" id="txt_dev_empid" type="text" value="<?php echo $emp; ?>" readonly class="form-control" >
		</div>
		
		<div class="col-lg-3 col-sm-6 col-xs-12"> 
			<label for="txt_dev_empid">Proveedor :</label></br>
			<input name="txt_dev_empid" id="txt_dev_empid" type="text" value="<?php echo $prov; ?>" readonly class="form-control" >
		</div>
		
		<div class="col-lg-3 col-sm-6 col-xs-12"> 
			<label for="txt_dev_empid">Num Doc :</label></br>
			<input name="txt_dev_empid" id="txt_dev_empid" type="text" value="<?php echo $numdoc; ?>" readonly class="form-control" >
		</div>
		<div class="col-lg-3 col-sm-2 col-xs-6">
			<label for="txt_dev_fec">Fecha Devolucion:</label>
			<input  name="txt_dev_fec" type="text"  class="form-control" readonly id="txt_dev_fec" value="<?php echo $fec?>" >
		</div>
		
		<div class="col-lg-12 col-sm-12 col-xs-12">
		<br />
		<div class="nav-tabs-custom">
		
				<ul class="nav nav-tabs">
						<a href="#tab_3" class="nav-item nav-link active"  data-toggle="tab" aria-expanded="false">Transportista</a>
				</ul>								
				
		<div class="tab-content">
				<div class="active tab-pane" id="tab_3">
						<div class="row">
			
			<div class="col-lg-4 col-sm-2 col-xs-6">
			<label for="txt_dev_tranom">Nombre:</label>
			<input  name="txt_dev_tranom" type="text" autocomplete="off" class="form-control"  id="txt_dev_tranom" value="<?php echo $tranom?>" >
			</div>
			
			<div class="col-lg-4 col-sm-2 col-xs-6">
			<label for="txt_dev_tracom">Comprobante:</label>
			<input  name="txt_dev_tracom" type="text" autocomplete="off" class="form-control" id="txt_dev_tracom" value="<?php echo $tracom?>" >
			</div>
			
			<div class="col-lg-6 col-sm-12 col-xs-12">
			<label for="txt_dev_obs1">Observacion:</label>
			<textarea name="txt_dev_obs1" id="txt_dev_obs1" class="form-control"><?php echo $obs1?></textarea>
			</div>
		
		</div>
		</div>
		</div>
		</div>
		</div>
		
			
			
			</div>
		
	<div class="col-lg-12 col-sm-12 col-xs-12" > 
			
	<div class="table-responsive">
		
	<div class="col-lg-12 col-md-12 col-xs-12 " >
	<br />
	<strong style="font-size:2rem;" >ITEMS DEVUELTOS </strong>
		
	<table cellspacing="1" id="tabla_compra_detalle" class="table table-bordered table-striped"> 
    <thead>
    <tr >       
		<th class="" >CANTIDAD</th>
        <th style="white-space: nowrap;">ARTÍCULO</th>
        <th class="" style="white-space: nowrap;" >MARCA</th>
        <th>UNIDAD</th>
		<th align="right" >V. UNI.</th>		
		<th align="right" >PRECIO TOTAL.</th>       
        </tr>
    </thead>
    <tbody>
    <?php
	
	if($num_rows>0){
	
	while($dt2 = mysqli_fetch_array($dts1))
	{
		$cantidad = $dt2['tb_devolucionproveedordetalle_can'];
		$dts1c=$oCatalogo->mostrarUno($dt2['tb_catalogo_id'],$dt2['tb_marca_id']);
		$dt1 = mysqli_fetch_array($dts1c);
		
		$valor_uni=$dt2['tb_devolucionproveedordetalle_valuni'];
		
		$pre_uni= formato_money4($valor_uni) * 1.18;
		$pretot= formato_money4($pre_uni) * $cantidad
		
	?>
	
      <tr >
       
		  <td class="" ><strong class="text-orange"> <?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($valor_uni);?></td>
          <td class="" align="right"><?php echo formato_money($pretot);?></td>
      </tr>
    <?php
	  $tot += $pretot;
    }
	    mysqli_free_result($dts1);
	
	}else{
	?>
		<tr>
		<td COLSPAN="6">NO HAY ITEMS SELECCIONADOS</td>
		</tr>
	<?php 
	}
    ?>
	
	<tr>
		<td colspan="4"></td>
		<td align="right" ><?php echo $lbl; ?></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>
	</tr>
	
  </tbody>
</table>
		
		
		</div>
		</div>
		</div>
		
		
		
		<div class="col-lg-12 col-sm-12 col-xs-12" style="height:15px;"> </div>		
	</form>
	<div class="box-footer float-right ">
			<span  data-dismiss="modal" style="cursor:pointer" class="btn btn-default cancel">Cancelar</span>
			<span data-dismiss="modal" style="cursor:pointer" class="btn btn-primary" id="save_form">Guardar</span>
	</div>	
</div>				
<script type="text/javascript">
$('#txt_dev_fec').datepicker({
 				format: 'dd-mm-yyyy',
 				autoclose:true			
});
$('#save_form').on('click', function() {  
		$("#for_dev").submit();
});
	
	$('#for_dev').bootstrapValidator({
	     
	      framework: 'bootstrap',
	      message: 'Valor no valido',
	     /* feedbackIcons: {
	      	valid: 'glyphicon glyphicon-ok',
	      	invalid: 'glyphicon glyphicon-remove',
	      	validating: 'glyphicon glyphicon-refresh'
	      },*/
	      fields: {	      	
	      	txt_dev_tracom: {
	      		group: '.col-lg-4',
	      		validators: {
	      			notEmpty: {
	      				message: 'Requerido *'
	      			}
	      		}
	      	}
	      }
	  }).on('success.form.bv', function(e) 
	  {
	  	
		
	  	$.ajax({
	  		type: "POST",
	  		url: "../devolucionproveedor/devolucionproveedor_reg.php",
	  		async:true,
	  		dataType: "json",
	  		data: $("#for_dev").serialize(),
	  		beforeSend: function(){					 
	  			
				var div = "<center><div class='overlay col-lg-12 col-sm-12 col-xs-12' style='background-color:#fff;padding:0%;font-size:3rem;' >  <i class='fa fa-refresh fa-spin ' ></i> PROCESANDO PETICION.</div>  </center>";	
				$('.div_devolucionproveedor_form').html(div);
				
	  		},
	  		success: function(data){
				
				toastr["info"](data.dev_msj);
				
				
				$('.modal').modal('hide');
				$('.in').removeClass('modal-backdrop');	
	  		},
	  		complete: function(){  	
			$("#txt_dev_numdoc").val('');
			devolucion_tabla();
			}
	  	});	 
	  });
			
			
			
			
	
</script>