File: /home/cafsindia/hrms_cafsinfotech_in/OLD/application/models/Fandf_calculation_model.php
<?php
class Fandf_calculation_model extends CI_Model{
private $month_day_res;
private $sup_emp;
private $ptax_rslt;
private $statutory_arr;
private $get_map_arr;
private $lwf_emp_arr;
private $emp_date_arr;
private $gratuity_arr;
private $ptax_arr;
public function Payroll_calculation($trans_array){
$month_day_qry = 'SELECT category,day_conditions,day_count,day_start,day_end from cw_month_day where cw_month_day.trans_status = 1 ';
$month_day_data = $this->db->query("CALL sp_a_run ('SELECT','$month_day_qry')");
$month_day_result = $month_day_data->result_array();
$month_day_data->next_result();
$this->month_day_res = array_reduce($month_day_result, function ($result, $arr) {
$result[$arr['category']] = $arr;
return $result;
}, array());
//get tax settings info
$ptax_qry = 'select cw_professional_tax.prime_professional_tax_id,location,calculation_period,ptax_deduction_month_first as first_period,ptax_deduction_month_second as second_period, osm_first_end,osm_second_end,osm_first_start,osm_second_start from cw_professional_tax where cw_professional_tax.trans_status = 1';
$ptax_data = $this->db->query("CALL sp_a_run ('SELECT','$ptax_qry')");
$ptax_result = $ptax_data->result_array();
$ptax_data->next_result();
$this->ptax_rslt = array_reduce($ptax_result, function ($result, $arr) {
$result[$arr['location']] = $arr;
return $result;
}, array());
// get_document_fees
/*$payroll_exist_query = 'SELECT employee_code,count(employee_code) as pay_count from cw_transactions where termination_status = 0 and trans_status = 1 group by employee_code';
$payroll_exist_info = $this->db->query("CALL sp_a_run ('RUN','$payroll_exist_query')");
$payroll_exist_result = $payroll_exist_info->result_array();
$payroll_exist_info->next_result();*/
//get statutory array
$get_statutory_qry = 'SELECT * FROM cw_statutory WHERE trans_status = 1';
$get_statutory_info = $this->db->query("CALL sp_a_run ('SELECT','$get_statutory_qry')");
$get_statutory_rslt = $get_statutory_info->result_array();
$get_statutory_info->next_result();
$this->statutory_arr = array_reduce($get_statutory_rslt, function ($result, $arr) {
$result[$arr['category']] = $arr;
return $result;
}, array());
//get Payroll Function Map array
$get_map_qry = 'select * from cw_payroll_function_map where trans_status=1';
$get_map_info = $this->db->query("CALL sp_a_run ('SELECT','$get_map_qry')");
$get_map_rslt = $get_map_info->result_array();
$get_map_info->next_result();
$this->get_map_arr = array_reduce($get_map_rslt, function ($result, $arr) {
$result[$arr['loc_name']] = $arr;
return $result;
}, array());
//Get lwf_employee & lwf_employer
$select_lwf_qry = 'select pay_month,company_amount,employee_amount from cw_lwf_setting inner join cw_lwf_setting_lwf_pay_month on cw_lwf_setting_lwf_pay_month.prime_lwf_setting_id=cw_lwf_setting.prime_lwf_setting_id WHERE cw_lwf_setting.trans_status =1';
$select_lwf_data = $this->db->query("CALL sp_a_run ('SELECT','$select_lwf_qry')");
$select_lwf_result = $select_lwf_data->result_array();
$select_lwf_data->next_result();
$this->lwf_emp_arr = array_reduce($select_lwf_result, function ($result, $arr) {
$result[$arr['lwf_location']] = $arr;
return $result;
}, array());
//Get Employee Date
$emp_date_qry = 'select last_working_date,date_of_joining,employee_code,termination_status,esi_location,esi_eligibility from cw_employees where trans_status = 1';
$emp_date_data = $this->db->query("CALL sp_a_run ('SELECT','$emp_date_qry')");
$emp_date_rslt = $emp_date_data->result_array();
$emp_date_data->next_result();
foreach($emp_date_rslt as $key => $value){
$this->emp_date_arr[$value['employee_code']] = $value;
}
/*$this->emp_date_arr = array_reduce($emp_date_rslt, function ($result, $arr) {
$result[$arr['employee_code']] = $arr;
return $result;
}, array());
*/
//Get Gratuity
$check_eligibilty_qry = 'select category,working_days,number_of_years,pay_days,year_rounding,formula_detail,formula_rounding from cw_gratuity where trans_status = 1';
$check_eligibilty_data = $this->db->query("CALL sp_a_run ('SELECT','$check_eligibilty_qry')");
$check_eligibilty_result = $check_eligibilty_data->result_array();
$check_eligibilty_data->next_result();
$this->gratuity_arr = array_reduce($check_eligibilty_result, function ($result, $arr) {
$result[$arr['category']] = $arr;
return $result;
}, array());
//Get Gratuity
$ptax_arr_qry = 'select cw_professional_tax.prime_professional_tax_id,location,calculation_period,ptax_deduction_month_first as first_period,ptax_deduction_month_second as second_period, osm_first_end,osm_second_end,osm_first_start,osm_second_start from cw_professional_tax_tax_range inner join cw_professional_tax on cw_professional_tax.prime_professional_tax_id = cw_professional_tax_tax_range.prime_professional_tax_id where cw_professional_tax.trans_status = 1';
$ptax_arr_data = $this->db->query("CALL sp_a_run ('SELECT','$ptax_arr_qry')");
$ptax_arr_result = $ptax_arr_data->result_array();
$ptax_arr_data->next_result();
foreach($emp_date_rslt as $key => $value){
$this->ptax_arr[$value['location']] = $value;
}
/*$this->ptax_arr = array_reduce($ptax_arr_result, function ($result, $arr) {
$result[$arr['location']] = $arr;
return $result;
}, array());
*/
$emp_qry = 'select GROUP_CONCAT(employee_code) as sup_emp from cw_monthly_input where trans_status = 1 and supplementary_status = 1';
$emp_data = $this->db->query("CALL sp_a_run ('SELECT','$emp_qry')");
$emp_result = $emp_data->result();
$emp_data->next_result();
$this->sup_emp = $emp_result[0]->sup_emp;
$logged_id = $this->session->userdata("logged_id");
$date = date("Y-m-d H:i:s");
$settlement_date = date("Y-m-d");
$payroll_array = array();
foreach($trans_array as $key => $trans){
$employee_code = $trans["employee_code"]; $trans["transactions_month"] = $trans["process_month"];
if((int)$trans["role"] === 3){
$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);
$trans["lwf"] = $this->get_lwf_employee($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["eer_lwf"] = $this->get_lwf_employer($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["fb"] = $trans["fb"];
$trans["fixed_hra"] = $trans["fixed_hra"];
$trans["flta"] = $trans["flta"];
$trans["fconv"] = $trans["fconv"];
$trans["fbns_adv"] = $trans["fbns_adv"];
$trans["ftconv"] = $trans["ftconv"];
$trans["ffc"] = $trans["ffc"];
$trans["ftr"] = $trans["ftr"];
$trans["fdr"] = $trans["fdr"];
$trans["fnps"] = $trans["fnps"];
$trans["md"] = $this->get_total_work_days($trans["role"],$trans["transactions_month"]);
$trans["separation_day"] = $this->get_seperation_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["extra_hrs"] = $trans["extra_hrs"];
$trans["pd"] = $trans["pd"];
$trans["fixed_gross"] = $trans["fixed_gross"];
$trans["gmc_in_ctc"] = $trans["gmc_in_ctc"];
$trans["tel_reim"] = $this->rounding_value(($trans["tel_reim"]),'1');
$trans["driver_reim"] = $this->rounding_value(( $trans["driver_reim"]),'1');
$trans["petty_cash"] = $trans["petty_cash"];
$trans["penalty"] = $trans["penalty"];
$trans["sw"] = $trans["sw"];
$trans["monthly_tds"] = $trans["monthly_tds"];
$trans["ptax_two"] = $trans["ptax_two"];
$trans["fded"] = $trans["fded"];
$trans["medi"] = $trans["medi"];
$trans["lic"] = $trans["lic"];
$trans["saladv"] = $trans["saladv"];
$trans["oth_ded"] = $trans["oth_ded"];
$trans["pf_eligibility"] = $trans["pf_eligibility"];
$trans["salary_loan"] = $trans["salary_loan"];
$trans["pf_er_share"] = $this->rounding_value(($trans["pf_er_share"]),'1');
$trans["pf_admin_charge"] = $this->rounding_value(($trans["pf_admin_charge"]),'1');
$trans["esi_er_share"] = $this->rounding_value(($trans["esi_er_share"]),'1');
$trans["gratuity"] = $this->rounding_value(($trans["gratuity"]),'1');
$trans["gpa"] = $this->rounding_value(($trans["gpa"]),'1');
$trans["ctc"] = $this->rounding_value(($trans["ctc"]),'1');
$trans["earned_tele_reim"] = $this->rounding_value(($this->dz($trans["ftr"]/ $trans["md"] )* $trans["pd"]),'1');
$trans["earned_driver_reim"] = $this->rounding_value(($this->dz($trans["fdr"]/$trans["md"])*$trans["pd"]),'1');
$trans["extra_ot"] = $this->rounding_value(($this->dz($trans["fixed_gross"]/$trans["md"]/8)*$trans["extra_hrs"] ),'1');
$trans["basic"] = $this->rounding_value(($this->dz($trans["fb"]/$trans["md"])*$trans["pd"]),'1');
$trans["hra"] = $this->rounding_value(($this->dz($trans["fixed_hra"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_gmc"] = $this->rounding_value(($this->dz($trans["gmc_in_ctc"]/$trans["md"])*$trans["pd"]),'1');
$trans["lta"] = $this->rounding_value(($this->dz($trans["flta"]/$trans["md"])*$trans["pd"]),'1');
$trans["conv"] = $this->rounding_value(($this->dz($trans["fconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["bns_adv"] = $this->rounding_value(($this->dz($trans["fbns_adv"]/$trans["md"])*$trans["pd"]),'1');
$trans["etconv"] = $this->rounding_value(($this->dz($trans["ftconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["efc"] = $this->rounding_value(($this->dz($trans["ffc"]/$trans["md"])*$trans["pd"]),'1');
$trans["enps"] = $this->rounding_value(($this->dz($trans["fnps"]/$trans["md"])*$trans["pd"]),'1');
$trans["eg"] = $this->rounding_value(($trans["basic"]+$trans["lta"]+$trans["conv"]+$trans["bns_adv"]+$trans["hra"]+$trans["driver_reim"]+$trans["tel_reim"]),'1');
if($trans["pf_eligibility"]==1){if($trans["fb"]>15000){$trans["fpf_gross"] = 15000;}else{$trans["fpf_gross"] = $trans["fixed_gross"];}}else{$trans["fpf_gross"] = 0;}
$trans["fixed_pf"] = $this->rounding_value(($trans["fpf_gross"]*0),'1');
$trans["ld"] = $trans["md"]-$trans["pd"]-$trans["differential_day"]-$trans["separation_day"];
$trans["fpt_gross"] = $trans["fixed_gross"];
$trans["earned_pf_er_share"] = $this->rounding_value(($this->dz($trans["pf_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_pf_admin"] = $this->rounding_value(($this->dz($trans["pf_admin_charge"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_esi_er_share"] = $this->rounding_value(($this->dz($trans["esi_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gpa"] = $this->rounding_value(($this->dz($trans["gpa"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gratuity"] = $this->rounding_value(($this->dz($trans["gratuity"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_ctc"] = $trans["eg"]+$trans["earned_pf_er_share"]+$trans["enps"]+$trans["efc"]+$trans["e_gratuity"]+$trans["earned_pf_admin"]+$trans["earned_esi_er_share"]+$trans["e_gpa"]+$trans["earned_gmc"]+$trans["earned_tele_reim"]+$trans["earned_driver_reim"]-$trans["driver_reim"]-$trans["tel_reim"];
$trans["one_time_tds"] = $this->rounding_value(($trans["eg"]*$this->dz(10/100)),'1');
$trans["tot_other_ded"] = $trans["monthly_tds"]+$trans["one_time_tds"]+$trans["fded"]+$trans["medi"]+$trans["saladv"]+$trans["oth_ded"]+ $trans["salary_loan"]+$trans["petty_cash"]+$trans["penalty"];
$trans["total_earnings"] = $this->rounding_value(($trans["hra"]+$trans["basic"]+$trans["conv"]+$trans["lta"]+$trans["bns_adv"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["total_deductions"] = $this->rounding_value(($trans["petty_cash"]+$trans["penalty"]+$trans["esi"]+$trans["npra"]+$trans["one_time_tds"]+$trans["monthly_tds"]+$trans["pfamount"]+$trans["vpf"]+$trans["sw"]+$trans["ptax_two"]+$trans["fded"]+$trans["medi"]+$trans["ptax"]+$trans["lic"]+$trans["saladv"]+$trans["oth_ded"]+$trans["salary_loan"]+$trans["lwf"]),'1');
$trans["net_pay"] = $this->rounding_value(($trans["total_earnings"]-$trans["total_deductions"]),'1');
$payroll_array[3][] ="('".$trans["employees_id"]."','".$trans["transactions_month"]."','".$trans["total_earnings"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."',\"$logged_id\",\"$date\",\"$settlement_date\",\"1\",'".$trans["fb"]."','".$trans["fixed_hra"]."','".$trans["flta"]."','".$trans["fconv"]."','".$trans["fbns_adv"]."','".$trans["ftconv"]."','".$trans["ffc"]."','".$trans["ftr"]."','".$trans["fdr"]."','".$trans["fnps"]."','".$trans["md"]."','".$trans["separation_day"]."','".$trans["differential_day"]."','".$trans["extra_hrs"]."','".$trans["pd"]."','".$trans["fixed_gross"]."','".$trans["gmc_in_ctc"]."','".$trans["tel_reim"]."','".$trans["driver_reim"]."','".$trans["petty_cash"]."','".$trans["penalty"]."','".$trans["sw"]."','".$trans["monthly_tds"]."','".$trans["ptax_two"]."','".$trans["fded"]."','".$trans["medi"]."','".$trans["lic"]."','".$trans["saladv"]."','".$trans["oth_ded"]."','".$trans["pf_eligibility"]."','".$trans["salary_loan"]."','".$trans["pf_er_share"]."','".$trans["pf_admin_charge"]."','".$trans["esi_er_share"]."','".$trans["gratuity"]."','".$trans["gpa"]."','".$trans["ctc"]."','".$trans["earned_tele_reim"]."','".$trans["earned_driver_reim"]."','".$trans["extra_ot"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["earned_gmc"]."','".$trans["lta"]."','".$trans["conv"]."','".$trans["bns_adv"]."','".$trans["etconv"]."','".$trans["efc"]."','".$trans["enps"]."','".$trans["eg"]."','".$trans["fpf_gross"]."','".$trans["fixed_pf"]."','".$trans["ld"]."','".$trans["fpt_gross"]."','".$trans["earned_pf_er_share"]."','".$trans["earned_pf_admin"]."','".$trans["earned_esi_er_share"]."','".$trans["e_gpa"]."','".$trans["e_gratuity"]."','".$trans["e_ctc"]."','".$trans["one_time_tds"]."','".$trans["tot_other_ded"]."','".$trans["ptax_two_total"]."','".$trans["ptax_two_installments"]."','".$trans["ptax_two_instal_count"]."','".$trans["ptax_two_balance"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."','".$trans["petty_cash_total"]."','".$trans["petty_cash_installments"]."','".$trans["petty_cash_instal_count"]."','".$trans["petty_cash_balance"]."','".$trans["penalty_total"]."','".$trans["penalty_installments"]."','".$trans["penalty_instal_count"]."','".$trans["penalty_balance"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["branch"]."','".$trans["professional_tax_location"]."','".$trans["location"]."','".$trans["bank_account_number"]."','".$trans["bank_name"]."','".$trans["ifsc_code"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["cost_centre"]."','".$trans["grade"]."','".$trans["paymode"]."','".$trans["perarea"]."','".$trans["wbs"]."','".$trans["cat"]."')";
$qry_3 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,settlement_date,fandf,fb,fixed_hra,flta,fconv,fbns_adv,ftconv,ffc,ftr,fdr,fnps,md,separation_day,differential_day,extra_hrs,pd,fixed_gross,gmc_in_ctc,tel_reim,driver_reim,petty_cash,penalty,sw,monthly_tds,ptax_two,fded,medi,lic,saladv,oth_ded,pf_eligibility,salary_loan,pf_er_share,pf_admin_charge,esi_er_share,gratuity,gpa,ctc,earned_tele_reim,earned_driver_reim,extra_ot,basic,hra,earned_gmc,lta,conv,bns_adv,etconv,efc,enps,eg,fpf_gross,fixed_pf,ld,fpt_gross,earned_pf_er_share,earned_pf_admin,earned_esi_er_share,e_gpa,e_gratuity,e_ctc,one_time_tds,tot_other_ded,ptax_two_total,ptax_two_installments,ptax_two_instal_count,ptax_two_balance,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance,petty_cash_total,petty_cash_installments,petty_cash_instal_count,petty_cash_balance,penalty_total,penalty_installments,penalty_instal_count,penalty_balance,role,employee_code,emp_name,department,designation,date_of_joining,branch,professional_tax_location,location,bank_account_number,bank_name,ifsc_code,lwf_location,process_month,resignation_date,termination_status,payroll,cost_centre,grade,paymode,perarea,wbs,cat'.$trans_key_array.') VALUES '.implode(',',$payroll_array[3]);
}else
if((int)$trans["role"] === 2){
$trans["fixed_hra"] = $trans["fixed_hra"];
$trans["flta"] = $trans["flta"];
$trans["fconv"] = $trans["fconv"];
$trans["fbns_adv"] = $trans["fbns_adv"];
$trans["ftconv"] = $trans["ftconv"];
$trans["ffc"] = $trans["ffc"];
$trans["ftr"] = $trans["ftr"];
$trans["gmc_in_ctc"] = $trans["gmc_in_ctc"];
$trans["fdr"] = $trans["fdr"];
$trans["fnps"] = $trans["fnps"];
$trans["fb"] = $trans["fb"];
$trans["separation_day"] = $this->get_seperation_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["pd"] = $trans["pd"];
$trans["md"] = $this->get_total_work_days($trans["role"],$trans["transactions_month"]);
$trans["fixed_gross"] = $trans["fixed_gross"];
$trans["tel_reim"] = $this->rounding_value(($trans["tel_reim"]),'1');
$trans["driver_reim"] = $this->rounding_value(($trans["driver_reim"]),'1');
$trans["gratuity"] = $this->rounding_value(($trans["gratuity"]),'1');
$trans["sw"] = $trans["sw"];
$trans["ptax_two"] = $trans["ptax_two"];
$trans["fded"] = $trans["fded"];
$trans["medi"] = $trans["medi"];
$trans["lic"] = $trans["lic"];
$trans["saladv"] = $trans["saladv"];
$trans["lcd"] = $trans["lcd"];
$trans["oth_ded"] = $trans["oth_ded"];
$trans["esi_eligibility"] = $trans["esi_eligibility"];
$trans["pf_eligibility"] = $trans["pf_eligibility"];
$trans["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["ab"] = $trans["ab"];
$trans["vpf"] = $trans["vpf"];
$trans["monthly_tds"] = $trans["monthly_tds"];
$trans["one_time_tds"] = $trans["one_time_tds"];
$trans["pfsts"] = $trans["pfsts"];
$trans["salary_loan"] = $trans["salary_loan"];
$trans["othrs"] = $trans["othrs"];
$trans["otrt"] = $trans["otrt"];
$trans["pf_er_share"] = $this->rounding_value(($trans["pf_er_share"]),'1');
$trans["pf_admin_charge"] = $this->rounding_value(($trans["pf_admin_charge"]),'1');
$trans["esi_er_share"] = $this->rounding_value(($trans["esi_er_share"]),'1');
$trans["gpa"] = $this->rounding_value(($trans["gpa"]),'1');
$trans["ctc"] = $this->rounding_value(($trans["ctc"]),'1');
$trans["extra_hrs"] = $trans["extra_hrs"];
$trans["penalty"] = $trans["penalty"];
$trans["petty_cash"] = $trans["petty_cash"];
$trans["earned_tele_reim"] = $this->rounding_value(($this->dz($trans["ftr"]/ $trans["md"] )* $trans["pd"]),'1');
$trans["earned_driver_reim"] = $this->rounding_value(($this->dz($trans["fdr"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_gmc"] = $this->rounding_value(($this->dz($trans["gmc_in_ctc"]/$trans["md"])*$trans["pd"]),'1');
$trans["basic"] = $this->rounding_value(($this->dz($trans["fb"]/$trans["md"])*$trans["pd"]),'1');
$trans["hra"] = $this->rounding_value(($this->dz($trans["fixed_hra"]/$trans["md"])*$trans["pd"]),'1');
$trans["lta"] = $this->rounding_value(($this->dz($trans["flta"]/$trans["md"])*$trans["pd"]),'1');
$trans["conv"] = $this->rounding_value(($this->dz($trans["fconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["bns_adv"] = $this->rounding_value(($this->dz($trans["fbns_adv"]/$trans["md"])*$trans["pd"]),'1');
$trans["etconv"] = $this->rounding_value(($this->dz($trans["ftconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["efc"] = $this->rounding_value(($this->dz($trans["ffc"]/$trans["md"])*$trans["pd"]),'1');
$trans["enps"] = $this->rounding_value(($this->dz($trans["fnps"]/$trans["md"])*$trans["pd"]),'1');
$trans["tot_other_ded"] = $trans["monthly_tds"]+$trans["one_time_tds"]+$trans["fded"]+$trans["medi"]+$trans["saladv"]+$trans["oth_ded"]+ $trans["salary_loan"]+$trans["petty_cash"]+$trans["penalty"];
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["basic"]>=15000){$trans["pf_wages"] = 15000;}else{$trans["pf_wages"] = $trans["basic"];}}else{$trans["pf_wages"] = 0;}
$trans["pfamount"] = $this->rounding_value(($trans["pf_wages"]*$this->dz(12/100)),'1');
// if$this->dz($trans["pf_wages"]>15000){$trans["fpf"] = 1250;}else{$trans["fpf"] = round$this->dz($trans["pf_wages"]*$this->dz(8.33/100),0);}
$trans["epf"] = $trans["pfamount"]-$trans["fpf"];
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["fb"]>=15000){$trans["fpf_gross"] = 15000;}else{$trans["fpf_gross"] = $trans["fb"];}}else{$trans["fpf_gross"] = 0;}
$trans["fixed_pf"] = $trans["fpf_gross"]*$this->dz(12/100);
$trans["fpt_gross"] = $trans["fixed_gross"];
$trans["ld"] = $trans["md"]-$trans["pd"]-$trans["differential_day"]-$trans["separation_day"];
$trans["otamt"] = $this->rounding_value((($trans["otrt"] * $trans["othrs"])),'1');
$trans["eg"] = $this->rounding_value(($trans["basic"]+$trans["lta"]+$trans["conv"]+$trans["bns_adv"]+$trans["hra"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["ept_gross"] = $trans["eg"];
$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);
if($trans["esi_eligibility"]==1){$trans["esi_gross"] = $trans["eg"];}else{$trans["esi_gross"] = 0;}
$trans["employer_esi"] = $this->rounding_value(($trans["esi_gross"]*$this->dz(3.25/100)),'1');
// if$this->dz($trans["fixed_gross"]>=5280){$trans["esi"] = ceil$this->dz($trans["esi_gross"]*$this->dz(0.75/100));}else{$trans["esi"] = 0;}
$trans["lwf_gross"] = $trans["eg"];
$trans["lwf"] = $this->get_lwf_employee($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["eer_lwf"] = $this->get_lwf_employer($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["extra_ot"] = $this->rounding_value(($this->dz($trans["fixed_gross"]/$trans["md"]/8)*$trans["extra_hrs"]),'1');
$trans["earned_pf_er_share"] = $this->rounding_value(($this->dz($trans["pf_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_pf_admin"] = $this->rounding_value(($this->dz($trans["pf_admin_charge"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_esi_er_share"] = $this->rounding_value(($this->dz($trans["esi_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gpa"] = $this->rounding_value(($this->dz($trans["gpa"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gratuity"] = $this->rounding_value(($this->dz($trans["gratuity"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_ctc"] = $trans["eg"]+$trans["earned_pf_er_share"]+$trans["enps"]+$trans["efc"]+$trans["e_gratuity"]+$trans["earned_pf_admin"]+$trans["earned_esi_er_share"]+$trans["e_gpa"]+$trans["earned_gmc"]+$trans["earned_tele_reim"]+$trans["earned_driver_reim"]-$trans["driver_reim"]-$trans["tel_reim"];
$trans["lop_cr_basic"] = $this->dz($trans["fb"]/$trans["md"])*$trans["lcd"];
$trans["lop_cr_hra"] = $this->dz($trans["fixed_hra"]/$trans["md"])*$trans["lcd"];
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["basic"]+$trans["ab"]>=15000){$trans["arr_pf_gross"] = 15000;}else{$trans["arr_pf_gross"] = $trans["basic"]+$trans["ab"];}}else{$trans["arr_pf_gross"] = 0;}
$trans["total_earnings"] = $this->rounding_value(($trans["hra"]+$trans["basic"]+$trans["conv"]+$trans["lta"]+$trans["bns_adv"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["total_deductions"] = $this->rounding_value(($trans["petty_cash"]+$trans["penalty"]+$trans["esi"]+$trans["npra"]+$trans["one_time_tds"]+$trans["monthly_tds"]+$trans["pfamount"]+$trans["vpf"]+$trans["sw"]+$trans["ptax_two"]+$trans["fded"]+$trans["medi"]+$trans["ptax"]+$trans["lic"]+$trans["saladv"]+$trans["oth_ded"]+$trans["salary_loan"]+$trans["lwf"]),'1');
$trans["net_pay"] = $this->rounding_value(($trans["total_earnings"]-$trans["total_deductions"]),'1');
$payroll_array[2][] ="('".$trans["employees_id"]."','".$trans["transactions_month"]."','".$trans["total_earnings"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."',\"$logged_id\",\"$date\",\"$settlement_date\",\"1\",'".$trans["fixed_hra"]."','".$trans["flta"]."','".$trans["fconv"]."','".$trans["fbns_adv"]."','".$trans["ftconv"]."','".$trans["ffc"]."','".$trans["ftr"]."','".$trans["gmc_in_ctc"]."','".$trans["fdr"]."','".$trans["fnps"]."','".$trans["fb"]."','".$trans["separation_day"]."','".$trans["pd"]."','".$trans["md"]."','".$trans["fixed_gross"]."','".$trans["tel_reim"]."','".$trans["driver_reim"]."','".$trans["gratuity"]."','".$trans["sw"]."','".$trans["ptax_two"]."','".$trans["fded"]."','".$trans["medi"]."','".$trans["lic"]."','".$trans["saladv"]."','".$trans["lcd"]."','".$trans["oth_ded"]."','".$trans["esi_eligibility"]."','".$trans["pf_eligibility"]."','".$trans["differential_day"]."','".$trans["ab"]."','".$trans["vpf"]."','".$trans["monthly_tds"]."','".$trans["one_time_tds"]."','".$trans["pfsts"]."','".$trans["salary_loan"]."','".$trans["othrs"]."','".$trans["otrt"]."','".$trans["pf_er_share"]."','".$trans["pf_admin_charge"]."','".$trans["esi_er_share"]."','".$trans["gpa"]."','".$trans["ctc"]."','".$trans["extra_hrs"]."','".$trans["penalty"]."','".$trans["petty_cash"]."','".$trans["earned_tele_reim"]."','".$trans["earned_driver_reim"]."','".$trans["earned_gmc"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["lta"]."','".$trans["conv"]."','".$trans["bns_adv"]."','".$trans["etconv"]."','".$trans["efc"]."','".$trans["enps"]."','".$trans["tot_other_ded"]."','".$trans["pf_wages"]."','".$trans["pfamount"]."','".$trans["fpf"]."','".$trans["epf"]."','".$trans["fpf_gross"]."','".$trans["fixed_pf"]."','".$trans["fpt_gross"]."','".$trans["ld"]."','".$trans["otamt"]."','".$trans["eg"]."','".$trans["ept_gross"]."','".$trans["ptax"]."','".$trans["esi_gross"]."','".$trans["employer_esi"]."','".$trans["esi"]."','".$trans["lwf_gross"]."','".$trans["lwf"]."','".$trans["eer_lwf"]."','".$trans["extra_ot"]."','".$trans["earned_pf_er_share"]."','".$trans["earned_pf_admin"]."','".$trans["earned_esi_er_share"]."','".$trans["e_gpa"]."','".$trans["e_gratuity"]."','".$trans["e_ctc"]."','".$trans["lop_cr_basic"]."','".$trans["lop_cr_hra"]."','".$trans["arr_pf_gross"]."','".$trans["ptax_two_total"]."','".$trans["ptax_two_installments"]."','".$trans["ptax_two_instal_count"]."','".$trans["ptax_two_balance"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."','".$trans["petty_cash_total"]."','".$trans["petty_cash_installments"]."','".$trans["petty_cash_instal_count"]."','".$trans["petty_cash_balance"]."','".$trans["penalty_total"]."','".$trans["penalty_installments"]."','".$trans["penalty_instal_count"]."','".$trans["penalty_balance"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["branch"]."','".$trans["professional_tax_location"]."','".$trans["location"]."','".$trans["bank_account_number"]."','".$trans["bank_name"]."','".$trans["ifsc_code"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["cost_centre"]."','".$trans["grade"]."','".$trans["paymode"]."','".$trans["perarea"]."','".$trans["wbs"]."','".$trans["cat"]."')";
$qry_2 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,settlement_date,fandf,fixed_hra,flta,fconv,fbns_adv,ftconv,ffc,ftr,gmc_in_ctc,fdr,fnps,fb,separation_day,pd,md,fixed_gross,tel_reim,driver_reim,gratuity,sw,ptax_two,fded,medi,lic,saladv,lcd,oth_ded,esi_eligibility,pf_eligibility,differential_day,ab,vpf,monthly_tds,one_time_tds,pfsts,salary_loan,othrs,otrt,pf_er_share,pf_admin_charge,esi_er_share,gpa,ctc,extra_hrs,penalty,petty_cash,earned_tele_reim,earned_driver_reim,earned_gmc,basic,hra,lta,conv,bns_adv,etconv,efc,enps,tot_other_ded,pf_wages,pfamount,fpf,epf,fpf_gross,fixed_pf,fpt_gross,ld,otamt,eg,ept_gross,ptax,esi_gross,employer_esi,esi,lwf_gross,lwf,eer_lwf,extra_ot,earned_pf_er_share,earned_pf_admin,earned_esi_er_share,e_gpa,e_gratuity,e_ctc,lop_cr_basic,lop_cr_hra,arr_pf_gross,ptax_two_total,ptax_two_installments,ptax_two_instal_count,ptax_two_balance,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance,petty_cash_total,petty_cash_installments,petty_cash_instal_count,petty_cash_balance,penalty_total,penalty_installments,penalty_instal_count,penalty_balance,role,employee_code,emp_name,department,designation,date_of_joining,branch,professional_tax_location,location,bank_account_number,bank_name,ifsc_code,lwf_location,process_month,resignation_date,termination_status,payroll,cost_centre,grade,paymode,perarea,wbs,cat'.$trans_key_array.') VALUES '.implode(',',$payroll_array[2]);
}else
if((int)$trans["role"] === 9){
$trans["fixed_hra"] = $trans["fixed_hra"];
$trans["flta"] = $trans["flta"];
$trans["fconv"] = $trans["fconv"];
$trans["fbns_adv"] = $trans["fbns_adv"];
$trans["ftconv"] = $trans["ftconv"];
$trans["ffc"] = $trans["ffc"];
$trans["ftr"] = $trans["ftr"];
$trans["fdr"] = $trans["fdr"];
$trans["fnps"] = $trans["fnps"];
$trans["separation_day"] = $this->get_seperation_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["pd"] = $trans["pd"];
$trans["fixed_gross"] = $trans["fixed_gross"];
$trans["fb"] = $trans["fb"];
$trans["tel_reim"] = $this->rounding_value(($trans["tel_reim"]),'1');
$trans["driver_reim"] = $this->rounding_value(($trans["driver_reim"]),'1');
$trans["sw"] = $trans["sw"];
$trans["ptax_two"] = $trans["ptax_two"];
$trans["fded"] = $trans["fded"];
$trans["medi"] = $trans["medi"];
$trans["lic"] = $trans["lic"];
$trans["saladv"] = $trans["saladv"];
$trans["oth_ded"] = $trans["oth_ded"];
$trans["pf_eligibility"] = $trans["pf_eligibility"];
$trans["gmc_in_ctc"] = $trans["gmc_in_ctc"];
$trans["esi_eligibility"] = $trans["esi_eligibility"];
$trans["vpf"] = $trans["vpf"];
$trans["monthly_tds"] = $trans["monthly_tds"];
$trans["one_time_tds"] = $trans["one_time_tds"];
$trans["pfsts"] = $trans["pfsts"];
$trans["salary_loan"] = $trans["salary_loan"];
$trans["othrs"] = $trans["othrs"];
$trans["otrt"] = $trans["otrt"];
$trans["md"] = $this->get_total_work_days($trans["role"],$trans["transactions_month"]);
$trans["pf_er_share"] = $this->rounding_value(($trans["pf_er_share"]),'1');
$trans["pf_admin_charge"] = $this->rounding_value(($trans["pf_admin_charge"]),'1');
$trans["esi_er_share"] = $this->rounding_value(($trans["esi_er_share"]),'1');
$trans["gratuity"] = $this->rounding_value(($trans["gratuity"]),'1');
$trans["gpa"] = $this->rounding_value(($trans["gpa"]),'1');
$trans["ctc"] = $this->rounding_value(($trans["ctc"]),'1');
$trans["extra_hrs"] = $trans["extra_hrs"];
$trans["penalty"] = $trans["penalty"];
$trans["petty_cash"] = $trans["petty_cash"];
$trans["earned_tele_reim"] = $this->rounding_value(($this->dz($trans["ftr"]/ $trans["md"] )* $trans["pd"]),'1');
$trans["earned_driver_reim"] = $this->rounding_value(($this->dz($trans["fdr"]/$trans["md"])*$trans["pd"]),'1');
$trans["basic"] = $this->rounding_value(($this->dz($trans["fb"]/$trans["md"])*$trans["pd"]),'1');
$trans["hra"] = $this->rounding_value(($this->dz($trans["fixed_hra"]/$trans["md"])*$trans["pd"]),'1');
$trans["lta"] = $this->rounding_value(($this->dz($trans["flta"]/$trans["md"])*$trans["pd"]),'1');
$trans["conv"] = $this->rounding_value(($this->dz($trans["fconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["bns_adv"] = $this->rounding_value(($this->dz($trans["fbns_adv"]/$trans["md"])*$trans["pd"]),'1');
$trans["etconv"] = $this->rounding_value(($this->dz($trans["ftconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["efc"] = $this->rounding_value(($this->dz($trans["ffc"]/$trans["md"])*$trans["pd"]),'1');
$trans["enps"] = $this->rounding_value(($this->dz($trans["fnps"]/$trans["md"])*$trans["pd"]),'1');
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["basic"]>=15000){$trans["pf_wages"] = 15000;}else{$trans["pf_wages"] = $trans["basic"];}}else{$trans["pf_wages"] = 0;}
$trans["pfamount"] = $this->rounding_value(($trans["pf_wages"]*$this->dz(12/100)),'1');
$trans["earned_gmc"] = $this->rounding_value(($this->dz($trans["gmc_in_ctc"]/$trans["md"])*$trans["pd"]),'1');
// if$this->dz($trans["pf_wages"]>15000){$trans["fpf"] = 1250;}else{$trans["fpf"] = round$this->dz($trans["pf_wages"]*$this->dz(8.33/100),0);}
$trans["epf"] = $trans["pfamount"]-$trans["fpf"];
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["fb"]>=15000){$trans["fpf_gross"] = 15000;}else{$trans["fpf_gross"] = $trans["fb"];}}else{$trans["fpf_gross"] = 0;}
$trans["fixed_pf"] = $trans["fpf_gross"]*$this->dz(12/100);
$trans["fpt_gross"] = $trans["fixed_gross"];
$trans["ld"] = $trans["md"]-$trans["pd"]-$trans["differential_day"]-$trans["separation_day"];
$trans["otamt"] = $this->rounding_value((($trans["otrt"] * $trans["othrs"])),'1');
$trans["eg"] = $this->rounding_value(($trans["basic"]+$trans["lta"]+$trans["conv"]+$trans["bns_adv"]+$trans["hra"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["ept_gross"] = $trans["eg"];
$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);
if($trans["esi_eligibility"]==1){$trans["esi_gross"] = $trans["eg"];}else{$trans["esi_gross"] = 0;}
$trans["employer_esi"] = $this->rounding_value(($trans["esi_gross"]*$this->dz(3.25/100)),'1');
// if$this->dz($trans["fixed_gross"]>=5280){$trans["esi"] = ceil$this->dz($trans["esi_gross"]*$this->dz(0.75/100));}else{$trans["esi"] = 0;}
$trans["lwf_gross"] = $trans["eg"];
$trans["lwf"] = $this->get_lwf_employee($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["eer_lwf"] = $this->get_lwf_employer($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["tot_other_ded"] = $trans["monthly_tds"]+$trans["one_time_tds"]+$trans["fded"]+$trans["medi"]+$trans["saladv"]+$trans["oth_ded"]+ $trans["salary_loan"]+$trans["petty_cash"]+$trans["penalty"];
$trans["extra_ot"] = $this->rounding_value(($this->dz($trans["fixed_gross"]/$trans["md"]/8)*$trans["extra_hrs"]),'1');
$trans["earned_pf_er_share"] = $this->rounding_value(($this->dz($trans["pf_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_pf_admin"] = $this->rounding_value(($this->dz($trans["pf_admin_charge"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_esi_er_share"] = $this->rounding_value(($this->dz($trans["esi_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gpa"] = $this->rounding_value(($this->dz($trans["gpa"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gratuity"] = $this->rounding_value(($this->dz($trans["gratuity"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_ctc"] = $trans["eg"]+$trans["earned_pf_er_share"]+$trans["enps"]+$trans["efc"]+$trans["e_gratuity"]+$trans["earned_pf_admin"]+$trans["earned_esi_er_share"]+$trans["e_gpa"]+$trans["earned_gmc"]+$trans["earned_tele_reim"]+$trans["earned_driver_reim"]-$trans["driver_reim"]-$trans["tel_reim"];
$trans["total_earnings"] = $this->rounding_value(($trans["hra"]+$trans["basic"]+$trans["conv"]+$trans["lta"]+$trans["bns_adv"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["total_deductions"] = $this->rounding_value(($trans["petty_cash"]+$trans["penalty"]+$trans["esi"]+$trans["npra"]+$trans["one_time_tds"]+$trans["monthly_tds"]+$trans["pfamount"]+$trans["vpf"]+$trans["sw"]+$trans["ptax_two"]+$trans["fded"]+$trans["medi"]+$trans["ptax"]+$trans["lic"]+$trans["saladv"]+$trans["oth_ded"]+$trans["salary_loan"]+$trans["lwf"]),'1');
$trans["net_pay"] = $this->rounding_value(($trans["total_earnings"]-$trans["total_deductions"]),'1');
$payroll_array[9][] ="('".$trans["employees_id"]."','".$trans["transactions_month"]."','".$trans["total_earnings"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."',\"$logged_id\",\"$date\",\"$settlement_date\",\"1\",'".$trans["fixed_hra"]."','".$trans["flta"]."','".$trans["fconv"]."','".$trans["fbns_adv"]."','".$trans["ftconv"]."','".$trans["ffc"]."','".$trans["ftr"]."','".$trans["fdr"]."','".$trans["fnps"]."','".$trans["separation_day"]."','".$trans["differential_day"]."','".$trans["pd"]."','".$trans["fixed_gross"]."','".$trans["fb"]."','".$trans["tel_reim"]."','".$trans["driver_reim"]."','".$trans["sw"]."','".$trans["ptax_two"]."','".$trans["fded"]."','".$trans["medi"]."','".$trans["lic"]."','".$trans["saladv"]."','".$trans["oth_ded"]."','".$trans["pf_eligibility"]."','".$trans["gmc_in_ctc"]."','".$trans["esi_eligibility"]."','".$trans["vpf"]."','".$trans["monthly_tds"]."','".$trans["one_time_tds"]."','".$trans["pfsts"]."','".$trans["salary_loan"]."','".$trans["othrs"]."','".$trans["otrt"]."','".$trans["md"]."','".$trans["pf_er_share"]."','".$trans["pf_admin_charge"]."','".$trans["esi_er_share"]."','".$trans["gratuity"]."','".$trans["gpa"]."','".$trans["ctc"]."','".$trans["extra_hrs"]."','".$trans["penalty"]."','".$trans["petty_cash"]."','".$trans["earned_tele_reim"]."','".$trans["earned_driver_reim"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["lta"]."','".$trans["conv"]."','".$trans["bns_adv"]."','".$trans["etconv"]."','".$trans["efc"]."','".$trans["enps"]."','".$trans["pf_wages"]."','".$trans["pfamount"]."','".$trans["earned_gmc"]."','".$trans["fpf"]."','".$trans["epf"]."','".$trans["fpf_gross"]."','".$trans["fixed_pf"]."','".$trans["fpt_gross"]."','".$trans["ld"]."','".$trans["otamt"]."','".$trans["eg"]."','".$trans["ept_gross"]."','".$trans["ptax"]."','".$trans["esi_gross"]."','".$trans["employer_esi"]."','".$trans["esi"]."','".$trans["lwf_gross"]."','".$trans["lwf"]."','".$trans["eer_lwf"]."','".$trans["tot_other_ded"]."','".$trans["extra_ot"]."','".$trans["earned_pf_er_share"]."','".$trans["earned_pf_admin"]."','".$trans["earned_esi_er_share"]."','".$trans["e_gpa"]."','".$trans["e_gratuity"]."','".$trans["e_ctc"]."','".$trans["ptax_two_total"]."','".$trans["ptax_two_installments"]."','".$trans["ptax_two_instal_count"]."','".$trans["ptax_two_balance"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."','".$trans["petty_cash_total"]."','".$trans["petty_cash_installments"]."','".$trans["petty_cash_instal_count"]."','".$trans["petty_cash_balance"]."','".$trans["penalty_total"]."','".$trans["penalty_installments"]."','".$trans["penalty_instal_count"]."','".$trans["penalty_balance"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["branch"]."','".$trans["professional_tax_location"]."','".$trans["location"]."','".$trans["bank_account_number"]."','".$trans["bank_name"]."','".$trans["ifsc_code"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["cost_centre"]."','".$trans["grade"]."','".$trans["paymode"]."','".$trans["perarea"]."','".$trans["wbs"]."','".$trans["cat"]."')";
$qry_9 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,settlement_date,fandf,fixed_hra,flta,fconv,fbns_adv,ftconv,ffc,ftr,fdr,fnps,separation_day,differential_day,pd,fixed_gross,fb,tel_reim,driver_reim,sw,ptax_two,fded,medi,lic,saladv,oth_ded,pf_eligibility,gmc_in_ctc,esi_eligibility,vpf,monthly_tds,one_time_tds,pfsts,salary_loan,othrs,otrt,md,pf_er_share,pf_admin_charge,esi_er_share,gratuity,gpa,ctc,extra_hrs,penalty,petty_cash,earned_tele_reim,earned_driver_reim,basic,hra,lta,conv,bns_adv,etconv,efc,enps,pf_wages,pfamount,earned_gmc,fpf,epf,fpf_gross,fixed_pf,fpt_gross,ld,otamt,eg,ept_gross,ptax,esi_gross,employer_esi,esi,lwf_gross,lwf,eer_lwf,tot_other_ded,extra_ot,earned_pf_er_share,earned_pf_admin,earned_esi_er_share,e_gpa,e_gratuity,e_ctc,ptax_two_total,ptax_two_installments,ptax_two_instal_count,ptax_two_balance,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance,petty_cash_total,petty_cash_installments,petty_cash_instal_count,petty_cash_balance,penalty_total,penalty_installments,penalty_instal_count,penalty_balance,role,employee_code,emp_name,department,designation,date_of_joining,branch,professional_tax_location,location,bank_account_number,bank_name,ifsc_code,lwf_location,process_month,resignation_date,termination_status,payroll,cost_centre,grade,paymode,perarea,wbs,cat'.$trans_key_array.') VALUES '.implode(',',$payroll_array[9]);
}else
if((int)$trans["role"] === 7){
$trans["fixed_hra"] = $trans["fixed_hra"];
$trans["flta"] = $trans["flta"];
$trans["fconv"] = $trans["fconv"];
$trans["fbns_adv"] = $trans["fbns_adv"];
$trans["ftconv"] = $trans["ftconv"];
$trans["ffc"] = $trans["ffc"];
$trans["ftr"] = $trans["ftr"];
$trans["fdr"] = $trans["fdr"];
$trans["fnps"] = $trans["fnps"];
$trans["separation_day"] = $this->get_seperation_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["gmc_in_ctc"] = $trans["gmc_in_ctc"];
$trans["pd"] = $trans["pd"];
$trans["fixed_gross"] = $trans["fixed_gross"];
$trans["fb"] = $trans["fb"];
$trans["tel_reim"] = $this->rounding_value(($trans["tel_reim"]),'1');
$trans["driver_reim"] = $this->rounding_value(($trans["driver_reim"]),'1');
$trans["sw"] = $trans["sw"];
$trans["ptax_two"] = $trans["ptax_two"];
$trans["fded"] = $trans["fded"];
$trans["medi"] = $trans["medi"];
$trans["lic"] = $trans["lic"];
$trans["saladv"] = $trans["saladv"];
$trans["oth_ded"] = $trans["oth_ded"];
$trans["pf_eligibility"] = $trans["pf_eligibility"];
$trans["esi_eligibility"] = $trans["esi_eligibility"];
$trans["vpf"] = $trans["vpf"];
$trans["monthly_tds"] = $trans["monthly_tds"];
$trans["one_time_tds"] = $trans["one_time_tds"];
$trans["pfsts"] = $trans["pfsts"];
$trans["salary_loan"] = $trans["salary_loan"];
$trans["othrs"] = $trans["othrs"];
$trans["otrt"] = $trans["otrt"];
$trans["md"] = $this->get_total_work_days($trans["role"],$trans["transactions_month"]);
$trans["pf_er_share"] = $this->rounding_value(($trans["pf_er_share"]),'1');
$trans["pf_admin_charge"] = $this->rounding_value(($trans["pf_admin_charge"]),'1');
$trans["esi_er_share"] = $this->rounding_value(($trans["esi_er_share"]),'1');
$trans["gratuity"] = $this->rounding_value(($trans["gratuity"]),'1');
$trans["gpa"] = $this->rounding_value(($trans["gpa"]),'1');
$trans["ctc"] = $this->rounding_value(($trans["ctc"]),'1');
$trans["extra_hrs"] = $trans["extra_hrs"];
$trans["penalty"] = $trans["penalty"];
$trans["petty_cash"] = $trans["petty_cash"];
$trans["earned_tele_reim"] = $this->rounding_value(($this->dz($trans["ftr"]/ $trans["md"] )* $trans["pd"]),'1');
$trans["earned_driver_reim"] = $this->rounding_value(($this->dz($trans["fdr"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_gmc"] = $this->rounding_value(($this->dz($trans["gmc_in_ctc"]/$trans["md"])*$trans["pd"]),'1');
$trans["basic"] = $this->rounding_value(($this->dz($trans["fb"]/$trans["md"])*$trans["pd"]),'1');
$trans["hra"] = $this->rounding_value(($this->dz($trans["fixed_hra"]/$trans["md"])*$trans["pd"]),'1');
$trans["lta"] = $this->rounding_value(($this->dz($trans["flta"]/$trans["md"])*$trans["pd"]),'1');
$trans["conv"] = $this->rounding_value(($this->dz($trans["fconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["bns_adv"] = $this->rounding_value(($this->dz($trans["fbns_adv"]/$trans["md"])*$trans["pd"]),'1');
$trans["etconv"] = $this->rounding_value(($this->dz($trans["ftconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["efc"] = $this->rounding_value(($this->dz($trans["ffc"]/$trans["md"])*$trans["pd"]),'1');
$trans["enps"] = $this->rounding_value(($this->dz($trans["fnps"]/$trans["md"])*$trans["pd"]),'1');
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["basic"]>=15000){$trans["pf_wages"] = 15000;}else{$trans["pf_wages"] = $trans["basic"];}}else{$trans["pf_wages"] = 0;}
$trans["pfamount"] = $this->rounding_value(($trans["pf_wages"]*$this->dz(12/100)),'1');
// if$this->dz($trans["pf_wages"]>15000){$trans["fpf"] = 1250;}else{$trans["fpf"] = round$this->dz($trans["pf_wages"]*$this->dz(8.33/100),0);}
$trans["epf"] = $trans["pfamount"]-$trans["fpf"];
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["fb"]>=15000){$trans["fpf_gross"] = 15000;}else{$trans["fpf_gross"] = $trans["fb"];}}else{$trans["fpf_gross"] = 0;}
$trans["fixed_pf"] = $trans["fpf_gross"]*$this->dz(12/100);
$trans["fpt_gross"] = $trans["fixed_gross"];
$trans["ld"] = $trans["md"]-$trans["pd"]-$trans["differential_day"]-$trans["separation_day"];
$trans["otamt"] = $this->rounding_value((($trans["otrt"] * $trans["othrs"])),'1');
$trans["eg"] = $this->rounding_value(($trans["basic"]+$trans["lta"]+$trans["conv"]+$trans["bns_adv"]+$trans["hra"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["ept_gross"] = $trans["eg"];
$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);
if($trans["esi_eligibility"]==1){$trans["esi_gross"] = $trans["eg"];}else{$trans["esi_gross"] = 0;}
$trans["employer_esi"] = $this->rounding_value(($trans["esi_gross"]*$this->dz(3.25/100)),'1');
// if$this->dz($trans["fixed_gross"]>=5280){$trans["esi"] = ceil$this->dz($trans["esi_gross"]*$this->dz(0.75/100));}else{$trans["esi"] = 0;}
$trans["tot_other_ded"] = $trans["monthly_tds"]+$trans["one_time_tds"]+$trans["fded"]+$trans["medi"]+$trans["saladv"]+$trans["oth_ded"]+ $trans["salary_loan"]+$trans["petty_cash"]+$trans["penalty"];
$trans["lwf_gross"] = $trans["eg"];
$trans["lwf"] = $this->get_lwf_employee($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["eer_lwf"] = $this->get_lwf_employer($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["extra_ot"] = $this->rounding_value(($this->dz($trans["fixed_gross"]/$trans["md"]/8)*$trans["extra_hrs"]),'1');
$trans["earned_pf_er_share"] = $this->rounding_value(($this->dz($trans["pf_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_pf_admin"] = $this->rounding_value(($this->dz($trans["pf_admin_charge"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_esi_er_share"] = $this->rounding_value(($this->dz($trans["esi_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gpa"] = $this->rounding_value(($this->dz($trans["gpa"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gratuity"] = $this->rounding_value(($this->dz($trans["gratuity"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_ctc"] = $trans["eg"]+$trans["earned_pf_er_share"]+$trans["enps"]+$trans["efc"]+$trans["e_gratuity"]+$trans["earned_pf_admin"]+$trans["earned_esi_er_share"]+$trans["e_gpa"]+$trans["earned_gmc"]+$trans["earned_tele_reim"]+$trans["earned_driver_reim"]-$trans["driver_reim"]-$trans["tel_reim"];
$trans["total_earnings"] = $this->rounding_value(($trans["hra"]+$trans["basic"]+$trans["conv"]+$trans["lta"]+$trans["bns_adv"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["total_deductions"] = $this->rounding_value(($trans["petty_cash"]+$trans["penalty"]+$trans["esi"]+$trans["npra"]+$trans["one_time_tds"]+$trans["monthly_tds"]+$trans["pfamount"]+$trans["vpf"]+$trans["sw"]+$trans["ptax_two"]+$trans["fded"]+$trans["medi"]+$trans["ptax"]+$trans["lic"]+$trans["saladv"]+$trans["oth_ded"]+$trans["salary_loan"]+$trans["lwf"]),'1');
$trans["net_pay"] = $this->rounding_value(($trans["total_earnings"]-$trans["total_deductions"]),'1');
$payroll_array[7][] ="('".$trans["employees_id"]."','".$trans["transactions_month"]."','".$trans["total_earnings"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."',\"$logged_id\",\"$date\",\"$settlement_date\",\"1\",'".$trans["fixed_hra"]."','".$trans["flta"]."','".$trans["fconv"]."','".$trans["fbns_adv"]."','".$trans["ftconv"]."','".$trans["ffc"]."','".$trans["ftr"]."','".$trans["fdr"]."','".$trans["fnps"]."','".$trans["separation_day"]."','".$trans["differential_day"]."','".$trans["gmc_in_ctc"]."','".$trans["pd"]."','".$trans["fixed_gross"]."','".$trans["fb"]."','".$trans["tel_reim"]."','".$trans["driver_reim"]."','".$trans["sw"]."','".$trans["ptax_two"]."','".$trans["fded"]."','".$trans["medi"]."','".$trans["lic"]."','".$trans["saladv"]."','".$trans["oth_ded"]."','".$trans["pf_eligibility"]."','".$trans["esi_eligibility"]."','".$trans["vpf"]."','".$trans["monthly_tds"]."','".$trans["one_time_tds"]."','".$trans["pfsts"]."','".$trans["salary_loan"]."','".$trans["othrs"]."','".$trans["otrt"]."','".$trans["md"]."','".$trans["pf_er_share"]."','".$trans["pf_admin_charge"]."','".$trans["esi_er_share"]."','".$trans["gratuity"]."','".$trans["gpa"]."','".$trans["ctc"]."','".$trans["extra_hrs"]."','".$trans["penalty"]."','".$trans["petty_cash"]."','".$trans["earned_tele_reim"]."','".$trans["earned_driver_reim"]."','".$trans["earned_gmc"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["lta"]."','".$trans["conv"]."','".$trans["bns_adv"]."','".$trans["etconv"]."','".$trans["efc"]."','".$trans["enps"]."','".$trans["pf_wages"]."','".$trans["pfamount"]."','".$trans["fpf"]."','".$trans["epf"]."','".$trans["fpf_gross"]."','".$trans["fixed_pf"]."','".$trans["fpt_gross"]."','".$trans["ld"]."','".$trans["otamt"]."','".$trans["eg"]."','".$trans["ept_gross"]."','".$trans["ptax"]."','".$trans["esi_gross"]."','".$trans["employer_esi"]."','".$trans["esi"]."','".$trans["tot_other_ded"]."','".$trans["lwf_gross"]."','".$trans["lwf"]."','".$trans["eer_lwf"]."','".$trans["extra_ot"]."','".$trans["earned_pf_er_share"]."','".$trans["earned_pf_admin"]."','".$trans["earned_esi_er_share"]."','".$trans["e_gpa"]."','".$trans["e_gratuity"]."','".$trans["e_ctc"]."','".$trans["ptax_two_total"]."','".$trans["ptax_two_installments"]."','".$trans["ptax_two_instal_count"]."','".$trans["ptax_two_balance"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."','".$trans["petty_cash_total"]."','".$trans["petty_cash_installments"]."','".$trans["petty_cash_instal_count"]."','".$trans["petty_cash_balance"]."','".$trans["penalty_total"]."','".$trans["penalty_installments"]."','".$trans["penalty_instal_count"]."','".$trans["penalty_balance"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["branch"]."','".$trans["professional_tax_location"]."','".$trans["location"]."','".$trans["bank_account_number"]."','".$trans["bank_name"]."','".$trans["ifsc_code"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["cost_centre"]."','".$trans["grade"]."','".$trans["paymode"]."','".$trans["perarea"]."','".$trans["wbs"]."','".$trans["cat"]."')";
$qry_7 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,settlement_date,fandf,fixed_hra,flta,fconv,fbns_adv,ftconv,ffc,ftr,fdr,fnps,separation_day,differential_day,gmc_in_ctc,pd,fixed_gross,fb,tel_reim,driver_reim,sw,ptax_two,fded,medi,lic,saladv,oth_ded,pf_eligibility,esi_eligibility,vpf,monthly_tds,one_time_tds,pfsts,salary_loan,othrs,otrt,md,pf_er_share,pf_admin_charge,esi_er_share,gratuity,gpa,ctc,extra_hrs,penalty,petty_cash,earned_tele_reim,earned_driver_reim,earned_gmc,basic,hra,lta,conv,bns_adv,etconv,efc,enps,pf_wages,pfamount,fpf,epf,fpf_gross,fixed_pf,fpt_gross,ld,otamt,eg,ept_gross,ptax,esi_gross,employer_esi,esi,tot_other_ded,lwf_gross,lwf,eer_lwf,extra_ot,earned_pf_er_share,earned_pf_admin,earned_esi_er_share,e_gpa,e_gratuity,e_ctc,ptax_two_total,ptax_two_installments,ptax_two_instal_count,ptax_two_balance,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance,petty_cash_total,petty_cash_installments,petty_cash_instal_count,petty_cash_balance,penalty_total,penalty_installments,penalty_instal_count,penalty_balance,role,employee_code,emp_name,department,designation,date_of_joining,branch,professional_tax_location,location,bank_account_number,bank_name,ifsc_code,lwf_location,process_month,resignation_date,termination_status,payroll,cost_centre,grade,paymode,perarea,wbs,cat'.$trans_key_array.') VALUES '.implode(',',$payroll_array[7]);
}else
if((int)$trans["role"] === 10){
$trans["fb"] = $trans["fb"];
$trans["gmc_in_ctc"] = $trans["gmc_in_ctc"];
$trans["driver_reim"] = $this->rounding_value(($trans["driver_reim"]),'1');
$trans["tel_reim"] = $this->rounding_value(($trans["tel_reim"]),'1');
$trans["fixed_hra"] = $trans["fixed_hra"];
$trans["flta"] = $trans["flta"];
$trans["fconv"] = $trans["fconv"];
$trans["fbns_adv"] = $trans["fbns_adv"];
$trans["ftconv"] = $trans["ftconv"];
$trans["ffc"] = $trans["ffc"];
$trans["ftr"] = $trans["ftr"];
$trans["fdr"] = $trans["fdr"];
$trans["fnps"] = $trans["fnps"];
$trans["separation_day"] = $this->get_seperation_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["pd"] = $trans["pd"];
$trans["fixed_gross"] = $trans["fixed_gross"];
$trans["sw"] = $trans["sw"];
$trans["ptax_two"] = $trans["ptax_two"];
$trans["fded"] = $trans["fded"];
$trans["medi"] = $trans["medi"];
$trans["lic"] = $trans["lic"];
$trans["saladv"] = $trans["saladv"];
$trans["oth_ded"] = $trans["oth_ded"];
$trans["pf_eligibility"] = $trans["pf_eligibility"];
$trans["esi_eligibility"] = $trans["esi_eligibility"];
$trans["vpf"] = $trans["vpf"];
$trans["monthly_tds"] = $trans["monthly_tds"];
$trans["one_time_tds"] = $trans["one_time_tds"];
$trans["pfsts"] = $trans["pfsts"];
$trans["salary_loan"] = $trans["salary_loan"];
$trans["othrs"] = $trans["othrs"];
$trans["otrt"] = $trans["otrt"];
$trans["md"] = $this->get_total_work_days($trans["role"],$trans["transactions_month"]);
$trans["pf_er_share"] = $this->rounding_value(($trans["pf_er_share"]),'1');
$trans["pf_admin_charge"] = $this->rounding_value(($trans["pf_admin_charge"]),'1');
$trans["esi_er_share"] = $this->rounding_value(($trans["esi_er_share"]),'1');
$trans["gratuity"] = $this->rounding_value(($trans["gratuity"]),'1');
$trans["gpa"] = $this->rounding_value(($trans["gpa"]),'1');
$trans["ctc"] = $this->rounding_value(($trans["ctc"]),'1');
$trans["extra_hrs"] = $trans["extra_hrs"];
$trans["penalty"] = $trans["penalty"];
$trans["petty_cash"] = $trans["petty_cash"];
$trans["earned_tele_reim"] = $this->rounding_value(($this->dz($trans["ftr"]/ $trans["md"] )* $trans["pd"]),'1');
$trans["earned_driver_reim"] = $this->rounding_value(($this->dz($trans["fdr"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_gmc"] = $this->rounding_value(($this->dz($trans["gmc_in_ctc"]/$trans["md"])*$trans["pd"]),'1');
$trans["tot_other_ded"] = $trans["monthly_tds"]+$trans["one_time_tds"]+$trans["fded"]+$trans["medi"]+$trans["saladv"]+$trans["oth_ded"]+ $trans["salary_loan"]+$trans["petty_cash"]+$trans["penalty"];
$trans["basic"] = $this->rounding_value(($this->dz($trans["fb"]/$trans["md"])*$trans["pd"]),'1');
$trans["hra"] = $this->rounding_value(($this->dz($trans["fixed_hra"]/$trans["md"])*$trans["pd"]),'1');
$trans["lta"] = $this->rounding_value(($this->dz($trans["flta"]/$trans["md"])*$trans["pd"]),'1');
$trans["conv"] = $this->rounding_value(($this->dz($trans["fconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["bns_adv"] = $this->rounding_value(($this->dz($trans["fbns_adv"]/$trans["md"])*$trans["pd"]),'1');
$trans["etconv"] = $this->rounding_value(($this->dz($trans["ftconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["efc"] = $this->rounding_value(($this->dz($trans["ffc"]/$trans["md"])*$trans["pd"]),'1');
$trans["enps"] = $this->rounding_value(($this->dz($trans["fnps"]/$trans["md"])*$trans["pd"]),'1');
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["basic"]>=15000){$trans["pf_wages"] = 15000;}else{$trans["pf_wages"] = $trans["basic"];}}else{$trans["pf_wages"] = 0;}
$trans["pfamount"] = $this->rounding_value(($trans["pf_wages"]*$this->dz(12/100)),'1');
// if$this->dz($trans["pf_wages"]>15000){$trans["fpf"] = 1250;}else{$trans["fpf"] = round$this->dz($trans["pf_wages"]*$this->dz(8.33/100),0);}
$trans["epf"] = $trans["pfamount"]-$trans["fpf"];
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["fb"]>=15000){$trans["fpf_gross"] = 15000;}else{$trans["fpf_gross"] = $trans["fb"];}}else{$trans["fpf_gross"] = 0;}
$trans["fixed_pf"] = $trans["fpf_gross"]*$this->dz(12/100);
$trans["fpt_gross"] = $trans["fixed_gross"];
$trans["ld"] = $trans["md"]-$trans["pd"]-$trans["differential_day"]-$trans["separation_day"];
$trans["otamt"] = $this->rounding_value((($trans["otrt"] * $trans["othrs"])),'1');
$trans["eg"] = $this->rounding_value(($trans["basic"]+$trans["lta"]+$trans["conv"]+$trans["bns_adv"]+$trans["hra"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["ept_gross"] = $trans["eg"];
$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);
if($trans["esi_eligibility"]==1){$trans["esi_gross"] = $trans["eg"];}else{$trans["esi_gross"] = 0;}
$trans["employer_esi"] = $this->rounding_value(($trans["esi_gross"]*$this->dz(3.25/100)),'1');
// if$this->dz($trans["fixed_gross"]>=5280){$trans["esi"] = ceil$this->dz($trans["esi_gross"]*$this->dz(0.75/100));}else{$trans["esi"] = 0;}
$trans["lwf_gross"] = $trans["eg"];
$trans["lwf"] = $this->get_lwf_employee($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["eer_lwf"] = $this->get_lwf_employer($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["extra_ot"] = $this->rounding_value(($this->dz($trans["fixed_gross"]/$trans["md"]/8)*$trans["extra_hrs"]),'1');
$trans["earned_pf_er_share"] = $this->rounding_value(($this->dz($trans["pf_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_pf_admin"] = $this->rounding_value(($this->dz($trans["pf_admin_charge"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_esi_er_share"] = $this->rounding_value(($this->dz($trans["esi_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gpa"] = $this->rounding_value(($this->dz($trans["gpa"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gratuity"] = $this->rounding_value(($this->dz($trans["gratuity"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_ctc"] = $trans["eg"]+$trans["earned_pf_er_share"]+$trans["enps"]+$trans["efc"]+$trans["e_gratuity"]+$trans["earned_pf_admin"]+$trans["earned_esi_er_share"]+$trans["e_gpa"]+$trans["earned_gmc"]+$trans["earned_tele_reim"]+$trans["earned_driver_reim"]-$trans["driver_reim"]-$trans["tel_reim"];
$trans["total_earnings"] = $this->rounding_value(($trans["hra"]+$trans["basic"]+$trans["conv"]+$trans["lta"]+$trans["bns_adv"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["total_deductions"] = $this->rounding_value(($trans["petty_cash"]+$trans["penalty"]+$trans["esi"]+$trans["npra"]+$trans["one_time_tds"]+$trans["monthly_tds"]+$trans["pfamount"]+$trans["vpf"]+$trans["sw"]+$trans["ptax_two"]+$trans["fded"]+$trans["medi"]+$trans["ptax"]+$trans["lic"]+$trans["saladv"]+$trans["oth_ded"]+$trans["salary_loan"]+$trans["lwf"]),'1');
$trans["net_pay"] = $this->rounding_value(($trans["total_earnings"]-$trans["total_deductions"]),'1');
$payroll_array[10][] ="('".$trans["employees_id"]."','".$trans["transactions_month"]."','".$trans["total_earnings"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."',\"$logged_id\",\"$date\",\"$settlement_date\",\"1\",'".$trans["fb"]."','".$trans["gmc_in_ctc"]."','".$trans["driver_reim"]."','".$trans["tel_reim"]."','".$trans["fixed_hra"]."','".$trans["flta"]."','".$trans["fconv"]."','".$trans["fbns_adv"]."','".$trans["ftconv"]."','".$trans["ffc"]."','".$trans["ftr"]."','".$trans["fdr"]."','".$trans["fnps"]."','".$trans["separation_day"]."','".$trans["differential_day"]."','".$trans["pd"]."','".$trans["fixed_gross"]."','".$trans["sw"]."','".$trans["ptax_two"]."','".$trans["fded"]."','".$trans["medi"]."','".$trans["lic"]."','".$trans["saladv"]."','".$trans["oth_ded"]."','".$trans["pf_eligibility"]."','".$trans["esi_eligibility"]."','".$trans["vpf"]."','".$trans["monthly_tds"]."','".$trans["one_time_tds"]."','".$trans["pfsts"]."','".$trans["salary_loan"]."','".$trans["othrs"]."','".$trans["otrt"]."','".$trans["md"]."','".$trans["pf_er_share"]."','".$trans["pf_admin_charge"]."','".$trans["esi_er_share"]."','".$trans["gratuity"]."','".$trans["gpa"]."','".$trans["ctc"]."','".$trans["extra_hrs"]."','".$trans["penalty"]."','".$trans["petty_cash"]."','".$trans["earned_tele_reim"]."','".$trans["earned_driver_reim"]."','".$trans["earned_gmc"]."','".$trans["tot_other_ded"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["lta"]."','".$trans["conv"]."','".$trans["bns_adv"]."','".$trans["etconv"]."','".$trans["efc"]."','".$trans["enps"]."','".$trans["pf_wages"]."','".$trans["pfamount"]."','".$trans["fpf"]."','".$trans["epf"]."','".$trans["fpf_gross"]."','".$trans["fixed_pf"]."','".$trans["fpt_gross"]."','".$trans["ld"]."','".$trans["otamt"]."','".$trans["eg"]."','".$trans["ept_gross"]."','".$trans["ptax"]."','".$trans["esi_gross"]."','".$trans["employer_esi"]."','".$trans["esi"]."','".$trans["lwf_gross"]."','".$trans["lwf"]."','".$trans["eer_lwf"]."','".$trans["extra_ot"]."','".$trans["earned_pf_er_share"]."','".$trans["earned_pf_admin"]."','".$trans["earned_esi_er_share"]."','".$trans["e_gpa"]."','".$trans["e_gratuity"]."','".$trans["e_ctc"]."','".$trans["ptax_two_total"]."','".$trans["ptax_two_installments"]."','".$trans["ptax_two_instal_count"]."','".$trans["ptax_two_balance"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."','".$trans["petty_cash_total"]."','".$trans["petty_cash_installments"]."','".$trans["petty_cash_instal_count"]."','".$trans["petty_cash_balance"]."','".$trans["penalty_total"]."','".$trans["penalty_installments"]."','".$trans["penalty_instal_count"]."','".$trans["penalty_balance"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["branch"]."','".$trans["professional_tax_location"]."','".$trans["location"]."','".$trans["bank_account_number"]."','".$trans["bank_name"]."','".$trans["ifsc_code"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["cost_centre"]."','".$trans["grade"]."','".$trans["paymode"]."','".$trans["perarea"]."','".$trans["wbs"]."','".$trans["cat"]."')";
$qry_10 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,settlement_date,fandf,fb,gmc_in_ctc,driver_reim,tel_reim,fixed_hra,flta,fconv,fbns_adv,ftconv,ffc,ftr,fdr,fnps,separation_day,differential_day,pd,fixed_gross,sw,ptax_two,fded,medi,lic,saladv,oth_ded,pf_eligibility,esi_eligibility,vpf,monthly_tds,one_time_tds,pfsts,salary_loan,othrs,otrt,md,pf_er_share,pf_admin_charge,esi_er_share,gratuity,gpa,ctc,extra_hrs,penalty,petty_cash,earned_tele_reim,earned_driver_reim,earned_gmc,tot_other_ded,basic,hra,lta,conv,bns_adv,etconv,efc,enps,pf_wages,pfamount,fpf,epf,fpf_gross,fixed_pf,fpt_gross,ld,otamt,eg,ept_gross,ptax,esi_gross,employer_esi,esi,lwf_gross,lwf,eer_lwf,extra_ot,earned_pf_er_share,earned_pf_admin,earned_esi_er_share,e_gpa,e_gratuity,e_ctc,ptax_two_total,ptax_two_installments,ptax_two_instal_count,ptax_two_balance,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance,petty_cash_total,petty_cash_installments,petty_cash_instal_count,petty_cash_balance,penalty_total,penalty_installments,penalty_instal_count,penalty_balance,role,employee_code,emp_name,department,designation,date_of_joining,branch,professional_tax_location,location,bank_account_number,bank_name,ifsc_code,lwf_location,process_month,resignation_date,termination_status,payroll,cost_centre,grade,paymode,perarea,wbs,cat'.$trans_key_array.') VALUES '.implode(',',$payroll_array[10]);
}else
if((int)$trans["role"] === 8){
$trans["fb"] = $trans["fb"];
$trans["gmc_in_ctc"] = $trans["gmc_in_ctc"];
$trans["fixed_hra"] = $trans["fixed_hra"];
$trans["flta"] = $trans["flta"];
$trans["fconv"] = $trans["fconv"];
$trans["fbns_adv"] = $trans["fbns_adv"];
$trans["ftconv"] = $trans["ftconv"];
$trans["ffc"] = $trans["ffc"];
$trans["ftr"] = $trans["ftr"];
$trans["fdr"] = $trans["fdr"];
$trans["fnps"] = $trans["fnps"];
$trans["separation_day"] = $this->get_seperation_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["pd"] = $trans["pd"];
$trans["fixed_gross"] = $trans["fixed_gross"];
$trans["tel_reim"] = $this->rounding_value(($trans["tel_reim"]),'1');
$trans["driver_reim"] = $this->rounding_value(($trans["driver_reim"]),'1');
$trans["sw"] = $trans["sw"];
$trans["ptax_two"] = $trans["ptax_two"];
$trans["fded"] = $trans["fded"];
$trans["medi"] = $trans["medi"];
$trans["lic"] = $trans["lic"];
$trans["saladv"] = $trans["saladv"];
$trans["oth_ded"] = $trans["oth_ded"];
$trans["pf_eligibility"] = $trans["pf_eligibility"];
$trans["esi_eligibility"] = $trans["esi_eligibility"];
$trans["vpf"] = $trans["vpf"];
$trans["monthly_tds"] = $trans["monthly_tds"];
$trans["one_time_tds"] = $trans["one_time_tds"];
$trans["pfsts"] = $trans["pfsts"];
$trans["salary_loan"] = $trans["salary_loan"];
$trans["othrs"] = $trans["othrs"];
$trans["otrt"] = $trans["otrt"];
$trans["md"] = $this->get_total_work_days($trans["role"],$trans["transactions_month"]);
$trans["pf_er_share"] = $this->rounding_value(($trans["pf_er_share"]),'1');
$trans["pf_admin_charge"] = $this->rounding_value(($trans["pf_admin_charge"]),'1');
$trans["esi_er_share"] = $this->rounding_value(($trans["esi_er_share"]),'1');
$trans["gratuity"] = $this->rounding_value(($trans["gratuity"]),'1');
$trans["gpa"] = $this->rounding_value(($trans["gpa"]),'1');
$trans["ctc"] = $this->rounding_value(($trans["ctc"]),'1');
$trans["extra_hrs"] = $trans["extra_hrs"];
$trans["penalty"] = $trans["penalty"];
$trans["petty_cash"] = $trans["petty_cash"];
$trans["earned_tele_reim"] = $this->rounding_value(($this->dz($trans["ftr"]/ $trans["md"] )* $trans["pd"]),'1');
$trans["earned_driver_reim"] = $this->rounding_value(($this->dz($trans["fdr"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_gmc"] = $this->rounding_value(($this->dz($trans["gmc_in_ctc"]/$trans["md"])*$trans["pd"]),'1');
$trans["tot_other_ded"] = $trans["monthly_tds"]+$trans["one_time_tds"]+$trans["fded"]+$trans["medi"]+$trans["saladv"]+$trans["oth_ded"]+ $trans["salary_loan"]+$trans["petty_cash"]+$trans["penalty"];
$trans["basic"] = $this->rounding_value(($this->dz($trans["fb"]/$trans["md"])*$trans["pd"]),'1');
$trans["hra"] = $this->rounding_value(($this->dz($trans["fixed_hra"]/$trans["md"])*$trans["pd"]),'1');
$trans["lta"] = $this->rounding_value(($this->dz($trans["flta"]/$trans["md"])*$trans["pd"]),'1');
$trans["conv"] = $this->rounding_value(($this->dz($trans["fconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["bns_adv"] = $this->rounding_value(($this->dz($trans["fbns_adv"]/$trans["md"])*$trans["pd"]),'1');
$trans["etconv"] = $this->rounding_value(($this->dz($trans["ftconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["efc"] = $this->rounding_value(($this->dz($trans["ffc"]/$trans["md"])*$trans["pd"]),'1');
$trans["enps"] = $this->rounding_value(($this->dz($trans["fnps"]/$trans["md"])*$trans["pd"]),'1');
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["basic"]>=15000){$trans["pf_wages"] = 15000;}else{$trans["pf_wages"] = $trans["basic"];}}else{$trans["pf_wages"] = 0;}
$trans["pfamount"] = $this->rounding_value(($trans["pf_wages"]*$this->dz(12/100)),'1');
// if$this->dz($trans["pf_wages"]>15000){$trans["fpf"] = 1250;}else{$trans["fpf"] = round$this->dz($trans["pf_wages"]*$this->dz(8.33/100),0);}
$trans["epf"] = $trans["pfamount"]-$trans["fpf"];
if((int)$trans["pf_eligibility"]==1){if($trans["pfsts"]==1&&$trans["fb"]>=15000){$trans["fpf_gross"] = 15000;}else{$trans["fpf_gross"] = $trans["fb"];}}else{$trans["fpf_gross"] = 0;}
$trans["fixed_pf"] = $trans["fpf_gross"]*$this->dz(12/100);
$trans["fpt_gross"] = $trans["fixed_gross"];
$trans["ld"] = $trans["md"]-$trans["pd"]-$trans["differential_day"]-$trans["separation_day"];
$trans["otamt"] = $this->rounding_value((($trans["otrt"] * $trans["othrs"])),'1');
$trans["eg"] = $this->rounding_value(($trans["basic"]+$trans["lta"]+$trans["conv"]+$trans["bns_adv"]+$trans["hra"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["ept_gross"] = $trans["eg"];
$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);
if($trans["esi_eligibility"]==1){$trans["esi_gross"] = $trans["eg"];}else{$trans["esi_gross"] = 0;}
$trans["employer_esi"] = $this->rounding_value(($trans["esi_gross"]*$this->dz(3.25/100)),'1');
// if$this->dz($trans["fixed_gross"]>=5280){$trans["esi"] = ceil$this->dz($trans["esi_gross"]*$this->dz(0.75/100));}else{$trans["esi"] = 0;}
$trans["lwf_gross"] = $trans["eg"];
$trans["lwf"] = $this->get_lwf_employee($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["eer_lwf"] = $this->get_lwf_employer($trans["employee_code"],$trans["lwf_location"],$trans["lwf_gross"],$trans["transactions_month"]);
$trans["extra_ot"] = $this->rounding_value(($this->dz($trans["fixed_gross"]/$trans["md"]/8)*$trans["extra_hrs"]),'1');
$trans["earned_pf_er_share"] = $this->rounding_value(($this->dz($trans["pf_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_pf_admin"] = $this->rounding_value(($this->dz($trans["pf_admin_charge"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_esi_er_share"] = $this->rounding_value(($this->dz($trans["esi_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gpa"] = $this->rounding_value(($this->dz($trans["gpa"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gratuity"] = $this->rounding_value(($this->dz($trans["gratuity"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_ctc"] = $trans["eg"]+$trans["earned_pf_er_share"]+$trans["enps"]+$trans["efc"]+$trans["e_gratuity"]+$trans["earned_pf_admin"]+$trans["earned_esi_er_share"]+$trans["e_gpa"]+$trans["earned_gmc"]+$trans["earned_tele_reim"]+$trans["earned_driver_reim"]-$trans["driver_reim"]-$trans["tel_reim"];
$trans["total_earnings"] = $this->rounding_value(($trans["hra"]+$trans["basic"]+$trans["conv"]+$trans["lta"]+$trans["bns_adv"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["total_deductions"] = $this->rounding_value(($trans["petty_cash"]+$trans["penalty"]+$trans["esi"]+$trans["npra"]+$trans["one_time_tds"]+$trans["monthly_tds"]+$trans["pfamount"]+$trans["vpf"]+$trans["sw"]+$trans["ptax_two"]+$trans["fded"]+$trans["medi"]+$trans["ptax"]+$trans["lic"]+$trans["saladv"]+$trans["oth_ded"]+$trans["salary_loan"]+$trans["lwf"]),'1');
$trans["net_pay"] = $this->rounding_value(($trans["total_earnings"]-$trans["total_deductions"]),'1');
$payroll_array[8][] ="('".$trans["employees_id"]."','".$trans["transactions_month"]."','".$trans["total_earnings"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."',\"$logged_id\",\"$date\",\"$settlement_date\",\"1\",'".$trans["fb"]."','".$trans["gmc_in_ctc"]."','".$trans["fixed_hra"]."','".$trans["flta"]."','".$trans["fconv"]."','".$trans["fbns_adv"]."','".$trans["ftconv"]."','".$trans["ffc"]."','".$trans["ftr"]."','".$trans["fdr"]."','".$trans["fnps"]."','".$trans["separation_day"]."','".$trans["differential_day"]."','".$trans["pd"]."','".$trans["fixed_gross"]."','".$trans["tel_reim"]."','".$trans["driver_reim"]."','".$trans["sw"]."','".$trans["ptax_two"]."','".$trans["fded"]."','".$trans["medi"]."','".$trans["lic"]."','".$trans["saladv"]."','".$trans["oth_ded"]."','".$trans["pf_eligibility"]."','".$trans["esi_eligibility"]."','".$trans["vpf"]."','".$trans["monthly_tds"]."','".$trans["one_time_tds"]."','".$trans["pfsts"]."','".$trans["salary_loan"]."','".$trans["othrs"]."','".$trans["otrt"]."','".$trans["md"]."','".$trans["pf_er_share"]."','".$trans["pf_admin_charge"]."','".$trans["esi_er_share"]."','".$trans["gratuity"]."','".$trans["gpa"]."','".$trans["ctc"]."','".$trans["extra_hrs"]."','".$trans["penalty"]."','".$trans["petty_cash"]."','".$trans["earned_tele_reim"]."','".$trans["earned_driver_reim"]."','".$trans["earned_gmc"]."','".$trans["tot_other_ded"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["lta"]."','".$trans["conv"]."','".$trans["bns_adv"]."','".$trans["etconv"]."','".$trans["efc"]."','".$trans["enps"]."','".$trans["pf_wages"]."','".$trans["pfamount"]."','".$trans["fpf"]."','".$trans["epf"]."','".$trans["fpf_gross"]."','".$trans["fixed_pf"]."','".$trans["fpt_gross"]."','".$trans["ld"]."','".$trans["otamt"]."','".$trans["eg"]."','".$trans["ept_gross"]."','".$trans["ptax"]."','".$trans["esi_gross"]."','".$trans["employer_esi"]."','".$trans["esi"]."','".$trans["lwf_gross"]."','".$trans["lwf"]."','".$trans["eer_lwf"]."','".$trans["extra_ot"]."','".$trans["earned_pf_er_share"]."','".$trans["earned_pf_admin"]."','".$trans["earned_esi_er_share"]."','".$trans["e_gpa"]."','".$trans["e_gratuity"]."','".$trans["e_ctc"]."','".$trans["ptax_two_total"]."','".$trans["ptax_two_installments"]."','".$trans["ptax_two_instal_count"]."','".$trans["ptax_two_balance"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."','".$trans["petty_cash_total"]."','".$trans["petty_cash_installments"]."','".$trans["petty_cash_instal_count"]."','".$trans["petty_cash_balance"]."','".$trans["penalty_total"]."','".$trans["penalty_installments"]."','".$trans["penalty_instal_count"]."','".$trans["penalty_balance"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["branch"]."','".$trans["professional_tax_location"]."','".$trans["location"]."','".$trans["bank_account_number"]."','".$trans["bank_name"]."','".$trans["ifsc_code"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["cost_centre"]."','".$trans["grade"]."','".$trans["paymode"]."','".$trans["perarea"]."','".$trans["wbs"]."','".$trans["cat"]."')";
$qry_8 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,settlement_date,fandf,fb,gmc_in_ctc,fixed_hra,flta,fconv,fbns_adv,ftconv,ffc,ftr,fdr,fnps,separation_day,differential_day,pd,fixed_gross,tel_reim,driver_reim,sw,ptax_two,fded,medi,lic,saladv,oth_ded,pf_eligibility,esi_eligibility,vpf,monthly_tds,one_time_tds,pfsts,salary_loan,othrs,otrt,md,pf_er_share,pf_admin_charge,esi_er_share,gratuity,gpa,ctc,extra_hrs,penalty,petty_cash,earned_tele_reim,earned_driver_reim,earned_gmc,tot_other_ded,basic,hra,lta,conv,bns_adv,etconv,efc,enps,pf_wages,pfamount,fpf,epf,fpf_gross,fixed_pf,fpt_gross,ld,otamt,eg,ept_gross,ptax,esi_gross,employer_esi,esi,lwf_gross,lwf,eer_lwf,extra_ot,earned_pf_er_share,earned_pf_admin,earned_esi_er_share,e_gpa,e_gratuity,e_ctc,ptax_two_total,ptax_two_installments,ptax_two_instal_count,ptax_two_balance,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance,petty_cash_total,petty_cash_installments,petty_cash_instal_count,petty_cash_balance,penalty_total,penalty_installments,penalty_instal_count,penalty_balance,role,employee_code,emp_name,department,designation,date_of_joining,branch,professional_tax_location,location,bank_account_number,bank_name,ifsc_code,lwf_location,process_month,resignation_date,termination_status,payroll,cost_centre,grade,paymode,perarea,wbs,cat'.$trans_key_array.') VALUES '.implode(',',$payroll_array[8]);
}else
if((int)$trans["role"] === 4){
$trans["one_time_tds"] = $this->rounding_value(($trans["one_time_tds"]),'1');
$trans["gmc_in_ctc"] = $trans["gmc_in_ctc"];
$trans["petty_cash"] = $trans["petty_cash"];
$trans["monthly_tds"] = $trans["monthly_tds"];
$trans["penalty"] = $trans["penalty"];
$trans["fb"] = $trans["fb"];
$trans["fixed_hra"] = $trans["fixed_hra"];
$trans["flta"] = $trans["flta"];
$trans["fconv"] = $trans["fconv"];
$trans["fbns_adv"] = $trans["fbns_adv"];
$trans["ftconv"] = $trans["ftconv"];
$trans["ffc"] = $trans["ffc"];
$trans["ftr"] = $trans["ftr"];
$trans["fdr"] = $trans["fdr"];
$trans["fnps"] = $trans["fnps"];
$trans["md"] = $this->get_total_work_days($trans["role"],$trans["transactions_month"]);
$trans["separation_day"] = $this->get_seperation_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);
$trans["pd"] = $trans["pd"];
$trans["fixed_gross"] = $trans["fixed_gross"];
$trans["tel_reim"] = $this->rounding_value(($trans["tel_reim"]),'1');
$trans["driver_reim"] = $this->rounding_value(( $trans["driver_reim"]),'1');
$trans["sw"] = $trans["sw"];
$trans["ptax_two"] = $trans["ptax_two"];
$trans["fded"] = $trans["fded"];
$trans["medi"] = $trans["medi"];
$trans["lic"] = $trans["lic"];
$trans["saladv"] = $trans["saladv"];
$trans["oth_ded"] = $trans["oth_ded"];
$trans["pf_eligibility"] = $trans["pf_eligibility"];
$trans["salary_loan"] = $trans["salary_loan"];
$trans["pf_er_share"] = $this->rounding_value(($trans["pf_er_share"]),'1');
$trans["pf_admin_charge"] = $this->rounding_value(($trans["pf_admin_charge"]),'1');
$trans["esi_er_share"] = $this->rounding_value(($trans["esi_er_share"]),'1');
$trans["gratuity"] = $this->rounding_value(($trans["gratuity"]),'1');
$trans["gpa"] = $this->rounding_value(($trans["gpa"]),'1');
$trans["ctc"] = $this->rounding_value(($trans["ctc"]),'1');
$trans["earned_tele_reim"] = $this->rounding_value(($this->dz($trans["ftr"]/ $trans["md"] )* $trans["pd"]),'1');
$trans["earned_driver_reim"] = $this->rounding_value(($this->dz($trans["fdr"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_gmc"] = $this->rounding_value(($this->dz($trans["gmc_in_ctc"]/$trans["md"])*$trans["pd"]),'1');
$trans["tot_other_ded"] = $trans["monthly_tds"]+$trans["one_time_tds"]+$trans["fded"]+$trans["medi"]+$trans["saladv"]+$trans["oth_ded"]+ $trans["salary_loan"]+$trans["petty_cash"]+$trans["penalty"];
$trans["basic"] = $this->rounding_value(($this->dz($trans["fb"]/$trans["md"])*$trans["pd"]),'1');
$trans["hra"] = $this->rounding_value(($this->dz($trans["fixed_hra"]/$trans["md"])*$trans["pd"]),'1');
$trans["lta"] = $this->rounding_value(($this->dz($trans["flta"]/$trans["md"])*$trans["pd"]),'1');
$trans["conv"] = $this->rounding_value(($this->dz($trans["fconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["bns_adv"] = $this->rounding_value(($this->dz($trans["fbns_adv"]/$trans["md"])*$trans["pd"]),'1');
$trans["etconv"] = $this->rounding_value(($this->dz($trans["ftconv"]/$trans["md"])*$trans["pd"]),'1');
$trans["efc"] = $this->rounding_value(($this->dz($trans["ffc"]/$trans["md"])*$trans["pd"]),'1');
$trans["enps"] = $this->rounding_value(($this->dz($trans["fnps"]/$trans["md"])*$trans["pd"]),'1');
$trans["eg"] = $this->rounding_value(($trans["basic"]+$trans["lta"]+$trans["conv"]+$trans["bns_adv"]+$trans["hra"]+$trans["driver_reim"]+$trans["tel_reim"]),'1');
if($trans["pf_eligibility"]==1){if($trans["fb"]>15000){$trans["fpf_gross"] = 15000;}else{$trans["fpf_gross"] = $trans["fixed_gross"];}}else{$trans["fpf_gross"] = 0;}
$trans["fixed_pf"] = $this->rounding_value(($trans["fpf_gross"]*0),'1');
$trans["ld"] = $trans["md"]-$trans["pd"]-$trans["differential_day"]-$trans["separation_day"];
$trans["fpt_gross"] = $trans["fixed_gross"];
$trans["earned_pf_er_share"] = $this->rounding_value(($this->dz($trans["pf_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_pf_admin"] = $this->rounding_value(($this->dz($trans["pf_admin_charge"]/$trans["md"])*$trans["pd"]),'1');
$trans["earned_esi_er_share"] = $this->rounding_value(($this->dz($trans["esi_er_share"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gpa"] = $this->rounding_value(($this->dz($trans["gpa"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_gratuity"] = $this->rounding_value(($this->dz($trans["gratuity"]/$trans["md"])*$trans["pd"]),'1');
$trans["e_ctc"] = $trans["eg"]+$trans["earned_pf_er_share"]+$trans["enps"]+$trans["efc"]+$trans["e_gratuity"]+$trans["earned_pf_admin"]+$trans["earned_esi_er_share"]+$trans["e_gpa"]+$trans["earned_gmc"]+$trans["earned_tele_reim"]+$trans["earned_driver_reim"]-$trans["driver_reim"]-$trans["tel_reim"];
$trans["total_earnings"] = $this->rounding_value(($trans["hra"]+$trans["basic"]+$trans["conv"]+$trans["lta"]+$trans["bns_adv"]+$trans["driver_reim"]+$trans["tel_reim"]+$trans["otamt"]),'1');
$trans["total_deductions"] = $this->rounding_value(($trans["petty_cash"]+$trans["penalty"]+$trans["esi"]+$trans["npra"]+$trans["one_time_tds"]+$trans["monthly_tds"]+$trans["pfamount"]+$trans["vpf"]+$trans["sw"]+$trans["ptax_two"]+$trans["fded"]+$trans["medi"]+$trans["ptax"]+$trans["lic"]+$trans["saladv"]+$trans["oth_ded"]+$trans["salary_loan"]+$trans["lwf"]),'1');
$trans["net_pay"] = $this->rounding_value(($trans["total_earnings"]-$trans["total_deductions"]),'1');
$payroll_array[4][] ="('".$trans["employees_id"]."','".$trans["transactions_month"]."','".$trans["total_earnings"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."',\"$logged_id\",\"$date\",\"$settlement_date\",\"1\",'".$trans["one_time_tds"]."','".$trans["gmc_in_ctc"]."','".$trans["petty_cash"]."','".$trans["monthly_tds"]."','".$trans["penalty"]."','".$trans["fb"]."','".$trans["fixed_hra"]."','".$trans["flta"]."','".$trans["fconv"]."','".$trans["fbns_adv"]."','".$trans["ftconv"]."','".$trans["ffc"]."','".$trans["ftr"]."','".$trans["fdr"]."','".$trans["fnps"]."','".$trans["md"]."','".$trans["separation_day"]."','".$trans["differential_day"]."','".$trans["pd"]."','".$trans["fixed_gross"]."','".$trans["tel_reim"]."','".$trans["driver_reim"]."','".$trans["sw"]."','".$trans["ptax_two"]."','".$trans["fded"]."','".$trans["medi"]."','".$trans["lic"]."','".$trans["saladv"]."','".$trans["oth_ded"]."','".$trans["pf_eligibility"]."','".$trans["salary_loan"]."','".$trans["pf_er_share"]."','".$trans["pf_admin_charge"]."','".$trans["esi_er_share"]."','".$trans["gratuity"]."','".$trans["gpa"]."','".$trans["ctc"]."','".$trans["earned_tele_reim"]."','".$trans["earned_driver_reim"]."','".$trans["earned_gmc"]."','".$trans["tot_other_ded"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["lta"]."','".$trans["conv"]."','".$trans["bns_adv"]."','".$trans["etconv"]."','".$trans["efc"]."','".$trans["enps"]."','".$trans["eg"]."','".$trans["fpf_gross"]."','".$trans["fixed_pf"]."','".$trans["ld"]."','".$trans["fpt_gross"]."','".$trans["earned_pf_er_share"]."','".$trans["earned_pf_admin"]."','".$trans["earned_esi_er_share"]."','".$trans["e_gpa"]."','".$trans["e_gratuity"]."','".$trans["e_ctc"]."','".$trans["ptax_two_total"]."','".$trans["ptax_two_installments"]."','".$trans["ptax_two_instal_count"]."','".$trans["ptax_two_balance"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."','".$trans["petty_cash_total"]."','".$trans["petty_cash_installments"]."','".$trans["petty_cash_instal_count"]."','".$trans["petty_cash_balance"]."','".$trans["penalty_total"]."','".$trans["penalty_installments"]."','".$trans["penalty_instal_count"]."','".$trans["penalty_balance"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["branch"]."','".$trans["professional_tax_location"]."','".$trans["location"]."','".$trans["bank_account_number"]."','".$trans["bank_name"]."','".$trans["ifsc_code"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["cost_centre"]."','".$trans["grade"]."','".$trans["paymode"]."','".$trans["perarea"]."','".$trans["wbs"]."','".$trans["cat"]."')";
$qry_4 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,settlement_date,fandf,one_time_tds,gmc_in_ctc,petty_cash,monthly_tds,penalty,fb,fixed_hra,flta,fconv,fbns_adv,ftconv,ffc,ftr,fdr,fnps,md,separation_day,differential_day,pd,fixed_gross,tel_reim,driver_reim,sw,ptax_two,fded,medi,lic,saladv,oth_ded,pf_eligibility,salary_loan,pf_er_share,pf_admin_charge,esi_er_share,gratuity,gpa,ctc,earned_tele_reim,earned_driver_reim,earned_gmc,tot_other_ded,basic,hra,lta,conv,bns_adv,etconv,efc,enps,eg,fpf_gross,fixed_pf,ld,fpt_gross,earned_pf_er_share,earned_pf_admin,earned_esi_er_share,e_gpa,e_gratuity,e_ctc,ptax_two_total,ptax_two_installments,ptax_two_instal_count,ptax_two_balance,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance,petty_cash_total,petty_cash_installments,petty_cash_instal_count,petty_cash_balance,penalty_total,penalty_installments,penalty_instal_count,penalty_balance,role,employee_code,emp_name,department,designation,date_of_joining,branch,professional_tax_location,location,bank_account_number,bank_name,ifsc_code,lwf_location,process_month,resignation_date,termination_status,payroll,cost_centre,grade,paymode,perarea,wbs,cat'.$trans_key_array.') VALUES '.implode(',',$payroll_array[4]);
}
}
if($payroll_array[3]){
$this->db->query($qry_3);
}
if($payroll_array[2]){
$this->db->query($qry_2);
}
if($payroll_array[9]){
$this->db->query($qry_9);
}
if($payroll_array[7]){
$this->db->query($qry_7);
}
if($payroll_array[10]){
$this->db->query($qry_10);
}
if($payroll_array[8]){
$this->db->query($qry_8);
}
if($payroll_array[4]){
$this->db->query($qry_4);
}
return true;
}
public function rounding_value($result, $round_mode){
$result = round($result,2);
$final_result =0;
if(($round_mode == 0.5) || ($round_mode == 1)){
$final_result = round($result/$round_mode, 0)* $round_mode;
}elseif($round_mode == '>1'){
$final_result = ceil($result);
}elseif($round_mode == '<1'){
$final_result = floor($result);
}elseif($round_mode == '<0.5'){
$rslt = explode('.', $result);
$int_value = $rslt[0];
$point_value = $rslt[1];
if((int)$point_value > 50){
$final_result = $int_value.'.50';
}else{
$final_result = ceil($result);
}
}elseif($round_mode == '>0.5'){
$rslt = explode('.', $result);
$int_value = $rslt[0];
$point_value = $rslt[1];
if((int)$point_value >= 50){
$final_result = round($result);
}else{
$final_result = $int_value.'.50';
}
}elseif(((int)$round_mode == 5) || ((int)$round_mode == 10) || ((int)$round_mode == 50) || ((int)$round_mode == 100)){
$final_result = (ceil($result)% $round_mode === 0) ? ceil($result) : round(($result+ $round_mode/2)/ $round_mode)*$round_mode;
}elseif($round_mode == 0.1){
$final_result = round($result, 2);
}
return $final_result;
}
public function dz($result){
if(is_nan($result) || is_infinite($result)){
$result = 0;
}else{
$result;
}
return $result;
} //GET TOTAL WORKING DAYS
public function get_total_work_days($role,$process_month){
$month_day_result = $this->month_day_res[$role];
if($month_day_result){
$role = $month_day_result['category'];
$day_conditions = $month_day_result['day_conditions'];
$day_count = $month_day_result['day_count'];
$day_start = $month_day_result['day_start'];
$day_end = $month_day_result['day_end'];
$month_day = array();
if((int)$day_conditions === 1){
//STATIC DAYS
$month_day = $day_count;
}else
if((int)$day_conditions === 2){
//CALENDER DAYS
$trans_month = explode('-',$process_month);
$month_val = $trans_month[0];
$year_val = $trans_month[1];
$day_count = cal_days_in_month(CAL_GREGORIAN, $month_val, $year_val);
$month_day = $day_count;
}else
if((int)$day_conditions === 3){
//CUTOFF DAYS
$trans_month = explode('-',$process_month);
$month_val = $trans_month[0];
$year_val = $trans_month[1];
$pre_month = (int)$month_val - 1;
$pre_year_val = $year_val;
if((int)$pre_month === 0){
$pre_month = 12;
$pre_year_val = (int)$year_val - 1;
}
$start_date = $day_start."-".$pre_month."-".$pre_year_val;
$end_date = $day_end."-".$month_val."-".$year_val;
$start_date = strtotime($start_date);
$end_date = strtotime($end_date);
$datediff = $end_date - $start_date;
$day_count = round($datediff/86400);//60 * 60 * 24
$month_day = (int)$day_count + 1;
}
}else{
$trans_month = explode("-",$process_month);
$month_val = $trans_month[0];
$year_val = $trans_month[1];
$day_count = cal_days_in_month(CAL_GREGORIAN, $month_val, $year_val);
$month_day = $day_count;
}
return $month_day;
}
//GET DIFFERENTIAL DAY COUNT FOR NEW JOINING details
//intermediate joining date and month days count differentiate day count
public function get_differential_day($employee_code,$role,$process_month){
$month_day_result = $this->month_day_res[$role];
$tot_month_day = $this->get_total_work_days($role,$process_month);
if($month_day_result){
$day_conditions = $month_day_result['day_conditions'];
$day_count = $month_day_result['day_count'];
$day_start = $month_day_result['day_start'];
$day_end = $month_day_result['day_end'];
$diff_day_qry = 'select date_of_joining from cw_employees where trans_status = 1 and employee_code = "'.$employee_code.'" and DATE_FORMAT(date_of_joining, "%m-%Y") like "'.$process_month.'"';
$diff_day_data = $this->db->query("CALL sp_a_run ('SELECT','$diff_day_qry')");
$diff_day_result = $diff_day_data->result();
$diff_day_data->next_result();
$doj = $diff_day_result[0]->date_of_joining;
$diff_day_count = $diff_day_data->num_rows();
if(((int)$day_conditions === 1) || ((int)$day_conditions === 2)){//STATIC DAYS AND CALENDER DAYS
if((int)$diff_day_count === 0){
$final_dif_day = 0;
}else{
$trans_month = explode('-',$process_month);
$month_val = $trans_month[0];
$year_val = $trans_month[1];
if((int)$day_conditions === 2){
$day_count = cal_days_in_month(CAL_GREGORIAN, $month_val, $year_val);
}
$process_date = $day_count.'-'.$process_month;
$process_date = date('d-m-Y', strtotime($process_date));
$process_date = strtotime($process_date);
$doj = strtotime($doj);
$diff = $process_date - $doj;
$differ_day = round($diff / 86400);
$final_dif_day = $tot_month_day - $differ_day - 1;
}
}else
if((int)$day_conditions === 3){//CUTOFF DAYS
$trans_month = explode("-",$process_month);
$month_val = $trans_month[0];
$year_val = $trans_month[1];
$process_end = $day_end."-".$month_val."-".$year_val;
$process_end = date('Y-m-d',strtotime($process_end));
$pre_month = ($month_val - 1) % 12;
$process_start = $day_start."-".$pre_month."-".$year_val;
$process_start = date('Y-m-d',strtotime($process_start));
$diff_cut_day_qry = 'select date_of_joining from cw_employees where trans_status = 1 and employee_code = "'.$employee_code.'" and DATE_FORMAT(date_of_joining, "%Y-%m-%d") between "'.$process_start.'" and "'.$process_end.'"';
$diff_cut_day_data = $this->db->query("CALL sp_a_run ('SELECT','$diff_cut_day_qry')");
$diff_cut_day_result = $diff_cut_day_data->result();
$diff_cut_day_data->next_result();
$diff_cut_day_count = $diff_cut_day_data->num_rows();
$doj = $diff_cut_day_result[0]->date_of_joining;
if((int)$diff_cut_day_count === 0){
$final_dif_day = 0;
}else{
$doj = strtotime($doj);
$process_end = strtotime($process_end);
$diff = $process_end - $doj;
$differ_day = round($diff / 86400);
$final_dif_day = $tot_month_day - $differ_day - 1;
}
}
}
return $final_dif_day;
}
//GET TOTAL LOAN AMOUNT FOR PER EMPLOYEE
public function get_loan_value($employee_code,$process_month){
$get_terminate_qry = 'select termination_status from cw_employees where trans_status=1 and employee_code ="'.$employee_code.'"';
$get_terminate_data = $this->db->query("CALL sp_a_run ('SELECT','$get_terminate_qry')");
$get_terminate_result = $get_terminate_data->result();
$get_terminate_data->next_result();
$terminate_sts = $get_terminate_result[0]->termination_status;
$loan_amt = 0;
if((int)$terminate_sts === 1){
$loan_qry = 'select IFNULL(sum(install_amount),0) as install_amt from cw_loan_installment where trans_status = 1 and paid_status = 0 and emp_code ="'.$employee_code.'" and date_format(str_to_date(install_year, "%m-%Y") , "%Y-%m") >= date_format(str_to_date("'.$process_month.'", "%m-%Y"), "%Y-%m")';
$loan_data = $this->db->query("CALL sp_a_run ('SELECT','$loan_qry')");
$loan_result = $loan_data->result();
$loan_data->next_result();
if(!empty($loan_result)){
$loan_amt = $loan_result[0]->install_amt;
}
}else{
$loan_qry = 'select IFNULL(install_amount,0) as install_amt from cw_loan_installment where trans_status = 1 and paid_status = 0 and emp_code ="'.$employee_code.'" and install_year ="'.$process_month.'"';
$loan_data = $this->db->query("CALL sp_a_run ('SELECT','$loan_qry')");
$loan_result = $loan_data->result();
$loan_data->next_result();
$loan_amt = 0;
if(!empty($loan_result)){
$loan_amt = $loan_result[0]->install_amt;
if($loan_amt > 0){
$upd_query = 'UPDATE cw_loan_installment SET paid_status = 1 WHERE trans_status = 1 and install_year ="'.$process_month.'" and emp_code="'.$employee_code.'"';
$update_info = $this->db->query("CALL sp_a_run ('UPDATE','$upd_query')");
}
}
}
return $loan_amt;
}
//Get ESI STATUS 20SEP2022 BSK
public function get_esi_status($earned_gross,$employee_code,$role,$process_month){
$statutory_rslt = $this->statutory_arr[$role];
$esi_limit = $statutory_rslt['esi_limit'];
$esi_conditions = $statutory_rslt['esi_conditions'];
$esi_start_check_month = $statutory_rslt['esi_start_check_month'];
$esi_end_check_month = $statutory_rslt['esi_end_check_month'];
$process_month = $statutory_rslt['process_month'];
$process_month_val = $statutory_rslt['process_month_val'];
$esi_loc_db = $this->get_map_arr['esi_loc']['db_column'];
$esi_elig_db = $this->get_map_arr['esi_elig']['db_column'];
if($esi_limit > 0){
//location nil is default
//1 -- Nil default no esi sts 2
/*$select_loc_qry = 'select '.$esi_loc_db.' as esi_loc from cw_employees where trans_status = 1 and role = "'.$role.'" and employee_code = "'.$employee_code.'"';
$select_loc_data = $this->db->query("CALL sp_a_run ('SELECT','$select_loc_qry')");
$select_loc_result = $select_loc_data->result_array();
$select_loc_data->next_result();*/
$esi_location = $this->emp_date_arr[$employee_code][$esi_loc_db];
$esi_eligibility = $this->emp_date_arr[$employee_code][$esi_elig_db];
if((int)$esi_location){
$upd_query = 'UPDATE cw_employees SET esi_eligibility = 2 WHERE trans_status = 1 and role ="'.$role.'" and employee_code="'.$employee_code.'"';
$update_info = $this->db->query("CALL sp_a_run ('UPDATE','$upd_query')");
$esi_sts = 2;
return $esi_sts;
}else{
//esi eligibility 1= yes 2 = no;
if(($esi_start_check_month === $process_month_val) || ($esi_end_check_month === $process_month_val)){
if((int)$earned_gross > (int)$esi_limit){
$upd_query = 'UPDATE cw_employees SET esi_eligibility = 2 WHERE trans_status = 1 and role ="'.$role.'" and employee_code="'.$employee_code.'"';
$update_info = $this->db->query("CALL sp_a_run ('UPDATE','$upd_query')");
$esi_sts = 2;
return $esi_sts;
}else{
$esi_sts = 1; //yes esi
return $esi_sts;
}
}else{
$select_esi_elig_qry = 'select '.$esi_loc_db.' as esi_elig from cw_employees where trans_status = 1 and role = "'.$role.'" and employee_code = "'.$employee_code.'"';
$select_esi_elig_data = $this->db->query("CALL sp_a_run ('SELECT','$select_esi_elig_qry')");
$select_esi_elig_result = $select_esi_elig_data->result();
$select_esi_elig_data->next_result();
$esi_sts = $select_esi_elig_result[0]->esi_elig;
return $esi_sts; //actual esi status from DB//
}
}
}
}
//GET LWF EMPLOYER (COMPANY AMOUNT) FUNCTION
public function get_lwf_employer($lwf_location,$process_month){
$process_month = explode("-",$process_month);
$process_month_val = $process_month[0];
//$process_month_val = 12;
$select_lwf_result = $this->lwf_emp_arr[$lwf_location];
$pay_month = $select_lwf_result['pay_month'];
$company_amount = $select_lwf_result['company_amount'];
$lwf_comp_amt = 0;
if($pay_month == "process_month_val"){
$lwf_comp_amt = $company_amount;
}
return $lwf_comp_amt;
}
//GET LWF EMPLOYEE (EMPLOYEE AMOUNT) FUNCTION
public function get_lwf_employee($lwf_location,$process_month){
$process_month = explode("-",$process_month);
$process_month_val = $process_month[0];
$select_lwf_result = $this->lwf_emp_arr[$lwf_location];
$pay_month = $select_lwf_result['pay_month'];
$employee_amount = $select_lwf_result['employee_amount'];
$lwf_emp_amt = 0;
if($pay_month == "process_month_val"){
$lwf_emp_amt = $employee_amount;
}
return $lwf_emp_amt;
}
//formula PD = MD-LD-DD-S_DD;
//find re-leaving date for resigning employee details check this values 13/12/2021
public function get_seperation_day($employee_code,$role,$process_month){
$sep_day = $this->emp_date_arr[$employee_code]['last_working_date'];
if($sep_day && $sep_day !== '0000-00-00' && $sep_day !== '1970-01-01'){
$month_day_result = $this->month_day_res[$role];
$day_conditions = $month_day_result['day_conditions'];
$day_count = $month_day_result['day_count'];
$day_start = $month_day_result['day_start'];
$day_end = $month_day_result['day_end'];
if((int)$day_conditions === 1){
//STATIC DAYS
$process_date = $day_count.'-'.$process_month;
$process_date = date('d-m-Y', strtotime($process_date));
$process_date = strtotime($process_date);
$sep_day = strtotime($sep_day);
$diff = $process_date - $sep_day;
$separation_day = round($diff / 86400);
}else
if((int)$day_conditions === 2){
//CALENDER DAYS
$trans_month = explode("-",$process_month);
$month_val = $trans_month[0];
$year_val = $trans_month[1];
$day_count = cal_days_in_month(CAL_GREGORIAN, $month_val, $year_val);
$process_date = $day_count.'-'.$process_month;
$process_date = date('d-m-Y', strtotime($process_date));
$process_date = strtotime($process_date);
$sep_day = strtotime($sep_day);
$diff = $process_date - $sep_day;
$separation_day = round($diff / 86400);
}else
if((int)$day_conditions === 3){
//CUTOFF DAYS
$trans_month = explode("-",$process_month);
$month_val = $trans_month[0];
$year_val = $trans_month[1];
$process_date = $day_end.'-'.$month_val.'-'.$year_val;
$process_date = strtotime($process_date);
$sep_day = strtotime($sep_day);
$diff = $process_date - $sep_day;
$separation_day = round($diff / 86400);
}
}else{
$separation_day = 0;
}
if($separation_day < 0){
$separation_day = 0;
}
return $separation_day;
}
public function get_gratuity($role,$employee_code){
$check_eligibilty_result = $this->gratuity_arr[$role];
$working_days = $check_eligibilty_result['working_days'];
$number_of_years = $check_eligibilty_result['number_of_years'];
$pay_days = $check_eligibilty_result['pay_days'];
$year_rounding = $check_eligibilty_result['year_rounding'];
$gratuity_formula = $check_eligibilty_result['formula_detail'];
$formula_rounding = $check_eligibilty_result['formula_rounding'];
$gratuity_formula = str_replace("@","",$gratuity_formula);
$gratuity_formula = "(".$gratuity_formula.") as gratuity";
$doj = $this->emp_date_arr[$employee_code]['date_of_joining'];
$last_day = $this->emp_date_arr[$employee_code]['last_working_date'];
$status = $this->emp_date_arr[$employee_code]['termination_status'];
$doj = strtotime($doj);
$last_day = strtotime($last_day);
$tot_year = (abs($last_day-$doj)/60/60/24)/365;
//year rounding base working year is rounded
$year_arr = array(1=>$tot_year,2=>round($tot_year),3=>ceil($tot_year),4=>floor($tot_year));
if($year_rounding){
$tot_year = $year_arr[$year_rounding];
}
$tot_year = number_format((float)$tot_year, 2, '.', '');
if($last_day && $last_day !== '0000-00-00' && $last_day !== '1970-01-01' && (int)$status === 1){
//gratuity calculations for given formula and employee code
if(($tot_year >= $number_of_years)){
$grat_formula_amt_qry = 'select '.$gratuity_formula.' from cw_employees where trans_status =1 and employee_code = "'.$employee_code.'"';
$grat_formula_amt_data = $this->db->query("CALL sp_a_run ('SELECT','$grat_formula_amt_qry')");
$grat_formula_amt_result = $grat_formula_amt_data->result();
$grat_formula_amt_data->next_result();
$grat_formula_amt = $grat_formula_amt_result[0]->gratuity;
$gratutity_amt = (($grat_formula_amt * $pay_days)/$working_days) * $tot_year;
if($formula_rounding){
$gratutity_amt = $this->rounding_value($gratutity_amt,$formula_rounding);
}
return $gratutity_amt;
}else{
return 0;
}
}else{
return 0;
}
}
public function get_salary_date($category){
$month_day_result = $this->gratuity_arr[$category];
if($month_day_result){
$role = $month_day_result['category'];
$day_conditions = $month_day_result['day_conditions'];
$day_count = $month_day_result['day_count'];
$day_start = $month_day_result['day_start'];
$day_end = $month_day_result['day_end'];
if((int)$day_conditions === 3){
return array('day_start'=> $day_start, 'day_end' => $day_end,'day_conditions'=>(int)$day_conditions);
}else{
$day_start = '01';
return array('day_start'=> $day_start, 'day_end' => $day_end,'day_conditions'=>(int)$day_conditions);
}
}
}
//CHECK PTAX FOR EVERY EMPLOYEE FOR THIS MONTH AND YEAR -- 11MAY2019 --Updates
public function get_professional_tax_value($employee_code,$professional_tax_location,$pt_projection,$total_earnings,$process_month){
$get_emp_sts_result = $this->emp_date_arr[$employee_code]['last_working_date'];
$term_sts = $get_emp_sts_result['termination_status'];
$doj = $get_emp_sts_result['date_of_joining'];
$professional_tax_amount_db = $this->get_map_arr['professional_tax_amount']['db_column'];
$earned_gross_db = $this->get_map_arr['earned_gross']['db_column'];
$pt_gross_db = $this->get_map_arr['pt_gross']['db_column'];
$ptax_result = $this->ptax_rslt[$professional_tax_location];
$prof_tax_id = $ptax_result['prime_professional_tax_id'];
$location = $ptax_result['location'];
$calculation_mode = $ptax_result['calculation_period'];
$osm_first_st_val = $ptax_result['osm_first_start'];
$osm_first_ed_val = $ptax_result['osm_first_end'];
$osm_second_st_val = $ptax_result['osm_second_start'];
$osm_second_ed_val = $ptax_result['osm_second_end'];
$osm_second_end_val = $ptax_result['osm_second_end'];
$ptax_deduct_first = $ptax_result['first_period'];
$ptax_deduct_second = $ptax_result['second_period'];
$trans_month = $process_month;
$process_month = explode("-",$process_month);
$process_month_val = $process_month[0];
$process_year_val = $process_month[1];
$process_month_date = $process_month[1]."-".$process_month[0]."-01";
//By Formula every month calculated ptax amount based on earn gross
$first_period = array();
for($osm_first_st_val;$osm_first_st_val<=$osm_first_ed_val;$osm_first_st_val++){
$first_period[] = $osm_first_st_val;
}
//array bulid based on months start
$second_period_part_i = array();
for($osm_second_st_val;$osm_second_st_val<=12;$osm_second_st_val++){
$second_period_part_i[] = $osm_second_st_val;
}
$second_period_part_ii = array();
for($osm_second_ed_val;$osm_second_ed_val>=1;$osm_second_ed_val--){
$second_period_part_ii[] = $osm_second_ed_val;
}
sort($second_period_part_ii);
$second_period = array_merge($second_period_part_i,$second_period_part_ii);
//array bulid based on months End
//Payroll month fall in first period and second priod start
//Payroll month fall in first period find process and proj count
if(in_array($process_month_val,$first_period ?? [])){
$act_count = array_search($osm_first_ed_val, array_values($first_period));
$cut_off_count = array_search($ptax_deduct_first, array_values($first_period));
$cur_count = array_search($process_month_val, array_values($first_period));
$cut_off_count++;
$process_count = (int)$cut_off_count - (int)$cur_count;
$proj_count = (int)$act_count - (int)$cur_count;
}else
if(in_array($process_month_val,$second_period ?? [])){
//Payroll month fall in second period find process and proj count
$act_count = array_search($osm_second_end_val, array_values($second_period));
$cut_off_count = array_search($ptax_deduct_second, array_values($second_period));
$cur_count = array_search($process_month_val, array_values($second_period));
$cut_off_count++;
$process_count = (int)$cut_off_count - (int)$cur_count;
$proj_count = (int)$act_count - (int)$cur_count;
}
if((int)$process_count < 0){
$process_count=0;
}
$prof_tax = 0;
if((int)$calculation_mode === 1){
//By Formula -- First Method
$every_month_qry = 'select professional_tax_amount as ptax_amt from cw_professional_tax_tax_range where trans_status=1 and prime_professional_tax_id ="'.$prof_tax_id.'" and earning_range_from <= "'.floor($total_earnings).'" and earning_range_to >= '.floor($total_earnings);
$every_month_data = $this->db->query("CALL sp_a_run ('SELECT','$every_month_qry')");
$every_month_result = $every_month_data->result();
$every_month_data->next_result();
$prof_tax = $every_month_result[0]->ptax_amt;
}else
if((int)$calculation_mode === 2){
//$projection_total = $pt_projection * (int)$proj_count; //2 month count
//Find last total earned gross amount
$projection_total = 0; //2 as discussed with jai sir
//Find last total earned gross amount
$last_month_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($process_month_date)) . " - ".$cur_count." months"));
$previous_tax_qry = 'select ifnull(sum('.$pt_gross_db.'),0) as total_earnings from cw_transactions where trans_status =1 and employee_code = "'.$employee_code.'" and date_format(str_to_date(CONCAT("01-",transactions_month), "%d-%m-%Y") , "%Y-%m") BETWEEN date_format("'.$last_month_date.'", "%Y-%m") and date_format("'.$process_month_date.'", "%Y-%m")';
$previous_tax_data = $this->db->query("CALL sp_a_run ('SELECT','$previous_tax_qry')");
$previous_tax_result = $previous_tax_data->result();
$previous_tax_data->next_result();
$previous_earned = $previous_tax_result[0]->total_earnings; //upto this month sum earned gross
$total_earn = $previous_earned + $projection_total + $total_earnings;
//Find current professional tax pay amount
$find_tax_qry = 'select professional_tax_amount as ptax_amt from cw_professional_tax_tax_range where trans_status = 1 and prime_professional_tax_id ="'.$prof_tax_id.'" and earning_range_from <= "'.floor($total_earn).'" and earning_range_to >= '.floor($total_earn);
$find_tax_data = $this->db->query("CALL sp_a_run ('SELECT','$find_tax_qry')");
$find_tax_result = $find_tax_data->result();
$find_tax_data->next_result();
$find_tax_val = $find_tax_result[0]->ptax_amt;
//Find last paying professional tax amount and find final professional tax values and return to ptax column
$last_tax_qry= 'select ifnull(sum('.$professional_tax_amount_db.'),0) as professional_tax from cw_transactions where trans_status =1 and employee_code = "'.$employee_code.'" and date_format(str_to_date(CONCAT("01-",transactions_month), "%d-%m-%Y") , "%Y-%m") BETWEEN date_format("'.$last_month_date.'", "%Y-%m") and date_format("'.$process_month_date.'", "%Y-%m")';
$last_tax_data = $this->db->query("CALL sp_a_run ('SELECT','$last_tax_qry')");
$last_tax_result = $last_tax_data->result();
$last_tax_data->next_result();
$last_tax_val = $last_tax_result[0]->professional_tax;
$prof_tax = $find_tax_val - $last_tax_val;
}else
if((int)$calculation_mode === 3){
//By Once in six month -- Last Method
//Find Projection amount
//projection amount
//$projection_total = $pt_projection * (int)$proj_count; //2 month count
$projection_total = 0; //2 as discussed with jai sir
//calculate sum of actual and projection amount and six month amount value
$last_month_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($process_month_date)) . " - ".$cur_count." months"));
$previous_tax_qry= 'select ifnull(sum('.$pt_gross_db.'),0) as total_earnings from cw_transactions where trans_status =1 and employee_code = "'.$employee_code.'" and date_format(str_to_date(CONCAT("01-",transactions_month), "%d-%m-%Y") , "%Y-%m") BETWEEN date_format("'.$last_month_date.'", "%Y-%m") and date_format("'.$process_month_date.'", "%Y-%m")';
$previous_tax_data = $this->db->query("CALL sp_a_run ('SELECT','$previous_tax_qry')");
$previous_tax_result = $previous_tax_data->result();
$previous_tax_data->next_result();
$previous_earned = $previous_tax_result[0]->total_earnings; //find curr to pre earned gross sum value
$total_earn =$previous_earned + $projection_total + $total_earnings; // total sum (earned + project)
//Find current professional tax pay amount
$find_tax_qry = 'select professional_tax_amount as ptax_amt from cw_professional_tax_tax_range where trans_status=1 and prime_professional_tax_id ="'.$prof_tax_id.'" and earning_range_from <= "'.floor($total_earn).'" and earning_range_to >= '.floor($total_earn);
$find_tax_data = $this->db->query("CALL sp_a_run ('SELECT','$find_tax_qry')");
$find_tax_result = $find_tax_data->result();
$find_tax_data->next_result();
$prof_tax = $find_tax_result[0]->ptax_amt;
}
if($prof_tax < 0 || $total_earnings < $prof_tax){
$prof_tax = 0;
}
return round($prof_tax);
}
}
?>