MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //home/cafsindia/uds.cafsinfotech.in/application/models/Fandf_calculation_model.php
<?php
 class Fandf_calculation_model extends CI_Model{
	public function Fandf_calculation($trans_array){ 
		 $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["company_lwf"] = $trans["company_lwf"];			
				$trans["salary_loan"] = $trans["salary_loan"];			
				$trans["dorm"] = $trans["dorm"];			
				$trans["meal"] = $trans["meal"];			
				$trans["other_deduction"] = $trans["other_deduction"];			
				$trans["department"] = $trans["department"];			
				$trans["designation"] = $trans["designation"];			
				$trans["paid_leave"] = $trans["paid_leave"];			
				$trans["monthly_tds"] = $trans["monthly_tds"];			
				$trans["differential_day"] = $this->Process_payroll_model->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);			
				$trans["separation_day"] = $trans["separation_day"];			
				$trans["fixed_basic"] = $trans["fixed_basic"];			
				$trans["a_basic"] = $this->rounding_value(($trans["a_basic"]),'>1');			
				$trans["month_days"] = $this->Process_payroll_model->get_total_work_days($trans["role"],$trans["transactions_month"]);			
				$trans["lop_days"] = $trans["lop_days"];			
				$trans["a_da"] = $trans["a_da"];			
				$trans["a_hra"] = $trans["a_hra"];			
				$trans["bonus"] = $trans["bonus"];			
				$trans["casual_leave"] = $trans["casual_leave"];			
				$trans["cl_op"] = $trans["cl_op"];			
				$trans["fcon"] = $trans["fcon"];			
				$trans["fixed_da"] = $trans["fixed_da"];			
				$trans["el"] = $trans["el"];			
				$trans["el_op"] = $trans["el_op"];			
				$trans["fixed_hra"] = $trans["fixed_hra"];			
				$trans["fixed_gross"] = $trans["fixed_gross"];			
				$trans["flta"] = $trans["flta"];			
				$trans["fmed"] = $trans["fmed"];			
				$trans["fspl"] = $trans["fspl"];			
				$trans["ftfa"] = $trans["ftfa"];			
				$trans["gratuity"] = $trans["gratuity"];			
				$trans["hd"] = $trans["hd"];			
				$trans["lev_encashday"] = $trans["lev_encashday"];			
				$trans["nsd"] = $trans["nsd"];			
				$trans["notice_period"] = $trans["notice_period"];			
				$trans["ot_hrs"] = $trans["ot_hrs"];			
				$trans["otr"] = $trans["otr"];			
				$trans["fo_allowance"] = $trans["fo_allowance"];			
				$trans["pb_ars"] = $trans["pb_ars"];			
				$trans["pot_hrs"] = $trans["pot_hrs"];			
				$trans["potr"] = $trans["potr"];			
				$trans["po_ars"] = $trans["po_ars"];			
				$trans["prd"] = $trans["prd"];			
				$trans["spm"] = $trans["spm"];			
				$trans["spl_pa"] = $trans["spl_pa"];			
				$trans["woff_days"] = $trans["woff_days"];			
				$trans["pf_eligibility"] = $trans["pf_eligibility"];			
				$trans["tds"] = $trans["tds"];			
				$trans["paid_days"] = $trans["month_days"]-($trans["lop_days"]+$trans["differential_day"]+$trans["separation_day"]);			
				$trans["basic"] = $this->rounding_value((($trans["fixed_basic"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["cl_balance"] = $trans["cl_op"]-$trans["casual_leave"];			
				$trans["econ"] = $this->rounding_value((($trans["fcon"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["da"] = $this->rounding_value((($trans["fixed_da"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["el_bal"] = $trans["el_op"]-$trans["el"];			
				$trans["hra"] = $this->rounding_value((($trans["fixed_hra"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["lev_encashrate"] = $trans["fixed_basic"]/26;			
				$trans["lev_encashamt"] = $trans["lev_encashday"]*$trans["lev_encashrate"];			
				$trans["elta"] = $this->rounding_value((($trans["flta"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["emed"] = $this->rounding_value((($trans["fmed"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["eot"] = $this->rounding_value((((($trans["fixed_gross"]/26)/8)*2)*$trans["ot_hrs"]),'>1');			
				$trans["pot"] = $this->rounding_value((((($trans["fixed_gross"]/26)/8)*2)*$trans["pot_hrs"]),'>1');			
				$trans["espl"] = $this->rounding_value((($trans["fspl"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["etfa"] = $trans["ftfa"];			
				$trans["gross"] = $trans["basic"]+$trans["da"]+$trans["hra"]+$trans["espl"]+$trans["emed"]+$trans["elta"]+$trans["econ"];			
				$trans["nsa"] = $trans["nsd"]*50;			
				$at_b=1000;$l=$trans["separation_day"]+$trans["differential_day"]+$trans["lop_days"]+$trans["paid_leave"];if($l>0){$trans["att_bns"] = 0;}else{$trans["att_bns"] = $at_b;}
				$trans["mgs"] = $trans["basic"]+$trans["da"]+$trans["hra"]+$trans["econ"]+$trans["espl"]+$trans["emed"]+$trans["elta"]+$trans["spl_pa"]+$trans["etfa"]+$trans["att_bns"]+$trans["nsa"]+$trans["fo_allowance"]+$trans["bonus"]+$trans["pb_ars"]+$trans["po_ars"]+$trans["eot"]+$trans["pot"];			
				$trans["pf_gross"] = $trans["gross"];			
				$a=0;if($trans["fixed_gross"]>21000){$trans["esi_gross"] = $a;}else{$trans["esi_gross"] = $trans["mgs"];}
				$trans["pf"] = $this->rounding_value((($trans["pf_gross"])*(12/100)),'1');			
				$trans["esi"] = $this->rounding_value(($trans["esi_gross"]*(0.75/100)),'1');			
				$trans["professional_tax"] = $this->Process_payroll_model->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["pt_projection"],$trans["mgs"],$trans["transactions_month"]);			
				$trans["esi_eligibility"] = $trans["fixed_basic"]+$trans["fixed_da"]+$trans["fixed_hra"]+$trans["fcon"]+$trans["fmed"]+$trans["flta"]+$trans["fspl"];			
				$trans["total_deductions"] = $this->rounding_value(($trans["pf"]+$trans["esi"]+$trans["tds"]+$trans["professional_tax"]+$trans["meal"]+$trans["dorm"]+$trans["company_lwf"]+$trans["other_deduction"]+$trans["salary_loan"]+$trans["monthly_tds"]),'1');			
				$trans["employee_pf"] = $trans["pf_gross"]*(3.67/100);			
				$trans["employer_pf"] = $this->rounding_value(($trans["pf_gross"]*(8.33/100)),'1');			
				$trans["emp_esi"] = $this->rounding_value(($trans["esi_gross"]*(3.25/100)),'1');			
				$trans["total_esi"] = $this->rounding_value(($trans["emp_esi"]+$trans["esi"]),'1');			
				$trans["net_pay"] = $this->rounding_value(($trans["mgs"]-$trans["total_deductions"]),'1');			$payroll_array[3][] ="('".$trans["employees_id"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["transactions_month"]."','".$trans["role"]."','".$trans["transactions_month"]."','".$trans["termination_status"]."','".$trans["company_lwf"]."','".$trans["salary_loan"]."','".$trans["dorm"]."','".$trans["meal"]."','".$trans["other_deduction"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["paid_leave"]."','".$trans["monthly_tds"]."','".$trans["differential_day"]."','".$trans["separation_day"]."','".$trans["fixed_basic"]."','".$trans["a_basic"]."','".$trans["month_days"]."','".$trans["lop_days"]."','".$trans["a_da"]."','".$trans["a_hra"]."','".$trans["bonus"]."','".$trans["casual_leave"]."','".$trans["cl_op"]."','".$trans["fcon"]."','".$trans["fixed_da"]."','".$trans["el"]."','".$trans["el_op"]."','".$trans["fixed_hra"]."','".$trans["fixed_gross"]."','".$trans["flta"]."','".$trans["fmed"]."','".$trans["fspl"]."','".$trans["ftfa"]."','".$trans["gratuity"]."','".$trans["hd"]."','".$trans["lev_encashday"]."','".$trans["nsd"]."','".$trans["notice_period"]."','".$trans["ot_hrs"]."','".$trans["otr"]."','".$trans["fo_allowance"]."','".$trans["pb_ars"]."','".$trans["pot_hrs"]."','".$trans["potr"]."','".$trans["po_ars"]."','".$trans["prd"]."','".$trans["spm"]."','".$trans["spl_pa"]."','".$trans["woff_days"]."','".$trans["pf_eligibility"]."','".$trans["tds"]."','".$trans["paid_days"]."','".$trans["basic"]."','".$trans["cl_balance"]."','".$trans["econ"]."','".$trans["da"]."','".$trans["el_bal"]."','".$trans["hra"]."','".$trans["lev_encashrate"]."','".$trans["lev_encashamt"]."','".$trans["elta"]."','".$trans["emed"]."','".$trans["eot"]."','".$trans["pot"]."','".$trans["espl"]."','".$trans["etfa"]."','".$trans["gross"]."','".$trans["nsa"]."','".$trans["att_bns"]."','".$trans["mgs"]."','".$trans["pf_gross"]."','".$trans["esi_gross"]."','".$trans["pf"]."','".$trans["esi"]."','".$trans["professional_tax"]."','".$trans["esi_eligibility"]."','".$trans["total_deductions"]."','".$trans["employee_pf"]."','".$trans["employer_pf"]."','".$trans["emp_esi"]."','".$trans["total_esi"]."','".$trans["net_pay"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."')";
						
		 $query_key = 'employees_id,employee_code,emp_name,transactions_month,role,process_month,termination_status,company_lwf,salary_loan,dorm,meal,other_deduction,department,designation,paid_leave,monthly_tds,differential_day,separation_day,fixed_basic,a_basic,month_days,lop_days,a_da,a_hra,bonus,casual_leave,cl_op,fcon,fixed_da,el,el_op,fixed_hra,fixed_gross,flta,fmed,fspl,ftfa,gratuity,hd,lev_encashday,nsd,notice_period,ot_hrs,otr,fo_allowance,pb_ars,pot_hrs,potr,po_ars,prd,spm,spl_pa,woff_days,pf_eligibility,tds,paid_days,basic,cl_balance,econ,da,el_bal,hra,lev_encashrate,lev_encashamt,elta,emed,eot,pot,espl,etfa,gross,nsa,att_bns,mgs,pf_gross,esi_gross,pf,esi,professional_tax,esi_eligibility,total_deductions,employee_pf,employer_pf,emp_esi,total_esi,net_pay,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance'; 
	 $qry_3 = 'INSERT INTO cw_transactions(employees_id,employee_code,emp_name,transactions_month,role,process_month,termination_status,company_lwf,salary_loan,dorm,meal,other_deduction,department,designation,paid_leave,monthly_tds,differential_day,separation_day,fixed_basic,a_basic,month_days,lop_days,a_da,a_hra,bonus,casual_leave,cl_op,fcon,fixed_da,el,el_op,fixed_hra,fixed_gross,flta,fmed,fspl,ftfa,gratuity,hd,lev_encashday,nsd,notice_period,ot_hrs,otr,fo_allowance,pb_ars,pot_hrs,potr,po_ars,prd,spm,spl_pa,woff_days,pf_eligibility,tds,paid_days,basic,cl_balance,econ,da,el_bal,hra,lev_encashrate,lev_encashamt,elta,emed,eot,pot,espl,etfa,gross,nsa,att_bns,mgs,pf_gross,esi_gross,pf,esi,professional_tax,esi_eligibility,total_deductions,employee_pf,employer_pf,emp_esi,total_esi,net_pay,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance'.$trans_key_array.') VALUES '.implode(',',$payroll_array[3]); 
			}else
			if((int)$trans["role"] === 2){
				$trans["month_days"] = $this->Process_payroll_model->get_total_work_days($trans["role"],$trans["transactions_month"]);			
				$trans["lop_days"] = $trans["lop_days"];			
				$trans["a_da"] = $trans["a_da"];			
				$trans["a_hra"] = $trans["a_hra"];			
				$trans["att_bns"] = $trans["att_bns"];			
				$trans["bonus"] = $trans["bonus"];			
				$trans["casual_leave"] = $trans["casual_leave"];			
				$trans["cl_op"] = $trans["cl_op"];			
				$trans["fcon"] = $trans["fcon"];			
				$trans["fixed_da"] = $trans["fixed_da"];			
				$trans["el"] = $trans["el"];			
				$trans["el_op"] = $trans["el_op"];			
				$trans["fixed_hra"] = $trans["fixed_hra"];			
				$trans["fixed_gross"] = $trans["fixed_gross"];			
				$trans["flta"] = $trans["flta"];			
				$trans["fmed"] = $trans["fmed"];			
				$trans["fspl"] = $trans["fspl"];			
				$trans["ftfa"] = $trans["ftfa"];			
				$trans["hd"] = $trans["hd"];			
				$trans["lev_encashday"] = $trans["lev_encashday"];			
				$trans["nsd"] = $trans["nsd"];			
				$trans["notice_period"] = $trans["notice_period"];			
				$trans["ot_hrs"] = $trans["ot_hrs"];			
				$trans["otr"] = $trans["otr"];			
				$trans["fo_allowance"] = $trans["fo_allowance"];			
				$trans["pb_ars"] = $trans["pb_ars"];			
				$trans["pot_hrs"] = $trans["pot_hrs"];			
				$trans["potr"] = $trans["potr"];			
				$trans["po_ars"] = $trans["po_ars"];			
				$trans["prd"] = $trans["prd"];			
				$trans["spm"] = $trans["spm"];			
				$trans["spl_pa"] = $trans["spl_pa"];			
				$trans["woff_days"] = $trans["woff_days"];			
				$trans["tds"] = $trans["tds"];			
				$trans["company_lwf"] = $trans["company_lwf"];			
				$trans["salary_loan"] = $trans["salary_loan"];			
				$trans["dorm"] = $trans["dorm"];			
				$trans["meal"] = $trans["meal"];			
				$trans["other_deduction"] = $trans["other_deduction"];			
				$trans["pf_eligibility"] = $trans["pf_eligibility"];			
				$trans["department"] = $trans["department"];			
				$trans["designation"] = $trans["designation"];			
				$trans["monthly_tds"] = $trans["monthly_tds"];			
				$trans["differential_day"] = $this->Process_payroll_model->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);			
				$trans["separation_day"] = $trans["separation_day"];			
				$trans["fixed_basic"] = $trans["fixed_basic"];			
				$trans["a_basic"] = $this->rounding_value(($trans["a_basic"]),'>1');			
				$trans["pf_tag"] = $trans["pf_tag"];			
				$trans["paid_days"] = $trans["month_days"]-($trans["lop_days"]+$trans["differential_day"]+$trans["separation_day"]);			
				$trans["basic"] = $this->rounding_value((($trans["fixed_basic"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["cl_balance"] = $trans["cl_op"]-$trans["casual_leave"];			
				$trans["econ"] = $this->rounding_value((($trans["fcon"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["da"] = $this->rounding_value((($trans["fixed_da"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["el_bal"] = $trans["el_op"]-$trans["el"];			
				$trans["hra"] = $this->rounding_value((($trans["fixed_hra"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["lev_encashrate"] = $trans["fixed_basic"]/26;			
				$trans["lev_encashamt"] = $trans["lev_encashday"]*$trans["lev_encashrate"];			
				$trans["elta"] = $this->rounding_value((($trans["flta"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["emed"] = $this->rounding_value((($trans["fmed"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["eot"] = $this->rounding_value((((($trans["fixed_gross"]/26)/8)*2)*$trans["ot_hrs"]),'>1');			
				$trans["pot"] = $this->rounding_value((((($trans["fixed_gross"]/26)/8)*2)*$trans["pot_hrs"]),'>1');			
				$trans["espl"] = $this->rounding_value((($trans["fspl"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["etfa"] = $trans["ftfa"];			
				$trans["gross"] = $trans["basic"]+$trans["da"]+$trans["hra"]+$trans["espl"]+$trans["emed"]+$trans["elta"]+$trans["econ"];			
				$trans["nsa"] = $trans["nsd"]*50;			
				$trans["mgs"] = $trans["basic"]+$trans["da"]+$trans["hra"]+$trans["econ"]+$trans["espl"]+$trans["emed"]+$trans["elta"]+$trans["spl_pa"]+$trans["etfa"]+$trans["att_bns"]+$trans["nsa"]+$trans["fo_allowance"]+$trans["bonus"]+$trans["pb_ars"]+$trans["po_ars"]+$trans["eot"]+$trans["pot"];			
				$a=15000;if($trans["pf_tag"]==2){if($trans["gross"]>15000){$trans["pf_gross"] = $a;}elseif($trans["gross"]<15000){$trans["pf_gross"] = $trans["gross"];}}elseif($trans["pf_tag"]==3){$trans["pf_gross"] = $trans["basic"]+$trans["da"];}else{$trans["pf_gross"] = 0;}
				$a=0;if($trans["fixed_gross"]>21000){$trans["esi_gross"] = $a;}else{$trans["esi_gross"] = $trans["mgs"];}
				$trans["pf"] = $this->rounding_value(($trans["pf_gross"]*(12/100)),'1');			
				$trans["esi"] = $this->rounding_value(($trans["esi_gross"]*(0.75/100)),'1');			
				$trans["professional_tax"] = $this->Process_payroll_model->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["pt_projection"],$trans["mgs"],$trans["transactions_month"]);			
				$trans["esi_eligibility"] = $trans["fixed_basic"]+$trans["fixed_da"]+$trans["fixed_hra"]+$trans["fcon"]+$trans["fmed"]+$trans["flta"]+$trans["fspl"];			
				$trans["total_deductions"] = $this->rounding_value(($trans["pf"]+$trans["esi"]+$trans["tds"]+$trans["professional_tax"]+$trans["meal"]+$trans["dorm"]+$trans["company_lwf"]+$trans["other_deduction"]+$trans["salary_loan"]+$trans["monthly_tds"]),'1');			
				$trans["employee_pf"] = $this->rounding_value(($trans["pf_gross"]*(3.67/100)),'1');			
				$trans["employer_pf"] = $this->rounding_value(($trans["pf_gross"]*(8.33/100)),'1');			
				$trans["emp_esi"] = $trans["esi_gross"]*(3.25/100);			
				$trans["total_esi"] = $this->rounding_value(($trans["emp_esi"]+$trans["esi"]),'1');			
				$trans["net_pay"] = $this->rounding_value(($trans["mgs"]-$trans["total_deductions"]),'1');			$payroll_array[2][] ="('".$trans["employees_id"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["transactions_month"]."','".$trans["role"]."','".$trans["transactions_month"]."','".$trans["termination_status"]."','".$trans["month_days"]."','".$trans["lop_days"]."','".$trans["a_da"]."','".$trans["a_hra"]."','".$trans["att_bns"]."','".$trans["bonus"]."','".$trans["casual_leave"]."','".$trans["cl_op"]."','".$trans["fcon"]."','".$trans["fixed_da"]."','".$trans["el"]."','".$trans["el_op"]."','".$trans["fixed_hra"]."','".$trans["fixed_gross"]."','".$trans["flta"]."','".$trans["fmed"]."','".$trans["fspl"]."','".$trans["ftfa"]."','".$trans["hd"]."','".$trans["lev_encashday"]."','".$trans["nsd"]."','".$trans["notice_period"]."','".$trans["ot_hrs"]."','".$trans["otr"]."','".$trans["fo_allowance"]."','".$trans["pb_ars"]."','".$trans["pot_hrs"]."','".$trans["potr"]."','".$trans["po_ars"]."','".$trans["prd"]."','".$trans["spm"]."','".$trans["spl_pa"]."','".$trans["woff_days"]."','".$trans["tds"]."','".$trans["company_lwf"]."','".$trans["salary_loan"]."','".$trans["dorm"]."','".$trans["meal"]."','".$trans["other_deduction"]."','".$trans["pf_eligibility"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["monthly_tds"]."','".$trans["differential_day"]."','".$trans["separation_day"]."','".$trans["fixed_basic"]."','".$trans["a_basic"]."','".$trans["pf_tag"]."','".$trans["paid_days"]."','".$trans["basic"]."','".$trans["cl_balance"]."','".$trans["econ"]."','".$trans["da"]."','".$trans["el_bal"]."','".$trans["hra"]."','".$trans["lev_encashrate"]."','".$trans["lev_encashamt"]."','".$trans["elta"]."','".$trans["emed"]."','".$trans["eot"]."','".$trans["pot"]."','".$trans["espl"]."','".$trans["etfa"]."','".$trans["gross"]."','".$trans["nsa"]."','".$trans["mgs"]."','".$trans["pf_gross"]."','".$trans["esi_gross"]."','".$trans["pf"]."','".$trans["esi"]."','".$trans["professional_tax"]."','".$trans["esi_eligibility"]."','".$trans["total_deductions"]."','".$trans["employee_pf"]."','".$trans["employer_pf"]."','".$trans["emp_esi"]."','".$trans["total_esi"]."','".$trans["net_pay"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."')";
						
		 $query_key = 'employees_id,employee_code,emp_name,transactions_month,role,process_month,termination_status,month_days,lop_days,a_da,a_hra,att_bns,bonus,casual_leave,cl_op,fcon,fixed_da,el,el_op,fixed_hra,fixed_gross,flta,fmed,fspl,ftfa,hd,lev_encashday,nsd,notice_period,ot_hrs,otr,fo_allowance,pb_ars,pot_hrs,potr,po_ars,prd,spm,spl_pa,woff_days,tds,company_lwf,salary_loan,dorm,meal,other_deduction,pf_eligibility,department,designation,monthly_tds,differential_day,separation_day,fixed_basic,a_basic,pf_tag,paid_days,basic,cl_balance,econ,da,el_bal,hra,lev_encashrate,lev_encashamt,elta,emed,eot,pot,espl,etfa,gross,nsa,mgs,pf_gross,esi_gross,pf,esi,professional_tax,esi_eligibility,total_deductions,employee_pf,employer_pf,emp_esi,total_esi,net_pay,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance'; 
	 $qry_2 = 'INSERT INTO cw_transactions(employees_id,employee_code,emp_name,transactions_month,role,process_month,termination_status,month_days,lop_days,a_da,a_hra,att_bns,bonus,casual_leave,cl_op,fcon,fixed_da,el,el_op,fixed_hra,fixed_gross,flta,fmed,fspl,ftfa,hd,lev_encashday,nsd,notice_period,ot_hrs,otr,fo_allowance,pb_ars,pot_hrs,potr,po_ars,prd,spm,spl_pa,woff_days,tds,company_lwf,salary_loan,dorm,meal,other_deduction,pf_eligibility,department,designation,monthly_tds,differential_day,separation_day,fixed_basic,a_basic,pf_tag,paid_days,basic,cl_balance,econ,da,el_bal,hra,lev_encashrate,lev_encashamt,elta,emed,eot,pot,espl,etfa,gross,nsa,mgs,pf_gross,esi_gross,pf,esi,professional_tax,esi_eligibility,total_deductions,employee_pf,employer_pf,emp_esi,total_esi,net_pay,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance'.$trans_key_array.') VALUES '.implode(',',$payroll_array[2]); 
			}else
			if((int)$trans["role"] === 4){
				$trans["pf_eligibility"] = $trans["pf_eligibility"];			
				$trans["month_days"] = $this->Process_payroll_model->get_total_work_days($trans["role"],$trans["transactions_month"]);			
				$trans["lop_days"] = $trans["lop_days"];			
				$trans["a_da"] = $trans["a_da"];			
				$trans["a_hra"] = $trans["a_hra"];			
				$trans["att_bns"] = $trans["att_bns"];			
				$trans["bonus"] = $trans["bonus"];			
				$trans["casual_leave"] = $trans["casual_leave"];			
				$trans["cl_op"] = $trans["cl_op"];			
				$trans["fcon"] = $trans["fcon"];			
				$trans["department"] = $trans["department"];			
				$trans["fixed_da"] = $trans["fixed_da"];			
				$trans["designation"] = $trans["designation"];			
				$trans["el"] = $trans["el"];			
				$trans["el_op"] = $trans["el_op"];			
				$trans["fixed_hra"] = $trans["fixed_hra"];			
				$trans["monthly_tds"] = $trans["monthly_tds"];			
				$trans["flta"] = $trans["flta"];			
				$trans["fmed"] = $trans["fmed"];			
				$trans["fspl"] = $trans["fspl"];			
				$trans["differential_day"] = $this->Process_payroll_model->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);			
				$trans["ftfa"] = $trans["ftfa"];			
				$trans["gratuity"] = $trans["gratuity"];			
				$trans["hd"] = $trans["hd"];			
				$trans["separation_day"] = $trans["separation_day"];			
				$trans["lev_encashday"] = $trans["lev_encashday"];			
				$trans["fixed_basic"] = $trans["fixed_basic"];			
				$trans["a_basic"] = $this->rounding_value(($trans["a_basic"]),'>1');			
				$trans["nsd"] = $trans["nsd"];			
				$trans["notice_period"] = $trans["notice_period"];			
				$trans["ot_hrs"] = $trans["ot_hrs"];			
				$trans["otr"] = $trans["otr"];			
				$trans["fo_allowance"] = $trans["fo_allowance"];			
				$trans["pb_ars"] = $trans["pb_ars"];			
				$trans["pot_hrs"] = $trans["pot_hrs"];			
				$trans["potr"] = $trans["potr"];			
				$trans["po_ars"] = $trans["po_ars"];			
				$trans["fixed_gross"] = $trans["fixed_gross"];			
				$trans["prd"] = $trans["prd"];			
				$trans["spm"] = $trans["spm"];			
				$trans["spl_pa"] = $trans["spl_pa"];			
				$trans["woff_days"] = $trans["woff_days"];			
				$trans["tds"] = $trans["tds"];			
				$trans["company_lwf"] = $trans["company_lwf"];			
				$trans["salary_loan"] = $trans["salary_loan"];			
				$trans["dorm"] = $trans["dorm"];			
				$trans["meal"] = $trans["meal"];			
				$trans["other_deduction"] = $trans["other_deduction"];			
				$trans["paid_days"] = $trans["month_days"]-($trans["lop_days"]+$trans["differential_day"]+$trans["separation_day"]);			
				$trans["basic"] = $this->rounding_value((($trans["fixed_basic"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["cl_balance"] = $trans["cl_op"]-$trans["casual_leave"];			
				$trans["econ"] = $this->rounding_value((($trans["fcon"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["da"] = $this->rounding_value((($trans["fixed_da"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["el_bal"] = $trans["el_op"]-$trans["el"];			
				$trans["hra"] = $this->rounding_value((($trans["fixed_hra"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["lev_encashrate"] = $trans["fixed_basic"]/26;			
				$trans["lev_encashamt"] = $trans["lev_encashday"]*$trans["lev_encashrate"];			
				$trans["elta"] = $this->rounding_value((($trans["flta"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["emed"] = $this->rounding_value((($trans["fmed"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["eot"] = $this->rounding_value((((($trans["fixed_gross"]/26)/8)*2)*$trans["ot_hrs"]),'>1');			
				$trans["pot"] = $this->rounding_value((((($trans["fixed_gross"]/26)/8)*2)*$trans["pot_hrs"]),'>1');			
				$trans["espl"] = $this->rounding_value((($trans["fspl"]/$trans["month_days"])*$trans["paid_days"]),'>1');			
				$trans["etfa"] = $trans["ftfa"];			
				$trans["gross"] = $trans["basic"]+$trans["da"]+$trans["hra"]+$trans["espl"]+$trans["emed"]+$trans["elta"]+$trans["econ"];			
				$trans["nsa"] = $trans["nsd"]*50;			
				$trans["mgs"] = $trans["gross"]+$trans["spl_pa"]+$trans["etfa"]+$trans["att_bns"]+$trans["nsa"]+$trans["fo_allowance"]+$trans["bonus"]+$trans["pb_ars"]+$trans["po_ars"]+$trans["eot"]+$trans["pot"];			
				$a=0;if($trans["fixed_gross"]>21000){$trans["esi_gross"] = $a;}else{$trans["esi_gross"] = $trans["mgs"];}
				$trans["esi"] = $this->rounding_value(($trans["esi_gross"]*(0)),'1');			
				$trans["professional_tax"] = $this->Process_payroll_model->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["pt_projection"],$trans["mgs"],$trans["transactions_month"]);			
				$trans["esi_eligibility"] = $trans["fixed_basic"]+$trans["fixed_da"]+$trans["fixed_hra"]+$trans["fcon"]+$trans["fmed"]+$trans["flta"]+$trans["fspl"];			
				$trans["pf_gross"] = $trans["gross"];			
				$trans["pf"] = $this->rounding_value((($trans["pf_gross"])*(12/100)),'1');			
				$trans["total_deductions"] = $this->rounding_value(($trans["pf"]+$trans["esi"]+$trans["tds"]+$trans["professional_tax"]+$trans["meal"]+$trans["dorm"]+$trans["company_lwf"]+$trans["other_deduction"]+$trans["salary_loan"]+$trans["monthly_tds"]),'1');			
				$trans["net_pay"] = $this->rounding_value(($trans["mgs"]-$trans["total_deductions"]),'1');			$payroll_array[4][] ="('".$trans["employees_id"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["transactions_month"]."','".$trans["role"]."','".$trans["transactions_month"]."','".$trans["termination_status"]."','".$trans["pf_eligibility"]."','".$trans["month_days"]."','".$trans["lop_days"]."','".$trans["a_da"]."','".$trans["a_hra"]."','".$trans["att_bns"]."','".$trans["bonus"]."','".$trans["casual_leave"]."','".$trans["cl_op"]."','".$trans["fcon"]."','".$trans["department"]."','".$trans["fixed_da"]."','".$trans["designation"]."','".$trans["el"]."','".$trans["el_op"]."','".$trans["fixed_hra"]."','".$trans["monthly_tds"]."','".$trans["flta"]."','".$trans["fmed"]."','".$trans["fspl"]."','".$trans["differential_day"]."','".$trans["ftfa"]."','".$trans["gratuity"]."','".$trans["hd"]."','".$trans["separation_day"]."','".$trans["lev_encashday"]."','".$trans["fixed_basic"]."','".$trans["a_basic"]."','".$trans["nsd"]."','".$trans["notice_period"]."','".$trans["ot_hrs"]."','".$trans["otr"]."','".$trans["fo_allowance"]."','".$trans["pb_ars"]."','".$trans["pot_hrs"]."','".$trans["potr"]."','".$trans["po_ars"]."','".$trans["fixed_gross"]."','".$trans["prd"]."','".$trans["spm"]."','".$trans["spl_pa"]."','".$trans["woff_days"]."','".$trans["tds"]."','".$trans["company_lwf"]."','".$trans["salary_loan"]."','".$trans["dorm"]."','".$trans["meal"]."','".$trans["other_deduction"]."','".$trans["paid_days"]."','".$trans["basic"]."','".$trans["cl_balance"]."','".$trans["econ"]."','".$trans["da"]."','".$trans["el_bal"]."','".$trans["hra"]."','".$trans["lev_encashrate"]."','".$trans["lev_encashamt"]."','".$trans["elta"]."','".$trans["emed"]."','".$trans["eot"]."','".$trans["pot"]."','".$trans["espl"]."','".$trans["etfa"]."','".$trans["gross"]."','".$trans["nsa"]."','".$trans["mgs"]."','".$trans["esi_gross"]."','".$trans["esi"]."','".$trans["professional_tax"]."','".$trans["esi_eligibility"]."','".$trans["pf_gross"]."','".$trans["pf"]."','".$trans["total_deductions"]."','".$trans["net_pay"]."','".$trans["salary_loan_total"]."','".$trans["salary_loan_installments"]."','".$trans["salary_loan_instal_count"]."','".$trans["salary_loan_balance"]."')";
						
		 $query_key = 'employees_id,employee_code,emp_name,transactions_month,role,process_month,termination_status,pf_eligibility,month_days,lop_days,a_da,a_hra,att_bns,bonus,casual_leave,cl_op,fcon,department,fixed_da,designation,el,el_op,fixed_hra,monthly_tds,flta,fmed,fspl,differential_day,ftfa,gratuity,hd,separation_day,lev_encashday,fixed_basic,a_basic,nsd,notice_period,ot_hrs,otr,fo_allowance,pb_ars,pot_hrs,potr,po_ars,fixed_gross,prd,spm,spl_pa,woff_days,tds,company_lwf,salary_loan,dorm,meal,other_deduction,paid_days,basic,cl_balance,econ,da,el_bal,hra,lev_encashrate,lev_encashamt,elta,emed,eot,pot,espl,etfa,gross,nsa,mgs,esi_gross,esi,professional_tax,esi_eligibility,pf_gross,pf,total_deductions,net_pay,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance'; 
	 $qry_4 = 'INSERT INTO cw_transactions(employees_id,employee_code,emp_name,transactions_month,role,process_month,termination_status,pf_eligibility,month_days,lop_days,a_da,a_hra,att_bns,bonus,casual_leave,cl_op,fcon,department,fixed_da,designation,el,el_op,fixed_hra,monthly_tds,flta,fmed,fspl,differential_day,ftfa,gratuity,hd,separation_day,lev_encashday,fixed_basic,a_basic,nsd,notice_period,ot_hrs,otr,fo_allowance,pb_ars,pot_hrs,potr,po_ars,fixed_gross,prd,spm,spl_pa,woff_days,tds,company_lwf,salary_loan,dorm,meal,other_deduction,paid_days,basic,cl_balance,econ,da,el_bal,hra,lev_encashrate,lev_encashamt,elta,emed,eot,pot,espl,etfa,gross,nsa,mgs,esi_gross,esi,professional_tax,esi_eligibility,pf_gross,pf,total_deductions,net_pay,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance'.$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[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;
	}

}
?>