From e40046121b9783081216e02ec1839de22921c5d1 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Tue, 21 Jan 2025 09:20:43 +0530 Subject: [PATCH 1/5] feat: add template for payments --- templates/Business.Payment.template.html | 124 +++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 templates/Business.Payment.template.html diff --git a/templates/Business.Payment.template.html b/templates/Business.Payment.template.html new file mode 100644 index 00000000..da6b0ad4 --- /dev/null +++ b/templates/Business.Payment.template.html @@ -0,0 +1,124 @@ +
+ +
+ +
+ + +
+

+ {{ print.companyName }} +

+ +

+ {{ print.links.address.addressDisplay }} +

+ +

+ GSTIN: {{ print.gstin }} +

+
+
+ + +
+ +
+

{{t`Bill`}}

+
+

{{ doc.name }}

+ +
+

{{ doc.date }}

+

{{doc?.time }}

+
+
+
+ + +
+

{{t`party`}}

+ +
+

{{ doc.party }}

+ +

+ {{ doc.links.party.links.address.addressDisplay }} +

+ +

GSTIN: {{ doc.links.party.gstin }}

+
+
+
+
+ + +
+
+

{{t`Payment Type`}}

+
:
+
{{ doc.paymentType }}
+ +
{{t`Payment Method`}}
+
:
+
+ {{ doc.paymentMethod }} +
+
+
+ +
+

Tax Summary

+ +
+

{{ tax.account }}

+

{{ tax.amount }}

+
+ +
+

Total Ex.Vat

+

{{doc.subTotal}}

+
+
+ + +
From 6b43d0b250048d3a3f381b70ecb53f563abf8807 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Tue, 21 Jan 2025 09:21:27 +0530 Subject: [PATCH 2/5] feat: pass required data to the template --- models/baseModels/Payment/Payment.ts | 8 +++++ schemas/app/Payment.json | 2 +- src/utils/printTemplates.ts | 51 +++++++++++++++++++++------- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/models/baseModels/Payment/Payment.ts b/models/baseModels/Payment/Payment.ts index c70a685b..58dfe212 100644 --- a/models/baseModels/Payment/Payment.ts +++ b/models/baseModels/Payment/Payment.ts @@ -502,6 +502,14 @@ export class Payment extends Transactional { date: () => new Date(), }; + async getTotalTax() { + const taxArr = await this.getTaxSummary(); + + return taxArr + .map(({ amount }) => amount) + .reduce((a, b) => a.add(b), this.fyo.pesa(0)); + } + async _getAccountsMap(): Promise { if (this._accountsMap) { return this._accountsMap; diff --git a/schemas/app/Payment.json b/schemas/app/Payment.json index 81d3fce9..d23b3655 100644 --- a/schemas/app/Payment.json +++ b/schemas/app/Payment.json @@ -36,7 +36,7 @@ { "fieldname": "date", "label": "Posting Date", - "fieldtype": "Date", + "fieldtype": "DateTime", "required": true, "section": "Default" }, diff --git a/src/utils/printTemplates.ts b/src/utils/printTemplates.ts index d1d57f71..b17fcb31 100644 --- a/src/utils/printTemplates.ts +++ b/src/utils/printTemplates.ts @@ -14,6 +14,7 @@ import { } from './ui'; import { Money } from 'pesa'; import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice'; +import { Payment } from 'models/baseModels/Payment/Payment'; export type PrintTemplateHint = { [key: string]: string | PrintTemplateHint | PrintTemplateHint[]; @@ -44,28 +45,54 @@ export async function getPrintTemplatePropValues( doc: Doc ): Promise { const fyo = doc.fyo; + let paymentId; + let sinvDoc; + const values: PrintValues = { doc: {}, print: {} }; values.doc = await getPrintTemplateDocValues(doc); - const totalTax = await (doc as Invoice)?.getTotalTax(); - const paymentId = await (doc as SalesInvoice).getPaymentIds(); + if (values.doc.entryType !== ModelNameEnum.Payment) { + paymentId = await (doc as SalesInvoice).getPaymentIds(); - if (paymentId.length) { - const paymentDoc = await fyo.doc.getDoc( - ModelNameEnum.Payment, - paymentId[0] + if (paymentId && paymentId.length) { + const paymentDoc = await fyo.doc.getDoc( + ModelNameEnum.Payment, + paymentId[0] + ); + + (values.doc as PrintTemplateData).paymentMethod = + paymentDoc.paymentMethod; + + (values.doc as PrintTemplateData).paidAmount = doc.fyo.format( + paymentDoc.amount as Money, + ModelNameEnum.Currency + ); + } + } + + if (doc.referenceType == ModelNameEnum.SalesInvoice) { + sinvDoc = await fyo.doc.getDoc( + ModelNameEnum.SalesInvoice, + (doc as Payment)?.for![0].referenceName ); - (values.doc as PrintTemplateData).paymentMethod = paymentDoc.paymentMethod; + if (sinvDoc.taxes) { + (values.doc as PrintTemplateData).taxes = sinvDoc.taxes; + } + } - (values.doc as PrintTemplateData).paidAmount = doc.fyo.format( - paymentDoc.amount as Money, - ModelNameEnum.Currency + const totalTax = await ( + (sinvDoc as Invoice) ?? (doc as Payment) + )?.getTotalTax(); + + if (doc.schema.name == ModelNameEnum.Payment) { + (values.doc as PrintTemplateData).amountPaidInWords = getGrandTotalInWords( + (doc.amountPaid as Money)?.float ); } (values.doc as PrintTemplateData).subTotal = doc.fyo.format( - (doc.grandTotal as Money).sub(totalTax), + ((doc.grandTotal as Money) ?? (doc.amount as Money)).sub(totalTax), ModelNameEnum.Currency ); @@ -95,7 +122,7 @@ export async function getPrintTemplatePropValues( } (values.doc as PrintTemplateData).grandTotalInWords = getGrandTotalInWords( - (doc.grandTotal as Money).float + ((doc.grandTotal as Money) ?? (doc.amount as Money)).float ); (values.doc as PrintTemplateData).date = getDate(doc.date as string); From 92b2b361e0b4aeed8f3501d83f88fc857f66f35f Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Fri, 31 Jan 2025 09:56:04 +0530 Subject: [PATCH 3/5] fix: changed DateTime fieldtype to Date --- schemas/app/Payment.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemas/app/Payment.json b/schemas/app/Payment.json index d23b3655..81d3fce9 100644 --- a/schemas/app/Payment.json +++ b/schemas/app/Payment.json @@ -36,7 +36,7 @@ { "fieldname": "date", "label": "Posting Date", - "fieldtype": "DateTime", + "fieldtype": "Date", "required": true, "section": "Default" }, From d0faffddf8b0672e84b05bf45c37bc00fdf8981b Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:12:46 +0530 Subject: [PATCH 4/5] fix: add translation support in print templates --- templates/Business.Payment.template.html | 6 +++--- templates/Business.template.html | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/Business.Payment.template.html b/templates/Business.Payment.template.html index da6b0ad4..3d530c3b 100644 --- a/templates/Business.Payment.template.html +++ b/templates/Business.Payment.template.html @@ -72,7 +72,7 @@
-

Tax Summary

+

{{t`Tax Summary`}}

-

Total Ex.Vat

+

{{t`Total Ex.Tax`}}

{{doc.subTotal}}

@@ -116,7 +116,7 @@
-

Notes

+

{{t`Notes`}}/h3>

{{ doc.terms }}

diff --git a/templates/Business.template.html b/templates/Business.template.html index 11e111fc..c3fe2a9a 100644 --- a/templates/Business.template.html +++ b/templates/Business.template.html @@ -127,11 +127,11 @@
-

Notes

+

{{t`Notes`}}

{{ doc.terms }}

-

Grand Total In Words:

+

{{t`Grand Total In Words`}}:

{{doc.grandTotalInWords}}

From 8e336f37a83fdc6bce41842273aef37bf4a933f0 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Fri, 31 Jan 2025 15:17:08 +0530 Subject: [PATCH 5/5] fix: resolved formatting issue --- templates/Business.Payment.template.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/Business.Payment.template.html b/templates/Business.Payment.template.html index 3d530c3b..2e33b70b 100644 --- a/templates/Business.Payment.template.html +++ b/templates/Business.Payment.template.html @@ -72,7 +72,9 @@
-

{{t`Tax Summary`}}

+

+ {{t`Tax Summary`}} +

-

{{t`Notes`}}/h3> +

{{t`Notes`}}

{{ doc.terms }}