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/hrms_cafsinfotech_in/application/controllers/House_rent_entry.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Action_controller.php");
class House_rent_entry  extends Action_controller{
	
	public function __construct(){
		parent::__construct('house_rent_entry');
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
	}
	
	// LOAD PAGE WITH TABLE DATA
	public function index(){	
		//PAGE INFO FUNCTION
		$this->page_info();
		$data['link_info']     = $this->quick_link;
		$data['pick_list']     = $this->pick_list;
		$data['form_info']     = $this->form_info;
		$data['table_head']    = $this->table_head;
		$data['fliter_list']   = $this->fliter_list;
		$data['table_headers']  = $this->xss_clean(get_dbtable_headers($this->table_info));
		$data['financial_info'] = $this->financial_info;

		$category_info   = $this->db->query("CALL sp_a_run ('SELECT','SELECT * FROM `cw_category` where trans_status = 1 and prime_category_id !=1')");
		$category_result = $category_info->result();
		$category_info->next_result();
		$category_list[""] = "---- Category For ----";
		foreach($category_result as $for){
			$cat_id                 = $for->prime_category_id;
			$category_name          = $for->category_name;
			$category_list[$cat_id] = $category_name;
		}
		$data['category_list']      = $category_list;
		$data['key']                = $this->generateKey();
		$this->load->view("$this->control_name/manage",$data);
	}
	
	//LOAD MODEL PAGE VIEW WITH DATA
	public function view($form_view_id=-1){
		//VIEW INFO FUNCTION
		$this->view_info($form_view_id);
		$data['module_sts']             = (int)$this->module_sts;
		//VIEW, FORM INPUT
		$data['view_info']              = $this->view_info;
		$data['form_info']              = $this->form_info;
		$data['formula_result']         = $this->formula_result;//for label color change
		$data['role_based_condition']   = $this->role_based_condition;//for label name readonly options
		$data['all_pick']               = $this->pick_list;//all pick result
		
		//DEPENDENT AUTO PICKLIST
		$data['auto_pick']              = $this->depen_auto_list;//dependent auto result			
		$data['condition_list']         = $this->form_condition_list;

		//VIEW DATA
		$base_query          = str_replace("@SELECT@",$this->view_select,$this->base_query);
		$form_view_qry       = $base_query .' where '.$this->prime_table.'.'.$this->prime_id.' = '.$form_view_id.' and '.$this->prime_table.'.trans_status = 1';
		$row_view_qry        = 'select * from cw_form_view_setting where  prime_view_module_id = "'.$this->control_name.'" and  form_view_type = "3" and trans_status = 1';
		
		$view_pro_qry        = [];
		$view_pro_qry[]      = array("return"=>"form_view","qry"=>$form_view_qry);
		$view_pro_qry[]      = array("return"=>"row_view_list","qry"=>$row_view_qry);	

		$view_info_rslt      = $this->run_multi_qry($view_pro_qry);
		$form_view_rslt      = $view_info_rslt->rslt->form_view[0];			
		$row_view_rslt       = $view_info_rslt->rslt->row_view_list;

		$data['form_view']   = $form_view_rslt;
		
		$row_view_list       = array();
		foreach($row_view_rslt as $view){
			$prime_form_view_id   = $view->prime_form_view_id;
			$row_set_data         = $this->get_row_set_data($prime_form_view_id,$form_view_id);
			$row_view_list[$prime_form_view_id] = $row_set_data;
		}
		$data['row_view_list']   = $row_view_list;
		// $financial_info       = $this->get_financial_year();
		$data['financial_info']  = $this->get_financial_year();
		$data['edit_id']         = $form_view_id;
		//FOR DEPENDENT
		$data['get_depend_prime_id']   = $this->get_depend_fun();
		$data['depend_label_id']   	   = $this->depend_label_fun();	
		$this->load->view("$this->control_name/form",$data);
	}
	
	//IMPORT FILE VIEW INFORMATION
	public function import(){
		$data['module_id']     = $this->control_name;		
		$excel_format_qry = 'select prime_excel_format_id,excel_name from cw_util_excel_format where excel_module_id = "'.$this->control_name.'" and trans_status = 1';
		$excel_format   = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
		$excel_result    = $excel_format->result();
		$excel_format->next_result();
		$excel_format_drop[""] = "---- Excel Format ----";
		foreach($excel_result as $excel){
			$prime_excel_format_id = $excel->prime_excel_format_id;
			$excel_name            = $excel->excel_name;
			$excel_format_drop[$prime_excel_format_id] = $excel_name;
		}
		$data['excel_format_drop'] = $excel_format_drop;
		
		$this->load->view("$this->control_name/import",$data);
	}
	
	//LOAD PAGE TABLE VIEW WITH DATA BASED ON SEARCH FILTERS
	public function search(){
		//SEARCH INFO FUNCTION
		$this->search_info();
		$search       = $this->input->get('search');
		$limit        = $this->input->get('limit');
		$offset       = $this->input->get('offset');
		$sort         = $this->input->get('sort');
		$order        = $this->input->get('order');
		$fliter_label = $this->input->get('fliter_label');
		$fliter_type  = $this->input->get('fliter_type');
		$filter_cond  = $this->input->get('filter_cond');
		$fliter_val   = $this->input->get('fliter_val');
		$filter_count = count($fliter_label ?? []);
		$fliter_query = "";
		$search_count = 0;
		for($i=0;$i<=(int)$filter_count;$i++){
			$db_name     = $fliter_label[$i];
			$table_name  = $fliter_type[$i];
			$db_cond     = $filter_cond[$i];
			$db_value    = $fliter_val[$i];
			if(($db_cond) && ($db_value)){
				$search_count++;
				$search_val = $db_value;
				if($db_cond === "LIKE"){ $search_val = "$db_value%"; }
				if((int)$table_name === 1){ $fliter_query .= ' and '. $this->prime_table .".". $db_name ." ". $db_cond .' "'.$search_val.'"'; }
				if((int)$table_name === 2){ $fliter_query .= ' and '. $this->cf_table .".". $db_name ." ". $db_cond .' "'.$search_val.'"'; }
			}			
		}
		
		$common_search = "";
		if($search){
			$count=0;
			foreach($this->form_info as $setting){
				$prime_form_id   = $setting->prime_form_id;
				$field_type      = $setting->field_type;
				$pick_list       = $setting->pick_list;
				$pick_table      = $setting->pick_table;
				$pick_list_type  = $setting->pick_list_type;
				$input_view_type = (int)$setting->input_view_type;
				$auto_prime_id      = $setting->auto_prime_id;
				$auto_dispaly_value = $setting->auto_dispaly_value;
				$label_id        = strtolower(str_replace(" ","_",$setting->label_name));
				$field_isdefault    = (int)$setting->field_isdefault;
				if($field_isdefault === 1){
					$pick_sel_table = "$this->prime_table";
				}else
				if($field_isdefault === 2){
					$pick_sel_table = "$this->cf_table";
				}
				$other_label_id = $pick_sel_table.".".$label_id;
				
				if(($input_view_type === 1) || ($input_view_type === 2)){
					if((int)$field_type === 4){
						if(strtotime($search)){
							$search_val = date('Y-m-d',strtotime($search));
							$common_search .= ' or '. $other_label_id .' like "'.$search_val.'%"';
						}
					}else
					if(((int)$field_type === 5) || ((int)$field_type === 7)){
						if((int)$pick_list_type === 1){
							$column_name = explode(",",$pick_list);
							$column_name = $column_name[1];
						}else{
							$column_name = $pick_table."_value";
						}
						$pick_query_as  = $pick_table."_".$prime_form_id;
						$label_id       = "$pick_query_as.$column_name";
						$common_search .= ' or '. $label_id .' like "'.$search.'%"';
					}else
					if((int)$field_type === 9){
						$pick_query_as  = $pick_table."_".$prime_form_id;
						$label_id       = "$pick_query_as.$auto_dispaly_value";
						$common_search .= ' or '. $label_id .' like "'.$search.'%"';
					}else{
						if(!strtotime($search)){
							$common_search .= ' or '. $other_label_id .' like "'.$search.'%"';
						}
					}
				}
			}
			if($common_search){
				$common_search = ltrim($common_search,' or ');
				$common_search = " and ($common_search)";
			}
		}
				
		if(!$sort){ $sort = $this->prime_table.".".$this->prime_id; }
		if(!$order){ $order = "asc";  }
		
		$select_info   = str_replace("@SELECT",$this->select_query,$this->base_query);
		$search_query  = $select_info. $this->pick_query;
		
		//ADDED BASIC,FILTER,COMMON QUERY HERE 
		$basic_query = "";
		if($this->table_search_info){
			$basic_query = $this->table_search_info;
		}
		$search_query .= " where $this->prime_table.trans_status = 1 $basic_query $fliter_query $common_search";
		$search_query .= " ORDER BY  $sort $order";
		$search_query .= " LIMIT  $offset,$limit";
		
		//FETCH RECORDS DATA
		$search_data   = $this->db->query("CALL sp_a_run ('SELECT','$search_query')");
		$search_result = $search_data->result();
		$num_rows      = $search_data->num_rows();
		$search_data->next_result();
		$data_rows     = array();
		foreach ($search_result as $search){
			$data_rows[]=get_dbdata_row($search,$this->table_info,$this->print_info,$this);
		}
		//$data_rows=$this->xss_clean($data_rows);
		
		//FETCH RECORDS COUNT
		$count_info    = "count(*) as rslt_count";
		$base_query    = str_replace("@SELECT",$count_info,$this->base_query);
		$search_query  = $base_query. $this->pick_query;
		$search_query .= " where $this->prime_table.trans_status = 1 $basic_query $fliter_query $common_search";
		$count_data    = $this->db->query("CALL sp_a_run ('SELECT','$search_query')");
		$count_result  = $count_data->result();
		$count_data->next_result();
		echo json_encode(array('total'=>$count_result[0]->rslt_count,'rows'=>$data_rows));
	}
	
	//SAVE MODEL DATA TO DATA BASE
	public function save(){
		//SAVE INFO FUNCTION
		$this->save_info();	
		$unq_chk         = array();
		$prime_qry_key   = "";
		$prime_qry_value = "";
		$prime_upd_query = "";
		$cf_qry_key      = "";
		$cf_qry_value    = "";
		$cf_upd_query    = "";	
		$cf_has          = false;
		$form_id         = (int)$this->input->post($this->prime_id);
		$previous_data   = $this->get_previous_view($form_id);
		$previous_data   = $previous_data[0];
		$form_post_data  = array();
	
		foreach($this->form_info as $setting){
			$field_type      = $setting->field_type;
			$input_view_type = (int)$setting->input_view_type;
			$label_id        = strtolower(str_replace(" ","_",$setting->label_name));
			$field_isdefault = $setting->field_isdefault;
			$unique_field    = (int)$setting->unique_field;
			$view_name       = $setting->view_name;
			$date_type       = $setting->date_type;
			if((int)$field_type === 5){
				$value = trim($this->input->post($label_id));
				$pick_array[$label_id]  = $value;
			}else	
			if((int)$field_type === 7){
				$multi_name = $label_id."[]";
				$value = trim(implode(",",$this->input->post($multi_name) ?? []));
			}else{
				$value = trim($this->input->post($label_id));
			}
			
			if((int)$field_type === 4){
				if((int)$date_type === 1){
					$value = date('Y-m-d',strtotime($value));
				}else{
					$value = $value;
				}
			}else
			if((int)$field_type === 13){
				$value = date('Y-m-d H:i:s',strtotime($value));
			}else
			if((int)$field_type === 8){//textbox only
				$value = str_replace('"',"~",$value);
				$value = str_replace("'","`",$value);
				
			}else
			if((int)$field_type === 10){//File Upload
				$value 		 		 = $value;
				$remove_upload_fname = "old_".$label_id;
				$remove_upload_file  = $this->input->post($remove_upload_fname);
				if($value !== $remove_upload_file){
					unlink($remove_upload_file);  
				}
			}
			
			if(($input_view_type === 1) || ($input_view_type === 2)){
				if((int)$field_isdefault === 1){
					$prime_qry_key     .= $label_id.",";
					$prime_qry_value   .= '"'.$value.'",';
					$prime_upd_query   .= $label_id.' = "'.$value.'",';
					if($unique_field === 1){
						$prime_unq_chk = $label_id.'= "'.$value.'"';
						$query = "select count(*) as rslt_count from $this->prime_table where $this->prime_id != $form_id and $prime_unq_chk";
						$unq_chk[] = array('label_id'=>$label_id,'view_name'=>$view_name,'query'=>$query,);
					}
				}else{
					$cf_has = true;
					$cf_qry_key     .= $label_id.",";
					$cf_qry_value   .= '"'.$value.'",';
					$cf_upd_query   .= $label_id.' = "'.$value.'",';
					if($unique_field === 1){
						$cf_unq_chk = $label_id.'= "'.$value.'"';
						$query = "select count(*) as rslt_count from $this->cf_table where $this->prime_id != $form_id and $cf_unq_chk";
						$unq_chk[] = array('label_id'=>$label_id,'view_name'=>$view_name,'query'=>$query,);
					}
				}
			}
		}
		$rslt_count = 0;
		$can_process = array();
		foreach($unq_chk as $unq_rslt){
			$query       = $unq_rslt['query'];
			$label_id    = $unq_rslt['label_id'];
			$view_name   = $unq_rslt['view_name'];
			$unq_info    = $this->db->query("CALL sp_a_run ('RUN','$query')");
			$unq_result  = $unq_info->result();
			$unq_info->next_result();
			if($unq_result){
				$rslt_count = (int)$unq_result[0]->rslt_count;
				if($rslt_count !== 0){
					$can_process[] = $view_name." already exist";
				}
			}
		}
		
		if(count($can_process) > 0){
			$can_process  = array_values($can_process);				
			$can_process  = implode(",<br/>", $can_process);
			echo json_encode(array('success' => false, 'message' => $can_process,));
		}else{
			$created_on = date("Y-m-d h:i:s");
			if((int)$form_id === 0){
				$prime_qry_key     .= "trans_created_by,trans_created_date";
				$prime_qry_value   .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
				$prime_insert_query = "insert into $this->prime_table ($prime_qry_key) values ($prime_qry_value)";
				$insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$prime_insert_query')");
				$insert_result      = $insert_info->result();
				$insert_info->next_result();
				$insert_id = $insert_result[0]->ins_id;
				
				$cf_qry_key     .= "trans_created_by,trans_created_date";
				$cf_qry_value   .= '"'.$this->logged_id.'",'.'"'.$created_on.'"';
				$cf_insert_query = 'insert into ' .$this->cf_table. ' ('.$this->prime_id.','.$cf_qry_key.') values ("'.$insert_id.'",'.$cf_qry_value.')';
				$insert_info     = $this->db->query("CALL sp_a_run ('INSERT','$cf_insert_query')");
				$insert_info->next_result();
				
				echo json_encode(array('success' => TRUE, 'message' => "Successfully added", 'insert_id' => $insert_id));
			}else{
				$prime_upd_query    .= 'trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
				$prime_update_query  = 'UPDATE '. $this->prime_table .' SET '. $prime_upd_query .' WHERE '. $this->prime_id .' = "'. $form_id .'"';
				$this->db->query("CALL sp_a_run ('UPDATE','$prime_update_query')");
				
				$cf_upd_query    .= 'trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'"';
				$cf_update_query  = 'UPDATE '. $this->cf_table .' SET '. $cf_upd_query .' WHERE '. $this->prime_id .' = "'. $form_id .'"';
				$this->db->query("CALL sp_a_run ('UPDATE','$cf_update_query')");
				echo json_encode(array('success' => TRUE, 'message' => "Successfully updated",'insert_id' => $form_id));
			}
		}
	}
		
	//category based employee list -- 27AUG2019
	public function get_employee_list(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
			exit(0);
		}
		$category = $this->input->post('category');
		$emp_query  = 'SELECT emp_name,employee_code FROM cw_employees WHERE role = "'.$category.'" and trans_status =1';
		$emp_info   = $this->db->query("CALL sp_a_run ('SELECT','$emp_query')");
		$emp_result = $emp_info->result();
		$emp_info->next_result();
		$emp_list = "<option value=''>---- Select Employee ----</option>";
		foreach($emp_result as $result){
			$name      = $result->emp_name;
			$emp_code  = $result->employee_code;
			$emp_list .= "<option value='$emp_code'>$emp_code - $name</option>";
		}
		echo $emp_list;
	}
	
	//section and subsection details
	public function get_house_rent_list(){	
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
			exit(0);
		}
		$this->save_info();
		$category             = $this->input->post('category');
		$emp_code             = $this->input->post('emp_code');
		$effective_month      = $this->input->post('effective_month');
		$financial_info       = $this->get_financial_year();
		$financial_setting_id = $financial_info[0]->prime_financial_setting_id;
		$tr_line = "";
		$today   = date('d');
		//get employee lock or unlock based on emp_code 
		$emp_lock_query  	='SELECT declaration_lock from cw_employees where employee_code ="'.$emp_code.'"';
		$query_info     	= $this->db->query("$emp_lock_query");
		$dec_lock_result    = $query_info->result();
		$dec_lock_data      = $dec_lock_result[0]->declaration_lock;
		$dec_lock_date      = $this->company_info[0]->dec_lock_date;
		//declaration lock employee
		if((int)$dec_lock_data === 1){
			echo json_encode(array('status' => "failed", 'message' => "Declaration is locked for this employee"));
			exit(0);
		}
		//declaration_lock_date condition
		if((int)$dec_lock_date < (int)$today){
			echo json_encode(array('success' => "failed", 'message' => "Declaration entry is locked in company information!.. Please contact HR!.."));
			exit(0);
		}	
		$months  = $this->get_months();
		foreach($months as $dt){				
			$month = $dt->format("M-Y");
			$month_date = date("Y-m-d",strtotime("01-".$dt->format('m-Y')));
			if($effective_month){
				// non_metro_rent_paid,non_metro_days
				// $house_rent_list_qry  = 'select metro_rent_paid,metro_days from cw_house_rent_entry WHERE financial_setting_id = "'. $financial_setting_id .'" and trans_status = 1 and employee_code = "'. $emp_code .'" and effective_month = "'. $effective_month .'" and month = "'. $month_date .'" group by month,effective_month';
		
				$house_rent_list_qry = 'SELECT metro_rent_paid,non_metro_rent_paid,metro_days,non_metro_days FROM cw_house_rent_entry as a INNER JOIN (SELECT employee_code, date_format(MAX(str_to_date(CONCAT("01-", effective_month), "%d-%m-%Y")) , "%m-%Y") AS max_date FROM cw_house_rent_entry where employee_code =  "'. $emp_code .'" and  financial_setting_id = "'.$financial_setting_id.'" and date_format(str_to_date(CONCAT("01-", effective_month), "%d-%m-%Y"), "%Y-%m-%d") <= date_format(str_to_date("01-'.$effective_month.'", "%d-%m-%Y"), "%Y-%m-%d") GROUP BY employee_code) as groupedtt  ON a.employee_code = groupedtt.employee_code AND a.effective_month = groupedtt.max_date AND MONTH = "'. $month_date .'"';
				$house_rent_list_info   = $this->db->query("CALL sp_a_run ('SELECT','$house_rent_list_qry')");
				$house_rent_list_result = $house_rent_list_info->result();
				$house_rent_list_info->next_result();
			}
			
			if($house_rent_list_result){
				$metro_rent_paid     = $house_rent_list_result[0]->metro_rent_paid;
				$non_metro_rent_paid = $house_rent_list_result[0]->non_metro_rent_paid;
				$metro_days = $house_rent_list_result[0]->metro_days;
				$non_metro_days = $house_rent_list_result[0]->non_metro_days;
			}else{
				$metro_rent_paid     = 0.00;
				$non_metro_rent_paid = 0.00;
				$metro_days          = 0.00;
				$non_metro_days      = 0.00;
			}
			$hid_input = "<input type='hidden' class='form-control' id='month_".$month."' name='month[]' value ='$month_date' class='form-control'/>";
			$tr_line .= "<tr>$hid_input <td>".$month."</td><td><input type='text' class='form-control' id='metro_".$month."' name='metro[]' value ='$metro_rent_paid'/></td><td><input type='text' class='form-control' id='metro_days_".$month."' name='metro_days[]' onchange=get_nonmetro_days(this.value,'".$month_date."','".$month."') value ='$metro_days'/></td><td><input type='text' class='form-control' id='non_metro_".$month."' name='non_metro[]' value ='$non_metro_rent_paid'/></td><td><input type='text' class='form-control' id='non_metro_days_".$month."' name='non_metro_days[]' onchange=get_metro_days(this.value,'".$month_date."','".$month."') value ='$non_metro_days'/></td></tr>";
		}
		
		$table_info = "<table class='table table-bordered'>
								<thead>
									<tr>
										<th>Month</th>
										<th>Metro Paid</th>										
										<th>Metro Days</th>
										<th>Non Metro Paid</th>
										<th>Non Metro Days</th>
									</tr>
								</thead>
								<tbody>
									$tr_line
								</tbody>
						   </table>
						   <div class='col-md-12' style='float: initial;text-align: end;'><button class='btn btn-primary btn-sm' id='save_data'><i class='fa fa-floppy-o' aria-hidden='true'></i>&nbsp; Save</button></div>";
		echo json_encode(array("status"=>"success","table"=>$table_info));
	}
	public function get_days(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
			exit(0);
		}
		$val    = $this->input->post('val');
		$month  = explode("-",$this->input->post('month_day'));
		$days = cal_days_in_month(CAL_GREGORIAN,$month[1],$month[0]);
		$result_days = $days - $val;
		echo $result_days;
	}
	public function save_house_rent(){
		$encString         = file_get_contents('php://input');
		$_POST             = $this->cryptoDecrypt($encString);
		if(!$_POST){
			echo json_encode(array('success' => false,'message' => 'Url Expired.. Please refresh the page and try again....','table_data' => ""));
			exit(0);
		}
		$this->save_info();
		$month           = $this->input->post('month');
		$category        = $this->input->post('category');
		$emp_code        = $this->input->post('emp_code');
		$effective_month = $this->input->post('effective_month');
		$metro           = $this->input->post('metro');
		$non_metro       = $this->input->post('non_metro');
		$metro_days      = $this->input->post('metro_days');
		$non_metro_days  = $this->input->post('non_metro_days');
		$count           = count($metro);
		$created_on      = date("Y-m-d H:i:s");
		//
		$today   = date('d');
		//get employee lock or unlock based on emp_code 
		$emp_lock_query  	='SELECT declaration_lock from cw_employees where employee_code ="'.$emp_code.'"';
		$query_info     	= $this->db->query("$emp_lock_query");
		$dec_lock_result    = $query_info->result();
		$dec_lock_data      = $dec_lock_result[0]->declaration_lock;
		$dec_lock_date      = $this->company_info[0]->dec_lock_date;
		//declaration lock employee
		if((int)$dec_lock_data === 1){
			echo json_encode(array('status' => "failed", 'message' => "Declaration is locked for this employee"));
			exit(0);
		}
		//declaration_lock_date condition
		if((int)$dec_lock_date < (int)$today){
			echo json_encode(array('status' => "failed", 'message' => "Declaration entry is locked in company information!.. Please contact HR!.."));
			exit(0);
		}	
		$financial_info       = $this->get_financial_year();
		$financial_setting_id = $financial_info[0]->prime_financial_setting_id;
		$house_rent_qry   = 'select count(*) as rslt_count from cw_house_rent_entry WHERE financial_setting_id = "'. $financial_setting_id .'" and employee_code = "'. $emp_code .'" and effective_month = "'. $effective_month .'" and trans_status = 1';
		$house_rent_info   = $this->db->query("CALL sp_a_run ('SELECT','$house_rent_qry')");
		$house_rent_result = $house_rent_info->result();
		$house_rent_info->next_result();		
		$house_rent_count = $house_rent_result[0]->rslt_count;

		for($i=0; $i < $count; $i++){
			if((int)$house_rent_count === 0){
				$dec_entry_insert_qry = 'insert into cw_house_rent_entry (financial_setting_id,category,employee_code,effective_month,month,metro_rent_paid,non_metro_rent_paid,metro_days,non_metro_days,trans_created_by,trans_created_date) values ("'.$financial_setting_id.'","'.$category.'","'.$emp_code.'","'.$effective_month.'","'.$month[$i].'","'.$metro[$i].'","'.$non_metro[$i].'","'.$metro_days[$i].'","'.$non_metro_days[$i].'","'.$this->logged_id.'",'.'"'.$created_on.'")';
				$dec_entry_insert_info        = $this->db->query("CALL sp_a_run ('INSERT','$dec_entry_insert_qry')");
				$dec_entry_insert_result      = $dec_entry_insert_info->result();
				$dec_entry_insert_info->next_result();				
			}else{
				$update_query  = 'UPDATE cw_house_rent_entry SET metro_rent_paid = "'. $metro[$i] .'",non_metro_rent_paid = "'. $non_metro[$i] .'",metro_days = "'. $metro_days[$i] .'",non_metro_days = "'. $non_metro_days[$i] .'",trans_updated_by = "'. $this->logged_id .'",trans_updated_date = "'.$created_on.'" WHERE financial_setting_id = "'. $financial_setting_id .'" and employee_code = "'. $emp_code .'" and effective_month = "'. $effective_month .'" and month = "'. $month[$i] .'" and trans_status = 1';
				// echo $update_query."<br/>";
				$dec_entry_update_info        = $this->db->query("CALL sp_a_run ('UPDATE','$update_query')");	
			}				
		}
		if($dec_entry_insert_result){
			echo json_encode(array('success' => TRUE, 'message' => "Successfully added your House Rent entry"));
		}else
		if($dec_entry_update_info){
			echo json_encode(array('success' => true, 'message' => "Successfully data is updated!!!"));	
		}else{
			echo json_encode(array('success' => False, 'message' => "Try After Sometime!!!"));
		}	
	}
	public function get_months(){
		$financial_info  = $this->get_financial_year();
		$start_date      = $financial_info[0]->start_date;
		$end_date        = $financial_info[0]->end_date;
		$start           = new DateTime($start_date);
		$end             = new DateTime($end_date);
		$start->modify('first day of this month');
		$end->modify('last day of this month');
		$interval = DateInterval::createFromDateString('1 month');
		$period   = new DatePeriod($start, $interval, $end);
		return $period;
	}
	//function for delete
	// public function delete_section(){
	// 	$category             = $this->input->post('category');
	// 	$emp_code             = $this->input->post('emp_code');
	// 	$effective_month      = $this->input->post('effective_month');
	// 	$created_on = date("Y-m-d H:i:s");
	// 	$financial_info       = $this->get_financial_year();
	// 	$financial_setting_id = $financial_info[0]->prime_financial_setting_id;
	// 	$update_upd_query    .= 'trans_deleted_by = "'. $this->logged_id .'",trans_deleted_date = "'.$created_on.'"';
	// 	if($effective_month){
	// 		$update_query  = 'UPDATE cw_house_rent_entry SET trans_status = 0, '. $update_upd_query .' WHERE financial_setting_id = "'. $financial_setting_id .'" and employee_code = "'. $emp_code .'" and effective_month = "'. $effective_month .'"';
			
	// 		$this->db->query("CALL sp_a_run ('UPDATE','$update_query')");
	// 		echo json_encode(array('success' => true, 'message' => "Deleted your data successfully!!!"));
	// 	}else{
	// 		echo json_encode(array('success' => false, 'message' => "Server timeout!!!"));
	// 	}
	// }
}
?>