<?php
session_start();

$cliente=$_SESSION['cliente'];
$perfil=$_SESSION['perfil'];
$rut=$_SESSION['rut'];

    
  include '../../conexion/conn.php';


?>

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../../../favicon.ico">

    <title>Inspector</title>
   
   
  </head>


  <body>

      <table class="display" style="width:100%; font-size: 12px;" id="planilla">
          <thead>
            <tr>
              <tr>
              <th >#</th>
              <th >pallet</th>
              <th >CM</th>
              <th >Especie</th>
              <th scope="col">Fecha</th>
              <th >Exp.</th>
              <th >Pack.</th>
              <th >Prod.</th>
              <th >Variedad</th>
              <th >Cla</th>
              <th >Emb.</th>
              <th >calibre</th>
              <th >Cant Cajas</th>
              <th >resultado</th>
              <th >Planilla</th>
              <th >Planilla Lote</th>
              <th >IR</th>
            </tr>
          </thead>
          <tbody>
            <?php
              $rs_planilla = mysql_query("SELECT * FROM cal_planilla_inspeccion INNER JOIN cal_cajas ON cal_planilla_inspeccion.pi_folio=cal_cajas.pi_folio WHERE cal_planilla_inspeccion.tipo_planilla='PALLET' AND cal_cajas.caja_madre='' AND cal_cajas.mostrar_caja='' AND cal_planilla_inspeccion.pi_inspector='$rut' ORDER BY cal_planilla_inspeccion.pi_fecha_inspeccion DESC");

              while($row_planilla = mysql_fetch_array($rs_planilla)){
                 echo '<tr style="text-align:center;">
                  <th>'.$row_planilla['caja_id'].'</th>
                  <td>'.$row_planilla['folio_pallet'].'</td>';
                  if($row_planilla['cant_caja_hijas']==0){
                    $cant_caja_hijas=1;
                  }else{
                    $cant_caja_hijas=$row_planilla['cant_caja_hijas'];
                  }
                  echo'<td>'.$cant_caja_hijas.'</td>';
                  $rscampos = mysql_query("SELECT * FROM cal_especies WHERE especie_id='".$row_planilla['pi_especie_id']."'");
                  if($rowcampos = mysql_fetch_array($rscampos)){
                    echo '<td>'.$rowcampos['especie_nombre'].'</td>';
                  }
                  echo '<td scope="row">'.$row_planilla['pi_fecha_inspeccion'].'</td>
                  <td>'.$row_planilla['pi_exportador_cod'].'</td>';
                  $rscampos = mysql_query("SELECT * FROM cal_packing WHERE packing_id='".$row_planilla['pi_packing_id']."'");
                  if($rowcampos = mysql_fetch_array($rscampos)){
                    echo '<td>'.$rowcampos['packing_nombre'].'</td>';
                  }
                  $rscampos = mysql_query("SELECT * FROM cal_productores WHERE productor_id='".$row_planilla['productor_id']."'");
                  if($rowcampos = mysql_fetch_array($rscampos)){
                    echo '<td>'.$row_planilla['productor_id'].' - '.$rowcampos['productor_nombre'].'</td>';   
                  }
                  $rscampos = mysql_query("SELECT * FROM cal_variedades WHERE variedad_id='".$row_planilla['variedad_id']."'");
                  if($rowcampos = mysql_fetch_array($rscampos)){
                    echo '<td>'.$rowcampos['variedad_nombre'].'</td>';    
                  }
                  $rscampos = mysql_query("SELECT * FROM cal_clasificacion WHERE clasificacion_id='".$row_planilla['clasificacion_id']."'");
                  if($rowcampos = mysql_fetch_array($rscampos)){
                    echo '<td>'.$rowcampos['nombre_clasificacion'].'</td>';    
                  }
                  echo '<td>'.$row_planilla['embalaje_cod'].'</td>';
                  $rscampos = mysql_query("SELECT * FROM cal_calibre WHERE calibre_id='".$row_planilla['calibre_id']."'");
                  if($rowcampos = mysql_fetch_array($rscampos)){
                    echo '<td>'.$rowcampos['calibre_nombre'].'</td>';
                  }
                  echo '<td>'.$row_planilla['cant_cajas'].'</td>';
                  if($row_planilla['resultado_pallet']=='A'){
                    echo '<td bgcolor="#01DF01">'.$row_planilla['resultado_pallet'].'</td>';
                  }else if($row_planilla['resultado_pallet']=='OA'){
                    echo '<td bgcolor="#FBFF00">'.$row_planilla['resultado_pallet'].'</td>';
                  }else if($row_planilla['resultado_pallet']=='N'){
                    echo '<td bgcolor="#FF8633">'.$row_planilla['resultado_pallet'].'</td>';
                  }else if($row_planilla['resultado_pallet']=='RR'){
                    echo '<td bgcolor="#FF0000">'.$row_planilla['resultado_pallet'].'</td>';
                  }
                  echo '<td><a target="_BLANK" href="planilla_pallet.php?caja_id='.$row_planilla['caja_id'].'">PDF</a></td>';
                  echo '<td><a target="_BLANK" href="planilla_pallet_lote.php?caja_id='.$row_planilla['caja_id'].'">PDF LOTE</a></td>
                  <td><a href="Inspeccion/Ingreso_Pallet/index.php?pi_folio='.$row_planilla['pi_folio'].'&especie_id='.$row_planilla['pi_especie_id'].'&embalaje_cod='.$row_planilla['embalaje_cod'].'&variedad_id='.$row_planilla['variedad_id'].'&productor_id='.$row_planilla['productor_id'].'&clasificacion_id='.$row_planilla['clasificacion_id'].'&calibre_id='.$row_planilla['calibre_id'].'&n_proceso='.$row_planilla['n_proceso'].'">IR</a></td>
                </tr>';
              } 

            ?>
          </tbody>
        </table>
    
    <!-- Bootstrap core JavaScript
    ================================================== -->
    
    
      <!-- Bootstrap core JavaScript
    ================================================== -->

    <script type="text/javascript">
        var events;
        var table;
        var rowData;
        var arreglo="";
      $(document).ready( function () {
        
          //$('#planilla').DataTable();
          //events = $('#events');
          table = $('#planilla').DataTable( {
              select: true
          } );
       
          table
              .on( 'select', function ( e, dt, type, indexes ) {
                  var rowData = table.rows( indexes ).data().toArray();
                  //events.prepend( '<div><b>'+type+' selection</b> - '+JSON.stringify( rowData )+'</div>' ); listar fila
                  arreglo=rowData;
              } )
              .on( 'deselect', function ( e, dt, type, indexes ) {
                  var rowData = table.rows( indexes ).data().toArray();
                  //events.prepend( '<div><b>'+type+' <i>de</i>selection</b> - '+JSON.stringify( rowData )+'</div>' ); listar fila
                  arreglo="";
              } );
      } );



    </script>
  </body>
</html>
