public static function ifDebugShow($pr) { $isDebuging = Generic::getOrDefault($_GET['is_debug'], Keys::$EMPTY); if ($isDebuging != Keys::$EMPTY) { pr($pr); } }
public function orderDone() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $idOrder = $this->mustCheck($_POST["id_order"], "No Order ID"); $order = new MasterOrderModel(); $order->getByID($idOrder); if ($order->status_progress == 2 || $order->status_progress == 3) { $order->status_progress = 4; $order->save(); } elseif ($order->status_progress == 4) { Generic::errorMsg("Order Already Done"); } elseif ($order->status_progress == 9) { Generic::errorMsg("Order Voided"); } else { Generic::errorMsg("Some Dishes Might Not Complete"); } $paymentPulled = 0; $payment_success = 0; if ($order->status_payment != Keys::$PAYMENT_STATUS_PAID && $order->type_order == Keys::$ORDER_TYPE_DINE_IN_APPS) { if ($order->payment_method == Keys::$PAYMENT_TYPE_CREDIT_CARD) { //credit card $ret = Util::payViaCreditCard($idOrder); if ($ret['success']) { $payment_success = 1; $paymentPulled = 1; } } if ($order->payment_method == Keys::$PAYMENT_TYPE_CASH) { $payment_success = 1; // if ($order->type_order != Keys::$ORDER_TYPE_TAKE_AWAY_APPS) { // //dibikin push order selesai // //push ke restaurant selesai // } else { // //gak boleh cash // } } if ($order->payment_method == Keys::$PAYMENT_TYPE_DOKU_WALLET) { $ret = Util::payViaDokuWallet($idOrder); if ($ret['success']) { $payment_success = 1; $paymentPulled = 1; } } if (!$payment_success) { $results['status_message'] = "Payment Failed"; $results['code'] = "PAYMENT_FAILED"; Generic::finish($results, 0); } } $o = new OrderDetailModel(); $orderDetails = $o->getWhere("id_order='{$idOrder}'"); foreach ($orderDetails as $orderDetail) { if (!$orderDetail instanceof OrderDetailModel) { return; } if ($orderDetail->status_progress != 9) { $orderDetail->load = 1; $orderDetail->status_progress = 4; $orderDetail->status_payment = Keys::$PAYMENT_STATUS_PAID; $orderDetail->save(); } } $resto = new MasterRestaurantModel(); $resto->getByID($order->id_restaurant); Mastertable::clearTable($order->id_table); $order->datetime_done = leap_mysqldate_isi(date('Y-m-d H:i:s')); $order->status_payment = Keys::$PAYMENT_STATUS_PAID; $order->isPaid = 1; $order->save(); $email = Generic::getOrDefault($_POST['email'], Keys::$EMPTY); Util::emailReceipt($idOrder, $email); ///masih kosong belum jalan if ($order->id_user != 0) { Util::pushUserOrderDone($order->id_order); } Util::pushRestoOrderDone($order->id_order); $json = array(); $json['status_code'] = 1; $json['results']["message"] = "Success"; echo json_encode($json); die; }
public function userSignUp() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $update = !Generic::IsNullOrEmptyString($_POST['id_user']); $idUser = Generic::IsNullOrEmptyString($_POST['id_user']) ? "" : $_POST['id_user']; $fullName = Generic::mustCheck($_POST['full_name'], Keys::$ERR_USER_EMPTY_FULL_NAME); $userName = Generic::mustCheck($_POST['user_name'], Keys::$ERR_USER_EMPTY_NICK_NAME); $email = Generic::mustCheck($_POST['email'], Keys::$ERR_USER_EMPTY_EMAIL); $password = Generic::mustCheck($_POST['pwd'], Keys::$ERR_USER_EMPTY_PASSWORD); // $password2 = Generic::mustCheck($_POST['pwd2'], Keys::$ERR_USER_EMPTY_PASSWORD_2); $idCuisine = Generic::mustCheck($_POST['pref_cuisine'], Keys::$ERR_USER_EMPTY_CUISINE); $birthday = Generic::mustCheck($_POST['birthday'], Keys::$ERR_USER_EMPTY_BIRTHDAY); $phoneNo = Generic::mustCheck($_POST['phone_no'], Keys::$ERR_USER_EMPTY_PHONE); $fbId = Generic::IsNullOrEmptyString($_POST['fb_id']) ? "" : $_POST['fb_id']; $latitude = Generic::getOrDefault($_POST['lat'], Keys::$DEFAULT_LATITUDE); $longitude = Generic::getOrDefault($_POST['long'], Keys::$DEFAULT_LONGITUDE); $district = Generic::getOrDefault($_POST['district'], Keys::$EMPTY); $city = Generic::getOrDefault($_POST['city'], Keys::$EMPTY); $pic = Generic::getOrDefault($_POST['pic'], Keys::$EMPTY); ///START OF LOVELY VALIDATION TIME if (!Generic::isValidUserName($userName)) { Generic::errorMsg(Keys::$ERR_USER_INVALID_USERNAME); } if (!Generic::isValidUserNameLength($userName)) { Generic::errorMsg(Keys::$ERR_USER_USERNAME_TOO_LONG); } if (!Generic::isValidEmail($email)) { Generic::errorMsg(Keys::$ERR_USER_INVALID_EMAIL); } if (!Generic::isValidPassword($password)) { Generic::errorMsg(Keys::$ERR_USER_INVALID_PASSWORD); } // if ($password != $password2) // Generic::errorMsg(Keys::$ERR_USER_CONFIRM_PASSWORD_NOT_MATCH); $u = new UserModel(); $arrU = $u->getWhere("user_name='{$userName}'"); if (count($arrU) > 0) { Generic::errorMsg(Keys::$ERR_USER_DUPLICATE_USERNAME); } $u1 = new UserModel(); $arrU = $u1->getWhere("email='{$email}'"); if (count($arrU) > 0) { Generic::errorMsg(Keys::$ERR_USER_DUPLICATE_EMAIL); } if ($fbId != "") { $u2 = new UserModel(); $arrU = $u2->getWhere("fb_id='{$fbId}'"); if (count($arrU) > 0) { Generic::errorMsg(Keys::$ERR_USER_DUPLICATE_FB_ID); } } ///END OF LOVELY VALIDATION TIME, HOW SAD :( //pagar untuk regis if (Efiwebsetting::getData('Doku_switch')) { $doku = new PaymentDoku(); $dokuId = $doku->registerCustomer($fullName, $email, $phoneNo); if (!$dokuId) { Generic::errorMsg(Keys::$ERR_USER_FAILED_CREATE_DOKU); } } $user = new UserModel(); $user->full_name = $fullName; $user->user_name = $userName; $user->email = $email; $user->password = $password; $user->id_cuisine = $idCuisine; $user->birthday = $birthday; if ($pic == "") { $user->pic = ""; } else { $user->pic = Util::savePic($pic); } $user->phone_no = $phoneNo; $user->fb_id = $fbId; $user->latitude = $latitude; $user->longitude = $longitude; $user->district = $district; $user->city = $city; $user->last_lat = $latitude; $user->last_long = $longitude; $user->last_district = $district; $user->last_city = $city; $user->status = "1"; $user->payment_id = $dokuId; // $user->load = 1; $uid = $user->save(); if (!$uid) { Generic::errorMsg(Keys::$ERR_USER_FAILED_CREATE); } else { Generic::saveDistrictCityFromLatLng($latitude, $longitude, $uid, false); $results['fb_id'] = $fbId; $results['id_user'] = $uid; //$user->id_user; $results['user_name'] = $userName; $results['full_name'] = $fullName; $results['email'] = $email; $results['pic'] = Generic::insertImageUrl($pic); Generic::finish($results); } }
public function getMenu() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $json = array(); $json['status_code'] = 1; $id_restaurant = isset($_GET['id_restaurant']) ? addslashes($_GET['id_restaurant']) : ""; if (!$id_restaurant) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $objRestaurant = new MasterRestaurantModel(); $arrResto = $objRestaurant->getWhere("id_restaurant={$id_restaurant}"); if (count($arrResto) == 0) { $json['status_code'] = 0; $json['status_message'] = "Can't find Restaurant in the Database!"; echo json_encode($json); die; } $resto = User::getRestaurant($id_restaurant); $json['results']['restaurant'][] = $resto; global $db; $objDish = new MasterDishModel(); $q = "SELECT id_category FROM {$objDish->table_name} WHERE availability=1 AND id_restaurant={$id_restaurant}"; $arrCat = $objDish->getWhere("availability=1 AND id_restaurant='{$id_restaurant}'"); if (count($arrCat) == 0) { $json['status_code'] = 1; $json['status_message'] = "Can't find dish in the Restaurant!"; $json['results']['categories'] = array(); echo json_encode($json); die; } $catIds = explode(",", $resto["id_categories"]); // pr($catIds); // foreach ($arrCat as $idCat) { // $arrIDCategory[] = $idCat->id_category; // $arrIDCategory = array_unique($arrIDCategory); // } $objCategory = new MasterCategoryModel(); $objDish = new MasterDishModel(); // $expCategory = explode(",", str_replace(" ", "", $objCategory->crud_webservice_allowed)); // $expDish = explode(",", str_replace(" ", "", $objDish->crud_webservice_allowed)); // $arrPicsDishToAddPhotoUrl = $objDish->crud_add_photourl; // pr($arrIDCategory); foreach ($catIds as $val) { $cat = MasterCategory::getCategoryByID($val); //echo "abc: " . $val ; $arrDish = $objDish->getWhere("availability=1 AND id_category='{$val}' AND id_restaurant='{$id_restaurant}'"); if (count($arrDish) == 0) { continue; } $dishHelp = array(); foreach ($arrDish as $val) { // echo $val->id_dish; $dishHelp[] = MasterDish::getDish($val->id_dish); } $cat['dishes'] = $dishHelp; $json['results']['categories'][] = $cat; } //TODO add order utk ini perlu user_id dan id_order $idUser = Generic::getOrDefault($_GET['id_user'], Keys::$EMPTY); $idOrder = Generic::getOrDefault($_GET['id_order'], Keys::$EMPTY); if ($idOrder != Keys::$EMPTY) { //ambil semua order yang active //dan isi2nya $orderModel = new MasterOrderModel(); $orderModel->getByID($idOrder); // $orderDetails = Util::getOrderDetailsByIDOrder($idOrder); // $order["Order_Details"] = Array(); $orderDetail = new OrderDetailModel(); $orderDetails = $orderDetail->getWhere("id_order = '{$idOrder}' AND id_user = '******'"); $new = array(); foreach ($orderDetails as $or) { if ($or->quantity < 1) { continue; } $new[] = Util::extractModel($or); } $json['order_details'] = $new; // pr($orderDetails); // $sudah = array(); // foreach ($new as $orderDetail) { // if($orderDetail['status_progress']=="")$orderDetail['status_progress'] = 0; // $dish = new MasterDishModel(); // $dish->getByID($orderDetail['id_dish']); // $userInstance = Util::createUserInstance($orderDetail["id_user"], $orderDetail["note"], $orderDetail["id_order_detail"]); // $string_name = rtrim(trim(preg_replace('/\s\s+/', ' ', $orderDetail['name']))); // $order['Order_Details_new'][$orderDetail['id_dish']]['quantity'] += $orderDetail['quantity']; // $order['Order_Details_new'][$orderDetail['id_dish']]['price'] += ($orderDetail['quantity']*$dish->price); // if($order['Order_Details'][$orderDetail['id_dish']]['status_progress']!==null) // $order['Order_Details_new'][$orderDetail['id_dish']]['status_progress'] = min($orderDetail['status_progress'],$order['Order_Details'][$orderDetail['id_dish']]['status_progress']); // else // $order['Order_Details_new'][$orderDetail['id_dish']]['status_progress'] = 0; // $order['Order_Details_new'][$orderDetail['id_dish']]['id_dish'] = $orderDetail['id_dish']; // $order['Order_Details_new'][$orderDetail['id_dish']]['name'] = $string_name; // $order['Order_Details_new'][$orderDetail['id_dish']]['single_price'] = (double)$dish->price; // $order['Order_Details_new'][$orderDetail['id_dish']]['users'][] = $userInstance; // } //// pr($order['Order_Details_new']); // // // foreach($order['Order_Details_new'] as $obj){ // if($obj['quantity']<1)continue; // $json['order_details'][] = $obj; // } // $orderDetail = new OrderDetailModel(); // $arrOrderDetail = $orderDetail->getWhere("id_order = '$idOrder'"); // // $json['order'] = Util::extractModel($orderModel); // // $new = array(); // foreach($arrOrderDetail as $or){ // // $new[] = Util::extractModel($or); // } // $json['order_details'] = $order['Order_Details']; } echo json_encode($json); die; }
public function regroupCategories() { $idResto = Generic::getOrDefault($_GET['id_restaurant'], Keys::$EMPTY); $catIdDefault = $this->createCategories("OTHERS"); echo "<h1>ID Others : {$catIdDefault}</h1>"; $r = new MasterRestaurantModel(); if (Generic::IsNullOrEmptyString($idResto)) { $arrResto = $r->getAll(); } else { $arrResto = $r->getWhere("id_restaurant='{$idResto}'"); } foreach ($arrResto as $resto) { if (!$resto instanceof MasterRestaurantModel) { continue; } echo "<h2>{$resto->id_restaurant} - {$resto->name}</h2>"; $resto->load = 1; if (Generic::IsNullOrEmptyString($resto->id_categories)) { $resto->id_categories = $catIdDefault; $resto->save(); continue; } $arrNewCats = array(); $arrCatIds = explode(',', $resto->id_categories); foreach ($arrCatIds as $catId) { if (!$this->isCategoryIdValid($catId)) { $arrNewCats[] = $catId; } } $arrNewCats = array_unique($arrNewCats); if (count($arrNewCats) <= 0) { $resto->id_categories = $catIdDefault; $resto->save(); } $resto->id_categories = implode(',', $arrNewCats); $resto->save(); echo "<h3>{$resto->id_categories}</h3>"; } $d = new MasterDishModel(); // $arrDish = $d->getAll(); $arrDish = $d->getWhere("id_restaurant='62'"); foreach ($arrDish as $dish) { if (!$dish instanceof MasterDishModel) { continue; } echo "<h2>{$dish->id_dish} - {$dish->name}-></h2>"; if (!$this->isCategoryIdValid($dish->id_category)) { $dish->id_category = $catIdDefault; $dish->load = 1; $dish->save(); } } }