<?php
$yesterday=date('Y-m-d');
?>
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-12">
      <div class="iq-card">
        <div class="iq-card-header d-flex justify-content-between">
          <div class="iq-header-title">
            <h4 class="card-title">Total Report</h4>
          </div>
          <span class="table-add float-right mb-3 mr-2">
            <!-- <a href="javascript:void(0)" class="btn btn-default"><i class="fa fa-file-excel-o" aria-hidden="true"></i> Export</a> -->
            <button class="btn btn-danger" style="float: right;margin-top: 0px;padding: 5px;" onclick="Convert_HTML_To_PDF();">Download</button>
            <button onclick="printDiv('#printArea');" class="btn btn-success" style="float: right;margin-top: 0px;padding: 5px;">Print</button>&emsp;
            <!-- <a href="<?php echo base_url(); ?>Reservation/add" class="btn btn-sm iq-bg-success"><i
              class="ri-add-fill"><span class="pl-1">Book Now</span></i>
            </a> -->
          </span>
        </div>
        <div style="margin: 20px;" id="printArea">
          <div style="width: 100%; padding: 6px 0;">
            <div style="width: 100%; text-align: center;">
              <h2 style="margin:0;font-size: 30px;font-weight: 400;line-height: 20px;padding: 15px 0;">Hotel <strong style="font-weight: 700;">Natraj</strong></h2>
            </div>
          </div>
          <div style=" width: 70%;border-bottom: 1px dashed #000;padding: 6px 20px;">
            <table style="color:#000;font-size: 16px; margin:0; width: 100%;">
              <tr>
                <td style="">Statement of all Advance Collection of: <?php echo $yesterday; ?></td>
              </tr>
              <tr>
                <td>Report Printed on: (<?php echo date('H:i'); ?>) <?php echo date('d/m/Y') ?></td>
              </tr>
            </table>
          </div>
          <?php
          $total_payment_receive=0;
          $cash_receive=0;
          $advance=0;
          $checkout=0;
          $due_amount=0;
          $paid_amount=0;
          $card_collections=0;
          $final_payable=0;
          $refund_amount=0;
          $tcard_collections=0;
          $today_payment_data = $this->db->like('p_date',date('Y-m-d'),'after')->get('payment')->result_array();
          foreach ($today_payment_data as $key => $payment_details) {
          $total_payment_receive=$total_payment_receive+$payment_details['p_amount'];
          if ($payment_details['payment_mode']=='Cash') {
          
          $cash_receive=$cash_receive+$payment_details['p_amount'];
          }
          if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']=='Cash') {
          
          $advance=$advance+$payment_details['p_amount'];
          }
          else if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']!='Cash') {
          
          $tcard_collections=$tcard_collections+$payment_details['p_amount'];
          }
          if ($payment_details['payment_purpose']=='Final Adjustment' && $payment_details['payment_mode']=='Cash') {
          if ($payment_details['p_amount']>0) {
          
          $final_payable=$final_payable+$payment_details['p_amount'];
          }
          else
          {
          $refund_amount=$refund_amount+$payment_details['p_amount'];
          }
          }
          }
          $today_check_in = $this->db->where('check_in',$yesterday)->get('walk_in_reservation')->result_array();
          $today_check_out = $this->db->where('check_out',$yesterday)->where('room_available',1)->get('walk_in_reservation')->result_array();
          $yesterday=date('Y-m-d');
          $today_booking_data = $this->db->like('booking_date',$yesterday,'after')->get('walk_in_reservation')->result_array();
          $today_booking = sizeof($today_booking_data);
          $today_bill_data = $this->db->like('date',$yesterday,'after')->get('reservation_billing')->result_array();
          // $total_payment_receive=0;
          // //$cash_receive=0;
          // //$advance=0;
          // $checkout=0;
          // //$card_collections=0;
          // //$tcard_collections=0;
          // foreach ($today_bill_data as $key => $bill_data) {
          //    $total_payment_receive=$total_payment_receive+$bill_data['net_amount'];
          
          //    $checkout=$checkout+$bill_data['net_amount'];
          //    // $final_payable=$final_payable+$bill_data['net_amount'];
          //    // if ($final_payable<0) {
          //    //    $final_payable=0;
          //    // }
          //    if ($bill_data['payment_mode']=='Cash') {
          
          //    //$cash_receive=$cash_receive+$bill_data['net_amount'];
          //    if ($bill_data['net_amount']<0) {
          //       //$refund_amount=$refund_amount-$bill_data['net_amount'];
          //    }
          //    }
          //    else
          //    {
          //      $card_collections=$card_collections+ $bill_data['net_amount'];
          //    }
          
          // }
          // foreach ($today_booking_data as $key => $booking_data) {
          //    $total_payment_receive=$total_payment_receive+$booking_data['adv_amount'];
          //    //$advance=$advance+$booking_data['adv_amount'];
          //    if ($bill_data['payment_mode']=='Cash') {
          
          //    //$cash_receive=$cash_receive+$booking_data['adv_amount'];
          //    }
          //    else
          //    {
          //      $card_collections=$card_collections+ $booking_data['adv_amount'];
          //      //$tcard_collections=$tcard_collections+ $booking_data['adv_amount'];
          //    }
          
          // }
          //                 $start=0;
          //                 $total_tarif=0;
          //         $total_advance=0;
          //         $total_adjcs=0;
          //         $total_advcr=0;
          //         $total_adjcr=0;
          //         $total_refn=0;
          //         $total_exref=0;
          //         $total_due=0;
          //         $card_collection=0;
          //                 $start=0;
          //                 for($i=0;$i<count($recordSet);$i++)
          //                    { $start++;
          //                    $tarif=$recordSet[$i]['amount']+$recordSet[$i]['extra_bed_price'];
          //       $due=0;
          //       $adjcs=0;
          //       if($yesterday==$recordSet[$i]['check_out'])
          //       {
          //       $adjcs=$tarif-$recordSet[$i]['adv_amount'];
          //       }
          //       else
          //       {
          //       $due=$tarif-$recordSet[$i]['adv_amount'];
          //       }
          //       $total_tarif=$total_tarif+$tarif;
          //       $total_advance=$total_advance+$recordSet[$i]['adv_amount'];
          //       $total_adjcs=$total_adjcs+$adjcs;
          //       $total_due=$total_due+$due;
          //       if ($recordSet[$i]['adv_amount']!='Cash') {
          //         $card_collection=$card_collection+$recordSet[$i]['adv_amount'];
          //       }
          //    }
          ?>
          <div style=" width: 70%;padding: 6px 20px;">
            <table style="color:#000;font-size: 16px; margin:0; width: 100%;">
              <tr>
                <td style="">Gross Advance Collection : Rs.--></td>
                <td style="text-align: right;"><?php echo round($advance,2) ?></td>
              </tr>
              <tr>
                <td style="">Less Advance Collection by Card : Rs.--></td>
                <td style="text-align: right;"><?php echo round($tcard_collections,2) ?></td>
              </tr>
              <tr>
                <td style="">Today's Final Payable : Rs.--></td>
                <td style="text-align: right;"><?php echo round($final_payable,2); ?></td>
              </tr>
              <tr>
                <td style="">Today's Less Refund by Cash : Rs.--></td>
                <td style="text-align: right;border-bottom: 1px dashed #000;"><?php echo round($refund_amount,2); ?></td>
              </tr>
              <tr>
                <td style="text-align: center;">Net Advance Cash Total:-</td>
                <td style="text-align: right;border-bottom: 1px dashed #000;"><?php echo round($cash_receive,2) ?></td>
              </tr>
            </table>
          </div>
          <div style="border-bottom: 1px dashed #000;padding: 6px 30px;">
            <p style="font-size:16px;color: #000;font-weight: bold;margin: 0;">Checked-In Details of : <?php echo date('d/m/Y',strtotime($yesterday)); ?></p>
          </div>
          <div style="border-bottom: 1px dashed #000;">
            <table style="color:#000;font-size: 16px; width: 100%; margin:0;">
              <thead>
                <?php
                $start=0;
                $total_tarif=0;
                $total_advance=0;
                $total_adjcs=0;
                $total_advcs=0;
                $total_advcr=0;
                $total_adjcr=0;
                $total_refn=0;
                $total_exref=0;
                $total_due=0;
                $card_collection=0;
                $total_guest=0;
                $start=0;
                ?>
                <tr>
                  <th style="border-bottom: 1px dashed #000;text-align:left;">Srl</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">Room</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">NOP</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">InTM</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">Tarif</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdvCs</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdvCr</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdjCs</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdjCr</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">Refn</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">ExRef</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">Due</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">OutTM</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">DepDate</th>
                </tr>
              </thead>
              <tbody>
                <?php
                //$recordSet=$this->db->select(' p.wr_id,p.payment_purpose, p.p_amount, p.payment_mode, wr.room_number, wr.check_in, wr.check_out,  wr.check_out_time, wr.room_available')->from('payment as p')->join('walk_in_reservation as wr', 'wr.wr_id = p.wr_id', 'LEFT')->like('p.p_date',date('Y-m-d'),'after')->order_by('p.p_id','desc')->get()->result_array();
                foreach ($today_check_in as $key => $booking_data) {
                $adv_cash=0;
                $adv_online=0;
                $adj_cash=0;
                $adj_online=0;
                $refn=0;
                $due=0;
                $exrefn=0;
                $reservation_billing_data = $this->db->where('wr_id',$booking_data['wr_id'])->get('reservation_billing')->result_array();
                $num_guest = $this->db->where('wr_id',$booking_data['wr_id'])->get('walk_in_guest')->num_rows();
                //$total_tarif=$total_tarif+$booking_data['total_amount'];
                //$total_advance=$total_advance+$booking_data['adv_amount'];
                $total_guest=$total_guest+$num_guest;
                $ttarif=0;
                $gdata = $this->db->where('wr_id',$booking_data['wr_id'])->get('guest_details')->result_array();
                foreach ($gdata as $key => $tfd) {
                $ttarif=$ttarif+$tfd['gd_amount'];
                
                }
                $ttpaid=0;
                $pdata = $this->db->where('wr_id',$booking_data['wr_id'])->get('payment')->result_array();
                foreach ($pdata as $key => $payment_details) {
                $ttpaid=$ttpaid+$payment_details['p_amount'];
                if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']=='Cash') {
                
                $adv_cash=$adv_cash+$payment_details['p_amount'];
                $total_advcs=$total_advcs+$adv_cash;
                }
                else if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']!='Cash') {
                
                $adv_online=$adv_online+$payment_details['p_amount'];
                $total_advcr=$total_advcr+$adv_online;
                }
                if ($payment_details['payment_purpose']=='Final Adjustment' && $payment_details['payment_mode']=='Cash') {
                
                $adj_cash=$adj_cash+$payment_details['p_amount'];
                $total_adjcs=$total_adjcs+$adj_cash;
                }
                else if ($payment_details['payment_purpose']=='Final Adjustment' && $payment_details['payment_mode']!='Cash') {
                
                $adj_online=$adj_online+$payment_details['p_amount'];
                $total_adjcr=$total_adjcr+$adj_online;
                }
                
                }
                if ($ttpaid>$ttarif) {
                $date = new DateTime($booking_data['check_out']);
                $now = new DateTime();
                if($date > $now) {
                //if ($booking_data['room_available']=='1') {
                $refn=$ttarif-$ttpaid;
                $total_refn=$total_refn+$refn;
                //}
                }
                else
                {
                if ($booking_data['room_available']=='0') {
                $exrefn=$ttarif-$ttpaid;
                }
                else
                {
                $exrefn=$ttarif-$ttpaid;
                //echo $reservation_billing_data[0]['hotel_tax'];
                $exrefn= $exrefn+$reservation_billing_data[0]['hotel_tax'];
                }
                $total_exref=$total_exref+$exrefn;
                }
                }
                else
                {
                if ($booking_data['room_available']=='0') {
                $due=$ttarif-$ttpaid;
                $total_due=$total_due+$due;
                }
                }
                $total_tarif=$total_tarif+$ttarif;
                $total_advance=$total_advance+$ttpaid;
                
                //   if ($booking_data['payment_mode']=='Cash') {
                //     $adv_cash=$booking_data['adv_amount'];
                //     $total_advcs=$total_advcs+$adv_cash;
                //     if ($booking_data['total_amount']>$booking_data['adv_amount']) {
                //     if ($booking_data['room_available']=='1') {
                
                //     $adj_cash=$booking_data['total_amount']-$booking_data['adv_amount'];
                //     $total_adjcs=$total_adjcs+$adj_cash;
                //    }
                //    }
                //   }
                //   else {
                //     $adv_online=$booking_data['adv_amount'];
                //     $total_advcr=$total_advcr+$adv_online;
                //      if ($booking_data['total_amount']>$booking_data['adv_amount']) {
                //     if ($booking_data['room_available']=='1') {
                //     $adj_online=$booking_data['total_amount']-$booking_data['adv_amount'];
                //     $total_adjcr=$total_adjcr+$adj_online;
                //    }
                //    }
                //   }
                //   if ($booking_data['total_amount']<$booking_data['adv_amount']) {
                //    $date = new DateTime($booking_data['check_out']);
                //    $now = new DateTime();
                //    if($date > $now) {
                //     if ($booking_data['room_available']=='1') {
                //     $refn=$booking_data['total_amount']-$booking_data['adv_amount'];
                //     $total_refn=$total_refn+$refn;
                //    }
                //   }
                //   else
                //   {
                //    $exrefn=$booking_data['total_amount']-$booking_data['adv_amount'];
                //    $total_exref=$total_exref+$exrefn;
                //   }
                //     }
                //    else
                //    {
                //      if ($booking_data['room_available']=='0') {
                //   $due=$booking_data['total_amount']-$booking_data['adv_amount'];
                //   $total_due=$total_due+$due;
                // }
                //    }
                ?>
                <tr>
                  <td style="text-align:left;"><?php echo $key+1; ?>.</td>
                  <td style="text-align:center;"><?php echo $booking_data['room_number']; ?></td>
                  <td style="text-align:center;"><?php echo $num_guest; ?></td>
                  <td style="text-align:center;"><?php echo $booking_data['check_in']; ?></td>
                  <td style="text-align:right;"><?php echo $ttarif; ?></td>
                  <td style="text-align:right;"><?php echo $adv_cash; ?></td>
                  <td style="text-align:right;"><?php echo $adv_online; ?></td>
                  <td style="text-align:right;"><?php echo $adj_cash; ?></td>
                  <td style="text-align:right;"><?php echo $adj_online; ?></td>
                  <td style="text-align:right;"><?php echo -$refn; ?></td>
                  <td style="text-align:right;"><?php echo -$exrefn; ?></td>
                  <td style="text-align:right;"><?php echo $due; ?></td>
                  <td style="text-align:center;"><?php if ($booking_data['room_available']=='1') { echo $booking_data['check_out_time']; } ?></td>
                  <td style="text-align:center;"><?php  if ($booking_data['room_available']=='1') {  echo date('d/m/Y',strtotime($booking_data['check_out'])); } ?></td>
                </tr>
                <?php } ?>
                
              </tbody>
              <thead>
                <tr>
                  <th style="border-top: 1px dashed #000;text-align:left;" colspan="4">Total :</th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_tarif; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_advcs; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_advcr; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_adjcs; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_adjcr; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo -$total_refn; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo -$total_exref; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_due; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:center;"></th>
                  <th style="border-top: 1px dashed #000;text-align:center;"></th>
                </tr>
              </thead>
            </table>
          </div>
          <div style="border-bottom: 1px dashed #000;padding: 6px 30px;">
            <p style="font-size:16px;color: #000;font-weight: bold;margin: 0;margin-top: 20px;">Continue Checked-In and If Advance Paid on : <?php echo date('d/m/Y',strtotime($yesterday)); ?></p>
          </div>
          <div style="border-bottom: 1px dashed #000;">
            <table style="color:#000;font-size: 16px; width: 100%; margin:0;">
              <thead>
                <tr>
                  <th style="border-bottom: 1px dashed #000;text-align:left;">Srl</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">Room</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">ArrvDate</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">Days</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">InTM</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">NOP</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">Tarri</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">Due</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">PrAdCs</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">PrAdCr</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdvCs</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdvCr</th>
                </tr>
              </thead>
              <tbody>
                <?php
                $total_tarif=0;
                $total_due=0;
                $total_advcs=0;
                $total_advcr=0;
                $total_adjcs=0;
                $total_adjcr=0;
                $total_tadvcs=0;
                $total_tadvcr=0;
                $today_continue_check_in = $this->db->where('check_in <',$yesterday)->where('room_available',0)->get('walk_in_reservation')->result_array();
                
                //$recordSet=$this->db->select(' p.wr_id,p.payment_purpose, p.p_amount, p.payment_mode, wr.room_number, wr.check_in, wr.check_out,  wr.check_out_time, wr.room_available')->from('payment as p')->join('walk_in_reservation as wr', 'wr.wr_id = p.wr_id', 'LEFT')->like('p.p_date',date('Y-m-d'),'after')->order_by('p.p_id','desc')->get()->result_array();
                foreach ($today_continue_check_in as $key => $booking_data) {
                $adv_cash=0;
                $pradcr=0;
                $refn=0;
                $due=0;
                $exrefn=0;
                $pradcs=0;
                $adj_cash=0;
                $adj_online=0;
                $advcs=0;
                $advcr=0;
                $now = time();
                $num_guest = $this->db->where('wr_id',$booking_data['wr_id'])->get('walk_in_guest')->num_rows();
                //$total_tarif=$total_tarif+$booking_data['total_amount'];
                //$total_advance=$total_advance+$booking_data['adv_amount'];
                $total_guest=$total_guest+$num_guest;
                $your_date = strtotime($booking_data['check_in']);
                $datediff = $now - $your_date;
                $num_days=round($datediff / (60 * 60 * 24));
                $ttarif=0;
                $gdata = $this->db->where('wr_id',$booking_data['wr_id'])->where('room_stay',0)->get('guest_details')->result_array();
                foreach ($gdata as $key => $tfd) {
                $ttarif=$ttarif+$tfd['gd_amount'];
                
                }
                $ttpaid=0;
                $pdata = $this->db->where('wr_id',$booking_data['wr_id'])->where('room_stay',0)->get('payment')->result_array();
                foreach ($pdata as $key => $payment_details) {
                $ttpaid=$ttpaid+$payment_details['p_amount'];
                $pdate=explode(' ', $payment_details['p_date']);
                if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']=='Cash') {
                
                if ($pdate[0]==date('Y-m-d')) {
                $advcs=$advcs+$payment_details['p_amount'];
                $total_tadvcs=$total_tadvcs+$advcs;
                }
                else
                {
                $pradcs=$pradcs+$payment_details['p_amount'];
                $total_advcs=$total_advcs+$pradcs;
                }
                // $pradcs=$booking_data['adv_amount'];
                //   $total_advcs=$total_advcs+$pradcs;
                }
                else if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']!='Cash') {
                if ($pdate[0]==date('Y-m-d')) {
                $advcr=$advcr+$payment_details['p_amount'];
                $total_tadvcr=$total_tadvcr+$advcr;
                }
                else
                {
                $pradcr=$pradcr+$payment_details['p_amount'];
                $total_advcr=$total_advcr+$pradcr;
                }
                }
                if ($payment_details['payment_purpose']=='Final Adjustment' && $payment_details['payment_mode']=='Cash') {
                
                $adj_cash=$adj_cash+$payment_details['p_amount'];
                $total_adjcs=$total_adjcs+$adj_cash;
                }
                else if ($payment_details['payment_purpose']=='Final Adjustment' && $payment_details['payment_mode']!='Cash') {
                
                $adj_online=$adj_online+$payment_details['p_amount'];
                $total_adjcr=$total_adjcr+$adj_online;
                }
                
                }
                if ($ttpaid>$ttarif) {
                $date = new DateTime($booking_data['check_out']);
                $now = new DateTime();
                if($date > $now) {
                //if ($booking_data['room_available']=='1') {
                $refn=$ttarif-$ttpaid;
                $total_refn=$total_refn+$refn;
                //}
                }
                else
                {
                $exrefn=$ttarif-$ttpaid;
                $total_exref=$total_exref+$exrefn;
                }
                }
                else
                {
                if ($booking_data['room_available']=='0') {
                $due=$ttarif-$ttpaid;
                $total_due=$total_due+$due;
                }
                }
                $total_tarif=$total_tarif+$ttarif;
                $total_advance=$total_advance+$ttpaid;
                ?>
                <tr>
                  <td style="text-align:left;"><?php echo $key+1; ?>.</td>
                  <td style="text-align:center;"><?php echo $booking_data['room_number']; ?></td>
                  <td style="text-align:center;"><?php echo $booking_data['check_in']; ?></td>
                  <td style="text-align:center;"><?php echo $num_days; ?></td>
                  <td style="text-align:center;"><?php echo $booking_data['check_in_time']; ?></td>
                  <td style="text-align:center;"><?php echo $num_guest; ?></td>
                  <td style="text-align:right;"><?php echo $ttarif; ?></td>
                  <td style="text-align:right;"><?php echo $due; ?></td>
                  <td style="text-align:right;"><?php echo $pradcs; ?></td>
                  <td style="text-align:right;"><?php echo $pradcr; ?></td>
                  <td style="text-align:right;"><?php echo $advcs; ?></td>
                  <td style="text-align:right;"><?php echo $advcr; ?></td>
                </tr>
                <?php } ?>
                
              </tbody>
              <thead>
                <tr>
                  <th style="border-top: 1px dashed #000;text-align:left;" colspan="7">Total :</th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_due; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_advcs; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_advcr; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_tadvcs; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_tadvcr; ?></th>
                </tr>
              </thead>
            </table>
          </div>
          <div style="border-bottom: 1px dashed #000;padding: 6px 30px;">
            <p style="font-size:16px;color: #000;font-weight: bold;margin: 0;margin-top: 20px;"> Checked-Out List : <?php echo date('d/m/Y',strtotime($yesterday)); ?></p>
          </div>
          <div style="border-bottom: 1px dashed #000;">
            <table style="color:#000;font-size: 16px; width: 100%; margin:0;">
              <thead>
                <tr>
                  <th style="border-bottom: 1px dashed #000;text-align:left;">Srl</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">Room</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">ArDate</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">InTM</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">Days</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">NOP</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">Tarif</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">BlAmt</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">PrAdCs</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">PrAdCr</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdjCs</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">AdjCr</th>
                  <th style="border-bottom: 1px dashed #000;text-align:right;">Refn</th>
                  <th style="border-bottom: 1px dashed #000;text-align:center;">OutTM</th>
                </tr>
              </thead>
              <tbody>
                <?php
                $start=0;
                $total_tarif=0;
                $total_advance=0;
                $totalbamount=0;
                $total_adjcs=0;
                $total_advcs=0;
                $total_advcr=0;
                $total_adjcr=0;
                $total_refn=0;
                $total_exref=0;
                $total_due=0;
                $card_collection=0;
                $total_guest=0;
                foreach ($today_check_out as $key => $booking_data) {
                $num_guest = $this->db->where('wr_id',$booking_data['wr_id'])->get('walk_in_guest')->num_rows();
                $bill_details = $this->db->where('wr_id',$booking_data['wr_id'])->get('reservation_billing')->result_array();
                $total_tarif=$total_tarif+$booking_data['total_amount'];
                $total_advance=$total_advance+$booking_data['adv_amount'];
                $total_guest=$total_guest+$num_guest;
                $due=$booking_data['total_amount']-$booking_data['adv_amount'];
                $total_due=$total_due+$due;
                $pradcr=0;
                $pradcs=0;
                $adv_cash=0;
                $adv_online=0;
                $adj_cash=0;
                $adj_online=0;
                $refn=0;
                $due=0;
                $exrefn=0;
                $now = time();
                //$now = strtotime($booking_data['check_out']); // or your date as well
                $your_date = strtotime($booking_data['check_in']);
                $datediff = $now - $your_date;
                $num_days=round($datediff / (60 * 60 * 24));
                $ttarif=0;
                $gdata = $this->db->where('wr_id',$booking_data['wr_id'])->get('guest_details')->result_array();
                foreach ($gdata as $key => $tfd) {
                $ttarif=$ttarif+$tfd['gd_amount'];
                
                }
                $ttpaid=0;
                $pdata = $this->db->where('wr_id',$booking_data['wr_id'])->get('payment')->result_array();
                foreach ($pdata as $key => $payment_details) {
                $ttpaid=$ttpaid+$payment_details['p_amount'];
                if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']=='Cash') {
                
                $adv_cash=$adv_cash+$payment_details['p_amount'];
                $total_advcs=$total_advcs+$adv_cash;
                $pradcs=$booking_data['adv_amount'];
                $total_advcs=$total_advcs+$pradcs;
                }
                else if ($payment_details['payment_purpose']=='Advance Payment' && $payment_details['payment_mode']!='Cash') {
                
                $pradcr=$pradcr+$payment_details['p_amount'];
                $total_advcr=$total_advcr+$pradcr;
                }
                if ($payment_details['payment_purpose']=='Final Adjustment' && $payment_details['payment_mode']=='Cash') {
                
                $adj_cash=$adj_cash+$payment_details['p_amount'];
                $total_adjcs=$total_adjcs+$adj_cash;
                }
                else if ($payment_details['payment_purpose']=='Final Adjustment' && $payment_details['payment_mode']!='Cash') {
                
                $adj_online=$adj_online+$payment_details['p_amount'];
                $total_adjcr=$total_adjcr+$adj_online;
                }
                
                }
                if ($ttpaid>$ttarif) {
                $date = new DateTime($booking_data['check_out']);
                $now = new DateTime();
                if($date > $now) {
                //if ($booking_data['room_available']=='1') {
                $refn=$ttarif-$ttpaid;
                $total_refn=$total_refn+$refn;
                //}
                }
                else
                {
                $exrefn=$ttarif-$ttpaid;
                $total_exref=$total_exref+$exrefn;
                }
                }
                else
                {
                if ($booking_data['room_available']=='0') {
                $due=$ttarif-$ttpaid;
                $total_due=$total_due+$due;
                }
                }
                $total_tarif=$total_tarif+$ttarif;
                $total_advance=$total_advance+$ttpaid;
                $totalbamount=$totalbamount+$ttpaid;
                ?>
                <tr>
                  <td style="text-align:left;"><?php echo $key+1; ?>.</td>
                  <td style="text-align:center;"><?php echo $booking_data['room_number']; ?></td>
                  <td style="text-align:center;"><?php echo $booking_data['check_in']; ?></td>
                  <td style="text-align:center;"><?php echo $booking_data['check_in_time']; ?></td>
                  <td style="text-align:center;"><?php echo $num_days; ?></td>
                  <td style="text-align:center;"><?php echo $num_guest; ?></td>
                  <td style="text-align:right;"><?php echo $ttarif; ?></td>
                  <td style="text-align:right;"><?php echo $ttpaid; ?></td>
                  <td style="text-align:right;"><?php echo $pradcs; ?></td>
                  <td style="text-align:right;"><?php echo $pradcr; ?></td>
                  <td style="text-align:right;"><?php echo $adj_cash; ?></td>
                  <td style="text-align:right;"><?php echo $adj_online; ?></td>
                  <td style="text-align:right;"><?php echo $refn; ?></td>
                  <td style="text-align:center;"><?php echo $booking_data['check_out_time']; ?></td>
                </tr>
                <?php } ?>
                
              </tbody>
              <thead>
                <tr>
                  <th style="border-top: 1px dashed #000;text-align:left;" colspan="6">Total :</th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_tarif; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $totalbamount; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_advcs; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_advcr; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_adjcs; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_adjcr; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"><?php echo $total_refn; ?></th>
                  <th style="border-top: 1px dashed #000;text-align:right;"></th>
                </tr>
              </thead>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
function printDiv() {
//  //$("input[id='ivnn']").each(function(){
//    var shiping_id = document.getElementById("service").value;
//    //qtyarray.push(qtyVal);
//    //console.log(shipping_id);
//  //});

// $.ajax({
//     url: 'server_pdf.php',
//     type: 'POST',
//     data: {service : shiping_id},
//     success: function(data) {
//        //$("#total"+id).html(data);
//     }
//  });

var divToPrint = document.getElementById('printArea').innerHTML;
//alert(divToPrint);
//console.log(divToPrint);
var newWin = window.open();
newWin.document.write('<html><head><title></title>');
newWin.document.write('</head><body >');
newWin.document.write(divToPrint);
newWin.document.write('</body></html>');
console.log(divToPrint);
newWin.document.close();
newWin.print();
//newWin.close();
//window.print();
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
<!-- jsPDF library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script>
window.jsPDF = window.jspdf.jsPDF;
// Convert HTML content to PDF
function Convert_HTML_To_PDF() {
var doc = new jsPDF();

// Source HTMLElement or a string containing HTML.
var elementHTML = document.querySelector("#printArea");
doc.html(elementHTML, {
callback: function(doc) {
// Save the PDF
doc.save('report.pdf');
},
margin: [10, 10, 10, 10],
autoPaging: 'text',
x: 0,
y: 0,
width: 150, //target width in the PDF document
windowWidth: 675 //window width in CSS pixels
});
}
</script>