public function showRestaurantsOrders()
 {
     if (!Backend::validateUser()) {
         return redirect('/');
     }
     $aSession = \Session::all();
     $aOrdersList = DB::table('orders')->where(array('id_restaurant' => $aSession['id_user']))->WhereNotIn('status', array('DONE'))->orderBy('date_inserted', 'desc')->get(array('*'));
     $aTmpOrder = array();
     $dTotalPrice = 0;
     $aOrders = array();
     foreach ($aOrdersList as $oOrder) {
         $aTmpOrder['customer'] = DB::table('users')->where(array('id_user' => $oOrder->id_user))->get(array('first_name', 'last_name', 'user_mobile', 'username', 'email'))[0];
         $oOrderDetails = json_decode($oOrder->order_details);
         $oOrder->order_details = $this->parseOrderDetails($oOrderDetails);
         $oOrder->status = str_replace('_', ' ', $oOrder->status);
         $oLocation = json_decode($oOrder->location);
         if (!empty($oLocation->lat)) {
             $aTmpOrder['location'] = "http://maps.google.com/maps?q={$oLocation->lat},{$oLocation->long}";
         }
         $aTmpOrder['info'] = $oOrder;
         $dTotalPrice += $oOrderDetails->total_price;
         $oOrder->date_inserted = Backend::ago(new \DateTime($oOrder->date_inserted));
         $aOrders[] = $aTmpOrder;
         $aTmpOrder = [];
     }
     $data = Backend::LoginData();
     $data['isRestaurant'] = true;
     $data['status'] = array('preparing', 'canceled', 'not approved yet', 'on the way');
     return view('pages.orders')->with(array('orders' => $aOrders, 'data' => $data));
 }
 public function checkout()
 {
     //Check if user is logged in
     if (!Backend::validateUser()) {
         return redirect('/');
     }
     $aRequest = \Request::all();
     //This is a temprory array that will be used to create a temp item to be used in saved and any processing on item before saving it.
     $tempItem = array();
     if (!isset($aRequest['items'])) {
         return;
     }
     /*
      * Total price will be saved here,
      * this also will be used to indicate the last price that will be required on each restaurant
      */
     foreach ($aRequest['items'] as $item) {
         $dTotalPrice = 0;
         $oItem = DB::table('food')->where(array('id_item' => $item['id_item']))->get(array("id_restaurant", "price"))[0];
         $tempItem['id_item'] = $item['id_item'];
         $tempItem['qty'] = $item['qty'];
         $tempItem['spicy'] = $item['spicy'];
         //$tempItem['note']=$item['note'];
         $tempItem['total_price'] = $oItem->price * $item['qty'];
         $dTotalPrice += $tempItem['total_price'];
         $aRestaurants[$oItem->id_restaurant]['total_price'] = $dTotalPrice;
         $aRestaurants[$oItem->id_restaurant]['items'][] = $tempItem;
         $tempItem = array();
     }
     $sNote = $aRequest['note'];
     $sLocation = json_encode($aRequest['location']);
     foreach ($aRestaurants as $id_restaurant => $aRestaurant) {
         $id_user = \Session::all()['id_user'];
         $sOrderDetails = json_encode($aRestaurant);
         $aOrder = array('id_user' => $id_user, 'id_restaurant' => $id_restaurant, 'order_details' => $sOrderDetails, 'note' => $sNote, 'location' => $sLocation, 'date_inserted' => Date('Y-m-d h:i:s'), 'status' => 'not_approved_yet');
         DB::table('orders')->insert($aOrder);
     }
     \Session::forget('cart');
     return redirect('/');
 }
 public function login()
 {
     //Check if the user is authorized to be on the login page
     if (Backend::validateUser()) {
         /*
          * User here is not authorized,
          * redirect user to homepage.
          */
         return redirect('/');
     }
     /*
      * User is authorized
      */
     return view("pages.login");
 }