public function clearTableWS()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $id_table = isset($_GET['id_table']) ? addslashes($_GET['id_table']) : "";
     if (!$id_table) {
         $json['status_code'] = 0;
         $json['status_message'] = "No ID Found";
         echo json_encode($json);
         die;
     }
     //        $objTable = new MasterTableModel();
     //        $arrTable = $objTable->getWhere("id_table='$id_table'");
     //
     //        MasterDish::checkCount($arrTable);
     //        // $onlyUpdates = array("id_order" => "0", "waitingOrder" => "0", "appOrder" => "", "cashPayment" => "");
     //        $arrTable[0]->id_order = "0";
     //        $arrTable[0]->waitingOrder = "0";
     //        $arrTable[0]->appOrder = "";
     //        $arrTable[0]->cashPayment = "";
     //        $arrTable[0]->status = "1";
     //        $arrTable[0]->load = 1;
     //        $id_objTable = $arrTable[0]->save();
     $id_objTable = self::clearTable($id_table);
     $objTable = new MasterTableModel();
     $objTable->getByID($id_table);
     $id_order = $objTable->id_order;
     if ($id_order != 0) {
         $objOrder = new MasterOrderModel();
         $objOrder->getByID($id_order);
         if ($id_table == $objOrder->id_table) {
             $objOrder->status_payment = "1";
             $objOrder->load = 1;
             $objOrder->save();
         }
     }
     if (!$id_objTable) {
         $json['status_code'] = 0;
         $json['results'] = Lang::t('save failed');
     } else {
         $json['status_code'] = 1;
         $json['results']['message'] = "success";
     }
     echo json_encode($json);
     die;
 }
 private function updateOrderHeaderStatusProgress($idOrder)
 {
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     $od = OrderDetail::getOrderDetailsByIDOrder($idOrder);
     foreach ($od as $orderDetail) {
         if (!$order->status_progress == $orderDetail->status_progress) {
             $order->status_progress = min($order->status_progress, $orderDetail->status_progress);
         }
     }
     $order->save();
     return $order;
 }
 private function calcRechnungAndSave($id_restaurant, $id_order)
 {
     $order = new MasterOrderModel();
     $order->getByID($id_order);
     $objResto = User::getRestaurant($id_restaurant);
     //        pr($objResto );
     $objOrder = MasterOrder::getOrder($id_order);
     $arrOrderDetails = OrderDetail::getOrderDetailsByIDOrderForCalc($id_order);
     $total = 0;
     foreach ($arrOrderDetails as $orderDetails) {
         //            pr($orderDetails);
         $total = $total + $orderDetails['price'];
     }
     $invoice['sub_total'] = strval($total);
     $order->total_cost = $invoice['sub_total'];
     if ($objResto['service_charge'] > 100) {
         $invoice['service_charge'] = strval($objResto['service_charge']);
     } else {
         $invoice['service_charge'] = strval($objResto['service_charge'] / 100 * $total);
     }
     $order->service_charge = $invoice['service_charge'];
     if ($objResto['other_charge'] > 100) {
         $invoice['other_charge'] = strval($objResto['other_charge']);
     } else {
         $invoice['other_charge'] = strval($objResto['other_charge'] / 100 * $total);
     }
     $order->other_charge = $invoice['other_charge'];
     if ($objResto['disc_mr'] > 100) {
         $invoice['Discount_MR'] = strval($objResto['disc_mr']);
     } else {
         $invoice['Discount_MR'] = strval($objResto['disc_mr'] / 100 * $total);
     }
     $order->disc_mr = $invoice['Discount_MR'];
     if ($objResto['disc_bank'] > 100) {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank']);
     } else {
         $invoice['Discount_Bank'] = strval($objResto['disc_bank'] / 100 * $total);
     }
     $order->disc_bank = $invoice['Discount_Bank'];
     if ($objResto['disc_resto'] > 100) {
         $invoice['Discount_Resto'] = strval($objResto['disc_resto']);
     } else {
         $invoice['Discount_Resto'] = strval($objResto['disc_resto'] / 100 * $total);
     }
     $order->disc_resto = $invoice['Discount_Resto'];
     $invoice['Tax'] = strval($total * ($objResto['tax_pb_1'] / 100));
     $order->tax_pb1 = $invoice['Discount_Resto'];
     $invoice['Total'] = strval($total + $invoice['Tax'] + $invoice['service_charge'] + $invoice['other_charge'] - $invoice['Discount_MR'] - $invoice['Discount_Bank'] - $invoice['Discount_Resto']);
     $order->grand_total = $invoice['Total'];
     $order->save();
     return $invoice;
 }
 public static function payViaCreditCard($idOrder, $idUser = "")
 {
     $restoInitiate = Generic::IsNullOrEmptyString($idUser);
     $userInitiate = !$restoInitiate;
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     //KALO USER INITIATE CEK APA DIA LEADER
     if ($userInitiate) {
         $user = new UserModel();
         $user->getByID($idUser);
         if (!Util::isLeader($idOrder, $idUser)) {
             Generic::errorMsg(Keys::$ERR_PAYMENT_NOT_LEADER);
         }
     } else {
         $idUser = $order->id_user;
         $user = new UserModel();
         $user->getByID($idUser);
     }
     //CEK APA PEMBAYARAN PAKE CREDIT CARD
     if ($order->payment_method != Keys::$PAYMENT_TYPE_CREDIT_CARD) {
         Generic::errorMsg("This Order Not Using Credit Card as Payment Method");
     }
     Doku_Initiate::$sharedKey = "iMdRs8Iz987Z";
     Doku_Initiate::$mallId = "3199";
     $invoice = new Invoice($idOrder, true);
     $params = array('amount' => Generic::dokuMoneyValue($invoice->grandTotal), 'invoice' => $idOrder, 'currency' => '360');
     $detailOrders = $invoice->orderDetails;
     $basket = array();
     foreach ($detailOrders as $detailOrder) {
         $b = array();
         $b['name'] = $detailOrder->name_dish;
         $b['amount'] = Generic::dokuMoneyValue($detailOrder->single_price);
         $b['quantity'] = $detailOrder->quantity;
         $b['subtotal'] = Generic::dokuMoneyValue($detailOrder->price);
         $basket[] = $b;
     }
     $words = Doku_Library::doCreateWords($params);
     $customer = array('name' => $user->full_name, 'data_phone' => $user->phone_no, 'data_email' => $user->email, 'data_address' => $user->district . ',' . $user->city);
     //        $basket[] = array(
     //            'name' => 'sayur',
     //            'amount' => '10000.00',
     //            'quantity' => '1',
     //            'subtotal' => '10000.00'
     //        );
     //        $basket[] = array(
     //            'name' => 'buah',
     //            'amount' => '10000.00',
     //            'quantity' => '1',
     //            'subtotal' => '10000.00'
     //        );
     $dataPayment = array('req_mall_id' => Doku_Initiate::$mallId, 'req_chain_merchant' => 'NA', 'req_amount' => $params['amount'], 'req_words' => $words, 'req_purchase_amount' => $params['amount'], 'req_trans_id_merchant' => $params['invoice'], 'req_request_date_time' => date('YmdHis'), 'req_currency' => '360', 'req_purchase_currency' => '360', 'req_session_id' => sha1(date('YmdHis')), 'req_name' => $customer['name'], 'req_payment_channel' => '15', 'req_email' => $customer['data_email'], 'req_basket' => $basket, 'req_address' => $customer['data_address'], 'req_token_payment' => $user->payment_token, 'req_customer_id' => $idUser);
     $response = Doku_Api::doDirectPayment($dataPayment);
     if ($response->res_response_code == '0000') {
         $status = "SUCCESS";
         $order->status_payment = Keys::$PAYMENT_STATUS_PAID;
         $order->isPaid = Keys::$YES;
         $order->load = 1;
         $order->save();
         //success
         $trans = new MasterRestoTransactionModel();
         $trans->id_restaurant = $order->id_restaurant;
         $trans->id_request = $order->id_order;
         $trans->gross_amount = $invoice->grandTotal;
         $trans->type_transaction = "1";
         $trans->datetime_transaction = leap_mysqldate();
         $trans->approved = "1";
         $trans->mr_fee = $invoice->valFeeMR;
         //doubleval($order->mr_fee);//((double)($arrOrder[0]->grand_total * $resto->mr_fee)) / 100;
         //TODO LATER CHANGE 3 (BANK FEE) INTO GLOBAL VAR
         $trans->other_fee = 0;
         //((double)($arrOrder[0]->grand_total * $resto->cc_fee)) / 100;
         $trans->bank_disc = $invoice->valDiscBank;
         //doubleval($order->disc_bank);//$objOrder->disc_bank;
         $valNetAmount = doubleval($trans->gross_amount - $trans->mr_fee - $trans->other_fee + $trans->bank_disc);
         $trans->net_amount = $valNetAmount;
         $trans->save();
         //reset user credit to 0
         $user = new UserModel();
         $user->getByID($idUser);
         $user->credit = 0;
         $user->save();
     } else {
         $status = "FAILED";
     }
     $results['status'] = $status;
     $results['res_token_id'] = $user->payment_token;
     $results['invoice_no'] = $idOrder;
     $results['id_user'] = $idUser;
     $results['res_response_code'] = $response->res_response_code;
     $results['doku_results'] = $response;
     //        $results['data_payment'] = $dataPayment;
     //        pr($results);
     if ($status == "SUCCESS") {
         return array("success" => 1, $results);
     } else {
         return array("success" => 0, $results);
     }
     //        Generic::finish($results);
 }
 public static function removeGuestOrder($idUser, $idOrder)
 {
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     if (Generic::IsNullOrEmptyString($order->user_guest_id) || $order->user_guest_id == "") {
         return false;
     }
     $arrGuest = explode(',', $order->user_guest_id);
     if (($key = array_search($idUser, $arrGuest)) !== false) {
         unset($arrGuest[$key]);
         $order->user_guest_id = count($arrGuest) <= 0 ? "" : implode(',', $arrGuest);
         //TODO SET USER ORDER DETAILS STATUS TO 0
         $order->save();
         return true;
     }
     return false;
 }
 public function scandinein()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $json = array();
     $json['status_code'] = 1;
     $id_user = isset($_GET['id_user']) ? addslashes($_GET['id_user']) : "";
     if (!$id_user) {
         Generic::errorMsg("Please login!");
     }
     if (!User::checkUserID($id_user)) {
         Generic::errorMsg("ID User not found!");
     }
     $QR = isset($_GET['QR']) ? addslashes($_GET['QR']) : "";
     if (!$QR) {
         Generic::errorMsg("No QR found!");
     }
     $id_order = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : "";
     if (!id_order) {
         Generic::errorMsg("id_order not found!");
     }
     if (!MasterOrder::isIdorderValid($id_order)) {
         Generic::errorMsg("id_order not found!");
     }
     $objTableHlp = Mastertable::getTableBYQR($QR);
     $objTable = new MasterTableModel();
     $objTable->getByID($objTableHlp[0]->id_table);
     $objTable->appOrder = "1";
     $objTable->id_order = $id_order;
     $objTable->status = "0";
     $objTable->waitingOrder = "2";
     $objTable->load = 1;
     $objTable->save();
     $objOrder = new MasterOrderModel();
     $objOrder->getByID($id_order);
     $objOrder->id_table = $objTableHlp[0]->id_table;
     $objOrder->type_order = "1";
     $objOrder->load = 1;
     $objOrder->save();
     $objOrderHlp = new MasterOrderModel();
     $arrOrder = $objOrderHlp->getWhere("id_user='******' AND status_progress < 3 OR status_payment='0'");
     Generic::checkCountWithMsg($arrOrder, "No ID Order from the ID User found");
     $id_order = $arrOrder[0]->id_order;
     $order = MasterOrder::getOrder($id_order);
     $arrOrderDetails = OrderDetail::getOrderDetailsByIDOrderAndUserID($id_order, $id_user);
     $order['Order_Details'] = $arrOrderDetails;
     $order['restaurant'] = User::getRestaurant($order['id_restaurant']);
     $json['results'][] = $order;
     echo json_encode($json);
     die;
 }
 public function saveToOrder()
 {
     $order = new MasterOrderModel();
     $order->getByID($this->idOrder);
     $order->disc_resto = doubleval($this->valDiscRestaurant);
     $order->disc_bank = doubleval($this->valDiscBank);
     $order->disc_mr = doubleval($this->valDiscMR);
     $order->tax_pb1 = doubleval($this->valTaxCharge);
     $order->service_charge = doubleval($this->valServiceCharge);
     $order->other_charge = doubleval($this->valOtherCharge);
     $order->cc_fee = doubleval($this->valFeeBank);
     $order->mr_fee = doubleval($this->valFeeMR);
     $order->total_cost = doubleval($this->subTotal);
     $order->grand_total = doubleval($this->grandTotal);
     //        pr($order);
     $order->save();
     return $order;
 }
 public function dineIn()
 {
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $id_user = isset($_POST['id_user']) ? addslashes($_POST['id_user']) : "";
     if (!$id_user) {
         Generic::errorMsg("ID User not found!");
     }
     if (!User::checkUserID($id_user)) {
         Generic::errorMsg("ID User not found!");
     }
     $id_order = isset($_POST['id_order']) ? addslashes($_POST['id_order']) : "";
     if (!$id_order) {
         Generic::errorMsg("ID Order not found!");
     }
     $nonce = isset($_POST["payment_method_nonce"]) ? addslashes($_POST["payment_method_nonce"]) : "";
     if (!$nonce) {
         Generic::errorMsg("Nonce not found!");
     }
     $json = array();
     $json['status_code'] = 1;
     $orderObj = new MasterOrderModel();
     $orderObj->getByID($id_order);
     $id_restaurant = $orderObj->id_restaurant;
     $objRestaurant = new MasterRestaurantModel();
     $objRestaurant->getByID($id_restaurant);
     $verification_amount = $objRestaurant->verification_amount;
     if ($orderObj->transaction_id != "" & $orderObj->nonce_cc != "") {
     }
     if ($orderObj->transaction_id != "" & $orderObj->nonce_cc != "") {
         Generic::errorMsg("ID Order " . $id_order . " with the transaction number is: " . $orderObj->transaction_id . " sudah bayar");
     }
     $result = Braintree_Transaction::sale(['customerId' => $id_user, 'amount' => $orderObj->total_cost, 'orderId' => $id_order, 'paymentMethodNonce' => $nonce, 'options' => ['submitForSettlement' => false]]);
     pr($result);
     die;
     // Jika pembayran gagal
     if ($result->success == "") {
         Generic::errorMsg("Failed");
     }
     $transaction = $result->transaction;
     $orderObj->transaction_id = $transaction->id;
     $orderObj->load = 1;
     $orderObj->status_payment = '1';
     $orderObj->nonce_cc = $nonce;
     $orderObj->isPaid = '1';
     $orderObj->save();
     $json['results'] = "Your Payment was successful with ID Order " . $id_order;
     echo json_encode($json);
     die;
 }
 private function createHeadOrder($id_user, $id_restaurant, $type_order)
 {
     //        $type_order = "3";
     $id_order = $this->addHeaderOrder($id_user, $type_order, false);
     $objOrderHlp = new MasterOrderModel();
     $objOrderHlp->getByID($id_order);
     $objOrderHlp->id_restaurant = $id_restaurant;
     $objOrderHlp->order_now = "0";
     $objOrderHlp->status_payment = "0";
     $objOrderHlp->user_count = "1";
     $objOrderHlp->load = 1;
     $objOrderHlp->save();
     return $id_order;
 }