public function getCategoriesByResto() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $idRestaurant = Generic::mustCheck($_GET['id_restaurant'], Keys::$ERR_NOT_FOUND_ID_RESTAURANT); $objResto = new MasterRestaurantModel(); $objResto->getByID($idRestaurant); if (!Generic::IsNullOrEmptyString($objResto->id_categories)) { $arrCategories = explode(",", $objResto->id_categories); } else { $arrCategories = array(); } $categories = array(); foreach ($arrCategories as $idCat) { $c = new MasterCategoryModel(); $c->getByID($idCat); if ($c->id_category) { $categories[] = $c->name; } } // pr($arrCategories); // pr($categories); $results['categories'] = $categories; $rawTags = array(); $id_dish = isset($_GET['id_dish']) ? addslashes($_GET['id_dish']) : ""; if ($id_dish) { $dish = new MasterDishModel(); $dish->getByID($id_dish); $tagsIds = explode(",", $dish->dish_tags); if (count($tagsIds) != 0) { foreach ($tagsIds as $tagsId) { if ($tagsId == null || $tagsId == "") { continue; } $dishTag = new MasterDishTagModel(); $dishTag->getByID($tagsId); $b["id_tag"] = $dishTag->id_tag; $b["name"] = $dishTag->name; $rawTags[] = $b; } } } $results['raw_tags'] = $rawTags; Generic::finish($results); }
public static function isDishValidAndAvailable($idDish) { $dish = new MasterDishModel(); $dish->getByID($idDish); if (Generic::IsNullOrEmptyString($dish->id_dish)) { return false; } if ($dish->status == Keys::$YES) { return $dish->availability == Keys::$YES; } else { return false; } }
public static function checkDish($id_dish) { $objDish = new MasterDishModel(); $arrDish = $objDish->getWhere("id_dish='{$id_dish}'"); if (count($arrDish) > 0) { return true; } else { return false; } }
public function addDishToMyFavorite() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $idUser = Generic::mustCheck($_GET['id_user'], "User ID not Found"); $idDish = Generic::mustCheck($_GET['id_dish'], "Dish ID not Found"); $user = new UserModel(); $user->getByID($idUser); $arrFavDishIds = explode(',', $user->fav_dishes_ids); $alreadyInFavorite = count($arrFavDishIds) <= 0 ? false : in_array($idDish, $arrFavDishIds); if ($alreadyInFavorite) { Generic::errorMsg("Already Favorited"); } if (count($arrFavDishIds) <= 0) { $user->fav_dishes_ids = $idDish; } else { $arrFavDishIds[] = $idDish; $arrFavDishIds = array_unique($arrFavDishIds); $user->fav_dishes_ids = implode(',', $arrFavDishIds); } $dish = new MasterDishModel(); $dish->getByID($idDish); $dish->fav = $dish->fav + 1; $dish->save(); $resto = new MasterRestaurantModel(); $resto->getByID($dish->id_restaurant); $resto->fav = $resto->fav + 1; $resto->save(); $user->save(); $this->success(); }
public function loadDish() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $cmd = isset($_GET['cmd']) ? addslashes($_GET['cmd']) : ""; $json = array(); $json['status_code'] = 1; if (!$cmd) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $id_user = isset($_GET['id']) ? addslashes($_GET['id']) : ""; if (!$id_user) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $user = new UserModel(); $arrUser = $user->getWhere("id_user={$id_user}"); if ($cmd == "fav") { foreach ($arrUser as $o) { $dishSearch['fav_dishes_ids'] = $o->fav_dishes_ids; } $objectDish = new MasterDishModel(); $objResto = new MasterRestaurantModel(); $arrdishSearch = explode(",", $dishSearch[fav_dishes_ids]); foreach ($arrdishSearch as $val) { if ($where == "") { $where = "{$objectDish->table_name}.id_dish={$val}"; } else { $where = $where . " or {$objectDish->table_name}.id_dish={$val}"; } } $where = $where . " ORDER BY {$objectDish->table_name}.fav DESC"; $where = $where; global $db; $arrDish = $objectDish->getWhere($where); foreach ($arrDish as $key => $dish) { $arrFavbyResto[] = $dish->id_restaurant; $arrGesDish[$dish->id_restaurant][] = MasterDish::getDish($dish->id_dish); } $arrFavbyResto = array_unique($arrFavbyResto); $sem = array(); foreach ($arrFavbyResto as $resto) { $restoHelp = self::getRestaurant($resto); foreach ($arrGesDish as $key => $valdish) { $dishhelp = array(); if ($key == $resto) { $dishhelp = $valdish; break; } } $restoHelp['dish'] = $dishhelp; $sem['restaurant'][] = $restoHelp; } $json['results'] = $sem; } elseif ($cmd == "his") { foreach ($arrUser as $o) { $dishSearch['history_dishes_ids'] = $o->history_dishes_ids; } $arrdishSearch = explode(",", $dishSearch[history_dishes_ids]); $objectDish = new MasterDishModel(); $objectRestaurant = new MasterRestaurantModel(); $exp = explode(",", str_replace(" ", "", $objectDish->crud_webservice_allowed)); $arrPicsToAddPhotoUrl = $objectDish->crud_add_photourl; foreach ($arrdishSearch as $val) { $arr = $objectDish->getWhere("id_dish=" . $val, "*"); if (count($arr) != 0) { $json['status_code'] = 1; } else { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $sem = array(); foreach ($arr as $o) { foreach ($exp as $attr) { // echo $attr; if (in_array($attr, $arrPicsToAddPhotoUrl)) { $sem[$attr] = _BPATH . _PHOTOURL . $o->{$attr}; } elseif ($attr == "id_restaurant") { // echo "masuk"; // echo $o->$attr; $sem[$attr] = stripslashes($o->{$attr}); $sem['restaurant'] = $this->getRestaurant($o->{$attr}); } else { $sem[$attr] = stripslashes($o->{$attr}); } } //$sem['restaurant'] = $objectRestaurant->getRestaurant($val); $json["results"][] = $sem; } } } elseif ($cmd == "receipthis") { } else { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } echo json_encode($json); die; }
public function setRestoCategories() { if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $json = array(); $json['status_code'] = 1; $id_restaurant = isset($_POST['id_restaurant']) ? addslashes($_POST['id_restaurant']) : ""; if (!$id_restaurant) { Generic::errorMsg("Restaurant ID not Found"); } $category = isset($_POST['categories']) ? $_POST['categories'] : ""; if (!$category) { Generic::errorMsg("Category ID not found!"); } $resto = new MasterRestaurantModel(); $resto->getByID($id_restaurant); $arrOldCategories = explode(",", $resto->id_categories); $jsonCategories = json_decode($category); $jsonCategorieshlp = array(); foreach ($jsonCategories as $cat) { $jsonCategorieshlp[] = $cat->category_name; } if (!in_array("OTHERS", $jsonCategorieshlp)) { $jsonCategorieshlp[] = "OTHERS"; } $jsonCategorieshlp = array_unique($jsonCategorieshlp); $objCategory = new MasterCategoryModel(); $idCategories = array(); foreach ($jsonCategorieshlp as $category) { $arrCategory = $objCategory->getWhere("name = '{$category}'"); if (count($arrCategory) == 0 && !Generic::IsNullOrEmptyString($category)) { $oc = new MasterCategoryModel(); $oc->name = strtoupper($category); $oc->status = "1"; $oc->is_drink = "0"; $oc->save(); } } foreach ($jsonCategorieshlp as $category) { $arrCategory = $objCategory->getWhere("name = '{$category}'"); foreach ($arrCategory as $val) { $idCategories[] = $val->id_category; } } //compare old categories to new categories //cari yang dulu ada sekarang ga ada //migrasi dish ke others $missingCategories = array_diff($arrOldCategories, $idCategories); foreach ($missingCategories as $category) { $d = new MasterDishModel(); $arrDishes = $d->getWhere("id_category = '{$category}' AND id_restaurant = '{$id_restaurant}'"); foreach ($arrDishes as $dish) { $dish->load = 1; $dish->id_category = "0"; $dish->save(); } } $objRestaurant = new MasterRestaurantModel(); $arrResto = $objRestaurant->getWhere("id_restaurant = '{$id_restaurant}'"); if (count($arrResto) == 0) { $json['status_code'] = 0; $json['status_message'] = "No ID Found"; echo json_encode($json); die; } $idCategories = implode(",", $idCategories); $arrResto[0]->id_categories = $idCategories; $arrResto[0]->load = 1; $idSave = $arrResto[0]->save(); if (!$idSave) { Generic::errorMsg(Lang::t('save failed')); } else { $json['status_code'] = 1; $json['results'] = "Success"; } echo json_encode($json); die; }
public function overwriteForm($return, $returnfull) { $r = new MasterRestaurantModel(); $arrR = $r->getWhere("aktiv='1'"); $arrHelp = array("0" => "Nothing Selected"); foreach ($arrR as $resto) { $arrHelp[$resto->id_restaurant] = $resto->name; } $return['id_restaurant'] = new \Leap\View\InputSelect($arrHelp, "id_restaurant", "id_restaurant", $this->id_restaurant); if (!isset($this->id_restaurant)) { $this->id_restaurant = key($arrHelp); } $d = new MasterDishModel(); $arrD = $d->getWhere("id_restaurant='{$this->id_restaurant}' AND status='1'"); $arrHelpDish = array("0" => "Nothing Selected"); foreach ($arrD as $dish) { $arrHelpDish[$dish->id_dish] = $dish->name; } $return['id_dish'] = new Leap\View\InputSelect($arrHelpDish, "id_dish", "id_dish", $this->id_dish); ?> <script> $("#id_restaurant").change(function () { var selVal = $("select#id_restaurant option:selected").val(); if (selVal == 0 || selVal == "" || selVal == "0") { $('#id_dish').empty(); $('#id_dish').append($("<option></option>") .attr("value", 0) .text("Nothing Selected")); return; } $.ajax({ method: "GET", url: _sppath + "RecommendationFood/getDishByRestoId", data: {id_restaurant: selVal} }).done(function (msg) { // console.log(msg); $('#id_dish').empty(); var json_obj = $.parseJSON(msg);//parse JSON for (var i in json_obj) { $('#id_dish') .append($("<option></option>") .attr("value", json_obj[i].value) .text(json_obj[i].text)); console.log(json_obj[i].text); } }); }); </script> <?php if (!isset($this->start)) { $dt = leap_mysqldate(); } else { $dt = $this->start; } $return['start'] = new \Leap\View\InputText("date", "start", "start", $dt); if (!isset($this->end)) { $dt = leap_mysqldate(); } else { $dt = $this->end; } $return['end'] = new \Leap\View\InputText("date", "end", "end", $dt); return $return; }
public function addOrderInPendingOrder() { //TODO Sama seperti add order kemarin, tapi quantity cuma bisa set 1 //TODO master apa bukan if (Efiwebsetting::getData('checkOAuth') == 'yes') { IMBAuth::checkOAuth(); } $id_user = isset($_GET['id_user']) ? addslashes($_GET['id_user']) : ""; if (!$id_user) { Generic::errorMsg("Please login!"); } $id_order = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : ""; if (!$id_order) { Generic::errorMsg("ID Order not found!"); } $id_dish = isset($_GET['id_dish']) ? addslashes($_GET['id_dish']) : ""; if (!$id_dish) { Generic::errorMsg("ID Dish not found!"); } $arah = addslashes($_GET['arah']); //plus //minus //ambil order saya, kalau blom ada, dan action plus, maka bikin baru //ambil order saya kalau blom ada dan action minus dan saya master..boleh kurangi, else meldung tidak bisa mengurangi order yang bukan milik anda //kalau master ambil order semua $ada_default_order = 0; $myOrder = ""; $objOrderDetail = new OrderDetailModel(); $arrObj = $objOrderDetail->getWhere("id_user = '******' AND id_order = '{$id_order}' AND id_dish ='{$id_dish}' AND order_now!=1 LIMIT 0,1"); if (count($arrObj) > 0) { $ada_default_order = 1; $myOrder = $arrObj[0]; } $dish = new MasterDishModel(); $dish->getByID($id_dish); $isLeader = Util::isLeader($id_order, $id_user); if ($arah == "plus") { if (!$ada_default_order) { $price = $dish->price; //krn qty = 1 $objOrderDetail = new OrderDetailModel(); $objOrderDetail->id_user = $id_user; $objOrderDetail->id_order = $id_order; $objOrderDetail->id_dish = $id_dish; $objOrderDetail->quantity = 1; $objOrderDetail->price = $price; $objOrderDetail->datetime_order = $this->setCurrentDate(); $objOrderDetail->status = "1"; // $dishname = MasterDish::getDish($id_dish); // $objOrderDetail->quantity = 1; $id = $objOrderDetail->save(); } else { $price = $dish->price * ($myOrder->quantity + 1); $myOrder->quantity++; $myOrder->price = $price; $myOrder->datetime_order = $this->setCurrentDate(); $myOrder->status = "1"; $myOrder->load = 1; $myOrder->save(); $id = $myOrder->id_order_detail; } } if ($arah == "minus") { if ($ada_default_order) { //cek apa default ordernya masi plus if ($myOrder->quantity > 0) { //minus biasa $price = $dish->price * ($myOrder->quantity - 1); $myOrder->quantity--; $myOrder->price = $price; $myOrder->datetime_order = $this->setCurrentDate(); $myOrder->status = "1"; $myOrder->load = 1; $myOrder->save(); $id = $myOrder->id_order_detail; } else { if ($isLeader) { //minus dari anggota yang lain $objOrderDetail = new OrderDetailModel(); $arrObjLain = $objOrderDetail->getWhere("id_order = '{$id_order}' AND id_dish ='{$id_dish}'"); if (count($arrObjLain) > 0) { //bisa dikurangin dari yang lain..lihat qty nya juga $sum = 0; foreach ($arrObjLain as $od) { $sum += $od->quantity; } if ($sum > 0) { foreach ($arrObjLain as $od) { if ($od->quantity > 0) { //minus biasa $price = $dish->price * ($od->quantity - 1); $od->quantity--; $od->price = $price; $od->datetime_order = $this->setCurrentDate(); $od->status = "1"; $od->load = 1; $od->save(); $id = $od->id_order_detail; break; } } } else { //habis ga bisa dikurangi Generic::errorMsg("Not Enough Quantity"); } } else { Generic::errorMsg("Not Enough Quantity"); } } else { //Notify kl jumlah tidak cukup utk dikurangi //habis ga bisa dikurangi Generic::errorMsg("Not Enough Quantity"); } } } else { //minus dr anggota yang lain if ($isLeader) { //minus dari anggota yang lain $objOrderDetail = new OrderDetailModel(); $arrObjLain = $objOrderDetail->getWhere("id_order = '{$id_order}' AND id_dish ='{$id_dish}'"); if (count($arrObjLain) > 0) { //bisa dikurangin dari yang lain..lihat qty nya juga $sum = 0; foreach ($arrObjLain as $od) { $sum += $od->quantity; } if ($sum > 0) { foreach ($arrObjLain as $od) { if ($od->quantity > 0) { //minus biasa $price = $dish->price * ($od->quantity - 1); $od->quantity--; $od->price = $price; $od->datetime_order = $this->setCurrentDate(); $od->status = "1"; $od->load = 1; $od->save(); $id = $od->id_order_detail; break; } } } else { //habis ga bisa dikurangi Generic::errorMsg("Not Enough Quantity"); } } else { Generic::errorMsg("Not Enough Quantity"); } } else { //Notify kl jumlah tidak cukup utk dikurangi Generic::errorMsg("Not Enough Quantity"); } } } if ($arah == "") { Generic::errorMsg("Please insert arah"); } // getcurrent qty dr iddish // $currQuantity = OrderDetail::getQuantityUserByID_dish($id_dish, $id_order, $id_user); // $id = $this->addOrderDetails($id_order, $id_user, $id_dish, $currQuantity + 1); if (!$id) { Generic::errorMsg("Add order failed!"); } $objOrder = new MasterOrderModel(); $objOrder->getByID($id_order); $invoice = $this->calcRechnung($objOrder->id_restaurant, $id_order); $inv = new Invoice($id_order, true); $this->setInvoiceInOrder($objOrder, $invoice); $objOrder->datetime_order = $this->setCurrentDate(); // $objOrder->total_cost = $invoice['Total']; $objOrder->load = 1; $id_updateOrder = $objOrder->save(); if (!$id_updateOrder) { Generic::errorMsg("Update Order failed!"); } $json = array(); $json['status_code'] = 1; $json['results']['messages'] = "Success"; $orderDetails = Util::getAllOrderDetailsByIDOrder($id_order); $orderDetailByDishID = array(); // pr($orderDetails); $total = array(); foreach ($orderDetails as $det) { if ($det['status_progress'] != 9) { // echo "dis ID ".$det['id_dish']." | ".$total[$det['id_dish']]['quantity']." add ".$det['quantity']."<br>"; $total[$det['id_dish']]['quantity'] += $det['quantity']; } $string_name = rtrim(trim(preg_replace('/\\s\\s+/', ' ', $det['name']))); $dish = new MasterDishModel(); $dish->getByID($det['id_dish']); $total[$det['id_dish']]['id_dish'] = $det['id_dish']; $total[$det['id_dish']]['name'] = $string_name; $total[$det['id_dish']]['single_price'] = (double) $dish->price; $orderDetailByDishID[$det['id_dish']][] = $det; } $hasilnya = array(); $all_total = 0; foreach ($total as $key => $val) { $sem = array(); $val['price_subtotal'] = $val['quantity'] * $val['single_price']; $all_total += $val['price_subtotal']; $sem = $val; $sem["orders"] = array(); //kelompokan menurut status progess foreach ($orderDetailByDishID[$key] as $orderDetail) { $userInstance = Util::createUserInstance($orderDetail["id_user"], $orderDetail["note"], $orderDetail["id_order_detail"]); $orderDetail['user'] = $userInstance; if ($orderDetail['order_now'] == 0) { $sem['orders']['Pending'][] = $orderDetail; } else { $sem['orders'][Helper::getStatusProgress()[$orderDetail['status_progress']]][] = $orderDetail; } } $hasilnya[] = $sem; } $json['results']['hasil'] = $hasilnya; $json['results']['alltotal'] = $all_total; $json['results']['invoice'] = $inv->getInvoice(); $ids = $this->getUserIdByIDOrder($id_order, $id_user); // $json['results']['push'] = $this->notifyAddOrder($ids, $id_order); $json['results']['push'] = Util::pushNotifyAddOrder($id_order, $id_user, $id_dish); echo json_encode($json); // $json['APA'] = ""; // $json2 =$this->notifyAddOrder($ids, $id_order); // $json3 = array_merge($json, $json2); // echo json_encode($json3) ; die; }
public function reinitiateCategories() { $idRestaurant = Generic::mustCheck($_GET['id_restaurant'], "BOOO!"); $catIdDefault = $this->createCategories("OTHERS"); $md = new MasterDishModel(); if ($idRestaurant == "all") { $arrDishes = $md->getAll(); } else { $arrDishes = $md->getWhere("id_restaurant='{$idRestaurant}'"); } echo "<h1>Default cat id : {$catIdDefault}</h1>"; foreach ($arrDishes as $d) { $dish = new MasterDishModel(); $dish->getByID($d->id_dish); echo "<h2>{$dish->id_dish} - {$dish->name}</h2>"; echo "<h3>From {$dish->id_category}"; if (Generic::IsNullOrEmptyString($dish->id_category)) { echo "changed to"; $dish->id_category = $catIdDefault; $dish->save(); } else { if (!$this->isCategoryIdValid($dish->id_category)) { echo "changed to"; $dish->id_category = $catIdDefault; $dish->save(); } else { echo "stay at"; } } echo " {$dish->id_category}</h3>"; $resto = new MasterRestaurantModel(); $resto->getByID($dish->id_restaurant); echo "<h2>{$resto->id_restaurant} - {$resto->name}</h2>"; echo "<h3>From {$resto->id_categories}"; if (Generic::IsNullOrEmptyString($resto->id_categories)) { $resto->id_categories = $catIdDefault; $resto->save(); } else { $arrCats = explode(',', $resto->id_categories); $arrCats[] = $dish->id_category; $arrCats = array_unique($arrCats); $resto->id_categories = implode(',', $arrCats); $resto->save(); } echo " To {$resto->id_categories}</h3>"; } }