<?php
  include VIEWPATH.'includes/new_header.php';
  ?>
  
<body class="hold-transition sidebar-mini">
<!-- Site wrapper -->
<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_carburant.php';
    ?>

    <!-- Main content -->
    <section class="content">

      <!-- Default box -->
      <div class="card">







        



      



      
      <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Enregistrement des ravitaillement en Carburant</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
                <form role="form" action="<?=base_url('voiture/Mettre_Carburant/save_mettre_carburant')?>" enctype="multipart/form-data" method="POST">
                  <input type="hidden" name="NUM_GENERATED" value="<?=$approv['NUM_GENERATED']?>">
                <div class="card-body row">

                  <div class="form-group col-md-3">
                        <label for="CONSOMATION_DATE">
                          Date de consomation
                          <i class="text-danger"> *</i>
                        </label>
                        <div class="input-group">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
                    </div>
                    <input type="text" class="form-control" name="CONSOMATION_DATE" id="CONSOMATION_DATE" data-inputmask-alias="datetime" data-inputmask-inputformat="dd/mm/yyyy" data-mask placeholder="Date de consomation">
                  </div>
                        <?php echo form_error('CONSOMATION_DATE', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-2">
                        <label for="VEHICULE_ID">
                          Voiture
                          <i class="text-danger"> *</i>
                        </label>
                  <select class="form-control select" name="VEHICULE_ID" onchange="getlastkm(this)" id="VEHICULE_ID" style="width: 100%;">
                    <option value=""> </option>
                    <?php 

                    foreach ($approv['VEHICULE_ID'] as $key) {
                      echo "<option value=".$key['VEHICULE_ID'].">".$key['PLAQUE_VEHICULE']."</option>";
                    }

                    ?>
                  </select>
                        <?php echo form_error('VEHICULE_ID', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-2">
                        <label for="STATION_ID">
                          Station
                          <i class="text-danger"> *</i>
                        </label>
                        
                        <select class="form-control select" name="STATION_ID" id="STATION_ID">
                    <option value=""> </option>
                    <?php 

                    foreach ($approv['STATION_ID'] as $key) {
                      echo "<option value=".$key['STATION_ID'].">".$key['STATION_NOM']."</option>";
                    }

                    ?>
                  </select>
                        <?php echo form_error('STATION_ID', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-5">
                        <label for="KM_A_APROVISIONNEMENT" id="KM_A_APROVISIONNEMENTTEXT">
                          KM au consomation 
                          <i class="text-danger"> *</i>
                        </label>
                        <input type="number" name="KM_A_APROVISIONNEMENT" value="<?=$approv['KM_A_APROVISIONNEMENT']?>" class="form-control" id="KM_A_APROVISIONNEMENT" placeholder="KM au consomation" min="0" step="0.001" readonly="readonly">
                        <?php echo form_error('KM_A_APROVISIONNEMENT', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-3">
                        <label for="QUANTITE_RECU">
                          Carburant 
                          <i class="text-danger"> *</i>
                        </label>
                        <select class="form-control" name="PRIX_CARBURANT_ID" onchange="getprice(this)" id="PRIX_CARBURANT_ID">
                    <option value=""> </option>
                    <?php 

                    foreach ($approv['PRIX_CARBURANT_ID'] as $key) {
                      echo "<option value=".$key['PRIX_UNITAIRE'].">".$key['DESCRIPTION']." (".$key['PRIX_UNITAIRE']." Fbu)</option>";
                    }

                    ?>
                  </select>
                        <?php echo form_error('QUANTITE_RECU', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-3">
                        <label for="QUANTITE_RECU">
                          Quantite (Nb littre) 
                          <i class="text-danger"> *</i>
                        </label>
                        <input type="number" name="QUANTITE_RECU" onkeyup="getall(this)" value="<?=$approv['QUANTITE_RECU']?>" class="form-control" id="QUANTITE_RECU" readonly="readonly" placeholder="Nb littres" step="0.001">
                        <?php echo form_error('QUANTITE_RECU', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     

                     <div class="form-group col-md-3">
                        <label for="MONTANT_CONSOMATION">
                          Montant Total de la facture
                          <i class="text-danger"> *</i>
                        </label>
                        <input type="number" name="MONTANT_CONSOMATION" value="<?=$approv['MONTANT_CONSOMATION']?>" class="form-control" readonly="readonly" id="MONTANT_CONSOMATION" placeholder="Montant Total" step="0.001">
                        <?php echo form_error('MONTANT_CONSOMATION', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-3">
                        <label for="PRIX_UNITAIRE">
                          Prix unitaire a la pompe
                          <i class="text-danger"> *</i>
                        </label>
                        <input type="number" name="PRIX_UNITAIRE" readonly="readonly" value="<?=$approv['PRIX_UNITAIRE']?>" class="form-control" id="PRIX_UNITAIRE" placeholder="Prix unitaire" step="0.001">
                        <?php echo form_error('PRIX_UNITAIRE', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-6">
                        <label for="CHAUFFEUR_ID">
                          Chauffeurs
                          <i class="text-danger"> *</i>
                        </label>
                  <select class="form-control select" name="CHAUFFEUR_ID" id="CHAUFFEUR_ID" style="width: 100%;">
                    <option value=""> </option>
                    <?php 

                    foreach ($approv['CHAUFFEUR_ID'] as $key) {
                      echo "<option value=".$key['ID_EMPLOYE'].">".$key['NOM']." ".$key['PRENOM']."</option>";
                    }

                    ?>
                  </select>
                        <?php echo form_error('CHAUFFEUR_ID', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-6">
                        <label for="PATH_FACTURE">
                          Images
                          <i class="text-danger"> *</i>
                        </label>
                        <label for="exampleInputEmail1">Documents (PDF)</label> 
                        <div class="custom-file"> 
                          <input type="file" class="custom-file-input" id="customFile" name="PATH_FACTURE" accept="application/pdf">  
                          <label class="custom-file-label" for="customFile">Chercher fichier</label>
                    </div>
                  <!-- <select class="form-control select" name="PATH_FACTURE" id="PATH_FACTURE" style="width: 100%;">
                    <option value=""> </option>
                    <?php 

                    foreach ($approv['PATH_FACTURE'] as $key) {
                      echo "<option value=".$key['ID_EMPLOYE'].">".$key['NOM']." ".$key['PRENOM']."</option>";
                    }

                    ?>
                  </select> -->
                        <?php echo form_error('PATH_FACTURE', '<div class="text-danger">', '</div>'); ?>
                     </div>

                  
                </div>
                <!-- /.card-body -->

                <div class="card-footer">
                  <button type="submit" class="btn btn-primary btn-block">Enregistrer</button>
                </div>
              </form>
            </div>
        
        
        <!-- /.card-body -->
        <!-- <div class="card-footer">
          Footer
        </div> -->
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <?php
 include VIEWPATH.'includes/new_copy_footer.php';  
  ?>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<?php
  include VIEWPATH.'includes/new_script.php';
  ?>

  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })

    //Datemask dd/mm/yyyy
    $('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
    //Datemask2 mm/dd/yyyy
    $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
    //Money Euro
    $('[data-mask]').inputmask()

    //Date range picker
    $('#reservation').daterangepicker()
    //Date range picker with time picker
    $('#reservationtime').daterangepicker({
      timePicker: true,
      timePickerIncrement: 30,
      locale: {
        format: 'MM/DD/YYYY hh:mm A'
      }
    })
    //Date range as a button
    $('#daterange-btn').daterangepicker(
      {
        ranges   : {
          'Today'       : [moment(), moment()],
          'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
          'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
          'Last 30 Days': [moment().subtract(29, 'days'), moment()],
          'This Month'  : [moment().startOf('month'), moment().endOf('month')],
          'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        },
        startDate: moment().subtract(29, 'days'),
        endDate  : moment()
      },
      function (start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
      }
    )

    //Timepicker
    $('#timepicker').datetimepicker({
      format: 'LT'
    })
    
    //Bootstrap Duallistbox
    $('.duallistbox').bootstrapDualListbox()

    //Colorpicker
    $('.my-colorpicker1').colorpicker()
    //color picker with addon
    $('.my-colorpicker2').colorpicker()

    $('.my-colorpicker2').on('colorpickerChange', function(event) {
      $('.my-colorpicker2 .fa-square').css('color', event.color.toString());
    });

    $("input[data-bootstrap-switch]").each(function(){
      $(this).bootstrapSwitch('state', $(this).prop('checked'));
    });

  })
</script>
<script type="text/javascript">
  function getprice(val) {
    var v= $(val).val();
    $('#PRIX_UNITAIRE').val(v);
    document.getElementById("QUANTITE_RECU").readOnly = false;
  }
</script>
<script type="text/javascript">
  function getall(val) {
    var QUANTITE_RECU= $('#QUANTITE_RECU').val();
    var PRIX_UNITAIRE= $('#PRIX_UNITAIRE').val();
    var MONTANT_CONSOMATION = QUANTITE_RECU * PRIX_UNITAIRE;
    $('#MONTANT_CONSOMATION').val(MONTANT_CONSOMATION);
  }
</script>

<script type="text/javascript">
  function getlastkm(val) {
    var VEHICULE_ID = $(val).val();
    // alert(VEHICULE_ID);
    $.post('<?php echo base_url('voiture/Mettre_Carburant/getlastkm')?>',
          {VEHICULE_ID:VEHICULE_ID},
          function(data){
            // alert(data);
            document.getElementById("KM_A_APROVISIONNEMENT").readOnly = false;
            // $( "#KM_A_APROVISIONNEMENT" ).attr("min",data);
             
            $('#KM_A_APROVISIONNEMENTTEXT').html('KM au consomation <i class="text-danger"> *</i> (+ de '+data+'  <input type="checkbox" name="PANNE_TABLEAU" id="" value="1"> Panne? </div>)'); 
            // $('#ID_BENEFICIAIRE').html('');

            // <input type="checkbox">
          });
  }
</script>
</body>
</html>
