public function setOutlet() { $this->Fo_log('INFO', 'ENTER setOutlet', $this->basic_context()); $outlet_id = intval($this->input->post('outlet_id') ?? 0); if ($outlet_id <= 0) { $this->Fo_log('INFO', 'setOutlet: invalid_outlet', ['post' => $_POST]); echo json_encode(['status' => false, 'msg' => 'Invalid outlet']); return; } // verify outlet exists and fetch company_id $row = $this->db->select('company_id')->get_where('tbl_outlets', ['id' => $outlet_id, 'del_status' => 'Live'])->row(); if (!$row) { $this->Fo_log('INFO', 'setOutlet: outlet_not_found', ['outlet_id' => $outlet_id]); echo json_encode(['status' => false, 'msg' => 'Outlet not found']); return; } $this->session->set_userdata('booking_outlet_id', $outlet_id); $this->session->set_userdata('booking_company_id', intval($row->company_id)); $this->Fo_log('INFO', 'setOutlet: session_updated', ['company_id' => $row->booking_company_id, 'booking_outlet_id' => $outlet_id]); echo json_encode(['status' => true]); } //public function food_ordering_with_menu($company_id = null, $outlet_id = null) /* ============================ Helper / Logging utilities ============================ */ public function set_visit_date() { // Always force today (server authority) $today = date('Y-m-d'); $this->session->set_userdata('menu_selected_date', $today); echo json_encode(['status' => true, 'date' => $today]); } public function getCart() { $this->Fo_log('INFO', 'ENTER getCart', $this->basic_context()); $current_outlet = (int) $this->session->userdata('booking_outlet_id'); $cart_outlet = (int) $this->session->userdata('cart_outlet_id'); $current_date = $this->session->userdata('menu_selected_date'); $cart_date = $this->session->userdata('cart_menu_date'); /* ------------------------------------------------- Enforce outlet consistency ------------------------------------------------- */ if ($cart_outlet && $current_outlet && $cart_outlet !== $current_outlet) { $this->session->unset_userdata([ 'menu_cart', 'cart_outlet_id', 'cart_menu_date' ]); echo json_encode(['cart'=>[]]); return; } /* ------------------------------------------------- Enforce date consistency ------------------------------------------------- */ if ($cart_date && $current_date && $cart_date !== $current_date) { $this->session->unset_userdata([ 'menu_cart', 'cart_outlet_id', 'cart_menu_date' ]); echo json_encode(['cart'=>[]]); return; } $cart = $this->session->userdata('menu_cart') ?: []; echo json_encode(['cart'=>$cart]); } private function calculatePriceWithTax($price, $tax_json, $is_inclusive) { $price = (float) $price; $taxes = []; $total_tax = 0; $base_price = $price; if (!$tax_json) { return [ 'base_price' => round($price,2), 'taxes' => [], 'tax_total' => 0, 'final_price'=> round($price,2) ]; } $tax_arr = is_string($tax_json) ? json_decode($tax_json, true) : $tax_json; if (!is_array($tax_arr)) $tax_arr = []; $total_rate = 0; foreach ($tax_arr as $t) { $total_rate += (float) ($t['tax_field_percentage'] ?? 0); } if ($is_inclusive && $total_rate > 0) { // price includes tax → extract base $base_price = $price / (1 + ($total_rate / 100)); } foreach ($tax_arr as $t) { $rate = (float) ($t['tax_field_percentage'] ?? 0); if ($rate <= 0) continue; $tax_amount = $base_price * ($rate / 100); $taxes[] = [ 'name' => $t['tax_field_name'] ?? 'Tax', 'rate' => $rate, 'amount' => round($tax_amount, 2) ]; $total_tax += $tax_amount; } if (!$is_inclusive) { $final_price = $base_price + $total_tax; } else { $final_price = $price; } return [ 'base_price' => round($base_price,2), 'taxes' => $taxes, 'tax_total' => round($total_tax,2), 'final_price' => round($final_price,2) ]; } private function tryRequireAutoload() { // Attempt to require a common autoload (optional, not required) $possible = [ APPPATH . 'vendor/autoload.php', FCPATH . 'vendor/autoload.php', APPPATH . '../vendor/autoload.php' ]; foreach ($possible as $p) { if (file_exists($p)) { $this->autoload_path = $p; require_once $p; return true; } } return false; } public function get_companies() { $this->Fo_log('INFO', 'ENTER get_companies', $this->basic_context()); $rows = $this->db->select('id,business_name') ->get_where('tbl_companies', ['del_status' => 'Live']) ->result(); $this->Fo_log('INFO', 'get_companies: count', ['count' => count($rows)]); echo json_encode($rows); } public function get_outlets_by_company($portal = 'food_ordering') { $this->Fo_log('INFO', 'ENTER get_outlets_by_company', $this->basic_context()); $company_id = (int) ($this->input->post('company_id') ?? 0); if (!$company_id) { echo json_encode([]); return; } $rows = $this->db ->select('o.id, o.outlet_name, o.address') ->from('tbl_outlets o') ->join( 'online_outlet_config oc', 'oc.outlet_id = o.id', 'inner' ) ->where([ 'o.company_id' => $company_id, 'o.del_status' => 'Live', 'oc.portal_type' => $portal, 'oc.is_delivering' => 1 ]) ->group_by('o.id') ->order_by('o.outlet_name', 'ASC') ->get() ->result(); $this->Fo_log('INFO', 'get_outlets_by_company: filtered result', [ 'company_id' => $company_id, 'portal' => $portal, 'count' => count($rows) ]); echo json_encode($rows); } private function isOutletAcceptingOrders($outlet_id, $portal = 'food_ordering') { return (bool) $this->db->get_where('online_outlet_config', [ 'outlet_id' => (int)$outlet_id, 'portal_type' => $portal, 'is_delivering' => 1, 'accepting_orders' => 'online' ])->row(); } private function validateOutletForCheckout() { $outlet_id = (int) $this->session->userdata('booking_outlet_id'); if (!$outlet_id) return false; return (bool) $this->db->get_where('online_outlet_config', [ 'outlet_id' => $outlet_id, 'portal_type' => 'food_ordering', 'is_delivering' => 1, 'accepting_orders' => 'online' ])->row(); } public function orders() { $this->requireCustomerLogin(); $customer_id = (int)$this->session->userdata("customer_id"); if (!$customer_id) redirect('login'); $this->load->model("Order_model"); // ---- ALL ORDERS ---- $data['orders'] = $this->Order_model->get_all_orders($customer_id); // ---- SELECTED ORDER ---- $order_id = (int)$this->input->get('order_id'); $data['order'] = null; $data['order_items'] = []; if ($order_id) { $order = $this->Order_model->get_order_detail($order_id, $customer_id); if ($order) { $data['order'] = $order; $data['order_items'] = $this->Order_model->get_order_items($order_id); } } // ---- CUSTOMER ---- $customer = $this->_get_customer($customer_id); $data['customer'] = $customer; // ---- DEFAULT ADDRESS ---- $addresses = $this->_getCustomerAddresses($customer); $default_row = null; if (!empty($addresses)) { foreach ($addresses as $a) { if ((int)$a->is_default === 1) { $default_row = $a; break; } } if (!$default_row) $default_row = $addresses[0]; } $data['default_address'] = $default_row ? ($default_row->address ?: '') : ($customer->address ?? ''); $data['main_content'] = $this->load->view( 'online_booking/order_food/orders_unified', $data, TRUE ); $this->load->view('online_booking/order_food/website_layout', $data); } public function order_status_json($order_id = 0) { $order_id = (int)$order_id; $customer_id = (int)$this->session->userdata('customer_id'); if (!$order_id || !$customer_id){ echo json_encode([]); return; } $this->load->model('Order_model'); $row = $this->Order_model->get_order_status_row($order_id, $customer_id); if (!$row){ echo json_encode([]); return; } echo json_encode([ 'order_status' => $row->order_status, 'self_order_status' => $row->self_order_status ]); } public function order_details($order_id = 0) { $this->requireCustomerLogin(); $order_id = (int)$order_id; if (!$order_id) show_404(); $customer_id = (int)$this->session->userdata("customer_id"); if (!$customer_id) redirect('login'); $this->load->model("Order_model"); $order = $this->Order_model->get_order_detail($order_id, $customer_id); if (!$order) show_404(); $data['order'] = $order; $data['order_items'] = $this->Order_model->get_order_items($order_id); $data['main_content'] = $this->load->view( 'online_booking/order_food/order_details_page', $data, TRUE ); $this->load->view('online_booking/order_food/website_layout', $data); } public function add_kitchen_sale_by_ajax() { log_message("info", "=== ENTER add_kitchen_sale_by_ajax() ==="); /* ================= SESSION ================= */ $company_id = intval($this->session->userdata("company_id")); $outlet_id = intval($this->session->userdata("outlet_id")); if (!$company_id || !$outlet_id) { log_message("error", "[KitchenAjax] Missing outlet/company in session"); echo json_encode(['status' => false, 'msg' => 'Session expired']); return; } /* ================= INPUT ================= */ $orderJson = $this->input->post('order'); $payment_method = $this->input->post('payment_method'); log_message("info", "[KitchenAjax] ORDER JSON: " . $orderJson); $order_details = json_decode($orderJson); if (!$order_details || !is_object($order_details)) { log_message("error", "[KitchenAjax] JSON decode failed"); echo json_encode(['status' => false, 'msg' => 'Invalid order JSON']); return; } /* ================= NORMALIZE ================= */ $order_details->counter_id = $order_details->counter_id ?? 0; $order_details->charge_type = 'Online'; $order_details->rounding_amount_hidden = 0; $order_details->open_invoice_date_hidden = date('Y-m-d'); $totalQty = 0; foreach ($order_details->items as $i) { $totalQty += intval($i->qty ?? 0); } $order_details->total_items_in_cart = $totalQty; foreach ($order_details->items as &$it) { $qty = floatval($it->qty ?? 0); $unit = floatval($it->menu_unit_price ?? 0); $line = round($qty * $unit, 2); $it->line_total = $line; $it->menu_price_with_discount = $line; $it->menu_price_without_discount = $line; $it->menu_discount_value = 0; $it->discount_type = 'fixed'; $it->item_discount_amount = 0; $it->item_vat = []; } unset($it); $order_details->outlet_id = $outlet_id; /* ================= DELIVERY ADDRESS ================= */ $del_address = ''; if (!empty($order_details->customer_address_id)) { $addr = $this->db->where('id', $order_details->customer_address_id) ->get('tbl_customer_address')->row(); if ($addr) { $del_address = trim($addr->label . ' — ' . $addr->address); } } /* ================= HEADER DATA ================= */ $data = []; $data['customer_id'] = intval($order_details->customer_id); $data['counter_id'] = 0; $data['is_online_order'] = "Yes"; $data['is_self_order'] = "No"; $data['is_accept'] = 2; $data['online_order_receiving_id'] = getOnlineOrderReceivingId($outlet_id); $data['del_address'] = $del_address; $data['total_items'] = $order_details->total_items_in_cart; $data['sub_total'] = $order_details->sub_total; $data['vat'] = $order_details->total_vat; // ✅ PAID ORDER LOGIC $paid_amount = floatval($order_details->total_payable); $data['total_payable'] = 0; $data['due_amount'] = 0; $data['paid_amount'] = $paid_amount; $data['delivery_charge'] = 0; $data['waiter_id'] = 0; $data['outlet_id'] = $outlet_id; $data['company_id'] = $company_id; $data['sale_date'] = date('Y-m-d'); $data['date_time'] = date('Y-m-d H:i:s'); $data['order_time'] = date('H:i:s'); $data['order_status'] = 2; $data['order_type'] = 3; $data['sale_no'] = $order_details->sale_no; $data['is_pickup_sale'] = 1; $data['del_status'] = 'Live'; /* ================= TAX BUILD ================= */ $saleVatMap = []; foreach ($order_details->items as &$it) { $menu = $this->db->select('tax_information') ->where('id', $it->food_menu_id) ->get('tbl_food_menus')->row(); $vatArr = []; $qty = floatval($it->qty); $unit = floatval($it->menu_unit_price); if ($menu && !empty($menu->tax_information)) { $taxes = json_decode($menu->tax_information); foreach ($taxes as $tx) { $percent = floatval($tx->tax_field_percentage); if ($percent <= 0) continue; $unit_tax = round(($unit * $percent) / 100, 2); $all_tax = round($unit_tax * $qty, 2); $vatArr[] = [ 'tax_field_id' => $tx->tax_field_id ?? 1, 'tax_field_company_id' => $company_id, 'tax_field_name' => $tx->tax_field_name, 'tax_field_percentage' => (string)$percent, 'item_vat_amount_for_unit_item' => number_format($unit_tax,2,'.',''), 'item_vat_amount_for_all_quantity' => number_format($all_tax,2,'.',''), ]; if (!isset($saleVatMap[$tx->tax_field_name])) { $saleVatMap[$tx->tax_field_name] = 0; } $saleVatMap[$tx->tax_field_name] += $all_tax; } } $it->item_vat = $vatArr; } unset($it); $sale_vat_objects = []; $total_vat = 0; foreach ($saleVatMap as $type => $amt) { $sale_vat_objects[] = [ 'tax_field_id' => 1, 'tax_field_type' => $type, 'tax_field_amount' => number_format($amt,2,'.','') ]; $total_vat += $amt; } $data['sale_vat_objects'] = json_encode($sale_vat_objects); $data['vat'] = number_format($total_vat,2,'.',''); $data['self_order_content'] = json_encode($order_details, JSON_UNESCAPED_UNICODE); /* ================= DB ================= */ $this->db->trans_begin(); $this->db->insert('tbl_kitchen_sales', $data); $sale_id = $this->db->insert_id(); foreach ($order_details->items as $item) { $lineTotal = round($item->menu_unit_price * $item->qty, 2); $item_data = [ 'food_menu_id' => $item->food_menu_id, 'menu_name' => $item->menu_name, 'qty' => $item->qty, 'tmp_qty' => $item->qty, 'menu_unit_price' => $item->menu_unit_price, 'menu_price_without_discount' => $lineTotal, 'menu_price_with_discount' => $lineTotal, 'menu_taxes' => json_encode($item->item_vat), 'menu_discount_value' => 0, 'discount_type' => 'fixed', 'discount_amount' => 0, 'item_type' => 'Kitchen Item', 'sales_id' => $sale_id, 'user_id' => 0, 'outlet_id' => $outlet_id, 'del_status' => 'Live', 'cooking_status' => 'New', 'cooking_start_time' => '0000-00-00 00:00:00', 'cooking_done_time' => '0000-00-00 00:00:00', 'previous_id' => 0 ]; $this->db->insert('tbl_kitchen_sales_details', $item_data); } $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { log_message("error", "[KitchenAjax] DB FAILED"); echo json_encode(['status' => false, 'msg' => 'DB transaction failed']); return; } /* ================= NOTIFY ================= */ $this->db->insert('tbl_notifications', [ 'notification' => "New order placed. Order No: ".$order_details->sale_no, 'sale_id' => $sale_id, 'waiter_id' => 0, 'outlet_id' => $outlet_id, 'push_status' => 1 ]); $this->db->insert('tbl_orders_table', [ 'persons' => 1, 'booking_time' => date('H:i'), 'sale_id' => $sale_id, 'sale_no' => $order_details->sale_no, 'outlet_id' => $outlet_id, 'table_id' => 0, 'del_status' => 'Live' ]); echo json_encode([ 'status' => true, 'order_id' => d($sale_id, 1) ]); } private function Fo_log($level = 'DEBUG', $title = '', $payload = []) { // ----------------------------- // Respect CI log_threshold // ----------------------------- $CI =& get_instance(); $threshold = $CI->config->item('log_threshold'); if (!$threshold || $threshold == 0) { return; // logging disabled } $level = strtoupper($level); // Map level to CI numeric severity $levelMap = [ 'ERROR' => 1, 'ERR' => 1, 'DEBUG' => 2, 'INFO' => 3, 'ALL' => 4 ]; $severity = $levelMap[$level] ?? 2; // If threshold does not allow this log → skip if ($threshold < $severity) { return; } // ----------------------------- // Build log message // ----------------------------- $date = date('Y-m-d H:i:s'); if (!is_array($payload)) { $payload = ['msg' => $payload]; } $message = sprintf( "[%s] %s - OFO::%s - %s\n", $date, $level, $title, json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ); // ----------------------------- // Write to custom file // ----------------------------- $logPath = APPPATH . 'logs/'; $file = $logPath . 'f_o_' . date('Y-m-d') . '.log'; if (!is_dir($logPath)) { return; } // Atomic append file_put_contents($file, $message, FILE_APPEND | LOCK_EX); } public function update_profile() { $customer_id = intval($this->session->userdata('customer_id') ?: 0); if (!$customer_id) { echo json_encode(['status' => false, 'msg' => 'Not logged in']); return; } $name = trim($this->input->post('name') ?? ''); $phone = trim($this->input->post('phone') ?? ''); $email = trim($this->input->post('email') ?? ''); if ($name === '' || $phone === '') { echo json_encode(['status' => false, 'msg' => 'Name & Mobile are required']); return; } $data = [ 'name' => $name, 'phone' => $phone, 'email' => $email, ]; $this->db->where('id', $customer_id)->update('tbl_customers', $data); if ($this->db->affected_rows() >= 0) { echo json_encode(['status' => true]); } else { echo json_encode(['status' => false, 'msg' => 'Nothing to update']); } } protected function _get_customer($id) { if (!$id) return null; return $this->db->get_where('tbl_customers', ['id' => $id])->row(); } public function apply_coupon() { $code = trim($this->input->post('code')); $sub_total = floatval($this->input->post('sub_total') ?: 0); if (!$code) { echo json_encode(['status'=>0, 'msg'=>'Enter coupon']); return; } // Example: Define coupons manually OR load from DB $coupons = [ 'SAVE10' => ['type'=>'percent', 'value'=>10], 'FLAT50' => ['type'=>'flat', 'value'=>50], ]; if (!isset($coupons[$code])) { echo json_encode(['status'=>0, 'msg'=>'Invalid or expired coupon']); return; } $c = $coupons[$code]; $discount = 0; if ($c['type'] === 'percent') { $discount = $sub_total * ($c['value'] / 100); } if ($c['type'] === 'flat') { $discount = $c['value']; } echo json_encode([ 'status' => 1, 'code' => $code, 'type' => $c['type'], 'value' => $c['value'], 'discount' => round($discount, 2) ]); } public function set_default_address() { $customer_id = (int) $this->session->userdata('customer_id'); $id = (int) $this->input->post('id'); if (!$customer_id || !$id) { echo json_encode(['status'=>false,'msg'=>'Invalid request']); return; } $this->db->trans_start(); $this->db->where([ 'id' => $id, 'customer_id' => $customer_id, 'del_status' => 'Live' ])->update('tbl_customer_address', [ 'is_default' => 1 ]); $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { echo json_encode(['status'=>false,'msg'=>'Unable to set default address']); return; } echo json_encode(['status'=>true]); } public function removeItem() { $this->requireCustomerLogin(); $index = intval($this->input->post('index')); $cart = $this->session->userdata('menu_cart') ?: []; if (!isset($cart[$index])) { echo json_encode(['status' => false, 'msg' => 'Invalid item index']); return; } unset($cart[$index]); $cart = array_values($cart); // reindex $this->session->set_userdata('menu_cart', $cart); $this->Fo_log('INFO', 'removeItem: removed', [ 'index_removed' => $index, 'cart_count' => count($cart) ]); echo json_encode(['status' => true, 'cart' => $cart]); } /* ============================ Session: set outlet (called by popup) - POST outlet_id - sets session outlet_id and company_id ============================ */ /* ============================ Addresses APIs - get_addresses : GET - save_address : POST (insert/update) - delete_address: POST (soft delete) ============================ */ public function get_addresses() { $this->Fo_log('INFO', 'ENTER get_addresses', $this->basic_context()); $customer_id = intval($this->session->userdata('customer_id') ?: 0); if (!$customer_id) { echo json_encode([]); return; } $custRow = $this->db->get_where('tbl_customers', ['id' => $customer_id])->row(); $addrs = $this->_getCustomerAddresses($custRow); // already filters del_status='Live' $out = []; foreach ($addrs as $r) { $out[] = [ 'id' => (int)$r->id, 'label' => $r->label, 'address' => $r->address, 'landmark' => $r->landmark, 'pincode' => $r->pincode, 'is_default' => (int)$r->is_default, 'is_active' => (int)$r->is_active, ]; } echo json_encode($out); } public function save_address() { $this->Fo_log('INFO', 'ENTER save_address', $this->basic_context()); $customer_id = intval($this->session->userdata('customer_id') ?: 0); if (!$customer_id) { echo json_encode(['status' => false, 'msg' => 'Not logged in']); return; } $id = intval($this->input->post('id') ?? 0); $label = trim($this->input->post('label') ?? ''); $address = trim($this->input->post('address') ?? ''); $landmark = trim($this->input->post('landmark') ?? ''); $pincode = trim($this->input->post('pincode') ?? ''); $is_default = intval($this->input->post('is_default') ? 1 : 0); if ($label === '' || $address === '') { echo json_encode(['status' => false, 'msg' => 'Label & address required']); return; } // Normalize label => Home / Office / Other $label_lc = strtolower($label); if (in_array($label_lc, ['home', 'house'])) { $label = 'Home'; } elseif (in_array($label_lc, ['office', 'work'])) { $label = 'Office'; } else { $label = 'Other'; } $this->db->trans_start(); if ($is_default) { // unset previous defaults $this->db->where('customer_id', $customer_id) ->update('tbl_customer_address', ['is_default' => 0]); } $data = [ 'customer_id' => $customer_id, 'label' => $label, 'address' => $address, 'landmark' => $landmark, 'pincode' => $pincode, 'is_default' => $is_default, 'is_active' => 1, 'del_status' => 'Live', ]; if ($id > 0) { // ensure the address belongs to this customer $this->db->where('id', $id) ->where('customer_id', $customer_id) ->update('tbl_customer_address', $data); $saved_id = $id; } else { $this->db->insert('tbl_customer_address', $data); $saved_id = $this->db->insert_id(); } $this->db->trans_complete(); if ($this->db->trans_status() === false) { $this->Fo_log('ERROR', 'save_address: db_trans_failed', $this->basic_context()); echo json_encode(['status' => false, 'msg' => 'DB error']); return; } $this->Fo_log('INFO', 'save_address: saved', ['saved_id' => $saved_id]); echo json_encode(['status' => true, 'id' => $saved_id]); } public function delete_address() { $this->Fo_log('INFO', 'ENTER delete_address', $this->basic_context()); $customer_id = intval($this->session->userdata('customer_id') ?: 0); if (!$customer_id) { echo json_encode(['status' => false, 'msg' => 'Not logged in']); return; } $id = intval($this->input->post('id') ?? 0); if ($id <= 0) { echo json_encode(['status' => false, 'msg' => 'Invalid id']); return; } $this->db->where('id', $id) ->where('customer_id', $customer_id) ->update('tbl_customer_address', [ 'del_status' => 'Deleted', 'is_default' => 0, 'is_active' => 0, ]); $this->Fo_log('INFO', 'delete_address: done', ['id' => $id]); echo json_encode(['status' => true]); } /* ============================ Private helpers ============================ */ /** * _getCustomerAddresses * - returns Live addresses for customer (and linked user_id) */ private function _getCustomerAddresses($customer) { $this->Fo_log('DEBUG', 'ENTER _getCustomerAddresses', [ 'customer_id' => $customer ? $customer->id : null ]); if (!$customer) { return []; } $candidates = [$customer->id]; if (!empty($customer->user_id) && $customer->user_id != $customer->id) { $candidates[] = $customer->user_id; } $candidates = array_map('intval', array_unique($candidates)); $this->db->where_in('customer_id', $candidates); $this->db->where('del_status', 'Live'); $result = $this->db->get('tbl_customer_address')->result(); $this->Fo_log('DEBUG', '_getCustomerAddresses: result', [ 'candidate_ids' => $candidates, 'count' => count($result) ]); return $result; } /* ============================ Razorpay ping (diagnostic) ============================ */ public function razorpay_ping() { try { $ch = curl_init("https://api.razorpay.com/v1/orders"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, $this->rzp_key_id . ":" . $this->rzp_key_secret); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); $response = curl_exec($ch); $error = curl_error($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $this->Fo_log('INFO', 'razorpay_ping', ['response' => $response, 'error' => $error, 'status' => $status]); header('Content-Type: text/plain'); echo "STATUS: $status\n"; echo "ERROR : $error\n"; echo "RESPONSE:\n$response\n"; } catch (Exception $e) { $this->Fo_log('ERROR', 'razorpay_ping: exception', ['err' => $e->getMessage()]); echo $e->getMessage(); } } public function get_foods_working_withoutDate($portal = 'food_ordering') { $this->Fo_log('INFO', 'ENTER get_foods', $this->basic_context()); $outlet_id = (int)$this->session->userdata('booking_outlet_id'); $company_id = (int)$this->session->userdata('booking_company_id'); if (!$outlet_id || !$company_id) { echo json_encode([]); return; } /* ------------------------------------------------- STEP 1: Validate outlet for portal ------------------------------------------------- */ $outlet_cfg = $this->db->get_where('online_outlet_config', [ 'outlet_id' => $outlet_id, 'portal_type' => $portal, 'is_delivering' => 1, 'accepting_orders' => 'online' ])->row(); if (!$outlet_cfg) { echo json_encode([]); return; } /* ------------------------------------------------- STEP 2: Outlet allowed foods Format: 1_ ------------------------------------------------- */ $outlet = $this->db ->select('available_online_foods') ->get_where('tbl_outlets', [ 'id' => $outlet_id, 'del_status' => 'Live' ]) ->row(); if (!$outlet || empty($outlet->available_online_foods)) { echo json_encode([]); return; } $allowed_food_ids = []; foreach (explode(',', $outlet->available_online_foods) as $v) { $v = trim($v); if ($v === '') continue; $parts = explode('_', $v); if (count($parts) !== 2) continue; if ((int)$parts[0] !== 1) continue; if (!ctype_digit($parts[1])) continue; $allowed_food_ids[] = (int)$parts[1]; } if (empty($allowed_food_ids)) { echo json_encode([]); return; } /* ------------------------------------------------- STEP 3: Fetch foods + categories + portal mapping ------------------------------------------------- */ /* ------------------------------------------------- STEP 3: Fetch parent foods + their variants ------------------------------------------------- */ // parent foods allowed by outlet $this->db->select('f.*, c.category_name'); $this->db->from('tbl_food_menus f'); $this->db->join('tbl_food_menu_categories c', 'c.id = f.category_id', 'inner'); $this->db->join( 'online_info_food_menu oif', 'oif.category_id = c.id AND oif.company_id = ' . (int)$company_id . ' AND oif.portal_type = ' . $this->db->escape($portal) . ' AND oif.is_enabled = 1', 'inner' ); $this->db->where([ 'f.del_status' => 'Live', 'c.del_status' => 'Live' ]); // IMPORTANT: parent foods OR their variants $this->db->group_start(); $this->db->where_in('f.id', $allowed_food_ids); // parents $this->db->or_where_in('f.parent_id', $allowed_food_ids); // variants $this->db->group_end(); $this->db->order_by('c.order_by ASC, f.parent_id ASC, f.name ASC'); $foods = $this->db->get()->result(); /* ------------------------------------------------- STEP 4: TAX MODE (inclusive / exclusive) ------------------------------------------------- */ $company = $this->db->select('tax_type') ->get_where('tbl_companies', ['id' => $company_id]) ->row(); $is_inclusive = ((int)($company->tax_type ?? 1) === 2); // 2 = inclusive /* ------------------------------------------------- STEP 5: TAX CALCULATION PER ITEM ------------------------------------------------- */ foreach ($foods as &$f) { // prefer delivery price if exists $price = (float) ($f->sale_price_delivery ?: $f->sale_price); $calc = $this->calculatePriceWithTax( $price, $f->tax_information, $is_inclusive ); // frontend fields $f->base_price = round($calc['base_price'], 2); $f->display_price = round($calc['final_price'], 2); $f->tax_total = round($calc['tax_total'], 2); $f->tax_breakup = $calc['taxes']; // normalize flags for JS $f->veg_item = (stripos($f->veg_item, 'veg') !== false) ? 1 : 0; $f->beverage_item = (stripos($f->beverage_item, 'bev') !== false) ? 1 : 0; } unset($f); echo json_encode($foods); } } 404 Page Not Found

404

Oops! Page Not Found

The page you're looking for doesn't exist or was moved.
Please check the URL or return to the dashboard.

← Back to Home