<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title><?= $this->config->item('company_name')?></title>
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/b-flash-1.6.1/b-html5-1.6.1/b-print-1.6.1/fc-3.3.0/fh-3.1.6/kt-2.5.1/r-2.2.3/rg-1.1.1/sc-2.0.1/sp-1.0.1/datatables.min.css"/>

</head>
<style type="text/css">

body { font-family:Tahoma, Geneva, sans-serif;
  font-style:normal;
  font-weight:normal;
  font-variant:normal;
  font-size:12px;
  padding:0px;
  margin:0px;
  line-height:18px;
}
.item_table td{
  padding: .75rem !important;
}
.item_table th{
  white-space: nowrap;
  padding: .75rem !important;
}
.table thead th {
  border-top: 2px solid #f4f5f8 !important;
}
@media print
{
  #print, .print_div
  {
    display: none !important;
  }
}
</style>
<body >
  <div class="m-grid__item m-grid__item--fluid m-wrapper" id="content">


    <div class="m-content">
      <div class="row">
        <div style="width:1000px; height:auto;">
          <div class="m-portlet">
            <div class="m-portlet__body m-portlet__body--no-padding">
              <!-- client Details -->
              <div class="m-portlet  m-portlet--rounded m-portlet--bordered print_div" style="text-align: right">
                <a href="javascript:;" style="margin-top: 20px;margin-bottom: 20px;margin-right: 20px"  id="print"   class="btn btn-primary m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
                  <span>
                    <i class="la la-print"></i>
                    <span>
                      Print
                    </span>
                  </span>
                </a>
              </div>
              <?php if($this->session->userdata('user_role')=='admin'){?>
                <div class="m-portlet  m-portlet--rounded m-portlet--bordered">
                  <div class="m-portlet__body">
                    <h3 class="m-portlet__head-text" style="text-align: center">
                      Client Payment Details
                    </h3>
                    <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="client_payments_view_table">
                      <thead>
                        <tr class="">
                          <th>Sl No</th>
                          <th>ID</th>
                          <th>Receipt ID</th>
                          <th>Received Date</th>
                          <th>Client Name</th>
                          <th>Work Name</th>
                          <th>Received Payment</th>
                          <th>Credited to Acc</th>
                          <th>Receipt No</th>
                          <th>Remarks</th>
                          <th>Received By</th>
                          <th>Created Date</th>
                          <th>Actions</th>
                          <th>Last Updated By</th>
                          <th>Last Updated Date</th>
                          <th>work id</th>
                          <th>Client Id</th>
                          <th>Credited to Acc</th>
                        </tr>
                      </thead>
                      <tbody>
                      </tbody>
                    </table>
                  </div>
                </div>
              <?php } ?>
              <!-- Purchase Payments -->
              <div class="m-portlet  m-portlet--rounded m-portlet--bordered">
                <div class="m-portlet__body">
                  <h3 class="m-portlet__head-text" style="text-align: center">
                    Purchase Payments
                  </h3>
                  <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="purchase_all_1">
                    <thead>
                      <tr class="">
                        <th>Sl No</th>
                        <th>Purchase ID</th>
                        <th>Paid Date</th>
                        <th>Supplier Name</th>
                        <th>Purchased To Location</th>
                        <th>Paid Amount</th>
                        <th>Debit Acc</th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                </div>
              </div>
              <div class="m-portlet  m-portlet--rounded m-portlet--bordered">
                <div class="m-portlet__body">
                  <h3 class="m-portlet__head-text" style="text-align: center">
                    Expenses
                  </h3>
                  <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="expense_view_table_1">
                    <thead>
                      <tr class="">
                        <th>Sl No</th>
                        <th>Date</th>
                        <th>Expense Type</th>
                        <th>Expense Head</th>
                        <th>Expense Amount</th>
                        <th>Debit From Acc</th>
                        <th>Remarks</th>
                        <th>Work</th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                </div>
              </div>
              <div class="m-portlet  m-portlet--rounded m-portlet--bordered">
                <div class="m-portlet__body">
                  <h3 class="m-portlet__head-text" style="text-align: center">
                    Subcontract Payments
                  </h3>
                  <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="subcontracts_payment_view_table_1">
                    <thead>
                      <tr class="">
                        <th>Sl No</th>
                        <th>Payment ID</th>
                        <th>Work</th>
                        <th>Work type</th>
                        <th>Subcontract Name</th>
                        <th>Contractor</th>
                        <th>Paid Amount</th>
                        <th>Paid Date</th>
                        <th>Debit From Acc</th>
                        <th>Remarks</th>
                        <th>Created By</th>
                        <th>Created Date</th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                </div>
              </div>
              <div class="m-portlet  m-portlet--rounded m-portlet--bordered">
                <div class="m-portlet__body">
                  <h3 class="m-portlet__head-text" style="text-align: center">
                    Payment Summary
                  </h3>
                  <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="all_payments">
                    <thead>
                      <tr class="">
                        <th>Types Of Payments</th>
                        <th>Amount</th>
                      </tr>
                    </thead>
                    <tbody>
                      <?php if($this->session->userdata('user_role')=='admin'){?>
                        <tr>
                          <td>Client Payment Received</td>
                          <strong><td id="client_total_received_1"></td></strong>
                        </tr>
                        <tr>
                          <td>Total Purchase Bill Commissions</td>
                          <strong><td id="purchase_bill_commission"></td></strong>
                        </tr>
                      <?php } ?>
                      <tr>
                        <td>Purchase Payments</td>
                        <strong><td id="total_purchases_1"></td></strong>
                      </tr>
                      <tr>
                        <td>Subcontract Payments</td>
                        <strong><td id="subcontract_payments_1"></td></strong>
                      </tr>
                      <tr>
                        <td>Other Expense</td>
                        <strong><td id="other_payments_1"></td></strong>
                      </tr>
                      <tr>
                        <td></td>
                        <td></td>
                      </tr>
                      <tr>
                        <td>Total Expenses</td>
                        <strong><td id="total_expenses_1"></td></strong>
                      </tr>
                      <?php if($this->session->userdata('user_role')=='admin'){?>
                        <tr>
                          <td>Total Project Management Commission Amount</td>
                          <strong><td id="total_commission_amount"></td></strong>
                        </tr>
                        <tr>
                          <td>Total Amount to Receive</td>
                          <strong><td id="total_amount_to_receive"></td></strong>
                        </tr>
                        <tr>
                          <td>Actual Received</td>
                          <strong><td id="total_income_1"></td></strong>
                        </tr>
                        <tr>
                          <td>Balance</td>
                          <strong><td id="total_balance_1"></td></strong>
                        </tr>
                      <?php } ?>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <script src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/vendors/base/vendors.bundle.js" type="text/javascript"></script>
      <script src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/demo/default/base/scripts.bundle.js" type="text/javascript"></script>
      <script type="text/javascript" src="https://cdn.datatables.net/v/bs4/jszip-2.5.0/dt-1.10.20/b-1.6.1/b-colvis-1.6.1/b-flash-1.6.1/b-html5-1.6.1/b-print-1.6.1/fc-3.3.0/fh-3.1.6/kt-2.5.1/r-2.2.3/rg-1.1.1/sc-2.0.1/sp-1.0.1/datatables.min.js"></script>

      <!--end::Base Scripts -->
      <script>
      var Datatable=function() {
        var t = function () {

          function GetSearchDate() {
            return "<?php echo $date?>"
          }

          function GetSearchWork() {
            return "<?php echo $work?>"
          }

          var table6 = $('#client_payments_view_table').DataTable({
            "ajax": {
              url: "<?php echo base_url()  . 'client_payments/select_client_payments/2' ?>", // json datasource
              type: "post", // type of method  , by default would be get
              data: function (d) {
                d.date = GetSearchDate();
                d.work = GetSearchWork();
              }
            },
            "bProcessing": true,
            "deferRender": true,
            "bDeferRender": true,
            "scrollX": false,
            bFilter: false,
            "bLengthChange": false,
            "bPaginate": false,
            "bInfo": false,
            "dom": "<'row' <'col-md-12'>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable

            "columnDefs": [
              {
                "targets": [1,2,8,9,10,11,12,13,14,15,16,17],
                className: "hidden"
              }
            ],
            'ordering': false
          });
          var table7 = $('#purchase_all_1').DataTable({
            "ajax": {
              url: "<?php echo base_url()  . 'purchases/select_purchase_payments/2' ?>", // json datasource
              type: "post", // type of method  , by default would be get
              data: function (d) {
                d.date = GetSearchDate();
                d.work = GetSearchWork();
              }
            },
            "bProcessing": true,
            "deferRender": true,
            "bDeferRender": true,
            "scrollX": false,
            bFilter: false,
            "bLengthChange": false,
            "bPaginate": false,
            "bInfo": false,
            "dom": "<'row' <'col-md-12'>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable

            "columnDefs": [
              {
                "targets": [],
                className: "hidden"
              }
            ],
            'ordering': false
          });
          var table8 = $('#expense_view_table_1').DataTable({
            "ajax": {
              url: "<?php echo base_url()  . 'expense/select_expense' ?>", // json datasource
              type: "post", // type of method  , by default would be get
              data: function (d) {
                //                         d.status = GetSearchStatus();
                d.date = GetSearchDate();
                d.work = GetSearchWork();
              }
            },
            "bProcessing": true,
            "deferRender": true,
            "bDeferRender": true,
            "scrollX": false,
            bFilter: false,
            "bLengthChange": false,
            "bPaginate": false,
            "bInfo": false,
            "dom": "<'row' <'col-md-12'>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable

            "columnDefs": [
              {
                "targets": [4],
                className: "hidden"
              }
            ],
            'ordering': false
          });
          var table9 = $('#subcontracts_payment_view_table_1').DataTable({
            "ajax": {
              url: "<?php echo base_url()  . 'subcontract_payments/select_subcontract_payments' ?>", // json datasource
              type: "post", // type of method  , by default would be get
              data: function (d) {
                //                         d.status = GetSearchStatus();
                d.date = GetSearchDate();
                d.work = GetSearchWork();
              }
            },
            "bProcessing": true,
            "deferRender": true,
            "bDeferRender": true,
            "scrollX": false,
            bFilter: false,
            "bLengthChange": false,
            "bPaginate": false,
            "bInfo": false,
            "dom": "<'row' <'col-md-12'>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable

            "columnDefs": [
              {
                "targets": [1,9,10,11],
                className: "hidden"
              }
            ],
            'ordering': false
          });

          $.post("<?php echo base_url().'reports/select_report_counts' ?>",{
            date:GetSearchDate(),work:GetSearchWork()
          },function(data){
            var obj= $.parseJSON(data);
            if(obj.status==1) {
              $("#client_total_received").html(obj.total_client_payments);
              $("#client_total_received_1").html(obj.total_client_payments);
              $("#total_purchases").html(obj.total_purchase_payments);
              $("#total_purchases_1").html(obj.total_purchase_payments);
              $("#subcontract_payments").html(obj.total_sub_payments);
              $("#subcontract_payments_1").html(obj.total_sub_payments);
              $("#other_payments").html(obj.total_other_expense);
              $("#other_payments_1").html(obj.total_other_expense);
              $("#total_expenses").html(obj.total_expenses)
              $("#total_expenses_1").html(obj.total_expenses)
              $("#total_income_1").html(obj.total_income)
              $("#total_balance_1").html(obj.total_balance)
              $("#total_commission_amount").html(obj.total_commission);
              $("#total_amount_to_receive").html(obj.total_amount_to_receive);
              $("#purchase_bill_commission").html(obj.total_purchase_commission);
            }

          })
        };
        return {
          init:function() {
            t()
          }
        }
      }();
      jQuery(document).ready(function() {
        Datatable.init();
        $(".hidden").hide();
        $($.fn.dataTable.tables(true)).DataTable()
        .columns.adjust()
        .responsive.recalc();
        $('#print').click(function(e) {
          window.print();
        })
      }

    );
    </script>
    <style>
    .hidden{
      display: none;
    }
    </style>
  </body>
  </html>
