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/cloud_cafsinfotech_in/application/models/Payroll_calculation_model.php
<?php
 class Payroll_calculation_model extends CI_Model{ 
			private $payroll_count;
		 
	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();

		$this->payroll_count = array_reduce($payroll_exist_result, function ($result, $arr){
		    $result[$arr['employee_code']] = $arr['pay_count'];
		    return $result;
		}, array());
	
        //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();
		$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();
		$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"); 
		 $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["differential_day"] = $this->get_differential_day($trans["employee_code"],$trans["role"],$trans["transactions_month"]);			
				$trans["ab"] = $this->rounding_value(($trans["ab"]),'1');			
				$trans["acea"] = $trans["acea"];			
				$trans["aconv"] = $trans["aconv"];			
				$trans["actc"] = $trans["actc"];			
				$trans["adv"] = $this->rounding_value(($trans["adv"]),'1');			
				$trans["aepf"] = $trans["aepf"];			
				$trans["afg"] = $trans["afg"];			
				$trans["amed"] = $trans["amed"];			
				$trans["apa"] = $trans["apa"];			
				$trans["aphone"] = $trans["aphone"];			
				$trans["app"] = $trans["app"];			
				$trans["arrearwithheld"] = $trans["arrearwithheld"];			
				$trans["att_per"] = $trans["att_per"];			
				$trans["b_inc"] = $trans["b_inc"];			
				$trans["bonus"] = $trans["bonus"];			
				$trans["cl"] = $trans["cl"];			
				$trans["cl_op"] = $trans["cl_op"];			
				$trans["comcha"] = $trans["comcha"];			
				$trans["creadj"] = $trans["creadj"];			
				$trans["e_days"] = $trans["e_days"];			
				$trans["err_per"] = $trans["err_per"];			
				$trans["estatt"] = $trans["estatt"];			
				$trans["estpro"] = $trans["estpro"];			
				$trans["fattire"] = $trans["fattire"];			
				$trans["fca"] = $trans["fca"];			
				$trans["feb_inc"] = $trans["feb_inc"];			
				$trans["flb"] = $trans["flb"];			
				$trans["fma"] = $trans["fma"];			
				$trans["fmed"] = $trans["fmed"];			
				$trans["food_pd"] = $trans["food_pd"];			
				$trans["fpa"] = $trans["fpa"];			
				$trans["fphone"] = $trans["fphone"];			
				$trans["fpp"] = $trans["fpp"];			
				$trans["inc_adj"] = $trans["inc_adj"];			
				$trans["lapreim"] = $trans["lapreim"];			
				$trans["lcd"] = $trans["lcd"];			
				$trans["lcmd"] = $trans["lcmd"];			
				$trans["ld"] = $trans["ld"];			
				$trans["lectc"] = $trans["lectc"];			
				$trans["led"] = $trans["led"];			
				$trans["lev_encashday"] = $trans["lev_encashday"];			
				$trans["m_sft_pd"] = $trans["m_sft_pd"];			
				$trans["marrs"] = $trans["marrs"];			
				$trans["maxpf_sts"] = $trans["maxpf_sts"];			
				$trans["njcd"] = $trans["njcd"];			
				$trans["njd"] = $trans["njd"];			
				$trans["oj_inc"] = $trans["oj_inc"];			
				$trans["ot_hrs"] = $trans["ot_hrs"];			
				$trans["otadj"] = $trans["otadj"];			
				$trans["pmfd"] = $trans["pmfd"];			
				$trans["pmot"] = $trans["pmot"];			
				$trans["prod_per"] = $trans["prod_per"];			
				$trans["prptg"] = $trans["prptg"];			
				$trans["pyinc"] = $trans["pyinc"];			
				$trans["rapd"] = $trans["rapd"];			
				$trans["rbs"] = $trans["rbs"];			
				$trans["salarycutrepaym"] = $trans["salarycutrepaym"];			
				$trans["salaryheldff"] = $trans["salaryheldff"];			
				$trans["sctc"] = $trans["sctc"];			
				$trans["sft_km"] = $trans["sft_km"];			
				$trans["sft_pd"] = $trans["sft_pd"];			
				$trans["sft_rate"] = $trans["sft_rate"];			
				$trans["sftadj"] = $trans["sftadj"];			
				$trans["sl"] = $trans["sl"];			
				$trans["sl_op"] = $trans["sl_op"];			
				$trans["tds_ret"] = $trans["tds_ret"];			
				$trans["trainincent"] = $trans["trainincent"];			
				$trans["weekoff_days"] = $trans["weekoff_days"];			
				$trans["yinc"] = $trans["yinc"];			
				$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["agreementrecove"] = $trans["agreementrecove"];			
				$trans["arr_paid"] = $trans["arr_paid"];			
				$trans["arrearhold"] = $trans["arrearhold"];			
				$trans["esi_sts"] = $trans["esi_sts"];			
				$trans["incadjd"] = $trans["incadjd"];			
				$trans["nprd"] = $trans["nprd"];			
				$trans["pfsts"] = $trans["pfsts"];			
				$trans["rec"] = $trans["rec"];			
				$trans["sadv"] = $trans["sadv"];			
				$trans["sal_adv"] = $trans["sal_adv"];			
				$trans["salarycut"] = $trans["salarycut"];			
				$trans["salholdnotice"] = $trans["salholdnotice"];			
				$trans["monthly_tds"] = $trans["monthly_tds"];			
				$trans["tds_inc"] = $trans["tds_inc"];			
				$trans["fb"] = $this->rounding_value(($trans["fb"]),'1');			
				$trans["fcea"] = $trans["fcea"];			
				$trans["notice_period"] = $trans["notice_period"];			
				$trans["ahra"] = $this->rounding_value(($this->dz($trans["ab"]*50)/100),'1');			
				$trans["alta"] = $this->rounding_value(($this->dz($trans["ab"]*8.33)/100),'1');			
				$trans["axg"] = $this->rounding_value(($this->dz($trans["ab"]*8.33)/100),'1');			
				$trans["aoth_alw"] = $trans["actc"]-($trans["ab"]+$trans["ahra"]+$trans["alta"]+$trans["aphone"]+$trans["axg"]);			
				$trans["ag"] = $trans["ab"]+$trans["ahra"]+$trans["aconv"]+$trans["aoth_alw"]+$trans["acea"]+$trans["axg"]+$trans["alta"]+$trans["amed"]+$trans["aphone"]+$trans["marrs"];			
				$trans["cl_bal"] = $trans["cl_op"]-$trans["cl"];			
				$trans["pd"] = $trans["md"]-$trans["ld"]-$trans["separation_day"]+$trans["njd"]+$trans["rapd"]-$trans["njcd"]+$trans["e_days"];			
				$trans["conv"] = $this->rounding_value(($this->dz( $this->dz($trans["fca"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fca"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["eattire"] = $this->rounding_value(($this->dz( $this->dz($trans["fattire"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fattire"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["eb"] = $this->rounding_value(($this->dz( $this->dz($trans["fb"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fb"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["ecea"] = $this->rounding_value(($this->dz( $this->dz($trans["fcea"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fcea"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["flta"] = $this->rounding_value(($this->dz($trans["fb"]*8.33)/100),'1');			
				$trans["elta"] = $this->rounding_value(($this->dz( $this->dz($trans["flta"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["flta"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["emed"] = $this->rounding_value(($this->dz( $this->dz($trans["fmed"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fmed"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["epa"] = $this->rounding_value(($this->dz( $this->dz($trans["fpa"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fpa"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["ephone"] = $this->rounding_value(($this->dz( $this->dz($trans["fphone"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fphone"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["epp"] = $this->rounding_value(($this->dz( $this->dz($trans["fpp"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fpp"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["fxg"] = $this->rounding_value(($this->dz($trans["fb"]*8.33)/100),'1');			
				$trans["exg"] = $this->rounding_value(($this->dz( $this->dz($trans["fxg"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fxg"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["fctc"] = $trans["sctc"];			
				$trans["fhra"] = $this->rounding_value(($this->dz($trans["fb"]*50)/100),'1');			
				$trans["fininc"] = $trans["att_per"]+$trans["err_per"]+$trans["prod_per"];			
				$trans["food"] = (($trans["food_pd"]*80)+($trans["pmfd"]*80));			
				$trans["hra"] = $this->rounding_value(($this->dz( $this->dz($trans["fhra"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fhra"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["lev_encashrate"] = $trans["lectc"]/30;			
				$trans["lev_encashamt"] = $trans["led"]*$trans["lev_encashrate"];			
				$trans["loyalbon"] = $this->dz($trans["flb"]/$trans["md"])*$trans["pd"];			
				$trans["m_sft_alw"] = $trans["m_sft_pd"]*50;			
				$trans["mealallo"] = $this->rounding_value(($this->dz($trans["fma"]/$trans["md"])*$trans["pd"]),'1');			
				$trans["ot_rate"] = $this->dz($this->dz($this->dz($trans["fctc"]/30)/8)/60);			
				if($trans["ld"]==$trans["md"]){$trans["eot"] = $trans["pfsts"]*0;}else{$trans["eot"] = $trans["pfsts"];}
				if($trans["ot_hrs"]>960){$trans["ot_maxhrs"] = 960;}else{$trans["ot_maxhrs"] = $trans["ot_hrs"];}
				$trans["fpfgt"] = $this->rounding_value(($trans["fctc"]*$trans["pfsts"]),'1');			
				if($trans["fctc"]>18749){$trans["fpfg"] = 15000*$trans["pfsts"];}else{$trans["fpfg"] = $trans["fpfgt"];}
				$trans["fepf"] = $this->rounding_value(($this->dz($trans["fpfg"]*12)/100),'1');			
				$trans["foa"] = $trans["fctc"]-($trans["fb"]+$trans["fhra"]+$trans["flta"]+$trans["fxg"]+$trans["fphone"]+$trans["fmed"]+$trans["fepf"]);			
				$trans["oth_alw"] = $this->rounding_value(($this->dz($this->dz( $this->dz($trans["foa"]/$trans["md"])*$trans["pd"])-$this->dz( $this->dz($this->dz(1800/$trans["md"])*$trans["ld"])*$trans["pfsts"])+$this->dz( $this->dz($trans["foa"]/$trans["lcmd"])*$trans["lcd"]))),'1');			
				$trans["eg"] = $trans["eb"]+$trans["hra"]+$trans["conv"]+$trans["oth_alw"]+$trans["ecea"]+$trans["exg"]+$trans["elta"]+$trans["emed"]+ $trans["epp"]+$trans["epa"]+$trans["ephone"]+$trans["eattire"];			
				$trans["pfgtot"] = $trans["eg"];			
				if($trans["pfgtot"]>15000){$trans["pfg"] = 15000;}else{$trans["pfg"] = $trans["pfgtot"];}
				$trans["cpf"] = $this->rounding_value(($this->dz($this->dz($trans["pfg"]*12)/100)*$trans["pfsts"]),'1');			
				$trans["ctc"] = $trans["eg"]+$trans["cpf"];			
				$trans["fg"] = $trans["fb"]+$trans["fcea"]+$trans["fca"]+$trans["fhra"]+$trans["flta"]+$trans["fmed"]+$trans["foa"]+$trans["fpp"]+$trans["fpa"]+$trans["fphone"]+$trans["fattire"];			
				$trans["pfamount"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["pfgtot"]*$trans["pfsts"])*12)/100)),'1');			
				$trans["emlr_pf"] = $this->rounding_value(($trans["pfamount"]),'1');			
				$trans["fnp"] = $this->rounding_value(($trans["fg"]-$trans["pfamount"]),'1');			
				$trans["jan_inc"] = $this->rounding_value(($this->dz( $this->dz($this->dz($trans["att_per"]+$trans["prod_per"]+$trans["err_per"])*$trans["b_inc"])/100)-$this->dz($trans["incadjd"]+$trans["inc_adj"])),'1');			
				$trans["ot"] = $this->rounding_value(((($trans["ot_rate"]*$trans["ot_maxhrs"])+$trans["otadj"]+($trans["ot_rate"]*$trans["pmot"]))),'1');			
				$trans["pmota"] = $trans["pmot"]*$trans["ot_rate"];			
				$trans["sft_alw"] = $this->rounding_value(((($trans["sft_pd"]*$trans["sft_rate"])*$trans["sft_km"])+(($trans["sftadj"]*$trans["sft_rate"])*$trans["sft_km"])),'1');			
				$trans["sl_bal"] = $trans["sl_op"]-$trans["sl"];			
				$trans["tl"] = $trans["ld"]+$trans["cl"]+$trans["sl"];			
				$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);			
				$trans["er_pf"] = $trans["pfamount"];			
				$trans["npra"] = $this->dz($trans["fctc"]/30)*$trans["notice_period"];			
				$trans["esi"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["eg"]+$trans["food"]+$trans["m_sft_alw"]+$trans["ot"]+$trans["sft_alw"]+$trans["jan_inc"]+$trans["ag"]+$trans["inc_adj"]+$trans["arrearwithheld"]+$trans["loyalbon"])*$trans["esi_sts"])*0.75)/100),'>1');			
				$trans["mealcard"] = $trans["mealallo"];			
				$trans["esi_grs_cond"] = $this->dz($trans["fg"]/$trans["md"])*$trans["pd"];			
				if($trans["fg"]>21000){$trans["esi_grs"] = 0;}else{$trans["esi_grs"] = $trans["esi_grs_cond"];}
				$trans["empr_esi_cond"] = $this->dz($trans["fg"]*4.75)/100;			
				if($trans["fg"]>21000){$trans["empr_esi"] = 0;}else{$trans["empr_esi"] = $trans["empr_esi_cond"];}
				$trans["total_earnings"] = $this->rounding_value(($trans["adv"]+$trans["oth_alw"]+$trans["ot"]+$trans["pmota"]+$trans["salarycutrepaym"]+$trans["salaryheldff"]+$trans["tds_ret"]+$trans["gratuity"]+$trans["oj_inc"]+$trans["sft_alw"]+$trans["ag"]+$trans["arrearwithheld"]+$trans["eattire"]+$trans["eb"]+$trans["comcha"]+$trans["conv"]+$trans["creadj"]+$trans["mealallo"]+$trans["epa"]+$trans["epp"]+$trans["emed"]+$trans["elta"]+$trans["ecea"]+$trans["exg"]+$trans["m_sft_alw"]+$trans["ephone"]+$trans["food"]+$trans["hra"]+$trans["lapreim"]+$trans["lev_encashamt"]+$trans["loyalbon"]),'1');			
				$trans["total_deductions"] = $this->rounding_value(($trans["monthly_tds"]+$trans["salholdnotice"]+$trans["tds_inc"]+$trans["vpfamount"]+$trans["ptax"]+$trans["salarycut"]+$trans["sal_adv"]+$trans["sadv"]+$trans["rec"]+$trans["pfamount"]+$trans["npra"]+$trans["mealcard"]+$trans["esi"]+$trans["arrearhold"]+$trans["arr_paid"]+$trans["agreementrecove"]),'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\",'".$trans["ab"]."','".$trans["acea"]."','".$trans["aconv"]."','".$trans["actc"]."','".$trans["adv"]."','".$trans["aepf"]."','".$trans["afg"]."','".$trans["amed"]."','".$trans["apa"]."','".$trans["aphone"]."','".$trans["app"]."','".$trans["arrearwithheld"]."','".$trans["att_per"]."','".$trans["b_inc"]."','".$trans["bonus"]."','".$trans["cl"]."','".$trans["cl_op"]."','".$trans["comcha"]."','".$trans["creadj"]."','".$trans["e_days"]."','".$trans["err_per"]."','".$trans["estatt"]."','".$trans["estpro"]."','".$trans["fattire"]."','".$trans["fca"]."','".$trans["feb_inc"]."','".$trans["flb"]."','".$trans["fma"]."','".$trans["fmed"]."','".$trans["food_pd"]."','".$trans["fpa"]."','".$trans["fphone"]."','".$trans["fpp"]."','".$trans["inc_adj"]."','".$trans["lapreim"]."','".$trans["lcd"]."','".$trans["lcmd"]."','".$trans["ld"]."','".$trans["lectc"]."','".$trans["led"]."','".$trans["lev_encashday"]."','".$trans["m_sft_pd"]."','".$trans["marrs"]."','".$trans["maxpf_sts"]."','".$trans["njcd"]."','".$trans["njd"]."','".$trans["oj_inc"]."','".$trans["ot_hrs"]."','".$trans["otadj"]."','".$trans["pmfd"]."','".$trans["pmot"]."','".$trans["prod_per"]."','".$trans["prptg"]."','".$trans["pyinc"]."','".$trans["rapd"]."','".$trans["rbs"]."','".$trans["salarycutrepaym"]."','".$trans["salaryheldff"]."','".$trans["sctc"]."','".$trans["sft_km"]."','".$trans["sft_pd"]."','".$trans["sft_rate"]."','".$trans["sftadj"]."','".$trans["sl"]."','".$trans["sl_op"]."','".$trans["tds_ret"]."','".$trans["trainincent"]."','".$trans["weekoff_days"]."','".$trans["yinc"]."','".$trans["md"]."','".$trans["separation_day"]."','".$trans["agreementrecove"]."','".$trans["arr_paid"]."','".$trans["arrearhold"]."','".$trans["esi_sts"]."','".$trans["incadjd"]."','".$trans["nprd"]."','".$trans["pfsts"]."','".$trans["rec"]."','".$trans["sadv"]."','".$trans["sal_adv"]."','".$trans["salarycut"]."','".$trans["salholdnotice"]."','".$trans["monthly_tds"]."','".$trans["tds_inc"]."','".$trans["fb"]."','".$trans["fcea"]."','".$trans["notice_period"]."','".$trans["ahra"]."','".$trans["alta"]."','".$trans["axg"]."','".$trans["aoth_alw"]."','".$trans["ag"]."','".$trans["cl_bal"]."','".$trans["pd"]."','".$trans["conv"]."','".$trans["eattire"]."','".$trans["eb"]."','".$trans["ecea"]."','".$trans["flta"]."','".$trans["elta"]."','".$trans["emed"]."','".$trans["epa"]."','".$trans["ephone"]."','".$trans["epp"]."','".$trans["fxg"]."','".$trans["exg"]."','".$trans["fctc"]."','".$trans["fhra"]."','".$trans["fininc"]."','".$trans["food"]."','".$trans["hra"]."','".$trans["lev_encashrate"]."','".$trans["lev_encashamt"]."','".$trans["loyalbon"]."','".$trans["m_sft_alw"]."','".$trans["mealallo"]."','".$trans["ot_rate"]."','".$trans["eot"]."','".$trans["ot_maxhrs"]."','".$trans["fpfgt"]."','".$trans["fpfg"]."','".$trans["fepf"]."','".$trans["foa"]."','".$trans["oth_alw"]."','".$trans["eg"]."','".$trans["pfgtot"]."','".$trans["pfg"]."','".$trans["cpf"]."','".$trans["ctc"]."','".$trans["fg"]."','".$trans["pfamount"]."','".$trans["emlr_pf"]."','".$trans["fnp"]."','".$trans["jan_inc"]."','".$trans["ot"]."','".$trans["pmota"]."','".$trans["sft_alw"]."','".$trans["sl_bal"]."','".$trans["tl"]."','".$trans["ptax"]."','".$trans["er_pf"]."','".$trans["npra"]."','".$trans["esi"]."','".$trans["mealcard"]."','".$trans["esi_grs_cond"]."','".$trans["esi_grs"]."','".$trans["empr_esi_cond"]."','".$trans["empr_esi"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["esi_eligibility"]."','".$trans["pf_eligibility"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["desgrade"]."')";
			 
		 
	 $qry_2 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,ab,acea,aconv,actc,adv,aepf,afg,amed,apa,aphone,app,arrearwithheld,att_per,b_inc,bonus,cl,cl_op,comcha,creadj,e_days,err_per,estatt,estpro,fattire,fca,feb_inc,flb,fma,fmed,food_pd,fpa,fphone,fpp,inc_adj,lapreim,lcd,lcmd,ld,lectc,led,lev_encashday,m_sft_pd,marrs,maxpf_sts,njcd,njd,oj_inc,ot_hrs,otadj,pmfd,pmot,prod_per,prptg,pyinc,rapd,rbs,salarycutrepaym,salaryheldff,sctc,sft_km,sft_pd,sft_rate,sftadj,sl,sl_op,tds_ret,trainincent,weekoff_days,yinc,md,separation_day,agreementrecove,arr_paid,arrearhold,esi_sts,incadjd,nprd,pfsts,rec,sadv,sal_adv,salarycut,salholdnotice,monthly_tds,tds_inc,fb,fcea,notice_period,ahra,alta,axg,aoth_alw,ag,cl_bal,pd,conv,eattire,eb,ecea,flta,elta,emed,epa,ephone,epp,fxg,exg,fctc,fhra,fininc,food,hra,lev_encashrate,lev_encashamt,loyalbon,m_sft_alw,mealallo,ot_rate,eot,ot_maxhrs,fpfgt,fpfg,fepf,foa,oth_alw,eg,pfgtot,pfg,cpf,ctc,fg,pfamount,emlr_pf,fnp,jan_inc,ot,pmota,sft_alw,sl_bal,tl,ptax,er_pf,npra,esi,mealcard,esi_grs_cond,esi_grs,empr_esi_cond,empr_esi,role,employee_code,emp_name,department,designation,date_of_joining,esi_eligibility,pf_eligibility,lwf_location,process_month,resignation_date,termination_status,payroll,desgrade'.$trans_key_array.') VALUES '.implode(',',$payroll_array[2]); 
			}else
			if((int)$trans["role"] === 3){
				$trans["ab"] = $this->rounding_value(($trans["ab"]),'1');			
				$trans["acea"] = $trans["acea"];			
				$trans["aconv"] = $trans["aconv"];			
				$trans["actc"] = $trans["actc"];			
				$trans["adv"] = $this->rounding_value(($trans["adv"]),'1');			
				$trans["aepf"] = $trans["aepf"];			
				$trans["afg"] = $trans["afg"];			
				$trans["amed"] = $trans["amed"];			
				$trans["apa"] = $trans["apa"];			
				$trans["aphone"] = $trans["aphone"];			
				$trans["app"] = $trans["app"];			
				$trans["arrearwithheld"] = $trans["arrearwithheld"];			
				$trans["att_per"] = $trans["att_per"];			
				$trans["b_inc"] = $trans["b_inc"];			
				$trans["bonus"] = $trans["bonus"];			
				$trans["cl"] = $trans["cl"];			
				$trans["cl_op"] = $trans["cl_op"];			
				$trans["comcha"] = $trans["comcha"];			
				$trans["creadj"] = $trans["creadj"];			
				$trans["e_days"] = $trans["e_days"];			
				$trans["err_per"] = $trans["err_per"];			
				$trans["estatt"] = $trans["estatt"];			
				$trans["estpro"] = $trans["estpro"];			
				$trans["fattire"] = $trans["fattire"];			
				$trans["fb"] = $this->rounding_value(($trans["fb"]),'1');			
				$trans["fca"] = $trans["fca"];			
				$trans["fcea"] = $trans["fcea"];			
				$trans["feb_inc"] = $trans["feb_inc"];			
				$trans["flb"] = $trans["flb"];			
				$trans["fma"] = $trans["fma"];			
				$trans["fmed"] = $trans["fmed"];			
				$trans["food_pd"] = $trans["food_pd"];			
				$trans["fpa"] = $trans["fpa"];			
				$trans["fphone"] = $trans["fphone"];			
				$trans["fpp"] = $trans["fpp"];			
				$trans["inc_adj"] = $trans["inc_adj"];			
				$trans["lapreim"] = $trans["lapreim"];			
				$trans["lcd"] = $trans["lcd"];			
				$trans["lcmd"] = $trans["lcmd"];			
				$trans["ld"] = $trans["ld"];			
				$trans["lectc"] = $trans["lectc"];			
				$trans["led"] = $trans["led"];			
				$trans["lev_encashday"] = $trans["lev_encashday"];			
				$trans["m_sft_pd"] = $trans["m_sft_pd"];			
				$trans["marrs"] = $trans["marrs"];			
				$trans["maxpf_sts"] = $trans["maxpf_sts"];			
				$trans["njcd"] = $trans["njcd"];			
				$trans["njd"] = $trans["njd"];			
				$trans["notice_period"] = $trans["notice_period"];			
				$trans["oj_inc"] = $trans["oj_inc"];			
				$trans["ot_hrs"] = $trans["ot_hrs"];			
				$trans["otadj"] = $trans["otadj"];			
				$trans["pmfd"] = $trans["pmfd"];			
				$trans["pmot"] = $trans["pmot"];			
				$trans["prod_per"] = $trans["prod_per"];			
				$trans["prptg"] = $trans["prptg"];			
				$trans["pyinc"] = $trans["pyinc"];			
				$trans["rapd"] = $trans["rapd"];			
				$trans["rbs"] = $trans["rbs"];			
				$trans["salarycutrepaym"] = $trans["salarycutrepaym"];			
				$trans["salaryheldff"] = $trans["salaryheldff"];			
				$trans["sctc"] = $trans["sctc"];			
				$trans["sft_km"] = $trans["sft_km"];			
				$trans["sft_pd"] = $trans["sft_pd"];			
				$trans["sft_rate"] = $trans["sft_rate"];			
				$trans["sftadj"] = $trans["sftadj"];			
				$trans["sl"] = $trans["sl"];			
				$trans["sl_op"] = $trans["sl_op"];			
				$trans["tds_ret"] = $trans["tds_ret"];			
				$trans["trainincent"] = $trans["trainincent"];			
				$trans["weekoff_days"] = $trans["weekoff_days"];			
				$trans["yinc"] = $trans["yinc"];			
				$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["agreementrecove"] = $trans["agreementrecove"];			
				$trans["arr_paid"] = $trans["arr_paid"];			
				$trans["arrearhold"] = $trans["arrearhold"];			
				$trans["esi_sts"] = $trans["esi_sts"];			
				$trans["incadjd"] = $trans["incadjd"];			
				$trans["nprd"] = $trans["nprd"];			
				$trans["pfsts"] = $trans["pfsts"];			
				$trans["rec"] = $trans["rec"];			
				$trans["sadv"] = $trans["sadv"];			
				$trans["sal_adv"] = $trans["sal_adv"];			
				$trans["salarycut"] = $trans["salarycut"];			
				$trans["salholdnotice"] = $trans["salholdnotice"];			
				$trans["monthly_tds"] = $trans["monthly_tds"];			
				$trans["tds_inc"] = $trans["tds_inc"];			
				$trans["ahra"] = $this->rounding_value(($this->dz($trans["ab"]*50)/100),'1');			
				$trans["alta"] = $this->rounding_value(($this->dz($trans["ab"]*8.33)/100),'1');			
				$trans["axg"] = $this->rounding_value(($this->dz($trans["ab"]*8.33)/100),'1');			
				$trans["aoth_alw"] = $trans["actc"]-($trans["ab"]+$trans["ahra"]+$trans["alta"]+$trans["aphone"]+$trans["axg"]);			
				$trans["ag"] = $trans["ab"]+$trans["ahra"]+$trans["aconv"]+$trans["aoth_alw"]+$trans["acea"]+$trans["axg"]+$trans["alta"]+$trans["amed"]+$trans["aphone"]+$trans["marrs"];			
				$trans["cl_bal"] = $trans["cl_op"]-$trans["cl"];			
				$trans["pd"] = $trans["md"]-$trans["ld"]-$trans["separation_day"]+$trans["njd"]+$trans["rapd"]-$trans["njcd"]+$trans["e_days"];			
				$trans["conv"] = $this->rounding_value(($this->dz( $this->dz($trans["fca"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fca"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["eattire"] = $this->rounding_value(($this->dz( $this->dz($trans["fattire"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fattire"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["eb"] = $this->rounding_value(($this->dz( $this->dz($trans["fb"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fb"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["ecea"] = $this->rounding_value(($this->dz( $this->dz($trans["fcea"]/$trans["md"])*$trans["pd"])+$this->dz( $this->dz($trans["fcea"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["flta"] = $this->rounding_value(($this->dz($trans["fb"]*8.33)/100),'1');			
				$trans["elta"] = $this->rounding_value(($this->dz($this->dz($trans["flta"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["flta"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["emed"] = $this->rounding_value(($this->dz($this->dz($trans["fmed"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fmed"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["epa"] = $this->rounding_value(($this->dz($this->dz($trans["fpa"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fpa"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["ephone"] = $this->rounding_value(($this->dz($this->dz($trans["fphone"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fphone"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["epp"] = $this->rounding_value(($this->dz($this->dz($trans["fpp"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fpp"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["fxg"] = $this->rounding_value(($this->dz($trans["fb"]*8.33)/100),'1');			
				$trans["exg"] = $this->rounding_value(($this->dz($this->dz($trans["fxg"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fxg"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["fctc"] = $trans["sctc"];			
				$trans["fhra"] = $this->rounding_value(($this->dz($trans["fb"]*50)/100),'1');			
				$trans["fininc"] = $trans["att_per"]+$trans["err_per"]+$trans["prod_per"];			
				$trans["food"] = (($trans["food_pd"]*80)+($trans["pmfd"]*80));			
				$trans["hra"] = $this->rounding_value(($this->dz($this->dz($trans["fhra"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fhra"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["lev_encashrate"] = $trans["lectc"]/30;			
				$trans["lev_encashamt"] = $trans["led"]*$trans["lev_encashrate"];			
				$trans["loyalbon"] = $this->dz($trans["flb"]/$trans["md"])*$trans["pd"];			
				$trans["m_sft_alw"] = $trans["m_sft_pd"]*50;			
				$trans["mealallo"] = $this->rounding_value(($this->dz($trans["fma"]/$trans["md"])*$trans["pd"]),'1');			
				$trans["ot_rate"] = $this->dz($this->dz($this->dz($trans["fctc"]/30)/8)/60);			
				if($trans["ld"]==$trans["md"]){$trans["eot"] = $trans["pfsts"]*0;}else{$trans["eot"] = $trans["pfsts"];}
				if($trans["ot_hrs"]>960){$trans["ot_maxhrs"] = 960;}else{$trans["ot_maxhrs"] = $trans["ot_hrs"];}
				$trans["fpfgt"] = $this->rounding_value(($trans["fctc"]*$trans["pfsts"]),'1');			
				if($trans["fctc"]>18749){$trans["fpfg"] = 15000*$trans["pfsts"];}else{$trans["fpfg"] = $trans["fpfgt"];}
				$trans["fepf"] = $this->rounding_value(($this->dz($trans["fpfg"]*12)/100),'1');			
				$trans["foa"] = $trans["fctc"]-($trans["fb"]+$trans["fhra"]+$trans["flta"]+$trans["fxg"]+$trans["fphone"]+$trans["fmed"]+$trans["fepf"]);			
				$trans["oth_alw"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["foa"]/$trans["md"])*$trans["pd"])-$this->dz($this->dz($this->dz(1800/$trans["md"])*$trans["ld"])*$trans["pfsts"])+$this->dz($this->dz($trans["foa"]/$trans["lcmd"])*$trans["lcd"]))),'1');			
				$trans["eg"] = $trans["eb"]+$trans["hra"]+$trans["conv"]+$trans["oth_alw"]+$trans["ecea"]+$trans["exg"]+$trans["elta"]+$trans["emed"]+ $trans["epp"]+$trans["epa"]+$trans["ephone"]+$trans["eattire"];			
				$trans["pfgtot"] = $trans["eg"];			
				if($trans["pfgtot"]>15000){$trans["pfg"] = 15000;}else{$trans["pfg"] = $trans["pfgtot"];}
				$trans["cpf"] = $this->rounding_value(($this->dz($this->dz($trans["pfg"]*12)/100)*$trans["pfsts"]),'1');			
				$trans["ctc"] = $trans["eg"]+$trans["cpf"];			
				$trans["fg"] = $trans["fb"]+$trans["fcea"]+$trans["fca"]+$trans["fhra"]+$trans["flta"]+$trans["fmed"]+$trans["foa"]+$trans["fpp"]+$trans["fpa"]+$trans["fphone"]+$trans["fattire"];			
				$trans["pfamount"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["pfgtot"]*$trans["pfsts"])*12)/100)),'1');			
				$trans["emlr_pf"] = $this->rounding_value(($trans["pfamount"]),'1');			
				$trans["fnp"] = $this->rounding_value(($trans["fg"]-$trans["pfamount"]),'1');			
				$trans["jan_inc"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["att_per"]+$trans["prod_per"]+$trans["err_per"])*$trans["b_inc"])/100)-$this->dz($trans["incadjd"]+$trans["inc_adj"])),'1');			
				$trans["ot"] = $this->rounding_value(((($trans["ot_rate"]*$trans["ot_maxhrs"])+$trans["otadj"]+($trans["ot_rate"]*$trans["pmot"]))),'1');			
				$trans["pmota"] = $trans["pmot"]*$trans["ot_rate"];			
				$trans["sft_alw"] = $this->rounding_value(((($trans["sft_pd"]*$trans["sft_rate"])*$trans["sft_km"])+(($trans["sftadj"]*$trans["sft_rate"])*$trans["sft_km"])),'1');			
				$trans["sl_bal"] = $trans["sl_op"]-$trans["sl"];			
				$trans["tl"] = $trans["ld"]+$trans["cl"]+$trans["sl"];			
				$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);			
				$trans["er_pf"] = $trans["pfamount"];			
				$trans["npra"] = $this->dz($trans["fctc"]/30)*$trans["notice_period"];			
				$trans["esi"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["eg"]+$trans["food"]+$trans["m_sft_alw"]+$trans["ot"]+$trans["sft_alw"]+$trans["jan_inc"]+$trans["ag"]+$trans["inc_adj"]+$trans["arrearwithheld"]+$trans["loyalbon"])*$trans["esi_sts"])*0.75)/100),'>1');			
				$trans["mealcard"] = $trans["mealallo"];			
				$trans["esi_grs_cond"] = $this->dz($trans["fg"]/$trans["md"])*$trans["pd"];			
				if($trans["fg"]>21000){$trans["esi_grs"] = 0;}else{$trans["esi_grs"] = $trans["esi_grs_cond"];}
				$trans["empr_esi_cond"] = $this->dz($trans["fg"]*4.75)/100;			
				if($trans["fg"]>21000){$trans["empr_esi"] = 0;}else{$trans["empr_esi"] = $trans["empr_esi_cond"];}
				$trans["total_earnings"] = $this->rounding_value(($trans["adv"]+$trans["oth_alw"]+$trans["ot"]+$trans["pmota"]+$trans["salarycutrepaym"]+$trans["salaryheldff"]+$trans["tds_ret"]+$trans["gratuity"]+$trans["oj_inc"]+$trans["sft_alw"]+$trans["ag"]+$trans["arrearwithheld"]+$trans["eattire"]+$trans["eb"]+$trans["comcha"]+$trans["conv"]+$trans["creadj"]+$trans["mealallo"]+$trans["epa"]+$trans["epp"]+$trans["emed"]+$trans["elta"]+$trans["ecea"]+$trans["exg"]+$trans["m_sft_alw"]+$trans["ephone"]+$trans["food"]+$trans["hra"]+$trans["lapreim"]+$trans["lev_encashamt"]+$trans["loyalbon"]),'1');			
				$trans["total_deductions"] = $this->rounding_value(($trans["monthly_tds"]+$trans["salholdnotice"]+$trans["tds_inc"]+$trans["vpfamount"]+$trans["ptax"]+$trans["salarycut"]+$trans["sal_adv"]+$trans["sadv"]+$trans["rec"]+$trans["pfamount"]+$trans["npra"]+$trans["mealcard"]+$trans["esi"]+$trans["arrearhold"]+$trans["arr_paid"]+$trans["agreementrecove"]),'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\",'".$trans["ab"]."','".$trans["acea"]."','".$trans["aconv"]."','".$trans["actc"]."','".$trans["adv"]."','".$trans["aepf"]."','".$trans["afg"]."','".$trans["amed"]."','".$trans["apa"]."','".$trans["aphone"]."','".$trans["app"]."','".$trans["arrearwithheld"]."','".$trans["att_per"]."','".$trans["b_inc"]."','".$trans["bonus"]."','".$trans["cl"]."','".$trans["cl_op"]."','".$trans["comcha"]."','".$trans["creadj"]."','".$trans["e_days"]."','".$trans["err_per"]."','".$trans["estatt"]."','".$trans["estpro"]."','".$trans["fattire"]."','".$trans["fb"]."','".$trans["fca"]."','".$trans["fcea"]."','".$trans["feb_inc"]."','".$trans["flb"]."','".$trans["fma"]."','".$trans["fmed"]."','".$trans["food_pd"]."','".$trans["fpa"]."','".$trans["fphone"]."','".$trans["fpp"]."','".$trans["inc_adj"]."','".$trans["lapreim"]."','".$trans["lcd"]."','".$trans["lcmd"]."','".$trans["ld"]."','".$trans["lectc"]."','".$trans["led"]."','".$trans["lev_encashday"]."','".$trans["m_sft_pd"]."','".$trans["marrs"]."','".$trans["maxpf_sts"]."','".$trans["njcd"]."','".$trans["njd"]."','".$trans["notice_period"]."','".$trans["oj_inc"]."','".$trans["ot_hrs"]."','".$trans["otadj"]."','".$trans["pmfd"]."','".$trans["pmot"]."','".$trans["prod_per"]."','".$trans["prptg"]."','".$trans["pyinc"]."','".$trans["rapd"]."','".$trans["rbs"]."','".$trans["salarycutrepaym"]."','".$trans["salaryheldff"]."','".$trans["sctc"]."','".$trans["sft_km"]."','".$trans["sft_pd"]."','".$trans["sft_rate"]."','".$trans["sftadj"]."','".$trans["sl"]."','".$trans["sl_op"]."','".$trans["tds_ret"]."','".$trans["trainincent"]."','".$trans["weekoff_days"]."','".$trans["yinc"]."','".$trans["md"]."','".$trans["separation_day"]."','".$trans["agreementrecove"]."','".$trans["arr_paid"]."','".$trans["arrearhold"]."','".$trans["esi_sts"]."','".$trans["incadjd"]."','".$trans["nprd"]."','".$trans["pfsts"]."','".$trans["rec"]."','".$trans["sadv"]."','".$trans["sal_adv"]."','".$trans["salarycut"]."','".$trans["salholdnotice"]."','".$trans["monthly_tds"]."','".$trans["tds_inc"]."','".$trans["ahra"]."','".$trans["alta"]."','".$trans["axg"]."','".$trans["aoth_alw"]."','".$trans["ag"]."','".$trans["cl_bal"]."','".$trans["pd"]."','".$trans["conv"]."','".$trans["eattire"]."','".$trans["eb"]."','".$trans["ecea"]."','".$trans["flta"]."','".$trans["elta"]."','".$trans["emed"]."','".$trans["epa"]."','".$trans["ephone"]."','".$trans["epp"]."','".$trans["fxg"]."','".$trans["exg"]."','".$trans["fctc"]."','".$trans["fhra"]."','".$trans["fininc"]."','".$trans["food"]."','".$trans["hra"]."','".$trans["lev_encashrate"]."','".$trans["lev_encashamt"]."','".$trans["loyalbon"]."','".$trans["m_sft_alw"]."','".$trans["mealallo"]."','".$trans["ot_rate"]."','".$trans["eot"]."','".$trans["ot_maxhrs"]."','".$trans["fpfgt"]."','".$trans["fpfg"]."','".$trans["fepf"]."','".$trans["foa"]."','".$trans["oth_alw"]."','".$trans["eg"]."','".$trans["pfgtot"]."','".$trans["pfg"]."','".$trans["cpf"]."','".$trans["ctc"]."','".$trans["fg"]."','".$trans["pfamount"]."','".$trans["emlr_pf"]."','".$trans["fnp"]."','".$trans["jan_inc"]."','".$trans["ot"]."','".$trans["pmota"]."','".$trans["sft_alw"]."','".$trans["sl_bal"]."','".$trans["tl"]."','".$trans["ptax"]."','".$trans["er_pf"]."','".$trans["npra"]."','".$trans["esi"]."','".$trans["mealcard"]."','".$trans["esi_grs_cond"]."','".$trans["esi_grs"]."','".$trans["empr_esi_cond"]."','".$trans["empr_esi"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["esi_eligibility"]."','".$trans["pf_eligibility"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["desgrade"]."')";
			 
		 
	 $qry_3 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,ab,acea,aconv,actc,adv,aepf,afg,amed,apa,aphone,app,arrearwithheld,att_per,b_inc,bonus,cl,cl_op,comcha,creadj,e_days,err_per,estatt,estpro,fattire,fb,fca,fcea,feb_inc,flb,fma,fmed,food_pd,fpa,fphone,fpp,inc_adj,lapreim,lcd,lcmd,ld,lectc,led,lev_encashday,m_sft_pd,marrs,maxpf_sts,njcd,njd,notice_period,oj_inc,ot_hrs,otadj,pmfd,pmot,prod_per,prptg,pyinc,rapd,rbs,salarycutrepaym,salaryheldff,sctc,sft_km,sft_pd,sft_rate,sftadj,sl,sl_op,tds_ret,trainincent,weekoff_days,yinc,md,separation_day,agreementrecove,arr_paid,arrearhold,esi_sts,incadjd,nprd,pfsts,rec,sadv,sal_adv,salarycut,salholdnotice,monthly_tds,tds_inc,ahra,alta,axg,aoth_alw,ag,cl_bal,pd,conv,eattire,eb,ecea,flta,elta,emed,epa,ephone,epp,fxg,exg,fctc,fhra,fininc,food,hra,lev_encashrate,lev_encashamt,loyalbon,m_sft_alw,mealallo,ot_rate,eot,ot_maxhrs,fpfgt,fpfg,fepf,foa,oth_alw,eg,pfgtot,pfg,cpf,ctc,fg,pfamount,emlr_pf,fnp,jan_inc,ot,pmota,sft_alw,sl_bal,tl,ptax,er_pf,npra,esi,mealcard,esi_grs_cond,esi_grs,empr_esi_cond,empr_esi,role,employee_code,emp_name,department,designation,date_of_joining,esi_eligibility,pf_eligibility,lwf_location,process_month,resignation_date,termination_status,payroll,desgrade'.$trans_key_array.') VALUES '.implode(',',$payroll_array[3]); 
			}else
			if((int)$trans["role"] === 4){
				$trans["ab"] = $this->rounding_value(($trans["ab"]),'1');			
				$trans["acea"] = $trans["acea"];			
				$trans["aconv"] = $trans["aconv"];			
				$trans["actc"] = $trans["actc"];			
				$trans["adv"] = $this->rounding_value(($trans["adv"]),'1');			
				$trans["aepf"] = $trans["aepf"];			
				$trans["afg"] = $trans["afg"];			
				$trans["amed"] = $trans["amed"];			
				$trans["apa"] = $trans["apa"];			
				$trans["aphone"] = $trans["aphone"];			
				$trans["app"] = $trans["app"];			
				$trans["arrearwithheld"] = $trans["arrearwithheld"];			
				$trans["att_per"] = $trans["att_per"];			
				$trans["b_inc"] = $trans["b_inc"];			
				$trans["bonus"] = $trans["bonus"];			
				$trans["cl"] = $trans["cl"];			
				$trans["cl_op"] = $trans["cl_op"];			
				$trans["comcha"] = $trans["comcha"];			
				$trans["creadj"] = $trans["creadj"];			
				$trans["e_days"] = $trans["e_days"];			
				$trans["err_per"] = $trans["err_per"];			
				$trans["estatt"] = $trans["estatt"];			
				$trans["estpro"] = $trans["estpro"];			
				$trans["fattire"] = $trans["fattire"];			
				$trans["fb"] = $this->rounding_value(($trans["fb"]),'1');			
				$trans["fca"] = $trans["fca"];			
				$trans["fcea"] = $trans["fcea"];			
				$trans["feb_inc"] = $trans["feb_inc"];			
				$trans["flb"] = $trans["flb"];			
				$trans["fma"] = $trans["fma"];			
				$trans["fmed"] = $trans["fmed"];			
				$trans["food_pd"] = $trans["food_pd"];			
				$trans["fpa"] = $trans["fpa"];			
				$trans["fphone"] = $trans["fphone"];			
				$trans["fpp"] = $trans["fpp"];			
				$trans["inc_adj"] = $trans["inc_adj"];			
				$trans["lapreim"] = $trans["lapreim"];			
				$trans["lcd"] = $trans["lcd"];			
				$trans["lcmd"] = $trans["lcmd"];			
				$trans["ld"] = $trans["ld"];			
				$trans["lectc"] = $trans["lectc"];			
				$trans["led"] = $trans["led"];			
				$trans["lev_encashday"] = $trans["lev_encashday"];			
				$trans["m_sft_pd"] = $trans["m_sft_pd"];			
				$trans["marrs"] = $trans["marrs"];			
				$trans["maxpf_sts"] = $trans["maxpf_sts"];			
				$trans["njcd"] = $trans["njcd"];			
				$trans["njd"] = $trans["njd"];			
				$trans["notice_period"] = $trans["notice_period"];			
				$trans["oj_inc"] = $trans["oj_inc"];			
				$trans["ot_hrs"] = $trans["ot_hrs"];			
				$trans["otadj"] = $trans["otadj"];			
				$trans["pmfd"] = $trans["pmfd"];			
				$trans["pmot"] = $trans["pmot"];			
				$trans["prod_per"] = $trans["prod_per"];			
				$trans["prptg"] = $trans["prptg"];			
				$trans["pyinc"] = $trans["pyinc"];			
				$trans["rapd"] = $trans["rapd"];			
				$trans["rbs"] = $trans["rbs"];			
				$trans["salarycutrepaym"] = $trans["salarycutrepaym"];			
				$trans["salaryheldff"] = $trans["salaryheldff"];			
				$trans["sctc"] = $trans["sctc"];			
				$trans["sft_km"] = $trans["sft_km"];			
				$trans["sft_pd"] = $trans["sft_pd"];			
				$trans["sft_rate"] = $trans["sft_rate"];			
				$trans["sftadj"] = $trans["sftadj"];			
				$trans["sl"] = $trans["sl"];			
				$trans["sl_op"] = $trans["sl_op"];			
				$trans["tds_ret"] = $trans["tds_ret"];			
				$trans["trainincent"] = $trans["trainincent"];			
				$trans["weekoff_days"] = $trans["weekoff_days"];			
				$trans["yinc"] = $trans["yinc"];			
				$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["agreementrecove"] = $trans["agreementrecove"];			
				$trans["arr_paid"] = $trans["arr_paid"];			
				$trans["arrearhold"] = $trans["arrearhold"];			
				$trans["esi_sts"] = $trans["esi_sts"];			
				$trans["incadjd"] = $trans["incadjd"];			
				$trans["nprd"] = $trans["nprd"];			
				$trans["pfsts"] = $trans["pfsts"];			
				$trans["rec"] = $trans["rec"];			
				$trans["sadv"] = $trans["sadv"];			
				$trans["sal_adv"] = $trans["sal_adv"];			
				$trans["salarycut"] = $trans["salarycut"];			
				$trans["salholdnotice"] = $trans["salholdnotice"];			
				$trans["monthly_tds"] = $trans["monthly_tds"];			
				$trans["tds_inc"] = $trans["tds_inc"];			
				$trans["ahra"] = $this->rounding_value(($this->dz($trans["ab"]*50)/100),'1');			
				$trans["alta"] = $this->rounding_value(($this->dz($trans["ab"]*8.33)/100),'1');			
				$trans["axg"] = $this->rounding_value(($this->dz($trans["ab"]*8.33)/100),'1');			
				$trans["aoth_alw"] = $trans["actc"]-($trans["ab"]+$trans["ahra"]+$trans["alta"]+$trans["aphone"]+$trans["axg"]);			
				$trans["ag"] = $trans["ab"]+$trans["ahra"]+$trans["aconv"]+$trans["aoth_alw"]+$trans["acea"]+$trans["axg"]+$trans["alta"]+$trans["amed"]+$trans["aphone"]+$trans["marrs"];			
				$trans["cl_bal"] = $trans["cl_op"]-$trans["cl"];			
				$trans["pd"] = $trans["md"]-$trans["ld"]-$trans["separation_day"]+$trans["njd"]+$trans["rapd"]-$trans["njcd"]+$trans["e_days"];			
				$trans["conv"] = $this->rounding_value(($this->dz($this->dz($trans["fca"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fca"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["eattire"] = $this->rounding_value(($this->dz($this->dz($trans["fattire"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fattire"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["eb"] = $this->rounding_value(($this->dz($this->dz($trans["fb"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fb"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["ecea"] = $this->rounding_value(($this->dz($this->dz($trans["fcea"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fcea"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["flta"] = $this->rounding_value(($this->dz($trans["fb"]*8.33)/100),'1');			
				$trans["elta"] = $this->rounding_value(($this->dz($this->dz($trans["flta"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["flta"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["emed"] = $this->rounding_value(($this->dz($this->dz($trans["fmed"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fmed"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["epa"] = $this->rounding_value(($this->dz($this->dz($trans["fpa"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fpa"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["ephone"] = $this->rounding_value(($this->dz($this->dz($trans["fphone"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fphone"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["epp"] = $this->rounding_value(($this->dz($this->dz($trans["fpp"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fpp"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["fxg"] = $this->rounding_value(($this->dz($trans["fb"]*8.33)/100),'1');			
				$trans["exg"] = $this->rounding_value(($this->dz($this->dz($trans["fxg"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fxg"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["fctc"] = $trans["sctc"];			
				$trans["fhra"] = $this->rounding_value(($this->dz($trans["fb"]*50)/100),'1');			
				$trans["fininc"] = $trans["att_per"]+$trans["err_per"]+$trans["prod_per"];			
				$trans["food"] = (($trans["food_pd"]*80)+($trans["pmfd"]*80));			
				$trans["hra"] = $this->rounding_value(($this->dz($this->dz($trans["fhra"]/$trans["md"])*$trans["pd"])+$this->dz($this->dz($trans["fhra"]/$trans["lcmd"])*$trans["lcd"])),'1');			
				$trans["lev_encashrate"] = $trans["lectc"]/30;			
				$trans["lev_encashamt"] = $trans["led"]*$trans["lev_encashrate"];			
				$trans["loyalbon"] = $this->dz($trans["flb"]/$trans["md"])*$trans["pd"];			
				$trans["m_sft_alw"] = $trans["m_sft_pd"]*50;			
				$trans["mealallo"] = $this->rounding_value(($this->dz($trans["fma"]/$trans["md"])*$trans["pd"]),'1');			
				$trans["ot_rate"] = $this->dz($this->dz($this->dz($trans["fctc"]/30)/8)/60);			
				if($trans["ld"]==$trans["md"]){$trans["eot"] = $trans["pfsts"]*0;}else{$trans["eot"] = $trans["pfsts"];}
				if($trans["ot_hrs"]>960){$trans["ot_maxhrs"] = 960;}else{$trans["ot_maxhrs"] = $trans["ot_hrs"];}
				$trans["fpfgt"] = $this->rounding_value(($trans["fctc"]*$trans["pfsts"]),'1');			
				if($trans["fctc"]>18749){$trans["fpfg"] = 15000*$trans["pfsts"];}else{$trans["fpfg"] = $trans["fpfgt"];}
				$trans["fepf"] = $this->rounding_value(($this->dz($trans["fpfg"]*12)/100),'1');			
				$trans["foa"] = $trans["fctc"]-($trans["fb"]+$trans["fhra"]+$trans["flta"]+$trans["fxg"]+$trans["fphone"]+$trans["fmed"]+$trans["fepf"]);			
				$trans["oth_alw"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["foa"]/$trans["md"])*$trans["pd"])-$this->dz($this->dz($this->dz(1800/$trans["md"])*$trans["ld"])*$trans["pfsts"])+$this->dz($this->dz($trans["foa"]/$trans["lcmd"])*$trans["lcd"]))),'1');			
				$trans["eg"] = $trans["eb"]+$trans["hra"]+$trans["conv"]+$trans["oth_alw"]+$trans["ecea"]+$trans["exg"]+$trans["elta"]+$trans["emed"]+ $trans["epp"]+$trans["epa"]+$trans["ephone"]+$trans["eattire"];			
				$trans["pfgtot"] = $trans["eg"];			
				if($trans["pfgtot"]>15000){$trans["pfg"] = 15000;}else{$trans["pfg"] = $trans["pfgtot"];}
				$trans["cpf"] = $this->rounding_value(($this->dz($this->dz($trans["pfg"]*12)/100)*$trans["pfsts"]),'1');			
				$trans["ctc"] = $trans["eg"]+$trans["cpf"];			
				$trans["fg"] = $trans["fb"]+$trans["fcea"]+$trans["fca"]+$trans["fhra"]+$trans["flta"]+$trans["fmed"]+$trans["foa"]+$trans["fpp"]+$trans["fpa"]+$trans["fphone"]+$trans["fattire"];			
				$trans["pfamount"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["pfgtot"]*$trans["pfsts"])*12)/100)),'1');			
				$trans["emlr_pf"] = $this->rounding_value(($trans["pfamount"]),'1');			
				$trans["fnp"] = $this->rounding_value(($trans["fg"]-$trans["pfamount"]),'1');			
				$trans["jan_inc"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["att_per"]+$trans["prod_per"]+$trans["err_per"])*$trans["b_inc"])/100)-$this->dz($trans["incadjd"]+$trans["inc_adj"])),'1');			
				$trans["ot"] = $this->rounding_value(((($trans["ot_rate"]*$trans["ot_maxhrs"])+$trans["otadj"]+($trans["ot_rate"]*$trans["pmot"]))),'1');			
				$trans["pmota"] = $trans["pmot"]*$trans["ot_rate"];			
				$trans["sft_alw"] = $this->rounding_value(((($trans["sft_pd"]*$trans["sft_rate"])*$trans["sft_km"])+(($trans["sftadj"]*$trans["sft_rate"])*$trans["sft_km"])),'1');			
				$trans["sl_bal"] = $trans["sl_op"]-$trans["sl"];			
				$trans["tl"] = $trans["ld"]+$trans["cl"]+$trans["sl"];			
				$trans["ptax"] = $this->get_professional_tax_value($trans["employee_code"],$trans["professional_tax_location"],$trans["fpt_gross"],$trans["ept_gross"],$trans["transactions_month"]);			
				$trans["er_pf"] = $trans["pfamount"];			
				$trans["npra"] = $this->dz($trans["fctc"]/30)*$trans["notice_period"];			
				$trans["esi"] = $this->rounding_value(($this->dz($this->dz($this->dz($trans["eg"]+$trans["food"]+$trans["m_sft_alw"]+$trans["ot"]+$trans["sft_alw"]+$trans["jan_inc"]+$trans["ag"]+$trans["inc_adj"]+$trans["arrearwithheld"]+$trans["loyalbon"])*$trans["esi_sts"])*0.75)/100),'>1');			
				$trans["mealcard"] = $trans["mealallo"];			
				$trans["esi_grs_cond"] = $this->dz($trans["fg"]/$trans["md"])*$trans["pd"];			
				if($trans["fg"]>21000){$trans["esi_grs"] = 0;}else{$trans["esi_grs"] = $trans["esi_grs_cond"];}
				$trans["empr_esi_cond"] = $this->dz($trans["fg"]*4.75)/100;			
				if($trans["fg"]>21000){$trans["empr_esi"] = 0;}else{$trans["empr_esi"] = $trans["empr_esi_cond"];}
				$trans["total_earnings"] = $this->rounding_value(($trans["adv"]+$trans["oth_alw"]+$trans["ot"]+$trans["pmota"]+$trans["salarycutrepaym"]+$trans["salaryheldff"]+$trans["tds_ret"]+$trans["gratuity"]+$trans["oj_inc"]+$trans["sft_alw"]+$trans["ag"]+$trans["arrearwithheld"]+$trans["eattire"]+$trans["eb"]+$trans["comcha"]+$trans["conv"]+$trans["creadj"]+$trans["mealallo"]+$trans["epa"]+$trans["epp"]+$trans["emed"]+$trans["elta"]+$trans["ecea"]+$trans["exg"]+$trans["m_sft_alw"]+$trans["ephone"]+$trans["food"]+$trans["hra"]+$trans["lapreim"]+$trans["lev_encashamt"]+$trans["loyalbon"]),'1');			
				$trans["total_deductions"] = $this->rounding_value(($trans["monthly_tds"]+$trans["salholdnotice"]+$trans["tds_inc"]+$trans["vpfamount"]+$trans["ptax"]+$trans["salarycut"]+$trans["sal_adv"]+$trans["sadv"]+$trans["rec"]+$trans["pfamount"]+$trans["npra"]+$trans["mealcard"]+$trans["esi"]+$trans["arrearhold"]+$trans["arr_paid"]+$trans["agreementrecove"]),'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\",'".$trans["ab"]."','".$trans["acea"]."','".$trans["aconv"]."','".$trans["actc"]."','".$trans["adv"]."','".$trans["aepf"]."','".$trans["afg"]."','".$trans["amed"]."','".$trans["apa"]."','".$trans["aphone"]."','".$trans["app"]."','".$trans["arrearwithheld"]."','".$trans["att_per"]."','".$trans["b_inc"]."','".$trans["bonus"]."','".$trans["cl"]."','".$trans["cl_op"]."','".$trans["comcha"]."','".$trans["creadj"]."','".$trans["e_days"]."','".$trans["err_per"]."','".$trans["estatt"]."','".$trans["estpro"]."','".$trans["fattire"]."','".$trans["fb"]."','".$trans["fca"]."','".$trans["fcea"]."','".$trans["feb_inc"]."','".$trans["flb"]."','".$trans["fma"]."','".$trans["fmed"]."','".$trans["food_pd"]."','".$trans["fpa"]."','".$trans["fphone"]."','".$trans["fpp"]."','".$trans["inc_adj"]."','".$trans["lapreim"]."','".$trans["lcd"]."','".$trans["lcmd"]."','".$trans["ld"]."','".$trans["lectc"]."','".$trans["led"]."','".$trans["lev_encashday"]."','".$trans["m_sft_pd"]."','".$trans["marrs"]."','".$trans["maxpf_sts"]."','".$trans["njcd"]."','".$trans["njd"]."','".$trans["notice_period"]."','".$trans["oj_inc"]."','".$trans["ot_hrs"]."','".$trans["otadj"]."','".$trans["pmfd"]."','".$trans["pmot"]."','".$trans["prod_per"]."','".$trans["prptg"]."','".$trans["pyinc"]."','".$trans["rapd"]."','".$trans["rbs"]."','".$trans["salarycutrepaym"]."','".$trans["salaryheldff"]."','".$trans["sctc"]."','".$trans["sft_km"]."','".$trans["sft_pd"]."','".$trans["sft_rate"]."','".$trans["sftadj"]."','".$trans["sl"]."','".$trans["sl_op"]."','".$trans["tds_ret"]."','".$trans["trainincent"]."','".$trans["weekoff_days"]."','".$trans["yinc"]."','".$trans["md"]."','".$trans["separation_day"]."','".$trans["agreementrecove"]."','".$trans["arr_paid"]."','".$trans["arrearhold"]."','".$trans["esi_sts"]."','".$trans["incadjd"]."','".$trans["nprd"]."','".$trans["pfsts"]."','".$trans["rec"]."','".$trans["sadv"]."','".$trans["sal_adv"]."','".$trans["salarycut"]."','".$trans["salholdnotice"]."','".$trans["monthly_tds"]."','".$trans["tds_inc"]."','".$trans["ahra"]."','".$trans["alta"]."','".$trans["axg"]."','".$trans["aoth_alw"]."','".$trans["ag"]."','".$trans["cl_bal"]."','".$trans["pd"]."','".$trans["conv"]."','".$trans["eattire"]."','".$trans["eb"]."','".$trans["ecea"]."','".$trans["flta"]."','".$trans["elta"]."','".$trans["emed"]."','".$trans["epa"]."','".$trans["ephone"]."','".$trans["epp"]."','".$trans["fxg"]."','".$trans["exg"]."','".$trans["fctc"]."','".$trans["fhra"]."','".$trans["fininc"]."','".$trans["food"]."','".$trans["hra"]."','".$trans["lev_encashrate"]."','".$trans["lev_encashamt"]."','".$trans["loyalbon"]."','".$trans["m_sft_alw"]."','".$trans["mealallo"]."','".$trans["ot_rate"]."','".$trans["eot"]."','".$trans["ot_maxhrs"]."','".$trans["fpfgt"]."','".$trans["fpfg"]."','".$trans["fepf"]."','".$trans["foa"]."','".$trans["oth_alw"]."','".$trans["eg"]."','".$trans["pfgtot"]."','".$trans["pfg"]."','".$trans["cpf"]."','".$trans["ctc"]."','".$trans["fg"]."','".$trans["pfamount"]."','".$trans["emlr_pf"]."','".$trans["fnp"]."','".$trans["jan_inc"]."','".$trans["ot"]."','".$trans["pmota"]."','".$trans["sft_alw"]."','".$trans["sl_bal"]."','".$trans["tl"]."','".$trans["ptax"]."','".$trans["er_pf"]."','".$trans["npra"]."','".$trans["esi"]."','".$trans["mealcard"]."','".$trans["esi_grs_cond"]."','".$trans["esi_grs"]."','".$trans["empr_esi_cond"]."','".$trans["empr_esi"]."','".$trans["role"]."','".$trans["employee_code"]."','".$trans["emp_name"]."','".$trans["department"]."','".$trans["designation"]."','".$trans["date_of_joining"]."','".$trans["esi_eligibility"]."','".$trans["pf_eligibility"]."','".$trans["lwf_location"]."','".$trans["process_month"]."','".$trans["resignation_date"]."','".$trans["termination_status"]."','".$trans["payroll"]."','".$trans["desgrade"]."')";
			 
		 
	 $qry_4 = 'INSERT INTO cw_transactions(employees_id,transactions_month,total_earnings,total_deductions,net_pay,trans_created_by,trans_created_date,ab,acea,aconv,actc,adv,aepf,afg,amed,apa,aphone,app,arrearwithheld,att_per,b_inc,bonus,cl,cl_op,comcha,creadj,e_days,err_per,estatt,estpro,fattire,fb,fca,fcea,feb_inc,flb,fma,fmed,food_pd,fpa,fphone,fpp,inc_adj,lapreim,lcd,lcmd,ld,lectc,led,lev_encashday,m_sft_pd,marrs,maxpf_sts,njcd,njd,notice_period,oj_inc,ot_hrs,otadj,pmfd,pmot,prod_per,prptg,pyinc,rapd,rbs,salarycutrepaym,salaryheldff,sctc,sft_km,sft_pd,sft_rate,sftadj,sl,sl_op,tds_ret,trainincent,weekoff_days,yinc,md,separation_day,agreementrecove,arr_paid,arrearhold,esi_sts,incadjd,nprd,pfsts,rec,sadv,sal_adv,salarycut,salholdnotice,monthly_tds,tds_inc,ahra,alta,axg,aoth_alw,ag,cl_bal,pd,conv,eattire,eb,ecea,flta,elta,emed,epa,ephone,epp,fxg,exg,fctc,fhra,fininc,food,hra,lev_encashrate,lev_encashamt,loyalbon,m_sft_alw,mealallo,ot_rate,eot,ot_maxhrs,fpfgt,fpfg,fepf,foa,oth_alw,eg,pfgtot,pfg,cpf,ctc,fg,pfamount,emlr_pf,fnp,jan_inc,ot,pmota,sft_alw,sl_bal,tl,ptax,er_pf,npra,esi,mealcard,esi_grs_cond,esi_grs,empr_esi_cond,empr_esi,role,employee_code,emp_name,department,designation,date_of_joining,esi_eligibility,pf_eligibility,lwf_location,process_month,resignation_date,termination_status,payroll,desgrade'.$trans_key_array.') VALUES '.implode(',',$payroll_array[4]); 
			}
		}  
	 if($payroll_array[2]){ 
	 $this->db->query($qry_2); 
	 }
	 if($payroll_array[3]){ 
	 $this->db->query($qry_3); 
	 }
	 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 Documentation Fee
	public function get_document_fees($category,$employee_code,$process_month){
		$payroll_exist_count = $this->payroll_count[$employee_code];
		if((int)$payroll_exist_count === 0 && $process_month !== "03-2020"){
			return 500;
		}else{
			return 0;
		}
	}
	//Get DRA Fee
	public function get_dra_amount($branch,$date_of_joining,$dra_prev,$dra_completion_status,$employee_code){		
		if((int)$dra_completion_status === 2){	
			// Get Branch wise DRA Amount
			$dra_amount_qry    = 'SELECT dra_amount,actual_amount from cw_dra_amount where cw_dra_amount.trans_status = 1 and cw_dra_amount.branch = "'.$branch.'" and start_date <= "'.$date_of_joining.'" and end_date >= "'.$date_of_joining.'"';
			$dra_amount_data   = $this->db->query("CALL sp_a_run ('SELECT','$dra_amount_qry')");
			$dra_amount_result = $dra_amount_data->result();
			$dra_amount_data->next_result();
			$dra_amount    = $dra_amount_result[0]->dra_amount;
			$actual_amount = $dra_amount/3;
			$payroll_exist  = (int)$this->payroll_count[$employee_code];
			$payroll_exist_count  = $payroll_exist + 1;
			if($dra_prev >= $dra_amount){
				return 0;
			}else{
				$payroll_check_list_1 = array(1,2,3);
				$payroll_check_list_2 = array(2,3,4);
				if(in_array($employee_code, $this->sup_emp)){
					if(in_array($payroll_exist_count, $payroll_check_list_1)){
						return $actual_amount;
					}else{
						return 0;
					}
				}else{
					if(in_array($payroll_exist_count, $payroll_check_list_2)){
						return $actual_amount;
					}else{
						return 0;
					}					
				}
			}
		}else{
			return 0;
		}
	}
	//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];
							$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'];

				//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'];
				$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, '.', '');
				//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{
					$gratuity_amt 	= 0;
					return $gratutity_amt;
				}
			}
			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);
					}
				}
			}
			public function get_fandf_professional_tax_value($professional_tax_location,$pt_projection,$total_earnings,$process_month){				
				$professional_tax_amount_db = $this->get_map_arr['professional_tax_amount']['db_column'];
				$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 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 and location = "'.$professional_tax_location.'"';
				$ptax_data 		= $this->db->query("CALL sp_a_run ('SELECT','$ptax_qry')");
				$ptax_result 		= $ptax_data->result();
				$ptax_data->next_result();
				$prof_tax_id         = $ptax_result[0]->prime_professional_tax_id;
				$location            = $ptax_result[0]->location;
				$calculation_mode    = $ptax_result[0]->calculation_period;
				$ptax_first_period   = $ptax_result[0]->osm_first_end;
				$ptax_second_period  = $ptax_result[0]->osm_second_end;
				$ptax_deduct_first   = $ptax_result[0]->first_period;
				$ptax_deduct_second  = $ptax_result[0]->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";

				//tax area Tamil Nadu tax calculation
				//By Formula every month calculated ptax amount based on earn gross
				$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){
					//By Monthly  -- Second Method -- values
					//create first and second tax pay period array			
					$period_qry 		= 'select osm_first_start,osm_first_end,osm_second_start,osm_second_end from cw_professional_tax where trans_status =1 and location = "'.$professional_tax_location.'"';
					$period_data 		= $this->db->query("CALL sp_a_run ('SELECT','$period_qry')");
					$period_result 	= $period_data->result();
					$period_data->next_result();
					$osm_first_st_val 	= $period_result[0]->osm_first_start;
					$osm_first_ed_val 	= $period_result[0]->osm_first_end;
					$osm_second_st_val = $period_result[0]->osm_second_start;
					$osm_second_ed_val = $period_result[0]->osm_second_end;
					$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;
					}
					$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);
					$loop_count    = 5;
					$tot_count     = 0;
					//calculating pending projection count loop
					if(in_array($process_month_val,$first_period)){
						$cur_count = array_search($process_month_val, array_values($first_period));
						$tot_count = (int)$loop_count - (int)$cur_count;
					}else
					if(in_array($process_month_val,$second_period)){
						$cur_count = array_search($process_month_val, array_values($second_period));
						$tot_count = (int)$loop_count - (int)$cur_count;
					}
					//projection amount
					$projection_total  = $pt_projection * (int)$tot_count; //2 month count
					//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(total_earnings),0) as total_earnings from cw_transactions where trans_status =1 and employee_code = "'.$employee_code.'" and date_format(str_to_date(transactions_month, "%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;
					//loop processing count
					$process_count 		= (int)$tot_count + 1;

					//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(transactions_month, "%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;
					if($prof_tax < 0){
						$prof_tax = 0;
					}
				}else
				if((int)$calculation_mode === 3){
					//By Once in six month -- Last Method
					$period_qry = 'select osm_first_start,osm_first_end,osm_second_start,osm_second_end from cw_professional_tax where trans_status =1 and location = "'.$professional_tax_location.'" ';
					$period_data    = $this->db->query("CALL sp_a_run ('SELECT','$period_qry')");
					$period_result  = $period_data->result();
					$period_data->next_result();
					$osm_first_st_val  = $period_result[0]->osm_first_start;
					$osm_first_ed_val  = $period_result[0]->osm_first_end;
					$osm_second_st_val = $period_result[0]->osm_second_start;
					$osm_second_ed_val = $period_result[0]->osm_second_end;

					$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;
					}
					$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);
					$loop_count    = 5;
					$tot_count     = 0;

					//calculating pending projection count loop
					if(in_array($process_month_val,$first_period)){
						$cur_count = array_search($process_month_val, array_values($first_period));
						$tot_count = (int)$loop_count - (int)$cur_count; 	
					}else
					if(in_array($process_month_val,$second_period)){
						$cur_count = array_search($process_month_val, array_values($second_period));
						$tot_count = (int)$loop_count - (int)$cur_count;
					}

					//Find Projection amount
					//projection amount
					$projection_total 		= $pt_projection * (int)$tot_count; //2 month count
					//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(total_earnings),0) as total_earnings from cw_transactions where trans_status =1 and employee_code = "'.$employee_code.'" and date_format(str_to_date(transactions_month, "%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;
				}
				return $this->rounding_value($prof_tax,1);
			}
	//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'];
		/*if($term_sts === 1){
			$prof_tax = $this->get_fandf_professional_tax_value($employee_code,$professional_tax_location,$pt_projection,$total_earnings,$process_month);
		}else{*/
		$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_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 and location = "'.$professional_tax_location.'"';
		$ptax_data   = $this->db->query("CALL sp_a_run ('SELECT','$ptax_qry')");
		$ptax_result = $ptax_data->result();
		$ptax_data->next_result();

		$prof_tax_id         = $ptax_result[0]->prime_professional_tax_id;
		$location            = $ptax_result[0]->location;
		$calculation_mode    = $ptax_result[0]->calculation_period;
		$osm_first_st_val    = $ptax_result[0]->osm_first_start;
		$osm_first_ed_val    = $ptax_result[0]->osm_first_end;
		$osm_second_st_val   = $ptax_result[0]->osm_second_start;
		$osm_second_ed_val   = $ptax_result[0]->osm_second_end;
		$osm_second_end_val  = $ptax_result[0]->osm_second_end;
		$ptax_deduct_first   = $ptax_result[0]->first_period;
		$ptax_deduct_second  = $ptax_result[0]->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
			$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_amt     = $find_tax_val - $last_tax_val;
			$prof_tax         = $prof_tax_amt/$process_count;
		}else
		if((int)$calculation_mode === 3){
			//By Once in six month -- Last Method
			if(((int)$process_month_val === (int)$ptax_deduct_first) || ((int)$process_month_val === (int)$ptax_deduct_second)){
				//Find Projection amount
				//projection amount
				$projection_total  = $pt_projection * (int)$proj_count; //2 month count
				//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;
					}
				}			
			return	round($prof_tax);
			}
		

}
	 
?>