File: /home/cafsindia/allyindian_com/sbltt/application/models/Package_model.php
<?php
class Package_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 = "from_date";
}
$this->db->from('package_management');
$this->db->group_start();
$this->db->like('package_id',$search);
$this->db->group_end();
$this->db->group_start();
$this->db->where('DATE_FORMAT(from_date, "%Y-%m-%d") BETWEEN '. $this->db->escape($start_date).' AND '.$this->db->escape($end_date))->or_where('DATE_FORMAT(to_date, "%Y-%m-%d") BETWEEN '. $this->db->escape($start_date).' AND '.$this->db->escape($end_date));
$this->db->group_end();
$this->db->where('package_management.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,$filters){
return $this->search($search, $filters)->num_rows();
}
public function get_info($package_id)
{
$this->db->from('package_management');
$this->db->where('package_id',$package_id);
$a=$this->db->get();
if($a->num_rows() === 1)
{
return $a->row();
}
else
{
foreach ($this->db->list_fields('package_management') as $field)
{
$PersonObj->field= '';
}
return $PersonObj;
}
}
public function exists($package_id){
$this->db->from('package_management');
$this->db->where('package_id', $package_id);
return ($this->db->get()->num_rows() == 1);
}
public function save_package(&$package_data, $package_id = FALSE){
if(!$package_id || !$this->exists($package_id, TRUE)){
if($this->db->insert('package_management', $package_data)){
$package_data['package_id'] = $this->db->insert_id();
return TRUE;
}
return FALSE;
}
$this->db->where('package_id', $package_id);
return $this->db->update('package_management', $package_data);
}
public function save_package_line($package_data,$package_line_id){
if($package_line_id){
$this->db->where('package_line_id', $package_line_id);
return $this->db->update('package_line', $package_data);
}else{
return $this->db->insert('package_line', $package_data);
}
}
public function package_line_list($package_id) {
$this->db->from('package_line');
$this->db->join('customers', 'customers.cust_id = package_line.cust_id','left');
$this->db->where('package_id', $package_id);
return $this->db->get()->result();
}
public function get_pack_line($package_line_id){
$this->db->from('package_line');
$this->db->join('customers', 'customers.cust_id = package_line.cust_id','left');
$this->db->where('package_line_id',$package_line_id);
return $this->db->get()->result();
}
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 delete_list($package_id){
$this->db->where_in('package_id',$package_id);
return $this->db->update('package_management',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('package_management');
$this->db->where_in('package_id', $cat_ids);
return $this->db->get()->result_array();
}
}
?>