@extends('layouts.admin')

  <title>Best Insurance | Completed Leads</title>
 
@section('content')
<!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
  <!-- Bootstrap CSS -->
<section class="content">
<div class="row">
    <div class="col-xs-12">
      <div class="box">
            <div class="box-header">
            
            </div>
            <div class="box-body table-responsive">
            <div class=" padding-left-none padding-right-none">
            <div class="dt-buttons">
                <a class="buttons-excel buttons-html5 btn btn-primary" tabindex="0" aria-controls="leadsList" href="{{ URL::to('account/completed-lead-export-to-excel') }}">
                <span class="">Export to excel</span>
                </a>
            </div>
            </div>
              <table class="table table-bordered table-responsive" id="completed-lead-table">
              <thead>
                  <tr>
                     
                       <th class="table-index appdate" width="5px">Application Date</th>
                      <th class="table-index">Insurance Start Date</th>
                      <th class="table-index">Policy Number</th>
                      <th class="table-index">Policy</th>
                      <!--<th class="table-index">Insurer</th>-->
                      <th class="table-index">Full Name</th>
                      <th class="table-index" width="5px">Cover Type</th>
                      <th class="table-index">Source</th>
                      <th class="table-index">Submitted By</th>
                      <th style="text-align: center" class="table-index" width="5px">Status</th>
                      <th style="text-align: center" class="table-index" width="5px">Customer Status</th>
                      <th class="table-index">Payment</th>
                      <th class="table-index">Bexhill LoanID</th>
                      <th class="table-index">Actions</th>
                      <!-- <th class="table-index">Created Date</th> -->
                      <!-- <th class="table-index">FirstName</th> -->
                      <!-- <th class="table-index">LastName</th> -->
                  </tr>
              </thead>
              <tbody>
                
              </tbody>
          </table>
            </div>
            
           <a data-target="#ConfirmDelete" role="button" data-toggle="modal" id="trigger"></a>
        </div>
    </div>
  </div>
</section>
<!-- Reject button modal -->
 <a data-target="#ConfirmReject" role="button" data-toggle="modal" id="rejectTrigger"></a>
<div class="modal fade" id="ConfirmReject">
    <div class="modal-dialog">
      <div class="modal-content">
          <!-- modal header -->
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
            <!-- modal title -->
            <div class="modal-title" id="reject-modal-title">  </div>
          </div>
          <!-- modal body -->
          <div class="modal-body " id="reject-modal-body">
          </div>

          <div class="modal-body" id="comment-btn">
          {{Form::open(array('url' => '/account/completed-leads/change-status', 'method' => 'POST', 'id' => 'formValidation'))}}
            <div class="form-group required" >
            <span class="control-label"></span>
              {{Form::label('Please provide the reasons for rejecting')}}
              {{Form::text('comment',null,array('class' => 'form-control','id' => 'comment'))}}
              {{Form::hidden('id',null,array('class' => 'form-control','id' => 'comment_id'))}}
            </div>
            <div class="form-group">
              {{Form::submit('Submit',array('class' => 'btn btn-success'))}}
            </div>
          {{Form::close()}}
          </div>

          <div class="modal-footer">
              <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
              <!-- confirm button -->
              <div id="RejConfirmButton"></div>
          </div>

      </div>
    </div>
</div>

<!-- Genetare schedule button modal -->
<a data-target="#gnrtSceduleTarget" role="button" data-toggle="modal" id="gnrtSceduleTarg"></a>
<div class="modal fade" id="gnrtSceduleTarget" style="text-align:center; height: auto;">
    <div class="modal-dialog">
      <div class="modal-content">
          <!-- modal header -->
          <div class="modal-header">
          <div class="pull-left" >
          <h4 style="color:#12a1a5" ><b>{{strtoupper( 'Schedule versions')}}</b></h4>
          </div>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close" id="close-model">
              <span aria-hidden="true">×</span>
            </button>
            <!-- modal title -->
            <div class="modal-title" id="scedule-modal-title">  </div>
          </div>
          <!-- modal body -->
          <div class="modal-body" id="scedule-modal-body">
          
          {{Form::open(array('url' => '/account/completed-leads/download-generate-scedule-pdf', 'method' => 'POST', 'id' => 'PdfForm'))}}
            <div class="form-group" id="versions" style="height: auto;">

              <br>
            </div>
            <input type="hidden" name="infoId" id="infoId" >
            <!-- <input type="hidden" name="" id="logInfoId" > -->
          </div>
          <div class="modal-footer" style="padding-top: 15px">
            <div class="col-xs-12">
              <div class="col-xs-3" style="padding-right: 0px;">
              <button type="button"  class="btn btn-default pull-left " data-dismiss="modal" id="close_button">Close</button>
              </div>
              <!-- confirm button -->
              <div class="col-xs-4" style="padding-right: 0px;">
              <div class="" >
                <input type="button" name="email_send" value="Mail" class="btn btn-success" id="btn-mail-send"/>
              </div>
              </div>
              <div class="col-xs-5">
                <div id="sceduleConfirmButton"></div>
                <div class="" >
                {{Form::submit('Download',array('class' => 'btn btn-success','id'=>'downlBtn'))}}
                </div>
              </div>

            </div>
          </div>
          {{Form::close()}}
      </div>
    </div>
</div>
<!-- Peding model -->
<!-- <a data-target="#pendingBtn" role="button" data-toggle="modal" id="pendingTrigger"></a> -->
<div class="modal fade" id="pendingBtn">
    <div class="modal-dialog">
      <div class="modal-content">
          <!-- modal header -->
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
            <!-- modal title -->
            <div class="modal-title" id="reject-modal-title">Change Status </div>
          </div>
          <!-- modal body -->
          <div class="modal-body" id="reject-modal-body">
          </div>

           <div class="modal-body" id="cancelled-modal-body">
           sdgsdf
          </div>

          <div class="modal-body" id="comment-btn">
          {{Form::open(array('url' => '/account/completed-leads/change-to-aaprove-status', 'method' => 'POST', 'id' => 'formValidation'))}}
            <div class="form-group" style="text-align: center" >
            <span class="control-label">Are you really want to approve this application?</span>
              
              <!-- <button class="btn btn-default">Approve</button> -->
                
              <!-- <a href="#" class="btn btn-default  rejectBtn" data-id="'.$query_data->id.'" data-target="#pendingBtn" data-toggle="modal">Reject</a> -->

              {{Form::hidden('id',null,array('class' => 'form-control','id' => 'information_id'))}}

            </div>
            <div class="form-group">
              
            </div>
          
          </div>

          <div class="modal-footer">
              <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Close</button>
              <!-- confirm button -->
              {{Form::submit('Approve',array('class' => 'btn btn-success'))}}
              {{Form::close()}}
              <!-- <div id="RejConfirmButton"> --></div>
          </div>

      </div>
    </div>
</div>


<!-- Modal -->
<div class="cnclmodal modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width:500px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
            
              <div><h2>Update the customer status.</h2></div>
                <div class="form-group">


                <table class='table table-borderless'>
                    <tr>
                      <td><b>Customer Status:</b></td>
                      <td>
                        <select name='update_customer_status' id="update_customer_status">
                          <option value='Submitted'>Submitted</option>
                          <option value='Arrears'>Arrears</option>
                          <option value='DD Cancelled'>DD Cancelled</option>
                          <option value='FNOL'>FNOL</option>
                          <option value='Sold'>Sold</option>
                          <option value='Sold-Claim'>Sold-Claim</option>
                          <option value='Sold-Claim-Arrears'>Sold-Claim-Arrears</option>
                          <option value='Sold-Claim-Complaint'>Sold-Claim-Complaint</option>
                          <option value='Sold-Complaint'>Sold-Complaint</option>
                          <option value='' disabled>------------------------------</option>
                          <option value='Cancel' style="color:red;">Cancel Policy</option>
                        </select>
                      </td>
                    </tr>
                    <tr>
                      <td><input type="button" value="Update" id="" class="btn btn-primary updateStatus" /></td>
                    </tr>
                    <input type="hidden" name="selected_id" id="selected_id" value="">
                  </table>
                </div>
               
             

            </div>
        </div>
    </div>
</div>
<!-- End Modal -->


<!-- Modal -->
<div class="cnclmodal modal fade" id="myModalReject" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document" style="width:500px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
            
              <div><h2>Update the customer status.</h2></div>
                <div class="form-group">


                <table class='table table-borderless'>
                    <tr>
                      <td><b>Customer Status:</b></td>
                      <td>
                        <select name='update_customer_status_reject' id="update_customer_status_reject">
                          <option value='Submitted'>Submitted
                        </select>
                      </td>
                    </tr>
                    <tr>
                      <td><input type="button" value="Update" id="" class="btn btn-primary updateStatusReject" /></td>
                    </tr>
                    <input type="hidden" name="selected_id" id="selected_id" value="">
                  </table>
                </div>
               
             

            </div>
        </div>
    </div>
</div>
<!-- End Modal -->

<!-- Modal mail to send -->
<div class="modal fade" id="email_send" tabindex="-1" role="dialog" aria-labelledby="email_send_Label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" >Email to send</h4>
            </div>
            <div class="modal-body">
              <form id="cc_email_form" class="popform">  
                <div class="form-group">
                  <label>CC</label>
                  <input type="text"  data-role="tagsinput" name="cc_emails" required>
                </div>
                
                <div class="form-group">
                  <label>BCC</label>
                  <input type="text"  data-role="tagsinput" name="bcc_emails" required> 
                </div>
                
                <div class="form-group" style="text-align: center;">
                  <input type="button" value="Send Email" id="final_btn_sened_email" class="btn btn-success " />
                </div>
                
              </form>
            </div>
        </div>
    </div>
</div>
<!-- End Modal -->


<!-- Modal mail to send -->
<div class="modal fade" id="email_send_cancel" tabindex="-1" role="dialog" aria-labelledby="email_send_Label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" >Email to send</h4>
            </div>
            <div class="modal-body">
              <form id="cc_email_form" class="popform">  
                 <input type="hidden"  name="send_mail" value="true"/>
                <div class="form-group">
                  <label>CC</label>
                  <input type="text"  data-role="tagsinput" name="cc_emails" required>
                </div>
                
                <div class="form-group">
                  <label>BCC</label>
                  <input type="text"  data-role="tagsinput" name="bcc_emails" required> 
                </div>
                
                <div class="form-group" style="text-align: center;">
                  <input type="button" value="Send Email" id="final_btn_cancel_email" class="btn btn-success " />
                </div>
                
              </form>
            </div>
        </div>
    </div>
</div>
<!-- End Modal -->




@stop

@section('pageBottomJs')
<style type="text/css">
    @media screen and (max-width: 767px) {
    li.paginate_button.previous {
        display: inline;
    }
 
    li.paginate_button.next {
        display: inline;
    }
 
    li.paginate_button {
        display: inline;
    }
  }
  /* */
  .popform label{
    width: 35px;
  }
  .popform input{
    outline: none;
    border: 1px solid #cecece;
    height: 30px;
    width: 210px;
    padding: 5px 15px;
    font-size: 14px;
  }
  .modal-body {
    border: 0px white solid;
    position: relative;
  }
  .modal-dialog {
    width: 300px;
}
.modal-content {
    border-radius: 8px;
}
    /* for validation msg */
    .error{
      color:red;
    }

    /**/
    .version-1{
      margin-top: 10px;
    }
    /**/
    .table-index{
      padding-right: 27px;
    }

    .table>thead:first-child>tr:first-child>th {
    border-top: 0;
    padding: 5px;
}
.table>thead:first-child>tr:first-child>th{
  /*white-space: nowrap;*/
}
.appdate{
  white-space: nowrap;
}
.cnclmodal .modal-dialog{
  width: 45%
}
.cnclmodal .modal-header .close{ 
    position: absolute;
    right: -10px;
    top: -10px;
    padding: 0px 8px;
    border-radius: 100%;
    background-color: #f00;
    opacity: 1;
    color: #FFF;
    line-height: normal;
    height: 27px;
}
.cnclmodal .modal-header{
     padding: 0px;
    border: 0px;
}
.cnclmodal form{
  margin-bottom: 0px;
}
.cnclmodal .formtitle h1{
    padding: 0px;
    padding-bottom: 6px;
    margin-bottom: 10px;
    text-align: left;
    font-size: 30px;
    font-weight: 500;
    margin-top: 0px;
    border-bottom: 1px solid #e8e8e8;
}
.cnclmodal .cancltext{
  margin-bottom: 30px;
}
.cnclmodal .cancltext label{
    font-size: 16px;
    font-weight: 400;
    color: #8a8a8a;
}
.cnclmodal .cancltext select,
.cnclmodal .cancltext input[type="date" i]{
  height: 40px;
    padding: 0px 10px;
    font-size: 16px;
    border: 1px solid #dcdcdc;
    color: #505050;
}
.cnclmodal .cancltextarea textarea{
width:100%;
height: 100px;
    padding: 10px;
    font-size: 16px;
    border: 1px solid #dcdcdc;
    color: #505050;
}
.cnclmodal .subbtn{
    background-color: #000;
    border: 0px;
    color: #FFF;
    font-size: 20px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 10px 30px;
    line-height: normal;
}
.cnclmodal input[type=date]::-webkit-inner-spin-button, 
.cnclmodal input[type=date]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
@media (max-width: 991px) {
    .cnclmodal .modal-dialog{
  width: 98%
}
}
</style>

<script src="{{ URL::asset('assets/js/dataTables/jquery.dataTables.min.js') }}"></script>

<script src="{{ URL::asset('assets/js/dataTables/dataTables.bootstrap.min.js') }}"></script>

<script src="{{ URL::asset('assets/js/dataTables/serverSideDataTables/jquery.dataTables.yadcf.js') }}"></script>

<link rel="stylesheet" href="{{ URL::asset('assets/js/dataTables/dataTables.bootstrap.css') }}">

<script>
$(document).ready(function() {
   var completed_leads_js = $('#completed-lead-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            "url": '{!! url('account/completed-lead/data') !!}',
            "type": "POST"
        },
        columns: [
            { data: 'date_added', name: 'date_added' ,'searchable': false},
            { data: 'insurance_startdate', name: 'insurance_startdate','searchable': false },
            { data: 'policy_number_full', name: 'policy_number_full' },
            { data: 'product_name', name: 'product_name','searchable': false },
           // { data: 'insurer', name: 'insurer', 'searchable': false},
            { data: 'full_name', name: 'full_name'},
            { data: 'typeofcover', name: 'typeofcover'},
            { data: 'lead_source_field', name: 'lead_source_field','searchable': false},
            { data: 'submitted_by', name: 'submitted_by','searchable': false},
            // { data: 'rates', name: 'rates' },
            { data: 'status', name: 'status','searchable': false },
            { data: 'customer_status', name: 'customer_status','searchable': false },
            { data: 'payment', name: 'payment','searchable': false },
            {data: 'active_loan_id', name: 'active_loan_id','searchable': true },
            { data: 'actions', name: 'actions','searchable': false}
        ],
        "columnDefs": [
            { "orderable": false, "targets": [10,11] },
        ]
    });






    $(document).on('click', '.btn-success', function(){
      var id=$(this).attr('data-atr');
      if(id != undefined){
        var action_url ='{{URL::to('branch-admin/assign-to')}}/'+id;
        $.ajax({
          type : 'get',
          url  : action_url,
          success:function(data){
            $('.modal-body').html(data);
          }
        });  
      }
    });


    



    $(document).on('click', '.payment', function(){
      var id=$(this).attr('data-atr');
      var action_url ='{{URL::to('payment')}}/'+id;
      $.ajax({
        type : 'get',
        url  : action_url,
        success:function(data){
          $('#myModal .modal-body').html(data);
        }
      });
    });


    $(document).on('click', '.refund', function(){
      var id=$(this).attr('data-atr');
      var action_url ='{{URL::to('refund')}}/'+id;
      $.ajax({
        type : 'get',
        url  : action_url,
        success:function(data){
          $('#myModal .modal-body').html(data);
        }
      });
    });


  


    $(document).on('click', '.updateStatus', function(){
      var id=$('#selected_id').val();
    //  alert(id);
      var customer_status=$('#update_customer_status').val();

     // var e = document.getElementById("update_customer_status").value();
     // alert(customer_status);

     
      if (confirm('Are you sure want to update the customer status?')) {


        if(customer_status=="Cancel")
        {

          window.location.href= '{{URL::to('cancelled')}}/'+id;
         // cancelled/97965

        }
        else
        {

          var action_url ='{{URL::to('updateCustomerStatus')}}/'+customer_status+'/'+id;

          $.ajax({
              type : 'post',
              url  : action_url,
              success:function(data){
             //$('#myModal .modal-body').html(data);
              window.location.reload();

              }
            });

        }
        
            
       }

    
    });


      $(document).on('click', '.updateStatusReject', function(){
      var id=$('#selected_id').val();
    //  alert(id);
      var customer_status=$('#update_customer_status_reject').val();

     // var e = document.getElementById("update_customer_status").value();
     // alert(customer_status);

     
      if (confirm('Are you sure want to update the customer status?')) {


        if(customer_status=="Cancel")
        {

          window.location.href= '{{URL::to('cancelled')}}/'+id;
         // cancelled/97965

        }
        else
        {

          var action_url ='{{URL::to('updateCustomerStatus')}}/'+customer_status+'/'+id;

          $.ajax({
              type : 'post',
              url  : action_url,
              success:function(data){
             //$('#myModal .modal-body').html(data);
              window.location.reload();

              }
            });

        }
        
            
       }

    
    });


    $(document).on('click', '.updateStatusBtn', function(){
      var id=$(this).attr('data-atr');
    //  alert(id);
     $('#selected_id').val(id);
    // alert($('#selected_id').val());

   
    });

     $(document).on('click', '.updateStatusBtnReject', function(){
      var id=$(this).attr('data-atr');
    //  alert(id);
     $('#selected_id').val(id);
    // alert($('#selected_id').val());

   
    });



    $(document).on('click', '.revert', function(e){
      e.preventDefault();
      var id=$(this).attr('data-atr');
      var action_url ='{{URL::to('revert')}}/'+id;
      if (confirm('Are sure want to revert')) {
          window.location = action_url;
      }
    });


    $(document).on("submit", "#cancelled_window_form", function(e) {
        e.preventDefault();
        var form = $(this);
        var url = form.attr('action');
        $.ajax({
            type: "POST",
            url: url,
            data: form.serialize(), // serializes the form's elements.
            success: function(data) {
              //alert(data);
           //   console.log(data);
                $('.modal').modal('hide');
              //  window.location.href = "{{url('cancel/download')}}?logInfoId=" + data.logInfoId;
              //  completed_leads_js.ajax.reload(null, false);
            }
        });
    });


        $(document).on("click","#final_btn_cancel_email", function (event) {
         $('#final_btn_cancel_email').attr("disabled",'true');
         $('#final_btn_cancel_email').val("Please wait");
          var conbibned_data = $('#cancelled_window_form,#cc_email_form').serialize();
          $.ajax({
                type: "POST",
                url: "/cancelled",
                headers: {
                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: conbibned_data,
                datatype: "json",
                success: function(results){
                    console.warn(results.status);
                    alert("Email sent successfully");
                    $('#final_btn_sened_email').val("Send Email");
                    $('#final_btn_sened_email').removeAttr("disabled");
                    $('.modal').modal('hide');
                    completed_leads_js.ajax.reload(null, false);
                },
                error:function(e){
                  $('#final_btn_sened_email').val("Send Email");
                  $('#final_btn_sened_email').removeAttr("disabled");
                }
          });
    });

});

</script>
<script src="{{ URL::asset('assets/js/views/leads/index.js') }}"></script>
@stop