public function apply()
 {
     if (Session::has('user_id')) {
         if (Input::has('storeId')) {
             $storeId = Input::get('storeId');
             $userId = Session::get('user_id');
             $status = StatusModel::where('store_id', $storeId)->first();
             $myQueue = QueueModel::where('store_id', $storeId)->where('user_id', $userId)->where('queue_no', '>', $status->current_queue_no)->whereRaw('DATE(created_at) = DATE(NOW())')->count();
             if ($myQueue == 0) {
                 $queueNo = $status->last_queue_no;
                 $status->last_queue_no = $queueNo + 1;
                 $status->save();
                 $queue = new QueueModel();
                 $queue->store_id = $storeId;
                 $queue->user_id = $userId;
                 $queue->queue_no = $queueNo + 1;
                 $queue->save();
                 return Response::json(['result' => 'success', 'msg' => 'You have been successfully apply on this store']);
             } else {
                 return Response::json(['result' => 'failed', 'msg' => 'You have already apply on this store', 'code' => 'CD00']);
             }
         } else {
             return Response::json(['result' => 'failed', 'msg' => 'Invalid Request', 'code' => 'CD00']);
         }
     } else {
         return Response::json(['result' => 'failed', 'msg' => 'You must login for apply', 'code' => 'CD01']);
     }
 }
 public function detail($id)
 {
     $param['store'] = StoreModel::find($id);
     $param['servedCount'] = QueueModel::where('store_id', $id)->count();
     $userId = Session::has('user_id') ? Session::get('user_id') : 0;
     $queueNo = QueueModel::where('user_id', $userId)->where('store_id', $id)->whereRaw('DATE(created_at) = DATE(NOW())')->orderBy('created_at', 'DESC')->get();
     if (count($queueNo) > 0) {
         $queueNo = $queueNo[0]->queue_no;
     } else {
         $queueNo = null;
     }
     $param['queueNo'] = $queueNo;
     return View::make('user.store.detail')->with($param);
 }
 public function detail()
 {
     if (Input::has('store_id') && Input::has('user_id')) {
         $storeId = Input::get('store_id');
         $userId = Input::get('user_id');
         $store = StoreModel::find($storeId);
         $queueNo = QueueModel::where('user_id', $userId)->where('store_id', $storeId)->whereRaw('DATE(created_at) = DATE(NOW())')->orderBy('created_at', 'DESC')->get();
         if (count($queueNo) > 0) {
             $queueNo = $queueNo[0]->queue_no;
         } else {
             $queueNo = null;
         }
         return Response::json(['result' => 'success', 'msg' => '', 'store_name' => $store->name, 'company_name' => $store->company->name, 'company_logo' => HTTP_LOGO_PATH . $store->company->setting->logo, 'company_created_at' => $store->company->created_at->format('Y-m-d H:i:s'), 'estimated_waiting' => count($store->activeAgent) == 0 ? '---' : ceil(($store->status->last_queue_no - $store->status->current_queue_no) / count($store->activeAgent)) * ($store->company->setting->waiting_time / 60) . 'min', 'next_number' => $store->status->last_queue_no, 'description' => str_replace('src="/assets', 'src="' . HTTP_PATH . '/assets', $store->description), 'category_name' => $store->company->category->name, 'city_name' => $store->company->city->name, 'address' => $store->address, 'total_customers_served' => QueueModel::where('store_id', $storeId)->count(), 'current_number' => $store->status->current_queue_no, 'queue_no' => $queueNo]);
     } else {
         return Response::json(['result' => 'failed', 'msg' => 'Invalid Request']);
     }
 }