<?php
session_start();
require_once ("../../config/Cado.php");
require_once("../guiaremision/cGuiaremision.php");
$oGuiaremision = new cGuiaremision();
require_once ("../notacredito/cNotacredito.php");
$oNotacredito = new cNotacredito();
require_once ("../notadebito/cNotadebito.php");
$oNotadebito = new cNotadebito();
require_once ("../historial/cHistorial.php");
$oHistorial = new cHistorial();
require_once ("../formatos/formato.php");
$fecha1 = $_POST['txt_fil_ven_fec1']; 
$fecha2 = $_POST['txt_fil_ven_fec2']; 
$dts1=$oGuiaremision->mostrar_filtro(fecha_mysql($fecha1),fecha_mysql($fecha2),$_POST['txt_fil_docnum'],$_POST['txt_fil_recdoc'],
	$_SESSION['usuario_id'],$_POST['cmb_fil_empresa_id']);
if($fecha1!=$fecha2 || $_POST['txt_fil_docnum'] !=""){
	
	
		$user_agen = $_SERVER['HTTP_USER_AGENT'];
		$mod = 19;
		$mod_ide = 0;
		$det = 'MOSTRANDO GUIAS DE REMISION SEGUN ['.$fecha1.' | '.$fecha2.' | '.$_POST['txt_fil_docnum'].']';
		$fec = date('Y-m-d');
		$doc_id = '';
		$numdoc = '';
		$ip = mostrar_ip();
	 	
		$oHistorial->insertar(
		fecha_mysql($fec),
		$det,
		$ip,
		intval($_SESSION['usuario_id']),
		intval($mod),
		intval($mod_ide),
		intval($doc_id),
		$numdoc
		);
	
}	
	
	
	
	
$num_rows= mysqli_num_rows($dts1);
?>
<section class="content">
	<div class="container-fluid">
	<div class="row">
	    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
		    <div class="card">
				<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:5px;">
	
	<div class="table-responsive">
		
          <table id="tabla_venta" class="table table-bordered table-striped">
		  
<?php 
//echo $_POST['cmb_fil_mon_id'];
/* 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 nowrap="nowrap"></th>
      <th nowrap="nowrap">ESTADO SUNAT</th>
      <th >REFERENCIAS</th>
      <th >FECHA</th>
      <th >DOCUMENTO</th>
      <th >EMPRESA</th>
      <th align="right" >DOC. REL.</th>
      <th >CLIENTE</th>
      <th >PUNTO PARTIDA</th>
      <th >PUNTA LLEGADA</th>
    </tr>
  </thead> 
            <tbody>
    <?php
    if($num_rows>0){
    while($dt1 = mysqli_fetch_array($dts1))
    {
     
	$reg = mostrarFechaHora($dt1['tb_guiaremision_reg']);
	  
	$numdocnc = '';
	$dtsnc = $oNotacredito->validarVenta($dt1['tb_venta_id']);
	$numrowsnc = mysqli_num_rows($dtsnc);
	$nc = '';
	if($numrowsnc>0){
		
		while($dtnc = mysqli_fetch_array($dtsnc)){
		$idnc = $dtnc['tb_notacredito_id'];
		$numdocnc = 'NC '.$dtnc['tb_notacredito_numdoc'];
		$nc .= ' <br /> <a href="../../files/notacredito/notacredito_impcpe_doc.php?notid='.$idnc.'" target="_blank" class="badge"
		style="background-color:#00897b;color:#fff;" >'.$numdocnc.'</a>';
	} 
	}
	
	$numdocnd = '';
	$dtsnd = $oNotadebito->validarVenta($dt1['tb_venta_id']);
	$numrowsnd = mysqli_num_rows($dtsnd);
	$nd = '';
	if($numrowsnd>0){
		
		while($dtnd = mysqli_fetch_array($dtsnd)){
		$idnd = $dtnd['tb_notadebito_id'];
		$numdocnd = 'ND '.$dtnd['tb_notadebito_numdoc'];
		$nd .= ' <br /> <a href="../../files/notadebito/notadebito_impcpe_doc.php?notid='.$idnd.'" target="_blank" class="badge"
		style="background-color:#1c2a48;color:#fff;" >'.$numdocnd.'</a>';
	} 
	
	}
	
	
	
	
	  
	$doc = '<a href="../../files/venta/venta_impcpe_doc.php?venid='.$dt1['tb_venta_id'].'" target="_blank" class="badge"
		style="background-color:#3F729B;color:#fff;" >'.$dt1['tb_venta_numdoc'].'</a> ';
	  
	  
    ?>
	
	
	
    <tr class="<?php echo $col; ?>" <?php echo $title;  ?> style="cursor:pointer;" >
      <td nowrap="nowrap" >
	  
 		<a  class="btn btn-sm" title="VER DESCARGAR Y/O IMPRIMIR PDF" data-toggle="tooltip" data-placement="top" style="text-align:left;background-color:#00897b;color:#fff;" href="../../files/guiaremision/guiaremision_impcpe_doc.php?guiaid=<?php echo $dt1['tb_guiaremision_id'] ?>" 
		target="_blank"><i class="fa fa-file-pdf"></i></a>
		
		<span class="btn btn-sm btn-info" onclick="enviarCorreo('<?php echo $dt1['tb_guiaremision_id']; ?>');" title="ENVIAR CORREO" data-toggle="tooltip" data-placement="top" ><i class="fas fa-envelope-square "></i></span>		 
				
		<?php 
		if($dt1['tb_guiaremision_estsun']==0){				
		?>
		<a href="javascript:void(0)" class="btn btn-success btn-sm" title="EMITIR DOCUMENTO :: ENVIAR A SUNAT :: IMPRIMIR" data-toggle="tooltip" data-placement="top" onClick="guia_ticket_datos('<?php echo $dt1['tb_guiaremision_id'] ?>');" ><i class="fas fa-angle-double-right"></i></a>
		
		<?php if($_SESSION['usuariogrupo_id']==1){?>
		<span class="btn btn-sm btn-primary" title="ACTUALIZAR ESTADO DE SUNAT" data-toggle="tooltip" data-placement="top" onClick="actualizarestado('<?php echo $dt1['tb_guiaremision_id']; ?>','guia');" ><i class="fas fa-retweet"></i></span>
		<?php 
		}}
		?>
		
		<!--
		<button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
 		<span class="caret"></span>
 		</button>
 		<ul class="dropdown-menu bg-gray" role="menu">
 		
		</ul>
		-->	  
	  </td>
	  <td>
	   <?php
	 
		if($dt1['tb_guiaremision_estsun']==0){
			echo '<badge class="badge badge-danger">RECHAZADA / NO CDR</badge>';
		}else{
				echo '<badge class="badge" style="color:#fff;background-color:#0d47a1">ACEPTADA</badge>';
		} 
	  ?>
	  </td>
	  <td>
	  <!--
	  <table>
			<tr>
			<td>
		<span onclick="enviar_documentos('<?php echo $dt1['tb_venta_id']; ?>','<?php echo $idnc ?>','<?php echo $dt1['tb_guiaremision_id']; ?>','<?php echo $dt1['tb_cliente_id']; ?>','<?php echo $idnd; ?>')" class="btn btn-xs btn-warning glyphicon glyphicon-envelope"></span>
			</td>
			</tr>
		</table>
	  -->
	  <?php 
	  echo $doc;
	  echo $nc;
	  echo $nd;
	  ?>
	  
	  </td>
      <td title="FECHA DE REGISTRO : <?php echo "$reg";  ?> " data-toggle="tooltip" data-placement="top" nowrap="nowrap"><?php echo mostrarFecha($dt1['tb_guiaremision_fec'])?></td>
      <td nowrap="nowrap"><?php echo $dt1['tb_documento_abr'].' '.$dt1['tb_guiaremision_numdoc']?></td>
      <td nowrap="nowrap"><?php echo $dt1['tb_empresa_nomcom']?></td>
      
	  <td nowrap align="right" ><span title="DOCUMENTO RELACIONADO"  data-toggle="tooltip" data-placement="top"  class="badge" style="cursor:pointer;background-color:#00897b;color:#fff;" ><?php echo $dt1['tb_venta_numdoc']?></span></td>
      <td nowrap ><?php echo $dt1['tb_receptor_nom'].' | '.$dt1['tb_receptor_doc'];?></td>
      <td nowrap align="right"><?php echo $dt1['tb_guiaremision_par']; ?></td>
      <td nowrap align="right"><?php echo $dt1['tb_guiaremision_lleg']; ?></td>     
    </tr>
    <?php
  }
  mysqli_free_result($dts1);
  }
  ?> 
			
</tbody> 
		<tr class="even">
			<td colspan="11"> <?php echo $num_rows; ?> REGISTROS</td>
		</tr>
			
   </table>
		 
		
		
			
      </div>
      </div>
      </div>
    </div>
  </div>
</div>
</section>
 <script type="text/javascript">
  $(function() {  
    $("#tabla_venta").DataTable( {
      "columnDefs": [
      { "orderable": false, "targets": [5,6,7,8] }
      ],
      "searching": false,
      "order":[[0,"asc"]]
    });
	
	$('.table-responsive').doubleScroll();
	
  }); 
</script>  