public function acceptInvitation()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_invitation = Generic::mustCheck($_GET['id_invitation'], "NO ID User found!");
     if (!$id_invitation) {
         Generic::errorMsg("NO ID Invitation found!");
     }
     $objInvitation = new InvitationModel();
     $objInvitation->getByID($id_invitation);
     $objInvitation->status = 1;
     $objInvitation->load = 1;
     $id = $objInvitation->save();
     if ($id != "") {
         $json['status_code'] = 1;
         $json['status_message'] = "Link is activate!";
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "Link is expired!";
     }
     echo json_encode($json);
     die;
 }
 public function recommendationRestoWS()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
     if ($lat == "" or !$lat) {
         $lat = MenuRevoConstants::$latitude;
     }
     if (!Generic::checkLatitude($lat)) {
         Generic::errorMsg("Latitude must be Numeric!");
     }
     $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
     if ($long == "" or !$long) {
         $long = MenuRevoConstants::$longitude;
     }
     if (!Generic::checklongitude($long)) {
         Generic::errorMsg("Longitude must be Numeric!");
     }
     $distance = isset($_GET['distance']) ? addslashes($_GET['distance']) : 20;
     if ($distance == '') {
         $distance = 20;
     }
     $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;
     $json = array();
     $json['status_code'] = 1;
     global $db;
     $objRecommendation = new RecommendationModel();
     $objRestaurant = new MasterRestaurantModel();
     $qdish = "SELECT recom.*, SQRT(POW(69.1 * (resto.latitude - {$lat}), 2) + POW(69.1 * ({$long} - resto.longitude) * COS(resto.latitude / 57.3), 2)) AS distance FROM {$objRecommendation->table_name} recom LEFT JOIN {$objRestaurant->table_name} resto ON  resto.id_restaurant= recom.id_restaurant AND DATE(recom.end) >= DATE(NOW()) AND DATE(recom.start)<= DATE(NOW())HAVING distance < {$distance} ORDER BY distance LIMIT {$begin},{$limit}";
     $arrRecom = $db->query($qdish, 2);
     //        if (count($arrRecom) == 0) {
     //            $json['status_code'] = 0;
     //            $json['status_message'] = "No ID Found";
     //            echo json_encode($json);
     //            die();
     //        }
     $json['results']['restaurant'] = array();
     foreach ($arrRecom as $recom) {
         $resto = Generic::getRestaurant($recom->id_restaurant);
         $resto['distance'] = $recom->distance;
         $json['results']['restaurant'][] = $resto;
     }
     echo json_encode($json);
     die;
 }
 public function changeStatusProgress()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_order_detail = isset($_GET['id_order_detail']) ? addslashes($_GET['id_order_detail']) : "";
     if (!$id_order_detail) {
         Generic::errorMsg("id order detail not found!");
     }
     $objOrderDetail = new OrderDetailModel();
     $objOrderDetail->getByID($id_order_detail);
     if ($objOrderDetail->id_order == "") {
         Generic::errorMsg("id order detail not found!");
     }
     $statusProgress = intval($objOrderDetail->status_progress);
     if ($statusProgress == 2) {
         Generic::errorMsg("Status is " . $statusProgress);
     }
     $statusProgress = $statusProgress + 1;
     $objOrderDetail->status_progress = strval($statusProgress);
     $objOrderDetail->load = 1;
     $objOrderDetail->save();
     $json['results'] = $statusProgress;
     echo json_encode($json);
     die;
 }
 public static function mustCheck($what, $errorMsg)
 {
     if (!isset($what) || $what == null) {
         Generic::errorMsg($errorMsg);
     } else {
         return addslashes($what);
     }
 }
 public function extraMenu()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $objHS = new HomeSettingModel();
     $json = array();
     $json['status_code'] = 1;
     $search_type = isset($_GET['search_type']) ? addslashes($_GET['search_type']) : "";
     if (!$search_type) {
         Generic::errorMsg("Search Type is blank!");
     }
     $search_term = isset($_GET['search_term']) ? addslashes($_GET['search_term']) : "";
     if (!search_term) {
         Generic::errorMsg("Search Term is blank!");
     }
 }
 public function setCashOutPaid()
 {
     $idRequest = Generic::mustCheck($_GET['id_request'], "Required ID Request");
     $cashOutModel = new MasterCashOutRequestModel();
     $cashOutModel->getByID($idRequest);
     $restoTrans = new MasterRestoTransactionModel();
     $arrRestoTrans = $restoTrans->getWhere("type_transaction = '2' AND id_request = '{$idRequest}'");
     if (count($arrRestoTrans) <= 0) {
         Generic::errorMsg("Transaction not found");
     }
     if ($cashOutModel->status == "1") {
         Generic::errorMsg("This Request Already Paid");
     }
     $rt = new MasterRestoTransactionModel();
     $rt->getByID($arrRestoTrans[0]->id_transaction);
     $rt->approved = "1";
     $rt->save();
     $cashOutModel->status = "1";
     $cashOutModel->save();
     $json['status_code'] = 1;
     $json['status_message'] = "Request status set to Paid";
     echo json_encode($json);
     die;
 }
 public static function payViaCreditCard($idOrder, $idUser = "")
 {
     $restoInitiate = Generic::IsNullOrEmptyString($idUser);
     $userInitiate = !$restoInitiate;
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     //KALO USER INITIATE CEK APA DIA LEADER
     if ($userInitiate) {
         $user = new UserModel();
         $user->getByID($idUser);
         if (!Util::isLeader($idOrder, $idUser)) {
             Generic::errorMsg(Keys::$ERR_PAYMENT_NOT_LEADER);
         }
     } else {
         $idUser = $order->id_user;
         $user = new UserModel();
         $user->getByID($idUser);
     }
     //CEK APA PEMBAYARAN PAKE CREDIT CARD
     if ($order->payment_method != Keys::$PAYMENT_TYPE_CREDIT_CARD) {
         Generic::errorMsg("This Order Not Using Credit Card as Payment Method");
     }
     Doku_Initiate::$sharedKey = "iMdRs8Iz987Z";
     Doku_Initiate::$mallId = "3199";
     $invoice = new Invoice($idOrder, true);
     $params = array('amount' => Generic::dokuMoneyValue($invoice->grandTotal), 'invoice' => $idOrder, 'currency' => '360');
     $detailOrders = $invoice->orderDetails;
     $basket = array();
     foreach ($detailOrders as $detailOrder) {
         $b = array();
         $b['name'] = $detailOrder->name_dish;
         $b['amount'] = Generic::dokuMoneyValue($detailOrder->single_price);
         $b['quantity'] = $detailOrder->quantity;
         $b['subtotal'] = Generic::dokuMoneyValue($detailOrder->price);
         $basket[] = $b;
     }
     $words = Doku_Library::doCreateWords($params);
     $customer = array('name' => $user->full_name, 'data_phone' => $user->phone_no, 'data_email' => $user->email, 'data_address' => $user->district . ',' . $user->city);
     //        $basket[] = array(
     //            'name' => 'sayur',
     //            'amount' => '10000.00',
     //            'quantity' => '1',
     //            'subtotal' => '10000.00'
     //        );
     //        $basket[] = array(
     //            'name' => 'buah',
     //            'amount' => '10000.00',
     //            'quantity' => '1',
     //            'subtotal' => '10000.00'
     //        );
     $dataPayment = array('req_mall_id' => Doku_Initiate::$mallId, 'req_chain_merchant' => 'NA', 'req_amount' => $params['amount'], 'req_words' => $words, 'req_purchase_amount' => $params['amount'], 'req_trans_id_merchant' => $params['invoice'], 'req_request_date_time' => date('YmdHis'), 'req_currency' => '360', 'req_purchase_currency' => '360', 'req_session_id' => sha1(date('YmdHis')), 'req_name' => $customer['name'], 'req_payment_channel' => '15', 'req_email' => $customer['data_email'], 'req_basket' => $basket, 'req_address' => $customer['data_address'], 'req_token_payment' => $user->payment_token, 'req_customer_id' => $idUser);
     $response = Doku_Api::doDirectPayment($dataPayment);
     if ($response->res_response_code == '0000') {
         $status = "SUCCESS";
         $order->status_payment = Keys::$PAYMENT_STATUS_PAID;
         $order->isPaid = Keys::$YES;
         $order->load = 1;
         $order->save();
         //success
         $trans = new MasterRestoTransactionModel();
         $trans->id_restaurant = $order->id_restaurant;
         $trans->id_request = $order->id_order;
         $trans->gross_amount = $invoice->grandTotal;
         $trans->type_transaction = "1";
         $trans->datetime_transaction = leap_mysqldate();
         $trans->approved = "1";
         $trans->mr_fee = $invoice->valFeeMR;
         //doubleval($order->mr_fee);//((double)($arrOrder[0]->grand_total * $resto->mr_fee)) / 100;
         //TODO LATER CHANGE 3 (BANK FEE) INTO GLOBAL VAR
         $trans->other_fee = 0;
         //((double)($arrOrder[0]->grand_total * $resto->cc_fee)) / 100;
         $trans->bank_disc = $invoice->valDiscBank;
         //doubleval($order->disc_bank);//$objOrder->disc_bank;
         $valNetAmount = doubleval($trans->gross_amount - $trans->mr_fee - $trans->other_fee + $trans->bank_disc);
         $trans->net_amount = $valNetAmount;
         $trans->save();
         //reset user credit to 0
         $user = new UserModel();
         $user->getByID($idUser);
         $user->credit = 0;
         $user->save();
     } else {
         $status = "FAILED";
     }
     $results['status'] = $status;
     $results['res_token_id'] = $user->payment_token;
     $results['invoice_no'] = $idOrder;
     $results['id_user'] = $idUser;
     $results['res_response_code'] = $response->res_response_code;
     $results['doku_results'] = $response;
     //        $results['data_payment'] = $dataPayment;
     //        pr($results);
     if ($status == "SUCCESS") {
         return array("success" => 1, $results);
     } else {
         return array("success" => 0, $results);
     }
     //        Generic::finish($results);
 }
 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 updateStatusProgress()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idDish = $_GET["id_dish"];
     $idOrder = $_GET["id_order"];
     $idResto = $_GET["id_restaurant"];
     //TODO cek id_resto di order header apakah sama degan $Resto
     $objOrder = new MasterOrderModel();
     $arrOrder = $objOrder->getWhere("id_order='{$idOrder}' AND order_now='1' AND status_payment='0'");
     //        $objOrder->getByID($idOrder);
     if ($arrOrder[0]->id_restaurant != $idResto) {
         Generic::errorMsg("ID Resto in Order is not same as id resto!");
     }
     $resto = new MasterRestaurantModel();
     $resto->getByID($idResto);
     $od = new OrderDetailModel();
     $arrOrDetails = $od->getWhere("id_order='{$idOrder}' AND id_dish='{$idDish}' AND status_progress > 3");
     Generic::checkCountWithMsg($arrOrDetails, "Dish already out!");
     //pr($arrOrDetails);
     foreach ($arrOrDetails as $oDetails) {
         if ($oDetails->status_progress < 2) {
             pr($oDetails->status_progress);
             $oDetails->status_progress = $oDetails->status_progress + 1;
             $oDetails->load = 1;
             $oDetails->save();
             $sp = $oDetails->status_progress;
         } else {
             //TODO ERROR order already out
         }
     }
     $order = $this->updateOrderHeaderStatusProgress($idOrder);
     $ids = $order->user_guest_id + "," + $order->id_user;
     $msg = "Your ";
     if ($order->type_order == "0") {
         $msg .= "Dine In ";
     } elseif ($order->type_order == "3") {
         $msg .= "Take Away ";
     } else {
         $json["status_code"] = 1;
         $json["results"]["id_dish"] = $idDish;
         $json["results"]["id_order"] = $idDish;
         $json["results"]["id_restaurant"] = $idDish;
         $json["results"]["status_progress"] = $sp;
         $json["results"]["order_status_progress"] = $order->status_progress;
         echo json_encode($json);
         die;
     }
     $msg .= "order's status at {$resto->name} has been updated";
     $j["id_order"] = $idOrder;
     $json = json_encode($j);
     $_POST["ids"] = $ids;
     $_POST["msg"] = $msg;
     $_POST["json"] = $json;
     $_POST["type"] = 41;
     $p = new PushTo();
     $p->users();
     echo json_encode($json);
     die;
 }
 public function setRestoCategories()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idRestaurant = Generic::mustCheck($_POST['id_restaurant'], Keys::$ERR_NOT_FOUND_ID_RESTAURANT);
     $category = Generic::mustCheck($_POST['categories'], Keys::$ERR_NOT_FOUND_CATEGORIES);
     //category yang di passing harus berupa JSON ARRAY
     $arrNewCategory = json_decode($category);
     foreach ($arrNewCategory as $newCategory) {
         echo $newCategory->category_name . "<br>";
     }
     die;
     $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);
     $other = '[{"category_name":"OTHERS"}]';
     $other = json_decode($other);
     $jsonCategories = json_decode($category);
     foreach ($jsonCategories as $cat) {
         $jsonCategorieshlp[] = $cat->category_name;
     }
     if (!in_array("OTHERS", $jsonCategorieshlp)) {
         $jsonCategories[]['category_name'] = "OTHERS";
     }
     $objCategory = new MasterCategoryModel();
     $idCategories = array();
     foreach ($jsonCategories as $category) {
         $arrCategory = $objCategory->getWhere("name = '{$category->category_name}'");
         if (count($arrCategory) == 0) {
             if (strtoupper($category->category_name) != strtoupper("OTHERS")) {
                 $objCategory->name = strtoupper($category->category_name);
                 //                    echo $objCategory->name;
                 $objCategory->status = "1";
                 $objCategory->is_drink = "0";
                 $objCategory->save();
             }
         }
     }
     foreach ($jsonCategories as $category) {
         $arrCategory = $objCategory->getWhere("name = '{$category->category_name}'");
         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 updateRestoMRFee()
 {
     $idsResto = Generic::mustCheck($_POST['id_restaurant'], "No Restaurant IDs Found");
     $fee = Generic::mustCheck($_POST['fee'], "No Fee Found");
     if (!is_numeric($fee)) {
         Generic::errorMsg("Fee Must Numbers");
     }
     if (doubleval($fee) > 100) {
         Generic::errorMsg("Fee Max 100%");
     }
     $ids = explode(',', $idsResto);
     if (count($ids) <= 0) {
         Generic::errorMsg("Empty Id");
     }
     $updateAll = in_array('0', $ids);
     if ($updateAll) {
         $r = new MasterRestaurantModel();
         $arrR = $r->getAll();
         foreach ($arrR as $singleR) {
             unset($resto);
             $resto = new MasterRestaurantModel();
             $resto->getByID($singleR->id_restaurant);
             $log = new LogDiscFeeModel();
             $log->id_reference = $singleR->id_restaurant;
             $log->change_type = "Fee MR";
             $log->change_from = Generic::IsNullOrEmptyString($resto->mr_fee) ? "0" : $resto->mr_fee;
             $log->change_to = $fee;
             $log->change_date_time = leap_mysqldate();
             $log->save();
             $resto->mr_fee = $fee;
             $resto->save();
         }
     } else {
         foreach ($ids as $id) {
             unset($resto);
             $resto = new MasterRestaurantModel();
             $resto->getByID($id);
             $log = new LogDiscFeeModel();
             $log->id_reference = $id;
             $log->change_type = "Fee MR";
             $log->change_from = Generic::IsNullOrEmptyString($resto->mr_fee) ? "0" : $resto->mr_fee;
             $log->change_to = $fee;
             $log->change_date_time = leap_mysqldate();
             $log->save();
             $resto->mr_fee = $fee;
             $resto->save();
         }
     }
     $json['status_code'] = 1;
     $json['status_message'] = "success";
     echo json_encode($json);
     die;
 }
 public function clearTable()
 {
     $idTable = Generic::mustCheck($_GET['id_table']);
     $d = Util::clearTable($idTable);
     if ($d) {
         Generic::finish($d);
     } else {
         Generic::errorMsg("Failed");
     }
 }
 public function settlePayment()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $id_order = $_GET["id_order"];
     $id_user = $_GET["id_user"];
     $user = new UserModel();
     $user->getByID($id_user);
     $order = new MasterOrderModel();
     $order->getByID($id_order);
     $objResto = new MasterRestaurantModel();
     $objResto->getByID($order->id_restaurant);
     if ($user->payment_id == null || $user->payment_id == "0") {
         Generic::errorMsg("No Payment Method");
     }
     try {
         $result = Braintree_PaymentMethodNonce::create($user->braintree_id);
         $nonce = $result->paymentMethodNonce->nonce;
         $resultSale = Braintree_Transaction::sale(['amount' => $order->grand_total, 'paymentMethodNonce' => $nonce, 'options' => ['submitForSettlement' => True]]);
     } catch (Exception $e) {
         Generic::errorMsg($e->getMessage());
     }
     //        $transaction = $resultSale->transaction;
     //        $order->transaction_id = $transaction->id;
     //        $order->load = 1;
     //        $order->status_payment = '1';
     //        $orderObj->nonce_cc = $nonce;
     //        $order->isPaid = '1';
     //        $order->save();
     pr($resultSale);
     //        $json['results'] = "Your Payment was successful with ID Order " . $id_order;
     //        echo json_encode($json);
     //,
     //                        'descriptor' => [
     //                            'name' => $objResto->name . " - " . $objResto->order_number
     //                        ]
     //        die();
 }
 public function searchDish()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $resto = "resto";
     $json = array();
     $json['status_code'] = 1;
     $search = isset($_GET['name']) ? addslashes($_GET['name']) : "";
     $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
     if ($lat == "" or !$lat) {
         $lat = MenuRevoConstants::$latitude;
     }
     if (!Generic::checkLatitude($lat)) {
         Generic::errorMsg("Latitude must be Numeric!");
     }
     $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
     if ($long == "" or !$long) {
         $long = MenuRevoConstants::$longitude;
     }
     if (!Generic::checklongitude($long)) {
         Generic::errorMsg("Longitude must be Numeric!");
     }
     $nearby = isset($_GET['nearby']) ? addslashes($_GET['nearby']) : 20;
     if ($nearby == '1') {
         $nearby = 20;
     } else {
         $nearby = 100000;
     }
     $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 = "  CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') >= (CONVERT_TZ(concat(CURRENT_DATE,' ',resto.time_open),@@session.time_zone, '+00:00' )) AND CONVERT_TZ(NOW(),@@session.time_zone, '+00:00') < (CONVERT_TZ(concat(CURRENT_DATE,' ',resto.time_close),@@session.time_zone, '+00:00' ))";
     }
     $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 dish.name LIKE '%{$search}%' ";
     if ($whereOption != "") {
         $where = $where . " AND " . $whereOption;
     }
     foreach ($arrWhere as $key => $val) {
         $where = $where . " AND {$resto}" . ".{$key}= '{$val}'";
     }
     foreach ($arrWhereOr as $key => $val) {
         $where = $where . " AND {$resto}" . ".{$key} != '0'";
     }
     $sort = $nearby . " ORDER BY ";
     foreach ($arrSort as $key => $val) {
         if ($key == "distance") {
             $sort = $sort . " {$key} ASC,";
         } elseif ($key == "fav") {
             $sort = $sort . " {$resto}" . ".{$key} DESC,";
         } elseif ($key == "houropen") {
             $sort = $sort . " {$resto}" . ".{$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();
     $objDish = new MasterDishModel();
     $qdish = "SELECT dish.*, resto.name as nama_restaurant, SQRT(POW(69.1 * (resto.latitude - {$lat}), 2) + POW(69.1 * ({$long} - resto.longitude) * COS(resto.latitude / 57.3), 2)) AS distance" . " FROM  {$objDish->table_name} dish LEFT JOIN {$objRestaurant->table_name} resto ON dish.id_restaurant=resto.id_restaurant " . $where . $sort . " LIMIT {$begin},{$limit}";
     //        echo $qdish. "<br>";
     $arrDish = $db->query($qdish, 2);
     if (count($arrDish) == 0) {
         Generic::errorMsg("No Food found!");
     }
     $arrDishHelp = array();
     foreach ($arrDish as $dish) {
         $dishhlp = MasterDish::getDish($dish->id_dish);
         $dishhlp['distance'] = $dish->distance;
         $dishhlp['nama_restaurant'] = $dish->nama_restaurant;
         $arrDishHelp[] = $dishhlp;
     }
     //
     //
     //        $qResto = "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  ;
     ////        echo $qResto;
     //        $arrResto = $db->query($qResto, 2);
     //        $checkCountResto = false;
     //        $arrDishHelp = array();
     //        foreach ($arrResto as $restoID) {
     //
     //            $arrSearchDish = $objDish->getWhere("name LIKE '%$search%' AND availability='1' AND id_restaurant='$restoID->id_restaurant' LIMIT $begin,$limit");
     //
     //            if (count($arrSearchDish) > 0) {
     //                $checkCountResto = true;
     //                $jarak = $restoID->distance;
     //
     //                foreach ($arrSearchDish as $dish) {
     //                    $dish = MasterDish::getDish($dish->id_dish);
     //                    $dish['distance'] = $jarak;
     //                    $dish['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($dish['id_restaurant']);
     //                    $arrDishHelp[] = $dish;
     //                }
     //
     //            }
     //
     //        }
     //
     //        if (!$checkCountResto) {
     //            Generic::errorMsg("No Food found!");
     //        }
     $json['results']['Dish'] = $arrDishHelp;
     echo json_encode($json);
     die;
 }
 public function getCategoriesByResto()
 {
     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) {
         Generic::errorMsg("No Restaurant ID Found");
     }
     $objResto = new MasterRestaurantModel();
     $objResto->getByID($id_restaurant);
     $categories = $objResto->id_categories;
     //        if (Generic::IsNullOrEmptyString($categories)) ;
     $json['results']['categories'] = array();
     $arrCategories = explode(",", $categories);
     foreach ($arrCategories as $idCat) {
         $json['results']['categories'][] = self::getCategoryNameByID($idCat);
     }
     $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;
             }
         }
     }
     $json['results']['raw_tags'] = $rawTags;
     echo json_encode($json);
     die;
 }
 public function updateRestoUserStatus()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $id_restaurant = isset($_POST['id_restaurant']) ? addslashes($_POST['id_restaurant']) : "";
     if (!$id_restaurant) {
         Generic::errorMsg("NO Restaurant ID");
     }
     $id_user = isset($_POST['id_user']) ? addslashes($_POST['id_user']) : "";
     if (!$id_user) {
         Generic::errorMsg("User ID?");
     }
     $rUser = new RestaurantUserModel();
     $rUser->getByID($id_user);
     if ($rUser->id_restaurant != $id_restaurant) {
         Generic::errorMsg("Mismatched");
     }
     if ($rUser->status == "1") {
         $rUser->status = "0";
     } else {
         $rUser->status = "1";
     }
     $rUser->save();
     $json = array();
     $json['status_code'] = 1;
     $a["message"] = "success";
     $json['results'] = $a;
     $this->getAllActiveRestoUser();
 }
 public function repositionTables()
 {
     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) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $jsonTables = isset($_POST['tables']) ? $_POST['tables'] : "";
     if (!$jsonTables) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $jsonArrayTables = json_decode($jsonTables);
     //        pr($jsonArrayTables);
     $countjsonArrayTables = count($jsonArrayTables);
     //        pr($countTables);
     $objResto = new MasterRestaurantModel();
     $arrResto = $objResto->getWhere("id_restaurant='{$id_restaurant}'");
     MasterDish::checkCount($arrResto);
     $countTablesinResto = $arrResto[0]->table_quantity;
     //        pr($arrResto);
     $objTable = new MasterTableModel();
     $arrTable = $objTable->getWhere("id_restaurant='{$id_restaurant}'");
     if ($countTablesinResto != $countjsonArrayTables) {
         Generic::errorMsg("Wrong Quantity");
     }
     //        $break = false;
     //        foreach ($jsonArrayTables as $key => $objTables) {
     ////
     //            $arrReposTable = $objTable->getWhere("id_restaurant='$id_restaurant' AND id_table='$objTables->table_id' ");
     //            if (count($arrReposTable) == 0) {
     //                $break = true;
     //                $msg = $msg . " $objTables->table_id can't find in database.";
     //            }
     //        }
     //        if ($break == false) {
     //            foreach ($jsonArrayTables as $key => $objTables) {
     //                $arrReposTable = $objTable->getWhere("id_restaurant='$id_restaurant' AND id_table='$objTables->table_id' ");
     ////               $arrReposTable[0]->table_position = $key + 1;
     //                $arrReposTable[0]->load = 1;
     //                $arrReposTable[0]->save();
     //            }
     //        }
     $counter = 1;
     foreach ($jsonArrayTables as $jsonObjTable) {
         $table = new MasterTableModel();
         $table->getByID($jsonObjTable->table_id);
         $table->table_position = $counter;
         $table->save();
         $counter++;
     }
     $json['status_code'] = 1;
     $json['results']['message'] = "success";
     echo json_encode($json);
     die;
 }
 public function updateRestoMRDiscount()
 {
     $idsResto = Generic::mustCheck($_POST['id_restaurant'], "No Restaurant IDs Found");
     $disc = Generic::mustCheck($_POST['discount'], "No Discount Found");
     if (!is_numeric($disc)) {
         Generic::errorMsg("Discount Must Numbers");
     }
     if (strlen(trim($disc)) > 2) {
         Generic::errorMsg("Discount Max 2 Digits");
     }
     $ids = explode(',', $idsResto);
     if (count($ids) <= 0) {
         Generic::errorMsg("Empty Id");
     }
     $updateAll = in_array('0', $ids);
     if ($updateAll) {
         $r = new MasterRestaurantModel();
         $arrR = $r->getAll();
         foreach ($arrR as $singleR) {
             unset($resto);
             $resto = new MasterRestaurantModel();
             $resto->getByID($singleR->id_restaurant);
             unset($logdisc);
             $logdisc = new LogDiscFeeModel();
             $logdisc->id_reference = $resto->id_restaurant;
             $logdisc->change_type = "Discount MR";
             $logdisc->change_from = Generic::IsNullOrEmptyString($resto->disc_mr) ? "0" : $resto->disc_mr;
             $logdisc->change_to = $disc;
             $logdisc->change_date_time = leap_mysqldate();
             $logdisc->save();
             $resto->disc_mr = $disc;
             $resto->save();
         }
     } else {
         foreach ($ids as $id) {
             unset($resto);
             $resto = new MasterRestaurantModel();
             $resto->getByID($id);
             unset($logdisc);
             $logdisc = new LogDiscFeeModel();
             $logdisc->id_reference = $resto->id_restaurant;
             $logdisc->change_type = "Discount MR";
             $logdisc->change_from = Generic::IsNullOrEmptyString($resto->disc_mr) ? "0" : $resto->disc_mr;
             $logdisc->change_to = $disc;
             $logdisc->change_date_time = leap_mysqldate();
             $logdisc->save();
             $resto->disc_mr = $disc;
             $resto->save();
         }
     }
     $json['status_code'] = 1;
     $json['status_message'] = "success";
     echo json_encode($json);
     die;
 }
 public function revoPromo()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
     if (!$lat) {
         Generic::errorMsg("Not Latitude");
     }
     $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
     if (!$long) {
         Generic::errorMsg("Not Longitude");
     }
     $distance = isset($_GET['distance']) ? addslashes($_GET['distance']) : 20;
     if (!$distance) {
         Generic::errorMsg("Not Distance");
     }
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         Generic::errorMsg("Not found Page");
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         Generic::errorMsg("Not found limit!");
     }
     $begin = ($page - 1) * $limit;
     $objPromo = new PromoModel();
     $json = array();
     $json['status_code'] = 1;
     $objResto = new MasterRestaurantModel();
     global $db;
     $q = "SELECT {$objPromo->table_name}.*, SQRT(POW(69.1 * ({$objResto->table_name}.latitude - {$lat}), 2) + POW(69.1 * ({$long} - {$objResto->table_name}.longitude) * COS({$objResto->table_name}.latitude / 57.3), 2)) AS distance\nFROM {$objPromo->table_name} INNER JOIN {$objResto->table_name} ON {$objPromo->table_name}.aktiv=1 AND {$objPromo->table_name}.id_restaurant={$objResto->table_name}.id_restaurant  HAVING distance < {$distance} ORDER BY distance   LIMIT {$begin},{$limit}";
     $arr = $db->query($q, 2);
     if (count($arr) == 0) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $exp = explode(",", str_replace(" ", "", $objPromo->crud_webservice_allowed));
     //tmbh untuk add photo url
     $arrPicsToAddPhotoUrl = $objPromo->crud_add_photourl;
     foreach ($arr as $o) {
         $sem = array();
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = _BPATH . _PHOTOURL . $o->{$attr};
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
         }
         $sem["jarak"] = $o->distance;
         $json["results"][] = $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 pushByLocation()
 {
     $idUsers = Generic::mustCheck($_POST['id_users'], "IDs User not Found");
     $title = Generic::mustCheck($_POST['title'], "Title not Found");
     $message = Generic::mustCheck($_POST['message'], "Message not Found");
     $image = Generic::IsNullOrEmptyString($_POST['image']) ? "" : $_POST['image'];
     if (Generic::IsNullOrEmptyString($idUsers)) {
         Generic::errorMsg("Empty IDs User");
     }
     $arrIdUser = explode(',', $idUsers);
     $results['id_users'] = $idUsers;
     $results['title'] = $title;
     $results['message'] = $message;
     $results['image'] = $image;
     $trackerModel = Util::getTrackerModelByCode(Keys::$TRACKER_PUSH);
     if (!$trackerModel) {
         Generic::errorMsg("Failed To Fetch Tracker Model");
     } else {
         $trackerModel->title = $title;
         $trackerModel->message = $message;
         $trackerModel->image = $image;
         $trackerModel->id_from = 0;
         $trackerModel->id_reference = 0;
         $trackerModel->id_to = $idUsers;
         $trackerModel->readed = "0";
         $trackerModel->answered = "1";
         $trackerModel->canceled = "0";
         $trackerModel->status = "1";
         $trackerModel->type = Push::$typeMRPushByLocation;
         $idTracker = $trackerModel->save();
     }
     foreach ($arrIdUser as $idUser) {
         //saving log
         $pLog = new MasterPushLoggerModel();
         $pLog->from_id = 0;
         $pLog->to_id = $idUser;
         $pLog->title = $title;
         $pLog->message = $message;
         //type 3 : MR to User
         $pLog->type = Push::$pushLogMRToUser;
         $pLog->push_code = Push::$typeMRPushByLocation;
         $pLog->datetime_notif = leap_mysqldate();
         $pLog->id_reference = $image;
         $pLog->status = "1";
         $pLog->save();
     }
     $_POST["ids"] = implode(',', $arrIdUser);
     $_POST["msg"] = $title;
     $_POST["json"] = $idTracker;
     //json_encode($j);
     $_POST["type"] = Push::$typeMRPushByCuisine;
     $push = new PushTo();
     $results['user_count'] = count($arrIdUser);
     $results['push'] = $push->usersMR();
     Generic::finish($results);
 }
 public function getBTToken()
 {
     $aCustomerId = $_POST["id_user"];
     $user = new UserModel();
     $user->getByID($aCustomerId);
     if ($user->device_ids == null || $user->device_ids == "") {
         if (!$this->createCust($user)) {
             Generic::errorMsg("error user not created");
             die;
         }
     } else {
         $customer = Braintree_Customer::find($aCustomerId);
         pr($customer);
         $aCustomerId = $customer->id;
         //            die();
     }
     $clientToken = Braintree_ClientToken::generate(["customerId" => $aCustomerId]);
     echo "{\"status_code\":1,\"results\":{\"btok\":\"{$clientToken}\"}}";
     die;
 }
 public function reportWS()
 {
     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 Restaurant found!";
         echo json_encode($json);
         die;
     }
     $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;
     }
     // 3 jenis search type, server_id, resto dan server
     //        $search = isset($_GET['search']) ? addslashes($_GET['search']) : "server_id";
     //
     //        if (!$search) {
     //            $json['status_code'] = 0;
     //            $json['status_message'] = "No Time range found!";
     //            echo json_encode($json);
     //            die();
     //        }
     //
     // Order_type = 0 => Dine in
     // order_type = 1> take away
     $order_type = isset($_GET['order_type']) ? addslashes($_GET['order_type']) : "0";
     if ($order_type) {
         $json['status_code'] = 0;
         $json['status_message'] = "No order_type found!";
         echo json_encode($json);
         die;
     }
     // order_via = 0 => cashier
     // order_via = 1=> apps
     //        $order_via = isset($_GET['order_via']) ? addslashes($_GET['order_via']) : "0";
     //
     //        if (!$order_via) {
     //            $json['status_code'] = 0;
     //            $json['status_message'] = "No Order via found!";
     //            echo json_encode($json);
     //            die();
     //        }
     $where = "";
     if ($order_type == "0") {
         $where = " type_order='0'";
     } elseif ($order_type == "1") {
         $where = " type_order='1'";
     } elseif ($order_type == "2") {
         $where = " type_order='2'";
     } elseif ($order_type == "3") {
         $where = " type_order='3'";
     }
     $objOrder = new MasterOrderModel();
     $objTable = new MasterTableModel();
     $objResto = new MasterRestaurantModel();
     global $db;
     $q = "SELECT CAST(o.datetime_order as DATE) as DATE, SUM(o.grand_total) as total_sales FROM {$objOrder->table_name} o RIGHT JOIN {$objTable->table_name} b ON o.id_table=b.id_table INNER JOIN {$objResto->table_name} resto ON resto.id_restaurant=b.id_restaurant AND resto.id_restaurant='{$id_restaurant}' WHERE o.status_payment='1' AND  DATE_SUB(CURRENT_DATE, INTERVAL " . $time_range . " MONTH) <= o.datetime_order AND " . $where . "  GROUP BY CAST(DATE AS DATE) ";
     // $q = "SELECT o.datetime_order as DATE, SUM(o.total_cost) as total_sales FROM {$objOrder->table_name} o RIGHT JOIN {$objTable->table_name} b ON o.id_table=b.id_table INNER JOIN {$objResto->table_name} resto ON resto.id_restaurant=b.id_restaurant AND resto.id_restaurant='$id_restaurant' WHERE o.status_payment='1' AND DATE_SUB(CURRENT_DATE, INTERVAL " . $time_range . " MONTH) <= o.datetime_order AND " . $where .  " GROUP BY DATE";
     //        $q = "SELECT o.*, b.id_restaurant, resto.name FROM {$objOrder->table_name} o LEFT JOIN {$objTable->table_name} b ON o.id_table=b.id_table INNER JOIN {$objResto->table_name} resto ON resto.id_restaurant=b.id_restaurant WHERE o.isPaid=1 AND DATE_SUB(CURRENT_DATE, INTERVAL ". $time_range ." MONTH) <= o.datetime_order ORDER BY o.datetime_order ASC";
     //        echo $q;
     $arrOrder = $db->query($q, 2);
     if (count($arrOrder) == 0) {
         Generic::errorMsg("No Sales founded!");
     }
     foreach ($arrOrder as $val) {
         $help[] = $val;
     }
     //        pr($arrOrder);
     $json['results'] = $help;
     echo json_encode($json);
     die;
 }