You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.6 KiB
JavaScript
87 lines
2.6 KiB
JavaScript
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
function sendTransactionToServer(callback) {
|
|
var items = [];
|
|
var payments = [];
|
|
var customer = customerid;
|
|
var register = $("#register").data('id');
|
|
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;
|
|
var code = $(this).data("code");
|
|
var id = $(this).data("itemid");
|
|
items.push({
|
|
each: each,
|
|
qty: qty,
|
|
code: code,
|
|
id: id
|
|
});
|
|
});
|
|
$("#payment-lines .list-group-item").each(function () {
|
|
var amount = $(".payment-entry", this).val() * 1.0;
|
|
var type = $(".payment-entry", this).data("type");
|
|
var code = '';
|
|
if ($(".giftcard-number", this).length) {
|
|
code = $(".giftcard-number", this).val();
|
|
}
|
|
payments.push({
|
|
amount: amount,
|
|
type: type,
|
|
code: code
|
|
});
|
|
});
|
|
|
|
$.post("action.php", {
|
|
action: "finish_transaction",
|
|
items: items,
|
|
payments: payments,
|
|
customer: customer,
|
|
register: register,
|
|
discountpercent: discountpercent
|
|
}, function (data) {
|
|
if (data.status == "OK") {
|
|
callback(data);
|
|
} else {
|
|
bsalert("Error", "The transaction could not be completed:<br />" + data.message);
|
|
}
|
|
}).fail(function () {
|
|
bsalert("Error", "The transaction could not be completed due to an unknown error.");
|
|
});
|
|
}
|
|
|
|
function showReceipt(txid) {
|
|
$("#receiptframe").attr("src", 'action.php?action=getreceipt&txid=' + txid);
|
|
$("#receiptmodal").modal();
|
|
}
|
|
|
|
function finishTransaction() {
|
|
sendTransactionToServer(function (data) {
|
|
showReceipt(data.txid);
|
|
});
|
|
}
|
|
|
|
$("#finishbtn").click(function () {
|
|
recalculate();
|
|
var owed = $("#owed-amount").text() * 1.0;
|
|
if (owed > 0) {
|
|
bsalert("Incomplete Transaction", "The customer still owes $" + owed.toFixed(2) + ". Add a payment or remove items until everything is paid for.");
|
|
} else {
|
|
finishTransaction();
|
|
}
|
|
});
|
|
|
|
$("#receiptprintbtn").click(function () {
|
|
document.getElementById("receiptframe").contentWindow.print();
|
|
});
|
|
|
|
$("#receiptmodal").on("hide.bs.modal", function () {
|
|
window.location.reload();
|
|
}); |