public function createInvitationLink()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_user = Generic::mustCheck($_GET['id_user'], "NO ID User found!");
     $id_order = Generic::mustCheck($_GET['id_order'], "NO ID Order found!");
     // check apakah id_order dgn id_user msh aktiv
     $objOrder = new MasterOrderModel();
     $arrOrder = $objOrder->getWhere("id_order='{$id_order}' AND id_user = '******' AND status_payment = '0'");
     Generic::checkCountWithMsg($arrOrder, "Order is not activate");
     $objInvitation = new InvitationModel();
     $objInvitation->inv_id_resto = $arrOrder[0]->id_restaurant;
     $objInvitation->inv_id_order = $id_order;
     $objInvitation->inv_id_table = $arrOrder[0]->id_table;
     $objInvitation->inv_from = $id_user;
     $id = $objInvitation->save();
     if ($id != "") {
         $link = _BPATH . "Invitation/acceptInvitation?id_invitation={$id}";
         $json['status_message'] = addslashes($link);
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "Link can't create!";
     }
     echo json_encode($json);
     die;
 }
 public function setTableAttributes()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     //        param, table id, table number, availabilty, sama qr(dalam base 64)
     $id_table = isset($_POST['id_table']) ? addslashes($_POST['id_table']) : "";
     //     echo $id_table;
     if (!$id_table) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Table Found";
         echo json_encode($json);
         die;
     }
     $table_number = isset($_POST['table_number']) ? addslashes($_POST['table_number']) : "";
     if (!$table_number) {
         $json['status_code'] = 0;
         $json['status_message'] = "No Table number Found";
         echo json_encode($json);
         die;
     }
     $availability = isset($_POST['availability']) ? addslashes($_POST['availability']) : "0";
     if (!$availability) {
         $json['status_code'] = 0;
         $json['status_message'] = "No availability Found";
         echo json_encode($json);
         die;
     }
     $QR = isset($_POST['QR']) ? addslashes($_POST['QR']) : "";
     if (!$QR) {
         $json['status_code'] = 0;
         $json['status_message'] = "No QR Found";
         echo json_encode($json);
         die;
     }
     $objQR = new QRModel();
     $arrQR = $objQR->getWhere("textQR='{$QR}' AND status = '0'");
     Generic::checkCountWithMsg($arrQR, "QR has been used!");
     $objTable = new MasterTableModel();
     $arrTable = $objTable->getWhere("id_table='{$id_table}'");
     Generic::checkCountWithMsg($arrTable, "Table not found!");
     $arrTable[0]->table_number = $table_number;
     $arrTable[0]->QR = $QR;
     $arrTable[0]->availability = "1";
     $arrTable[0]->load = 1;
     $arrTable[0]->save();
     $arrQR[0]->status = "1";
     $arrQR[0]->load = "1";
     $arrQR[0]->save();
     $json['status_code'] = 1;
     $json['results'] = Mastertable::getTableByTableID($arrTable[0]->id_table);
     echo json_encode($json);
     die;
 }
 public function getWaitingOrderById()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     //validation
     $idUser = Generic::mustCheck($_GET['id_user'], Keys::$ERR_PLEASE_LOGIN);
     $idOrder = Generic::mustCheck($_GET['id_order'], Keys::$ERR_NOT_FOUND_ID_ORDER);
     if (!User::checkUserID($idUser)) {
         Generic::errorMsg(Keys::$ERR_NOT_FOUND_USER);
     }
     //pastikan ini waiting order, tidak voided, status ok
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     if (Generic::IsNullOrEmptyString($order->id_order)) {
         Generic::errorMsg(Keys::$ERR_NOT_FOUND_ORDER);
     }
     if (!Util::isRunningOrder($order)) {
         Generic::errorMsg(Keys::$ERR_ORDER_INVALID);
     }
     //pastikan user ada di order
     if (!Util::isPartOfOrder($idOrder, $idUser)) {
         Generic::errorMsg(Keys::$FATAL_ERROR_MISMATCH_USER);
     }
     $isLeader = $order->id_user == $idUser ? Keys::$YES : Keys::$NO;
     $hasTable = $order->id_table > 0 ? Keys::$YES : Keys::$NO;
     $restaurant = new MasterRestaurantModel();
     $restaurant->getByID($order->id_restaurant);
     $results = Util::extractModel($order);
     $results['isLeader'] = $isLeader;
     $results['hasTable'] = $hasTable;
     $results['restaurant'] = Util::extractModel($restaurant);
     $arrOrderDetails = Util::getSettedOrderDetail($idOrder);
     Generic::checkCountWithMsg($arrOrderDetails, "No Order Details found!");
     $ao = array();
     foreach ($arrOrderDetails as $orderDetail) {
         $ao[$orderDetail["id_dish"]] = $orderDetail["id_dish"];
     }
     foreach ($ao as $iddish) {
         $b = array();
         $minhlp = array();
         foreach ($arrOrderDetails as $orderDetail) {
             if ($iddish == $orderDetail["id_dish"]) {
                 $b["id_dish"] = $orderDetail["id_dish"];
                 $b["quantity"] = strval(intval($b["quantity"]) + $orderDetail["quantity"]);
                 $b["price"] = strval(intval($b["price"]) + $orderDetail["price"]);
                 $b["name"] = $orderDetail["name"];
                 $minhlp[] = intval($orderDetail["status_progress"]);
                 $b["status_progress"] = strval(min($minhlp));
                 $b["hasOrder"] = $idUser == $orderDetail["id_user"] ? Keys::$YES : Keys::$NO;
                 $userInstance = Util::createUserInstance($orderDetail["id_user"], $orderDetail["note"], $orderDetail["id_order_detail"]);
                 $b["users"][] = $userInstance;
             }
         }
         $results["Order_Details"][] = $b;
     }
     Generic::finish($results);
 }
 public function reportByManuOrderMonthly()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $time_range = isset($_GET['time_range']) ? addslashes($_GET['time_range']) : 1;
     if (!$time_range) {
         $json['status_code'] = 0;
         $json['status_message'] = "No Time range found!";
         echo json_encode($json);
         die;
     }
     $json = array();
     $json['status_code'] = 1;
     $objOrder = new MasterOrderModel();
     global $db;
     $q = "SELECT month(o.datetime_order) as month, SUM(o.grand_total) as total_sales FROM {$objOrder->table_name} o WHERE (o.type_order='0' or o.type_order='2' ) AND DATE_SUB(CURRENT_DATE, INTERVAL " . $time_range . " MONTH) <= o.datetime_order GROUP BY  YEAR(o.datetime_order), MONTH(o.datetime_order)";
     //        echo $q;
     //        die();
     $arrOrder = $db->query($q, 2);
     Generic::checkCountWithMsg($arrOrder, "No Data found!");
     foreach ($arrOrder as $val) {
         $help[] = $val;
     }
     $json['results'] = $help;
     echo json_encode($json);
     die;
 }
 public function searchResto()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $search = isset($_GET['name']) ? addslashes($_GET['name']) : "";
     $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
     if ($lat != "") {
         if (!Generic::checkLatitude($lat)) {
             Generic::errorMsg("Latitude must be Numeric!");
         }
     } else {
         Generic::errorMsg("Latitude is empty");
     }
     $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
     if ($long != "") {
         if (!Generic::checklongitude($long)) {
             Generic::errorMsg("Longitude must be Numeric!");
         }
     } else {
         Generic::errorMsg("Longitude is empty");
     }
     //
     $nearby = isset($_GET['nearby']) ? addslashes($_GET['nearby']) : 20;
     if ($nearby == '1') {
         $nearby = 20;
     } else {
         $nearby = 100000;
     }
     //        echo "near: " . $nearby;
     $arrSort['distance'] = 1;
     $nearby = " HAVING distance < " . $nearby;
     $favorite = isset($_GET['fav']) ? addslashes($_GET['fav']) : "0";
     if ($favorite == '1') {
         $arrSort['fav'] = $favorite;
     }
     $houropen = isset($_GET['houropen']) ? addslashes($_GET['houropen']) : "0";
     if ($houropen == '1') {
         $whereOption = " AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') >= (CONVERT_TZ(concat(CURRENT_DATE,' ',time_open),@@session.time_zone, '+00:00' )) AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') < (CONVERT_TZ(concat(CURRENT_DATE,' ',time_close),@@session.time_zone, '+00:00' ))";
         //            CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') >= (CONVERT_TZ(concat(CURRENT_DATE,' ',time_open),@@session.time_zone, '+00:00' )) AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') < (CONVERT_TZ(concat(CURRENT_DATE,' ',time_close),@@session.time_zone, '+00:00' ))
         //            $whereOption = " AND (CURTIME() BETWEEN time_open AND time_close) ";
     }
     $cuisine = isset($_GET['id_cuisine']) ? addslashes($_GET['id_cuisine']) : "None";
     if (Cuisine::checkCuisineID($cuisine) != 0) {
         $arrWhere['id_cuisine'] = $cuisine;
     }
     $restotype = isset($_GET['id_restotype']) ? addslashes($_GET['id_restotype']) : "None";
     if (MasterRestaurantType::isRestoTypeByIDAvailable($restotype) != 0) {
         $arrWhere['restaurant_type'] = $restotype;
     }
     $disc_mr = isset($_GET['disc_mr']) ? addslashes($_GET['disc_mr']) : "None";
     if ($disc_mr == 1) {
         $arrWhereOr['disc_mr'] = $disc_mr;
     }
     $disc_cc = isset($_GET['disc_cc']) ? addslashes($_GET['disc_cc']) : "None";
     if ($disc_cc == 1) {
         $arrWhereOr['disc_cc'] = $disc_cc;
     }
     $disc_resto = isset($_GET['disc_resto']) ? addslashes($_GET['disc_resto']) : "None";
     if ($disc_resto == 1) {
         $arrWhereOr['disc_resto'] = $disc_resto;
     }
     $where = " WHERE name LIKE '%{$search}%' AND aktiv='1' AND show_in_apps='1'";
     if ($whereOption != "") {
         $where = $where . $whereOption;
     }
     foreach ($arrWhere as $key => $val) {
         $where = $where . " AND {$key}= '{$val}'";
     }
     foreach ($arrWhereOr as $key => $val) {
         $where = $where . " AND {$key} != '0'";
     }
     //        pr($where);
     //        die();
     $sort = " ORDER BY ";
     foreach ($arrSort as $key => $val) {
         if ($key == "distance") {
             $sort = $sort . " {$key} ASC,";
         } elseif ($key == "fav") {
             $sort = $sort . " {$key} DESC,";
         } elseif ($key == "houropen") {
             $sort = $sort . " {$key} ASC,";
         }
     }
     $sort = substr($sort, 0, -1);
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         $json['status_code'] = 0;
         $json['status_message'] = "No Page Found";
         echo json_encode($json);
         die;
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         $json['status_code'] = 0;
         $json['status_message'] = "Limit Error";
         echo json_encode($json);
         die;
     }
     $begin = ($page - 1) * $limit;
     global $db;
     $objRestaurant = new MasterRestaurantModel();
     $q = "SELECT *, SQRT(POW(69.1 * (latitude - {$lat}), 2) + POW(69.1 * ({$long} - longitude) * COS(latitude / 57.3), 2)) AS distance FROM {$objRestaurant->table_name} " . $where . $sort . " LIMIT {$begin},{$limit}";
     //        echo $q;
     $arrResto = $db->query($q, 2);
     Generic::checkCountWithMsg($arrResto, "Can't find the Restaurant");
     $json['results']['restaurant'] = array();
     foreach ($arrResto as $resto) {
         $resto_help = User::getRestaurant($resto->id_restaurant);
         $resto_help['distance'] = $resto->distance;
         $sem[] = $resto_help;
     }
     $json['results']['restaurant'] = $sem;
     echo json_encode($json);
     die;
 }
 public function scandinein()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_user = isset($_GET['id_user']) ? addslashes($_GET['id_user']) : "";
     if (!$id_user) {
         Generic::errorMsg("Please login!");
     }
     if (!User::checkUserID($id_user)) {
         Generic::errorMsg("ID User not found!");
     }
     $QR = isset($_GET['QR']) ? addslashes($_GET['QR']) : "";
     if (!$QR) {
         Generic::errorMsg("No QR found!");
     }
     $id_order = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : "";
     if (!id_order) {
         Generic::errorMsg("id_order not found!");
     }
     if (!MasterOrder::isIdorderValid($id_order)) {
         Generic::errorMsg("id_order not found!");
     }
     $objTableHlp = Mastertable::getTableBYQR($QR);
     $objTable = new MasterTableModel();
     $objTable->getByID($objTableHlp[0]->id_table);
     $objTable->appOrder = "1";
     $objTable->id_order = $id_order;
     $objTable->status = "0";
     $objTable->waitingOrder = "2";
     $objTable->load = 1;
     $objTable->save();
     $objOrder = new MasterOrderModel();
     $objOrder->getByID($id_order);
     $objOrder->id_table = $objTableHlp[0]->id_table;
     $objOrder->type_order = "1";
     $objOrder->load = 1;
     $objOrder->save();
     $objOrderHlp = new MasterOrderModel();
     $arrOrder = $objOrderHlp->getWhere("id_user='******' AND status_progress < 3 OR status_payment='0'");
     Generic::checkCountWithMsg($arrOrder, "No ID Order from the ID User found");
     $id_order = $arrOrder[0]->id_order;
     $order = MasterOrder::getOrder($id_order);
     $arrOrderDetails = OrderDetail::getOrderDetailsByIDOrderAndUserID($id_order, $id_user);
     $order['Order_Details'] = $arrOrderDetails;
     $order['restaurant'] = User::getRestaurant($order['id_restaurant']);
     $json['results'][] = $order;
     echo json_encode($json);
     die;
 }
 public static function getTodayFinishOrderKitchenByRestoID($id_restaurant)
 {
     $objOrder = new MasterOrderModel();
     $arrOrder = $objOrder->getWhere("DATE(datetime_order)>=CURDATE() AND id_restaurant = '{$id_restaurant}' AND status_progress >=3 AND order_now='1' ORDER BY datetime_order DESC");
     Generic::checkCountWithMsg($arrOrder, "No finish order found!");
     $exp = explode(",", str_replace(" ", "", $objOrder->crud_webservice_allowed));
     foreach ($arrOrder as $o) {
         foreach ($exp as $attr) {
             $sem[$attr] = stripslashes($o->{$attr});
         }
         $tableObj = new MasterTableModel();
         $tableObj->getByID($o->id_table);
         if ($tableObj->table_number != null) {
             $sem["table_number"] = $tableObj->table_number;
         } else {
             $sem["table_number"] = "";
         }
         $activeOrder[] = $sem;
     }
     return $activeOrder;
 }