/*
* 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 addItem(name, code, price) {
if ($(".list-group-item[data-code='" + code + "']").length) {
updateQty($(".list-group-item[data-code='" + code + "']").find(".qty-plus"), 1);
return;
}
$("#pos-lines-box").append('
'
+ '
'
+ '
'
+ name
+ '
'
+ ''
+ '' + code + ''
+ ''
+ '$'
+ price
+ ''
+ ''
+ '
'
+ ''
+ '
'
+ '
');
}
function recalculate() {
var total = 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));
total += line;
});
$(".grand-total").text(total.toFixed(2));
}
function updateQty(btn, diff) {
var qtybox = $(btn).parent().parent().find(".item-qty");
var qty = parseInt(qtybox.val());
qty += diff;
if (qty > 0) {
qtybox.val(qty);
var minbtn = $(btn).parent().parent().find(".qty-minus");
if (qty == 1) {
minbtn.html("");
} else {
minbtn.html("");
}
} else {
qtybox.closest(".list-group-item").remove();
}
recalculate();
}
$("#pos-lines-box").on("click", ".qty-minus", function () {
updateQty(this, -1);
});
$("#pos-lines-box").on("click", ".qty-plus", function () {
updateQty(this, 1);
});
$("#pos-lines-box").on("change", ".item-qty,.item-price", function () {
recalculate();
});