/** * This method loads the index page of the application * * @return html content */ public function index() { $this->load->model('user_model'); $this->load->model('shift_model'); $this->load->helper('my_helper'); /* store_view custom javascript */ $this->layout_lib->add_additional_js('/assets/js/views/dashboard.js'); $this->view_data['page_title'] = 'Dashboard'; $this->view_data['logged_in_user'] = $this->logged_in_user; $active_shifts = $this->shift_model->get_records(['end_date' => NULL]); $current_paid = 0; $current_unpaid = 0; foreach ($active_shifts as &$shift) { $shift->shift_orders(); $datatime_now = new DateTime('NOW', new DateTimeZone('UTC')); $shift->total_orders = count($shift->orders); $shift->unpaid_orders = 0; $shift->start_date = substr($shift->start_date, 11); $shift->time_worked = get_seconds_diff_from_dates($shift->start_date, $datatime_now->format('Y-m-d H:i:s')); foreach ($shift->orders as $key => $order) { if ($order->payment_status == 'unpaid' or $order->payment_status == 'pending') { $shift->unpaid_orders++; $current_unpaid += $order->calculate_total_cost(); } else { $current_paid += $order->calculate_total_cost(); } } $shift->completed_orders = $shift->total_orders - $shift->unpaid_orders; } $this->view_data['active_shifts'] = $active_shifts; $this->view_data['current_paid'] = $current_paid; $this->view_data['current_unpaid'] = $current_unpaid; $this->view_data['current_total'] = $current_unpaid + $current_paid; $this->layout_lib->load('store_layout_view', 'store/dashboard', $this->view_data); }
/** * This method fetches and calculates waiters shift info * * @return json object */ public function ajax_shift_info() { if ($this->input->is_ajax_request() and $this->input->method() == 'post') { $this->load->model('order_model'); $this->load->model('shift_model'); $this->load->helper('my_helper'); $user = $this->view_data['logged_in_user']; $shift = $this->shift_model->get_record(['user_record_id' => $user->record_id, 'end_date' => NULL]); $shift->shift_orders(); $datatime_now = new DateTime('NOW', new DateTimeZone('UTC')); $info['total_orders'] = count($shift->orders); $info['unpaid_orders'] = 0; $info['time_worked'] = get_seconds_diff_from_dates($shift->start_date, $datatime_now->format('Y-m-d H:i:s')); foreach ($shift->orders as $key => $order) { if ($order->payment_status == 'unpaid' or $order->payment_status == 'pending') { $info['unpaid_orders']++; } } echo json_encode($info); } }
/** * This method fetches and prepairs the data for the completed orders * The data is to be shown in datatable * * @return json encoded object of arrays */ public function datatable_completed_orders_data() { $this->load->model('order_model'); $this->load->helper('my_helper'); $data = array(); $orders = $this->order_model->get_all_records(['end_date IS NOT' => NULL, 'payment_status' => 'paid']); foreach ($orders as $order) { $order->store_table_info(); $order->user_info(); $diff = get_seconds_diff_from_dates($order->start_date, $order->end_date); array_push($data, [0 => $order->record_id, 1 => $order->store_table_info->caption, 2 => $order->user_info->lastname . ' ' . $order->user_info->firstname, 3 => $order->time_zone_greece($order->start_date, 'H:i:s'), 4 => $order->time_zone_greece($order->end_date, 'H:i:s'), 5 => seconds_to_time($diff), 6 => $order->calculate_total_cost(), 7 => '<a href="/orders/print_order_modal_form/' . $order->record_id . '" class="view-order btn btn-success btn-block" data-toggle="modal" data-target="#myModal"><i class="fa fa-print fa-fw fa-lg"></i>Εκτύπωση</a>']); } /* Create an object of arrays */ $obj = (object) array(); $obj->data = array_values($data); echo json_encode($obj); }