<?php 
//check if current user role is allowed access to the pages
$can_add = ACL::is_allowed("salary_data/add");
$can_edit = ACL::is_allowed("salary_data/edit");
$can_view = ACL::is_allowed("salary_data/view");
$can_delete = ACL::is_allowed("salary_data/delete");
?>
<?php
$comp_model = new SharedController;
$page_element_id = "list-page-" . random_str();
$current_page = $this->set_current_page_link();
$csrf_token = Csrf::$token;
//Page Data From Controller
$view_data = $this->view_data;
$records = $view_data->records;
$record_count = $view_data->record_count;
$total_records = $view_data->total_records;
$field_name = $this->route->field_name;
$field_value = $this->route->field_value;
$view_title = $this->view_title;
$show_header = $this->show_header;
$show_footer = $this->show_footer;
$show_pagination = $this->show_pagination;
?>
<section class="page" id="<?php echo $page_element_id; ?>" data-page-type="list"  data-display-type="table" data-page-url="<?php print_link($current_page); ?>">
    <?php
    if( $show_header == true ){
    ?>
    <div  class="bg-light p-3 mb-3">
        <div class="container-fluid">
            <div class="row ">
                <div class="col ">
                    <h4 class="record-title">Salary Data</h4>
                </div>
                <div class="col-sm-3 ">
                </div>
                <div class="col-sm-4 ">
                    <form  class="search" action="<?php print_link('salary_data'); ?>" method="get">
                        <div class="input-group">
                            <input value="<?php echo get_value('search'); ?>" class="form-control" type="text" name="search"  placeholder="Search" />
                                <div class="input-group-append">
                                    <button class="btn btn-primary"><i class="fa fa-search"></i></button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="col-md-12 comp-grid">
                        <div class="">
                            <!-- Page bread crumbs components-->
                            <?php
                            if(!empty($field_name) || !empty($_GET['search'])){
                            ?>
                            <hr class="sm d-block d-sm-none" />
                            <nav class="page-header-breadcrumbs mt-2" aria-label="breadcrumb">
                                <ul class="breadcrumb m-0 p-1">
                                    <?php
                                    if(!empty($field_name)){
                                    ?>
                                    <li class="breadcrumb-item">
                                        <a class="text-decoration-none" href="<?php print_link('salary_data'); ?>">
                                            <i class="fa fa-angle-left"></i>
                                        </a>
                                    </li>
                                    <li class="breadcrumb-item">
                                        <?php echo (get_value("tag") ? get_value("tag")  :  make_readable($field_name)); ?>
                                    </li>
                                    <li  class="breadcrumb-item active text-capitalize font-weight-bold">
                                        <?php echo (get_value("label") ? get_value("label")  :  make_readable(urldecode($field_value))); ?>
                                    </li>
                                    <?php 
                                    }   
                                    ?>
                                    <?php
                                    if(get_value("search")){
                                    ?>
                                    <li class="breadcrumb-item">
                                        <a class="text-decoration-none" href="<?php print_link('salary_data'); ?>">
                                            <i class="fa fa-angle-left"></i>
                                        </a>
                                    </li>
                                    <li class="breadcrumb-item text-capitalize">
                                        Search
                                    </li>
                                    <li  class="breadcrumb-item active text-capitalize font-weight-bold"><?php echo get_value("search"); ?></li>
                                    <?php
                                    }
                                    ?>
                                </ul>
                            </nav>
                            <!--End of Page bread crumbs components-->
                            <?php
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php
        }
        ?>
        <div  class="">
            <div class="container-fluid">
                <div class="row ">
                    <div class="col-md-12 comp-grid">
                        <?php $this :: display_page_errors(); ?>
                        <div  class=" animated fadeIn page-content">
                            <div id="salary_data-userlist-records">
                                <div id="page-report-body" class="table-responsive">
                                    <table class="table  table-striped table-sm text-left">
                                        <thead class="table-header bg-light">
                                            <tr>
                                                <?php if($can_delete){ ?>
                                                <th class="td-checkbox">
                                                    <label class="custom-control custom-checkbox custom-control-inline">
                                                        <input class="toggle-check-all custom-control-input" type="checkbox" />
                                                        <span class="custom-control-label"></span>
                                                    </label>
                                                </th>
                                                <?php } ?>
                                                <th class="td-sno">#</th>
                                                <th  class="td-month_year"> Month Year</th>
                                                <th  class="td-name_of_emp"> Name Of Emp</th>
                                                <th  class="td-absent_days"> Absent Days</th>
                                                <th  class="td-basic_pay"> Basic Pay</th>
                                                <th  class="td-new_basic_after_absent"> New Basic After Absent</th>
                                                <th  class="td-da"> Da</th>
                                                <th  class="td-hra"> Hra</th>
                                                <th  class="td-ta_vahtuk_bhatta"> Ta Vahtuk Bhatta</th>
                                                <th  class="td-washing"> Washing</th>
                                                <th  class="td-incentive_allowance"> Incentive Allowance</th>
                                                <th  class="td-festive_advance"> Festive Advance</th>
                                                <th  class="td-quarter_rent"> Quarter Rent</th>
                                                <th  class="td-petrol_allowance"> Petrol Allowance</th>
                                                <th  class="td-dcps"> Dcps</th>
                                                <th  class="td-epf"> Epf</th>
                                                <th  class="td-allowance_others"> Allowance Others</th>
                                                <th  class="td-pt"> Property Tax</th>
                                                <th  class="td-dcps_14_mc"> Dcps 14 Mc</th>
                                                <th  class="td-dcps_10_own"> Dcps 10 Own</th>
                                                <th  class="td-epf_12_mc"> Epf 12 Mc</th>
                                                <th  class="td-eps_12_own"> Eps 12 Own</th>
                                                <th  class="td-gpf_b_n_n_vargani"> Gpf B N N Vargani</th>
                                                <th  class="td-gpf_b_n_n_hafta"> Gpf B N N Hafta</th>
                                                <th  class="td-lic"> Lic</th>
                                                <th  class="td-mediclaim"> Mediclaim</th>
                                                <th  class="td-accidental_insurance"> Accidental Insurance</th>
                                                <th  class="td-group_insurance"> Group Insurance</th>
                                                <th  class="td-income_tax"> Income Tax</th>
                                                <th  class="td-festival_adv_installment"> Festival Adv Installment</th>
                                                <th  class="td-court_fee"> Court Fee</th>
                                                <th  class="td-soc_1"> Soc 1</th>
                                                <th  class="td-soc_2"> Soc 2</th>
                                                <th  class="td-soc_3"> Soc 3</th>
                                                <th  class="td-bank_1"> Bank 1</th>
                                                <th  class="td-bank_2"> Bank 2</th>
                                                <th  class="td-bank_3"> Bank 3</th>
                                                <th  class="td-deductions_other"> Deductions Other</th>
                                                <th  class="td-gross_salary"> Gross Salary</th>
                                                <th  class="td-total_deductions"> Total Deductions</th>
                                                <th  class="td-net_salary"> Net Salary</th>
                                                <th  class="td-absent_deductions"> Absent Deductions</th>
                                                <th class="td-btn"></th>
                                            </tr>
                                        </thead>
                                        <?php
                                        if(!empty($records)){
                                        ?>
                                        <tbody class="page-data" id="page-data-<?php echo $page_element_id; ?>">
                                            <!--record-->
                                            <?php
                                            $counter = 0;
                                            $sum_of_basic_pay = 0;
                                            $sum_of_new_basic_after_absent = 0;
                                            $sum_of_da = 0;
                                            $sum_of_hra = 0;
                                            $sum_of_washing = 0;
                                            $sum_of_incentive_allowance = 0;
                                            $sum_of_festive_advance = 0;
                                            $sum_of_quarter_rent = 0;
                                            $sum_of_petrol_allowance = 0;
                                            $sum_of_dcps = 0;
                                            $sum_of_epf = 0;
                                            $sum_of_allowance_others = 0;
                                            $sum_of_pt = 0;
                                            $sum_of_dcps_14_mc = 0;
                                            $sum_of_dcps_10_own = 0;
                                            $sum_of_epf_12_mc = 0;
                                            $sum_of_eps_12_own = 0;
                                            $sum_of_gpf_b_n_n_vargani = 0;
                                            $sum_of_gpf_b_n_n_hafta = 0;
                                            $sum_of_lic = 0;
                                            $sum_of_mediclaim = 0;
                                            $sum_of_accidental_insurance = 0;
                                            $sum_of_group_insurance = 0;
                                            $sum_of_income_tax = 0;
                                            $sum_of_festival_adv_installment = 0;
                                            $sum_of_court_fee = 0;
                                            $sum_of_soc_1 = 0;
                                            $sum_of_soc_2 = 0;
                                            $sum_of_soc_3 = 0;
                                            $sum_of_bank_1 = 0;
                                            $sum_of_bank_2 = 0;
                                            $sum_of_bank_3 = 0;
                                            $sum_of_deductions_other = 0;
                                            $sum_of_gross_salary = 0;
                                            $sum_of_total_deductions = 0;
                                            $sum_of_net_salary = 0;
                                            $sum_of_absent_deductions = 0;
                                            foreach($records as $data){
                                            $rec_id = (!empty($data['id']) ? urlencode($data['id']) : null);
                                            $counter++;
                                            $sum_of_basic_pay = $sum_of_basic_pay + $data['basic_pay'];
                                            $sum_of_new_basic_after_absent = $sum_of_new_basic_after_absent + $data['new_basic_after_absent'];
                                            $sum_of_da = $sum_of_da + $data['da'];
                                            $sum_of_hra = $sum_of_hra + $data['hra'];
                                            $sum_of_washing = $sum_of_washing + $data['washing'];
                                            $sum_of_incentive_allowance = $sum_of_incentive_allowance + $data['incentive_allowance'];
                                            $sum_of_festive_advance = $sum_of_festive_advance + $data['festive_advance'];
                                            $sum_of_quarter_rent = $sum_of_quarter_rent + $data['quarter_rent'];
                                            $sum_of_petrol_allowance = $sum_of_petrol_allowance + $data['petrol_allowance'];
                                            $sum_of_dcps = $sum_of_dcps + $data['dcps'];
                                            $sum_of_epf = $sum_of_epf + $data['epf'];
                                            $sum_of_allowance_others = $sum_of_allowance_others + $data['allowance_others'];
                                            $sum_of_pt = $sum_of_pt + $data['pt'];
                                            $sum_of_dcps_14_mc = $sum_of_dcps_14_mc + $data['dcps_14_mc'];
                                            $sum_of_dcps_10_own = $sum_of_dcps_10_own + $data['dcps_10_own'];
                                            $sum_of_epf_12_mc = $sum_of_epf_12_mc + $data['epf_12_mc'];
                                            $sum_of_eps_12_own = $sum_of_eps_12_own + $data['eps_12_own'];
                                            $sum_of_gpf_b_n_n_vargani = $sum_of_gpf_b_n_n_vargani + $data['gpf_b_n_n_vargani'];
                                            $sum_of_gpf_b_n_n_hafta = $sum_of_gpf_b_n_n_hafta + $data['gpf_b_n_n_hafta'];
                                            $sum_of_lic = $sum_of_lic + $data['lic'];
                                            $sum_of_mediclaim = $sum_of_mediclaim + $data['mediclaim'];
                                            $sum_of_accidental_insurance = $sum_of_accidental_insurance + $data['accidental_insurance'];
                                            $sum_of_group_insurance = $sum_of_group_insurance + $data['group_insurance'];
                                            $sum_of_income_tax = $sum_of_income_tax + $data['income_tax'];
                                            $sum_of_festival_adv_installment = $sum_of_festival_adv_installment + $data['festival_adv_installment'];
                                            $sum_of_court_fee = $sum_of_court_fee + $data['court_fee'];
                                            $sum_of_soc_1 = $sum_of_soc_1 + $data['soc_1'];
                                            $sum_of_soc_2 = $sum_of_soc_2 + $data['soc_2'];
                                            $sum_of_soc_3 = $sum_of_soc_3 + $data['soc_3'];
                                            $sum_of_bank_1 = $sum_of_bank_1 + $data['bank_1'];
                                            $sum_of_bank_2 = $sum_of_bank_2 + $data['bank_2'];
                                            $sum_of_bank_3 = $sum_of_bank_3 + $data['bank_3'];
                                            $sum_of_deductions_other = $sum_of_deductions_other + $data['deductions_other'];
                                            $sum_of_gross_salary = $sum_of_gross_salary + $data['gross_salary'];
                                            $sum_of_total_deductions = $sum_of_total_deductions + $data['total_deductions'];
                                            $sum_of_net_salary = $sum_of_net_salary + $data['net_salary'];
                                            $sum_of_absent_deductions = $sum_of_absent_deductions + $data['absent_deductions'];
                                            ?>
                                            <tr>
                                                <?php if($can_delete){ ?>
                                                <th class=" td-checkbox">
                                                    <label class="custom-control custom-checkbox custom-control-inline">
                                                        <input class="optioncheck custom-control-input" name="optioncheck[]" value="<?php echo $data['id'] ?>" type="checkbox" />
                                                            <span class="custom-control-label"></span>
                                                        </label>
                                                    </th>
                                                    <?php } ?>
                                                    <th class="td-sno"><?php echo $counter; ?></th>
                                                    <td class="td-month_year"> <?php echo $data['month_year']; ?></td>
                                                    <td class="td-name_of_emp"> <?php echo $data['name_of_emp']; ?></td>
                                                    <td class="td-absent_days"> <?php echo $data['absent_days']; ?></td>
                                                    <td class="td-basic_pay"> <?php echo $data['basic_pay']; ?></td>
                                                    <td class="td-new_basic_after_absent"> <?php echo $data['new_basic_after_absent']; ?></td>
                                                    <td class="td-da"> <?php echo $data['da']; ?></td>
                                                    <td class="td-hra"> <?php echo $data['hra']; ?></td>
                                                    <td class="td-ta_vahtuk_bhatta"> <?php echo $data['ta_vahtuk_bhatta']; ?></td>
                                                    <td class="td-washing"> <?php echo $data['washing']; ?></td>
                                                    <td class="td-incentive_allowance"> <?php echo $data['incentive_allowance']; ?></td>
                                                    <td class="td-festive_advance"> <?php echo $data['festive_advance']; ?></td>
                                                    <td class="td-quarter_rent"> <?php echo $data['quarter_rent']; ?></td>
                                                    <td class="td-petrol_allowance"> <?php echo $data['petrol_allowance']; ?></td>
                                                    <td class="td-dcps"> <?php echo $data['dcps']; ?></td>
                                                    <td class="td-epf"> <?php echo $data['epf']; ?></td>
                                                    <td class="td-allowance_others"> <?php echo $data['allowance_others']; ?></td>
                                                    <td class="td-pt"> <?php echo $data['pt']; ?></td>
                                                    <td class="td-dcps_14_mc"> <?php echo $data['dcps_14_mc']; ?></td>
                                                    <td class="td-dcps_10_own"> <?php echo $data['dcps_10_own']; ?></td>
                                                    <td class="td-epf_12_mc"> <?php echo $data['epf_12_mc']; ?></td>
                                                    <td class="td-eps_12_own"> <?php echo $data['eps_12_own']; ?></td>
                                                    <td class="td-gpf_b_n_n_vargani"> <?php echo $data['gpf_b_n_n_vargani']; ?></td>
                                                    <td class="td-gpf_b_n_n_hafta"> <?php echo $data['gpf_b_n_n_hafta']; ?></td>
                                                    <td class="td-lic"> <?php echo $data['lic']; ?></td>
                                                    <td class="td-mediclaim"> <?php echo $data['mediclaim']; ?></td>
                                                    <td class="td-accidental_insurance"> <?php echo $data['accidental_insurance']; ?></td>
                                                    <td class="td-group_insurance"> <?php echo $data['group_insurance']; ?></td>
                                                    <td class="td-income_tax"> <?php echo $data['income_tax']; ?></td>
                                                    <td class="td-festival_adv_installment"> <?php echo $data['festival_adv_installment']; ?></td>
                                                    <td class="td-court_fee"> <?php echo $data['court_fee']; ?></td>
                                                    <td class="td-soc_1"> <?php echo $data['soc_1']; ?></td>
                                                    <td class="td-soc_2"> <?php echo $data['soc_2']; ?></td>
                                                    <td class="td-soc_3"> <?php echo $data['soc_3']; ?></td>
                                                    <td class="td-bank_1"> <?php echo $data['bank_1']; ?></td>
                                                    <td class="td-bank_2"> <?php echo $data['bank_2']; ?></td>
                                                    <td class="td-bank_3"> <?php echo $data['bank_3']; ?></td>
                                                    <td class="td-deductions_other"> <?php echo $data['deductions_other']; ?></td>
                                                    <td class="td-gross_salary"> <?php echo $data['gross_salary']; ?></td>
                                                    <td class="td-total_deductions"> <?php echo $data['total_deductions']; ?></td>
                                                    <td class="td-net_salary"> <?php echo $data['net_salary']; ?></td>
                                                    <td class="td-absent_deductions"> <?php echo $data['absent_deductions']; ?></td>
                                                    <th class="td-btn">
                                                        <?php if($can_delete){ ?>
                                                        <a class="btn btn-sm btn-danger has-tooltip record-delete-btn" title="Delete this record" href="<?php print_link("salary_data/delete/$rec_id/?csrf_token=$csrf_token&redirect=$current_page"); ?>" data-prompt-msg="Are you sure you want to delete this record?" data-display-style="modal">
                                                            <i class="fa fa-times"></i>
                                                            Delete
                                                        </a>
                                                        <?php } ?>
                                                    </th>
                                                </tr>
                                                <?php 
                                                }
                                                ?>
                                                <!--endrecord-->
                                            </tbody>
                                            <tbody class="search-data" id="search-data-<?php echo $page_element_id; ?>"></tbody>
                                            <tfoot><tr> <th></th><th></th><th></th><th></th><th><?php echo $sum_of_basic_pay;  ?></th><th><?php echo $sum_of_new_basic_after_absent;  ?></th><th><?php echo $sum_of_da;  ?></th><th><?php echo $sum_of_hra;  ?></th><th></th><th><?php echo $sum_of_washing;  ?></th><th><?php echo $sum_of_incentive_allowance;  ?></th><th><?php echo $sum_of_festive_advance;  ?></th><th><?php echo $sum_of_quarter_rent;  ?></th><th><?php echo $sum_of_petrol_allowance;  ?></th><th><?php echo $sum_of_dcps;  ?></th><th><?php echo $sum_of_epf;  ?></th><th><?php echo $sum_of_allowance_others;  ?></th><th><?php echo $sum_of_pt;  ?></th><th><?php echo $sum_of_dcps_14_mc;  ?></th><th><?php echo $sum_of_dcps_10_own;  ?></th><th><?php echo $sum_of_epf_12_mc;  ?></th><th><?php echo $sum_of_eps_12_own;  ?></th><th><?php echo $sum_of_gpf_b_n_n_vargani;  ?></th><th><?php echo $sum_of_gpf_b_n_n_hafta;  ?></th><th><?php echo $sum_of_lic;  ?></th><th><?php echo $sum_of_mediclaim;  ?></th><th><?php echo $sum_of_accidental_insurance;  ?></th><th><?php echo $sum_of_group_insurance;  ?></th><th><?php echo $sum_of_income_tax;  ?></th><th><?php echo $sum_of_festival_adv_installment;  ?></th><th><?php echo $sum_of_court_fee;  ?></th><th><?php echo $sum_of_soc_1;  ?></th><th><?php echo $sum_of_soc_2;  ?></th><th><?php echo $sum_of_soc_3;  ?></th><th><?php echo $sum_of_bank_1;  ?></th><th><?php echo $sum_of_bank_2;  ?></th><th><?php echo $sum_of_bank_3;  ?></th><th><?php echo $sum_of_deductions_other;  ?></th><th><?php echo $sum_of_gross_salary;  ?></th><th><?php echo $sum_of_total_deductions;  ?></th><th><?php echo $sum_of_net_salary;  ?></th><th><?php echo $sum_of_absent_deductions;  ?></th><th></th></tr></tfoot>
                                            <?php
                                            }
                                            ?>
                                        </table>
                                        <?php 
                                        if(empty($records)){
                                        ?>
                                        <h4 class="bg-light text-center border-top text-muted animated bounce  p-3">
                                            <i class="fa fa-ban"></i> No record found
                                        </h4>
                                        <?php
                                        }
                                        ?>
                                    </div>
                                    <?php
                                    if( $show_footer && !empty($records)){
                                    ?>
                                    <div class=" border-top mt-2">
                                        <div class="row justify-content-center">    
                                            <div class="col-md-auto justify-content-center">    
                                                <div class="p-3 d-flex justify-content-between">    
                                                    <?php if($can_delete){ ?>
                                                    <button data-prompt-msg="Are you sure you want to delete these records?" data-display-style="modal" data-url="<?php print_link("salary_data/delete/{sel_ids}/?csrf_token=$csrf_token&redirect=$current_page"); ?>" class="btn btn-sm btn-danger btn-delete-selected d-none">
                                                        <i class="fa fa-times"></i> Delete Selected
                                                    </button>
                                                    <?php } ?>
                                                    <div class="dropup export-btn-holder mx-1">
                                                        <button class="btn btn-sm btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                                            <i class="fa fa-save"></i> Export
                                                        </button>
                                                        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                                                            <?php $export_print_link = $this->set_current_page_link(array('format' => 'print')); ?>
                                                            <a class="dropdown-item export-link-btn" data-format="print" href="<?php print_link($export_print_link); ?>" target="_blank">
                                                                <img src="<?php print_link('assets/images/print.png') ?>" class="mr-2" /> PRINT
                                                                </a>
                                                                <?php $export_pdf_link = $this->set_current_page_link(array('format' => 'pdf')); ?>
                                                                <a class="dropdown-item export-link-btn" data-format="pdf" href="<?php print_link($export_pdf_link); ?>" target="_blank">
                                                                    <img src="<?php print_link('assets/images/pdf.png') ?>" class="mr-2" /> PDF
                                                                    </a>
                                                                    <?php $export_word_link = $this->set_current_page_link(array('format' => 'word')); ?>
                                                                    <a class="dropdown-item export-link-btn" data-format="word" href="<?php print_link($export_word_link); ?>" target="_blank">
                                                                        <img src="<?php print_link('assets/images/doc.png') ?>" class="mr-2" /> WORD
                                                                        </a>
                                                                        <?php $export_csv_link = $this->set_current_page_link(array('format' => 'csv')); ?>
                                                                        <a class="dropdown-item export-link-btn" data-format="csv" href="<?php print_link($export_csv_link); ?>" target="_blank">
                                                                            <img src="<?php print_link('assets/images/csv.png') ?>" class="mr-2" /> CSV
                                                                            </a>
                                                                            <?php $export_excel_link = $this->set_current_page_link(array('format' => 'excel')); ?>
                                                                            <a class="dropdown-item export-link-btn" data-format="excel" href="<?php print_link($export_excel_link); ?>" target="_blank">
                                                                                <img src="<?php print_link('assets/images/xsl.png') ?>" class="mr-2" /> EXCEL
                                                                                </a>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                                <div class="col">   
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <?php
                                                        }
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </section>
