
<!-- PAGE-INDEX-STARTS -->

<div class="breadcrumbs">
    <div class="breadcrumbs-inner">
        <?php
        if($this->session->flashdata('message')) {
        $message = $this->session->flashdata('message');
        ?>
            <div class="alert alert-<?php echo $message['class']; ?>">
                <button class="close" data-dismiss="alert" type="button">×</button>
                <?php echo $message['message']; ?>
            </div>
        <?php } ?>
        <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>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- PAGE-INDEX-ENDS -->

<!-- PAGE-CONTENT-STARTS -->

<div class="content">
    <div class="animated fadeIn">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header">
                        <strong class="card-title"><?= $pDescription ?></strong>
                    </div>
                    <div class="card-body">
                        <table id="" class="table table-striped table-bordered dataTable-custom" data-ajax="Garage_request/get_all_Garage_request">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <td>Request Code</td>                                    
                                    <th>Customer Name</th>
                                    <th>Vehicle Details</th>
                                    <th>Booking Date</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                              
                            </tbody>
                            <tfoot>
                               <tr>
                                    <th>No</th> 
                                    <td>Request Code</td>                                   
                                    <th>Customer Name</th>
                                    <th>Vehicle Details</th>
                                    <th>Booking Date</th>
                                    <th>Action</th>
                               </tr>
                     </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
  <div id="myModal2" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false">
      <div class="modal-dialog modal-lg">

        <!-- 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" >
             
        <input class="form-control req_id" value="" type="hidden" id="req_id" >
        <input class="form-control grg_id" value="" type="hidden" id="grg_id" >
       
           <div class="form-group"  type="text">
           <h6>Quote Base</h6>
            </div>
           <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <input class="form-control" id="bl_cost" placeholder="Labour Cost">
                    </div>
                    <div class="col-md-6">
                         <input class="form-control" id="bp_cost" placeholder="Parts Cost">
                    </div>
                </div>
            </div>
             <div class="form-group">
           <h6>Quote Medium</h6>
            </div>
              <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <input class="form-control" id="ml_cost" placeholder="Labour Cost">
                    </div>
                    <div class="col-md-6">
                         <input class="form-control" id="mp_cost" placeholder="Parts Cost">
                    </div>
                </div>
            </div>
             <div class="form-group">
           <h6>Quote Premium</h6>
            </div>
              <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <input class="form-control" id="pl_cost" placeholder="Labour Cost">
                    </div>
                    <div class="col-md-6">
                         <input class="form-control" id="pp_cost" placeholder="Parts Cost">
                    </div>
                </div>
            </div>
          </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>
               

            </div>

 <!-- .model -->

            <div id="myModal23" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false">
      <div class="modal-dialog modal-lg">

        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Quote List</h4>
          </div>
          <div class="modal-body" id="details" >
             
   
          </div>
          <div class="modal-footer">
               <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>

      </div>
    </div>
                            </div>
                        </div>

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

            </div>
<!-- PAGE-CONTENT-ENDS -->
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>    
    <script type="text/javascript">        
        function doconfirm(){
        action = confirm("Are you sure to delete permanently?");
        if(action != true) return false;
        }
    </script>
    <script type="text/javascript">
  function getRequestDetails(request_id,garage_id){ 
      //$("#add_item").on('click', function(ev){
      
      jQuery('[id="myModal2"]').modal('show');
       $('.req_id').val(request_id);
        $('.grg_id').val(garage_id);
       ev.preventDefault();
      //})
}  

    
      $("#add_prod").on('click', function(){
        
        var req_id = $('#req_id').val();
        var grg_id = $('#grg_id').val();
        var bl_cost = $('#bl_cost').val();
        var bp_cost = $('#bp_cost').val();
        var ml_cost = $('#ml_cost').val();
        var mp_cost = $('#mp_cost').val();
        var pl_cost = $('#pl_cost').val();
        var pp_cost = $('#pp_cost').val();
       
        if(req_id){
            var post_data = {"garage_id": grg_id,"req_id":req_id,"bl_cost":bl_cost,"bp_cost":bp_cost,"ml_cost":ml_cost,"mp_cost":mp_cost,"pl_cost":pl_cost,"pp_cost":pp_cost};
          
           $.ajax({
            type: "POST",
            url: '<?php echo base_url('Garage_request/approve_garage'); ?>',
            data: post_data,
            success: function(response){
              var obj = JSON.parse(response);
              bundle_add_list(obj);
              item_list = obj;

                //$( "#result" ).empty().append( response );
            }
          });
        }        
      })

    

    </script>

     <script type="text/javascript">
  
     
function viewRequestDetails(request_id,garage_id){ 

    if(request_id=='' || request_id==undefined || request_id=='undefined' || request_id==null || request_id=='null'){
        return true;
    }
    // modalTrigger('Quote Details','');
    // addModalLoader();
    jQuery('[id="myModal23"]').modal('show');
    var resp = post_ajax(base_url+"Garage_request/getQuoteData",{'request_id':request_id,'view_all':'1'});
    if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
        remModalLoader();
        jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        return false;
    }
    var quote_data = jQuery.parseJSON(resp).data;
    
console.log(quote_data);
    jQuery.each(quote_data, function (index, value) {
        if(value == '' || value == null || value == undefined || value == 'null' || value == 'undefined'){
            quote_data[index] = ' -- ';
        }
    });
    var html =  '<table id="DataTables_Table_0" class="table table-striped table-bordered dataTable-custom dataTable" data-ajax="Garage_request/get_all_Garage_request" role="grid" aria-describedby="DataTables_Table_0_info">'+
                            '<thead>'+
                            
                                '<tr role="row">'+
                                  '<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 136.004px;" aria-label="Request Code: activate to sort column ascending">Request Code</th>'+
                                  '<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 346.004px;" aria-label="Customer Name: activate to sort column ascending">Quote Type</th>'+
                                  '<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 168px;" aria-label="Vehicle Details: activate to sort column ascending">Labour Cost </th>'+
                                  '<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 0px;" aria-label="Booking Date: activate to sort column ascending">Parts Cost</th>'+
                                  '<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 0px;" aria-label="Action: activate to sort column ascending">Status</th>'+
                                '</tr>'+
                            '</thead>'+
                            '<tbody>';
                              
                            

  
                                 for(var i=0; i<quote_data.length; i++)
                                    {
                                      
                               if(quote_data[i]['status']=='1'){}else{}         


                             html +='<tr role="row" class="odd">'+ 
                             '<td>'+quote_data[i]['request_code']+'</td>'+
                              '<td>'+quote_data[i]['quote_type']+'</td>'+
                              '<td>'+quote_data[i]['labour_cost']+'</td>'+
                              '<td>'+quote_data[i]['parts_cost']+'</td>';
                               if(quote_data[i]['status']=='1'){

                              html +=  '<td> <a class="btn btn-sm btn-success" onclick="viewRequestDetails(2,2)">'+
                              '<i class="fa fa-cog"></i> Approved </a></td>';
                               }else{
                               html +=  '<td> <a class="btn btn-sm btn-warning" onclick="viewRequestDetails(2,2)">'+
                              '<i class="fa fa-cog"></i> Not Approved </a></td>';
                               } 

                             html +=  '</tr>';
                        } 
                             html += 
                            '</tbody>'+
                           
                        '</table>';

    remModalLoader();
    jQuery('[id="details"]').html(html);

    jQuery('[id="customerProfileImg"]').error(function() {
        jQuery('[id="customerProfileImg"]').attr('src',base_url+'assets/images/no_image.png');
    });
}













    </script>