@extends('layouts.admin')
@section('pageTitle')
<title>Best Insurance | Completed Leads</title>
@stop
@section('pageCss')
<link rel="stylesheet" href="{{ URL::asset('assets/plugins/datepicker/datepicker3.css') }}">
@stop
@section('content')
<section class="content">

  <div class="box get-quote">
   <div class="box-body no-padding">
    <div class="form-group col-md-12" style="border-right: 2px solid #ccc;">
      <table class="table">
        <thead>
          <tr>
            
            <th>Policy Number</th>
            <th>Action</th>
            <th>Date</th>
            <th>Reason</th>
            <th>Download/Email</th>
            <th>RAF Document status</th>
            <th>Bundle status</th>
            <th>RAF Webhook Messages</th>
          </tr>
        </thead>
        <tbody>
          @foreach($log_details as $log_detail)
          <tr>
            
            <td>{{$log_detail['information']['policy_number_full']}}</td>
            @if(empty($log_detail['information']['action']))
            <td>New</td>
            @else
            <td>{{$log_detail['information']['action']}}</td>
            @endif
            @if(empty($log_detail['information']['action']))
            <td>{{$log_detail['information']['created_at']->format('d/m/Y H:i:s')}}</td>
            @else
            <td>{{$log_detail['information']['created_at']->format('d/m/Y H:i:s')}}</td>
            @endif

            @if(empty($log_detail['information']['reason']))
            <td>-</td>
            @else
            <td>{{$log_detail['information']['reason']}}</td>
            @endif
            <td>
              <?php
$raf_print_status = "NA";
if ((!empty($log_detail['raf_documents'])) && ($log_detail['information']['is_bundled']=="1")) {
  $raf_print_status = "Generated";
} elseif ((!empty($log_detail['raf_documents'])) && ($log_detail['information']['is_bundled']=="0")) {
  $raf_print_status = "Generated";
}
?>            
@if($log_detail['information']['action']=="Transfer_Cover_Letter")

      @if($log_detail['information']['customer_status']=="Sold-Claim")
                <a class="btn btn-warning btn-xs download"  download data-title="Download"
                href=
                "{{ URL::asset('cover_letters/transfer/total') }}/{{$log_detail['information']['schedule_pdf']}}"
                ><i class="fa fa-download"></i></a>
      @else

              <a class="btn btn-warning btn-xs download"  download data-title="Download"
                href=
                "{{ URL::asset('cover_letters/transfer/total') }}/{{$log_detail['information']['schedule_pdf']}}"
                ><i class="fa fa-download"></i></a>
      @endif

@elseif($log_detail['information']['action']!="Rejected")
                <a class="btn btn-warning btn-xs download"  download data-title="Download"
                href=
                "{{url('download-version?logInfoId=')}}{{$log_detail['information']['id']}}"
                ><i class="fa fa-download"></i></a>
              
              @elseif($log_detail['information']['action']=="Rejected" || $log_detail['information']['action']=="" )

                <button class="btn btn-danger btn-xs email" data-title="Email"
                data-id="{{url('download-version?logInfoId=')}}{{$log_detail['information']['id']}}&email=1"
                ><i class="fa fa-envelope"></i></button>

              @endif
              @if(($log_detail['information']['status']==1) && $log_detail['information']['action']!="Transfer_Cover_Letter")
              <button class="btn btn-danger btn-xs email" data-title="Email"
              data-id="{{url('download-version?logInfoId=')}}{{$log_detail['information']['id']}}&email=1"
              ><i class="fa fa-envelope"></i></button>
            
            @if(!empty($log_detail['raf_documents']))
           <input type="hidden" name="customer_id" id="customer_id" value="{{$log_detail['information']['customerid']}}">
            <button data-title="RAF Payment History" data-id="#info__" class="transactions btn-xs btn btn-success" loan_id="{{$log_detail['information']['loanid']}}"><i class="fa fa-clone" ></i></button>
            <div class="dropdown__">
              <button data-title="RAF documents" class="btn btn-info btn-xs dropbtn__" ><i class="fa fa-file-text" ></i></button>
              <div class="dropdown-content__">
                <ul class="">
                  @foreach($log_detail['raf_documents'] as $raf_doc)
                  <li>
                    @if(!empty($raf_doc['s3_url']))
                    <a href="{{url('/download-raf-doc',$raf_doc['id'])}}">RAF_{{$raf_doc['Alias']}}</a>
                    @else
                    <a>RAF_{{$raf_doc['Alias']}}</a>
                    @endif
                  </li>
                  @endforeach
                </ul>
                @elseif(($log_detail['information']['action'] != "RENEW") && ($log_detail['information']['status']==1))
                <ul>
                  @foreach($log_detail['raf_documents'] as $raf_doc)
                  @if(!empty($raf_doc['s3_url']))
                  <li><a href="{{url('/download-raf-doc',$raf_doc['id'])}}">RAF_{{$raf_doc['Alias']}}</a></li>
                  @else
                  <li><a>RAF_{{$raf_doc['Alias']}}</a></li>
                  @endif
                  @endforeach
                </ul>
                @endif
              </div>
            </div>
            @endif
          </td>
          <td>
            {{$raf_print_status}}
          </td>
          <td>
             <?php
$raf_bundle_status = "NA";
if ((!empty($log_detail['raf_documents'])) && $log_detail['information']['is_bundled'] == "1") {
  $raf_bundle_status = "Generated";
  

} else {
  $raf_bundle_status = "Pending";
}
?>
{{$raf_bundle_status}}    @if($log_detail['information']['is_bundled'] == "1")
            <div class="dropdown__">
              <button data-title="RAF documents" class="btn btn-info btn-xs dropbtn__" ><i class="fa fa-file-text" ></i></button>
              <div class="dropdown-content__">
                <ul class="">

                <li>
                    
                    <a href="{{url('/download-raf-bundle-doc-policy',$log_detail['information']['id'])}}">Policy Documents</a>
                  
                  </li>

                  <li>
                   
                    <a href="{{url('/download-raf-bundle-doc-directdebit',$log_detail['information']['id'])}}">Direct Debit Documents</a>
                    
                  </li>

                  <li>
                   
                    <a href="{{url('/download-raf-bundle-doc-terms',$log_detail['information']['id'])}}">Terms & Conditions</a>
                   
                  </li>

                  
                </ul>
               
            </div>
            @endif
          </td>
          <td>
            @if(!empty($log_detail['raf_documents']))
            <a href="{{url('raf-webhook-messages?raf_cust_id=')}}{{$log_detail['information']['customerid']}}">Webhook Messages</a>
            @else
            NA
            @endif
          </td>
        </tr>
        @endforeach
      </tbody>
    </table>
  </div>
</div>
</div>

<div class="box get-quote">
  <div class="box box-warning col-md-12">
    <div class="box-header with-border">
      <h3 class="box-title" >

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



  <div class="box-body no-padding">
    <div class="form-group col-md-6" style="border-right: 2px solid #ccc;">

      <div class="clearfix"></div>

      @if(count($mailtracker)>0)
      <div class="box-body no-padding">
        <div class="align-center"><h3>Mail History</h3></div>
        <div>
          <ul class="list-group" id="mailtracker">
            @foreach($mailtracker as $mail_data)
            @if($mail_data->mt_type == 1)
            <?php
$subject = "Your protection policy schedule and documents";
$type = "Generate Schedule";
?>
            @elseif($mail_data->mt_type == 2)
            <?php
$subject = "Your protection policy schedule and documents";
$type = "Generate MTA";
?>
            @elseif($mail_data->mt_type == 3)
            <?php $subject = "Your protection policy cancellation documents";
$type = "Cancellation";
?>
            @else
            <?php $subject = "";
$type = "";?>
            @endif


            <li class="list-group-item list-group-item-light mail_list" mt-id={{$mail_data->mt_id}}>

              <table class="bitable">
                <tbody>
                  <tr>
                    <td><i class="fa fa-list-alt" aria-hidden="true"></i><b>Type</b></td>
                    <td>{{$type}}:</td>
                  </tr>
                  <tr>
                    <td><i class="fa fa-calendar" aria-hidden="true"></i> <b>Date & Time</b></td>
                    <td>{{$mail_data->created_at->format('d/m/Y,H:i:s')}}</td>
                  </tr>
                  <tr>
                    <td><i class="fa fa-user" aria-hidden="true"></i><b>Customer Name</b></td>
                    <td>{{ucwords(strtolower($log_detail['information']['fname']))}}</td>
                  </tr>
                  <tr>
                    <td><i class="fa fa-envelope" aria-hidden="true"></i><b>Email Sent Subject</b></td>
                    <td>{!!$subject!!}</td>
                  </tr>

                  <tr>
                    <td><i class="fa fa-envelope" aria-hidden="true"></i><b>Email Sent to</b></td>
                    <td>{{$mail_data->to_email}}</td>
                  </tr>

                  <tr>
                    <td><i class="fa fa-reply" aria-hidden="true"></i><b>Email Sent by</b></td>
                    <td>{!!$mail_data->sender->profile->first_name.' '.$mail_data->sender->profile->last_name!!}</td>
                  </tr>

                </tbody>
              </table>
            </li>
            @endforeach
          </ul>
        </div>
      </div>
      @endif

    </div>


    <style>
      .bitable{
        width: 100%;
        border-collapse: collapse;
      }
      .bitable tr td{
        padding: 4px 12px;
        font-size: 14px;
      }
      .bitable tr td i{
        font-size: 14px;
        padding-right: 8px;
        font-weight: 100;
        color: #3c8dbc;
        vertical-align: middle;
        line-height: normal;
      }
      .bitable tr td{
        border: 1px solid #efefef;
      }

a[data-title],
button{position: relative;}
a[data-title]:hover:after,
button[data-title]:hover:after {
 content: attr(data-title);
 position: absolute;
 top: 100%;
 width:150px;
 left: 0;
 background-color:#ffd59c;
 padding:5px 10px;
 border-radius:5px;
color: #712c12;
z-index: 999;
}



    </style>



  </form>
</div>
</div>
<!-- </div> -->
</section>



<!-- 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">
          <input type="hidden" id="hidden_url">
          <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 -->


<!-- information model starts -->
<div class="modal fade" id="info__" tabindex="-1" role="dialog" aria-labelledby="">
  <div class="modal-dialog modal-dialog__" role="document">
    <div class="modal-content" id="payment_transactions_data">
      <div class="modal-body">
        <h1>djfksdj</h1>
      </div>
    </div>
  </div>
</div>



<!-- ends -->







@stop
@section('pageBottomJs')
<style type="text/css">
  .lead-padding{
    margin-bottom: 15px;
  }
  .tooltip.fade.right{
    width:100%;
  }
  .tooltip.fade.right .tooltip-inner{
    max-width: 100%;
    width:100%;
    background-color: #FFF;
    border:1px solid #ddd;
    padding:15px;
    -webkit-box-shadow: 2px 3px 14px -2px rgba(0,0,0,0.75);
    -moz-box-shadow: 2px 3px 14px -2px rgba(0,0,0,0.75);
    box-shadow: 2px 3px 14px -2px rgba(0,0,0,0.75);
  }
  .tooltip.fade.right .tooltip-inner table td{
    color:#000 !important;
    text-align: left;
  }
  .tooltip.fade.right .tooltip-inner table{
    width:100%;
  }

  @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-dialog__{
    width: 90%;
  }
  .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;
}


.green__{color: #199034; margin-top: 5px;}
.red__{color: #cc1e2f;}


.dropbtn__ {

  border: none;
}

/* The container <div> - needed to position the dropdown content */
.dropdown__ {
  position: relative;
  display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content__ {
  display: none;
  position: absolute;
  background-color: #cbecff;
  min-width: 190px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content__,.dropdown-content__ ul{
  margin:0;padding:0;

}
.dropdown-content__ li {list-style-type: none; padding:5px 10px; border-bottom: 1px solid #75a8c5; }

.dropdown-content__ li:last-child{
  border-bottom:0px solid #75a8c5;
}
.dropdown-content__ a {
  color: black;
  padding:0px 3px;
  font-size: 13px;
  text-decoration: none;
  display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content__ li:hover {background-color: #59bef9;}

/* Show the dropdown menu on hover */
.dropdown__:hover .dropdown-content__ {display: block;}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown__:hover .dropbtn__ {background-color: #3e8e41;}







@media (max-width: 991px) {
  .cnclmodal .modal-dialog{
    width: 98%
  }
}
</style>


<link rel="stylesheet" href="{{ URL::asset('assets/plugins/iCheck/all.css') }}">
<!-- iCheck 1.0.1 -->
<script src="{{ URL::asset('assets/plugins/iCheck/icheck.min.js') }}"></script>
<script src="{{ URL::asset('assets/plugins/datepicker/bootstrap-datepicker.js') }}"></script>
<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 email_data = {!!$mailtracker!!};
    $('#datepicker').datepicker({
      autoclose: true
    });

    $('#datepicker').datepicker({
      autoclose: true
    });
    var data = [];
        for ( var i=0 ; i<50000 ; i++ ) {
            data.push( [ i, i, i, i, i ] );
        }

             
        $('#example').DataTable( {
            data:           data,
            deferRender:    true,
            scrollY:        200,
            scrollCollapse: true,
            scroller:       true
        } );
 

    $('.mail_list').hover(function () {
      var selected_li = $(this);
      var mt_id = $(this).attr('mt-id');
      var content = email_data.filter(
        function(email_data) {
          return email_data.mt_id == mt_id;
        }
        );
      content = content[0]['mt_contents'];
      selected_li.tooltip({title: content, html: true, placement: "right"});

    }, function () {});


    $(document).on("click",".email", function (event) {
      url = $(this).attr("data-id");
      $('#email_send').modal('show');

      $('#hidden_url').val(url);

      $('input[name=cc_emails]').val('');
      $('input[name=bcc_emails]').val('');
    });


    $(document).on("click",".transactions", function (event) {
      var loan_id = $(this).attr('loan_id');
      var customer_id = $('#customer_id').val();
    //  alert(loan_id);
    //  alert(customer_id);
      $.ajax({
          url: "{{url('/account/raf/loan/payment/transactions')}}",
          type: 'POST',
          data: {loan_id:loan_id,customer_id:customer_id},
        //  data: {customer_id:customer_id},
          dataType: 'html',
          success: function(data) {
              $('#payment_transactions_data').html(data);
              $('#info__').modal('show');
          }
      });
    });




  $(document).on("click","#final_btn_sened_email", function (event) {
     $('#final_btn_sened_email').attr("disabled",'true');
     $('#final_btn_sened_email').val("Please wait");
     var conbibned_data = $('#PdfForm,#cc_email_form').serialize();
     var url = $('#hidden_url').val();
     $.ajax({
      type: "GET",
      url: url,
      headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
      },
      data: conbibned_data,
      datatype: "json",
      success: function(results){
        alert(results.message);
        $('#final_btn_sened_email').val("Send Email");
        $('#final_btn_sened_email').removeAttr("disabled");
        $('.modal').modal('hide');
      },
      error:function(e){
        $('#final_btn_sened_email').val("Send Email");
        $('#final_btn_sened_email').removeAttr("disabled");
      }
    });
 });

        //

      });



    </script>
    @stop