<?php $this->view("includes/Inc_pagehead");?>
<!-- Page Styles Goes Here-->
<style>
.m-input{
  border: 1px solid #ebedf2 !important;
  background-color: #f4f5f833 !important;
}
#payment_view_table .dataTables_scrollHeadInner {
  width:100% !important;
  padding: 0 !important;
}
</style>
<?php $this->view("includes/Inc_navigation");?>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
  <!-- BEGIN: Subheader -->
  <div class="m-subheader ">
    <div class="d-flex align-items-center">
      <div class="mr-auto">
        <h3 class="m-subheader__title m-subheader__title--separator">
          Subcontract Work Profile
        </h3>
      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="row">
      <div class="col-xl-3 col-lg-4">
        <div class="m-portlet m-portlet--full-height  ">
          <div class="m-portlet__body" style="padding-top: 0px">
            <div class="m-card-profile">
              <div class="m-card-profile__title m--hide">
                Subcontract Work Profile
              </div>
              <div class="m-card-profile__pic">
                <div class="m-card-profile__pic-wrapper" style="overflow: hidden;">
                  <img src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/app/media/img/misc/work.png" alt=""/>
                </div>
              </div>
              <div class="m-card-profile__details">
                <span class="m-card-profile__name">
                  <?php echo $subcontract_data->sub_work_name ?>
                  <br>
                  <?php
                  if (is_numeric($subcontract_data->contractor)) {
                    $contractor = $subcontract_data->contractor_name;
                  } else {
                    $contractor = $subcontract_data->contractor;
                  }
                  echo " [ ".$contractor." - ".$subcontract_data->phone." ]"?>
                </span>
                <br/>
              </div>
              <div class="m-card-profile__details">
                <span class="m-card-profile__name">
                  <a href="<?php echo base_url()?>work/profile/<?php echo $subcontract_data->work_id ?>" class="m-card-profile__email m-link">
                    Project: <?php echo $subcontract_data->work_name ?>
                  </a>
                </span>
                <br/>
                <a data-contract-id="<?php echo $subcontract_data->contract_id ?>" style="margin-left: 5px;margin-right: 5px;margin-top: 10px" data-type="work_order" class="btn_print_subcontract btn btn-warning m-btn m-btn--icon  m-btn--pill m-btn--air">
                  <i class="fa fa-print"></i> Print <?php if($this->config->item('Subcontract_work_order_template')==2){ echo "Agreement";}else{echo "Work Order";} ?>
                </a>
                <br/>
                <a data-contract-id="<?php echo $subcontract_data->contract_id ?>" style="margin-left: 5px;margin-right: 5px;margin-top: 10px" data-type="summary" class="btn_print_subcontract btn btn-info m-btn m-btn--icon  m-btn--pill m-btn--air">
                  <i class="fa fa-print"></i> Print Summary
                </a>
                <br/>
                <a style="margin-top:10px;margin-bottom:10px;"href="<?php echo base_url()?>subcontracts/edit/<?php echo $subcontract_data->contract_id ?>" style="margin-left: 5px;margin-right: 5px"  class="btn btn-danger m-btn m-btn--icon  m-btn--pill m-btn--air">
                  <i class="fa fa-edit"></i> Edit Subcontract
                </a>
                <br/>
                <a style="margin-left: 5px;margin-right: 5px" target="_blank" href="<?php echo base_url().'subcontracts/add_bill/'.$subcontract_data->contract_id?>"  class="btn btn-focus m-btn m-btn--icon  m-btn--pill m-btn--air">
                  <i class="fa fa-plus"></i> Add Bill / Advance Payment
                </a>
              </div>

            </div>
            <ul class="m-nav m-nav--hover-bg m-portlet-fit--sides">
              <li class="m-nav__separator m-nav__separator--fit" style="margin-top: 0px"></li>
              <li class="m-nav__section m--hide">
                <span class="m-nav__section-text">
                  Section
                </span>
              </li>
              <li class="m-nav__item profile_nav" id="nav_info" data-nav="info" data-table-name=''>
                <a href="javascript:;" class="m-nav__link">
                  <i class="m-nav__link-icon fa fa-info-circle"></i>
                  <span class="m-nav__link-title">
                    <span class="m-nav__link-wrap">
                      <span class="m-nav__link-text">
                        Subcontract Info
                      </span>
                    </span>
                  </span>
                </a>
              </li>
              <li class="m-nav__item profile_nav" id="nav_bills" data-nav="bills" data-table-name='subcontract_bills_view_table'>
                <a href="javascript:;" class="m-nav__link">
                  <i class="m-nav__link-icon fa fa-shopping-cart"></i>
                  <span class="m-nav__link-title">
                    <span class="m-nav__link-wrap">
                      <span class="m-nav__link-text">
                        Bills
                      </span>
                    </span>
                  </span>
                </a>
              </li>
              <li class="m-nav__item profile_nav" id="nav_payments" data-nav="payments" data-table-name='subcontract_payments_view_table'>
                <a href="javascript:;" class="m-nav__link">
                  <i class="m-nav__link-icon fa fa-rupee-sign"></i>
                  <span class="m-nav__link-title">
                    <span class="m-nav__link-wrap">
                      <span class="m-nav__link-text">
                        Payments
                      </span>
                    </span>
                  </span>
                </a>
              </li>
              <li class="m-nav__item profile_nav" id="nav_deductions" data-nav="deductions" data-table-name='subcontract_deductions_view_table'>
                <a href="javascript:;" class="m-nav__link">
                  <i class="m-nav__link-icon fa fa-th-list"></i>
                  <span class="m-nav__link-title">
                    <span class="m-nav__link-wrap">
                      <span class="m-nav__link-text">
                        Deductions
                      </span>
                    </span>
                  </span>
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="col-xl-9 col-lg-8">
        <div id="div_info" class="profile_nav_div">

          <div class="m-portlet">
            <div class="m-portlet__body m-portlet__body--no-padding">
              <div class="row m-row--no-padding m-row--col-separator-xl">
                <div class="col-md-12 col-lg-12 col-xl-2">
                  <!--begin:: Widgets/Stats2-1 -->
                  <div class="m-widget1">
                    <div class="m-widget1__item">
                      <div class="row m-row--no-padding align-items-center">
                        <span class="m-widget1__number m--font-brand">
                          <label><?php echo $subcontract_data->total_budget ?></label>
                        </span>
                      </div>
                      <h3 class="m-widget1__title">
                        Est. Budget
                      </h3>
                    </div>
                  </div>
                  <!--end:: Widgets/Stats2-1 -->
                </div>
                <div class="col-md-12 col-lg-12 col-xl-2">
                  <!--begin:: Widgets/Stats2-3 -->
                  <div class="m-widget1">
                    <div class="m-widget1__item">
                      <div class="row m-row--no-padding align-items-center">
                        <span class="m-widget1__number m--font-success">
                          <label class=""><?php echo $no_of_bills ?></label>
                        </span>
                      </div>
                      <h3 class="m-widget1__title">
                        No of bills
                      </h3>
                    </div>
                  </div>
                  <!--begin:: Widgets/Stats2-3 -->
                </div>
                <div class="col-md-12 col-lg-12 col-xl-2">
                  <!--begin:: Widgets/Stats2-3 -->
                  <div class="m-widget1">
                    <div class="m-widget1__item">
                      <div class="row m-row--no-padding align-items-center">
                        <span class="m-widget1__number m--font-success">
                          <label class=""><?php echo $bill_amount ?></label>
                        </span>
                      </div>
                      <h3 class="m-widget1__title">
                        Total Bill Amount
                      </h3>
                    </div>
                  </div>
                  <!--begin:: Widgets/Stats2-3 -->
                </div>
                <div class="col-md-12 col-lg-12 col-xl-2">
                  <!--begin:: Widgets/Stats2-3 -->
                  <div class="m-widget1">
                    <div class="m-widget1__item">
                      <div class="row m-row--no-padding align-items-center">
                        <span class="m-widget1__number m--font-success">
                          <label class=""><?php echo $total_paid ?></label>
                        </span>
                      </div>
                      <h3 class="m-widget1__title">
                        Total Paid (Bill+Advance+OP Balance)
                      </h3>
                    </div>
                  </div>
                  <!--begin:: Widgets/Stats2-3 -->
                </div>
                <div class="col-md-12 col-lg-12 col-xl-2">
                  <!--begin:: Widgets/Stats2-3 -->
                  <div class="m-widget1">
                    <div class="m-widget1__item">
                      <div class="row m-row--no-padding align-items-center">
                        <span class="m-widget1__number m--font-success">
                          <label class=""><?php echo $bill_amount-$deduction_amount-$total_paid ?></label>
                        </span>
                      </div>
                      <h3 class="m-widget1__title">
                        Balance Payable (Bill Amt-Deductions-Total Paid)
                      </h3>
                    </div>
                  </div>
                  <!--begin:: Widgets/Stats2-3 -->
                </div>
                <div class="col-md-12 col-lg-12 col-xl-2">
                  <!--begin:: Widgets/Stats2-3 -->
                  <div class="m-widget1">
                    <div class="m-widget1__item">
                      <div class="row m-row--no-padding align-items-center">
                        <span class="m-widget1__number m--font-success">
                          <label class=""><?php echo $budget_balance-$bill_tds_amount-$deduction_amount ?></label>
                        </span>
                      </div>
                      <h3 class="m-widget1__title">
                        Balance to Budget<br/>(Budget-Total Paid-TDS-Deductions)
                      </h3>
                    </div>
                  </div>
                  <!--begin:: Widgets/Stats2-3 -->
                </div>
              </div>
            </div>
          </div>

          <div class="m-portlet">
            <div class="m-portlet__head">
              <div class="m-portlet__head-caption">
                <div class="m-portlet__head-title">
                  <h3 class="m-portlet__head-text">
                    Subcontract Info
                  </h3>
                </div>
              </div>
            </div>
            <div class="m-portlet__body">
              <div style="background: white;border: 4px solid #f7f7fa;padding: 20px;margin: 0px;padding-bottom: 0px">
                <div class="m-section" style="margin: 0px 0 10px 0;">
                  <h3 class="m-section__heading" style="padding: 0px;margin: 0px;padding-bottom: 15px">Subcontract Details</h3>
                  <div class="row" >
                    <?php
                    if ($subcontract_data->contract_type == 'fixed_rate') {
                      $contract_type = "<span class='m-badge m-badge--success m-badge--wide'><i class='fa fa-check'></i> Fixed Rate</span>";
                    } else {
                      $contract_type = "<span class='m-badge m-badge--info m-badge--wide'><i class='fa fa-ellipsis-h'></i> Unit Rate</span>";
                    }
                    ?>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Subcontract ID
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="#<?php echo $subcontract_data->contract_id ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-4">
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Subwork Name
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input  readonly value="<?php echo $subcontract_data->sub_work_name ?>"  type="text" name="bill_date" class="form-control m-input m-input--pill m-input--air " >
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-5" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Project
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo $subcontract_data->work_name ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-lg-4" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Contractor
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo $contractor ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-user"></i></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-4" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Phone
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo $subcontract_data->phone; ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-user"></i></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-4" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Address
                        </label>
                        <textarea readonly disabled class="form-control  m-input m-input--pill m-input--solid m-input--air"  aria-describedby="basic-addon1" rows="2"><?php echo $subcontract_data->contractor_address ?></textarea>
                      </div>
                    </div>
                  </div>
                  <div class="row" >
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Date
                        </label>
                        <input readonly value="<?php if($subcontract_data->subcontract_date!='0000-00-00'){ echo date('d-m-Y',strtotime($subcontract_data->subcontract_date));} ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Reference No
                        </label>
                        <input readonly value="<?php echo $subcontract_data->reference_no; ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                      </div>
                    </div>
                    <div class="col-lg-6">
                      <div class="form-group m-form__group">
                        <label for="user_name">
                          Work Description
                        </label>
                        <div style="border-radius: 20px;padding:15px;background-color: #f4f5f8 !important;
    border-color: #ebedf2 !important;
    color: #575962 !important;">
                          <?php echo $subcontract_data->description ?>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Contract Type
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <?php echo $contract_type ?>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Est. Budget
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $subcontract_data->total_budget ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Retention %
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $subcontract_data->retention_percent ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Retention Amount
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $subcontract_data->retention_amount ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Total Payable Amount
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $subcontract_data->payable_amount ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Op. Balance Paid
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $subcontract_data->op_balance ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Total Advance Paid
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo ($advance_paid_amount) ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3">
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          No. of Bills Received
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input  readonly value="<?php echo $no_of_bills ?>"  type="text" name="bill_date" class="form-control m-input m-input--pill m-input--air " >
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Total Bill Amount
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo $bill_amount ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Total Paid on Bill
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo ($bill_paid_amount) ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" style="display:none">
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Balance to Bills
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $bill_balance_amount ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-4" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Total Paid (Advance + Bill + OP Balance)
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo ($total_paid) ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-2" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Deductions
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $deduction_amount ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="row" >
                    <div class="col-lg-5" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Balance Payable (Bill Amount - Deductions - Total Paid )
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input readonly value="<?php echo ($bill_amount-$deduction_amount-$total_paid) ?>" type="text" class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-2" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          TDS
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $bill_tds_amount ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-2" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Retention
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $bill_retention_amount ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                    <div class="col-lg-3" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          <strong>Balance to Budget</strong> <br/>(Budget-Total Paid-TDS-Deductions)
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" readonly value="<?php echo $budget_balance-$bill_tds_amount-$deduction_amount ?>"  class="form-control m-input m-input--pill m-input--air" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format') ?></span></span>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <br/>
              <div style="background: white;border: 4px solid #f7f7fa;padding: 20px;margin: 0px;padding-bottom: 0px">
                <div class="m-section" style="margin: 0px 0 10px 0;">
                  <h3 class="m-section__heading" style="padding: 0px;margin: 0px;padding-bottom: 15px">Work Items</h3>
                  <table class="table table-striped m-table m-table--head-bg-brand">
                    <thead>
                      <tr>
                        <th>Sl No</th>
                        <th>Work Type</th>
                        <?php if($subcontract_data->contract_type == 'unit_rate') { ?>
                          <th>Measure Unit</th>
                          <th>Unit Rate</th>
                          <th>Quantity</th>
                          <th>Tax %</th>
                        <?php } ?>
                        <th>Est Amount</th>
                        <?php if($this->config->item('Subcontract_bill_type')=='work_items_based'){ ?>
                          <th>Billed Qty</th>
                          <th>Billed Amt</th>
                        <?php } ?>
                        <th>Remarks</th>
                      </tr>
                    </thead>
                    <tbody>
                      <?php
                      $item_sl_no = 1;
                      $total_est_amount = $total_billed_amount = 0;
                      foreach ($work_items->result() as $key => $value) {
                        $colspan2 = 3;?>
                        <tr>
                          <td><?php echo $item_sl_no ?></td>
                          <td><?php echo $value->type_name ?></td>
                          <?php if($subcontract_data->contract_type == 'unit_rate') {
                            $colspan2 += 4;?>
                            <td><?php echo $value->unit_name ?></td>
                            <td><?php echo $value->unit_rate ?></td>
                            <td><?php echo $value->qty ?></td>
                            <td><?php echo $value->tax_percent ?></td>
                          <?php } ?>
                          <td><?php echo round($value->est_amount,$this->config->item('Currency_amount_decimals_2')) ?></td>
                          <?php if($this->config->item('Subcontract_bill_type')=='work_items_based'){
                            $colspan2 += 2;?>
                            <td><?php echo $value->acheived_qty ?></td>
                            <?php if($subcontract_data->contract_type == 'unit_rate') {
                              $total_billed_amount += round($value->acheived_qty*$value->unit_rate,$this->config->item('Currency_amount_decimals_2'));
                              ?>
                              <td><?php echo round($value->acheived_qty*$value->unit_rate,$this->config->item('Currency_amount_decimals_2')) ?></td>
                            <?php }else{
                              $total_billed_amount += round($value->acheived_qty*$value->unit_rate_bill,$this->config->item('Currency_amount_decimals_2'));
                              ?>
                              <td><?php echo round($value->acheived_qty*$value->unit_rate_bill,$this->config->item('Currency_amount_decimals_2')) ?></td>
                            <?php } ?>
                          <?php } ?>
                          <td><?php echo $value->remarks ?></td>
                        </tr>
                        <tr>
                          <td></td>
                          <td colspan="<?php echo $colspan2 ?>">Description: <?php echo $value->work_details ?></td>
                        </tr>
                        <?php
                        $item_sl_no++;
                        $total_est_amount+=$value->est_amount;
                      } ?>
                      <tr>
                        <?php if($subcontract_data->contract_type == 'unit_rate') {
                          $colspan=6;
                        }else{
                          $colspan=2;
                        }?>
                        <td colspan="<?php echo $colspan ?>"><strong>Total</strong></td>
                        <td><strong><?php echo $total_est_amount ?></strong></td>
                        <?php if($this->config->item('Subcontract_bill_type')=='work_items_based'){ ?>
                          <td></td>
                          <td><strong><?php echo $total_billed_amount ?></strong></td>
                        <?php } ?>
                        <td></td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
              <div style="background: white;border: 4px solid #f7f7fa;padding: 20px;margin: 0px;padding-bottom: 0px">
                <div class="m-section" style="margin: 0px 0 10px 0;">
                  <h3 class="m-section__heading" style="padding: 0px;margin: 0px;padding-bottom: 15px">Terms & Conditions</h3>
                  <table class="table table-striped m-table m-table--head-bg-focus">
                    <thead>
                      <tr>
                        <th>Sl No</th>
                        <th>Title </th>
                        <th>Description</th>
                      </tr>
                    </thead>
                    <tbody>
                      <?php
                      $terms = unserialize($subcontract_data->terms_and_conditions);
                      if($terms!='' && $terms!=null) {
                        $count = sizeof($terms);
                        $i = 1;
                        foreach ($terms as $key => $value5) { ?>
                          <tr>
                            <td><?php echo $i ?></td>
                            <td><?php echo $value5['title'] ?></td>
                            <td><?php echo $value5['description'] ?></td>
                          </tr>
                          <?php $i++;
                        }
                      } ?>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div id="div_bills" class="profile_nav_div">
          <div class="m-portlet m-portlet--mobile m-portlet--info m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
            <div class="m-portlet__head">
              <div class="m-portlet__head-caption">
                <div class="m-portlet__head-title">
                  <h3 class="m-portlet__head-text">
                    Subcontract Bills
                  </h3>
                </div>
              </div>
              <div class="m-portlet__head-tools">
                <?php if($this->session->userdata('user_role')!='purchase_manager' && $this->session->userdata('user_role')!='boq_manager' && $this->session->userdata('user_role')!='sales_manager'  && $this->session->userdata('user_role')!='sales_staff' && ($this->session->userdata('user_role')!='auditor' || $this->session->userdata('user_data_permission')['adding']==1) ) { ?>
                  <a target="_blank" href="<?php echo base_url()?>subcontracts/add_bill/<?php echo $subcontract_data->contract_id?>" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
                    <span>
                      <i class="la la-plus"></i>
                      <span>
                        Add New Bill
                      </span>
                    </span>
                  </a>
                <?php } ?>
              </div>
            </div>
            <div class="m-portlet__body">
              <?php $this->view("modules/include_tables/table_subcontract_bills");?>
            </div>
          </div>
        </div>
        <div id="div_payments" class="profile_nav_div">
          <div class="m-portlet m-portlet--mobile m-portlet--info m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
            <div class="m-portlet__head">
              <div class="m-portlet__head-caption">
                <div class="m-portlet__head-title">
                  <h3 class="m-portlet__head-text">
                    Subcontract Payments
                  </h3>
                </div>
              </div>
              <div class="m-portlet__head-tools">
                <?php if($this->session->userdata('user_role')!='purchase_manager' && $this->session->userdata('user_role')!='boq_manager' && $this->session->userdata('user_role')!='sales_manager'  && $this->session->userdata('user_role')!='sales_staff' && ($this->session->userdata('user_role')!='auditor' || $this->session->userdata('user_data_permission')['adding']==1) ) { ?>
                  <a target="_blank" href="<?php echo base_url()?>subcontracts/add_bill/<?php echo $subcontract_data->contract_id?>" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
                    <span>
                      <i class="la la-plus"></i>
                      <span>
                        Add Advance Payment
                      </span>
                    </span>
                  </a>
                <?php } ?>
              </div>
            </div>
            <div class="m-portlet__body">
              <?php $this->view("modules/include_tables/table_subcontract_payments");?>
            </div>
          </div>
        </div>
        <div id="div_deductions" class="profile_nav_div">
          <div class="m-portlet m-portlet--mobile m-portlet--info m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
            <div class="m-portlet__head">
              <div class="m-portlet__head-caption">
                <div class="m-portlet__head-title">
                  <h3 class="m-portlet__head-text">
                    Subcontract Deductions
                  </h3>
                </div>
              </div>
              <div class="m-portlet__head-tools">
                <?php if($this->session->userdata('user_role')!='purchase_manager' && $this->session->userdata('user_role')!='boq_manager' && $this->session->userdata('user_role')!='sales_manager'  && $this->session->userdata('user_role')!='sales_staff' && ($this->session->userdata('user_role')!='auditor' || $this->session->userdata('user_data_permission')['adding']==1) ) { ?>
                  <a href="#" data-toggle="modal" data-target="#subcontract_deductions_add_modal" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
                    <span>
                      <i class="la la-plus"></i>
                      <span>
                        Add Deductions
                      </span>
                    </span>
                  </a>
                <?php } ?>
              </div>
            </div>
            <div class="m-portlet__body">
              <?php $this->view("modules/include_tables/table_subcontract_deductions");?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<?php $this->view("modules/include_modals/modal_bills");?>
<?php $this->view("modules/include_modals/modal_transaction_delete");?>


</div>
</div>
<!-- end:: Body -->
<!-- begin::Footer -->
<?php $this->view("includes/Inc_footer");?>
<!-- end::Footer -->
</div>
<!-- end:: Page -->
<?php $this->view("includes/Inc_sidebar");?>
<?php $this->view("includes/Inc_scripts");?>

<!--begin::Page Snippets -->
<script src="<?php echo $this->config->item('Template_template_file_url'); ?>template/assets/app/js/dashboard.js" type="text/javascript"></script>
<!--end::Page Snippets -->

<script>
function hide_all(){
  $(".profile_nav").removeClass('m-nav__item--active');
  $(".profile_nav_div").hide();
}
function active(menu_name){
  hide_all();
  $("#nav_"+menu_name).addClass('m-nav__item--active');
  $("#div_"+menu_name).show();
  $("#div_"+menu_name).fadeIn("slow");
  $('html, body').animate({
    scrollTop: eval($("#div_"+menu_name).offset().top - 150)
  }, 500);
}
//  Hide All Div and In Active All Menu
hide_all();
//  Active First Menu and Its div
active('info');
$('body').on('click', '.profile_nav', function() {
  var nav = $(this).attr('data-nav');
  active(nav);
})
</script>
<script>

$("#subcontract_menu").addClass('m-menu__item--active m-menu__item--open');
$("#subcontract_menu_1").addClass('m-menu__item--active');
$("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
$("#body").addClass("m-brand--minimize m-aside-left--minimize");
</script>
<!-- Bill Scripts -->
<?php $this->view("modules/include_scripts/bill_scripts");?>
<!-- Transaction Scripts -->
<?php $this->view("modules/include_scripts/transaction_scripts");?>
<?php $this->view("modules/include_scripts/subcontract_payments_view_scripts");?>
<?php $this->view("modules/include_scripts/subcontract_bill_scripts");?>
<script>
$("#deduction_date_add,#deduction_date_edit").datepicker( {
  todayHighlight:!0, orientation:"bottom right", templates: {
    leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
  }
})
$('body').on('click', '#subcontract_deduction_delete_btn', function() {
  var no = $(this).closest('tr').children('td');
  $('#deduction_id_delete').val(no.eq(0).text());
})
$('body').on('click', '#subcontract_deduction_edit_btn', function() {
  var no = $(this).closest('tr').children('td');
  $('#deduction_id_edit').val(no.eq(0).text());
  $('#deduction_date_edit').datepicker("setDate",no.eq(2).text());
  $('#deduction_amount_edit').val(no.eq(3).text());
  $('#deduction_description_edit').val(no.eq(4).text());
})

$('body').on('click', '.btn_print_subcontract', function() {
  var id=$(this).data('contract-id');
  var type=$(this).data('type');
  window.open('<?php echo base_url().'subcontracts/print/' ?>'+id+"/"+type,'newwindow','width=1200,height=700');
  return false
});
var id = "<?php echo $subcontract_data->contract_id?>";

$('body').on('click', '#subcontract_delete_btn', function() {
  var no = $(this).closest('tr').children('td');
  $('#delete_contract_id').val(no.eq(20).text());
})

var subcontract_deductions_view_table = $('#subcontract_deductions_view_table').DataTable({
  "ajax": {
    url: "<?php echo base_url() . 'subcontracts/select_subcontract_deductions/' ?>", // json datasource
    type: "post", // type of method  , by default would be get
    data: function(d) {
      <?php if ($page_name == 'subcontract_profile') { ?>
        d.contract_id = "<?php echo $subcontract_data->contract_id ?>";
        <?php } ?>
      }
    },
    "bProcessing": true,
    "deferRender": true,
    "bDeferRender": true,
    <?php if ($page_name == 'work_summary') { ?> "scrollX": false,
    bFilter: false,
    "bLengthChange": false,
    "bPaginate": false,
    "bInfo": false,
    buttons: [{
      extend: 'colvis',
      className: 'btn dark btn-outline',
      text: 'Columns'
    }],
    "dom": "<'row' <'col-md-12'B>><'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
    <?php } else { ?>
      "scrollX": true,
      buttons: [{
        extend: 'print',
        className: 'btn dark btn-outline',
        exportOptions: {
          columns: ':visible'
        },
        title: 'Subcontract Deductions',
        <?php if($this->config->item('company_letter_head')!=''){ ?>
          customize: function ( win ) {
            $(win.document.body).prepend(
              '<img src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" style="top:0; left:0;width:100%;" />'
            );
          }
          <?php } ?>
        },
        {
          extend: 'csv',
          className: 'btn purple btn-outline '
        },
        {
          extend: 'colvis',
          className: 'btn dark btn-outline',
          text: 'Columns'
        }
      ],
      dom: "<'row'<'col-sm-6 text-left'B><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
      "lengthMenu": [
        [25, 50, 100, -1],
        [25, 50, 100, "All"] // change per page values here
      ],
      <?php } ?>
      "columnDefs": [{
        "targets": [0],
        className: "hidden"
      }],
      'order': false
    });



    jQuery(document).ready(function() {
      $('.profile_nav').on('click', function(e){
        var table_name = $(this).attr('data-table-name');
        if(table_name!=''){
          var tables = table_name.split(',');
          $.each(tables, function( index, value ){
            var table_name = value;
            eval(table_name).ajax.reload();
          });
        }
      });
      $(".form_submit_btn").click(function (e) {
        e.preventDefault();
        var a = $(this),
        l = $(this).closest("form"),
        action = l.attr('action');
        var form_id = l.attr('id');
        l.validate({
          rules: {
            paid_amount: {
              number: !0,
              required: !0
            }
          }, invalidHandler: function (e, r) {
            var i = $("#" + form_id + "_msg");
            i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
          }, submitHandler: function (e) {
          }
        }), l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
        l.ajaxSubmit({
          url: action,
          success: function (e, t, r, s) {
            var modal_id = l.attr('data-modal-id');
            var form_type = l.attr('data-form-type');
            $("#" + form_id + "_msg").addClass("m--hide");
            // Block UI
            mApp.blockPage({
              overlayColor: "#000000",
              type: "loader",
              state: "success",
              message: "Please wait..."
            }), setTimeout(function () {
              mApp.unblockPage()
            }, 2e3);
            var obj = $.parseJSON(e);
            if (obj.status == 1) {
              a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
              toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
              $("#"+modal_id).modal('toggle');
              $("."+form_id+"_fields").val('');
              $("."+form_id+"_select").val('').trigger("change");
              // select_summary();
              subcontract_bills_view_table.ajax.reload();
              subcontract_payments_view_table.ajax.reload();
              subcontract_deductions_view_table.ajax.reload();
            } else {
              a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
              toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
            }
            if (obj == null) {
              setTimeout(function () {
                a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                toastr["warning"]("Your Attempt is Timed Out. Please Try Again.", "Timed Out");
              }, 2e4)
            }
          },error: function() {
            a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
            toastr["error"]("Sorry. There Has Been Some Error Occurred. Please Try Again.", "Error");
          }
        })
      )
    });
    $($.fn.dataTable.tables(true)).DataTable()
    .columns.adjust()
    .responsive.recalc();

  });
</script>
