From be44333e640b4f0325ca833ad80061080ff82b36 Mon Sep 17 00:00:00 2001 From: 18alantom <2.alan.tom@gmail.com> Date: Wed, 13 Jul 2022 13:43:42 +0530 Subject: [PATCH] incr: display discount breakdown --- src/pages/InvoiceForm.vue | 102 +++++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 18 deletions(-) diff --git a/src/pages/InvoiceForm.vue b/src/pages/InvoiceForm.vue index c7ea2f33..78b410fa 100644 --- a/src/pages/InvoiceForm.vue +++ b/src/pages/InvoiceForm.vue @@ -124,9 +124,9 @@

-
+
-

+

{{ discountNote }}

@@ -135,7 +135,7 @@ :df="getField('terms')" :value="doc.terms" input-class="bg-gray-100" - class="absolute bottom-0 w-full" + class="mt-auto" @change="(value) => doc.set('terms', value)" :read-only="doc?.submitted" /> @@ -150,24 +150,71 @@

+ +
+
+
{{ t`Item Discount` }}
+
+ {{ `- ${fyo.format(itemDiscountAmount, 'Currency')}` }} +
+
+
+
{{ t`Invoice Discount` }}
+
{{ `- ${fyo.format(discountAmount, 'Currency')}` }}
+
+
+
+
-
{{ tax.account }}
-
- {{ - fyo.format(tax.amount, { - fieldtype: 'Currency', - currency: doc.currency, - }) - }} +
+
{{ tax.account }}
+
+ {{ + fyo.format(tax.amount, { + fieldtype: 'Currency', + currency: doc.currency, + }) + }} +

+ +
+
+
{{ t`Item Discount` }}
+
+ {{ `- ${fyo.format(itemDiscountAmount, 'Currency')}` }} +
+
+
+
{{ t`Invoice Discount` }}
+
{{ `- ${fyo.format(discountAmount, 'Currency')}` }}
+
+
+
+
0" /> +
{{ t`Outstanding Amount` }}
@@ -277,8 +324,7 @@ export default { return getDocStatus(this.doc); }, discountNote() { - const zeroInvoiceDiscount = - this.doc?.discountAmount?.isZero() && this.doc?.discountPercent === 0; + const zeroInvoiceDiscount = this.doc?.discountAmount?.isZero(); const zeroItemDiscount = (this.doc?.items ?? []).every( (i) => i?.itemDiscountAmount?.isZero() && i?.itemDiscountPercent === 0 @@ -298,6 +344,26 @@ export default { return text; }, + totalDiscount() { + const discountAmount = this.doc?.discountAmount ?? fyo.pesa(0); + const itemDiscount = (this.doc?.items ?? []).reduce( + (acc, i) => acc.add(i.itemDiscountAmount), + fyo.pesa(0) + ); + + return discountAmount.add(itemDiscount); + }, + discountAmount() { + return this.doc?.discountAmount ?? fyo.pesa(0); + }, + itemDiscountAmount() { + const itemDiscountAmount = (this.doc?.items ?? []).reduce( + (acc, i) => acc.add(i.itemDiscountAmount), + fyo.pesa(0) + ); + + return itemDiscountAmount; + }, }, activated() { docsPath.value = docsPathMap[this.schemaName];