public function getUndoneReceiptDetail()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $result = "";
     $idOrder = Generic::mustCheck($_GET['id_order'], "No ID Order");
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     $result['Order'] = MasterOrder::getOrder($idOrder);
     $result['Order Details'] = Util::getSettedOrderDetails($idOrder);
     $resto = new MasterRestaurantModel();
     $resto->getByID($order->id_restaurant);
     $result['restaurant']['image_logo'] = _BPATH . _PHOTOURL . $resto->image_logo;
     $result['restaurant']['name'] = $resto->name;
     $result['restaurant']['address'] = $resto->address;
     $result['restaurant']['district'] = $resto->district;
     $result['restaurant']['city'] = $resto->city;
     $result['restaurant']['phone_no'] = $resto->phone_no;
     $this->finish($result);
 }
 private function calcRechnungAndSave($id_restaurant, $id_order)
 {
     $order = new MasterOrderModel();
     $order->getByID($id_order);
     $objResto = User::getRestaurant($id_restaurant);
     //        pr($objResto );
     $objOrder = MasterOrder::getOrder($id_order);
     $arrOrderDetails = OrderDetail::getOrderDetailsByIDOrderForCalc($id_order);
     $total = 0;
     foreach ($arrOrderDetails as $orderDetails) {
         //            pr($orderDetails);
         $total = $total + $orderDetails['price'];
     }
     $invoice['sub_total'] = strval($total);
     $order->total_cost = $invoice['sub_total'];
     if ($objResto['service_charge'] > 100) {
         $invoice['service_charge'] = strval($objResto['service_charge']);
     } else {
         $invoice['service_charge'] = strval($objResto['service_charge'] / 100 * $total);
     }
     $order->service_charge = $invoice['service_charge'];
     if ($objResto['other_charge'] > 100) {
         $invoice['other_charge'] = strval($objResto['other_charge']);
     } else {
         $invoice['other_charge'] = strval($objResto['other_charge'] / 100 * $total);
     }
     $order->other_charge = $invoice['other_charge'];
     if ($objResto['disc_mr'] > 100) {
         $invoice['Discount_MR'] = strval($objResto['disc_mr']);
     } else {
         $invoice['Discount_MR'] = strval($objResto['disc_mr'] / 100 * $total);
     }
     $order->disc_mr = $invoice['Discount_MR'];
     if ($objResto['disc_bank'] > 100) {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank']);
     } else {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank'] / 100 * $total);
     }
     $order->disc_bank = $invoice['Discount_Bank'];
     if ($objResto['disc_resto'] > 100) {
         $invoice['Discount_Resto'] = strval($objResto['disc_resto']);
     } else {
         $invoice['Discount_Resto'] = strval($objResto['disc_resto'] / 100 * $total);
     }
     $order->disc_resto = $invoice['Discount_Resto'];
     $invoice['Tax'] = strval($total * ($objResto['tax_pb_1'] / 100));
     $order->tax_pb1 = $invoice['Discount_Resto'];
     $invoice['Total'] = strval($total + $invoice['Tax'] + $invoice['service_charge'] + $invoice['other_charge'] - $invoice['Discount_MR'] - $invoice['Discount_Bank'] - $invoice['Discount_Resto']);
     $order->grand_total = $invoice['Total'];
     $order->save();
     return $invoice;
 }
 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 loadHome()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $cmd = Generic::mustCheck($_GET['cmd'], "No CMD Found");
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         $page = 1;
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         $limit = 10;
     }
     $begin = ($page - 1) * $limit;
     $json = array();
     $sem = array();
     $json['status_code'] = 1;
     if ($cmd == "fav" || $cmd == "nearby") {
         global $db;
         $objRestaurant = new MasterRestaurantModel();
         $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
         $arrPicsToAddPhotoUrl = $objRestaurant->crud_add_photourl;
         $currentLat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
         if (!$currentLat) {
             Generic::errorMsg("No Lat");
         }
         $currentLong = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
         if (!$currentLong) {
             Generic::errorMsg("No Long");
         }
         if ($cmd == "fav") {
             //                $arr = $objRestaurant->getOrderBy("fav DESC  LIMIT $begin,$limit", "*");
             $q = "SELECT *, SQRT(POW(69.1 * (latitude - {$currentLat}), 2) + POW(69.1 * ({$currentLong} - longitude) * COS(latitude / 57.3), 2)) AS distance FROM {$objRestaurant->table_name} WHERE show_in_apps='1' HAVING distance < 1000000 ORDER by fav DESC, DISTANCE ASC  LIMIT {$begin},{$limit}";
             //                echo $q;
             $arr = $db->query($q, 2);
         } elseif ($cmd == "nearby") {
             $q = "SELECT *, SQRT(POW(69.1 * (latitude - {$currentLat}), 2) + POW(69.1 * ({$currentLong} - longitude) * COS(latitude / 57.3), 2)) AS distance FROM {$objRestaurant->table_name} WHERE show_in_apps='1' HAVING distance < 1000000 ORDER by DISTANCE ASC  LIMIT {$begin},{$limit}";
             $arr = $db->query($q, 2);
             if (count($arr) == 0) {
                 Generic::errorMsg("No Count");
                 die;
             }
         }
     } elseif ($cmd == "recommendation") {
         $objRecommendation = new RecommendationModel();
         $exp = explode(",", str_replace(" ", "", $objRecommendation->crud_webservice_allowed));
         $arrPicsToAddPhotoUrl = $objRecommendation->crud_add_photourl;
         $arr = $objRecommendation->getWhere("show_in_apps='1' AND 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;
         }
     } else {
         $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});
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
             $sem['disc_mr'] = MasterOrder::getDiscountMR($o->id_restaurant);
         }
         if ($cmd == "fav" || $cmd == "nearby") {
             $sem["distance"] = sqrt(pow(69.09999999999999 * ($o->latitude - $currentLat), 2) + pow(69.09999999999999 * ($currentLong - $o->longitude) * cos($o->latitude / 57.3), 2));
         }
         if ($cmd == "recommendation") {
             $sem['restaurant'] = User::getRestaurant($o->id_restaurant);
         }
         $json["results"]['restaurant'][] = $sem;
     }
     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 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 function orderNow()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_user = isset($_POST['id_user']) ? addslashes($_POST['id_user']) : "";
     if (!$id_user) {
         Generic::errorMsg("Please login!");
     }
     if (!User::checkUserID($id_user)) {
         Generic::errorMsg("ID User not found!");
     }
     $id_order = isset($_POST['id_order']) ? addslashes($_POST['id_order']) : "";
     if (!$id_order) {
         Generic::errorMsg("ID Order not found!");
     }
     $allergy = isset($_POST['allergy']) ? addslashes($_POST['allergy']) : "";
     $generalNote = isset($_POST['generalNote']) ? addslashes($_POST['generalNote']) : "";
     $objOrder = new MasterOrderModel();
     $arrOrder = $objOrder->getWhere("id_user='******'  AND id_order = '{$id_order}' AND status != '0' AND status_payment = '0' AND order_now = '0'");
     Generic::checkCountWithMsg($arrOrder, "ID Order not found!");
     $id_order = $arrOrder[0]->id_order;
     $dineIn = true;
     if ($arrOrder[0]->type_order == 3) {
         $dineIn = false;
     }
     $id_restaurant = $arrOrder[0]->id_restaurant;
     $arrOrder[0]->datetime_order = $this->setCurrentDate();
     $arrOrder[0]->order_now = "1";
     $arrOrder[0]->datetime_order = leap_mysqldate();
     $arrOrder[0]->generalNote = $generalNote;
     $arrOrder[0]->allergy = $allergy;
     $arrOrder[0]->load = 1;
     $id = $arrOrder[0]->save();
     // cari orderdetails yg id_order
     $objOrderDetails = new OrderDetailModel();
     $arrOrderdetails = $objOrderDetails->getWhere("id_order='{$id_order}'");
     Generic::checkCountWithMsg($arrOrderdetails, "ID Order Details not found!");
     foreach ($arrOrderdetails as $orderdetails) {
         $orderdetails->datetime_order = $this->setCurrentDate();
         $orderdetails->load = 1;
         $orderdetails->save();
     }
     $objTable = new MasterTableModel();
     $objTable->getByID($arrOrder[0]->id_table);
     $objTable->waitingOrder = "1";
     $objTable->load = 1;
     $objTable->save();
     //        pr($objTable);
     $json['results'] = MasterOrder::getOrder($id_order);
     echo json_encode($json);
     $j["id_order"] = $id_order;
     $j['datetime'] = date('Y-m-d H:i:s');
     $msg = $dineIn ? "Table {$objTable->table_number} : New Apps Dine In Order " : "New Apps Take Away Order";
     $pushType = $dineIn ? Push::$typeNotifNewOrder : Push::$typeNotifNewTakeAway;
     $this->pushToRestoCashier($id_restaurant, $msg, $j, $pushType);
     die;
 }