<?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;
  }
  .m-nav .m-nav__item>.m-nav__link .m-nav__link-title>.m-nav__link-wrap .m-nav__link-text {

  }
  .weekend {
    background: #f4f7f4;
  }

  .gantt_selected .weekend {
    background: #f7eb91;
  }
  .gantt_grid_head_add{
    display: none;
    }.gantt_add{
      display: none
    }
    .gantt_task_line, .gantt_line_wrapper {
      margin-top: -9px;
    }
    .gantt_side_content {
      margin-bottom: 7px;
    }
    .gantt_task_link .gantt_link_arrow {
      margin-top: -12px
    }
    .gantt_side_content.gantt_right {
      bottom: 0;
    }
    .baseline {
      position: absolute;
      border-radius: 2px;
      opacity: 0.6;
      margin-top: -7px;
      height: 12px;
      background: #ffd180;
      border: 1px solid rgb(255,153,0);
    }
  </style>

  <script src="<?php echo base_url()?>template/assets/vendors/custom/gantt/codebase/dhtmlxgantt.js?v=6.3.3"></script>
  <script src="<?php echo base_url()?>template/assets/vendors/custom/gantt/codebase/ext/dhtmlxgantt_tooltip.js?v=6.3.3"></script>
  <link rel="stylesheet" href="<?php echo base_url()?>template/assets/vendors/custom/gantt/codebase/dhtmlxgantt.css?v=6.3.3">

  <script src="<?php echo base_url()?>template/assets/vendors/custom/gantt/samples/common/testdata.js?v=6.3.3"></script>
  <?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">
            Stage 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">
                  Stage Profile
                </div>
                <div class="m-card-profile__pic">
                  <div class="m-card-profile__pic-wrapper">
                    <?php if ($work_data->photo!='') { ?>
                      <img src="<?php echo base_url()?>uploads/projects/<?= $work_data->photo ?>" alt=""/>
                    <?php }else{ ?>
                      <img src="<?php echo base_url()?>uploads/projects/default.png" alt=""/>
                    <?php } ?>
                  </div>
                </div>
                <div class="m-card-profile__details">
                  <span class="m-card-profile__name">
                    #<?= $stage_data->stage_no .' - '. $stage_data->stage_name?>
                  </span>
                  <a href="" class="m-card-profile__email m-link">
                    <?= $work_data->work_name ?>
                  </a>
                </div>
                <div class="m-card-profile__details">
                  <span class="m-card-profile__name">

                  </span>
                </div>
                <br/>
              </div>
              <ul class="m-nav m-nav--hover-bg m-portlet-fit--sides" id="m_nav" role="tablist">
                <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>
                <?php if($this->session->userdata('user_role')!='boq_manager') {?>
                  <li class="m-nav__item profile_nav" id="nav_overview" data-nav="overview" data-table-name=''>
                    <a href="javascript:;" class="m-nav__link">
                      <i class="m-nav__link-icon fa fa-industry"></i>
                      <span class="m-nav__link-title">
                        <span class="m-nav__link-wrap">
                          <span class="m-nav__link-text">
                            Stage Overview
                          </span>
                        </span>
                      </span>
                    </a>
                  </li>
                <?php } ?>
                <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">
                          Stage Info
                        </span>
                      </span>
                    </span>
                  </a>
                </li>
                <!-- Include All Profile Navigations -->
                <?php $this->view("includes/Inc_stage_profile_navigation");?>

              </ul>
            </div>
          </div>
        </div>
        <div class="col-xl-9 col-lg-8">
          <?php if($this->config->item('user_data_access_view_all')!=1){?>
            <div class="m-alert m-alert--outline m-alert--outline-2x alert alert-danger alert-dismissible fade show" role="alert">
              <strong>Please Note!</strong> Project Data and Counts are Shown only Based on Your Entries... Whole Project Details Will Not be Shown Here
            </div>
          <?php } ?>

          <div class="m-portlet">
            <div class="m-portlet__head" style="height: auto;text-align: center">
              <div class="m-portlet__head-tools" style="display: -webkit-box !important;">
                <?php if($this->session->userdata('user_role')=='madmin' || $this->session->userdata('user_role')=='admin' || ($this->session->userdata('user_role')=='manager' && $this->session->userdata('user_id')==$work_data->work_created_by)) {?>
                  <a style="margin-right: 5px" href="<?php echo base_url()?>work/edit/<?php echo $work_data->work_id?>"  class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
                    <span>
                      <i class="la la-edit"></i>
                      <span>
                        Edit Project Details
                      </span>
                    </span>
                  </a>
                  <a href="#" style="margin-left: 5px;margin-right: 5px" data-toggle="modal" data-target="#stage_status_edit_modal"  class="btn btn-success m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
                    <span>
                      <i class="la la-edit"></i>
                      <span>
                        Edit Stage Status
                      </span>
                    </span>
                  </a>

              <?php } ?>

              <?php if($this->session->userdata('user_role')!='boq_manager'){ ?>
                <a href="#" style="margin-left: 5px;margin-right: 5px" id="print_summary"  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 Stage Summary
                    </span>
                  </span>
                </a>
              <?php } ?>
            </div>
          </div>
        </div>
        <div id="div_overview" class="profile_nav_div">
          <?php if($this->session->userdata('user_role')!='purchase_manager' && $this->session->userdata('user_role')!='boq_manager'){?>
            <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-4">
                    <!--begin:: Widgets/Stats2-1 -->
                    <?php if($this->session->userdata('user_role')=='admin' || $this->session->userdata('user_role')=='accounts_manager'){?>
                      <div class="m-widget1">
                        <div class="m-widget1__item">
                          <div class="row m-row--no-padding align-items-center">
                            <div class="col">
                              <h3 class="m-widget1__title">
                                Stage Budget
                              </h3>
                            </div>
                            <div class="col m--align-right">
                              <span class="m-widget1__number m--font-brand">
                                <label class="total_stage_budget_info"></label>
                              </span>
                            </div>
                          </div>
                        </div>
                      </div>
                    <?php } ?>
                    <!--end:: Widgets/Stats2-1 -->
                  </div>
                  <div class="col-md-12 col-lg-12 col-xl-4">
                    <!--begin:: Widgets/Stats2-2 -->
                    <?php if($this->session->userdata('user_role')!='supervisor'){?>
                      <div class="m-widget1">
                        <div class="m-widget1__item">
                          <div class="row m-row--no-padding align-items-center">
                            <div class="col">
                              <h3 class="m-widget1__title">
                                Received From Client
                              </h3>
                            </div>
                            <div class="col m--align-right">
                              <span class="m-widget1__number m--font-accent">
                                <label class="total_received_from_client_info"></label>
                              </span>
                            </div>
                          </div>
                        </div>
                      </div>
                    <?php } ?>
                    <!--begin:: Widgets/Stats2-2 -->
                  </div>
                  <div class="col-md-12 col-lg-12 col-xl-4">
                    <!--begin:: Widgets/Stats2-3 -->
                    <div class="m-widget1">
                      <div class="m-widget1__item">
                        <div class="row m-row--no-padding align-items-center">
                          <div class="col">
                            <h3 class="m-widget1__title">
                              Total Expense Payments
                            </h3>
                          </div>
                          <div class="col m--align-right">
                            <span class="m-widget1__number m--font-success">
                              <label class="total_expense_payments_info"></label>
                            </span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!--begin:: Widgets/Stats2-3 -->
                  </div>

                </div>
              </div>
            </div>
          <?php } ?>
          <?php if($this->session->userdata('user_role')!='boq_manager'){?>

            <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-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="total_purchase_payment_info"></label>
                          </span>
                          <h3 class="m-widget1__title">
                            Purchase Payments
                          </h3>
                        </div>
                      </div>
                    </div>
                    <!--begin:: Widgets/Stats2-3 -->
                  </div>
                  <?php if($this->session->userdata('user_role')!='purchase_manager'){?>
                    <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="total_subcontract_payment_info"></label>
                            </span>
                            <h3 class="m-widget1__title">
                              Subcontract Payments
                            </h3>
                          </div>
                        </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="total_labour_wages_info"></label>
                            </span>
                            <h3 class="m-widget1__title">
                              Labour Wages
                            </h3>
                          </div>
                        </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="total_other_expense_payments_info"></label>
                            </span>
                            <h3 class="m-widget1__title">
                              Other Expense Payments
                            </h3>
                          </div>
                        </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="total_salary_payment_info"></label>
                            </span>
                            <h3 class="m-widget1__title">
                              Salary Payments
                            </h3>
                          </div>
                        </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="total_vehicle_payments_info"></label>
                            </span>
                            <h3 class="m-widget1__title">
                              Vehicle Payments
                            </h3>
                          </div>
                        </div>

                      </div>
                      <!--begin:: Widgets/Stats2-3 -->
                    </div>
                  <?php } ?>
                </div>
              </div>
            </div>
          <?php } ?>

          <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">
                <?php if($this->session->userdata('user_role')=='admin'){?>
                  <div class="col-md-12 col-lg-12 col-xl-6">
                    <!--begin:: Widgets/Stats2-3 -->
                    <div class="m-widget1">
                      <div class="m-widget1__item">
                        <div class="row m-row--no-padding align-items-center">
                          <div class="col">
                            <h3 class="m-widget1__title">
                              Actual Profit
                            </h3>
                          </div>
                          <div class="col m--align-right">
                            <span class="m-widget1__number m--font-success">
                              <label class="total_profit_info"></label>
                            </span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!--begin:: Widgets/Stats2-3 -->
                  </div>
                  <div class="col-md-12 col-lg-12 col-xl-6">
                    <!--begin:: Widgets/Stats2-3 -->
                    <div class="m-widget1">
                      <div class="m-widget1__item">
                        <div class="row m-row--no-padding align-items-center">
                          <div class="col">
                            <h3 class="m-widget1__title">
                              Balance to Receive
                            </h3>
                          </div>
                          <div class="col m--align-right">
                            <span class="m-widget1__number m--font-danger">
                              <label class="total_balance_info"></label>
                            </span>
                          </div>
                        </div>
                      </div>
                    </div>
                    <!--begin:: Widgets/Stats2-3 -->
                  </div>
                <?php } ?>
              </div>
            </div>
          </div>
          <?php if($this->session->userdata('user_role')!='boq_manager'){?>
            <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">
                  Project Summary
                </h3>
                <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="table_summary">
                  <thead>
                    <tr class="">
                      <th>Heads</th>
                      <th>Amount</th>
                    </tr>
                  </thead>
                  <tbody>

                    <?php if($this->session->userdata('user_role')=='admin'){?>
                      <tr>
                        <td>Stage Budget Estimated</td>
                        <strong><td class="total_stage_budget_info"></td></strong>
                      </tr>
                    <?php } ?>
                    <?php if($this->session->userdata('user_role')!='supervisor'){?>
                      <tr>
                        <td></td>
                        <td></td>
                      </tr>
                      <?php if($this->session->userdata('user_role')!='purchase_manager' && $this->session->userdata('user_role')!='boq_manager'){?>
                        <tr>
                          <td>Client Payment Received</td>
                          <strong><td class="total_received_from_client_info"></td></strong>
                        </tr>
                      <?php } ?>
                      <tr>
                        <td>Total Purchase Bill Commissions Received</td>
                        <strong><td class="purchase_bill_commission_info"></td></strong>
                      </tr>
                      <tr>
                        <td></td>
                        <td></td>
                      </tr>
                    <?php } ?>
                    <tr>
                      <td>Total Purchase Bill Amount</td>
                      <strong><td class="total_purchases_bill_info"></td></strong>
                    </tr>
                    <?php if($this->config->item('app_module_purchase_order')==1){?>
                      <tr>
                        <td>Purchase Order Payments Made (Advances)</td>
                        <strong><td class="total_purchase_order_payments_info"></td></strong>
                      </tr>
                    <?php } ?>
                    <tr>
                      <td>Purchase Bill Payments Made</td>
                      <strong><td class="total_purchases_bill_payment_info"></td></strong>
                    </tr>
                    <?php if($this->config->item('app_module_purchase_order')==1){?>
                      <tr>
                        <td>Total Purchase Payments Made (Purchase Bill + Purchase Order)</td>
                        <strong><td class="total_purchase_payment_info"></td></strong>
                      </tr>
                    <?php } ?>
                    <tr>
                      <td>Pending Purchase Bill Payments</td>
                      <strong><td class="total_purchases_bill_pending_info"></td></strong>
                    </tr>
                    <tr>
                      <td></td>
                      <td></td>
                    </tr>
                    <?php if($this->config->item('app_module_stock_management')==1){?>
                      <tr>
                        <td>Total Stock Purchased Amount</td>
                        <strong><td class="total_purchases_bill_info"></td></strong>
                      </tr>
                      <tr>
                        <td>Total Stock Transfer In Amount</td>
                        <strong><td class="total_stock_transfer_in_info"></td></strong>
                      </tr>
                      <tr>
                        <td>Total Stock Transfer Out Amount</td>
                        <strong><td class="total_stock_transfer_out_info"></td></strong>
                      </tr>
                      <tr>
                        <td>Total Stock Consumed Amount</td>
                        <strong><td class="total_stock_consumed_info"></td></strong>
                      </tr>
                      <tr>
                        <td>Total Stock Balance Amount</td>
                        <strong><td class="total_stock_balance_info"></td></strong>
                      </tr>
                      <tr>
                        <td></td>
                        <td></td>
                      </tr>
                    <?php } ?>
                    <?php if($this->session->userdata('user_role')!='purchase_manager'){?>
                      <tr>
                        <td>Total Subcontract Payments</td>
                        <strong><td class="total_subcontract_payment_info"></td></strong>
                      </tr>
                    <?php } ?>
                    <?php if($this->session->userdata('user_role')!='purchase_manager'){?>
                      <tr>
                        <td>Total Labour Wages</td>
                        <strong><td class="total_labour_wages_info"></td></strong>
                      </tr>
                    <?php } ?>
                    <?php if($this->session->userdata('user_role')!='purchase_manager'){?>
                      <tr>
                        <td>Total Salary Payments</td>
                        <strong><td class="total_salary_payment_info"></td></strong>
                      </tr>
                    <?php } ?>
                    <?php if($this->session->userdata('user_role')!='purchase_manager'){?>
                      <tr>
                        <td>Total Other Expense Payments</td>
                        <strong><td class="total_other_expense_payments_info"></td></strong>
                      </tr>
                    <?php }?>
                    <?php if($this->session->userdata('user_role')!='purchase_manager'){?>
                      <?php if($this->config->item('User_project_commission_payment')==1){ ?>
                        <tr>
                          <td>Total User Commission Payments</td>
                          <strong><td class="total_user_commission_payment_info"></td></strong>
                        </tr>
                      <?php } ?>
                    <?php } ?>
                    <tr>
                      <td></td>
                      <td></td>
                    </tr>
                    <?php if($this->session->userdata('user_role')!='purchase_manager'){?>
                      <tr>
                        <td>Total Expense Payments</td>
                        <strong><td class="total_expense_payments_info"></td></strong>
                      </tr>
                    <?php } ?>
                    <?php if($this->session->userdata('user_role')=='admin'){?>
                      <?php if($work_data->work_type==1){ ?>
                        <tr>
                          <td>Total Project Management Commission</td>
                          <strong><td class="total_commission_info"></td></strong>
                        </tr>
                      <?php } ?>
                      <tr>
                        <td>Total Amount to Receive From Client</td>
                        <strong><td class="total_amount_to_receive_info"></td></strong>
                      </tr>
                      <tr>
                        <td>Actual Received</td>
                        <strong><td class="total_received_from_client_info"></td></strong>
                      </tr>
                      <tr>
                        <td>Balance to Receive</td>
                        <strong><td class="total_balance_info"></td></strong>
                      </tr>
                      <tr>
                        <td>Total Project Profit (Actual Received - Actual Expense)</td>
                        <strong><td class="total_profit_info"></td></strong>
                      </tr>
                    <?php } ?>
                  </tbody>
                </table>
              </div>
            </div>
          <?php } ?>
        </div>

        <div id="div_info" class="profile_nav_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">
                    Stage Info
                  </h3>
                </div>
              </div>
            </div>
            <div class="m-portlet__body">
              <form autocomplete="off" class="m-form m-form--fit m-form--label-align-right">
                <div class="m-portlet__body">
                  <div class="form-group m-form__group row">
                    <div class="col-9 ml-auto">
                      <h4 class="m-form__section">
                        Stage Status
                      </h4>
                    </div>
                  </div>
                  <div class="form-group m-form__group row">
                    <label class="col-xl-3 col-lg-3 col-form-label">
                      Stage Status
                    </label>
                    <div class="col-xl-7 col-lg-7" style="padding-top: 5px">
                      <?php if($stage_data->stage_status==1){ ?>
                        <span class='m-badge m-badge--success m-badge--wide'><i class="fa fa-check"></i> Completed <?= $completed_date ?></span>
                      <?php }else{ ?>
                        <span class='m-badge m-badge--info m-badge--wide'><i class="fa fa-ellipsis-h"></i>In Progress</span>
                      <?php } ?>
                    </div>
                  </div>

                  <div class="form-group m-form__group row">
                    <div class="col-9 ml-auto">
                      <h4 class="m-form__section">
                        1. Satge Details
                      </h4>
                    </div>
                  </div>
                  <div class="form-group m-form__group row">
                    <label class="col-xl-3 col-lg-3 col-form-label">
                      Stage Name
                    </label>
                    <div class="col-xl-7 col-lg-7">
                      <div class="input-group m-input-group--air">
                        <div class="input-group-prepend">
                          <span class="input-group-text">
                            <i class="fa fa-briefcase "></i>
                          </span>
                        </div>
                        <input disabled type="text" name="name" class="form-control m-input m-input--solid" value="<?php echo $stage_data->stage_name?>">
                      </div>
                    </div>
                  </div>

                  <div class="form-group m-form__group row">
                    <label class="col-xl-3 col-lg-3 col-form-label">
                      Created Date
                    </label>
                    <div class="col-xl-7 col-lg-7">
                      <div class="input-group m-input-group--air">
                        <div class="input-group-prepend">
                          <span class="input-group-text">
                            <i class="la la-tag"></i>
                          </span>
                        </div>
                        <input disabled type="text" name="pob" class="form-control m-input m-input--solid"  value="<?php echo date('d-m-Y',strtotime($stage_data->created_date))?>">
                      </div>
                    </div>
                  </div>
                  <?php if($this->session->userdata('user_role')=='admin'){?>
                    <div class="form-group m-form__group row">
                      <label class="col-xl-3 col-lg-3 col-form-label">
                        Stage Budget Amount
                      </label>
                      <div class="col-xl-7 col-lg-7">
                        <div class="m-input-icon m-input-icon--left">
                          <input required type="text" value="<?php echo $this->config->item('currency_format')->formatCurrency($stage_data->stage_budget,$this->config->item('Currency_currency_shortname'))?>" name="budget_amt" type="text" placeholder="Budget Amount" class="form-control  m-input m-input--air" >
                          <span class="m-input-icon__icon m-input-icon__icon--left">
                            <span>
                              <?php echo $this->config->item('Currency_currency_format'); ?>
                            </span>
                          </span>
                        </div>
                      </div>
                    </div>
                  <?php } ?>
                  <div class="form-group m-form__group row">
                    <label class="col-xl-3 col-lg-3 col-form-label">
                      Date of Completion
                    </label>
                    <div class="col-xl-7 col-lg-7">
                      <div class="input-group m-input-group--air date">
                        <div class="input-group-prepend">
                          <span class="input-group-text">
                            <i class="la la-calendar"></i>
                          </span>
                        </div>
                        <input disabled type="text" name="doj" class="form-control m-input m-input--solid"   value="<?php if($stage_data->stage_end_date!='0000-00-00'){ echo date('d-m-Y',strtotime($work_data->planned_date_of_completion));} ?>">
                      </div>
                    </div>
                  </div>
                  <div class="form-group m-form__group row">
                    <label class="col-xl-3 col-lg-3 col-form-label">
                      Stage Description
                    </label>
                    <div class="col-xl-7 col-lg-7">
                      <textarea disabled class="form-control m-input m-input--air" id="work_description" name="work_description" rows="3"><?php echo $stage_data->stage_description?></textarea>
                    </div>
                  </div>


                </div>

              </form>
            </div>
          </div>
        </div>

        <!-- Include All Profile DIvs -->
        <?php $this->view("includes/Inc_stage_profile_div");?>

      </div>
    </div>
  </div>

  <div class="modal fade" tabindex="-1" id="work_stage_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog " role="document" style="max-width: 350px">
      <div class="modal-content" >
        <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
          <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
            Update Work Stage
          </h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">
              &times;
            </span>
          </button>
        </div>
        <form data-form-type="project_status" data-modal-id="work_stage_edit_modal" autocomplete="off" id="work_stage_edit_modal_form" method="post" action="<?php echo base_url().'work/update_work_stage'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
          <div class="modal-body">
            <div class="m-form__content">
              <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_material_add_msg">
                <div class="m-alert__icon">
                  <i class="la la-warning"></i>
                </div>
                <div class="m-alert__text">
                  Oh snap! Change a few things up and try submitting again.
                </div>
                <div class="m-alert__close">
                  <button type="button" class="close" data-close="alert" aria-label="Close"></button>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-lg-12">
                <div class="form-group m-form__group" >
                  <label for="user_name">
                    Stages
                  </label>
                  <div class="m-select2 m-select2--air m-select2--pill">
                    <select  style="width: 100%" class="form-control m-select2  work_stage_edit_modal_form_select" id="project_stages" name="project_stage"  >
                      <option selected disabled>Select Stage</option>
                      <?php
                      foreach($stages as $row):
                        $selected = "";
                        if($row->stage_id==$stage_data->stage_id){
                          $selected = "selected";
                        }
                        ?>
                        <option <?= $selected ?> value="<?php echo $row->stage_id?>"><?php echo $row->stage_name." [ No - ".$row->stage_no." ]"?></option>
                        <?php
                      endforeach;
                      ?>
                    </select>
                  </div>
                  <span class="m-form__help"></span>
                </div>
              </div>
            </div>

            <input type="hidden"  name="work_id" value="<?php echo $work_data->work_id?>">

          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">
              Close
            </button>
            <button type="submit" class="btn btn-primary form_submit_btn">
              Submit
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>


  <div class="modal fade" tabindex="-1" id="stage_status_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog " role="document" style="max-width: 800px">
      <div class="modal-content" >
        <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
          <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
            Edit Stage Status
          </h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">
              &times;
            </span>
          </button>
        </div>
        <form data-form-type="project_status" data-modal-id="stage_status_edit_modal" autocomplete="off" id="edit_stage_status_form" method="post" action="<?php echo base_url().'work/update_stage_status'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
          <div class="modal-body">
            <div class="m-form__content">
              <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_material_add_msg">
                <div class="m-alert__icon">
                  <i class="la la-warning"></i>
                </div>
                <div class="m-alert__text">
                  Oh snap! Change a few things up and try submitting again.
                </div>
                <div class="m-alert__close">
                  <button type="button" class="close" data-close="alert" aria-label="Close"></button>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-lg-7">
                <div class="m-radio-inline" style="margin-top: 10px;">
                  <label class="m-radio m-radio m-radio--solid m-radio--state-brand">
                    <input type="radio" name="stage_status"  value="2">
                    In Progress
                    <span></span>
                  </label>
                  <label class="m-radio m-radio m-radio--solid m-radio--state-success">
                    <input type="radio" name="stage_status"  value="1">
                    Completed
                    <span></span>
                  </label>
                </div>
              </div>

              <input type="hidden" name="stage_id" value="<?php echo $stage_data->stage_id?>">
              <input type="hidden" name="stages_status1" id="stage_status1">
              <input type="hidden" name="redirect_url" value="<?php echo base_url(uri_string())?>" >

              <br/>
              <div class="row">
                <?php if($this->config->item('User_project_commission_payment')==1){ ?>
                  <div id="user_commission_payment_div" style="background: white;border: 4px solid #f7f7fa;padding: 10px;margin: 20px;padding-bottom: 0px;display:none">
                    <div class="m-section" style="margin: 0px 0 10px 0;">
                      <h3 class="m-section__heading" style="margin: 0px;margin-bottom: 10px">Project Commission Details</h3>
                      <div class="col-lg-12">
                        <div class="form-group m-form__group" >
                          <label for="user_name">
                            <span class="subtask_t"></span>Total Project Budget
                          </label>
                          <div class="m-input-icon m-input-icon--right">
                            <input value="<?php echo $work_data->est_budget_amt ?>" readonly type="text"  class="form-control m-input m-input--pill m-input--air"  aria-describedby="basic-addon1" name="project_bydget">
                            <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-12">
                        <table class="table table-bordered m-table m-table--border-success">
                          <thead>
                            <tr>
                              <th>User</th>
                              <th>Commission %</th>
                              <th>Commission Amount</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php
                            $total_commission_amount = 0;
                            foreach ($assigned_users as $key => $value) {
                              $user_commission_amount = $work_data->est_budget_amt*$value->project_commission_percent/100;
                              $total_commission_amount+=$user_commission_amount;
                              ?>
                              <tr>
                                <td><?php echo $value->user_alias ?></td>
                                <td><?php echo $value->project_commission_percent ?></td>
                                <td><?php echo  $user_commission_amount; ?></td>
                              </tr>
                            <?php } ?>
                          </tbody>
                        </table>
                      </div>
                    </div>
                  </div>
                <?php } ?>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">
              Close
            </button>
            <button type="submit" class="btn btn-primary form_submit_btn">
              Submit
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
  <div class="modal fade" tabindex="-1" id="user_commission_payment_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog " role="document" style="max-width: 800px">
      <div class="modal-content" >
        <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
          <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
            Add Payment Towards User Project Commission
          </h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">
              &times;
            </span>
          </button>
        </div>
        <form data-form-type="user_commission_payment" data-modal-id="user_commission_payment_add_modal" autocomplete="off" id="user_commission_payment_add_form" method="post" action="<?php echo base_url().'accounts/create_transaction'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
          <div class="modal-body">
            <div class="m-form__content">
              <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_material_add_msg">
                <div class="m-alert__icon">
                  <i class="la la-warning"></i>
                </div>
                <div class="m-alert__text">
                  Oh snap! Change a few things up and try submitting again.
                </div>
                <div class="m-alert__close">
                  <button type="button" class="close" data-close="alert" aria-label="Close"></button>
                </div>
              </div>
              <div class="row">
                <div class="col-lg-12">
                  <div class="row" style="padding-top: 15px" >
                    <div class="col-lg-4" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Paid Amount
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input  type="text" name="paid_amount" id="paid_amount_add_commission" value="" class="form-control form_commission_req_fields m-input m-input--pill m-input--air form_commission_add_fields" placeholder="Paid Amount" 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>
                        <span class="m-form__help"></span>
                      </div>
                    </div>
                    <div class="col-lg-4">
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Paid Date
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input  data-date-format="dd-mm-yyyy" id="paid_date_add_commission"  type="text" name="paid_date" class="form_commission_add_fields form_commission_req_fields form-control m-input m-input--pill m-input--air " placeholder="Transaction Date" >
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-calendar"></i></span></span>
                        </div>
                        <span class="m-form__help"></span>
                      </div>
                    </div>
                    <div class="col-lg-4">
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Paid From Acc
                        </label>
                        <div class="m-select2 m-select2--air m-select2--pill">
                          <select  id="debit_acc_add_commission" name="debit_acc" style="width: 100%" class="form-control m-input form_commission_add_select form_commission_req_fields"  aria-describedby="basic-addon1">
                            <?php
                            foreach($this->config->item('account_heads') as $row):
                              $selected="";
                              if($row->acc_head_id==1){
                                $selected="selected";
                              }
                              ?>
                              <option <?php echo $selected?> value="<?php echo $row->acc_head_id?>"><?php echo $row->acc_head_name?></option>
                              <?php
                            endforeach;
                            ?>
                          </select>
                        </div>
                        <span class="m-form__help"></span>
                      </div>
                    </div>
                  </div>
                  <div class="row" >
                    <div class="col-lg-4">
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Payment Mode
                        </label>
                        <div class="m-select2 m-select2--air m-select2--pill">
                          <select  id="payment_mode_add_commission" name="payment_mode" style="width: 100%" class="form_commission_req_fields form-control m-input form_commission_add_select paid_amount_req_fields"  aria-describedby="basic-addon1">
                            <option selected disabled>Select Payment Mode</option>
                            <?php
                            foreach($this->config->item('payment_modes') as $row):
                              ?>
                              <option value="<?php echo $row?>"><?php echo $row?></option>
                              <?php
                            endforeach;
                            ?>
                          </select>
                        </div>
                        <span class="m-form__help"></span>
                      </div>
                    </div>
                    <div class="col-lg-4" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          TR Reference No
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" name="reference_no"  class="form-control m-input m-input--pill m-input--air form_commission_add_fields" placeholder="Reference No" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                        </div>
                        <span class="m-form__help"></span>
                      </div>
                    </div>
                    <div class="col-lg-4">
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          TR Reference Date
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" data-date-format="dd-mm-yyyy" name="reference_date" id="reference_date_add_commission"  class="form-control m-input m-input--pill m-input--air form_commission_add_fields" placeholder="Reference Date" 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>
                        <span class="m-form__help"></span>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-lg-8" >
                      <div class="form-group m-form__group" >
                        <label for="user_name">
                          Transaction Remarks
                        </label>
                        <div class="m-input-icon m-input-icon--right">
                          <input type="text" name="tr_remarks" class="form-control m-input m-input--pill m-input--air form_commission_add_fields" placeholder="Transaction Remarks" aria-describedby="basic-addon1">
                          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                        </div>
                        <span class="m-form__help"></span>
                      </div>
                    </div>
                    <input type="hidden" name="tr_type" value="user_commission_transaction">
                    <input type="hidden" name="reference_id" id="reference_id_add_commission">
                    <input type="hidden" name="reference_type" value="user_account_head" >
                  </div>
                </div>
              </div>
            </div>
            <input type="hidden"  name="work_id" value="<?php echo $work_data->work_id?>">
            <input type="hidden" name="redirect_url" value="<?php echo base_url(uri_string())?>" >
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">
              Close
            </button>
            <button type="submit" class="btn btn-primary form_submit_btn">
              Submit
            </button>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<?php $this->view("modules/include_modals/modal_labour_assign");?>

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

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

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

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

<?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 base_url()?>template/assets/app/js/dashboard.js" type="text/javascript"></script>
<!--end::Page Snippets -->

<script>
//    Toggle Sidebar
$("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
$("#body").addClass("m-brand--minimize m-aside-left--minimize");

$("#works_menu").addClass('m-menu__item--active m-menu__item--open');
$("#works_menu_2").addClass('m-menu__item--active');
</script>
<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();
<?php if($this->session->userdata('user_role')!='boq_manager'){ ?>
  //  Active First Menu and Its div
  active('overview');
<?php }else{ ?>
  active('info');
<?php } ?>

$('body').on('click', '.profile_nav', function() {
  var nav = $(this).attr('data-nav');
  active(nav);
})
</script>
<script>
  $('#print_summary').click(function(e){
    var work =  "<?php echo $work_data->work_id?>";
    var stage_id =  "<?php echo $stage_data->stage_id?>";
    window.open('<?php echo base_url().'work/print_stage_summary/'?>'+work+'/'+stage_id,'newwindow','width=1200,height=700');
    return false
  });
  function select_work_type(select_id){
    $('#'+select_id).html('');
    $("#"+select_id).append("<option disabled selected >Select Work Type</option>");
    $.post("<?php echo base_url() ?>work_types/select",{},function(data) {
      var obj = $.parseJSON(data);
      var i=0;
      if(obj.count>0) {
        while (i < obj.id.length) {
          $("#"+select_id).append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
          i++;
        }
      }
    })
  }
  function select_expense_type(select_id){
    $('#'+select_id).html('');
    $("#"+select_id).append("<option disabled selected >Select Expense Head</option>");
    $.post("<?php echo base_url() ?>accounts/select_heads_2",{account_type:11},function(data) {
      var obj = $.parseJSON(data);
      var i=0;
      if(obj.count>0) {
        while (i < obj.id.length) {
          $("#"+select_id).append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
          i++;
        }
      }
    })
  }

  var work_commission = "<?php echo $work_data->work_type ?>"
  if (work_commission == 1) {
    $("#poject_management_commission_amount").show();
  } else {
    $("#poject_management_commission_amount").hide();
  }
    //For Plan hide
    var work_commission = "<?php echo $work_data->work_type ?>"
    // if (work_commission == 3) {
    //     $("#purchase_tab").hide();
    //     $("#subcontract_tab").hide();
    //     $("#types_of_expenses").hide();
    // } else {
    //     $("#purchase_tab").show();
    //     $("#subcontract_tab").show();
    //     $("#types_of_expenses").show();
    // }


    $("#work_completed_date,#paid_date_add_commission,#reference_date_add_commission,#stage_start_date,#stage_end_date,#stage_start_date_edit,#stage_end_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>'
      }
    });



    var stage_status_1 = "<?php echo $stage_data->stage_status?>";

    $('input[name=stage_status][value=' + stage_status_1 + ']').prop('checked',true)

    $('body').on('click', '.btn_add_types', function(e) {
      e.preventDefault();
      var modal_id = $(this).closest('.modal').attr('id');
      $("#"+modal_id).modal('toggle');
    })
  </script>

  <!-- Bill Scripts -->
  <?php $this->view("modules/include_scripts/bill_scripts");?>
  <?php $this->view("modules/include_scripts/invoices_scripts");?>
  <?php // $this->view("modules/include_scripts/invoices_payments_scripts");?>

  <!-- Transaction Scripts -->
  <?php $this->view("modules/include_scripts/transaction_scripts");?>

  <!-- Include All Profile Scripts -->
  <?php $this->view("includes/Inc_stage_profile_scripts");?>

  <?php // $this->view("modules/include_scripts/labour_assign_scripts");?>
  <?php $this->view("modules/include_scripts/stock_consumption_scripts");?>

  <?php $this->view("modules/include_scripts/project_stages_scripts");?>

  <script>
    $("#user_assign").select2({
      placeholder: "Select Supervisor",
      dropdownParent: $("#form_user_assign")
    })

    $('#project_stages').select2({
      placeholder: "Select Stage",
      dropdownParent: $("#work_stage_edit_modal_form")
    })

    $("#debit_acc_add_commission").select2({
      placeholder: "Select Debit Account",
      dropdownParent: $("#user_commission_payment_add_form")
    })

    $("#payment_mode_add_commission").select2({
      placeholder: "Select Payment Mode",
      dropdownParent: $("#user_commission_payment_add_form")
    })

    $('body').on('click', '#btn_delete_user_assign', function() {
      var no = $(this).closest('tr').children('td');
      $('#assign_log_id').val(no.eq(1).text());
    })
    $('body').on('click', '#btn_add_user_commission_payment', function() {
      var no = $(this).closest('tr').children('td');
      $('#reference_id_add_commission').val(no.eq(8).text());
      $('#paid_amount_add_commission').val(no.eq(7).text());
    })
    select_summary();
    function select_summary(){
      var stage_id = "<?php echo $stage_data->stage_id?>";
      var work_id = "<?php echo $stage_data->project_id?>";

      $.post("<?php echo base_url().'work/select_stage_summary/count' ?>",{
        stage_id:stage_id,work_id:work_id
      },function(data){
        var obj= $.parseJSON(data);

        $(".total_stage_budget_info").html(obj.total_stage_budget);
        $(".total_received_from_client_info").html(obj.total_client_payments_received);
        $(".purchase_bill_commission_info").html(obj.total_purchase_bill_commission);
        $(".total_purchases_bill_info").html(obj.total_purchase_bill_amount);
        $(".total_purchase_order_payments_info").html(obj.total_purchase_order_payment);
        $(".total_purchases_bill_payment_info").html(obj.total_purchase_bill_payment);
        $(".total_purchase_payment_info").html(obj.total_purchase_payment);
        $(".total_purchases_bill_pending_info").html(obj.total_purchase_bill_balance_amount);
        $(".total_subcontract_payment_info").html(obj.total_subcontract_payment);
        $(".total_labour_wages_info").html(obj.total_labour_wages);
        $(".total_salary_payment_info").html(obj.total_salary_payments);
        $(".total_vehicle_payments_info").html(obj.total_vehicle_payments);
        $(".total_other_expense_payments_info").html(obj.total_other_expense);
        $(".total_user_commission_payment_info").html(obj.total_user_commission_payments);
        $(".total_expense_payments_info").html(obj.total_expense_amount);
        $(".total_commission_info").html(obj.total_project_commission_amount);
        $(".total_amount_to_receive_info").html(obj.total_amount_to_receive);
        $(".total_balance_info").html(obj.balance_to_receive);
        $(".total_profit_info").html(obj.total_profit);

        $(".total_labours_worked_info").html(obj.total_labours_worked);
        $(".total_labours_days_info").html(obj.total_labour_days);
        $(".total_labours_wage_info").html(obj.total_labour_wages);

        $(".total_stock_transfer_in_info").html(obj.total_stock_transfer_in_amount);
        $(".total_stock_transfer_out_info").html(obj.total_stock_transfer_out_amount);
        $(".total_stock_consumed_info").html(obj.total_stock_consumption_amount);
        $(".total_stock_balance_info").html(obj.total_stock_balance_amount);

      })
    }

  </script>

  <script>
    var client_id = "<?php echo $work_data->client_id?>";
    var work_id = "<?php echo $work_data->work_id?>";

    var user_assign_view_table = $('#user_assign_view_table').DataTable({
      "ajax":{
      url :"<?php echo base_url().'work/select_assigned_users' ?>", // json datasource
      type: "post", // type of method  , by default would be get
      data: function(d){
        d.work_id = work_id;
      }
    },
    "bProcessing": true,
    "deferRender": true,
    "bDeferRender": true,
    "scrollX" : true,
    buttons: [
    { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Assigned Users' },
    { 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>>",
    "lengthMenu": [
    [25, 50, 100, -1],
      [25, 50, 100, "All"] // change per page values here
      ],
      "columnDefs": [
      {
        "targets": [ 1,8<?php if($this->config->item('User_project_commission_payment')==0){ echo ",4";}?> ],
        className: "hidden"
      }
      ],
      'order': false
    });

    var labour_assign_view_table = $('#labour_assign_view_table').DataTable({
      "ajax":{
      url :"<?php echo base_url().'labours/select_labour' ?>", // json datasource
      type: "post", // type of method  , by default would be get
      data: function(d){
        // d.labour_type = 1;
        d.work_id = "<?php echo $work_data->work_id?>";
      }
    },
    "bProcessing": true,
    "deferRender": true,
    "bDeferRender": true,
    "scrollX" : true,
    buttons: [
    { extend: 'print', className: 'btn dark btn-outline',title: 'Assigned Labours' },
    { 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
      ],
      "columnDefs": [
      {
        "targets": [ 1,7,8,9,10,11,12,13,14,15,16,17,18],
        className: "hidden"
      }
      ],
      'order': false
    });

    <?php if($this->config->item('User_project_commission_payment')==1){ ?>
      var user_commission_payment_view_table = $('#user_commission_payment_view_table').DataTable({
        "ajax":{
        url :"<?php echo base_url().'accounts/select_account_transactions/user_commission' ?>", // json datasource
        type: "post", // type of method  , by default would be get
        data: function(d){
          d.work_id = work_id;
        }
      },
      "bProcessing": true,
      "deferRender": true,
      "bDeferRender": true,
      "scrollX" : true,
      buttons: [
      { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'User Commission Payments' },
      { 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>>",
      "lengthMenu": [
      [25, 50, 100, -1],
        [25, 50, 100, "All"] // change per page values here
        ],
        "columnDefs": [
        {
          "targets": [3,5,6,7,8,9,18,19],
          className: "hidden"
        }
        ],
        'order': false
      });
    <?php } ?>

    $(".hide_column").hide();
    $('.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
          },
          received_amount: {
            number: !0,
            required: !0
          },
          commission_percent:{
            number: !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");
            if(form_type=="expense_head"){
              select_expense_head("expense_head_add");
              select_expense_head("expense_head_edit");
            }else if(form_type=='client_payment'){
              client_payments_view_table.ajax.reload();
              invoice_payments_view_table.ajax.reload();
              invoices_view_table.ajax.reload();
            }else if(form_type=='expense_bill'){
              expense_bills_view_table.ajax.reload();
            }else if(form_type=='labour_wage'){
              $("."+form_id+"_fields_1").val(0);
              $("."+form_id+"_fields_2").val(1);
              labour_wage_view_table.ajax.reload();
              $('#labour_wage_work_date_add,#labour_wage_work_date_edit,#paid_date_add').datepicker("setDate", "<?php echo date('d-m-Y')?>");
            }else if(form_type=='user_assign'){
              user_assign_view_table.ajax.reload();
              location.reload();
            }else if(form_type=='labour_assign'){
              labour_assign_view_table.ajax.reload();
            }else if(form_type=='user_commission_payment'){
              user_commission_payment_view_table.ajax.reload();
              user_assign_view_table.ajax.reload();
            }else if(form_type=='consumption'){
              stock_list_table("<?php echo $work_data->work_id?>","<?php echo $work_data->work_name?>");
              stock_consumption_view_table.ajax.reload();
            }else if(form_type=='project_task'){
              initialise_gantt();
              project_tasks_view_table.ajax.reload();
              var task_id2 = $("#parent_task_id").val();
              get_subtask(task_id2);
            }else if(form_type=='project_task_activity'){
              var task_id2 = $("#data-task-id").val();
              get_activities(task_id2);
              initialise_gantt();
              project_tasks_view_table.ajax.reload();
            }else if(form_type=='boq'){
              boq_view_table.ajax.reload();
              if(form_id=='form_boq_add'){
                swal({
                  width: 500,
                  title: obj.flashdata_title,
                  text: obj.flashdata_msg,
                  type: obj.flashdata_type,
                  showCancelButton: !0,
                  confirmButtonText: "Go to BOQ Details",
                  cancelButtonText: "Close",
                  confirmButtonColor: '#3085d6',
                  cancelButtonColor: '#d33',
                  reverseButtons: !0,
                  closeOnClickOutside: false,
                  allowOutsideClick: false
                }).then(function(e) {
                  e.value ? window.location.replace("<?php echo base_url()?>boq/profile/" + obj.boq_id) : "cancel" === e.dismiss ;
                })
              }
            }else if(form_type=='subcontract'){
              subcontracts_view_table.ajax.reload();
              subcontract_payments_view_table.ajax.reload();
            }else if(form_type=='project_status'){
              location.reload();
            }else if(form_type=='project_stage'){
              project_stages_view_table.ajax.reload();
            }else{
              subcontracts_view_table.ajax.reload();
              subcontract_payments_view_table.ajax.reload();
              expense_bills_view_table.ajax.reload();
              client_payments_view_table.ajax.reload();
              purchase_bills_view_table.ajax.reload();
              purchase_bill_transaction_view_table.ajax.reload();
              purchase_request_view_table.ajax.reload();
              purchase_order_view_table.ajax.reload();
              purchase_order_transaction_view_table.ajax.reload();
              salary_slip_view_table.ajax.reload();
              salary_slip_transaction_view_table.ajax.reload();
              invoice_payments_view_table.ajax.reload();
              invoices_view_table.ajax.reload();

            }
            select_summary();
          } 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>
