@php($message = 'Booking Form against booking details (Article Name:"'.$booking->plot->plot_id.' " Type:" '.$booking->plot->type .'") has been viewed')
    @php(EF::createLogs($message,'document'))
@php($app_name ="Sky Lite")
<!DOCTYPE html>
  <html>
    <head>
      <meta charset="UTF-8">
      <title>Confirmation of Allotment</title>
      <style type="text/css">
        .container{
          /*border: 1px solid #000;*/
          width: 100%;

          margin-top: 2px;
          font-size: 13px;
          text-align: justify;
          text-justify:inter-word;
        /*   margin-left: 3%;
            margin-right:2%;*/
         }
        .letterimage
        {
            width:120px;
            height:100px;
            border:1px solid;
            margin-top:-6px;
        }
        .right_div
        {
            float:right;
        }
        .date_style
        {
            margin-top: -24px;
            margin-right: 20px;
        }
        .ref_style
        {
            margin-top: -25px;
            margin-right: 27px;
        }
        .hrstyle
        {
            border: 1px solid black;
        }

        header{
          position: fixed;
          top: 100%;
          left: 0px;
          right: 0px;
          height: 50px;

            /** Extra personal styles **/
            /*background-color: #03a9f4;
            color: white;*/
          /*  text-align: center;
            line-height: 35px;*/
        }

        footer {
            position: fixed;
            bottom: 200px;
            left: 50px;
            right: 50px;
            height: 50px; 

            /** Extra personal styles **/
            /*   background-color: #03a9f4;
            color: white;
            text-align: center;
            line-height: 35px;*/
        }

        .page{
            /*margin-top:10%; */
            margin-left: 2.5%;
            margin-right: 2.5%;
        }
      </style>
    </head>

    <body class="pdf-body" style="margin-top: 10%;margin-bottom: 18% !important; ">
        {{--@include('letters.pdf_letter_header')--}}
        <footer>
               <hr align="left" width="25%" class = "hrstyle">
              <div>Authorised Signatory</div>
               <div>Skylite Builders</div>
               <br>
               <div>Date Printed: {{EF::dateFormat($print_date)}}</div>
        </footer>
        <div class="container page" >
          <div class = "right_div">
              <p class = "date_style">Date: {{EF::dateFormat($booking->created_at)}}<br>
               <b>{{strtoupper($booking->ref)}}</b></p><br><br><br>
               {{-- <img class = "letterimage" src="{{ asset('graphics/logo/logo.jpg') }}" > --}}
               @if(!isset($co_owner->id))
                 <img class = "letterimage" src="{{ EF::getFile($user->dp) }}"  >
                 <p ><br></p>
                   <p style = "margin-top: -10px; margin-left:27px;"><b>Reg No: {{$booking->reference_number}}</b></p>
                @else
                  <img style = "width: 80px" class= "letterimage" src="{{ EF::getFile($user->dp) }}" >
                        <img style = "width: 80px" class= "letterimage" src="{{ EF::getFile($co_owner->dp) }}" >
                        
                        <p style = "margin-top:-160px; margin-right:20px;"><b>Reg No: {{$booking->reference_number}}</b></p>
                @endif
          </div>
          <div>
            @if(!isset($co_owner->id))
                    <div style=" width: 80%; margin-right: 0px;">
                        @if($user->relation == "S/O")Mr. @elseif($user->relation == "D/O") Miss. @else Mrs. 
                        @endif {{strtoupper($user->name)}} <br>
                        @if($user->relation == "S/O")
                        S / O: {{strtoupper($user->fname)}}  <br>
                        @elseif($user->relation == "D/O")
                        D / O: {{strtoupper($user->fname)}}  <br>
                        @elseif($user->relation == "W/O")
                        W / O: {{strtoupper($user->fname)}}  <br>
                        @else
                        S / O: {{strtoupper($user->fname)}}  <br>
                        @endif
                        CNIC NO: {{$user->cnic}}  <br>
                        <p style="width: 60%;">Address: {{strtoupper($user->temp_address)}}</p> 
                        <br><br>
                        Mobile: {{$user->contact}} <br>
                        Phone:  {{$user->other_contact}} <br><br>
                    </div>
                @else
                    <div style=" width: 35%;height: 170px;border:1px solid; display: inline-block;">
                        <span style="padding-left: 4px;">
                          @if($user->relation == "S/O")Mr. @elseif($user->relation == "D/O") Miss. @else Mrs. 
                          @endif {{strtoupper($user->name)}}
                        </span> <br>
                        <span style="padding-left: 4px;">
                          @if($user->relation == "S/O")
                          S / O: {{strtoupper($user->fname)}}  <br>
                          @elseif($user->relation == "D/O")
                          D / O: {{strtoupper($user->fname)}}  <br>
                          @elseif($user->relation == "W/O")
                          W / O: {{strtoupper($user->fname)}}  <br>
                          @else
                          S / O: {{strtoupper($user->fname)}}  <br>
                          @endif
                        </span>
                        <span style="padding-left: 4px;">CNIC NO: {{$user->cnic}}</span>  <br>
                        

                        <br><span style="padding-left: 4px;">Mobile: {{$user->contact}}</span> <br>
                        <span style="padding-left: 4px;">Phone:  {{$user->other_contact}}</span> <br>
                        <p style="width: 100%;padding-left: 4px;padding-right: 4px;word-spacing: normal;line-height: normal;margin-right: 3px;">Address: {{strtoupper($user->temp_address)}} </p> 
                    </div>

                    <div style=" width: 35%;height: 170px; border:1px solid; display: inline-block;">
                        <span style="padding-left: 4px;">
                          @if($co_owner->relation == "S/O")Mr. @elseif($co_owner->relation == "D/O") Miss. @else Mrs. 
                          @endif {{strtoupper($co_owner->name)}}
                        </span><br>
                        <span style="padding-left: 4px;">
                          @if($co_owner->relation == "S/O")
                            S / O: {{strtoupper($co_owner->fname)}}  <br>
                          @elseif($co_owner->relation == "D/O")
                          D / O: {{strtoupper($co_owner->fname)}}  <br>
                          @elseif($co_owner->relation == "W/O")
                          W / O: {{strtoupper($co_owner->fname)}}  <br>
                          @else
                          S / O: {{strtoupper($co_owner->fname)}}  <br>
                          @endif
                        </span>
                        <span style="padding-left: 4px;"> 
                          CNIC NO: {{$co_owner->cnic}}
                        </span>  <br>
                       

                        <br><span style="padding-left: 4px;">Mobile: {{$co_owner->contact}}</span> <br>
                        <span style="padding-left: 4px;">Phone:  {{$co_owner->other_contact}}</span> <br>
                        <p style="padding-left: 4px; width: 100%;word-spacing: normal;line-height: normal;">Address: {{strtoupper($co_owner->temp_address)}}</p>
                    </div>
                @endif
          </div>

          <div class = "subject_div">Subject: <b><u>CONFIRMATION OF ALLOTMENT - {{strtoupper($booking->branch->name)}}</u></b>
          </div>
          <div style = "line-height: 0.75rem;">
            <p style = "  font-family: Calibri Regular !important;"><b>Dear Sir/Madam,</b></p>
            <p>With reference to your application for booking of {{$plot->type}} in {{strtoupper($booking->branch->name)}} {{strtoupper($plot->location)}}</p>
            <p>We are pleased to inform you that your application has been approved.</p>
            <p>Your allotment details are mentioned below:</p>
            <p>Type: {{$plot->type}} Category: {{strtoupper($plot->category)}},{{strtoupper($plot->feature_description)}},Registration no. {{$booking->reference_number}}</p>
            <p>Size: {{strtoupper($plot->size)}}, Location:{{$plot->location}}</p>
          </div>

          <br>

          <div>
            <b style = "margin-left:10%; margin-right: 7%;" >Total Price: </b>Rs. {{EF::numberFormat($plot->rate)}} <small>(Rupees {{EF::numberToWords($plot->rate)}})</small>
          </div>
          <div>
            <b style = "margin-left:10%;  margin-right: 1%;">Received Payment:</b> Rs. {{EF::numberFormat($balancedetail['debit'])}}  <small>(Rupees {{EF::numberToWords($balancedetail['debit'])}})</small>
          </div>
          <div>
            <b style = "margin-left:10%; ">Balance Receivable: </b> Rs. {{EF::numberFormat($balancedetail['credit'])}}  <small>(Rupees {{EF::numberToWords($balancedetail['credit'])}})</small>
          </div>
          <div>
            <b style = "margin-left:10%; margin-right: 4%;">Payment Term:</b>{{$payment_term}}
          </div>
          <div style = "line-height: 0.75rem;">
            <p>This allotment is subject to the terms and conditions mentioned in the RESERVATION FORM. </p>
            <p>As per our construction schedule we are planning to complete the construction of the {{strtoupper($booking->branch->name)}}, by {{EF::dateFormat($booking->branch->end_date)}}.</p>
            <p>Therefore timely payment by the allottee is of vital importance.</p>
            <p>We acknowledge the receipt of payments as mentioned below:</p>
          </div>

          <table  style=" margin-top:3%; text-align: center; width:100%;">

            <thead>
              <tr>
                <th style = "width:15%;">Receipt No</th>
                <th style = "width:15%;">Date</th>
                <th style = "width:15%;">Ch #</th>
                <th style = "width:15%;">Drawn on</th>
                <th style = "width:40%;">Amount</th>
              </tr>
            </thead>

            <tbody>
                @foreach($payment_receipts as $rows)

                  @if($rows->generic_type_id === EF::getGenericTableIndex()['Installment'] && in_array($rows->generic_id,$installment_list))
                    <tr>
                      <td>{{$rows->receipt_no}}</td>
                      <td>{{EF::dateFormat($rows->created_at)}}</td>
                      <td>{{$rows->instrument}}</td>
                      <td>{{$rows->drawn_on}}</td>
                      <td>{{EF::numberFormat($rows->amount)}}</td>
                    </tr>
                  @endif
                @endforeach
            </tbody>
          </table>
   
          <div class="description" style="margin-bottom: 30%">
              <p>All Receipts are enclosed for your record.</p>
              <p>The purchaser is responsible for following all the <b>organizational and governmental policies and taxes</b> as applicable from time to time.</p>
              <p >Once again we congratulate you for the confirmation of the {{$plot->type}} and assure you the best of co-operation and services.Please don't hesitate to contact us if you have any further questions or queries.</p>
          </div>

    


          @php($net_balance = 0)

          <div class="row clear" style="page-break-before: always;">
            <div class = "right_div">
              <p style = "margin-top: -10px;" class = "date_style">Date: {{EF::dateFormat($booking->created_at)}}<br>
                <b>{{strtoupper($booking->ref)}}</b></p>
              <p style = "margin-top: -10px;"><b>Reg No: {{$booking->reference_number}}</b></p>
            </div>
            <div>
              @if($user->relation == "S/O")Mr. @elseif($user->relation == "D/O") Miss. @else Mrs. @endif {{strtoupper($user->name)}} <br>
                {{strtoupper($user->relation)}}: {{strtoupper($user->fname)}}  <br>
            </div>

             <div class = "subject_div"><br><br>Subject: <b><u>Installment Schedule</u></b>
             </div>

             <div style = "line-height: 0.75rem;">
              <p style = "  font-family: Calibri Regular !important;"><b>Dear Sir/Madam,</b></p>
              <p>Mentioned below is the Installment Schedule which is done to be followed strictly as per the payment due dates. This will help us to complete the project timely and secure you from the late paymet penalties, as per day terms and conditions.</p>
             </div>
          </div>

          <div class="row clear">
            <h3><u>PAYMENT SCHEDULE</u></h3>
              <table  border="0" style="border-collapse: collapse; margin-top:3%;margin-bottom:33%; text-align: center; width:100%; font-size: 8.5pt;">
                <thead>
                  <tr>
                     <th>Description</th>
                      <th>Amount</th>
                      <th>Due Date</th>
                      <th>Balance</th>
                      <th>Payment</th>
                      <th>Net Balance</th>
                  </tr>
                  <tbody>
                    @php ($totalamount = 0)
                    @php($received = 0)
                    @php($balance = 0 )
                    @php($short = 0)

                    <!-- DOWN PAYMENT SECTION -->
                    @foreach($installment as $rows)
                      @if($rows->type_of_installment === "Down Payment")
                        <tr>
                          <td>{{$rows->description}} </td>
                          <td>{{EF::numberFormat($rows->amount)}}</td>
                          <td>{{EF::dateFormat($rows->due_date)}}</td>
                          <td>{{EF::numberFormat($rows->amount)}}</td>
                          <td>{{EF::numberFormat($rows->received_amount)}}</td>
                          <td>{{EF::numberFormat(($rows->amount)-($rows->received_amount))}}</td>
                        </tr>
                      @endif
                    @endforeach
                    <tr>
                      <th>Total Down Payment</th>
                      <th colspan="6"></th>
                    </tr>
                    <!-- END DOWN PAYMENT SECTION -->

                    <!-- INSTALLMENT SECTION -->
                    @foreach($installment as $rows)
                      @if($rows->type_of_installment === "Installment")
                        <tr>
                            <td>{{$rows->description}} </td>
                            <td>{{EF::numberFormat($rows->amount)}}</td>
                            <td>{{EF::dateFormat($rows->due_date)}}</td>
                            <td>{{EF::numberFormat($rows->amount)}}</td>
                            <td>{{EF::numberFormat($rows->received_amount)}}</td>
                            @if($rows->received_amount > 0)
                              @php($net_balance += ($rows->amount)-($rows->received_amount))
                              <td>{{EF::numberFormat($net_balance)}}</td>
                            @else
                              <td>{{EF::numberFormat(($rows->amount)-($rows->received_amount))}}</td>
                            @endif
                            @php($totalamount = $totalamount +($rows->amount))
                            @php($received = $received +($rows->received_amount))
                            @php($balance = $balance +(($rows->amount)-($rows->received_amount)))
                        </tr>
                      @endif
                    @endforeach
                    <tr>
                      <th>Total Installment Amount</th>
                      <th>{{EF::numberFormat($totalamount)}}</th>
                      <th></th>
                      <th>{{EF::numberFormat($totalamount)}}</th>
                      <th>{{EF::numberFormat($received)}}</th>
                      <th>{{EF::numberFormat($balance)}}</th>
                    </tr>
                    <!-- END INSTALLMENT PAYMENT SECTION -->

                    <!-- OTHER PAYMENT SECTION -->
                    @foreach($installment as $rows)
                      @if($rows->type_of_installment != "Installment" && $rows->type_of_installment != "Down Payment")
                          <tr>
                            <td>{{$rows->description}} </td>
                            <td>{{EF::numberFormat($rows->amount)}}</td>
                            <td>{{EF::dateFormat($rows->due_date)}}</td>
                            <td>{{EF::numberFormat($rows->amount)}}</td>
                            <td>{{EF::numberFormat($rows->received_amount)}}</td>
                            @if($rows->received_amount > 0)
                              @php($net_balance += ($rows->amount)-($rows->received_amount))
                              <td>{{EF::numberFormat($net_balance)}}</td>
                            @else
                              <td>{{EF::numberFormat(($rows->amount)-($rows->received_amount))}}</td>
                            @endif
                            @php($totalamount = $totalamount +($rows->amount))
                            @php($received = $received +($rows->received_amount))
                            @php($balance = $balance +(($rows->amount)-($rows->received_amount)))
                          </tr>
                      @endif
                    @endforeach

                    <!-- END OTHER PAYMENT SECTION -->
                  </tbody>
                </thead>
              </table>
          </div>

          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
              <!-- INSTALLMENT PLAN -->
        </div>
    </body>
  </html>
