From aea29b0394b5a29794113663e9d70ff0b0d66c63 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:09:20 +0530 Subject: [PATCH 1/3] feat: add option to display time in templates --- models/baseModels/PrintSettings/PrintSettings.ts | 1 + schemas/app/PrintSettings.json | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/models/baseModels/PrintSettings/PrintSettings.ts b/models/baseModels/PrintSettings/PrintSettings.ts index e2cae51f..bdbad09c 100644 --- a/models/baseModels/PrintSettings/PrintSettings.ts +++ b/models/baseModels/PrintSettings/PrintSettings.ts @@ -11,6 +11,7 @@ export class PrintSettings extends Doc { color?: string; font?: string; displayLogo?: boolean; + displayTime?: boolean; amountInWords?: boolean; override hidden: HiddenMap = {}; } diff --git a/schemas/app/PrintSettings.json b/schemas/app/PrintSettings.json index d7eed41d..359a4ec0 100644 --- a/schemas/app/PrintSettings.json +++ b/schemas/app/PrintSettings.json @@ -120,6 +120,12 @@ "label": "Display Amount In Words", "fieldtype": "Check", "section": "Customizations" + }, + { + "fieldname": "displayTime", + "label": "Display Time In Invoice", + "fieldtype": "Check", + "section": "Customizations" } ] } From 4bad6f12b0e19aa583263648f61e471e2e59a793 Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:10:53 +0530 Subject: [PATCH 2/3] feat: get and pass date to templates --- src/utils/printTemplates.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/utils/printTemplates.ts b/src/utils/printTemplates.ts index 960dca81..8400027e 100644 --- a/src/utils/printTemplates.ts +++ b/src/utils/printTemplates.ts @@ -69,9 +69,30 @@ export async function getPrintTemplatePropValues( (doc.grandTotal as Money).float ); + (values.doc as PrintTemplateData).date = getDate(doc.date as string); + + if (printSettings.displayTime) { + (values.doc as PrintTemplateData).time = getTime(doc.date as string); + } + return values; } +function getDate(dateString: string): string { + const date = new Date(dateString); + date.setMonth(date.getMonth() - 1); + + return `${date.toLocaleString('default', { + month: 'short', + })} ${date.getDate()}, ${date.getFullYear()}`; +} + +function getTime(dateString: string): string { + const date = new Date(dateString); + + return date.toTimeString().split(' ')[0]; +} + export function getPrintTemplatePropHints(schemaName: string, fyo: Fyo) { const hints: PrintTemplateHint = {}; const schema = fyo.schemaMap[schemaName]!; From 0190f34aabfaadc85e824236bd2c45f3ab4beedf Mon Sep 17 00:00:00 2001 From: AbleKSaju <126228406+AbleKSaju@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:11:26 +0530 Subject: [PATCH 3/3] feat: display time in templates --- templates/Basic.template.html | 6 +++++- templates/Business.template.html | 6 +++++- templates/Minimal.template.html | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/templates/Basic.template.html b/templates/Basic.template.html index 1ac7a80f..9bd8c3f8 100644 --- a/templates/Basic.template.html +++ b/templates/Basic.template.html @@ -31,7 +31,11 @@

{{ doc.name }}

-

{{ doc.date }}

+ +
+

{{ doc.date }}

+

{{ doc?.time }}

+
diff --git a/templates/Business.template.html b/templates/Business.template.html index 41480bea..11e111fc 100644 --- a/templates/Business.template.html +++ b/templates/Business.template.html @@ -31,7 +31,11 @@

{{ doc.name }}

-

{{ doc.date }}

+ +
+

{{ doc.date }}

+

{{doc?.time }}

+
diff --git a/templates/Minimal.template.html b/templates/Minimal.template.html index 697c0577..81ce3b36 100644 --- a/templates/Minimal.template.html +++ b/templates/Minimal.template.html @@ -13,7 +13,11 @@

{{ print.companyName }}

-

{{ doc.date }}

+ +
+

{{ doc.date }}

+

{{ doc?.time }}

+