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/allyindian_com/sbltt/application/models/Demand_date_model.php
<?php
class Demand_date_model extends CI_Model
{
	public function search($search,$rows = 0,$limit_from= 0,$sort='demand_date_id',$order='asc'){
		$this->db->from('demand_date');
		$this->db->where('demand_date.status',1);
		$this->db->group_start();
		$this->db->like('demand_date_id',$search);
		$this->db->or_like('demand_month',$search);
		$this->db->group_end();
		$this->db->order_by('demand_date_id',$order);
		if($rows>0)
		{
			$this->db->limit($rows, $limit_from);
		}
		return $this->db->get();
	}
	
	public function get_found_rows($search){
		$this->db->from('demand_date');
		$this->db->where('status',1);
		return $this->db->get()->num_rows();
	}

	public function get_info($demand_date_id){
		$this->db->from('demand_date');
		$this->db->where('demand_date_id',$demand_date_id);
		$a=$this->db->get();
		if($a->num_rows() === 1){
			return $a->row();		
		}else{
			foreach ($this->db->list_fields('demand_date') as $field){
				$PersonObj->field= '';
			}
			return $PersonObj;
		}
	}

	public function exists($demand_date_id,$demand_month){
		$this->db->from('demand_date');
		$this->db->group_start();
          $this->db->where("demand_date_id",$demand_date_id)->or_where("demand_month",$demand_month);
        $this->db->group_end();
		return ($this->db->get()->num_rows() == 1);
	}

	/*
	Inserts or updates a demand_date
	*/
	public function save_demand_date(&$demand_date_data, $demand_date_id = FALSE){
		//print_r($demand_date_data);
		$demand_month = explode("-",$demand_date_data['demand_month']) ;
		$percentage   = $demand_date_data['percentage'];
		$created_by   = $demand_date_data['created_by'];
		$created_date = $demand_date_data['created_date'];
		$demand_date  = $demand_date_data['demand_date'];
		
		$count = count($demand_date);
		//$days  = date("t");
		$days =cal_days_in_month(CAL_GREGORIAN,$demand_month[0],$demand_month[1]);
		$demand_data['demand_month'] = $demand_month[1]."-".$demand_month[0];
		$demand_data['percentage']   = $percentage;
		$demand_data['created_by']   = $created_by;
		$demand_data['created_date'] = $created_date;
		for($i=1; $i <= $days; $i++){
			$col = "day_".$i;
			if(in_array($i, $demand_date)){
				$demand_data[$col] = "1";
			}else{
				$demand_data[$col] = "0";
			}
		}
		if(!$demand_date_id || !$this->exists($demand_date_id, $demand_data['demand_month'])){
			if($this->db->insert('demand_date', $demand_data)){
				$demand_date_data['demand_date_id'] = $this->db->insert_id();
				return TRUE;
			}
			return FALSE;
		}	
		$this->db->where('demand_date_id', $demand_date_id);
		return $this->db->update('demand_date', $demand_data);
	}

	public function delete_list($demand_date_id){
		$this->db->where_in('demand_date_id',$demand_date_id);
		return $this->db->update('demand_date',array('status'=>0,'deleted_by'=>$this->session->userdata('emp_id'),'deleted_date'=>date('Y-m-d h:i:s')));
	}

	public function get_multiple_info($cat_ids){
		$this->db->from('demand_date');
		$this->db->where_in('demand_date_id', $cat_ids);
		return $this->db->get()->result_array();
	}
}
?>