
<!-- 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="Pos_request/get_all_Pos_request">
                            <thead>
                                <tr>                                   
                                    <th type="hidden">Id</th>
                                    <th>PosCode</th>
                                    <th>Customer Name</th>
                                    <th>Phone</th>
                                    <th>Product Name</th>
                                    <th>Status</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="myModal24" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Request Details</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>
<!-- PAGE-CONTENT-ENDS -->
        
    <script type="text/javascript">        
        function doconfirm(){
            action = confirm("Are you sure to delete permanently?");
            if(action != true) return false;
        }

        function getPos_requestDetails(request_id){ 
            if(request_id=='' || request_id==undefined || request_id=='undefined' || request_id==null || request_id=='null'){
                return true;
            }
            jQuery('[id="myModal24"]').modal('show');
            var resp = post_ajax(base_url+"Pos_request/getPosData",{'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; 
            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" 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="2" style="width: 200px;" aria-label="Request Code: activate to sort column ascending">Request Code:'+ quote_data['posReq_id']+'</th>'+
                          '</tr>'+
                    '</thead>'+
                    '<tbody>'+
                  '<tr role="row" class="odd">'+ 
                     '<td>Product Name</td>'+
                      '<td>'+ quote_data['unique_name']+'</td>'+
                      '</tr>'+
                    '</tbody>'+
                '</table>'+
            '<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="2" style="width: 200px;" aria-label="Request Code: activate to sort column ascending">Customer Details</th>'+
                      // '<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="2" style="width: 200px;" aria-label="Customer Name: activate to sort column ascending">Vehicle</th>'+
                    '</tr>'+
                '</thead>'+
                '<tbody>'+
                '<tr role="row" class="odd">'+ 
                 '<td>Name</td>'+
                 '<td>'+ quote_data['customer_name']+'</td>'+
                 '</tr>'+
                 '<tr role="row" class="odd">'+ 
                 '<td>Phone No</td>'+
                 '<td>'+ quote_data['phone_no']+'</td>'+
                 '</tr>'+
                  '<tr role="row" class="odd">'+ 
                 '<td>Address</td>'+
                 '<td>'+ quote_data['house_no']+', '+quote_data['phone_no']+', '+quote_data['area']+', '+quote_data['city']+', '+quote_data['district']+'</td>'+
                 '</tr>'+
                '</tbody>'+
                '</table>'+
                 '<table id="DataTables_Table_0" class="table table-striped table-bordered dataTable-custom dataTable" 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="2" style="width: 200px;" aria-label="Request Code: activate to sort column ascending">Vehicle</th>'+
                    '</tr>'+
                '</thead>'+
                '<tbody>'+
                '<tr role="row" class="odd">'+ 
                 '<td>Vehicle Name</td>'+
                 '<td>'+ quote_data['vehicle_name']+'</td>'+
                 '</tr>'+
                 '<tr role="row" class="odd">'+ 
                  '<td>Vehicle Modal</td>'+
                  '<td>'+ quote_data['model']+'</td>'+
                 '</tr>'+
                   '<tr role="row" class="odd">'+ 
                  '<td>Vehicle Make</td>'+
                  '<td>'+ quote_data['make']+'</td>'+
                 '</tr>'+
                  '<tr role="row" class="odd">'+ 
                  '<td>Vehicle Year</td>'+
                  '<td>'+ quote_data['year']+'</td>'+
                 '</tr>'+
                  '<tr role="row" class="odd">'+ 
                  '<td>Vehicle Mileage</td>'+
                  '<td>'+ quote_data['mileage']+'</td>'+
                 '</tr>'+
                '</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');
            });
        }


        function sendQuote(req_id,partId){
          if(req_id == '' || req_id==undefined || req_id == 'undefined' || req_id == null || req_id=='null' || partId == '' || partId==undefined || partId == 'undefined' || partId == null || partId=='null'){
            return true;
          }
          modalTrigger('Send Quote','');
          addModalLoader();
          jQuery.ajax({
            url : base_url+"Pos_request/getPosDetails",
            type : 'POST',
            data : {'requestId':req_id,'view_all':'1'},
            success : function(resp){
              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 resp_data = jQuery.parseJSON(resp);
              if(resp_data['status'] == '0'){
                remModalLoader();
                jQuery('[id="modal_content"]').html('Something went wrong, Please try again later...!');
                return false;
              }

              var issueHtml = '';
              issueHtml +=  '<form id="customQuote" role="form" method="post">'+
                               '<div class="col-md-12" style="padding-top:10px">'+
                                '<div class="row"><label><b>Product Details</b></label></div>'+
                                '<div class="row">'+
                                    '<div class="col-md-6">'+
                                        '<div class="row">'+
                                            '<div class="col-md-6">Request Code</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].posReq_id+'</label></div>'+
                                        '</div> '+
                                    '</div>'+
                                    '<div class="col-md-6">'+
                                        '<div class="row">'+
                                            '<div class="col-md-6">Product Name</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].unique_name+'</label></div>'+
                                        '</div> '+
                                    '</div>'+
                                    '</div>'+
                                '</div>'+
                                '<div class="col-md-12" style="padding-top:20px;">'+
                                    '<div class="row"><label><b>Customer Details</b></label></div>'+
                                    '<div class="row">'+
                                    '<div class="col-md-6">'+
                                        '<div class="row">'+
                                            '<div class="col-md-6">Customer Name</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].customer_name+'</label></div>'+
                                        '</div> '+
                                        '<div class="row"> '+
                                            '<div class="col-md-6">Customer Ph No</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].phone_no+'</label></div> '+
                                        '</div> '+
                                    '</div>'+
                                    '<div class="col-md-6">'+
                                        '<div class="row"> '+
                                            '<div class="col-md-6">Customer Location</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].area+'</label></div> '+
                                        '</div> '+
                                    '</div>'+
                                    '</div>'+
                                '</div> '+
                                '<div class="col-md-12" style="padding-top:20px;">'+
                                    '<div class="row"><label><b>Vehicle Details</b></label></div>'+
                                    '<div class="row">'+
                                    '<div class="col-md-6">'+
                                        '<div class="row">'+
                                            '<div class="col-md-6">Vehicle Make</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].make+'</label></div>'+
                                        '</div> '+
                                        '<div class="row">'+
                                            '<div class="col-md-6">Vehicle Year</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].year+'</label></div>'+
                                        '</div> '+
                                    '</div>'+
                                     '<div class="col-md-6">'+
                                         '<div class="row">'+
                                            '<div class="col-md-6">Vehicle Model</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].model+'</label></div>'+
                                        '</div> '+
                                         '<div class="row">'+
                                            '<div class="col-md-6">Vehicle mileage</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-4"><label>'+resp_data['data'].mileage+'</label></div>'+
                                        '</div> '+
                                    '</div>'+
                                    '</div>'+
                                '</div> '+
                                '<div class="col-md-12">'+
                                   '<div class="row"><label><b>Add Cost</b></label></div>'+
                                   '<div class="col-md-12">'+
                                       '<div class="row">'+
                                            '<div class="col-md-3"> Amount</div>'+
                                            '<div class="col-md-1">:</div>'+
                                            '<div class="col-md-5">'+
                                                '<input class="marginTop10" placeholder="Amount" id="amount" type="number" name="amount">'+
                                                '<input class="marginTop10" id="req_id" value="'+req_id+'" type="hidden">'+
                                                '<input class="marginTop10" id="part_id" value="'+partId+'" type="hidden">'+
                                            '</div>'+
                                            '<div class="col-md-3">'+
                                                '<button type="button" style="height: 25px;font-size: 13px;padding-bottom: 22px;" onclick="submitCustQuote(event);" class="btn btn-primary">Submit</button>'+
                                            '</div>'+
                                        '</div>'+
                                    '</div>'+
                                '</div>'+
                            '</form>';
              remModalLoader();
              jQuery('[id="modal_content"]').html(issueHtml);
            },
            fail: function(xhr, textStatus, errorThrown){
                remModalLoader();
                jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
            },
            error: function (ajaxContext) {
                remModalLoader();
                jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
            }
          })
        }

function submitCustQuote(e){
  e.preventDefault();

  var amount = jQuery('[id="amount"]').val();
  var reqId = jQuery('[id="req_id"]').val();
  var partId = jQuery('[id="part_id"]').val();
  if((amount != '' && reqId == '') || (amount == '' && reqId != '')){
    if(amount == ''){
      jQuery('[id="amount"]').addClass('errInput');
    }
    if(reqId == '' || partId == ''){
      remModalLoader();
      jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
    }
    return false;
  }
  jQuery.ajax({
      url  : base_url+"Pos_response/SendCustomQuote", 
      type : 'POST',
      data : {"amount":amount,"reqId":reqId,'partId':partId},
      success: function(resp){
        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 resp_data = jQuery.parseJSON(resp);
        if(resp_data['status'] == 'error'){
          remModalLoader();
          jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
          return false;
        }
        else{
          window.location.reload();
        }
      },
        fail: function(xhr, textStatus, errorThrown){
          remModalLoader();
          jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
        },
        error: function (ajaxContext) {
          remModalLoader();
          jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
      }
  })
}


  function quoteDetails(req_id){
    if(req_id == '' || req_id==undefined || req_id == 'undefined' || req_id == null || req_id=='null'){
      return true;
    }
    modalTrigger('Send Quote Details','');
    addModalLoader();
    jQuery.ajax({
      url : base_url+"Pos_request/getSendQuoteDetails",
      type : 'POST',
      data : {'requestId':req_id,'view_all':'1'},
      success : function(resp){
        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 resp_data = jQuery.parseJSON(resp);
        if(resp_data['status'] == '0'){
          remModalLoader();
          jQuery('[id="modal_content"]').html('Something went wrong, Please try again later...!');
          return false;
        }

        var issueHtml = '';
        issueHtml +=  '<form id="customQuote" role="form" method="post">'+
                         '<div class="col-md-12" style="padding-top:10px">'+
                          '<div class="row"><label><b>Product Details</b></label></div>'+
                          '<div class="row">'+
                              '<div class="col-md-6">'+
                                  '<div class="row">'+
                                      '<div class="col-md-6">Request Code</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].posReq_id+'</label></div>'+
                                  '</div> '+
                              '</div>'+
                              '<div class="col-md-6">'+
                                  '<div class="row">'+
                                      '<div class="col-md-6">Product Name</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].unique_name+'</label></div>'+
                                  '</div> '+
                              '</div>'+
                              '</div>'+
                          '</div>'+
                          '<div class="col-md-12" style="padding-top:20px;">'+
                              '<div class="row"><label><b>Customer Details</b></label></div>'+
                              '<div class="row">'+
                              '<div class="col-md-6">'+
                                  '<div class="row">'+
                                      '<div class="col-md-6">Customer Name</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].customer_name+'</label></div>'+
                                  '</div> '+
                                  '<div class="row"> '+
                                      '<div class="col-md-6">Customer Ph No</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].phone_no+'</label></div> '+
                                  '</div> '+
                              '</div>'+
                              '<div class="col-md-6">'+
                                  '<div class="row"> '+
                                      '<div class="col-md-6">Customer Location</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].area+'</label></div> '+
                                  '</div> '+
                              '</div>'+
                              '</div>'+
                          '</div> '+
                          '<div class="col-md-12" style="padding-top:20px;">'+
                              '<div class="row"><label><b>Vehicle Details</b></label></div>'+
                              '<div class="row">'+
                              '<div class="col-md-6">'+
                                  '<div class="row">'+
                                      '<div class="col-md-6">Vehicle Make</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].make+'</label></div>'+
                                  '</div> '+
                                  '<div class="row">'+
                                      '<div class="col-md-6">Vehicle Year</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].year+'</label></div>'+
                                  '</div> '+
                              '</div>'+
                               '<div class="col-md-6">'+
                                   '<div class="row">'+
                                      '<div class="col-md-6">Vehicle Model</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].model+'</label></div>'+
                                  '</div> '+
                                   '<div class="row">'+
                                      '<div class="col-md-6">Vehicle mileage</div>'+
                                      '<div class="col-md-1">:</div>'+
                                      '<div class="col-md-4"><label>'+resp_data['data'].mileage+'</label></div>'+
                                  '</div> '+
                              '</div>'+
                              '</div>'+
                          '</div> '+
                          '<div class="col-md-12">'+
                             '<div class="row"><label><b>Send Quote Details</b></label></div>'+
                             '<div class="row">'+
                               '<div class="col-md-6">'+
                                   '<div class="row">'+
                                        '<div class="col-md-6"> Amount</div>'+
                                        '<div class="col-md-1">:</div>'+
                                        '<div class="col-md-4">'+
                                          '<label>'+resp_data['data'].cost+'</label>'+
                                        '</div>'+
                                    '</div>'+
                                '</div>'+
                              '</div>'+
                          '</div>'+
                      '</form>';
        remModalLoader();
        jQuery('[id="modal_content"]').html(issueHtml);
      },
      fail: function(xhr, textStatus, errorThrown){
          remModalLoader();
          jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
      },
      error: function (ajaxContext) {
          remModalLoader();
          jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
      }
    })
  }

    </script>