public function getUserDWBalance()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     if (Generic::IsNullOrEmptyString($_GET['id_user'])) {
         $results['balance'] = doubleval(0);
         Generic::finish($results);
     }
     $idUser = addslashes($_GET['id_user']);
     $user = new UserModel();
     $user->getByID($idUser);
     $results["pic"] = Generic::insertImageUrl($user->pic);
     $allowDokuWallet = Efiwebsetting::getData('App_Allow_Doku_Wallet') == 'yes';
     if (Generic::IsNullOrEmptyString($user->payment_id) || $user->payment_id == 0) {
         $results['balance'] = doubleval(0);
     } else {
         if ($allowDokuWallet) {
             $doku = new PaymentDoku();
             $results['balance'] = $doku->checkBalance($user->payment_id);
         } else {
             $results['balance'] = doubleval(0);
         }
     }
     Generic::finish($results);
 }
 public static function getMyPayment($idUser)
 {
     $allowCash = Efiwebsetting::getData('App_Allow_Cash') == 'yes';
     $allowDokuWallet = Efiwebsetting::getData('App_Allow_Doku_Wallet') == 'yes';
     $allowCreditCard = Efiwebsetting::getData('App_Allow_Credit_Card') == 'yes';
     $user = new UserModel();
     $user->getByID($idUser);
     if (Generic::IsNullOrEmptyString($user->id_user)) {
         Generic::errorMsg(Keys::$ERR_NOT_FOUND_USER);
     }
     $results['allow_cash'] = $allowCash;
     $results['allow_doku_wallet'] = $allowDokuWallet;
     $results['allow_credit_card'] = $allowCreditCard;
     if (Generic::IsNullOrEmptyString($user->payment_type)) {
         $user->payment_type = Keys::$PAYMENT_TYPE_CASH;
         $user->save();
     }
     $results['user'] = Util::extractModel($user, Helper::$columnReturnLogin);
     $results['payment_type'] = $user->payment_type;
     $results['has_doku_wallet'] = !Generic::IsNullOrEmptyString($user->payment_id);
     $results['has_credit_card'] = !Generic::IsNullOrEmptyString($user->payment_token);
     $results['doku_wallet']['balance'] = Keys::$EMPTY;
     $results['doku_wallet']['doku_id'] = Keys::$EMPTY;
     $results['credit_card']['payment_token'] = Keys::$EMPTY;
     //        $results['credit_card']['payment_id'] =  Keys::$EMPTY;
     $results['credit_card']['payment_bank'] = Keys::$EMPTY;
     $results['credit_card']['payment_mcn'] = Keys::$EMPTY;
     if ($allowDokuWallet) {
         $doku = new PaymentDoku();
         $results['doku_wallet']['status_init'] = $doku->STATUS_INIT;
         $results['doku_wallet']['doku_error'] = $doku->DOKU_ERROR;
         if ($doku->DOKU_ERROR) {
             $results['has_doku_wallet'] = false;
         }
         $results['doku_wallet']['balance'] = $doku->checkBalance($user->payment_id);
         $results['doku_wallet']['doku_id'] = $user->payment_id;
     }
     if ($allowCreditCard) {
         $results['credit_card']['payment_token'] = Generic::IsNullOrEmptyString($user->payment_token) ? "" : $user->payment_token;
         //        $results['credit_card']['payment_id'] = (Generic::IsNullOrEmptyString($user->payment_id)) ? "" : $user->payment_id;
         $results['credit_card']['payment_bank'] = Generic::IsNullOrEmptyString($user->payment_bank) ? "" : $user->payment_bank;
         $results['credit_card']['payment_mcn'] = Generic::IsNullOrEmptyString($user->payment_mcn) ? "" : $user->payment_mcn;
         $results['credit_card']['payment_bank_pic'] = Generic::insertImageUrl(Keys::$EMPTY);
     }
     return $results;
 }
 public static function getDish($id_dish)
 {
     $objDish = new MasterDishModel();
     $arrDish = $objDish->getWhere("id_dish='{$id_dish}'");
     $exp = explode(",", str_replace(" ", "", $objDish->crud_webservice_allowed));
     $arrPicsToAddPhotoUrl = $objDish->crud_add_photourl;
     $sem = array();
     foreach ($arrDish as $o) {
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = Generic::insertImageUrl($o->{$attr});
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
         }
     }
     return $sem;
 }
 public static function getRestaurant($restaurant_id)
 {
     $objRestaurant = new MasterRestaurantModel();
     $arr = $objRestaurant->getWhere("id_restaurant={$restaurant_id}");
     $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
     $arrPicsToAddPhotoUrl = $objRestaurant->crud_add_photourl;
     $sem = array();
     foreach ($arr as $o) {
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = Generic::insertImageUrl($o->{$attr});
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
             $sem['disc_mr'] = MasterOrder::getDiscountMR($restaurant_id);
         }
     }
     return $sem;
 }
 public function getHomeResults()
 {
     $idHome = Generic::mustCheck($_GET['id_home'], "ID Not Found");
     $currentLat = !Generic::IsNullOrEmptyString($_GET['latitude']) ? $_GET['latitude'] : "";
     $currentLong = !Generic::IsNullOrEmptyString($_GET['longitude']) ? $_GET['longitude'] : "";
     $home = new HomeModel();
     $home->getByID($idHome);
     if ($home->status != "1") {
         Generic::errorMsg("Not Active Home");
     }
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         Generic::errorMsg("No Page Found");
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         Generic::errorMsg("Limit Error");
     }
     $begin = ($page - 1) * $limit;
     $extraQ = " LIMIT {$begin},{$limit}";
     $key = "key";
     $results = array();
     $searchType = $home->search_type;
     $searchTerm = $home->search_term;
     $query = $home->query;
     switch ($searchType) {
         case "0":
             break;
         case "1":
             $resto = new MasterRestaurantModel();
             $results = $resto->getWhere("restaurant_type='{$searchTerm}' AND show_in_apps='1' ORDER BY fav DESC {$extraQ}");
             $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed));
             $arrPicsToAddPhotoUrl = $resto->crud_add_photourl;
             $key = "restaurant";
             break;
         case "2":
             $resto = new MasterRestaurantModel();
             $results = $resto->getWhere("FIND_IN_SET('{$searchTerm}', id_categories) AND show_in_apps='1' ORDER BY fav DESC {$extraQ}");
             $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed));
             $arrPicsToAddPhotoUrl = $resto->crud_add_photourl;
             $key = "restaurant";
             break;
         case "3":
             $resto = new MasterRestaurantModel();
             $results = $resto->getWhere("id_cuisine='{$searchTerm}' AND show_in_apps='1' ORDER BY fav DESC {$extraQ}");
             $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed));
             $arrPicsToAddPhotoUrl = $resto->crud_add_photourl;
             $key = "restaurant";
             break;
         case "4":
             $resto = new MasterRestaurantModel();
             $results = $resto->getWhere("name LIKE '%{$query}%' AND show_in_apps='1' ORDER BY fav DESC {$extraQ}");
             $exp = explode(",", str_replace(" ", "", $resto->crud_webservice_allowed));
             $arrPicsToAddPhotoUrl = $resto->crud_add_photourl;
             $key = "restaurant";
             break;
         case "5":
             $dish = new MasterDishModel();
             $results = $dish->getWhere("'{$searchTerm}' IN (dish_tags) ORDER BY id_dish DESC {$extraQ}");
             $exp = explode(",", str_replace(" ", "", $dish->crud_webservice_allowed));
             $arrPicsToAddPhotoUrl = $dish->crud_add_photourl;
             $key = "Dish";
             break;
         case "6":
             $dish = new MasterDishModel();
             $results = $dish->getWhere("name LIKE '%{$query}%' ORDER BY id_dish DESC {$extraQ}");
             $exp = explode(",", str_replace(" ", "", $dish->crud_webservice_allowed));
             $arrPicsToAddPhotoUrl = $dish->crud_add_photourl;
             $key = "Dish";
             break;
         case "8888":
             break;
         default:
             break;
     }
     $json["results"]["latitude"] = $currentLat;
     $json["results"]["longitude"] = $currentLong;
     $json["results"][$key] = array();
     foreach ($results as $o) {
         $sem = array();
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = Generic::insertImageUrl($o->{$attr});
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
         }
         if ($searchType == "5" || $searchType == "6") {
             $sem['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($o->id_restaurant);
         }
         if ($currentLat != "" && $currentLong != "") {
             $sem["distance"] = sqrt(pow(69.09999999999999 * ($o->latitude - $currentLat), 2) + pow(69.09999999999999 * ($currentLong - $o->longitude) * cos($o->latitude / 57.3), 2));
         } else {
             $sem["distance"] = 0;
         }
         //            $json["results"]["search_type"] = Generic::homeSearchType($searchType);
         $json["results"][$key][] = $sem;
     }
     $json['status_code'] = 1;
     echo json_encode($json);
     die;
 }
 public function loadHomeRecommendation()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         Generic::errorMsg("No Page Found");
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         Generic::errorMsg("Limit Error");
     }
     $begin = ($page - 1) * $limit;
     $json = array();
     $sem = array();
     $objRecommendation = new RecommendationModel();
     $exp = explode(",", str_replace(" ", "", $objRecommendation->crud_webservice_allowed));
     $arrPicsToAddPhotoUrl = $objRecommendation->crud_add_photourl;
     $arr = $objRecommendation->getWhere("DATE(end) >= DATE(NOW()) AND DATE(start)<= DATE(NOW())  LIMIT {$begin},{$limit}");
     if (count($arr) == 0) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $json["results"]['restaurant'] = array();
     foreach ($arr as $o) {
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = Generic::insertImageUrl($o->{$attr});
             } elseif ($attr == "time_open" || $attr == "time_close") {
                 $sem[$attr] = date('H:i', strtotime(stripslashes($o->{$attr})));
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
             $sem['disc_mr'] = MasterOrder::getDiscountMR($o->id_restaurant);
         }
         $sem['restaurant'] = User::getRestaurant($o->id_restaurant);
         $json["results"]['restaurant'][] = $sem;
     }
     echo json_encode($json);
     die;
 }
 public function getMyOrders()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idUser = Generic::mustCheck($_GET["id_user"], "ID User Not Found");
     $arrStatusOK = implode(',', Helper::getDefaultOrderStatusOK());
     $stPaymentUnpaid = Keys::$PAYMENT_STATUS_UNPAID;
     $o = new MasterOrderModel();
     //        $arrOrder = $o->getWhere("
     //        (id_user='******' OR FIND_IN_SET('$idUser', user_guest_id))
     //        AND status_progress !='9'
     //        AND (status_payment ='0' OR status_payment='$stPaymentUnpaid')
     //        AND status != 0
     //         ");
     $arrOrder = $o->getWhere("\n        (id_user='******' OR FIND_IN_SET('{$idUser}', user_guest_id))\n        AND status_progress !='9'\n        AND status_progress !='4'\n        AND status != 0\n         ");
     $results["status_code"] = 1;
     $results["results"] = array();
     foreach ($arrOrder as $order) {
         //            $order = new MasterOrderModel();
         $od["id_order"] = $order->id_order;
         $resto = new MasterRestaurantModel();
         $resto->getByID($order->id_restaurant);
         $od["name"] = $resto->name;
         $od["image_logo"] = Generic::insertImageUrl($resto->image_logo);
         $od["order_now"] = $order->order_now;
         if ($order->id_user == $idUser) {
             $od['isLeader'] = "1";
         } else {
             $od['isLeader'] = "0";
         }
         if ($order->type_order == "1") {
             $od["type_order"] = "Dine In";
         } elseif ($order->type_order == "3") {
             $od["type_order"] = "Take Away";
         } else {
             $od["type_order"] = "Not defined";
         }
         $od["status_progress"] = $order->status_progress;
         $od['datetime_order'] = $order->datetime_order;
         if ($order->id_table == "0" || $order->id_table == "") {
             $od['table_number'] = "0";
         } else {
             $table = new MasterTableModel();
             $table->getByID($order->id_table);
             $od['table_number'] = $table->table_number;
         }
         $od['order_number'] = $order->order_number;
         $results["results"][] = $od;
     }
     echo json_encode($results);
     die;
 }