diff --git a/src/pages/Claim/Card/ClaimLines.vue b/src/pages/Claim/Card/ClaimLines.vue index c4a7db201..52fbfca98 100644 --- a/src/pages/Claim/Card/ClaimLines.vue +++ b/src/pages/Claim/Card/ClaimLines.vue @@ -45,20 +45,25 @@ async function onFetchClaim(data) { const amount = ref(); const amountClaimed = ref(); -async function onFetch(rows) { +async function onFetch(rows, newRows) { + if (newRows) rows = newRows; amount.value = 0; amountClaimed.value = 0; if (!rows || !rows.length) return; - amount.value = rows.reduce( - (accumulator, { sale }) => accumulator + sale.price * sale.quantity, - 0 - ); + for (const row of rows) { + const { sale } = row; + 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( - (accumulator, line) => accumulator + line.sale.price * line.quantity, - 0 - ); +function totalRow({ price, quantity, discount }) { + const amount = price * quantity; + const appliedDiscount = (discount * amount) / 100; + return amount - appliedDiscount; } const columns = computed(() => [ @@ -102,12 +107,7 @@ const columns = computed(() => [ { name: 'total', label: t('Total'), - field: ({ sale }) => { - const amount = sale.price * sale.quantity; - const appliedDiscount = (sale.discount * amount) / 100; - - return amount - appliedDiscount; - }, + field: ({ sale }) => totalRow(sale), format: (value) => toCurrency(value), sortable: true, }, @@ -129,6 +129,7 @@ async function updateDiscount({ saleFk, discount, canceller }) { await axios.post(query, body, { signal: canceller.signal, }); + await claimLinesForm.value.reload(); } function onUpdateDiscount(response) { @@ -151,8 +152,11 @@ function showImportDialog() { .onOk(() => claimLinesForm.value.reload()); } -function saveWhenHasChanges() { - claimLinesForm.value.getChanges().updates && claimLinesForm.value.onSubmit(); +async function saveWhenHasChanges() { + if (claimLinesForm.value.getChanges().updates) { + await claimLinesForm.value.onSubmit(); + await claimLinesForm.value.reload(); + } }