0
0
Fork 0

fix(claimLines): refs #6336 fix total calc

This commit is contained in:
Alex Moreno 2024-04-29 10:33:32 +02:00
parent 8b55044891
commit 806f3a13d5
1 changed files with 21 additions and 18 deletions

View File

@ -45,20 +45,25 @@ async function onFetchClaim(data) {
const amount = ref(); const amount = ref();
const amountClaimed = ref(); const amountClaimed = ref();
async function onFetch(rows) { async function onFetch(rows, newRows) {
if (newRows) rows = newRows;
amount.value = 0; amount.value = 0;
amountClaimed.value = 0; amountClaimed.value = 0;
if (!rows || !rows.length) return; if (!rows || !rows.length) return;
amount.value = rows.reduce( for (const row of rows) {
(accumulator, { sale }) => accumulator + sale.price * sale.quantity, const { sale } = row;
0 amount.value = amount.value + totalRow(sale);
); const price = row.quantity * sale.price;
const discount = (sale.discount * price) / 100;
amountClaimed.value = amountClaimed.value + (price - discount);
}
}
amountClaimed.value = rows.reduce( function totalRow({ price, quantity, discount }) {
(accumulator, line) => accumulator + line.sale.price * line.quantity, const amount = price * quantity;
0 const appliedDiscount = (discount * amount) / 100;
); return amount - appliedDiscount;
} }
const columns = computed(() => [ const columns = computed(() => [
@ -102,12 +107,7 @@ const columns = computed(() => [
{ {
name: 'total', name: 'total',
label: t('Total'), label: t('Total'),
field: ({ sale }) => { field: ({ sale }) => totalRow(sale),
const amount = sale.price * sale.quantity;
const appliedDiscount = (sale.discount * amount) / 100;
return amount - appliedDiscount;
},
format: (value) => toCurrency(value), format: (value) => toCurrency(value),
sortable: true, sortable: true,
}, },
@ -129,6 +129,7 @@ async function updateDiscount({ saleFk, discount, canceller }) {
await axios.post(query, body, { await axios.post(query, body, {
signal: canceller.signal, signal: canceller.signal,
}); });
await claimLinesForm.value.reload();
} }
function onUpdateDiscount(response) { function onUpdateDiscount(response) {
@ -151,8 +152,11 @@ function showImportDialog() {
.onOk(() => claimLinesForm.value.reload()); .onOk(() => claimLinesForm.value.reload());
} }
function saveWhenHasChanges() { async function saveWhenHasChanges() {
claimLinesForm.value.getChanges().updates && claimLinesForm.value.onSubmit(); if (claimLinesForm.value.getChanges().updates) {
await claimLinesForm.value.onSubmit();
await claimLinesForm.value.reload();
}
} }
</script> </script>
<template> <template>
@ -188,7 +192,6 @@ function saveWhenHasChanges() {
save-url="ClaimBeginnings/crud" save-url="ClaimBeginnings/crud"
:filter="linesFilter" :filter="linesFilter"
@on-fetch="onFetch" @on-fetch="onFetch"
@save-changes="onFetch"
v-model:selected="selected" v-model:selected="selected"
:default-save="false" :default-save="false"
:default-reset="false" :default-reset="false"