public function overwriteRead($return)
 {
     $objs = $return['objs'];
     foreach ($objs as $obj) {
         if (isset($obj->id_restaurant)) {
             $resto = new MasterRestaurantModel();
             $resto->getByID($obj->id_restaurant);
             $obj->id_restaurant = $resto->name;
         }
         if (isset($obj->id_bank)) {
             $bank = new BankModel();
             $bank->getByID($obj->id_bank);
             $obj->id_bank = $bank->bank_name;
         }
         if (isset($obj->start_fee)) {
             $date = new DateTime($obj->start_fee);
             $obj->start_fee = $date->format('d.m.Y');
         }
         if (isset($obj->end_fee)) {
             $dateEnd = new DateTime($obj->end_fee);
             $obj->end_fee = $dateEnd->format('d.m.Y');
         }
     }
     return $return;
 }
    public function overwriteRead($return)
    {
        $objs = $return['objs'];
        foreach ($objs as $obj) {
            $obj->removeAutoCrudClick = array("status");
            if (isset($obj->status)) {
                $idR = $obj->id_request;
                if ($obj->status == "1") {
                    $obj->status = '<button type="button" id="button' . $idR . '" onclick="updateStatusCashout(' . $obj->status . ',' . $idR . ')" style="width: 100%;" class="btn btn-success">Paid</button>';
                } else {
                    if ($obj->status == "0") {
                        $obj->status = '<button type="button" id="button' . $idR . '" onclick="updateStatusCashout(' . $obj->status . ',' . $idR . ')" style="width: 100%;" class="btn btn-danger">Pay Now</button>';
                    }
                }
            }
            if (isset($obj->id_restaurant)) {
                if ($obj->id_restaurant != "") {
                    $r = new MasterRestaurantModel();
                    $r->getByID($obj->id_restaurant);
                    $obj->id_restaurant = $r->name;
                }
            }
            if (isset($obj->datetime_request)) {
                $d = strtotime("{$obj->datetime_request}");
                $obj->datetime_request = date("d M, y h:m a", $d);
            }
        }
        ?>
        <script>
            function updateStatusCashout(status, id) {
                if (status == "1") {
                    alert("ID " + id + " Already Paid");
                    return;
                } else {
                    if (!confirm("Set Request to Paid?")) {
                        return;
                    }
                }

                $.ajax({
                    method: "GET",
                    url: _sppath + "MasterCashOutRequest/setCashOutPaid",
                    data: {id_request: id}
                })
                    .done(function (msg) {
                        console.log(msg);
                        var json_obj = $.parseJSON(msg);//parse JSON
                        var statusCode = json_obj.status_code;
                        if (statusCode == 0) {
                            alert(json_obj.status_message);
                        } else {
                            alert(json_obj.status_message);
                        }
                        lwrefresh('CashOutRequest');
                    });
            }
        </script>
        <?php 
        return $return;
    }
 public function overwriteForm($return, $returnfull)
 {
     $return['status'] = new Leap\View\InputSelect(array("1" => "Free", "0" => "Occupied"), "status", "status", $this->status);
     $return['availability'] = new Leap\View\InputSelect(array("1" => "Active", "0" => "Inactive"), "availability", "availability", $this->availability);
     $resto = new MasterRestaurantModel();
     $resto->getByID($this->id_restaurant);
     $return['id_restaurant'] = new \Leap\View\InputText("hidden", "id_restaurant", "id_restaurant", $this->id_restaurant);
     $return['resto_name'] = new \Leap\View\InputText("text", "resto_name", "resto_name", $resto->name);
     $return['resto_name']->setReadOnly(true);
     return $return;
 }
 public function overwriteForm($return, $returnfull)
 {
     $resto = new MasterRestaurantModel();
     $res = $resto->getAll();
     foreach ($res as $value) {
         $arrHelp[$value->id_restaurant] = $value->name;
     }
     $return['id_restaurant'] = new Leap\View\InputSelect($arrHelp, "id_restaurant", "id_restaurant", $this->id_restaurant);
     $return['status'] = new Leap\View\InputSelect(array("1" => "Active", "0" => "Inactive"), "status", "status", $this->status);
     return $return;
 }
 public function overwriteRead($return)
 {
     $objs = $return['objs'];
     foreach ($objs as $obj) {
         if (isset($obj->id_restaurant)) {
             $resto = new MasterRestaurantModel();
             $resto->getByID($obj->id_restaurant);
             $obj->id_restaurant = $resto->name;
         }
     }
     return $return;
 }
 public function overwriteRead($return)
 {
     $objs = $return['objs'];
     foreach ($objs as $obj) {
         if (isset($obj->id_restaurant)) {
             $resto = new MasterRestaurantModel();
             $resto->getByID($obj->id_restaurant);
             $obj->id_restaurant = $resto->name;
         }
         if (isset($obj->start)) {
             $date = new DateTime($obj->start);
             $obj->start = $date->format('d.m.Y');
         }
         if (isset($obj->end)) {
             $dateEnd = new DateTime($obj->end);
             $obj->end = $dateEnd->format('d.m.Y');
         }
         ?>
         <script>
             $(document).ready(function () {
                 var date = new Date();
                 var i = 1;
                 while ($('#id_MR_' + i).text().trim()) {
                     var dateEndNow = $('#end_' + i).text().trim();
                     var dt1 = parseInt(dateEndNow.substring(0, 2));
                     var mon1 = parseInt(dateEndNow.substring(3, 5));
                     var yr1 = parseInt(dateEndNow.substring(6, 10));
                     var dateEnd = new Date(yr1, mon1 - 1, dt1);
                     var diff = dateEnd - date, sign = diff < 0 ? -1 : 1, milliseconds, seconds, minutes, hours, days;
                     diff = (diff - (milliseconds = diff % 1000)) / 1000;
                     diff = (diff - (seconds = diff % 60)) / 60;
                     diff = (diff - (minutes = diff % 60)) / 60;
                     days = (diff - (hours = diff % 24)) / 24;
                     if(days <2){
                         $("#MRDiscountModel_" + i).css("background-color", "red");
                     }
                     else{
                         
                         $("#MRDiscountModel_" + i).css("background-color", "yellow");
                     }
                     i = i + 1;
                 }
             });
             </script>
             <?php 
     }
     return $return;
 }
 public function overwriteForm($return, $returnfull)
 {
     $return = parent::overwriteForm($return, $returnfull);
     $userModel = new UserModel();
     $arrUser = $userModel->getAll();
     foreach ($arrUser as $value) {
         $arrUserHelp[$value->id_user] = $value->user_name;
     }
     $return['inv_from'] = new Leap\View\InputSelect($arrUserHelp, "inv_from", "inv_from", $this->inv_from);
     $resto = new MasterRestaurantModel();
     $res = $resto->getAll();
     foreach ($res as $value) {
         $arrHelp[$value->id_restaurant] = $value->name;
     }
     $return['inv_id_resto'] = new Leap\View\InputSelect($arrHelp, "inv_id_resto", "inv_id_resto", $this->inv_id_resto);
     return $return;
 }
 public function requestCashOut()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idResto = Generic::mustCheck($_GET['id_restaurant'], "No ID Restaurant Found");
     $amount = Generic::mustCheck($_GET['amount'], "No Amount Found");
     if ($amount == "0") {
         Generic::errorMsg("Zero Amount not Allowed");
     }
     $bankAcc = new RestoBankAccModel();
     $arrBank = $bankAcc->getWhere("id_restaurant='{$idResto}'");
     if (count($arrBank) <= 0) {
         Generic::errorMsg("You Have Not Set Your Cash Out Account");
     }
     $req = new MasterCashOutRequestModel();
     $arrReq = $req->getWhere("id_restaurant='{$idResto}' AND status='0'");
     if (count($arrReq) > 0) {
         Generic::errorMsg("You Already Request Cash Out");
     }
     $resto = new MasterRestaurantModel();
     $resto->getByID($idResto);
     $cashOut = new MasterCashOutRequestModel();
     $cashOut->id_restaurant = $idResto;
     $cashOut->datetime_request = leap_mysqldate();
     $cashOut->amount = $amount;
     $cashOut->status = 0;
     $idNewRequest = $cashOut->save();
     $tr = new MasterRestoTransactionModel();
     $tr->id_request = $idNewRequest;
     $tr->id_restaurant = $idResto;
     $tr->gross_amount = (double) $amount * -1;
     $tr->net_amount = (double) $amount * -1;
     $tr->approved = "0";
     $tr->type_transaction = "2";
     $tr->datetime_transaction = leap_mysqldate();
     $tr->mr_fee = 0;
     $tr->credit_card_fee = 0;
     $tr->other_fee = 0;
     $tr->bank_disc = 0;
     $tr->save();
     $json['status_code'] = 1;
     $json['results']['messages'] = "success";
     echo json_encode($json);
     die;
 }
 public function unactivateTag($id_tag)
 {
     $r = new MasterRestaurantModel();
     $arrResto = $r->getAll();
     foreach ($arrResto as $resto) {
         if ($resto->restaurant_tags == null || $resto->restaurant_tags == "") {
             continue;
         }
         $arrTags = explode(",", $resto->restaurant_tags);
         for ($i = 0; $i < count($arrTags); $i++) {
             if ($arrTags[$i] == $id_tag) {
                 unset($arrTags[$i]);
                 $resto->restaurant_tags = implode(",", array_unique($arrTags));
                 $resto->save();
                 break;
             }
         }
     }
 }
 public function requestRestoPermission($userModel, $tableModel, $paymentMethod)
 {
     $resto = new MasterRestaurantModel();
     $resto->getByID($tableModel['id_restaurant']);
     //TODO CHECK RESTAURANT EMPTY, IF EMPTY goto ERROR()  -> sdh di kerjakan
     if ($resto == null) {
         Generic::errorMsg("Restaurant is empty");
     }
     $msg = $userModel->user_name . " want to open table no. " . $tableModel['table_number'];
     $j["user_id"] = $userModel->id_user;
     $j["user_name"] = $userModel->full_name;
     $j["user_pic"] = _BPATH . _PHOTOURL . $userModel->pic;
     $j["id_table"] = $tableModel['id_table'];
     $j["table_number"] = $tableModel['table_number'];
     $j["payment_method"] = $paymentMethod;
     $j['datetime'] = date('Y-m-d H:i:s');
     $restoId = $tableModel['id_restaurant'];
     $this->pushToRestoCashier($tableModel['id_restaurant'], $msg, json_encode($j), Push::$typeRequestOpenTable);
 }
 /**
  * Invoice constructor.
  */
 public function __construct($idOrder, $calcPending = 1)
 {
     $this->calcPending = $calcPending;
     $this->idOrder = $idOrder;
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     $restaurant = new MasterRestaurantModel();
     $restaurant->getByID($order->id_restaurant);
     $this->idRestaurant = $order->id_restaurant;
     $this->restaurantName = $restaurant->name;
     $user = new UserModel();
     $user->getByID($order->id_user);
     $this->idUser = $order->id_user;
     $this->userName = $user->full_name;
     $this->paymentMethod = $order->payment_method;
     $this->discRestaurant = $restaurant->disc_resto;
     $this->discMR = Util::getDiscountMR($order->id_restaurant);
     $this->feeMR = Util::getFeeMR($order->id_restaurant);
     if ($order->payment_method == Keys::$PAYMENT_TYPE_CREDIT_CARD) {
         $this->discBank = Util::getDiscountCreditCard($order->id_restaurant, $user->payment_bank_id);
         $this->feeNominalBank = Util::getFeeNominalCreditCard($order->id_restaurant, $user->payment_bank_id);
         $this->feePercentBank = Util::getFeePercentCreditCard($order->id_restaurant, $user->payment_bank_id);
     } else {
         if ($order->payment_method == Keys::$PAYMENT_TYPE_DOKU_WALLET) {
             $this->discBank = 0;
             $this->feeNominalBank = 0;
             $this->feePercentBank = 0;
         } else {
             $this->discBank = 0;
             $this->feeNominalBank = 0;
             $this->feePercentBank = 0;
         }
     }
     $this->serviceCharge = $restaurant->service_charge;
     $this->taxCharge = $restaurant->tax_pb_1;
     $this->otherCharge = $restaurant->other_charge;
     $this->updateSubTotal();
     $this->assignValue();
 }
 public function overwriteRead($return)
 {
     $objs = $return['objs'];
     foreach ($objs as $obj) {
         if (isset($obj->id_restaurant)) {
             if ($obj->id_restaurant != "") {
                 $r = new MasterRestaurantModel();
                 $r->getByID($obj->id_restaurant);
                 $obj->id_restaurant = $r->name;
             }
         }
         if (isset($obj->type_transaction)) {
             if ($obj->type_transaction == "1") {
                 $obj->type_transaction = "User Transaction";
             } elseif ($obj->type_transaction == "2") {
                 $obj->type_transaction = "Cash Out Request";
             } else {
                 $obj->type_transaction = "Error";
             }
         }
         if (isset($obj->approved)) {
             if ($obj->approved == "1") {
                 $obj->approved = "Yes";
             } elseif ($obj->approved == "0") {
                 $obj->approved = "No";
             } else {
                 $obj->approved = "Error";
             }
         }
         if (isset($obj->datetime_transaction)) {
             $d = strtotime("{$obj->datetime_transaction}");
             $obj->datetime_transaction = date("d M Y h:m a", $d);
         }
     }
     return $return;
 }
    function formCreatedQR()
    {
        ?>
        <form class="form_crud" role="form" method="POST" action="<?php 
        echo _SPPATH . "QR/createQRbyRestoID";
        ?>
">
            <div class="form-group">
                <label for="quantityQR" class="col-sm-2 control-label">ID-Restaurant</label>
                <div class="col-sm-10">
                    <?php 
        $objResto = new MasterRestaurantModel();
        $arrResto = $objResto->getAll();
        foreach ($arrResto as $resto) {
            $arrRestoID[] = $resto->id_restaurant;
            $arrRestoName[] = $resto->name;
        }
        $t = time();
        ?>
                    <select id="selectresto_<?php 
        echo $t;
        ?>
" name ='id_restaurant' class="form-control">
                        <?php 
        foreach ($arrRestoID as $n => $name) {
            ?>
                            <option value="<?php 
            echo $arrRestoID[$n];
            ?>
"><?php 
            echo $arrRestoName[$n];
            ?>
</option>
                        <?php 
        }
        ?>
                    </select>
                </div>            

                <label for="quantityQR" class="col-sm-2 control-label">Quantity</label>

                <div class="col-sm-10">
                    <input type="text" class="form-control" id="quantityQR" name = "quantityQR" placeholder="Quantity" required>

                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-1">
                    <button type="submit" class="btn btn-default">Submit</button>
                </div>
            </div>
        </form>
        <?php 
    }
 public function getCategoriesByResto()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idRestaurant = Generic::mustCheck($_GET['id_restaurant'], Keys::$ERR_NOT_FOUND_ID_RESTAURANT);
     $objResto = new MasterRestaurantModel();
     $objResto->getByID($idRestaurant);
     if (!Generic::IsNullOrEmptyString($objResto->id_categories)) {
         $arrCategories = explode(",", $objResto->id_categories);
     } else {
         $arrCategories = array();
     }
     $categories = array();
     foreach ($arrCategories as $idCat) {
         $c = new MasterCategoryModel();
         $c->getByID($idCat);
         if ($c->id_category) {
             $categories[] = $c->name;
         }
     }
     //        pr($arrCategories);
     //        pr($categories);
     $results['categories'] = $categories;
     $rawTags = array();
     $id_dish = isset($_GET['id_dish']) ? addslashes($_GET['id_dish']) : "";
     if ($id_dish) {
         $dish = new MasterDishModel();
         $dish->getByID($id_dish);
         $tagsIds = explode(",", $dish->dish_tags);
         if (count($tagsIds) != 0) {
             foreach ($tagsIds as $tagsId) {
                 if ($tagsId == null || $tagsId == "") {
                     continue;
                 }
                 $dishTag = new MasterDishTagModel();
                 $dishTag->getByID($tagsId);
                 $b["id_tag"] = $dishTag->id_tag;
                 $b["name"] = $dishTag->name;
                 $rawTags[] = $b;
             }
         }
     }
     $results['raw_tags'] = $rawTags;
     Generic::finish($results);
 }
 public function loadHomeFav()
 {
     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");
     }
     $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");
     }
     $begin = ($page - 1) * $limit;
     $json = array();
     $sem = array();
     global $db;
     $objRestaurant = new MasterRestaurantModel();
     $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
     $arrPicsToAddPhotoUrl = $objRestaurant->crud_add_photourl;
     $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} HAVING distance < 1000000 ORDER by fav DESC, DISTANCE ASC  LIMIT {$begin},{$limit}";
     $arr = $db->query($q, 2);
     $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["distance"] = sqrt(pow(69.09999999999999 * ($o->latitude - $currentLat), 2) + pow(69.09999999999999 * ($currentLong - $o->longitude) * cos($o->latitude / 57.3), 2));
         $json["results"]['restaurant'][] = $sem;
     }
     echo json_encode($json);
     die;
 }
 public function addDishToMyFavorite()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idUser = Generic::mustCheck($_GET['id_user'], "User ID not Found");
     $idDish = Generic::mustCheck($_GET['id_dish'], "Dish ID not Found");
     $user = new UserModel();
     $user->getByID($idUser);
     $arrFavDishIds = explode(',', $user->fav_dishes_ids);
     $alreadyInFavorite = count($arrFavDishIds) <= 0 ? false : in_array($idDish, $arrFavDishIds);
     if ($alreadyInFavorite) {
         Generic::errorMsg("Already Favorited");
     }
     if (count($arrFavDishIds) <= 0) {
         $user->fav_dishes_ids = $idDish;
     } else {
         $arrFavDishIds[] = $idDish;
         $arrFavDishIds = array_unique($arrFavDishIds);
         $user->fav_dishes_ids = implode(',', $arrFavDishIds);
     }
     $dish = new MasterDishModel();
     $dish->getByID($idDish);
     $dish->fav = $dish->fav + 1;
     $dish->save();
     $resto = new MasterRestaurantModel();
     $resto->getByID($dish->id_restaurant);
     $resto->fav = $resto->fav + 1;
     $resto->save();
     $user->save();
     $this->success();
 }
    public function createQRbyRestoID()
    {
        $id_restaurant = $_GET['id_restaurant'];
        $quantityQR = $_GET['quantityQR'];
        $id_request = $_GET['id_request'];
        $objResto = new MasterRestaurantModel();
        $objResto->getByID($id_restaurant);
        $objResto->table_quantity = $objResto->table_quantity + $quantityQR;
        $objResto->load = 1;
        $objResto->save();
        //        pr($objResto);
        $objQRRequest = new QRRequestModel();
        $objQRRequest->getByID($id_request);
        $objQRRequest->createdOn = leap_mysqldate();
        //        pr($objQRRequest);
        $objQRRequest->status = "1";
        $objQRRequest->load = 1;
        $objQRRequest->save();
        $objQR = new QRModel();
        global $db;
        $qtydiDB = "SELECT max(id_qr) as max from menurevo__QR";
        $arr = $db->query($qtydiDB, 1);
        for ($i = $arr->max + 1; $i <= $quantityQR + $arr->max; $i++) {
            $encode = addslashes(base64_encode($i));
            $q = "INSERT INTO menurevo__QR (id_qr, textQR,status) VALUES({$i},'{$encode}',0)";
            $id = $db->query($q, 1);
        }
        $pdf = new FPDF();
        $myarray = array(1, 2, 3);
        $pdf->SetFont('Arial', 'B', 16);
        for ($i = $arr->max + 1; $i <= $quantityQR + $arr->max; $i++) {
            $pdf->AddPage();
            $pdf->Image("https://chart.googleapis.com/chart?chs=150x150&cht=qr&chld=L|0&chl=" . base64_encode($i), 60, 30, 90, 0, 'PNG');
            $pdf->Text(85, 130, "Menu Revolution");
        }
        $pdf->Output();
        ?>


        <html>
            <head>
                <title>Print QR-Code</title>
                <style>
                    body{ margin: 0; padding: 0; font-family: verdana;}
                </style>
            </head>
            <body>
        <?php 
        for ($i = $arr->max + 1; $i <= $quantityQR + $arr->max; $i++) {
            ?>
                    <!--                    <div style="width:800px; border-bottom: 3px dashed #aaaaaa; margin-bottom: 20px;">
                                            <img src="<?php 
            echo _SPPATH;
            ?>
images/headerleap.jpg"  width="100%">-->

                    <div style="padding:40px; text-align: center;">
                        <!--<div style="letter-spacing: 2px; font-size: 18px; font-weight: bold; padding-bottom: 20px;"> <?php 
            echo $mur->admin_nama_depan;
            ?>
</div>-->
                        <img src="<?php 
            echo "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chld=L|0&chl=" . base64_encode($i);
            ?>
"alt="QR">

                    </div>

                    <!--</div>--> 

            <?php 
        }
        ?>
 </body>

        </html><?php 
        die('finished');
    }
 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 overwriteForm($return, $returnfull)
    {
        $r = new MasterRestaurantModel();
        $arrR = $r->getWhere("aktiv='1'");
        $arrHelp = array("0" => "Nothing Selected");
        foreach ($arrR as $resto) {
            $arrHelp[$resto->id_restaurant] = $resto->name;
        }
        $return['id_restaurant'] = new \Leap\View\InputSelect($arrHelp, "id_restaurant", "id_restaurant", $this->id_restaurant);
        if (!isset($this->id_restaurant)) {
            $this->id_restaurant = key($arrHelp);
        }
        $d = new MasterDishModel();
        $arrD = $d->getWhere("id_restaurant='{$this->id_restaurant}' AND status='1'");
        $arrHelpDish = array("0" => "Nothing Selected");
        foreach ($arrD as $dish) {
            $arrHelpDish[$dish->id_dish] = $dish->name;
        }
        $return['id_dish'] = new Leap\View\InputSelect($arrHelpDish, "id_dish", "id_dish", $this->id_dish);
        ?>
        <script>
            $("#id_restaurant").change(function () {
                var selVal = $("select#id_restaurant option:selected").val();
                if (selVal == 0 || selVal == "" || selVal == "0") {
                    $('#id_dish').empty();
                    $('#id_dish').append($("<option></option>")
                        .attr("value", 0)
                        .text("Nothing Selected"));
                    return;
                }
                $.ajax({
                    method: "GET",
                    url: _sppath + "RecommendationFood/getDishByRestoId",
                    data: {id_restaurant: selVal}
                }).done(function (msg) {
//                        console.log(msg);
                    $('#id_dish').empty();
                    var json_obj = $.parseJSON(msg);//parse JSON
                    for (var i in json_obj) {
                        $('#id_dish')
                            .append($("<option></option>")
                                .attr("value", json_obj[i].value)
                                .text(json_obj[i].text));
                        console.log(json_obj[i].text);
                    }
                });
            });
        </script>
        <?php 
        if (!isset($this->start)) {
            $dt = leap_mysqldate();
        } else {
            $dt = $this->start;
        }
        $return['start'] = new \Leap\View\InputText("date", "start", "start", $dt);
        if (!isset($this->end)) {
            $dt = leap_mysqldate();
        } else {
            $dt = $this->end;
        }
        $return['end'] = new \Leap\View\InputText("date", "end", "end", $dt);
        return $return;
    }
 public static function getRestoNameByIDResto($id_restaurant)
 {
     $objResto = new MasterRestaurantModel();
     $arrResto = $objResto->getWhere("id_restaurant = '{$id_restaurant}'");
     if (count($arrResto) > 0) {
         return $arrResto[0]->name;
     } else {
         return "";
     }
 }
 private function viewSearchTerm($searchType, $searchTerm)
 {
     switch ($searchType) {
         case "1":
             $rt = new MasterRestaurantTypeModel();
             $rt->getByID($searchTerm);
             return $rt->name;
         case "2":
             $r = new MasterCategoryModel();
             $r->getByID($searchTerm);
             return $r->name;
         case "3":
             $r = new CuisineModel();
             $r->getByID($searchTerm);
             return $r->name_cuisine;
             //            case "4": {
             //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
             //            }
             //            case "5": {
             //                $r = new MasterDishTagModel();
             //                $r->getByID($searchTerm);
             //                return $r->name;
             //            }
             //            case "6": {
             //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
             //            }
         //            case "4": {
         //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
         //            }
         //            case "5": {
         //                $r = new MasterDishTagModel();
         //                $r->getByID($searchTerm);
         //                return $r->name;
         //            }
         //            case "6": {
         //                return new Leap\View\InputText("text", "search_term", "search_term", $this->search_term);
         //            }
         case "7":
             $r = new MasterRestaurantModel();
             $r->getByID($searchTerm);
             return $r->name;
         case "8888":
             return "Not Available";
         default:
             return "Not Available";
     }
 }
 public static function isRestaurantOpen($idResto)
 {
     $resto = new MasterRestaurantModel();
     $resto->getByID($idResto);
     return $resto->now_open == "1";
 }
 public function sendwithreturn()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $idOrder = $_GET['id_order'];
     $toEmail = $_GET['email'];
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     $resto = new MasterRestaurantModel();
     $resto->getByID($order->id_restaurant);
     $subject = "Your receipt from " . $restoName . " , Receipt#" . $idOrder;
     $od = new OrderDetailModel();
     $d = new MasterDishModel();
     //      $dompdf = new Dompdf\Dompdf();
     global $db;
     $q = "SELECT {$od->table_name}.id_dish, {$d->table_name}.name, SUM(quantity) AS sum_qty, {$d->table_name}.price,\nSUM({$od->table_name}.price) AS sum_price, status_progress FROM `{$od->table_name}`\nRIGHT JOIN {$d->table_name} ON {$od->table_name}.id_dish = {$d->table_name}.id_dish WHERE id_order='{$idOrder}' GROUP BY id_dish";
     $arrDetails = $db->query($q, 2);
     $css_boot = _BPATH . "themes/tbstheme_ori/css/bootstrap.min.css";
     $image1 = _BPATH . _PHOTOURL . $resto->image_logo;
     if ($image1 == "") {
         $image1 = _BPATH . _PHOTOURL . "noimage.jpg";
     }
     $head = "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
     $head = "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Notification email</title>";
     $head = $head . "<link href=" . $css_boot . " rel=\"stylesheet\">";
     $head = $head . "<link href=\"https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700&subset=latin,latin-ext\" rel=\"stylesheet\" type=\"text/css\">";
     $head = $head . "</head>";
     $html = "<div style=\"max-width: 800px; box-shadow: 0 0 10px rgba(0, 0, 0, .15); font-size: 16px; line-height: 24px; font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif; color: #555; margin: auto; padding: 30px; border: 1px solid #eee;\">\n<table style=\"width: 100%; line-height: inherit; text-align: left;\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"vertical-align: top; padding: 5px;\" colspan=\"2\">\n<table style=\"width: 100%; line-height: inherit; text-align: left;\">\n<tbody>\n<tr>\n<td style=\"vertical-align: top; font-size: 45px; line-height: 45px; color: #333; width: 50%; display: block; text-align: left; padding: 5px 5px 20px;\" align=\"left\" valign=\"top\"><img style=\"width: 50%; max-width: 300px;\" src=" . $image1 . " alt=\"\" /></td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; width: 100%; display: block; text-align: left; padding: 5px 5px 40px;\" align=\"center\" valign=\"top\">";
     $html = $html . "<strong>" . $resto->name . "</strong><br />";
     $html = $html . $resto->district . " - " . $resto->city . " <br>";
     $html = $html . "Phone : " . $resto->phone_no . "</td>";
     $html = $html . "</tr>\n</tbody>\n</table>\n</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; padding: 5px;\" colspan=\"2\" valign=\"top\">\n<table style=\"width: 100%; line-height: inherit; text-align: left;\">\n<tbody>\n<tr>\n<td style=\"vertical-align: top; text-align: left; t width: 50%; display: block; padding: 5px 5px 20px;\" align=\"left\" valign=\"top\">";
     $html = $html . "</tr>";
     $html = $html . "Receipt #: " . $idOrder;
     $html = $html . "<br/>";
     $html = $html . "  Server : ";
     if ($order->type_order == "1" || $order->type_order == "3") {
         $html = $html . "Apps Order";
     } else {
         $html = $html . $order->server_name;
     }
     $html = $html . "<br/>";
     $html = $html . " Time Order : " . date("d M, Y H:m", strtotime($order->datetime_order));
     $html = $html . "<br/>";
     $html = $html . " Payment Method : " . Generic::selectPaymentMethod($order->status_payment);
     $html = $html . "<br/>";
     if ($order->type_order == "1" || $order->type_order == "3") {
         $html = $html . "Apps Order";
     } else {
         $html = $html . "Manual Order";
     }
     $html = $html . "<br/>";
     $html = $html . "</td>";
     $html = $html . "</tr> \n</tbody>\n</table>\n</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ddd; font-weight: bold; background-color: #eee; padding: 5px;\" valign=\"top\" bgcolor=\"#eee\">Item</td>\n<td style=\"vertical-align: top; text-align: right; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ddd; font-weight: bold; background-color: #eee; padding: 5px;\" align=\"center\" valign=\"top\" bgcolor=\"#eee\">#</td>\n<td style=\"vertical-align: top; text-align: right; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ddd; font-weight: bold; background-color: #eee; padding: 5px;\" align=\"right\" valign=\"top\" bgcolor=\"#eee\">Price</td>\n  <td style=\"vertical-align: top; text-align: right; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ddd; font-weight: bold; background-color: #eee; padding: 5px;\" align=\"right\" valign=\"top\" bgcolor=\"#eee\">Total</td>\n</tr>";
     foreach ($arrDetails as $details) {
         $void = "";
         if ($details->status_progress == "9") {
             $void = "<strong> Voided </strong>";
             $details->price = 0;
             $details->sum_price = 0;
         }
         $html = $html . "<tr><td style=\"vertical-align: top; border-bottom-width: 1px; border-bottom-color: #eee; border-bottom-style: solid; padding: 5px;\" valign=\"top\">" . $details->name . $void . "</td>";
         $html = $html . "<td style=\"vertical-align: top; text-align: right; border-bottom-width: 1px; border-bottom-color: #eee; border-bottom-style: solid; padding: 5px;\" align=\"right\" valign=\"top\">" . $details->sum_qty . "</td>";
         $html = $html . "<td style=\"vertical-align: top; text-align: right; border-bottom-width: 1px; border-bottom-color: #eee; border-bottom-style: solid; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($details->price) . "</td>";
         $html = $html . "<td style=\"vertical-align: top; text-align: right; border-bottom-width: 1px; border-bottom-color: #eee; border-bottom-style: solid; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($details->sum_price) . "</td></tr>";
     }
     $html = $html . "<tr>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Total : </td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->total_cost) . "</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Disc Resto : </td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->disc_resto) . "</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Disc Credit Card : </td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->disc_bank) . "</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Disc MR : </td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->disc_mr) . "</td>\n</tr>\n\n<tr>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Tax PB1 : </td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->tax_pb1) . "</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Service Charge : </td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->tax_pb1) . "</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Other Charge : </td>\n<td style=\"vertical-align: top; text-align: right; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->tax_pb1) . "</td>\n</tr>\n<tr>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\"></td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">Grand Total :</td>\n<td style=\"vertical-align: top; text-align: right; border-top-style: solid; border-top-width: 2px; border-top-color: #eee; font-weight: bold; padding: 5px;\" align=\"right\" valign=\"top\">" . Generic::formatRupiah($order->grand_total) . "</td>\n</tr>\n\n</tbody>\n</table>\n</div></html>";
     $html = $head . $html;
     $mail = new Leapmail();
     $res = $mail->sendEmailHTML($toEmail, $subject, $html);
     return $res;
 }
    public function reportFee()
    {
        $id_restaurant = isset($_GET['id_restaurant']) ? addslashes($_GET['id_restaurant']) : "0";
        $type_order = isset($_GET['type_order']) ? addslashes($_GET['type_order']) : "8";
        $dateVon = isset($_GET['dateVon']) ? addslashes($_GET['dateVon']) : date('Y-m-d', time());
        $dateBis = isset($_GET['dateBis']) ? addslashes($_GET['dateBis']) : date('Y-m-d', time());
        //        $dateBis = isset($_GET['dateBis']) ? addslashes($_GET['dateBis']) : Generic::setCurrentDate();
        $id_server = isset($_GET['id_server']) ? addslashes($_GET['id_server']) : "0";
        $status_payment = isset($_GET['status_payment']) ? addslashes($_GET['status_payment']) : 0;
        $status_progress = isset($_GET['status_progress']) ? addslashes($_GET['status_progress']) : 4;
        $objResto = new MasterRestaurantModel();
        $arrResto = $objResto->getAll();
        $arrRestoIndex[0] = "All";
        foreach ($arrResto as $resto) {
            if ($resto->name != "") {
                $arrRestoIndex[$resto->id_restaurant] = $resto->name;
            }
        }
        $objOrder = new MasterOrderModel();
        $first_key = key($arrRestoIndex);
        $arrOrder = $objOrder->getWhere("id_restaurant='{$id_restaurant}'");
        $arrRestoUserIndex[0] = "All";
        foreach ($arrOrder as $val) {
            $user = RestaurantUser::getRestaurantUserName($val->id_server);
            if ($user != "") {
                $arrRestoUserIndex[$val->id_server] = $user;
            }
        }
        $arrTypeOrder[0] = "Dine In - Manual";
        $arrTypeOrder[1] = "Dine In - Apps";
        $arrTypeOrder[2] = "Take Away - Manual";
        $arrTypeOrder[3] = "Take Away  - Apps";
        $arrTypeOrder[4] = "All Manual Order";
        $arrTypeOrder[5] = "All Apps Order";
        $arrTypeOrder[6] = "All Dine In Order";
        $arrTypeOrder[7] = "All Take Away Order";
        $arrTypeOrder[8] = "All Order Types";
        $arrStatusPaymentMethod[1] = "Cash";
        $arrStatusPaymentMethod[2] = "Credit Card";
        $arrStatusPaymentMethod[3] = "Others";
        $arrStatusPaymentMethod[0] = "All Payment Method";
        $arrStatusProgress[4] = "Done";
        $arrStatusProgress[9] = "Void";
        $t = time();
        $where = " ";
        if ($id_restaurant == 0) {
            $where = $where;
        } else {
            $allResto = false;
            $where = $where . " resto.id_restaurant='{$id_restaurant}' AND ";
        }
        if ($type_order == "8") {
        } else {
            $where = $where . "  o.type_order='{$type_order}' AND ";
        }
        if ($dateVon == "") {
            ?>
            <?php 
            $dateVon = Generic::setCurrentDate();
        } else {
            $date = new DateTime($dateVon);
            //            $dateVon = leap_mysqldate_isi(date('Y-m-d H:i:s'));
            //            pr($dateVon);
            $where = $where . "  o.datetime_order >='{$dateVon}' AND ";
        }
        if ($dateBis == "") {
            $dateBis = Generic::setCurrentDate();
        } else {
            $date = new DateTime($dateVon);
            $where = $where . "  o.datetime_order <= '{$dateBis}' AND ";
        }
        if ($id_server == "0") {
            $where = $where;
        } else {
            $where = $where . "  o.id_server='{$id_server}' AND ";
        }
        if ($status_payment == "" | $status_payment == "0") {
            $where = $where;
        } else {
            $where = $where . "  o.status_payment='{$status_payment}' AND ";
        }
        if ($status_progress == "") {
        } else {
            $where = $where . "  o.status_progress='{$status_progress}'  ";
        }
        $objOrder = new MasterOrderModel();
        $objResto = new MasterRestaurantModel();
        $objOrderDetail = new OrderDetailModel();
        $objDish = new MasterDishModel();
        global $db;
        $q = "SELECT o.datetime_order as dateOrder,o.datetime_order as timeOrder , resto.name,   o.id_order,  o.mr_fee, o.cc_fee, o.mr_fee+o.cc_fee as Total FROM {$objResto->table_name} resto INNER JOIN {$objOrder->table_name} o ON resto.id_restaurant = o.id_restaurant";
        //        $q = $q . " INNER JOIN {$objOrderDetail->table_name} orderdetail ON o.id_order = orderdetail.id_order  ";
        //        $q = $q . " INNER JOIN {$objDish->table_name} dish ON orderdetail.id_dish =  dish.id_dish ";
        $q = $q . " WHERE " . $where;
        //        pr($q);
        $arrQuery = $db->query($q, 2);
        //        pr($arrQuery);
        //        die();
        //        $data = json_encode($arrQuery);
        $data = $arrQuery;
        //        pr($arrRestoIndex);
        ?>

        <div  class="col-md-12">
            <div class="col-sm-12">
                <h1>Reporting Fee</h1>
            </div>

            <div id="formgroup_selected_restaurant" class="form-group">
                <div class='col-sm-6'>
                    <select id = "restoID_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrRestoIndex as $key => $val) {
            if ($key == $_GET['id_restaurant']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>
                    </select>

                </div>
                <div class='col-sm-6'>
                    <select id = "type_order_<?php 
        echo $t;
        ?>
" class="form-control">

                        <?php 
        foreach ($arrTypeOrder as $key => $val) {
            if ($key == $_GET['type_order']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>
                    </select>
                </div>
                <div class="clearfix"></div>
            </div>

            <div id="formgroup_date" class="form-group">
                <div class='col-sm-6'>
                    <div class="form-group">
                        <div class='input-group date' id='datetimepickerFrom_<?php 
        echo $t;
        ?>
' data-date-format="dd-mm-yyyy">
                            <input type='text' id= "dateVon_<?php 
        echo $t;
        ?>
"class="form-control"
                                   />
                            <span id = "cobaFrom" class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>

                        </div>
                    </div>
                </div>

                <div class='col-sm-6'>
                    <div class="form-group">
                        <div class='input-group date' id='datetimepickerTo_<?php 
        echo $t;
        ?>
'>
                            <input type='text' id= "dateBis_<?php 
        echo $t;
        ?>
" class="form-control" />
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>

            </div>

            <div id="formgroup_server" class="form-group">
                <div class='col-sm-6'>
                    <select id = "selectServer_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrRestoUserIndex as $key => $val) {
            if ($key == $_GET['id_server']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>

                    </select>
                </div>
                <div class='col-sm-6'>
                    <select id = "status_payment_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrStatusPaymentMethod as $key => $val) {
            if ($key == $_GET['status_payment']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>

                    </select>
                </div>
                <div class="clearfix"></div>

            </div>

            <div id="formgroup_progress" class="form-group">
                <div class='col-sm-6'>
                    <select id = "status_progress_<?php 
        echo $t;
        ?>
" class="form-control">
                        <?php 
        foreach ($arrStatusProgress as $key => $val) {
            if ($key == $_GET['status_progress']) {
                echo "<option selected='selected' value='" . $key . "'>" . $val . "</option>";
            } else {
                echo "<option value='" . $key . "'>" . $val . "</option>";
            }
        }
        ?>

                    </select>
                </div>

                <div class="btn-group col-sm-4" role="group" aria-label="...">
                    <button type="button" class="btn btn-default"  id="export_<?php 
        echo $t;
        ?>
">Export</button>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>




        <script type="text/javascript">
            var dateFrom, dateTo;

            if (dateFrom == null) {
                var now = new Date();
                var day = ("0" + now.getDate()).slice(-2);
                var month = ("0" + (now.getMonth() + 1)).slice(-2);
                var dateFrom = now.getFullYear() + "-" + (month) + "-" + (day);

            }
            if (dateTo == null) {
                var now = new Date();
                var day = ("0" + now.getDate()).slice(-2);
                var month = ("0" + (now.getMonth() + 1)).slice(-2);
                var dateTo = now.getFullYear() + "-" + (month) + "-" + (day);
            }


            $('#restoID_<?php 
        echo $t;
        ?>
').change(function () {
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);

                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?id_server=0" + "&id_restaurant=" + id_restaurant + "&dateVon=" + dateFrom + "&dateBis=" + dateTo, "fade");
            });

            $('#type_order_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });

            $('#selectServer_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            $('#status_payment_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            $('#status_progress_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            var datetimepickerFrom = $('#datetimepickerFrom_<?php 
        echo $t;
        ?>
');
            var datetimepickerTo = $('#datetimepickerTo_<?php 
        echo $t;
        ?>
');

            $('#dateVon_<?php 
        echo $t;
        ?>
').change(function () {
                var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                console.log("type_order: " + type_order);
                var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                console.log("id_restaurant: " + id_restaurant);
                var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                console.log("server: " + server);
                var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                var status_progress = $('#status_progress<?php 
        echo $t;
        ?>
').val();
                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo + "&status_progress=" + status_progress, "fade");
            });


            $('#export_<?php 
        echo $t;
        ?>
').click(function () {
        <?php 
        $_SESSION["data"] = $data;
        ?>
                // initializes and invokes show immediately           
                window.open('<?php 
        echo _SPPATH;
        ?>
Report/exportIt', "_blank ");

            });
            //
            $(function () {
                datetimepickerFrom.datetimepicker({
                    format: 'DD/MM/YYYY',
                    defaultDate: dateFrom
                            //Im,portant! See issue #1075

                });
                datetimepickerTo.datetimepicker({
                    format: 'DD/MM/YYYY',
                    defaultDate: dateTo
                });
                datetimepickerFrom.on("dp.change", function (e) {
                    datetimepickerTo.data("DateTimePicker").minDate(e.date);
                    var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                    console.log("type_order: " + type_order);
                    var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                    console.log("id_restaurant: " + id_restaurant);
                    var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                    console.log("server: " + server);
                    var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                    dateFrom = new Date(e.date);
                    console.log(e);
                    if (e.oldDate != null) {
                        dateFrom = new Date();
                        dateFrom = moment().format('DD/MM/YYYY');
                    }

                    if (e.oldDate != null) {
                        var changed = false;
                        if (e.date != e.oldDate) {
                            changed = true;
                            console.log("olddate: " + e.oldDate.format('Y-M-D'));
                            console.log("Date: " + e.date.format('Y-M-D'));
                            console.log("dateVon_: " + $('#dateVon_<?php 
        echo $t;
        ?>
').val());

                            var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                            console.log("type_order: " + type_order);
                            var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                            console.log("id_restaurant: " + id_restaurant);
                            var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                            console.log("server: " + server);
                            var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                            var tglFrom = e.date.format('Y-M-D');
                            dateFrom = e.date.format('Y-M-D');
                            $('#dateVon_<?php 
        echo $t;
        ?>
').val(dateFrom);
                            var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                            if (changed) {
                                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo, "fade");
                                changed = false;
                            }

                        }

                    }


                });

                datetimepickerTo.on("dp.change", function (e) {
                    datetimepickerFrom.data("DateTimePicker").maxDate(e.date);
                    if (e.oldDate != null) {
                        var changed = false;
                        if (e.date != e.oldDate) {
                            changed = true;
                            console.log("olddate: " + e.oldDate.format('Y-M-D'));
                            console.log("Date: " + e.date.format('Y-M-D'));
                            console.log("dateBis_: " + $('#dateBis_<?php 
        echo $t;
        ?>
').val());

                            var type_order = $('#type_order_<?php 
        echo $t;
        ?>
').val();
                            console.log("type_order: " + type_order);
                            var id_restaurant = $('#restoID_<?php 
        echo $t;
        ?>
').val();
                            console.log("id_restaurant: " + id_restaurant);
                            var server = $('#selectServer_<?php 
        echo $t;
        ?>
').val();
                            console.log("server: " + server);
                            var status_payment = $('#status_payment_<?php 
        echo $t;
        ?>
').val();
                            var tglFrom = e.date.format('Y-M-D');
                            dateTo = e.date.format('Y-M-D');
                            var status_progress = $('#status_progress_<?php 
        echo $t;
        ?>
').val();
                            $('#dateBis_<?php 
        echo $t;
        ?>
').val(dateTo);
                            if (changed) {
                                openLw("DiscountCC", "<?php 
        echo _SPPATH;
        ?>
Report/reportFee?type_order=" + type_order + "&id_restaurant=" + id_restaurant + "&id_server=" + server + "&status_payment=" + status_payment + "&dateVon=" + dateFrom + "&dateBis=" + dateTo, "fade");
                                changed = false;
                            }

                        }

                    }
                });
            });
            //            $("[name='status_progress_<?php 
        echo $t;
        ?>
']").bootstrapSwitch('state', true, true);
        </script>

        <div class="col-md-12">
            <div class="table-responsive">
                <table id = "table_report_<?php 
        echo $t;
        ?>
" class="table table-bordered table-striped table-hover crud-table" style="background-color: white;">

                    <tbody><tr>
                            <th id="h_id_date_<?php 
        echo $t;
        ?>
">Date</th>
                            <th id="h_id_time_<?php 
        echo $t;
        ?>
">Time</th>
                            <th id="h_id_restaurant_<?php 
        echo $t;
        ?>
">Restaurant</th>
                            <th id="h_id_order_<?php 
        echo $t;
        ?>
">Order No.</th>
                            <th id="h_total_<?php 
        echo $t;
        ?>
">MR Fee</th>
                            <th id="h_disc_<?php 
        echo $t;
        ?>
">Credit Card Fee</th>
                            <th id="h_charges_<?php 
        echo $t;
        ?>
">Total Fee</th>
                        </tr>

                        <?php 
        foreach ($arrQuery as $key => $val) {
            ?>
                            <tr id="report_<?php 
            echo $t;
            ?>
">
                                <?php 
            $date = new DateTime($val->datetime_order);
            ?>
                                <td id="id_date_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"> <?php 
            echo $date->format('d.m.Y');
            ?>
</td>
                                <td id="id_time_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"> <?php 
            echo $date->format('H:i:s');
            ?>
</td>
                                <td id="id_restaurant_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"> <?php 
            echo $val->name;
            ?>
</td>
                                <td id="id_order_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo $val->id_order;
            ?>
</td>
                                <td id="total_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo Generic::formatRupiah($val->mr_fee);
            ?>
</td>
                                <td id="disc_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo Generic::formatRupiah($val->cc_fee);
            ?>
</td>
                                <td id="charges_<?php 
            echo $t . "_" . $val->id_order;
            ?>
"><?php 
            echo Generic::formatRupiah($val->Total);
            ?>
</td>


                            </tr>
                        <script>
                            $('#id_order_<?php 
            echo $t . "_" . $val->id_order;
            ?>
').click(function () {
                                openLw("order_detail", "<?php 
            echo _SPPATH;
            ?>
Report/viewOrderDetail?id_order=" + <?php 
            echo $val->id_order;
            ?>
, "fade");

                            });

                        </script>
                        <?php 
        }
        ?>

                    </tbody>
                </table>
            </div>




        </div>
        <?php 
    }
 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 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 updateStatusProgress()
 {
     $idDish = $_GET["id_dish"];
     $idOrder = $_GET["id_order"];
     $idResto = $_GET["id_restaurant"];
     //TODO cek id_resto di order header apakah sama degan $Resto
     $resto = new MasterRestaurantModel();
     $resto->getByID($resto);
     $od = new OrderDetailModel();
     $arrOrDetails = $od->getWhere("id_order='{$idOrder}' AND id_dish='{$idDish}'");
     foreach ($arrOrDetails as $oDetails) {
         if ($oDetails->status_progress < 2) {
             $oDetails->status_progress++;
             $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;
         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();
     die;
 }
 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)) {
                 if ($o->{$attr} != "" and $o->{$attr} != 0) {
                     $sem[$attr] = _BPATH . _PHOTOURL . $o->{$attr};
                 } else {
                     $sem[$attr] = "";
                 }
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
         }
     }
     return $sem;
 }
    public function overwriteRead($return)
    {
        $objs = $return['objs'];
        $dateNow = new DateTime('now');
        foreach ($objs as $obj) {
            foreach ($obj as $key => $val) {
                if ($key == "end") {
                    $datetimeEnd = new DateTime($val);
                    $interval = $dateNow->diff($datetimeEnd);
                    if ($dateNow->format("Y.m.d") > $datetimeEnd->format("Y.m.d")) {
                    }
                    if ($interval->format('%R%a') >= 1) {
                    } else {
                    }
                }
            }
            if (isset($obj->id_restaurant)) {
                $resto = new MasterRestaurantModel();
                $resto->getByID($obj->id_restaurant);
                $obj->id_restaurant = $resto->name;
            }
            if (isset($obj->id_bank)) {
                $bank = new BankModel();
                $bank->getByID($obj->id_bank);
                $obj->id_bank = $bank->bank_name;
            }
            if (isset($obj->start)) {
                $date = new DateTime($obj->start);
                $obj->start = $date->format('d.m.Y');
            }
            if (isset($obj->end)) {
                $dateEnd = new DateTime($obj->end);
                $obj->end = $dateEnd->format('d.m.Y');
            }
            ?>
            <script>
                $(document).ready(function () {
                    var date = new Date();
                    var i = 1;
                    while ($('#id_bank_discount_' + i).text().trim()) {
                        var dateEndNow = $('#end_' + i).text().trim();
                        var dt1 = parseInt(dateEndNow.substring(0, 2));
                        var mon1 = parseInt(dateEndNow.substring(3, 5));
                        var yr1 = parseInt(dateEndNow.substring(6, 10));
                        var dateEnd = new Date(yr1, mon1 - 1, dt1);
                        var diff = dateEnd - date, sign = diff < 0 ? -1 : 1, milliseconds, seconds, minutes, hours, days;
                        diff = (diff - (milliseconds = diff % 1000)) / 1000;
                        diff = (diff - (seconds = diff % 60)) / 60;
                        diff = (diff - (minutes = diff % 60)) / 60;
                        days = (diff - (hours = diff % 24)) / 24;
                        if(days <2){
                            $("#BankDiscountModel_" + i).css("background-color", "red");
                        }
                        else{
                            
                            $("#BankDiscountModel_" + i).css("background-color", "yellow");
                        }
                        i = i + 1;
                    }
                });

            </script>
            <?php 
        }
        ?>


        <style>
            .table{
                background-color: red;
            }

            #BankDiscountModel_1{
                background-color: red;
            }

            #BankDiscountModel_{
                background-color: greenyellow;
            }
        </style>
        <?php 
        return $return;
    }
 public static function getRestaurantnyID($id_restaurant)
 {
     $objResto = new MasterRestaurantModel();
     $arrResto = $objResto->getWhere("id_restaurant='{$id_restaurant}'");
     return $arrResto;
 }