File: /home/cafsindia/allyindian_com/sbltt/application/models/Catering_model.php
<?php
class Catering_model extends CI_Model
{
public function search($search,$filters,$rows = 0,$limit_from= 0,$sort='',$order='asc'){
$start_date = $filters['start_date'];
$end_date = $filters['end_date'];
if(!$sort){
$sort = "order_date";
}
$this->db->from('catering_outside');
$this->db->join('customers', 'customers.cust_id = catering_outside.cust_id','left');
$this->db->join('booking_type', 'booking_type.booking_type_id = catering_outside.cust_type','left');
$this->db->group_start();
$this->db->like('cat_out_id',$search);
$this->db->or_like('customer_name',$search);
if(strpos($search, '-') !== false){
$this->db->or_like('order_date', date('Y-m-d',strtotime($search)));
}
$this->db->group_end();
$this->db->where('catering_outside.status',1);
$this->db->order_by('cat_out_id',$order);
if($rows>0)
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
public function get_load_data($cat_out_id){
$this->db->select('*,catering_outside.created_date as catering_date');
$this->db->from('catering_outside');
$this->db->join('customers', 'customers.cust_id = catering_outside.cust_id','left');
$this->db->join('booking_type', 'booking_type.booking_type_id = catering_outside.cust_type','left');
$this->db->join('state', 'state_code = customers.state','left');
$this->db->where('catering_outside.status',1);
$this->db->where('cat_out_id',$cat_out_id);
return $this->db->get()->result();
}
public function get_found_rows($search,$filters){
return $this->search($search, $filters)->num_rows();
}
public function get_info($cat_out_id){
$this->db->from('catering_outside');
$this->db->where('cat_out_id',$cat_out_id);
$a=$this->db->get();
if($a->num_rows() === 1){
return $a->row();
}else{
foreach ($this->db->list_fields('catering_outside') as $field){
$PersonObj->field= '';
}
return $PersonObj;
}
}
public function exists($cat_out_id){
$this->db->from('catering_outside');
$this->db->where('cat_out_id', $cat_out_id);
return $this->db->get()->num_rows();
}
public function save_catering(&$catering_orders_data, $cat_out_id = FALSE){
$count = $this->exists($cat_out_id, TRUE);
if((int)$count > 0){
$this->db->where('cat_out_id', $cat_out_id);
return $this->db->update('catering_outside', $catering_orders_data);
}else{
$this->db->insert('catering_outside', $catering_orders_data);
return $catering_orders_data['cat_out_id'] = $this->db->insert_id();
}
}
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('booking') as $field){
$PersonObj->field= '';
}
return $PersonObj;
}
}
public function get_state() {
$this->db->from('state');
$this->db->order_by('state_name', 'asc');
return $this->db->get();
}
public function get_booking_type() {
$this->db->from('booking_type');
$this->db->order_by('booking_type_name', 'asc');
return $this->db->get();
}
public function get_catering_team() {
$this->db->from('employees');
$this->db->join('people', 'people.person_id = employees.person_id');
$this->db->join('role', 'employees.role = role.role_id');
$this->db->where('status', 1);
$this->db->where('role', 10);
return $this->db->get()->result();
}
public function get_catering_menu() {
$this->db->from('catering_menu');
$this->db->order_by('name', 'asc');
$this->db->where('status',1);
return $this->db->get();
}
public function get_menu($catering_menu_id){
$this->db->from('catering_menu');
$this->db->where('catering_menu_id',$catering_menu_id);
$this->db->where('status',1);
return $this->db->get()->result();
}
public function save_balance_log($balance_data,$cat_bal_log_id){
$cat_out_id = $balance_data['cat_out_id'];
if($cat_bal_log_id){
$this->db->where('cat_bal_log_id', $cat_bal_log_id);
$this->db->update('cat_balance_log', $balance_data);
return $this->update_balance($cat_out_id);
}else{
$this->db->insert('cat_balance_log', $balance_data);
return $this->update_balance($cat_out_id);
}
}
public function balance_log_list($cat_out_id) {
$this->db->from('cat_balance_log');
$this->db->where('cat_out_id', $cat_out_id);
$this->db->order_by('balance_date', 'asc');
return $this->db->get()->result();
}
public function get_balance_log($cat_bal_log_id){
$this->db->from('cat_balance_log');
$this->db->where('cat_bal_log_id',$cat_bal_log_id);
return $this->db->get()->result();
}
public function get_catline_amount($cat_out_id){
$this->db->select('IFNULL(sum(amount), 0) as line_amt');
$this->db->from('cat_line_orders');
$this->db->where('cat_out_id', $cat_out_id);
$catline_amount = $this->db->get()->row();
$line_amt = $catline_amount->line_amt;
$catering_info = $this->get_load_data($cat_out_id);
foreach($catering_info as $catering){
$tax_precentage = $catering->tax_precentage;
$includ_gst = $catering->includ_gst;
$state = $catering->state;
}
$igst = 0;
$sgst = 0;
$cgst = 0;
if($tax_precentage > 0){
$igst = $tax_precentage;
$sgst = $tax_precentage /2;
$cgst = $tax_precentage /2;
}
$igst_amt = $line_amt * $igst/100;
$sgst_amt = $line_amt * $sgst/100;
$cgst_amt = $line_amt * $cgst/100;
$total_amt = $line_amt;
if($includ_gst === "1"){
if($state === "33"){
$total_amt = $line_amt + $cgst_amt + $sgst_amt;
}else{
$total_amt = $line_amt + $igst_amt;
}
}
return $total_amt;
}
public function get_bal_log_amount($cat_out_id) {
$this->db->select('IFNULL(sum(amount), 0) as paid_amt');
$this->db->from('cat_balance_log');
$this->db->where('cat_out_id', $cat_out_id);
return $this->db->get()->row();
}
public function get_total_amt($cat_out_id){
$this->db->select('IFNULL(catering_amount, 0) as total_amt');
$this->db->from('catering_outside');
$this->db->where('cat_out_id', $cat_out_id);
return $this->db->get()->row();
}
public function update_balance($cat_out_id){
$total_info = $this->get_total_amt($cat_out_id);
$paid_info = $this->get_bal_log_amount($cat_out_id);
$total_amt = $total_info->total_amt;
$paid_amt = $paid_info->paid_amt;
$balance_amt = (int)$total_amt - (int)$paid_amt;
$this->db->where('cat_out_id', $cat_out_id);
return $this->db->update('catering_outside', array('balance'=>$balance_amt));
}
public function catering_line_save($catering_data,$cat_out_id, $date){
$count = $this->catering_exists($cat_out_id,$date);
if($count === 0){
$this->db->insert('cat_line_orders', $catering_data);
$catline_amount = $this->get_catline_amount($cat_out_id);
$this->db->where('cat_out_id', $cat_out_id);
return $this->db->update('catering_outside', array('catering_amount'=>$catline_amount));
}else{
$this->db->where('cat_out_id', $cat_out_id);
$this->db->where('order_date', $date);
$this->db->update('cat_line_orders', $catering_data);
$catline_amount = $this->get_catline_amount($cat_out_id);
$this->db->where('cat_out_id', $cat_out_id);
return $this->db->update('catering_outside', array('catering_amount'=>$catline_amount));
}
}
public function catering_exists($cat_out_id,$date){
$this->db->from('cat_line_orders');
$this->db->where('cat_out_id', $cat_out_id);
$this->db->where('order_date', $date);
return $this->db->get()->num_rows();
}
public function get_catering_order($cat_out_id) {
$this->db->from('cat_line_orders');
$this->db->where('cat_out_id', $cat_out_id);
$this->db->order_by('order_date', 'asc');
return $this->db->get()->result();
}
public function get_order($out_line_id){
$this->db->from('cat_line_orders');
$this->db->where('out_line_id',$out_line_id);
$this->db->where('status',1);
return $this->db->get()->result();
}
public function delete_list($cat_out_id){
$this->db->where_in('cat_out_id',$cat_out_id);
return $this->db->update('catering_outside',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('catering_outside');
$this->db->where_in('cat_out_id', $cat_ids);
return $this->db->get()->result_array();
}
}
?>