diff --git a/action.php b/action.php
index 346ca74..4a40dbf 100644
--- a/action.php
+++ b/action.php
@@ -37,6 +37,7 @@ switch ($VARS['action']) {
$payments = $VARS['payments'];
$customer = $VARS['customer'];
$register = $VARS['register'];
+ $discountpercent = $VARS['discountpercent'];
if ($customer != "" && !$database->has('customers', ['customerid' => $customer])) {
exit(json_encode(["status" => "ERROR", "message" => lang("invalid customer", false)]));
@@ -69,6 +70,13 @@ switch ($VARS['action']) {
}
}
+ if (is_numeric($discountpercent) && $discountpercent > 0 && $discountpercent < 100) {
+ $discountpercent = $discountpercent * 1.0;
+ $totalcharge *= 1.0 - ($discountpercent / 100.0);
+ } else {
+ $discountpercent = 0.0;
+ }
+
if ($totalcharge > $totalpaid) {
exit(json_encode(["status" => "ERROR", "message" => lang("insufficient payment", false)]));
}
@@ -83,7 +91,8 @@ switch ($VARS['action']) {
'customerid' => ($customer != "" ? $customer : null),
'type' => 1,
'cashier' => $_SESSION['uid'],
- 'cashid' => $cashid
+ 'cashid' => $cashid,
+ 'discountpercent' => $discountpercent
]);
$txid = $database->id();
@@ -128,7 +137,7 @@ switch ($VARS['action']) {
exit(json_encode(["status" => "ERROR", "txid" => null]));
}
- $tx = $database->get('transactions', ['txid', 'txdate', 'customerid', 'type', 'cashier'], ['txid' => $VARS['txid']]);
+ $tx = $database->get('transactions', ['txid', 'txdate', 'customerid', 'type', 'cashier', 'discountpercent'], ['txid' => $VARS['txid']]);
$txid = $tx['txid'];
$datetime = date(DATETIME_FORMAT, strtotime($tx['txdate']));
@@ -142,7 +151,7 @@ switch ($VARS['action']) {
$itemhtml = "";
$items = $database->select('lines', ['amount', 'name', 'itemid', 'qty'], ['txid' => $txid]);
- $total = 0.0;
+ $subtotal = 0.0;
$paid = 0.0;
foreach ($items as $i) {
$itemhtml .= "\n";
@@ -152,9 +161,11 @@ switch ($VARS['action']) {
$itemhtml .= '
x' . (float) $i['qty'] . '
';
$itemhtml .= '$' . number_format($i['qty'] * $i['amount'] * 1.0, 2) . '
';
$itemhtml .= '';
- $total += $i['qty'] * $i['amount'] * 1.0;
+ $subtotal += $i['qty'] * $i['amount'] * 1.0;
}
+ $total = $subtotal * (1.0 - ((float) $tx['discountpercent'] / 100));
+
$paymenthtml = "";
$payments = $database->select('payments', [
'[>]payment_types' => ['type' => 'typeid']
@@ -177,9 +188,15 @@ switch ($VARS['action']) {
$change = 0.0;
}
- $totalstr = number_format($total, 2);
+ $subtotalstr = number_format($subtotal, 2);
$paidstr = number_format($paid, 2);
$changestr = number_format($change, 2);
+ $totalstr = $subtotalstr;
+ $discountstr = "";
+ if ($tx['discountpercent'] > 0) {
+ $discountstr = 'Discount: ' . (float) $tx['discountpercent'] . '% off
';
+ $totalstr = number_format($total, 2);
+ }
$html = <<
@@ -203,6 +220,8 @@ $customerline
$itemhtml
+Subtotal: $$subtotalstr
+$discountstr
Total: $$totalstr
diff --git a/database.mwb b/database.mwb
index 5e13297..cbdacbd 100644
Binary files a/database.mwb and b/database.mwb differ
diff --git a/lang/en_us.php b/lang/en_us.php
index 2baf03f..9eff48a 100644
--- a/lang/en_us.php
+++ b/lang/en_us.php
@@ -47,4 +47,5 @@ define("STRINGS", [
"print" => "Print",
"customer" => "Customer",
"customer search" => "Search customers",
+ "new sale" => "New Sale",
]);
\ No newline at end of file
diff --git a/pages/pos.php b/pages/pos.php
index 4d1f8d6..f845693 100644
--- a/pages/pos.php
+++ b/pages/pos.php
@@ -19,7 +19,7 @@
@@ -83,7 +83,8 @@
-
+
+
diff --git a/static/js/pos.js b/static/js/pos.js
index 7a544e6..fc043ae 100644
--- a/static/js/pos.js
+++ b/static/js/pos.js
@@ -25,6 +25,11 @@ function recalculate() {
paid += line;
});
+ var discountpercent = $("#discountpercentbtn").data("percent");
+ if (discountpercent > 0 && discountpercent < 100) {
+ total *= 1.0 - ((discountpercent * 1.0) / 100);
+ }
+
remaining = total - paid;
change = (total - paid) * -1.0;
if (remaining <= 0) {
diff --git a/static/js/pos_finish.js b/static/js/pos_finish.js
index fc37670..a51df59 100644
--- a/static/js/pos_finish.js
+++ b/static/js/pos_finish.js
@@ -9,6 +9,10 @@ function sendTransactionToServer(callback) {
var payments = [];
var customer = customerid;
var register = '';
+ var discountpercent = $("#discountpercentbtn").data("percent");
+ if (discountpercent <= 0) {
+ discountpercent = 0.0;
+ }
$("#pos-lines-box .list-group-item").each(function () {
var each = $(".item-price", this).val() * 1.0;
var qty = $(".item-qty", this).val() * 1.0;
@@ -40,7 +44,8 @@ function sendTransactionToServer(callback) {
items: items,
payments: payments,
customer: customer,
- register: register
+ register: register,
+ discountpercent: discountpercent
}, function (data) {
if (data.status == "OK") {
callback(data);
diff --git a/static/js/pos_payment.js b/static/js/pos_payment.js
index 496b920..24e7c75 100644
--- a/static/js/pos_payment.js
+++ b/static/js/pos_payment.js
@@ -108,4 +108,22 @@ $("#paymentbtn").click(function () {
$(".payment-method-button").click(function () {
addPayment($(this).data("payment-method"), $(this).data("icon"), $(this).data("text"));
-});
\ No newline at end of file
+});
+
+$("#discountpercentbtn").click(function () {
+ bsprompt("Sale Discount",
+ "Enter a percentage to discount the transaction",
+ "Discount",
+ "Cancel",
+ "number",
+ function (result) {
+ if (result <= 0 || result >= 100) {
+ $("#discountpercentbtn").data("percent", 0.0);
+ $("#discountpercentbtnlabel").text("");
+ return;
+ }
+ $("#discountpercentbtn").data("percent", result);
+ $("#discountpercentbtnlabel").text(result);
+ recalculate();
+ });
+})
\ No newline at end of file