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.
68 lines
2.0 KiB
JavaScript
68 lines
2.0 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 recalculate() {
|
|
removezero();
|
|
var total = 0.0;
|
|
var paid = 0.0;
|
|
var remaining = 0.0;
|
|
var change = 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 line = each * qty;
|
|
$(".line-total", this).text(line.toFixed(2));
|
|
$(".item-price", this).val(each.toFixed(2));
|
|
console.log(each.toFixed(2));
|
|
total += line;
|
|
});
|
|
|
|
$("#payment-lines .list-group-item").each(function () {
|
|
var line = $(".payment-entry", this).val() * 1.0;
|
|
paid += line;
|
|
});
|
|
|
|
remaining = total - paid;
|
|
change = (total - paid) * -1.0;
|
|
if (remaining <= 0) {
|
|
remaining = 0.0;
|
|
$("#owed-amount").parent().removeClass("font-weight-bold");
|
|
} else {
|
|
$("#owed-amount").parent().addClass("font-weight-bold");
|
|
}
|
|
|
|
if (change <= 0) {
|
|
change = 0.0;
|
|
$("#change-amount").parent().removeClass("font-weight-bold");
|
|
} else {
|
|
$("#change-amount").parent().addClass("font-weight-bold");
|
|
}
|
|
|
|
$("#grand-total").text(total.toFixed(2));
|
|
$("#paid-amount").text(paid.toFixed(2));
|
|
$("#owed-amount").text(remaining.toFixed(2));
|
|
$("#change-amount").text(change.toFixed(2));
|
|
}
|
|
|
|
|
|
$("body").on("keypress", "input[type=money],input[type=number]", function (e) {
|
|
//console.log(String.fromCharCode(e.which) + "|" + e.which);
|
|
var c = String.fromCharCode(e.which);
|
|
var k = e.which;
|
|
if (/[0-9]|[\.]/.test(c)) {
|
|
// Numbers and period
|
|
} else if (k == 0 || k == 8) {
|
|
// Delete, backspace, etc
|
|
} else {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
// Make sure the session doesn't expire
|
|
setInterval(function () {
|
|
$.get("action.php", {action: "session_keepalive"});
|
|
}, 1000 * 60); |