<?php
  include VIEWPATH.'includes/new_header.php';
  ?>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  
  <?php
  include VIEWPATH.'includes/new_top_menu.php';
  include VIEWPATH.'includes/new_menu_principal.php';
  ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    
    <?php 
    include 'includes/menu_lot.php';
    ?>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
            <!-- /.card -->

            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Production</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
               



                <table id="example1" class="table table-bordered table-striped" style="width:100%">
        <thead>
            <tr>
                <th>Lot</th>
                <th>Date</th>
                <th>Quantite produit</th>
                <th>Details</th>
                <th>Etat</th>
                <th>Declarer</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
          <?php

          $resultat=$this->Model->getRequete('SELECT * FROM `prod_lot`');

          foreach ($resultat as $key) 
         {


          $quantite=$this->Model->getRequeteOne('SELECT SUM((QUANTITE_PRODUIT * QUANTITE_LITRE)) AS PRODUCTION_LITRE FROM `prod_production` JOIN syst_taille_bouteille ON syst_taille_bouteille.ID_TAILLE_BOUTEILLE = prod_production.ID_TAILLE_BOUTEILLE WHERE ID_LOT LIKE "'.$key['ID_LOT'].'"');

          $requetdet=$this->Model->getRequete('SELECT syst_taille_bouteille.DESCRIPTION, QUANTITE_PRODUIT, syst_taille_bouteille.QUANTITE_LITRE, (QUANTITE_PRODUIT * QUANTITE_LITRE) AS PRODUCTION_LITRE FROM `prod_production` JOIN syst_taille_bouteille ON syst_taille_bouteille.ID_TAILLE_BOUTEILLE = prod_production.ID_TAILLE_BOUTEILLE WHERE prod_production.ID_LOT LIKE "'.$key['ID_LOT'].'"');
          $details = '<table class="table"><tr><td>Taille</td><td>Quantite</td><td>Quantite Litre</td></tr>';
          foreach ($requetdet as $value) {
            $details .= '<tr><td>'.$value['DESCRIPTION'].'</td><td>'.$value['QUANTITE_PRODUIT'].'</td><td>'.$value['PRODUCTION_LITRE'].'</td></tr>';
          }
          $details .= '</table>';
          // if ($quantite['PRODUCTION_LITRE'] != NULL) {
          //   $productions = $quantite['PRODUCTION_LITRE'];
          // }
          // else{
          //   $productions = 0;
          // }

          if ($key['ID_STATUS'] == 1) {
            $ID_STATUS = 'Actif';
          }
          else{
            $ID_STATUS = 'Innactif';
          }
          
          
          echo "<tr>
                <td>".$key['LOT_PRODUCTION']."</td>
                <td>".$key['DATE_CREATION']."</td>
                <td>".$key['LOT_VOLUME']."</td>
                <td>";
                echo'<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modaldetail'.$key['ID_LOT'].'">
                Details
              </button>
              
              <!-- Modal -->
              <div class="modal fade" id="modaldetail'.$key['ID_LOT'].'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog modal-lg" role="document">
                  <div class="modal-content">
                    <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">Informations</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                      
                    </div>
                    <div class="modal-body">
                    Details production<br>
                    <b>Lot:</b> '.$key['LOT_PRODUCTION'].'<br>

                    '.$details.'
                    
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                    </div>
                  </div>
                </div>
              </div>'; 
                echo"</td>
                <td>".$ID_STATUS."</td><td>";

                echo'<button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#modalfin'.$key['ID_LOT'].'">
                Daclarer fin
              </button>
              
              <!-- Modal -->
              <div class="modal fade" id="modalfin'.$key['ID_LOT'].'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog modal-lg" role="document">
                  <div class="modal-content">
                    <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">Declarer fin</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                      
                    </div>
                    <div class="modal-body">
                    Voulez vous declarer  ce lot termine?<br>
                    
                    
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                      <a href="'.base_url("production/Lot/finlot/".$key['ID_LOT']).'" class="btn btn-danger">Supprimer</a>
                    </div>
                  </div>
                </div>
              </div>';
                
                echo "
                </td>
                <td>";

                echo'<button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#modaldelete'.$key['ID_LOT'].'">
                Suppression
              </button>
              
              <!-- Modal -->
              <div class="modal fade" id="modaldelete'.$key['ID_LOT'].'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog modal-lg" role="document">
                  <div class="modal-content">
                    <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">Informations</h4>
                      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                      
                    </div>
                    <div class="modal-body">
                    Voulez vous effacer ce lot ainsi que son impact sur le stock?<br>
                    
                    
                    </div>
                    <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                      <a href="'.base_url("production/Lot/suppression/".$key['ID_LOT']).'" class="btn btn-danger">Supprimer</a>
                    </div>
                  </div>
                </div>
              </div>';
         echo "</td></tr>";
       }
          ?>
            
        </tbody>
        
    </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <?php
 include VIEWPATH.'includes/new_copy_footer.php';  
  ?>
  

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>

<!-- ./wrapper -->
<?php
  include VIEWPATH.'includes/new_script.php';
  ?>

<!-- Page specific script -->
<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper  .col-md-6:eq(0)');
   
  });
</script>

<script type="text/javascript">
  function changelist() {
document.getElementById("myForm").submit();
  }

  $('#reservation').daterangepicker({

        locale: {
        format: 'DD/MM/YYYY'
      }
    })
  $('.select').select2();

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