public function postPersonalizedBusinesses() { $processing = array(); $not_processing = array(); $post = json_decode(file_get_contents("php://input")); if ($post) { $user_timezone = isset($post->user_timezone) ? $post->user_timezone : 'Asia/Manila'; //ARA set user timezone if any if ($post->latitude && $post->longitude) { $res = Business::getBusinessByLatitudeLongitude($post->latitude, $post->longitude, $user_timezone); // get location first if (!count($res)) { $res = Business::all(); } } else { $res = Business::all(); } foreach ($res as $count => $data) { $first_service = Service::getFirstServiceOfBusiness($data->business_id); $all_numbers = ProcessQueue::allNumbers($first_service->service_id); $time_open = $data->open_hour . ':' . Helper::doubleZero($data->open_minute) . ' ' . strtoupper($data->open_ampm); $time_close = $data->close_hour . ':' . Helper::doubleZero($data->close_minute) . ' ' . strtoupper($data->close_ampm); // check if business is currently processing numbers if (Business::processingBusinessBool($data->business_id)) { if (Auth::check()) { $processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address, 'time_open' => Helper::changeBusinessTimeTimezone($time_open, $data->timezone, $user_timezone), 'time_close' => Helper::changeBusinessTimeTimezone($time_close, $data->timezone, $user_timezone), 'waiting_time' => Analytics::getWaitingTimeString($data->business_id), 'last_number_called' => count($all_numbers->called_numbers) > 0 ? $all_numbers->called_numbers[0]['priority_number'] : 'none', 'next_available_number' => $all_numbers->next_number, 'last_active' => Analytics::getLastActive($data->business_id), 'card_bool' => true); } else { $processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address); } } else { if (Auth::check()) { $not_processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address, 'time_open' => Helper::changeBusinessTimeTimezone($time_open, $data->timezone, $user_timezone), 'time_close' => Helper::changeBusinessTimeTimezone($time_close, $data->timezone, $user_timezone), 'waiting_time' => Analytics::getWaitingTimeString($data->business_id), 'last_number_called' => count($all_numbers->called_numbers) > 0 ? $all_numbers->called_numbers[0]['priority_number'] : 'none', 'next_available_number' => $all_numbers->next_number, 'last_active' => Analytics::getLastActive($data->business_id), 'card_bool' => false); } else { $not_processing[] = array('business_id' => $data->business_id, 'business_name' => $data->name, 'local_address' => $data->local_address); } } } $merged_businesses = array_merge($processing, $not_processing); if (Auth::check()) { // dashboard business boxes should be 8; known users will be redirected to dashboard $merged_businesses = array_slice($merged_businesses, 0, 8); } else { // homepage business boxes should be only 7 to give space for (more business) box; anon users will be redirected to homepage $merged_businesses = array_slice($merged_businesses, 0, 7); } return json_encode($merged_businesses); } }
/** * @author Ruffy * @param $query Query string input for searching for a businesses under an industry * @return JSON response containing businesses that qualified with the search query */ public function getSearchIndustry($query) { $search_results = DB::table('business')->where('industry', '=', $query)->select(array('business_id', 'name', 'local_address', 'latitude', 'longitude'))->get(); //ARA added info for businesses foreach ($search_results as $index => $business) { $first_service = Service::getFirstServiceOfBusiness($business->business_id); $all_numbers = ProcessQueue::allNumbers($first_service->service_id); $search_results[$index]->last_number_called = count($all_numbers->called_numbers) > 0 ? $all_numbers->called_numbers[0]['priority_number'] : 'none'; $search_results[$index]->next_available_number = $all_numbers->next_number; $search_results[$index]->active = count($all_numbers->called_numbers) + count($all_numbers->uncalled_numbers) + count($all_numbers->timebound_numbers) > 0 ? 1 : 0; } $found_business = array('search-result' => $search_results); return Response::json($found_business, 200, array(), JSON_PRETTY_PRINT); }
public static function processingBusinessBool($business_id) { /* $filepath = public_path() . '/json/' . $business_id . '.json'; $data = json_decode(file_get_contents($filepath)); if ($data->box1->number != '') { return TRUE; } elseif (isset($data->box2)) { if ($data->box2->number != '') { return TRUE; } } elseif (isset($data->box3)) { if ($data->box3->number != '') { return TRUE; } } elseif (isset($data->box4)) { if ($data->box4->number != '') { return TRUE; } } elseif (isset($data->box5)) { if ($data->box5->number != '') { return TRUE; } } elseif (isset($data->box6)) { if ($data->box6->number != '') { return TRUE; } } elseif ($data->get_num != '') { return TRUE; } return FALSE; */ // will be using Aunne's data from process queue to determine if the business is active or inactive $first_service = Service::getFirstServiceOfBusiness($business_id); $all_numbers = ProcessQueue::allNumbers($first_service->service_id); $is_calling = count($all_numbers->called_numbers) > 0 ? true : false; $is_issuing = count($all_numbers->uncalled_numbers) + count($all_numbers->timebound_numbers) > 0 ? true : false; return $is_calling || $is_issuing; }
public static function getServiceRemainingCount($service_id) { $all_numbers = ProcessQueue::allNumbers($service_id); return isset($all_numbers->uncalled_numbers) ? count($all_numbers->uncalled_numbers) : 0; }
public function getAllnumbers($service_id, $terminal_id) { $numbers = ProcessQueue::allNumbers($service_id, $terminal_id); ProcessQueue::updateBusinessBroadcast(Business::getBusinessIdByServiceId($service_id)); return json_encode(['success' => 1, 'numbers' => $numbers], JSON_PRETTY_PRINT); }