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/.trash/backup/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"] === 2){
				$trans["lop_days"] = $trans["lop_days"];			
				$trans["month_days"] = $this->Process_payroll_model->get_total_work_days($trans["role"],$trans["transactions_month"]);			
				$trans["tds_percent"] = $trans["tds_percent"];			
				$trans["professional_tax_location"] = $trans["professional_tax_location"];			
				$trans["differential_day"] = $this->Process_payroll_model->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);			
				$trans["fixed_gross"] = $trans["fixed_gross"];			
				$trans["other_deduction"] = $trans["other_deduction"];			
				$trans["salary_loan"] = $trans["salary_loan"];			
				$trans["marketing_percentage"] = $trans["marketing_percentage"];			
				$trans["pf_eligibility"] = $trans["pf_eligibility"];			
				$trans["esi_eligibility"] = $trans["esi_eligibility"];			
				$trans["salary_advance"] = $trans["salary_advance"];			
				$trans["pre_count"] = $trans["pre_count"];			
				$trans["trainee_deduction"] = $trans["trainee_deduction"];			
				$trans["date_of_joining"] = $trans["date_of_joining"];			
				$trans["fixed_basic"] = $this->rounding_value(($trans["fixed_gross"]*(40/100)),'1');			
				$trans["fixed_hra"] = $this->rounding_value(($trans["fixed_gross"]*(30/100)),'1');			
				$trans["fixed_da"] = $this->rounding_value(($trans["fixed_basic"]*(50/100)),'1');			
				$trans["fo_allowance"] = $this->rounding_value(($trans["fixed_da"]*(50/100)),'1');			
				$trans["paid_days"] = $trans["month_days"]-$trans["lop_days"]-$trans["differential_day"];			
				$trans["basic"] = $this->rounding_value((($trans["fixed_basic"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				$trans["hra"] = $this->rounding_value((($trans["fixed_hra"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				$trans["da"] = $this->rounding_value((($trans["fixed_da"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				$trans["other_allowance"] = $this->rounding_value((($trans["fo_allowance"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				$trans["gross"] = $trans["basic"]+$trans["hra"]+$trans["da"]+$trans["other_allowance"];			
				if($trans["pf_eligibility"]==1){$trans["pf_gross"] = ($trans["basic"]+$trans["da"]+$trans["other_allowance"]);}else{$trans["pf_gross"] = 0;}
				$trans["tds_amount"] = $this->rounding_value(($trans["gross"]*($trans["tds_percent"]/100)),'1');			
				if($trans["pf_eligibility"]==1){$trans["pf"] = round($trans["pf_gross"]*(12/100));}else{$trans["pf"] = 0;}
				if($trans["esi_eligibility"]==1){$trans["esi_gross"] = $trans["gross"];}else{$trans["esi_gross"] = 0;}
				if($trans["esi_eligibility"]==1){$trans["esi"] = ceil($trans["esi_gross"]*(0.75/100));}else{$trans["esi"] = 0;}
				if($trans["pf_eligibility"]==1){$trans["employer_pf"] = round($trans["pf_gross"]*(12/100));}else{$trans["employer_pf"] = 0;}
				if($trans["esi_eligibility"]==1){$trans["emp_esi"] = ceil($trans["esi_gross"]*(3.25/100));}else{$trans["emp_esi"] = 0;}
				$trans["pt_projection"] = $trans["fixed_gross"];			
				$trans["payroll_count"] = $trans["pre_count"]+1;			
				$trans["perday"] = $this->rounding_value(($trans["fixed_gross"]/$trans["month_days"]),'1');			
				if(($trans["trainee_deduction"]==1)&&($trans["payroll_count"]==1)){$trans["salary_deduction"] = round($trans["perday"]*7);}else{$trans["salary_deduction"] = 0;}
				if(($trans["trainee_deduction"]==1)&&($trans["payroll_count"]==4)){$x=round($trans["perday"]*7);$y=round($x*(20/100));$z=$x+$y;$trans["emp_incentive"] = $z;}else{$trans["emp_incentive"] = 0;}
				$trans["total_earnings"] = $trans["gross"]+$trans["emp_incentive"];			
				$trans["marketing_amount"] = $this->rounding_value(($trans["total_earnings"]*($trans["marketing_percentage"]/100)),'1');			
				$trans["professional_tax"] = $this->Process_payroll_model->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["pt_projection"],$trans["total_earnings"],$trans["transactions_month"]);			
				$trans["total_deductions"] = $trans["pf"]+$trans["esi"]+$trans["professional_tax"]+$trans["tds_amount"]+$trans["marketing_amount"]+$trans["salary_advance"]+$trans["salary_deduction"]+$trans["salary_loan"];			
				$trans["net_pay"] = $trans["total_earnings"]-$trans["total_deductions"];			$payroll_array[2][] ="('".$trans["employees_id"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["transactions_month"]."','".$trans["role"]."','".$trans["transactions_month"]."','".$trans["termination_status"]."','".$trans["lop_days"]."','".$trans["month_days"]."','".$trans["tds_percent"]."','".$trans["professional_tax_location"]."','".$trans["differential_day"]."','".$trans["fixed_gross"]."','".$trans["other_deduction"]."','".$trans["salary_loan"]."','".$trans["marketing_percentage"]."','".$trans["pf_eligibility"]."','".$trans["esi_eligibility"]."','".$trans["salary_advance"]."','".$trans["pre_count"]."','".$trans["trainee_deduction"]."','".$trans["date_of_joining"]."','".$trans["fixed_basic"]."','".$trans["fixed_hra"]."','".$trans["fixed_da"]."','".$trans["fo_allowance"]."','".$trans["paid_days"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["da"]."','".$trans["other_allowance"]."','".$trans["gross"]."','".$trans["pf_gross"]."','".$trans["tds_amount"]."','".$trans["pf"]."','".$trans["esi_gross"]."','".$trans["esi"]."','".$trans["employer_pf"]."','".$trans["emp_esi"]."','".$trans["pt_projection"]."','".$trans["payroll_count"]."','".$trans["perday"]."','".$trans["salary_deduction"]."','".$trans["emp_incentive"]."','".$trans["total_earnings"]."','".$trans["marketing_amount"]."','".$trans["professional_tax"]."','".$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,lop_days,month_days,tds_percent,professional_tax_location,differential_day,fixed_gross,other_deduction,salary_loan,marketing_percentage,pf_eligibility,esi_eligibility,salary_advance,pre_count,trainee_deduction,date_of_joining,fixed_basic,fixed_hra,fixed_da,fo_allowance,paid_days,basic,hra,da,other_allowance,gross,pf_gross,tds_amount,pf,esi_gross,esi,employer_pf,emp_esi,pt_projection,payroll_count,perday,salary_deduction,emp_incentive,total_earnings,marketing_amount,professional_tax,total_deductions,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,lop_days,month_days,tds_percent,professional_tax_location,differential_day,fixed_gross,other_deduction,salary_loan,marketing_percentage,pf_eligibility,esi_eligibility,salary_advance,pre_count,trainee_deduction,date_of_joining,fixed_basic,fixed_hra,fixed_da,fo_allowance,paid_days,basic,hra,da,other_allowance,gross,pf_gross,tds_amount,pf,esi_gross,esi,employer_pf,emp_esi,pt_projection,payroll_count,perday,salary_deduction,emp_incentive,total_earnings,marketing_amount,professional_tax,total_deductions,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"] === 3){
				$trans["lop_days"] = $trans["lop_days"];			
				$trans["month_days"] = $this->Process_payroll_model->get_total_work_days($trans["role"],$trans["transactions_month"]);			
				$trans["tds_percent"] = $trans["tds_percent"];			
				$trans["professional_tax_location"] = $trans["professional_tax_location"];			
				$trans["differential_day"] = $this->Process_payroll_model->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);			
				$trans["fixed_gross"] = $trans["fixed_gross"];			
				$trans["other_deduction"] = $trans["other_deduction"];			
				$trans["salary_loan"] = $trans["salary_loan"];			
				$trans["marketing_percentage"] = $trans["marketing_percentage"];			
				$trans["pf_eligibility"] = $trans["pf_eligibility"];			
				$trans["esi_eligibility"] = $trans["esi_eligibility"];			
				$trans["salary_advance"] = $trans["salary_advance"];			
				$trans["pre_count"] = $trans["pre_count"];			
				$trans["date_of_joining"] = $trans["date_of_joining"];			
				$trans["trainee_deduction"] = $trans["trainee_deduction"];			
				$trans["supplementary_month"] = $trans["supplementary_month"];			
				$trans["supplementary_day"] = $trans["supplementary_day"];			
				$trans["a_gross"] = $trans["a_gross"];			
				$trans["fixed_basic"] = $this->rounding_value(($trans["fixed_gross"]*(40/100)),'1');			
				$trans["fixed_hra"] = $this->rounding_value(($trans["fixed_gross"]*(30/100)),'1');			
				$trans["fixed_da"] = $this->rounding_value(($trans["fixed_basic"]*(50/100)),'1');			
				$trans["fo_allowance"] = $this->rounding_value(($trans["fixed_da"]*(50/100)),'1');			
				$trans["paid_days"] = $trans["month_days"]-$trans["lop_days"]-$trans["differential_day"];			
				$trans["basic"] = $this->rounding_value((($trans["fixed_basic"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				$trans["hra"] = $this->rounding_value((($trans["fixed_hra"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				$trans["da"] = $this->rounding_value((($trans["fixed_da"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				$trans["other_allowance"] = $this->rounding_value((($trans["fo_allowance"]/$trans["month_days"])*$trans["paid_days"]),'1');			
				if($trans["pf_eligibility"]==1){$trans["pf_gross"] = ($trans["basic"]+$trans["da"]+$trans["other_allowance"]);}else{$trans["pf_gross"] = 0;}
				if($trans["pf_eligibility"]==1){$trans["pf"] = round($trans["pf_gross"]*(12/100));}else{$trans["pf"] = 0;}
				if($trans["pf_eligibility"]==1){$trans["employer_pf"] = round($trans["pf_gross"]*(12/100));}else{$trans["employer_pf"] = 0;}
				$trans["pt_projection"] = $trans["fixed_gross"];			
				$trans["payroll_count"] = $trans["pre_count"]+1;			
				$trans["perday"] = $this->rounding_value(($trans["fixed_gross"]/$trans["month_days"]),'1');			
				if(($trans["trainee_deduction"]==1)&&($trans["payroll_count"]==1)){$trans["salary_deduction"] = round($trans["perday"]*7);}else{$trans["salary_deduction"] = 0;}
				if(($trans["trainee_deduction"]==1)&&($trans["payroll_count"]==4)){$x=round($trans["perday"]*7);$y=round($x*(20/100));$z=$x+$y;$trans["emp_incentive"] = $z;}else{$trans["emp_incentive"] = 0;}
				$trans["s_basic"] = $this->rounding_value(($this->dz(($trans["fixed_basic"]/$trans["supplementary_month"])*$trans["supplementary_day"])),'1');			
				$trans["s_hra"] = $this->rounding_value(($this->dz(($trans["fixed_hra"]/$trans["supplementary_month"])*$trans["supplementary_day"])),'1');			
				$trans["s_conveyance"] = $this->rounding_value(($this->dz(($trans["fixed_da"]/$trans["supplementary_month"])*$trans["supplementary_day"])),'1');			
				$trans["s_other_allowance"] = $this->rounding_value(($this->dz(($trans["fo_allowance"]/$trans["supplementary_month"])*$trans["supplementary_day"])),'1');			
				$trans["s_gross"] = $trans["s_basic"]+$trans["s_conveyance"]+$trans["s_hra"]+$trans["s_other_allowance"];			
				$trans["gross"] = $trans["basic"]+$trans["hra"]+$trans["da"]+$trans["other_allowance"]+$trans["s_gross"];			
				$trans["total_earnings"] = $trans["gross"]+$trans["emp_incentive"]+$trans["a_gross"];			
				$trans["professional_tax"] = $this->Process_payroll_model->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["pt_projection"],$trans["total_earnings"],$trans["transactions_month"]);			
				if($trans["esi_eligibility"]==1){$trans["esi_gross"] = $trans["gross"];}else{$trans["esi_gross"] = 0;}
				if($trans["esi_eligibility"]==1){$trans["emp_esi"] = ceil($trans["esi_gross"]*(3.25/100));}else{$trans["emp_esi"] = 0;}
				if($trans["esi_eligibility"]==1){$trans["esi"] = ceil($trans["esi_gross"]*(0.75/100));}else{$trans["esi"] = 0;}
				$trans["tds_amount"] = $this->rounding_value(($trans["gross"]*($trans["tds_percent"]/100)),'1');			
				$trans["marketing_amount"] = $this->rounding_value((($trans["total_earnings"]-$trans["salary_deduction"])*(3.75/100)),'1');			
				$trans["total_deductions"] = $trans["pf"]+$trans["esi"]+$trans["professional_tax"]+$trans["tds_amount"]+$trans["marketing_amount"]+$trans["salary_advance"]+$trans["salary_deduction"]+$trans["salary_loan"]+$trans["other_deduction"];			
				$trans["net_pay"] = $trans["total_earnings"]-$trans["total_deductions"];			$payroll_array[3][] ="('".$trans["employees_id"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["transactions_month"]."','".$trans["role"]."','".$trans["transactions_month"]."','".$trans["termination_status"]."','".$trans["lop_days"]."','".$trans["month_days"]."','".$trans["tds_percent"]."','".$trans["professional_tax_location"]."','".$trans["differential_day"]."','".$trans["fixed_gross"]."','".$trans["other_deduction"]."','".$trans["salary_loan"]."','".$trans["marketing_percentage"]."','".$trans["pf_eligibility"]."','".$trans["esi_eligibility"]."','".$trans["salary_advance"]."','".$trans["pre_count"]."','".$trans["date_of_joining"]."','".$trans["trainee_deduction"]."','".$trans["supplementary_month"]."','".$trans["supplementary_day"]."','".$trans["a_gross"]."','".$trans["fixed_basic"]."','".$trans["fixed_hra"]."','".$trans["fixed_da"]."','".$trans["fo_allowance"]."','".$trans["paid_days"]."','".$trans["basic"]."','".$trans["hra"]."','".$trans["da"]."','".$trans["other_allowance"]."','".$trans["pf_gross"]."','".$trans["pf"]."','".$trans["employer_pf"]."','".$trans["pt_projection"]."','".$trans["payroll_count"]."','".$trans["perday"]."','".$trans["salary_deduction"]."','".$trans["emp_incentive"]."','".$trans["s_basic"]."','".$trans["s_hra"]."','".$trans["s_conveyance"]."','".$trans["s_other_allowance"]."','".$trans["s_gross"]."','".$trans["gross"]."','".$trans["total_earnings"]."','".$trans["professional_tax"]."','".$trans["esi_gross"]."','".$trans["emp_esi"]."','".$trans["esi"]."','".$trans["tds_amount"]."','".$trans["marketing_amount"]."','".$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,lop_days,month_days,tds_percent,professional_tax_location,differential_day,fixed_gross,other_deduction,salary_loan,marketing_percentage,pf_eligibility,esi_eligibility,salary_advance,pre_count,date_of_joining,trainee_deduction,supplementary_month,supplementary_day,a_gross,fixed_basic,fixed_hra,fixed_da,fo_allowance,paid_days,basic,hra,da,other_allowance,pf_gross,pf,employer_pf,pt_projection,payroll_count,perday,salary_deduction,emp_incentive,s_basic,s_hra,s_conveyance,s_other_allowance,s_gross,gross,total_earnings,professional_tax,esi_gross,emp_esi,esi,tds_amount,marketing_amount,total_deductions,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,lop_days,month_days,tds_percent,professional_tax_location,differential_day,fixed_gross,other_deduction,salary_loan,marketing_percentage,pf_eligibility,esi_eligibility,salary_advance,pre_count,date_of_joining,trainee_deduction,supplementary_month,supplementary_day,a_gross,fixed_basic,fixed_hra,fixed_da,fo_allowance,paid_days,basic,hra,da,other_allowance,pf_gross,pf,employer_pf,pt_projection,payroll_count,perday,salary_deduction,emp_incentive,s_basic,s_hra,s_conveyance,s_other_allowance,s_gross,gross,total_earnings,professional_tax,esi_gross,emp_esi,esi,tds_amount,marketing_amount,total_deductions,net_pay,salary_loan_total,salary_loan_installments,salary_loan_instal_count,salary_loan_balance'.$trans_key_array.') VALUES '.implode(',',$payroll_array[3]); 
			}
		}  
	 if($payroll_array[2]){ 
	 $this->db->query($qry_2); 
	 }
	 if($payroll_array[3]){ 
	 $this->db->query($qry_3); 
	 } 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;
	}

}
?>