public static function calcRechnung($id_restaurant, $id_order, $save = false)
 {
     $objResto = User::getRestaurant($id_restaurant);
     $objOrder = new MasterOrderModel();
     $objOrder->getByID($id_order);
     $arrOrderDetails = OrderDetail::getOrderDetailsByIDOrderForCalc($id_order);
     $total = 0;
     foreach ($arrOrderDetails as $orderDetails) {
         //            pr($orderDetails);
         if ($orderDetails['status_progress'] != '9') {
             $total = $total + $orderDetails['price'];
         }
     }
     $invoice['sub_total'] = strval($total);
     //        $invoice['service_charge'] = $objResto['service_charge'];
     //        $invoice['other_charge'] = $objResto['other_charge'];
     if ($objResto['service_charge'] > 100) {
         $invoice['service_charge'] = strval($objResto['service_charge']);
     } else {
         $invoice['service_charge'] = strval($objResto['service_charge'] / 100 * $total);
     }
     if ($objResto['other_charge'] > 100) {
         //
         $invoice['other_charge'] = strval($objResto['other_charge']);
     } else {
         $invoice['other_charge'] = strval($objResto['other_charge'] / 100 * $total);
     }
     $disc_bank = self::getDiscountCreditCard($id_restaurant, $id_bank);
     if ($objResto['disc_bank'] > 100) {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank']);
     } else {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank'] / 100 * $total);
     }
     $discMR = self::getDiscountMR($id_restaurant);
     if ($discMR > 100) {
         //
         $invoice['Discount_MR'] = strval($discMR);
     } else {
         $invoice['Discount_MR'] = strval($discMR / 100 * $total);
     }
     $feeMR = self::getFeeMR($id_restaurant);
     $feeBank = self::getFeeCreditCard($id_restaurant, $id_bank);
     //        $total_2 = $total_2 - $invoice['Discount_Bank'];
     if ($objResto['disc_resto'] > 100) {
         //
         $invoice['Discount_Resto'] = strval($objResto['disc_resto']);
     } else {
         $invoice['Discount_Resto'] = strval($objResto['disc_resto'] / 100 * $total);
     }
     // Fee
     //
     //        $total_2 = $total_2 - $invoice['Discount_Resto'];
     $invoice['Tax'] = strval($total * ($objResto['tax_pb_1'] / 100));
     $invoice['Total'] = strval($total + $invoice['Tax'] + $invoice['service_charge'] + $invoice['other_charge'] - $invoice['Discount_MR'] - $invoice['Discount_Bank'] - $invoice['Discount_Resto']);
     return $invoice;
 }
 public function send()
 {
     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);
     $restoName = User::getRestaurant($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);
     if ($res) {
         $json['status_code'] = 1;
         $json['status_message'] = "Success!";
     } else {
         $json['status_code'] = 0;
         $json['status_message'] = "Failed!!";
     }
     echo json_encode($json);
     die;
 }
 private function calcRechnungAndSave($id_restaurant, $id_order)
 {
     $order = new MasterOrderModel();
     $order->getByID($id_order);
     $objResto = User::getRestaurant($id_restaurant);
     //        pr($objResto );
     $objOrder = MasterOrder::getOrder($id_order);
     $arrOrderDetails = OrderDetail::getOrderDetailsByIDOrderForCalc($id_order);
     $total = 0;
     foreach ($arrOrderDetails as $orderDetails) {
         //            pr($orderDetails);
         $total = $total + $orderDetails['price'];
     }
     $invoice['sub_total'] = strval($total);
     $order->total_cost = $invoice['sub_total'];
     if ($objResto['service_charge'] > 100) {
         $invoice['service_charge'] = strval($objResto['service_charge']);
     } else {
         $invoice['service_charge'] = strval($objResto['service_charge'] / 100 * $total);
     }
     $order->service_charge = $invoice['service_charge'];
     if ($objResto['other_charge'] > 100) {
         $invoice['other_charge'] = strval($objResto['other_charge']);
     } else {
         $invoice['other_charge'] = strval($objResto['other_charge'] / 100 * $total);
     }
     $order->other_charge = $invoice['other_charge'];
     if ($objResto['disc_mr'] > 100) {
         $invoice['Discount_MR'] = strval($objResto['disc_mr']);
     } else {
         $invoice['Discount_MR'] = strval($objResto['disc_mr'] / 100 * $total);
     }
     $order->disc_mr = $invoice['Discount_MR'];
     if ($objResto['disc_bank'] > 100) {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank']);
     } else {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank'] / 100 * $total);
     }
     $order->disc_bank = $invoice['Discount_Bank'];
     if ($objResto['disc_resto'] > 100) {
         $invoice['Discount_Resto'] = strval($objResto['disc_resto']);
     } else {
         $invoice['Discount_Resto'] = strval($objResto['disc_resto'] / 100 * $total);
     }
     $order->disc_resto = $invoice['Discount_Resto'];
     $invoice['Tax'] = strval($total * ($objResto['tax_pb_1'] / 100));
     $order->tax_pb1 = $invoice['Discount_Resto'];
     $invoice['Total'] = strval($total + $invoice['Tax'] + $invoice['service_charge'] + $invoice['other_charge'] - $invoice['Discount_MR'] - $invoice['Discount_Bank'] - $invoice['Discount_Resto']);
     $order->grand_total = $invoice['Total'];
     $order->save();
     return $invoice;
 }
 public function getAllOrderById()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $idUser = Generic::mustCheck($_GET['id_user'], Keys::$ERR_NOT_FOUND_ID_USER);
     $idOrder = Generic::mustCheck($_GET['id_order'], Keys::$ERR_NOT_FOUND_ID_ORDER);
     if (!Util::checkUserID($idUser)) {
         Generic::errorMsg(Keys::$ERR_NOT_FOUND_ID_USER);
     }
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     //Tambahan :
     //cek apakah ada payment method yang dikirim (utk set pertama atau ganti payment method)
     $payment_method = addslashes($_GET['payment_method']);
     if ($payment_method != "") {
         $order->payment_method = $payment_method;
         $order->save();
     }
     //cek user apakah bagian dari order
     if (!Util::isPartOfOrder($idOrder, $idUser)) {
         Generic::errorMsg(Keys::$FATAL_ERROR_MISMATCH_ORDER);
     }
     //ini pending maka order yang dipanggil harus :
     // 1. status aktif
     // 2. belum di bayar
     // 3. belum order now
     if ($order->status_payment != Keys::$PAYMENT_STATUS_UNPAID && $order->order_now != Keys::$NO && $order->status_payment == Keys::$NO) {
         Generic::errorMsg("ERROR - NOT PENDING ORDER");
     }
     //cek leader atau bukan
     if (Util::isLeader($idOrder, $idUser)) {
         $user = new UserModel();
         $user->getByID($idUser);
         $isLeader = Keys::$YES;
         $paymentType = $user->payment_type;
         $paymentId = $user->payment_id;
         $paymentToken = $user->payment_token;
         $hasToken = Generic::IsNullOrEmptyString($user->payment_token) ? false : true;
         $isCash = Generic::IsNullOrEmptyString($user->payment_type) || $user->payment_type == Keys::$PAYMENT_TYPE_CASH ? true : false;
     } else {
         $isLeader = Keys::$NO;
         $paymentType = Keys::$EMPTY;
         $paymentId = Keys::$EMPTY;
         $paymentToken = Keys::$EMPTY;
         $hasToken = false;
         $isCash = false;
     }
     $hasTable = intval($order->id_table) > 0 ? Keys::$YES : Keys::$NO;
     $order = Util::getOrder($idOrder);
     $order['isLeader'] = $isLeader;
     $order['hasTable'] = $hasTable;
     $order['payment_type'] = $paymentType;
     $order['payment_id'] = $paymentId;
     $order['payment_token'] = $paymentToken;
     $order['has_token'] = $hasToken;
     $order['default_cash'] = $isCash;
     $order['restaurant'] = User::getRestaurant($order['id_restaurant']);
     $orderDetails = Util::getAllOrderDetailsByIDOrder($idOrder);
     //        $order["Order_Details"] = Array();
     $orderDetailByDishID = array();
     //        pr($orderDetails);
     $total = array();
     foreach ($orderDetails as $det) {
         if ($det['status_progress'] != 9) {
             //                echo "dis ID ".$det['id_dish']." | ".$total[$det['id_dish']]['quantity']." add ".$det['quantity']."<br>";
             $total[$det['id_dish']]['quantity'] += $det['quantity'];
         }
         $string_name = rtrim(trim(preg_replace('/\\s\\s+/', ' ', $det['name'])));
         $dish = new MasterDishModel();
         $dish->getByID($det['id_dish']);
         $total[$det['id_dish']]['id_dish'] = $det['id_dish'];
         $total[$det['id_dish']]['name'] = $string_name;
         $total[$det['id_dish']]['single_price'] = (double) $dish->price;
         $orderDetailByDishID[$det['id_dish']][] = $det;
     }
     //        pr($orderDetailByDishID);
     //        $order["total"] = $total;
     $hasilnya = array();
     $all_total = 0;
     foreach ($total as $key => $val) {
         $sem = array();
         $val['price_subtotal'] = $val['quantity'] * $val['single_price'];
         $all_total += $val['price_subtotal'];
         $sem = $val;
         $sem["orders"] = array();
         //kelompokan menurut status progess
         foreach ($orderDetailByDishID[$key] as $orderDetail) {
             $userInstance = Util::createUserInstance($orderDetail["id_user"], $orderDetail["note"], $orderDetail["id_order_detail"]);
             $orderDetail['user'] = $userInstance;
             if ($orderDetail['order_now'] == 0) {
                 $sem['orders']['Pending'][] = $orderDetail;
             } else {
                 $sem['orders'][Helper::getStatusProgress()[$orderDetail['status_progress']]][] = $orderDetail;
             }
         }
         $hasilnya[] = $sem;
     }
     $order['hasil'] = $hasilnya;
     $order['alltotal'] = $all_total;
     //        $sudah = array();
     //        foreach ($orderDetails as $orderDetail) {
     //            if ($orderDetail['status_progress'] == "") $orderDetail['status_progress'] = 0;
     //            $dish = new MasterDishModel();
     //            $dish->getByID($orderDetail['id_dish']);
     //
     //            $userInstance = Util::createUserInstance($orderDetail["id_user"], $orderDetail["note"], $orderDetail["id_order_detail"]);
     //            $string_name = rtrim(trim(preg_replace('/\s\s+/', ' ', $orderDetail['name'])));
     //
     //            $order['Order_Details_new'][$orderDetail['id_dish']]['quantity'] += $orderDetail['quantity'];
     //            $order['Order_Details_new'][$orderDetail['id_dish']]['price'] += ($orderDetail['quantity'] * $dish->price);
     //            if ($order['Order_Details'][$orderDetail['id_dish']]['status_progress'] !== null)
     //                $order['Order_Details_new'][$orderDetail['id_dish']]['status_progress'] = min($orderDetail['status_progress'], $order['Order_Details'][$orderDetail['id_dish']]['status_progress']);
     //            else
     //                $order['Order_Details_new'][$orderDetail['id_dish']]['status_progress'] = 0;
     //
     //            $order['Order_Details_new'][$orderDetail['id_dish']]['id_dish'] = $orderDetail['id_dish'];
     //            $order['Order_Details_new'][$orderDetail['id_dish']]['name'] = $string_name;
     //            $order['Order_Details_new'][$orderDetail['id_dish']]['single_price'] = (double)$dish->price;
     //            $order['Order_Details_new'][$orderDetail['id_dish']]['users'][] = $userInstance;
     //        }
     ////        pr($order['Order_Details_new']);
     //
     //
     //        foreach ($order['Order_Details_new'] as $obj) {
     //            if ($obj['quantity'] < 1) continue;
     //            $order['Order_Details'][] = $obj;
     //        }
     //        foreach ($orderDetails as $orderDetail) {
     //
     //
     //            $b = array();
     //            $userInstance = Util::createUserInstance($orderDetail["id_user"], $orderDetail["note"], $orderDetail["id_order_detail"]);
     //            $posDuplicate = Util::checkDuplicateDishId($order["Order_Details"], $orderDetail["id_dish"]);
     //            if ($posDuplicate !== null && $orderDetail["quantity"] > 0) {
     //                $order["Order_Details"][$posDuplicate]["users"][] = $userInstance;
     //                $order["Order_Details"][$posDuplicate]["quantity"] = (string)($order["Order_Details"][$posDuplicate]["quantity"] + $orderDetail["quantity"]);
     //                $order["Order_Details"][$posDuplicate]["price"] = (string)($orderDetail["price"] + $order["Order_Details"][$posDuplicate]["price"]);
     //                $order["Order_Details"][$posDuplicate]["status_progress"] = min($orderDetail["status_progress"], $order["Order_Details"][$posDuplicate]["status_progress"]);
     //            } else {
     //                $dish = new MasterDishModel();
     //                $dish->getByID($orderDetail["id_dish"]);
     //
     //                $b["id_dish"] = $orderDetail["id_dish"];
     //                $b["quantity"] = $orderDetail["quantity"];
     //                $b["price"] = $orderDetail["price"];
     //                $b["name"] = $orderDetail["name"];
     //                $b["status_progress"] = $orderDetail["status_progress"];
     //                $b["single_price"] = (double)$dish->price;
     //                $b["users"][] = $userInstance;
     //                array_push($order["Order_Details"], $b);
     //            }
     //        }
     //        pr($order['Order_Details']);
     //                $order['Group_Order_Details'] = $arr;
     //        $invoice = Util::calcRechnung($order['id_restaurant'], $idOrder);
     //        Util::setInvoiceInOrder($order, $invoice);
     $inv = new Invoice($idOrder, 2);
     $order['invoice'] = $inv->getInvoice();
     $order['my_payment'] = Util::getMyPayment($idUser);
     Generic::finish($order);
     die;
     /////////LAMA//////////
 }
 public function updateResto_tmp()
 {
     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;
     }
     $json = array();
     $json['status_code'] = 1;
     $objRestaurant = new MasterRestaurantModel();
     $objRestaurant->getById($id_restaurant);
     $exp = explode(",", str_replace(" ", "", $objRestaurant->crud_webservice_allowed));
     foreach ($exp as $attr) {
         if ($_POST[$attr] != "") {
             if ($attr == "image_logo") {
                 $file = self::savePic($_POST[$attr]);
                 $objRestaurant->{$attr} = $file;
             } else {
                 $objRestaurant->{$attr} = $_POST[$attr];
             }
         }
     }
     $objRestaurant->load = 1;
     $id = $objRestaurant->save();
     if ($id == "") {
         Generic::errorMsg("Update failed!");
     }
     $json['results'] = User::getRestaurant($id_restaurant);
     echo json_encode($json);
     die;
 }
 public function loadHomeRecommendation()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $page = addslashes($_GET['page']);
     if ($page == "" || $page < 1) {
         Generic::errorMsg("No Page Found");
     }
     $limit = addslashes($_GET['limit']);
     if ($limit == "" || $limit < 1) {
         Generic::errorMsg("Limit Error");
     }
     $begin = ($page - 1) * $limit;
     $json = array();
     $sem = array();
     $objRecommendation = new RecommendationModel();
     $exp = explode(",", str_replace(" ", "", $objRecommendation->crud_webservice_allowed));
     $arrPicsToAddPhotoUrl = $objRecommendation->crud_add_photourl;
     $arr = $objRecommendation->getWhere("DATE(end) >= DATE(NOW()) AND DATE(start)<= DATE(NOW())  LIMIT {$begin},{$limit}");
     if (count($arr) == 0) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     $json["results"]['restaurant'] = array();
     foreach ($arr as $o) {
         foreach ($exp as $attr) {
             if (in_array($attr, $arrPicsToAddPhotoUrl)) {
                 $sem[$attr] = Generic::insertImageUrl($o->{$attr});
             } elseif ($attr == "time_open" || $attr == "time_close") {
                 $sem[$attr] = date('H:i', strtotime(stripslashes($o->{$attr})));
             } else {
                 $sem[$attr] = stripslashes($o->{$attr});
             }
             $sem['disc_mr'] = MasterOrder::getDiscountMR($o->id_restaurant);
         }
         $sem['restaurant'] = User::getRestaurant($o->id_restaurant);
         $json["results"]['restaurant'][] = $sem;
     }
     echo json_encode($json);
     die;
 }
 public function scandinein()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_user = isset($_GET['id_user']) ? addslashes($_GET['id_user']) : "";
     if (!$id_user) {
         Generic::errorMsg("Please login!");
     }
     if (!User::checkUserID($id_user)) {
         Generic::errorMsg("ID User not found!");
     }
     $QR = isset($_GET['QR']) ? addslashes($_GET['QR']) : "";
     if (!$QR) {
         Generic::errorMsg("No QR found!");
     }
     $id_order = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : "";
     if (!id_order) {
         Generic::errorMsg("id_order not found!");
     }
     if (!MasterOrder::isIdorderValid($id_order)) {
         Generic::errorMsg("id_order not found!");
     }
     $objTableHlp = Mastertable::getTableBYQR($QR);
     $objTable = new MasterTableModel();
     $objTable->getByID($objTableHlp[0]->id_table);
     $objTable->appOrder = "1";
     $objTable->id_order = $id_order;
     $objTable->status = "0";
     $objTable->waitingOrder = "2";
     $objTable->load = 1;
     $objTable->save();
     $objOrder = new MasterOrderModel();
     $objOrder->getByID($id_order);
     $objOrder->id_table = $objTableHlp[0]->id_table;
     $objOrder->type_order = "1";
     $objOrder->load = 1;
     $objOrder->save();
     $objOrderHlp = new MasterOrderModel();
     $arrOrder = $objOrderHlp->getWhere("id_user='******' AND status_progress < 3 OR status_payment='0'");
     Generic::checkCountWithMsg($arrOrder, "No ID Order from the ID User found");
     $id_order = $arrOrder[0]->id_order;
     $order = MasterOrder::getOrder($id_order);
     $arrOrderDetails = OrderDetail::getOrderDetailsByIDOrderAndUserID($id_order, $id_user);
     $order['Order_Details'] = $arrOrderDetails;
     $order['restaurant'] = User::getRestaurant($order['id_restaurant']);
     $json['results'][] = $order;
     echo json_encode($json);
     die;
 }