diff --git a/frontend/src/routes/document/PositionList.svelte b/frontend/src/routes/document/PositionList.svelte index ab27592..c981016 100644 --- a/frontend/src/routes/document/PositionList.svelte +++ b/frontend/src/routes/document/PositionList.svelte @@ -14,6 +14,23 @@ } = $props(); let editable = $derived(document.state == 1); + let sums = $derived.by(calcSums); + + function calcSums(){ + let data = {} + let net = 0; + let gross = 0; + for (let pos of Object.values(document.positions)){ + let net_price = pos.unit_price * pos.amount; + let tax = +pos.tax; + data[tax] = net_price + (data[tax] ? data[tax] : 0); + net += net_price; + } + for (let [tax, price] of Object.entries(data)) gross += price * (+tax+100)/100; + data['net'] = net/100; + data['gross'] = (gross/100).toFixed(2); + return data; + } async function updatePositions(resp){ let json = await resp.json(); @@ -22,7 +39,7 @@ } async function movePos(number,step){ - const url = api(`document/${document.id}/position`); + const url = api(`document/${document.id}/position`); const resp = await fetch(url,{ method : 'PATCH', credentials: 'include', @@ -38,7 +55,7 @@ async function drop(number){ let confirmed = confirm(t('confirm_deletion').replace('{pos}',document.positions[number].item)); if (!confirmed) return; - const url = api(`document/${document.id}/position`); + const url = api(`document/${document.id}/position`); const resp = await fetch(url,{ method : 'DELETE', credentials: 'include', @@ -73,9 +90,9 @@