public static function queueStatus($transaction_number) { $number = TerminalTransaction::where('transaction_number', '=', $transaction_number)->first(); $called = $number->time_called != 0 ? TRUE : FALSE; $served = $number->time_completed != 0 ? TRUE : FALSE; $removed = $number->time_removed != 0 ? TRUE : FALSE; if (!$called && !$removed) { return 'Queueing'; } else { if ($called && !$served && !$removed) { return 'Called'; } else { if ($called && !$served && $removed) { return 'Dropped'; } else { if (!$called && $removed) { return 'Removed'; } else { if ($called && $served) { return 'Served'; } else { return 'Error'; } } } } } }
public static function sendNumberNextAndroid($transaction_number, $diff) { $priority_queue = PriorityQueue::find($transaction_number); if ($priority_queue) { $user_id = $priority_queue->user_id; $priority_number = $priority_queue->priority_number; $queue_platform = $priority_queue->queue_platform; $email = $priority_queue->email; $terminal_id = TerminalTransaction::terminalId($transaction_number); $terminal_name = $terminal_id != 0 ? Terminal::name($terminal_id) : ''; $business_id = $terminal_id != 0 ? Business::getBusinessIdByTerminalId($terminal_id) : 0; $business_name = $business_id != 0 ? Business::name($business_id) : ''; $waiting_time = Analytics::getWaitingTime($business_id); $estimated_time = Helper::millisecondsToHMSFormat($waiting_time); $message = "Your number ({$priority_number}) will be called in approximately {$estimated_time}. "; if ($diff == 1) { $message .= "There is currently {$diff} person ahead of you at the {$terminal_name} at {$business_name}."; } else { $message .= "There are currently {$diff} people ahead of you at the {$terminal_name} at {$business_name}."; } if ($queue_platform != 'web' && $queue_platform != 'specific') { $gcm_token = User::gcmToken($user_id); if ($gcm_token) { Notifier::sendAndroid($gcm_token, $message); } } else { if (($queue_platform == 'web' || $queue_platform == 'specific') && $email != null) { $user = User::searchByEmail($email); $gcm_token = $user ? User::gcmToken($user['user_id']) : null; if ($gcm_token) { Notifier::sendAndroid($gcm_token, $message); } } } } }
public static function getActiveBusinesses() { /* return DB::table('business')->join('branch', 'business.business_id', '=', 'branch.business_id') ->join('service', 'branch.branch_id', '=', 'service.branch_id') ->join('priority_number', 'service.service_id', '=', 'priority_number.service_id') ->join('priority_queue', 'priority_number.track_id', '=', 'priority_queue.track_id') ->join('terminal_transaction', 'priority_queue.transaction_number', '=', 'terminal_transaction.transaction_number') ->where('terminal_transaction.time_queued', '!=', 0) ->select(array('business.business_id', 'business.name', 'business.local_address')) ->get(); */ $active_businesses = array(); $businesses = Business::all(); foreach ($businesses as $count => $business) { $branches = Branch::getBranchesByBusinessId($business->business_id); foreach ($branches as $count2 => $branch) { $services = Service::getServicesByBranchId($branch->branch_id); foreach ($services as $count3 => $service) { $priority_numbers = PriorityNumber::getTrackIdByServiceId($service->service_id); foreach ($priority_numbers as $count4 => $priority_number) { $priority_queues = PriorityQueue::getTransactionNumberByTrackId($priority_number->track_id); foreach ($priority_queues as $count5 => $priority_queue) { $terminal_transactions = TerminalTransaction::getTimesByTransactionNumber($priority_queue->transaction_number); foreach ($terminal_transactions as $count6 => $terminal_transaction) { $grace_period = time() - $terminal_transaction->time_queued; // issued time must be on the current day to count as active if ($terminal_transaction->time_queued != 0 && $terminal_transaction->time_completed == 0 && $terminal_transaction->time_removed == 0 && $grace_period < 86400) { // 1 day; 60secs * 60 min * 24 hours $active_businesses[$business->business_id] = array('local_address' => $business->local_address, 'name' => $business->name); break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } if (array_key_exists($business->business_id, $active_businesses)) { break; } } } return $active_businesses; }