<?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_reparation.php';
    ?>

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

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







        



      
<div class="modal fade" id="modal_default">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Ajout d'une piece</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <form id="myformsassuree" method="POST" class="form-horizontal" onsubmit="submitformulaireun();return false"  accept-charset="utf-8" enctype="multipart/form-data">
            <div class="modal-body">


              


              <table class="table">
                <tr>
                  <td>Nom de la piece</td>
                  <td>
                    <input type="text" name="PIECE_NOM" id="PIECE_NOM" class="form-control" placeholder="Nom de la Pieces">     
                  </td>
                </tr>


                <tr>
                  <td>Nom de la marque</td>
                  <td>
                    <input type="text" name="MARQUE_ID" id="MARQUE_ID" class="form-control" placeholder="Nom de la marque">     
                  </td>
                </tr>


                <tr>
                  <td>Nom de la categorie</td>
                  <td>
                    <input type="text" name="PIECE_CATEGORIE_ID" id="PIECE_CATEGORIE_ID" class="form-control" placeholder="Nom de la categorie">     
                  </td>
                </tr>
              </table>
              
            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
              <!-- <button type="button" class="btn btn-primary"></button> -->
              <input type="submit" value="Enregistrer" class="btn btn-primary">
            </div>
          </form>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
      </div>


      
      <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Enregistrement d'une reparation</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
                <form role="form" action="<?=base_url('voiture/Reparation/save_reparation')?>" enctype="multipart/form-data" method="POST">
                  <input type="hidden" name="NUM_GENERATED" id="NUM_GENERATED" value="<?=$approv['NUM_GENERATED']?>">
                <div class="card-body row">

                  <div class="form-group col-md-3">
                        <label for="CONSOMATION_DATE">
                          Date
                          <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-3">
                        <label for="VEHICULE_ID">
                          Voiture
                          <i class="text-danger"> *</i>
                        </label>
                  <select class="form-control select" name="VEHICULE_ID" 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-3">
                        <label for="GARAGE_ID">
                          Garage
                          <i class="text-danger"> *</i>
                        </label>
                        
                        <select class="form-control select" name="GARAGE_ID" id="GARAGE_ID">
                    <option value=""> </option>
                    <?php 

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

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

                     <div class="form-group col-md-3">
                        <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="row"> -->

                      <div class="form-group col-md-3">
                        <label for="PIECE_ID">
                          Piece <button type="button" class="btn btn-link btn-xs" data-toggle="modal" data-target="#modal_default">Piece non list&eacute;e?</button> 
                          <i class="text-danger"> *</i>
                        </label>
                  <select class="form-control select" name="PIECE_ID" id="PIECE_ID" style="width: 100%;">
                    <option value=""> </option>
                    <?php 
                    foreach ($approv['PIECE_ID'] as $key) {
                      echo "<option value=".$key['PIECE_ID'].">".$key['PIECE_NOM']."</option>";
                    }
                    ?>
                  </select>
                        <?php echo form_error('PIECE_ID', '<div class="text-danger">', '</div>'); ?>
                      </div>
                      <div class="form-group col-md-6">
                        <label for="REPARATION_FAITE">
                          Reparation faite
                          <i class="text-danger"> *</i>
                        </label>
                  <input type="text" name="REPARATION_FAITE" value="" class="form-control" id="REPARATION_FAITE" placeholder="Nb littres">
                        <?php echo form_error('REPARATION_FAITE', '<div class="text-danger">', '</div>'); ?>
                      </div>


                      
                      <div class="form-group col-md-2">
                        <label for="MONTANT_UNITAIRE">
                          Montant
                          <i class="text-danger"> *</i>
                        </label>
                        <input type="number" name="MONTANT_UNITAIRE" value="" class="form-control" id="MONTANT_UNITAIRE" placeholder="Montant unitaire" step="0.001">
                        <?php echo form_error('MONTANT_UNITAIRE', '<div class="text-danger">', '</div>'); ?>
                     </div>


                      <div class="form-group col-md-1">
                        <label for=""> _ </label>
                        <a  class="btn btn-primary btn-block" href="#"  onclick="addElement()">+</a>

                      </div>


                       
                     <!-- </div> -->

                     

                    

                     

                     

                     <div class="form-group col-md-12" id="resultattablea">
                        
                     </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 addElement() {

    var PIECE_ID= $('#PIECE_ID').val();
    var REPARATION_FAITE= $('#REPARATION_FAITE').val();
    var MONTANT_UNITAIRE= $('#MONTANT_UNITAIRE').val();
    var NUM_GENERATED= $('#NUM_GENERATED').val();

    $.post('<?php echo base_url('voiture/Reparation/save_detail_reparation')?>',
          {
            PIECE_ID:PIECE_ID,
            REPARATION_FAITE:REPARATION_FAITE,
            MONTANT_UNITAIRE:MONTANT_UNITAIRE,
            NUM_GENERATED:NUM_GENERATED
          },
          function(data){
            $('#resultattablea').html(data); 
            
          });
    // 
                      // 
                      // 
    // body...
  }
</script>
  
<script>
  function submitformulaireun(val){
var PIECE_NOM= $('#PIECE_NOM').val();
var MARQUE_ID= $('#MARQUE_ID').val();
var PIECE_CATEGORIE_ID= $('#PIECE_CATEGORIE_ID').val();
$.post('<?php echo base_url('voiture/Reparation/save_piece_rechange')?>',
          {
            DESCRIPTION:DESCRIPTION
          },
          function(data){
            $('#PIECE_ID').html(data); 
            $('#PIECE_ID').selectpicker('refresh');
            
          });
      $('#modal_default').modal('hide');
}
</script>

</body>
</html>
