
<div class="breadcrumbs">
  <div class="breadcrumbs-inner">
    <div class="row m-0">
      <div class="col-sm-4">
        <div class="page-header float-left">
          <div class="page-title">
            <h1><?= $pTitle ?></h1>
          </div>
        </div>
      </div>
      <div class="col-sm-8">
        <div class="page-header float-right">
          <div class="page-title">
            <ol class="breadcrumb text-right">
              <li><a href="<?= base_url() ?>">Dashboard</a></li>
              <li><a ><?= $menu ?></a></li>
              <li class="active"><?= $smenu ?></li>
            </ol>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<!-- PAGE-INDEX-ENDS -->
<?php

$Currency = getCurrency();

?>

<div class="content">
  <div class="animated fadeIn">
    <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-header">
            <strong class="card-title"> <?= $smenu ?></strong>
          </div>
          <div class="card-body">
            <div id="pay-invoice">
             <?php 
             $url = (!isset($request_id)||empty($request_id))
             ?'Service/create_service':'Service/edit_service/'.$request_id;
             if($this->session->flashdata('message')) { 
              $flashdata = $this->session->flashdata('message'); ?>
              <div class="alert alert-<?= $flashdata['class'] ?>">
                <button class="close" data-dismiss="alert" type="button">×</button>
                <?= $flashdata['message'] ?>
              </div>
            <?php } ?>
            <div class="col-md-12">
              <div class="box box-primary">
                <div class="box-header with-border">
                  <h3 class="box-title"></h3>
                  <div class="pull-right box-tools"></div>
                </div>
                <div class="box-body">
                  <div class="col-md-12">
                    <div class="row">
                      <div class="col-md-12">
                        <img src="<?= (isset($requestData['0']->vehicle_image))? (base_url($requestData['0']->vehicle_image)):'' ?>" width="150px" height="92%" style="float: left;border: 1px solid #ccc; margin : 10px">
                        <div class="div1">
                          Services:<?= $requestData['0']->service_name ?></br>
                          Request Code: <?= $requestData['0']->request_code ?></br>
                          Customer:<?= $requestData['0']->customer_name ?></br>
                          Customer Phone:<?= $requestData['0']->phone_no ?></br>
                          Vehicle Name: <?= $requestData['0']->vehicle_name ?></br>
                          Model: <?= $requestData['0']->model ?></br>
                          Make: <?= $requestData['0']->make ?></br>
                          Year: <?= $requestData['0']->year ?></br>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="row">
                      <div class="col-md-12">
                        <div class="table-responsive">
                          <table class="table table-striped table-bordered " >
                            <thead>
                              <tr>
                                <th colspan="5">Assigned garages<span style="float: right;"><button class="btn btn-info btn-sm" type="button" id="add_item" onclick="getRequestDetails('<?= $requestData['0']->id ?>')">Assign</button>
                                </span>
                              </th>
                              </tr>
                              <tr>
                                <td>Garages Name</td>
                                <td>Phone</td>
                                <td>Garages Code</td>
                                <td>Location</td>
                              </tr>
                            </thead>
                          <?php  if  (isset($assign_garage)||!empty($assign_garage)||!null($assign_garage)) { ?>
                            <tbody id="bundle_list">
                              <?php   foreach($assign_garage as $key =>  $garage) { ?> 
                              <tr>                             
                                <td><?= $garage['garage_name'] ?></td>
                                <td><?= $garage['phone_no'] ?></td>
                                <td><?= $garage['garage_code'] ?></td>
                                <td><?= $garage['location'] ?></td>
                              </tr>
                            <?php } ?>
                            </tbody>
                            <?php } ?>      
                          </table>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </section>
      </div>
<div id="myModal2" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Garage List</h4>
      </div>
      <div class="modal-body" >
        <table class="table table-bordered">
          <thead>
           <input type="hidden" value="" id="req_id" class="req_id">
           <tr>
            <td colspan="2" >
              <select name="garages[]"  id="second"  class="form-control chosen-select" multiple data-placeholder="Choose Garage...">

                <option disabled="">Select Garage</option>
                <?php 
                foreach ($garageData as $garage) { ?>
                  <option value="<?php echo $garage->garage_id; ?>"><?php echo $garage->garage_name.'('.($garage->garage_code).')'; ?></option>
                <?php } ?>
              </select>
            </td>     
          </tr>
        </thead>


      </table>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-info" id="add_prod" data-dismiss="modal">Post</button>
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
  </div>

</div>
</div>


</div>
</div>

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

</div>
<!--/.col-->

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>     
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/select2.min.js"></script>
<script type="text/javascript">
 /* $('.garage2').select2({
    maximumSelectionLength: 2
  placeholder: 'Select an option'
});*/
</script>
<!-- PAGE-CONTENT-ENDS -->
<script type="text/javascript">
  function getRequestDetails(request_id){ 
      //$("#add_item").on('click', function(ev){

        jQuery('[id="myModal2"]').modal('show');
        $('.req_id').val(request_id);

       // ev.preventDefault();
      //})
    }  

    
    $("#add_prod").on('click', function(){
      var selectedValues = $('#second').val();
      var req_id = $('#req_id').val();


      if(selectedValues){
        var post_data = {"garage": selectedValues,"req_id":req_id};
          // var ids = JSON.stringify(selectedValues);

          $.ajax({
            type: "POST",
            url: '<?php echo base_url('Service_request/assign_garage'); ?>',
            data: post_data,
            success: function(response){

              window.location.reload();
            }
          });
        }        
      })

    

    </script>
    <style>
      .chosen-container{
        min-width: 100% !important;
      }
    </style>