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/Temple_enquiry_model.php
<?php
class Temple_enquiry_model extends CI_Model
{
	public function search($search,$filters,$rows = 0,$limit_from= 0,$sort='',$order='desc'){
		$start_date = $filters['start_date'];
		$end_date   = $filters['end_date'];
		if(!$sort){
			$sort = "enquiry_date"; 
		}
		
		$this->db->from('temple_enquiry');
		$this->db->join('customers', 'customers.cust_id = temple_enquiry.cust_id','left');
		$this->db->join('package_management', 'package_management.package_id = temple_enquiry.package_id','left');
		
		
		if($search){
			$this->db->group_start();
				$this->db->or_like('customer_name',$search);
				$this->db->or_like('phone_number',$search);
				$this->db->or_like('package_name',$search);
				$this->db->or_like('enquiry_month',$search);
				if(strpos($search, '-') !== false){
				  $this->db->or_like('enquiry_date', date('Y-m-d',strtotime($search))); 
				}
			$this->db->group_end();	
		}
		$sts = array();
		if($filters['Pending'] != FALSE){ $sts[] = 1; }
		if($filters['Confirm']   != FALSE){ $sts[] = 2; }
		if($filters['Cancelled']   != FALSE){ $sts[] = 3; }
		if(!empty($sts)) {
			$this->db->where_in('enquiry_sts', $sts);
		}		
		
		$this->db->group_start();
			$this->db->where('DATE_FORMAT(enquiry_date, "%Y-%m-%d") BETWEEN '. $this->db->escape($start_date).' AND '.$this->db->escape($end_date));
		$this->db->group_end();
		
		$this->db->where('temple_enquiry.status',1);
		$this->db->order_by($sort,$order);
		if($rows>0){
			$this->db->limit($rows, $limit_from);
		}
		return $this->db->get();
	}
	
	public function get_found_rows($search){
		$this->db->from('temple_enquiry');
		$this->db->where('status',1);
		return $this->db->get()->num_rows();
	}

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

	public function exists($temple_enquiry_id){
		$this->db->from('temple_enquiry');
		$this->db->where('temple_enquiry_id', $temple_enquiry_id);

		return ($this->db->get()->num_rows() == 1);
	}

	/*
	Inserts or updates a temple_enquiry
	*/
	public function save_temple_enquiry(&$temple_enquiry_data, $package_data,$temple_enquiry_id = FALSE){
		$enquiry_sts = $temple_enquiry_data['enquiry_sts'];
		if(!$temple_enquiry_id || !$this->exists($temple_enquiry_id, TRUE)){
			if($this->db->insert('temple_enquiry', $temple_enquiry_data)){
				$temple_enquiry_id = $this->db->insert_id();
				$temple_enquiry_data['temple_enquiry_id'] = $temple_enquiry_id;
				if($enquiry_sts === "2"){
					$package_data['temple_enquiry_id'] = $temple_enquiry_id;
					$this->db->insert('package_line', $package_data);
				}
				return TRUE;
			}
			return FALSE;
		}
		if($enquiry_sts === "2"){
			$package_data['temple_enquiry_id'] = $temple_enquiry_id;
			$this->db->insert('package_line', $package_data);
		}else
		if($enquiry_sts === "3"){
			$this->db->where('temple_enquiry_id', $temple_enquiry_id);
			$this->db->update('package_line', $package_data);
		}
		$this->db->where('temple_enquiry_id', $temple_enquiry_id);
		return $this->db->update('temple_enquiry', $temple_enquiry_data);

	}
	public function get_package() {
	   $this->db->from('package_management');
	   $this->db->where('package_sts', 1);
	   $this->db->order_by('from_date', 'asc');
	   return $this->db->get();
	}
	public function get_state() {
	   $this->db->from('state');
	   $this->db->order_by('state_name', 'asc');
	   return $this->db->get();
	}
	public function get_customer_suggestions($search){		
		$this->db->from('customers');	
		$this->db->where('deleted', 0);
		$this->db->group_start();
			$this->db->like('customer_name', $search);
			$this->db->or_like('phone_number',$search);
			$this->db->or_like('cust_email',$search);
		$this->db->group_end();
		$this->db->order_by('customer_name', 'asc');
		
		$suggestions = array();
		foreach($this->db->get()->result() as $row){
			$suggestions[] = array('cust_id' => $row->cust_id,'customer_name' => $row->customer_name,'phone_number' => $row->phone_number,'cust_email' => $row->cust_email,'cust_address' => $row->cust_address);
		}
		return $suggestions;
	}
	public function get_customer_info($search){	
		$this->db->from('customers');	
		$this->db->where('cust_id', $search);		
		$suggestions = array();
		foreach($this->db->get()->result() as $row){
			
			$suggestions[] = array('cust_id' => $row->cust_id,'customer_name' => $row->customer_name,'phone_number' => $row->phone_number,'alt_number' => $row->alt_number,'land_line' => $row->land_line,'cust_email' => $row->cust_email,'cust_address' => $row->cust_address,'city' => $row->city,'state' => $row->state,'dob' => date('d-m-Y',strtotime($row->dob)),'cust_type' => $row->cust_type,'referral_type' => $row->referral_type,'allow_contract' => $row->allow_contract,'cust_sts' => $row->cust_sts,'includ_gst' => $row->includ_gst,'cust_zone' => $row->cust_zone,'csut_gst' => $row->csut_gst,'csut_pan' => $row->csut_pan);
		}
		return $suggestions;
	}
	public function get_customer($cust_id)	{
		$this->db->from('customers');	
		$this->db->where('cust_id', $cust_id);
		$a=$this->db->get();
		if($a->num_rows() === 1){
			return $a->row();		
		}else{
			foreach ($this->db->list_fields('enquiry') as $field){
				$PersonObj->field= '';
			}
			return $PersonObj;
		}
	}
	public function delete_list($temple_enquiry_id){
		$this->db->where_in('temple_enquiry_id',$temple_enquiry_id);
		return $this->db->update('temple_enquiry',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('temple_enquiry');
		$this->db->where_in('temple_enquiry_id', $cat_ids);
		return $this->db->get()->result_array();
	}
}
?>