
<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 
             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->vehicle_image))? (base_url($requestData->vehicle_image)):'' ?>" width="150px" height="92%" style="float: left;border: 1px solid #ccc; margin : 10px">
                        <div class="div1" style="line-height: 1.7">
                          Product  :  <?= $requestData->unique_name ?></br>
                          Request Code  :  <?= $requestData->posReq_id ?></br>
                          Customer  :  <?= $requestData->customer_name ?></br>
                          Customer Phone  :  <?= $requestData->customer_phone ?></br>
                          Vehicle Name  :  <?= $requestData->vehicle_name ?></br>
                          Model  :  <?= $requestData->model ?></br>
                          Make  :  <?= $requestData->make ?></br>
                          Year  :  <?= $requestData->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 POS <span style="float: right;"><button class="btn btn-info btn-sm" type="button" onclick="getRequestDetails('<?= $requestData->id ?>')">Assign</button>
                                </span>
                                </th>
                              </tr>
                              <?php  if(isset($assign_pos) && !empty($assign_pos)) { ?>
                              <tr>
                                <td>POS Name</td>
                                <td>POS Code</td>
                                <td>Phone</td>
                                <td>Location</td>
                              </tr>
                            <?php } ?>
                            </thead>
                            <?php  if(isset($assign_pos) && !empty($assign_pos)) { ?>
                            <tbody id="bundle_list">
                              <?php   foreach($assign_pos as $key =>  $pos) { ?> 
                              <tr>
                                <td><?= $pos['name'] ?></td>
                                <td><?= $pos['pos_code'] ?></td>
                                <td><?= $pos['phone_no'] ?></td>
                                <td><?= $pos['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="pos[]"  id="second"  class="form-control chosen-select" multiple data-placeholder="Choose Garage...">

                <option disabled="">Select POS</option>
                <?php 
                foreach ($posData as $key => $pos) { ?>
                  <option value="<?php echo $pos['pos_id']; ?>"><?php echo $pos['name'].'('.($pos['pos_code']).')'; ?></option>
                <?php } ?>
              </select>
            </td>     
          </tr>
        </thead>


      </table>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-info" id="assign_pos" 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){ 
    jQuery('[id="myModal2"]').modal('show');
    $('.req_id').val(request_id);
  }  

  $("#assign_pos").on('click', function(){
    var selectedValues = $('#second').val();
    var req_id = $('#req_id').val();
    if(selectedValues){
      var post_data = {"pos": selectedValues,"req_id":req_id};
      $.ajax({
        type: "POST",
        url: '<?php echo base_url('Pos_request/assign_pos'); ?>',
        data: post_data,
        success: function(response){
          window.location.reload();
        }
      });
    }        
  })


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