File: //home/cafsindia/allyindian_com/sbltt/application/controllers/Catering.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class catering extends Secure_Controller{
public function __construct(){
parent::__construct('catering');
$this->load->model('Catering_model');
$this->load->model('Sms_model');
$this->load->model('Customer');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_catering_headers());
$this->load->view('catering/manage',$data);
}
public function date_difference(){
$from_date = date("Y-m-d", strtotime($this->input->post('from_date')));
$to_date = date("Y-m-d", strtotime($this->input->post('to_date')));
$diff = abs(strtotime($to_date) - strtotime($from_date));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$days = $days +1;
echo "$days";
}
public function search(){
$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');
$filters = array('start_date' => $this->input->get('start_date'),'end_date' => $this->input->get('end_date'));
//print_r($filters);
/*
$filledup = array_fill_keys($this->input->get('filters'), TRUE);
$filters = array_merge($filters, $filledup);
*/
$catering=$this->Catering_model->search($search,$filters,$limit,$offset,$sort,$order);
$TotalRows=$this->Catering_model->get_found_rows($search,$filters);
$DataRows=array();
foreach ($catering->result() as $person){
$DataRows[]=get_catering_datarows($person,$this);
}
$DataRows=$this->xss_clean($DataRows);
echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
}
public function view($cat_out_id=-1){
$info=$this->Catering_model->get_info($cat_out_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['catering']=$info;
$getcust = $data['catering'];
$cust_id = $getcust->cust_id;
$cust_info=$this->Catering_model->get_customer($cust_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['cust_info']=$cust_info;
$state_info[""] = "--Select State--";
foreach($this->Catering_model->get_state()->result_array() as $row){
$state_info[$this->xss_clean($row['state_code'])] = $this->xss_clean($row['state_name']);
}
$data['state_info'] = $state_info;
$booking_type[""] = "--Select Customer Type--";
foreach($this->Catering_model->get_booking_type()->result_array() as $row){
$booking_type[$this->xss_clean($row['booking_type_id'])] = $this->xss_clean($row['booking_type_name']);
}
$data['booking_type'] = $booking_type;
$catering_team[""] = "--Select Catering Team--";
foreach($this->Catering_model->get_catering_team() as $row){
$catering_team[$this->xss_clean($row->id)] = $this->xss_clean($row->first_name);
}
$data['catering_team'] = $catering_team;
$this->load->view("catering/form",$data);
}
public function balance_log($cat_out_id){
$info=$this->Catering_model->get_info($cat_out_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['catering_info']=$info;
$data['balance_info'] = $this->Catering_model->balance_log_list($cat_out_id);
$this->load->view("catering/balance_form",$data);
}
public function save_balance_log($cat_out_id){
$cat_bal_log_id = $this->input->post('cat_bal_log_id');
$balance_data = array(
'cat_out_id' => $this->input->post('cat_out_id'),
'balance_date' => date('Y-m-d',strtotime($this->input->post('balance_date'))),
'amount' => $this->input->post('amount'),
'remarks' => $this->input->post('remarks'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d H:i:s"),
);
if($this->Catering_model->save_balance_log($balance_data,$cat_bal_log_id)){
$balance_info = $this->Catering_model->balance_log_list($cat_out_id);
echo json_encode(array('success' => TRUE, 'balance_info' =>$balance_info));
}else{
echo "Unable process your request";
}
}
public function get_balance_log(){
$cat_bal_log_id = $this->input->post('cat_bal_log_id');
$balance_info = $this->Catering_model->get_balance_log($cat_bal_log_id);
echo json_encode(array('success' => TRUE, 'balance_info' => $balance_info));
}
public function catering_info($cat_out_id){
$info=$this->Catering_model->get_info($cat_out_id);
foreach (get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['catering_info']=$info;
$catering_menu[""] = "--Select Menu--";
foreach($this->Catering_model->get_catering_menu()->result_array() as $row){
$catering_menu[$this->xss_clean($row['catering_menu_id'])] = $this->xss_clean($row['name']);
}
$data['catering_menu'] = $catering_menu;
$data['catering_order'] = $this->Catering_model->get_catering_order($cat_out_id);
$this->load->view("catering/catering_form",$data);
}
public function get_order(){
$out_line_id = $this->input->post('out_line_id');
$order_info = $this->Catering_model->get_order($out_line_id);
echo json_encode(array('success' => TRUE, 'order_info' => $order_info));
}
public function save($cat_out_id = -1){
$mobile = $this->input->post('phone_number');
$customer_data = array(
'customer_name' => $this->input->post('customer_name'),
'phone_number' => $this->input->post('phone_number'),
'alt_number' => $this->input->post('alt_number'),
'land_line' => $this->input->post('land_line'),
'cust_email' => $this->input->post('email'),
'cust_address' => $this->input->post('cust_address'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'dob' => date('Y-m-d',strtotime($this->input->post('dob'))),
'referral_type' => $this->input->post('referral_type'),
'allow_contract' => $this->input->post('allow_contract'),
'cust_sts' => $this->input->post('cust_sts'),
'cust_zone' => $this->input->post('cust_zone'),
'csut_gst' => $this->input->post('csut_gst'),
'csut_pan' => $this->input->post('csut_pan'),
'includ_gst' => $this->input->post('includ_gst')
);
$cust_id = $this->Customer->lead_save_customer($customer_data, $mobile);
$catering_data = array(
'cat_out_id' => $this->input->post('cat_out_id'),
'cust_id' => $cust_id,
'cust_type' => $this->input->post('cust_type'),
'catering_type' => $this->input->post('catering_type'),
'from_date' => date('Y-m-d',strtotime($this->input->post('from_date'))),
'to_date' => date('Y-m-d',strtotime($this->input->post('to_date'))),
'days_count' => $this->input->post('days_count'),
'reporting_time' => $this->input->post('reporting_time'),
'billing_name' => $this->input->post('billing_name'),
'report_address' => $this->input->post('report_address'),
'fucntion_place' => $this->input->post('fucntion_place'),
'fucntion_name' => $this->input->post('fucntion_name'),
'tax_precentage' => $this->input->post('tax_precentage'),
'pax' => $this->input->post('pax'),
'catering_sts' => $this->input->post('catering_sts'),
'service' => $this->input->post('service'),
'delivery' => $this->input->post('delivery'),
'catering_team' => $this->input->post('catering_team'),
'catreing_information' => $this->input->post('catreing_information'),
'special_information' => $this->input->post('special_information'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d H:i:s"),
);
if($this->input->post('catering_type') === "1"){
$catering_data['catering_amount'] = $this->input->post('catering_amount');
}
if($this->Catering_model->save_catering($catering_data, $cat_out_id)){
$catering_data = $this->xss_clean($catering_data);
if($cat_out_id == -1){
$cat_out_id = $catering_data['cat_out_id'];
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('catering_successful_adding').' '. $catering_data['catering_name'], 'id' => $catering_data['cat_out_id']));
}else {
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('catering_successful_updating').' '. $catering_data['catering_name'], 'id' => $cat_out_id));
}
// SEND SMS
if($this->input->post('catering_sts') === "Enquiry"){
if($mobile){
$this->Sms_model->send_sms($cat_out_id,$mobile,"catering_enquiry");
}
}else
if($this->input->post('catering_sts') === "Confirm"){
if($mobile){
$this->Sms_model->send_sms($cat_out_id,$mobile,"catering_confirm");
}
}else
if($this->input->post('catering_sts') === "Cancelled"){
if($mobile){
$this->Sms_model->send_sms($cat_out_id,$mobile,"catering_cancelled");
}
}
}else{
$catering_data = $this->xss_clean($catering_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('catering_error_adding_updating').' '. $catering_data['catering_name'], 'id' => -1));
}
}
public function get_row($order_ids){
$catering_infos = $this->Catering_model->get_multiple_info($order_ids);
$result = array();
foreach($catering_infos as $item_info){
$result[$item_info->cat_out_id] = $this->xss_clean(get_item_data_row($item_info, $this));
}
echo json_encode($result);
}
public function suggest_customer(){
$suggestions = $this->xss_clean($this->Catering_model->get_customer_suggestions($this->input->post('term')));
echo json_encode(array('success' => TRUE, 'search' => $suggestions));
}
public function get_customer(){
$suggestions = $this->xss_clean($this->Catering_model->get_customer_info($this->input->post('term')));
echo json_encode(array('success' => TRUE, 'search' => $suggestions));
}
public function get_menu(){
$menu_id = $this->input->post('menu_id');
$menu = $this->Catering_model->get_menu($menu_id);
echo json_encode(array('success' => TRUE, 'menu_list' => $menu));
}
public function catering_add(){
$date = date('Y-m-d',strtotime($this->input->post('date')));
$cat_out_id = $this->input->post('cat_out_id');
$catering_data = array(
'cat_out_id' => $this->input->post('cat_out_id'),
'order_date' => date('Y-m-d',strtotime($this->input->post('date'))),
'break_fast' => $this->input->post('break_fast'),
'break_fast_menu' => $this->input->post('bf_menu'),
'bf_count' => $this->input->post('bf_count'),
'bf_amount' => $this->input->post('bf_amount'),
'lunch' => $this->input->post('lunch'),
'lunch_menu' => $this->input->post('lunch_menu'),
'lunch_count' => $this->input->post('lunch_count'),
'lunch_amount' => $this->input->post('lunch_amount'),
'dinner' => $this->input->post('dinner'),
'dinner_menu' => $this->input->post('dinner_menu'),
'dinner_count' => $this->input->post('dinner_count'),
'dinner_amount' => $this->input->post('dinner_amount'),
'amount' => $this->input->post('amount'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d H:i:s"),
);
if($this->Catering_model->catering_line_save($catering_data,$cat_out_id, $date)){
$catering_order = $this->Catering_model->get_catering_order($cat_out_id);
echo json_encode(array('success' => TRUE, 'catering_order' =>$catering_order));
}else{
echo "Unable process your request";
}
}
public function print_catering($cat_out_id){
$data = $this->_load_catering_data($cat_out_id);
$this->load->view('catering/print_catering',$data);
}
private function _load_catering_data($cat_out_id){
$data['catering_info'] = $this->Catering_model->get_load_data($cat_out_id);
$data['catering_order'] = $this->Catering_model->get_catering_order($cat_out_id);
$data['bal_log_amount'] = $this->Catering_model->get_bal_log_amount($cat_out_id);
return $data;
}
public function delete(){
$catering_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->Catering_model->delete_list($catering_to_delete)){
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('catering_successful_deleted').' '. count($catering_to_delete).' '.$this->lang->line('catering_one_or_multiple')));
}else{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('catering_cannot_be_deleted')));
}
}
}
?>