Added mutation observer to sum totals
This commit is contained in:
@@ -191,7 +191,7 @@ Array.prototype.where = function<x>(this: x[], property: string, value: any) {
|
||||
return this.filter( item => (item as any)[property] === value)[0] || null
|
||||
}
|
||||
|
||||
const money = (amount: number) => currency(amount, {fromCents: true})
|
||||
const money = (amount: number, fromCents=true) => currency(amount, {fromCents: fromCents})
|
||||
const moneyFromString = (amount: string) => currency(amount)
|
||||
|
||||
//Id generator.
|
||||
|
||||
@@ -55,6 +55,16 @@ const setupOrderScreen = (data: OrderScreenData) => {
|
||||
turnOnMode('accumulate')
|
||||
|
||||
$('.loadPageGroup').first().trigger('click')
|
||||
|
||||
let observer = new window.MutationObserver((mutations, observer) => updateOrderBoxTotals())
|
||||
|
||||
observer.observe($('.orderBoxTable tbody').get()[0], {
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
childList: true
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,6 +293,23 @@ const voidLastItem = () => {
|
||||
voidRows(allRows.last())
|
||||
}
|
||||
|
||||
const updateOrderBoxTotals = () => {
|
||||
const allRows = $('.orderBoxTable tbody tr')
|
||||
const selectedRows = $('.orderBoxTable tbody tr.selected')
|
||||
$('.orderBoxTotal').text(getTotalOfRows(allRows))
|
||||
$('.orderBoxSelectedTotal').text(getTotalOfRows(selectedRows))
|
||||
}
|
||||
|
||||
const getTotalOfRows = (rows: JQuery) => {
|
||||
return money(rows
|
||||
.find('td.totalPriceCell')
|
||||
.get()
|
||||
.map(cell => Number(cell.innerText))
|
||||
.filter(number => !isNaN(number))
|
||||
.reduce( (total, number) => total + number , 0), false)
|
||||
.format()
|
||||
}
|
||||
|
||||
const getQty = (row: JQuery) => Number(row.getColumnValue(lang('qty_header')))
|
||||
const getUnitPrice = (row: JQuery) => moneyFromString(row.getColumnValue(lang('price_header')))
|
||||
const calculateRowTotal = (row: JQuery) => {
|
||||
|
||||
Reference in New Issue
Block a user