public function changePaymentMethod()
 {
     $idUser = Generic::mustCheck($_GET['id_user'], Keys::$ERR_NOT_FOUND_ID_USER);
     $idOrder = Generic::mustCheck($_GET['id_order'], Keys::$ERR_NOT_FOUND_ID_ORDER);
     $paymentMethod = Generic::mustCheck($_GET['payment_method'], Keys::$ERR_NOT_FOUND_PAYMENT_METHOD);
     if (!Util::isLeader($idOrder, $idUser)) {
         Generic::errorMsg(Keys::$ERR_CHANGE_PAYMENT_NOT_LEADER);
     }
     if (!in_array($paymentMethod, Helper::getPaymentTypes())) {
         Generic::errorMsg(Keys::$ERR_PAYMENT_TYPE_NOT_ALLOWED);
     }
     $order = new MasterOrderModel();
     $order->getByID($idOrder);
     $order->payment_method = $paymentMethod;
     $invoice = new Invoice($idOrder, true);
     //update totalan di row order model
     $order->disc_resto = $invoice->valDiscRestaurant;
     $order->disc_bank = $invoice->valDiscBank;
     $order->disc_mr = $invoice->valDiscMR;
     $order->tax_pb1 = $invoice->valTaxCharge;
     $order->service_charge = $invoice->valServiceCharge;
     $order->other_charge = $invoice->valOtherCharge;
     $order->cc_fee = $invoice->valFeeBank;
     $order->mr_fee = $invoice->valFeeMR;
     $order->total_cost = $invoice->subTotal;
     $order->grand_total = $invoice->grandTotal;
     $order->save();
     $results['invoice'] = $invoice->getInvoice();
     Generic::finish($results);
 }
<?php

require 'core/init.php';
?>

<?php 
//Create Topics Object
$invoice = new Invoice();
$user = new User();
//Get user From URL
$user_id = isset($_GET['username']) ? $_GET['username'] : null;
//Get Template & Assign Vars
$template = new Template('templates/invoices.php');
$name = getUser()['username'];
$id = htmlspecialchars($_GET["id"]);
$template->invoices = $invoice->getInvoice($id);
$unique = $invoice->getInvoice($id);
$_SESSION['invoice_number'] = $unique->invoice_number;
$_SESSION['create_date'] = $unique->create_date;
$_SESSION['due'] = $unique->due;
$_SESSION['payee'] = $unique->payee;
$_SESSION['amount'] = $unique->amount;
$_SESSION['description'] = $unique->description;
//Setting the id of the invoice
$_SESSION['singleId'] = $id;
//Display template
echo $template;
 public function addOrderInPendingOrder()
 {
     //TODO Sama seperti add order kemarin, tapi quantity cuma bisa set 1
     //TODO master apa bukan
     if (Efiwebsetting::getData('checkOAuth') == 'yes') {
         IMBAuth::checkOAuth();
     }
     $id_user = isset($_GET['id_user']) ? addslashes($_GET['id_user']) : "";
     if (!$id_user) {
         Generic::errorMsg("Please login!");
     }
     $id_order = isset($_GET['id_order']) ? addslashes($_GET['id_order']) : "";
     if (!$id_order) {
         Generic::errorMsg("ID Order not found!");
     }
     $id_dish = isset($_GET['id_dish']) ? addslashes($_GET['id_dish']) : "";
     if (!$id_dish) {
         Generic::errorMsg("ID Dish not found!");
     }
     $arah = addslashes($_GET['arah']);
     //plus //minus
     //ambil order saya, kalau blom ada, dan action plus, maka bikin baru
     //ambil order saya kalau blom ada dan action minus dan saya master..boleh kurangi, else meldung tidak bisa mengurangi order yang bukan milik anda
     //kalau master ambil order semua
     $ada_default_order = 0;
     $myOrder = "";
     $objOrderDetail = new OrderDetailModel();
     $arrObj = $objOrderDetail->getWhere("id_user = '******' AND id_order = '{$id_order}' AND id_dish ='{$id_dish}' AND order_now!=1 LIMIT 0,1");
     if (count($arrObj) > 0) {
         $ada_default_order = 1;
         $myOrder = $arrObj[0];
     }
     $dish = new MasterDishModel();
     $dish->getByID($id_dish);
     $isLeader = Util::isLeader($id_order, $id_user);
     if ($arah == "plus") {
         if (!$ada_default_order) {
             $price = $dish->price;
             //krn qty = 1
             $objOrderDetail = new OrderDetailModel();
             $objOrderDetail->id_user = $id_user;
             $objOrderDetail->id_order = $id_order;
             $objOrderDetail->id_dish = $id_dish;
             $objOrderDetail->quantity = 1;
             $objOrderDetail->price = $price;
             $objOrderDetail->datetime_order = $this->setCurrentDate();
             $objOrderDetail->status = "1";
             //            $dishname = MasterDish::getDish($id_dish);
             //                $objOrderDetail->quantity = 1;
             $id = $objOrderDetail->save();
         } else {
             $price = $dish->price * ($myOrder->quantity + 1);
             $myOrder->quantity++;
             $myOrder->price = $price;
             $myOrder->datetime_order = $this->setCurrentDate();
             $myOrder->status = "1";
             $myOrder->load = 1;
             $myOrder->save();
             $id = $myOrder->id_order_detail;
         }
     }
     if ($arah == "minus") {
         if ($ada_default_order) {
             //cek apa default ordernya masi plus
             if ($myOrder->quantity > 0) {
                 //minus biasa
                 $price = $dish->price * ($myOrder->quantity - 1);
                 $myOrder->quantity--;
                 $myOrder->price = $price;
                 $myOrder->datetime_order = $this->setCurrentDate();
                 $myOrder->status = "1";
                 $myOrder->load = 1;
                 $myOrder->save();
                 $id = $myOrder->id_order_detail;
             } else {
                 if ($isLeader) {
                     //minus dari anggota yang lain
                     $objOrderDetail = new OrderDetailModel();
                     $arrObjLain = $objOrderDetail->getWhere("id_order = '{$id_order}' AND id_dish ='{$id_dish}'");
                     if (count($arrObjLain) > 0) {
                         //bisa dikurangin dari yang lain..lihat qty nya juga
                         $sum = 0;
                         foreach ($arrObjLain as $od) {
                             $sum += $od->quantity;
                         }
                         if ($sum > 0) {
                             foreach ($arrObjLain as $od) {
                                 if ($od->quantity > 0) {
                                     //minus biasa
                                     $price = $dish->price * ($od->quantity - 1);
                                     $od->quantity--;
                                     $od->price = $price;
                                     $od->datetime_order = $this->setCurrentDate();
                                     $od->status = "1";
                                     $od->load = 1;
                                     $od->save();
                                     $id = $od->id_order_detail;
                                     break;
                                 }
                             }
                         } else {
                             //habis ga bisa dikurangi
                             Generic::errorMsg("Not Enough Quantity");
                         }
                     } else {
                         Generic::errorMsg("Not Enough Quantity");
                     }
                 } else {
                     //Notify kl jumlah tidak cukup utk dikurangi
                     //habis ga bisa dikurangi
                     Generic::errorMsg("Not Enough Quantity");
                 }
             }
         } else {
             //minus dr anggota yang lain
             if ($isLeader) {
                 //minus dari anggota yang lain
                 $objOrderDetail = new OrderDetailModel();
                 $arrObjLain = $objOrderDetail->getWhere("id_order = '{$id_order}' AND id_dish ='{$id_dish}'");
                 if (count($arrObjLain) > 0) {
                     //bisa dikurangin dari yang lain..lihat qty nya juga
                     $sum = 0;
                     foreach ($arrObjLain as $od) {
                         $sum += $od->quantity;
                     }
                     if ($sum > 0) {
                         foreach ($arrObjLain as $od) {
                             if ($od->quantity > 0) {
                                 //minus biasa
                                 $price = $dish->price * ($od->quantity - 1);
                                 $od->quantity--;
                                 $od->price = $price;
                                 $od->datetime_order = $this->setCurrentDate();
                                 $od->status = "1";
                                 $od->load = 1;
                                 $od->save();
                                 $id = $od->id_order_detail;
                                 break;
                             }
                         }
                     } else {
                         //habis ga bisa dikurangi
                         Generic::errorMsg("Not Enough Quantity");
                     }
                 } else {
                     Generic::errorMsg("Not Enough Quantity");
                 }
             } else {
                 //Notify kl jumlah tidak cukup utk dikurangi
                 Generic::errorMsg("Not Enough Quantity");
             }
         }
     }
     if ($arah == "") {
         Generic::errorMsg("Please insert arah");
     }
     // getcurrent qty dr iddish
     //        $currQuantity = OrderDetail::getQuantityUserByID_dish($id_dish, $id_order, $id_user);
     //        $id = $this->addOrderDetails($id_order, $id_user, $id_dish, $currQuantity + 1);
     if (!$id) {
         Generic::errorMsg("Add order failed!");
     }
     $objOrder = new MasterOrderModel();
     $objOrder->getByID($id_order);
     $invoice = $this->calcRechnung($objOrder->id_restaurant, $id_order);
     $inv = new Invoice($id_order, true);
     $this->setInvoiceInOrder($objOrder, $invoice);
     $objOrder->datetime_order = $this->setCurrentDate();
     //        $objOrder->total_cost = $invoice['Total'];
     $objOrder->load = 1;
     $id_updateOrder = $objOrder->save();
     if (!$id_updateOrder) {
         Generic::errorMsg("Update Order failed!");
     }
     $json = array();
     $json['status_code'] = 1;
     $json['results']['messages'] = "Success";
     $orderDetails = Util::getAllOrderDetailsByIDOrder($id_order);
     $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;
     }
     $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;
     }
     $json['results']['hasil'] = $hasilnya;
     $json['results']['alltotal'] = $all_total;
     $json['results']['invoice'] = $inv->getInvoice();
     $ids = $this->getUserIdByIDOrder($id_order, $id_user);
     //        $json['results']['push'] = $this->notifyAddOrder($ids, $id_order);
     $json['results']['push'] = Util::pushNotifyAddOrder($id_order, $id_user, $id_dish);
     echo json_encode($json);
     //        $json['APA'] = "";
     //        $json2 =$this->notifyAddOrder($ids, $id_order);
     //        $json3 = array_merge($json, $json2);
     //        echo json_encode($json3) ;
     die;
 }
<?php

require 'core/init.php';
$invoice = new Invoice();
$user = new User();
$searcher = getUser()['user_id'];
$search = $_POST['search'];
$searchIDs = $invoice->search($search);
foreach ($searchIDs as $key) {
    foreach ($key as $var => $info) {
        // echo $info; "<br/>";
        $invoices = $invoice->getInvoice($info);
    }
}
//Get Template & Assign Vars
$template = new Template('templates/frontpage.php');
$template->invoices = $invoice->search($search);
//Display template
echo $template;
Exemple #5
0
        $invoices = Invoice::getInvoices($patient_id);
        $patient = getPatient($patient_id);
        //set the backLink
        $backLink = "index.php?com=patient&view=patient&patient_id=" . $patient_id;
        include 'views/list.php';
        break;
    case 'edit_invoice':
        $user_id = get_current_user_id();
        // get all the uninvoiced payments for the a patient..
        $payments = Payment::getPayments($patient_id, 0);
        $appointments = getAppointments($patient_id);
        $patient = getPatient($patient_id);
        if (getVar('invoice_id') != NULL) {
            $invoice_id = getVar('invoice_id');
        }
        // if letter_id == NULL -> a call was made to create a new invoice. invoice_id is passed from the create_new_invoice task
        $invoice = Invoice::getInvoice($invoice_id);
        $invoice_date = new DateTime($invoice->date);
        //get all invoice items
        $invoice_items = Invoice::getInvoiceItems($invoice_id);
        //get the invoice heading for the clinic
        $invoice_heading = Invoice::getInvoiceHeading($patient->clinic);
        //get the practitioner name for the invoice
        $user = get_userdata($patient->practitioner);
        //get the signature
        $signature = "img/signatures/signature_thierry.png";
        //set the backLink
        $backLink = "index.php?com=invoice&view=list&patient_id=" . $patient->patient_id;
        include 'views/edit_invoice.php';
        break;
}