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/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); diff --git a/templates/Business.Payment.template.html b/templates/Business.Payment.template.html new file mode 100644 index 00000000..2e33b70b --- /dev/null +++ b/templates/Business.Payment.template.html @@ -0,0 +1,126 @@ +
+ +
+ +
+ + +
+

+ {{ 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 }} +
+
+
+ +
+

+ {{t`Tax Summary`}} +

+ +
+

{{ tax.account }}

+

{{ tax.amount }}

+
+ +
+

{{t`Total Ex.Tax`}}

+

{{doc.subTotal}}

+
+
+ +
+
+
+
+

{{t`Grand Total`}}

+
+ +
:
+ +
+

{{ doc.amount }}

+

{{ doc.grandTotalInWords }}

+
+ +
{{t`Amount Paid`}}
+ +
:
+ +
+

{{ doc.amountPaid }}

+

{{ doc.amountPaidInWords }}

+
+
+
+ + +
+

{{t`Notes`}}

+ +

{{ 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}}