<table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="vehicle_allocations_view_table">
  <thead>
    <tr class="">
      <th>Sl No</th>
      <th>Date</th>
      <th>Vehicle</th>
      <th>Allocation Status</th>
      <th>Allocated Location</th>
      <th>Driver</th>
      <th>Remarks</th>
      <th>Actions</th>
      <th>Vehicle ID</th>
      <th>Allocation Status</th>
      <th>Location ID</th>
      <th>Driver ID</th>
      <th>Allocation ID</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>
<div class="modal fade" tabindex="-1" id="vehicle_allocation_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content" style="width: 750px">
      <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
          Allocate Vehicle
        </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">
            &times;
          </span>
        </button>
      </div>
      <form autocomplete="off" data-form-type="renewal" id="form_vehicle_allocation_add" data-modal-id="vehicle_allocation_add_modal" method="post" action="<?php echo base_url().'vehicles/create_allocation'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
        <div class="modal-body">
          <div class="m-form__content">
            <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_vehicle_allocation_add_msg">
              <div class="m-alert__icon">
                <i class="la la-warning"></i>
              </div>
              <div class="m-alert__text">
                Oh snap! Change a few things up and try submitting again.
              </div>
              <div class="m-alert__close">
                <button type="button" class="close" data-close="alert" aria-label="Close"></button>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-lg-8">
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Vehicle
                </label>
                <div class="input-group m-input-group--air m-input-group--pill  date">
                  <input id="vehicle_name_allocation_add"  type="text"  class="form-control  m-input form_vehicle_allocation_add_fields" readonly>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <input type="hidden" name="vehicle_id" id="vehicle_id_allocation_add" />
            <div class="col-lg-4">
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Date
                </label>
                <div class="input-group m-input-group--air m-input-group--pill  date">
                  <input id="date_allocation_add" name="date"  type="text"  class="form-control  m-input form_vehicle_allocation_add_fields" readonly>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-lg-4">
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Allocation Status
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required style="width: 100%" class="form-control m-select2  form_vehicle_allocation_add_select" id="allocation_status_add" name="allocation_status" required >
                    <option selected disabled>Select Status</option>
                    <option value="0">IDLE</option>
                    <option value="1">Allocate to Project/Warehouse</option>
                    <option value="2">Service/Maintenance</option>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group allocated_details_add_div" style="display:none">
                <label for="user_name">
                  Location
                </label>
                <div class="m-select2 m-select2--air m-select2--pill ">
                  <select  id="allocated_location_add" name="location" style="width: 100%" class="form-control m-input form_vehicle_allocation_add_select" aria-describedby="basic-addon1" data-placeholder="Select Location">
                    <option selected disabled>Select Location</option>
                    <?php
                    foreach($stock_locations as $row):
                      $location_name = $row->location_name;
                      if($row->location_type=='work_site'){
                        $location_name .= " [Project Site]";
                      }elseif($row->location_type=='ware_house'){
                        $location_name .= " [Warehouse]";
                      }
                      ?>
                      <option data-work-status="<?php echo $row->work_status?>"  data-work_id="<?= $row->work_id ?>" value="<?php echo $row->location_id?>"><?php echo $location_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4" >
              <div class="form-group m-form__group m-select2--pill allocated_details_add_div" style="display:none">
                <label for="user_name">
                  Driver/Operator
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select style="width: 100%" class="form-control m-select2 m-select2-general form_vehicle_allocation_add_select"  id="allocated_driver_add" name="driver" data-placeholder="Select Driver">
                    <option selected disabled>Select Driver</option>
                    <?php
                    foreach($driver_employees as $row):
                      ?>
                      <option value="<?php echo $row->employee_id?>"><?php echo $row->employee_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-12" >
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Remarks
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input type="text" name="remarks" class="form-control m-input m-input--pill m-input--air form_vehicle_allocation_add_fields" placeholder="Remarks" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">
            Close
          </button>
          <button type="submit" class="btn btn-primary form_submit_btn">
            Submit
          </button>
        </div>
      </form>
    </div>
  </div>
</div>
<div class="modal fade" tabindex="-1" id="vehicle_allocation_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content" style="width: 750px">
      <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
          Edit Vehicle Allocation
        </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">
            &times;
          </span>
        </button>
      </div>
      <form autocomplete="off" data-form-type="renewal" id="form_vehicle_allocation_edit" data-modal-id="vehicle_allocation_edit_modal" method="post" action="<?php echo base_url().'vehicles/update_allocation'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
        <div class="modal-body">
          <div class="m-form__content">
            <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_vehicle_allocation_edit_msg">
              <div class="m-alert__icon">
                <i class="la la-warning"></i>
              </div>
              <div class="m-alert__text">
                Oh snap! Change a few things up and try submitting again.
              </div>
              <div class="m-alert__close">
                <button type="button" class="close" data-close="alert" aria-label="Close"></button>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-lg-8">
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Vehicle
                </label>
                <div class="input-group m-input-group--air m-input-group--pill  date">
                  <input id="vehicle_name_allocation_edit"  type="text"  class="form-control  m-input form_vehicle_allocation_edit_fields" readonly>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <input type="hidden" name="vehicle_id" id="vehicle_id_allocation_edit" />
            <input type="hidden" name="allocation_id" id="allocation_id_edit" />
            <div class="col-lg-4">
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Date
                </label>
                <div class="input-group m-input-group--air m-input-group--pill  date">
                  <input id="date_allocation_edit" name="date"  type="text"  class="form-control  m-input form_vehicle_allocation_edit_fields" readonly>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-lg-4">
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Allocation Status
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required style="width: 100%" class="form-control m-select2  form_vehicle_allocation_edit_select" id="allocation_status_edit" name="allocation_status" required >
                    <option selected disabled>Select Status</option>
                    <option value="0">IDLE</option>
                    <option value="1">Allocate to Project/Warehouse</option>
                    <option value="2">Service/Maintenance</option>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group allocated_details_edit_div" style="display:none">
                <label for="user_name">
                  Location
                </label>
                <div class="m-select2 m-select2--air m-select2--pill ">
                  <select  id="allocated_location_edit" name="location" style="width: 100%" class="form-control m-input form_vehicle_allocation_edit_select" aria-describedby="basic-addon1" data-placeholder="Select Location">
                    <option selected disabled>Select Location</option>
                    <?php
                    foreach($stock_locations as $row):
                      $location_name = $row->location_name;
                      if($row->location_type=='work_site'){
                        $location_name .= " [Project Site]";
                      }elseif($row->location_type=='ware_house'){
                        $location_name .= " [Warehouse]";
                      }
                      ?>
                      <option data-work-status="<?php echo $row->work_status?>"  data-work_id="<?= $row->work_id ?>" value="<?php echo $row->location_id?>"><?php echo $location_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-4" >
              <div class="form-group m-form__group m-select2--pill allocated_details_edit_div" style="display:none">
                <label for="user_name">
                  Driver/Operator
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select style="width: 100%" class="form-control m-select2 m-select2-general form_vehicle_allocation_edit_select"  id="allocated_driver_edit" name="driver" data-placeholder="Select Driver">
                    <option selected disabled>Select Driver</option>
                    <?php
                    foreach($driver_employees as $row):
                      ?>
                      <option value="<?php echo $row->employee_id?>"><?php echo $row->employee_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-12" >
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Remarks
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input id="allocation_remarks" type="text" name="remarks" class="form-control m-input m-input--pill m-input--air form_vehicle_allocation_edit_fields" placeholder="Remarks" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">
            Close
          </button>
          <button type="submit" class="btn btn-primary form_submit_btn">
            Submit
          </button>
        </div>
      </form>
    </div>
  </div>
</div>
<div class="modal fade" tabindex="-1" id="vehicle_allocation_delete_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" >
    <form id="form_vehicle_allocation_delete" data-modal-id="vehicle_allocation_delete_modal" autocomplete="off" method="post" action="<?php echo base_url().'vehicles/delete_allocation'?>" class="form-horizontal">
      <div class="modal-content">
        <div class="alert alert-danger" role="alert" style="margin-bottom: 0px">
          <button type="button" class="close" data-dismiss="modal"></button>
          <br/>
          <h4 class="alert-heading">Warning! Please Confirm Your Action</h4>
          <br/>
          <p> Are You Sure to Delete this Data ?. All the Associated Data will Lost. </p>
          <p>
            <button class="btn btn-danger form_submit_btn" type="submit" name="submit">Confirm & Delete</button>
            <button type="button" class="btn btn-primary modal-dismiss" data-dismiss="modal">Cancel</button>
          </p>
          <input type="hidden" name="allocation_id" id="allocation_id_delete">
        </div>
      </div>
    </form>
  </div>
</div>
