public static function getRestaurantUser($id_user)
 {
     $objRestoUser = new RestaurantUserModel();
     $arrRestoUser = $objRestoUser->getWhere("id_user='******'");
     MasterDish::checkCount($arrRestoUser);
     $exp = explode(",", str_replace(" ", "", $objRestoUser->crud_webservice_allowed));
     $sem = array();
     foreach ($arrRestoUser as $o) {
         foreach ($exp as $attr) {
             $sem[$attr] = stripslashes($o->{$attr});
         }
     }
     return $sem;
 }
 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 static function getOrderDetailsByIDOrderAndUserID($id_order, $id_user)
 {
     $objOrderDetails = new OrderDetailModel();
     $objUser = new UserModel();
     $objUser->getByID($id_user);
     $arrOrderDetails = $objOrderDetails->getWhere("id_order='{$id_order}' AND id_user='******'");
     //        MasterDish::checkCount($arrOrderDetails);
     if (count($arrOrderDetails) > 0) {
         $exp = explode(",", str_replace(" ", "", $objOrderDetails->crud_webservice_allowed));
         $orderdetails = array();
         foreach ($arrOrderDetails as $order) {
             $sem = array();
             foreach ($exp as $attr) {
                 $sem[$attr] = stripslashes($order->{$attr});
             }
             $sem['name'] = MasterDish::getDishNameByID($order->id_dish);
             $sem['image_user'] = _BPATH . _PHOTOURL . $objUser->pic;
             $orderdetails[] = $sem;
         }
     }
     return $orderdetails;
 }
 public static function getAllOrderDetailsByIDOrder($id_order)
 {
     $objOrderDetails = new OrderDetailModel();
     $arrOrderDetails = $objOrderDetails->getWhere("id_order='{$id_order}' ORDER BY status_progress ASC, id_dish ASC");
     //        MasterDish::checkCount($arrOrderDetails);
     $orderdetails = array();
     if (count($arrOrderDetails) > 0) {
         $exp = explode(",", str_replace(" ", "", $objOrderDetails->crud_webservice_allowed));
         foreach ($arrOrderDetails as $order) {
             $sem = array();
             foreach ($exp as $attr) {
                 $sem[$attr] = stripslashes($order->{$attr});
             }
             $sem['name'] = MasterDish::getDishNameByID($order->id_dish);
             $orderdetails[] = $sem;
         }
     }
     return $orderdetails;
 }
 public function restoUserLogin()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $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;
     }
     $pin = isset($_POST['pin']) ? addslashes($_POST['pin']) : "";
     if (!$pin) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $json = array();
     $json['status_code'] = 1;
     $objRestoUsers = new RestaurantUserModel();
     $arrRestoUsers = $objRestoUsers->getWhere("id_restaurant = '{$id_restaurant}' AND pin_password='******' AND status='1'");
     MasterDish::checkCount($arrRestoUsers);
     $sem = array();
     foreach ($arrRestoUsers as $val) {
         $sem['user'] = RestaurantUser::getRestaurantUser($val->id_user);
     }
     $json['results'] = $sem;
     echo json_encode($json);
     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 viewOrderDetail()
    {
        $id_order = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : "";
        global $db;
        //        $id_order = '350';
        $q = "SELECT * FROM menurevo__order_detail WHERE id_order='{$id_order}'";
        $arrOrderDetail = $db->query($q, 2);
        $q = "SELECT * FROM menurevo__ms_order WHERE id_order='{$id_order}'";
        $arrOrder = $db->query($q, 2);
        //         echo $q;
        ?>

        <div class="well">

            <table class="table responsive"style="background: #dedede; width: 100%;" >
                <tr>
                    <td style="width: 50%;">

                        <h2>Take Away Order ID <?php 
        echo $id_order;
        ?>
                            , Order No. <?php 
        echo $arrOrder[0]->order_number;
        ?>
</h2>
                        <br>
                        <table class="table responsive" style="background: #dedede;">
                            <tr >
                                <td>
                                    Server : <?php 
        echo $arrOrder[0]->server_name;
        ?>
                                </td> 
                                <td style="text-align: right;">
                                    <?php 
        echo $arrOrder[0]->datetime_order;
        ?>
                                </td> 
                            </tr>  
                            <tr>
                                <td>
                                    Total :
                                </td>
                                <td style="text-align: right;">
                                    <?php 
        echo Generic::formatRupiah($arrOrder[0]->total_cost);
        ?>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Disc Resto :
                                </td>
                                <td style="text-align: right;">
                                    <?php 
        echo Generic::formatRupiah($arrOrder[0]->disc_resto);
        ?>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Disc Bank :
                                </td>
                                <td style="text-align: right;">
                                    <?php 
        echo Generic::formatRupiah($arrOrder[0]->disc_bank);
        ?>
                                </td>

                            </tr>
                            <tr>
                                <td>
                                    Tax PB1 :
                                </td>
                                <td style="text-align: right;">
                                    <?php 
        echo Generic::formatRupiah($arrOrder[0]->tax_pb1);
        ?>
                                </td>

                            </tr>
                            <tr>
                                <td>
                                    Service Charge :
                                </td>
                                <td style="text-align: right;">
                                    <?php 
        echo Generic::formatRupiah($arrOrder[0]->service_charge);
        ?>
                                </td>

                            </tr>

                            <tr>
                                <td>
                                    Other Charge :
                                </td>
                                <td style="text-align: right;">
                                    <?php 
        echo Generic::formatRupiah($arrOrder[0]->other_charge);
        ?>
                                </td>

                            </tr>

                            <tr>
                                <td style="font-size: large;">
                                    <strong> Grand Total : </strong>
                                </td>
                                <td style="text-align: right; font-size: large;">
                                    <strong><?php 
        echo Generic::formatRupiah($arrOrder[0]->grand_total);
        ?>
 </strong>
                                </td>
                            </tr>

                            <tr>
                                <td style="font-size: large;">

                                </td>
                                <td style="text-align: right; font-size: medium;">
                                    <button id='close_<?php 
        echo $id_order;
        ?>
'><strong>Close</strong></button>
                                </td>
                            <script>
                                $('#close_<?php 
        echo $id_order;
        ?>
').click(function () {
                                    lwclose(window.selected_page);
                                });
                            </script>
                </tr>
            </table>
        </td>
        <td style="width: 50%;">
            <table class="table responsive" style="background: #dedede;vertical-align:middle;border-radius: 25px;">
                <tr >

                    <td style="border-top:0px;border-bottom:1px;"> <h2>Order Details</h2>

                    </td>

                </tr>
                <?php 
        foreach ($arrOrderDetail as $detail) {
            ?>
                    <tr style="border-bottom:1px;border-top:1px;">
                        <td><h3><strong><?php 
            echo $detail->quantity;
            ?>
</strong></h3></td>
                        <td><?php 
            echo MasterDish::getDishNameByID($detail->id_dish);
            ?>
                            <br/>
                            <?php 
            echo Generic::formatRupiah($detail->price);
            ?>
</td>
                        <td><?php 
            //= $detail->status;
            ?>
                            <button type="button" id="button6"  style="width: 100%;" class="btn btn-success">Paid</button>
                        </td>
                    </tr>
                    <?php 
        }
        ?>
            </table>
            <?php 
        //                        pr($arrOrderDetail);
        ?>
</td>
        </tr>
        </table>


        </div>
        <?php 
    }
 public function getRestoTables()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_restaurant = isset($_GET['id_restaurant']) ? addslashes($_GET['id_restaurant']) : "";
     if (!$id_restaurant) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $objTable = new MasterTableModel();
     global $db;
     //        $q = "SELECT * FROM {$objTable->table_name} WHERE id_restaurant='$id_restaurant' ORDER BY table_position ASC";
     //        $arrTable = $db->query($q, 2);
     $arrTable = $objTable->getWhere("id_restaurant='{$id_restaurant}' ORDER BY table_position ASC");
     MasterDish::checkCount($arrTable);
     $exp = explode(",", str_replace(" ", "", $objTable->crud_webservice_allowed));
     //        pr($arrTable);
     $semTable = array();
     foreach ($arrTable as $table) {
         foreach ($exp as $attr) {
             $semTable[$attr] = $table->{$attr};
         }
         $json['results']['Table'][] = $semTable;
     }
     $objResto = new MasterRestaurantModel();
     $arrResto = $objResto->getWhere("id_restaurant='{$id_restaurant}'");
     MasterDish::checkCount($arrResto);
     foreach ($arrResto as $key => $index) {
         $json['results']['Table Col'] = $arrResto[$key]->table_column;
         $json['results']['Table Qty'] = $arrResto[$key]->table_quantity;
     }
     echo json_encode($json);
     die;
 }
 public function loadRestoDishNearBy()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $distance = isset($_GET['distance']) ? addslashes($_GET['distance']) : 20;
     if (!$distance) {
         Generic::errorMsg("Not Distance");
     }
     $lat = isset($_GET['latitude']) ? addslashes($_GET['latitude']) : "";
     if (!$lat) {
         Generic::errorMsg("No Lat");
     }
     $long = isset($_GET['longitude']) ? addslashes($_GET['longitude']) : "";
     if (!$long) {
         Generic::errorMsg("No longitude");
     }
     $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;
     $objRestaurant = new MasterRestaurantModel();
     $objDish = new MasterDishModel();
     global $db;
     $q = "SELECT *,SQRT(POW(69.1 * (latitude - {$lat}), 2) + POW(69.1 * ({$long} - longitude) * COS(latitude / 57.3), 2)) AS distance\nFROM {$objRestaurant->table_name} HAVING distance < {$distance} ORDER BY distance";
     $arrResto = $db->query($q, 2);
     MasterDish::checkCount($arrResto);
     $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
     //tmbh untuk add photo url
     $arrPicsToAddPhotoUrl = $objRestaurant->crud_add_photourl;
     $arrPicsDishToAddPhotoUrl = $objRestaurant->crud_add_photourl;
     $json['results']['Dish'] = array();
     $arrDishHelp = array();
     $qdish = "SELECT objDish.*, SQRT(POW(69.1 * (objDish.latitude - {$lat}), 2) + POW(69.1 * ({$long} - objDish.longitude) * COS(objDish.latitude / 57.3), 2)) AS distance" . " FROM (SELECT menurevo__ms_dish.*, menurevo__ms_restaurant.latitude, menurevo__ms_restaurant.longitude FROM menurevo__ms_dish LEFT JOIN menurevo__ms_restaurant ON menurevo__ms_dish.id_restaurant = menurevo__ms_restaurant.id_restaurant ORDER BY menurevo__ms_dish.fav DESC)as objDish " . "GROUP BY objDish.id_restaurant HAVING distance < 20 ORDER BY distance ASC LIMIT {$begin},{$limit}";
     //            echo $qdish;
     $arrDish = $db->query($qdish, 2);
     $arrDishHelp = array();
     foreach ($arrDish as $dish) {
         $jarak = $dish->distance;
         $dish = MasterDish::getDish($dish->id_dish);
         $dish['distance'] = $jarak;
         $dish['nama_restaurant'] = MasterRestaurant::getRestoNameByIDResto($dish['id_restaurant']);
         $arrDishHelp[] = $dish;
     }
     $json['results']['Dish'] = $arrDishHelp;
     echo json_encode($json);
     die;
 }
 public static function getOrder($id_order)
 {
     $objOrder = new MasterOrderModel();
     $arrOrder = $objOrder->getWhere("id_order = '{$id_order}' ORDER BY id_order asc");
     MasterDish::checkCount($arrOrder);
     $exp = explode(",", str_replace(" ", "", $objOrder->crud_webservice_allowed));
     $sem = array();
     foreach ($arrOrder as $o) {
         foreach ($exp as $attr) {
             $sem[$attr] = stripslashes($o->{$attr});
         }
         if ($o->id_table != 0) {
             $table = new MasterTableModel();
             $table->getByID($o->id_table);
             $sem["table_number"] = $table->table_number;
         }
     }
     return $sem;
 }
 public static function getCategoryNameByID($id_category)
 {
     $objCategory = new MasterCategoryModel();
     $arrCat = $objCategory->getWhere("id_category='{$id_category}' LIMIT 1");
     MasterDish::checkCount($arrCat);
     //        echo $arrCat[0]->name;
     return $arrCat[0]->name;
 }