implemented live price update in document view
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -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 @@
|
||||
<tr class="sums">
|
||||
<td colspan="2"></td>
|
||||
<td>{t('net_sum')}</td>
|
||||
<td>{document.net_sum/100} {document.currency}</td>
|
||||
<td>{sums['net']} {document.currency}</td>
|
||||
<td colspan="2">{t('gross_sum')}</td>
|
||||
<td>{document.gross_sum/100} {document.currency}</td>
|
||||
<td>{sums['gross']} {document.currency}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user