@extends('layouts.dashboard')

@section('page_title')
View Booking
@endsection


@section('page_body')

{{ Breadcrumbs::render('booking_detail',Crypt::encrypt($booking->id),(EF::showPlotFormat($plot))) }}

@if($booking->status == 'Unapprove')
 @include('booking.approve_booking')

 @else

@php($label_list = EF::getWhiteLabel())
<div class="row">
  <div class="col-md-4 col-sm-12 " >
   <div class="card">
     <div class="card-header">
       <div class="card-title">
         <strong>Booking Information </strong>
       </div>
         @if(Auth::user()->hasAnyPermission(['All','Update Booking']))
       <div class="card-options">
        <a data-toggle="modal" data-target="#md_update_booking" href="#" class="btn btn-sm btn-primary ml-2"> Edit </a>
      </div>
      @endif
    </div>
    <div class ="card-body cls-clear-padding">
     <div class="cls_border-bottom"> </div>
     <div class="row">

      <div class="col-md-5 cls_alignment col-sm-6">
        <label class="form-label">Booking Details: </label>
      </div>
      <div class="col-md-7 cls_alignment col-sm-6">

       {{EF::showPlotFormat($plot)}}
     </div>
   </div>

 <div class="cls_border-bottom"> </div>
 <div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label">{{ucwords(str_replace('_',' ',$label_list['total_amount']))}}: </label>
  </div>
  <div class="col-md-7  cls_alignment col-sm-6">
    {{EF::numberFormat($booking->rate_per_marla)}}
  </div>
</div>

<div class="cls_border-bottom"> </div>
 <div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label">{{ucwords(str_replace('_',' ',$label_list['size']))}}: </label>
  </div>
  <div class="col-md-7  cls_alignment col-sm-6">
    {{$booking->plot->size}}
  </div>
</div>

<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5 cls_alignment col-sm-6">
    <label class="form-label">{{ucwords(str_replace('_',' ',$label_list['discount']))}}: </label>
  </div>
  <div class="col-md-7  cls_alignment col-sm-6">
   {{EF::numberFormat($booking->discount)}}
 </div>
</div>
<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5 cls_alignment col-sm-6">
    <label class="form-label" >{{ucwords(str_replace('_',' ',$label_list['feature_charges']))}}: </label>
  </div>
  <div class="col-md-7 cls_alignment col-sm-6">
    {{EF::numberFormat($booking->feature_charges)}}
  </div>
</div>
<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label" >{{ucwords(str_replace('_',' ',$label_list['agreed_amount']))}}: </label>
  </div>
  <div class="col-md-7  cls_alignment col-sm-6">
    <span class="badge badge-primary badge-bolder">
     {{EF::numberFormat($booking->agreed_amount)}}
   </span>
 </div>
</div>
<div class="cls_border-bottom"> </div>
@php($balance_detail = $booking->getBalanceDetail($booking->id))

<div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label" >Received Amount: </label>
  </div>
  <div class="col-md-7  cls_alignment col-sm-6 ">
    <span class="badge badge-success badge-bolder"> {{EF::numberFormat($balance_detail['debit'])}}
    </span>
  </div>
</div>
<div class="cls_border-bottom"> </div>

<div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label" >Balance Amount: </label>
  </div>
  <div class="col-md-7  cls_alignment col-sm-6">
    <span class="badge badge-danger badge-bolder">
     {{EF::numberFormat($balance_detail['credit'])}}
   </span>
 </div>
</div>
<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label" >{{ucwords(str_replace('_',' ',$label_list['booking_date']))}}: </label>
  </div>
  <div class="col-md-7 cls_alignment  col-sm-6">
   {{EF::dateFormat($booking->created_at)}}
 </div>
</div>
<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label" >{{ucwords(str_replace('_',' ',$label_list['approve_date']))}}: </label>
  </div>
  <div class="col-md-7 cls_alignment  col-sm-6">
   {{EF::dateFormat($booking->approve_date)}}
 </div>
</div>

<div class="cls_border-bottom"> </div>
</div>

<div class="card-status  card-status-left bg-blue">
</div>

</div>

<div class="card" >
 <div class="card-header">
   <div class="card-title">
     <strong>Customer Information </strong>
   </div>

   @php($user_data = [])
   @php(
   $user_data = array(
   'user_id'              => Crypt::encrypt($user->id),
   'full_name'            => $user->name,
   'father_name'          => $user->fname,
   'dob'                  => str_replace('1970-01-01','',date('Y-m-d',strtotime($user->dob))),
   'cnic'                 => ($user->cnic),
   'email'                => $user->email,
   'contact'              => $user->contact,
   'relation'             => $user->relation,
   'gender'               => $user->gender,
   'nationality'          => $user->nationality,
   'occupation'           => $user->occupation,
   'temporary_address'    => $user->temp_address,
   'permanent_address'    => $user->per_address,
   'user_image'           => $user->dp,
   'branch'               => trim($user->branch->code.' '.$user->branch->name),
   )
   )
 @if(Auth::user()->hasAnyPermission(['All','Update Customer']))
   <div class="card-options">
    <a href="#" class="btn btn-sm btn-primary ml-2" onclick="update(event,'{{json_encode($user_data)}}','form_update_customer','md_update_customer')"> Edit </a>
  </div>
  @endif


</div>
<div class ="card-body cls-clear-padding">
  <br>
   <div class = "row">
    <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">

    </div>
    <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">
    <center> <img class="rounded image_padding img-fluid" src="{{EF::getFile($user->dp)}}" width="75%" alt="Customer Image"> </center>

   </div>



   <div class="col-md-4 col-sm-4 col-xs-4 col-lg-4">

   </div>

 </div>

<br>

 <div class="row">
  <div class="col-md-5 cls_alignment col-sm-6">
    <label class="  form-label">Name: </label>
  </div>
  <div class="col-md-7 cls_alignment col-sm-6">
    {{ucfirst($user->name)}}
  </div>
</div>
<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5 cls_alignment  col-sm-6">
    <label class="form-label">{{$user->relation}}: </label>
  </div>
  <div class="col-md-7 cls_alignment col-sm-6">
    {{ucfirst($user->fname)}}
  </div>
</div>

<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5 cls_alignment col-sm-6">
    <label class="form-label">Contact No: </label>
  </div>
  <div class="col-md-7  cls_alignment col-sm-6">
    {{$user->contact}}
  </div>
</div>

<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5 cls_alignment col-sm-6">
    <label class="form-label">Email: </label>
  </div>
  <div class="col-md-7 cls_alignment col-sm-6">
    {{EF::filterEmail($user->email)}}
  </div>
</div>
<div class="cls_border-bottom"> </div>
<div class="row">
  <div class="col-md-5  cls_alignment col-sm-6">
    <label class="form-label" >Address: </label>
  </div>
  <div class="col-md-7 cls_alignment col-sm-6 pr-4" >
   {{($user->temp_address)}}
 </div>
</div>
<div class="cls_border-bottom"> </div>
</div>

<div class="card-status  card-status-left bg-blue">
</div>

</div>


@if(Auth::user()->hasAnyPermission(['All','View Booking Receipts']))
<div class="card " >
 <div class="card-header" style ="padding:1.3rem;">
   <div class="card-title" >
     <strong> Payment Receipts </strong>
   </div>



 </div>
 <div class ="card-body cls-clear-padding table-responsive">
   <div class="cls_border-bottom"> </div>

   <table class="table table-hover table-outline  table-vcenter text-nowrap card-table " id = "payment_receipts" style = "overflow-y: auto;">
    <thead>
      <tr>

      <!--   <th>Sr #</th> -->
        <th>Description</th>
        <th>Amount</th>
        <th>Action</th>

      </tr>
    </thead>
    <tbody style = "  max-height:400px; overflow-y:auto;" >
     @foreach($payment_list as $rows)
        @if($rows->status === "Reject")
          <tr style="background-color:#ffd2d2">
        @elseif($rows->status === "Approve")
          <tr style="background-color:#dcffb8">
        @else
          <tr style="background-color:#fdf7bf">
        @endif
   <!--    <td>{{$loop->iteration}} </td> -->
      @if($rows->installment_id > 0)
            <td>{{$rows->installment->description}} </td>
      @elseif($rows->commission_id > 0)
      <td>{{$rows->commission->description}} </td>
      @else
      <td>{{$rows->description}} </td>
      @endif


      <td>{{EF::numberFormat($rows->amount)}} </td>
      <td>
        <a target="_blank"  href="{{route('document.paymentreceipt',['id' => Crypt::encrypt($rows->id)])}}"><i class="dropdown-icon fa fa-print "></i>View</a>
         </td>

    </tr>
    @endforeach
  </tbody>
</table>






</div>

<div class="card-status  card-status-left bg-blue">
</div>

</div>
@endif
</div>


<div class = "col-md-8 col-sm-12">
  <div class = "row">

    @include('installment.manage_installment')


    @include('commission.manage_commission')


    @include('booking.transfer_amount')

    @include('payments.pending_payments')

    <div id="modal_add_payment"> </div>
    <div id="modal_update_payment"> </div>

    @include('user.manage_nominee')

    @include('booking.manage_document')

  </div>
</div>

</div>
@endif

@endsection


@section('page_modal')
  @include('user.modals.add_nominee')
  @include('user.modals.update_nominee')
  @include('commission.modals.add_commission')
  @include('commission.modals.update_commission')
  @include('installment.modals.make_installment')
  @include('installment.modals.update_installment')
  @include('installment.modals.interval_installment')
  @if(sizeof($installment_list) > 0)
    @if($booking->installment_mode != 'One Time')
      @include('installment.modals.update_installment_mode')
    @endif
  @endif

  @include('user.modals.add_dealer')
  @include('user.modals.add_employee')
  @include('user.modals.update_customer')
  @include('booking.modals.update_booking')
  @include('booking.modals.upload_booking_document')
      <div id="modal_add_payment"> </div>
      <div id="modal_update_payment"> </div>
      <div id="modal_payment_voucher"> </div>

@endsection

@section('page_script')
@include('scripts.booking')
@include('scripts.payment')


@include('scripts.commission')
@include('scripts.user')

@include('scripts.onetime')
@include('scripts.installment')
@include('scripts.account')


@endsection
