Skip to content

Commit

Permalink
Merge pull request #1062 from AbleKSaju/feat-time-in-templates
Browse files Browse the repository at this point in the history
feat: option to display time in print templates
  • Loading branch information
akshayitzme authored Jan 2, 2025
2 parents 3838c9d + 0190f34 commit 8462dc4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions models/baseModels/PrintSettings/PrintSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class PrintSettings extends Doc {
color?: string;
font?: string;
displayLogo?: boolean;
displayTime?: boolean;
amountInWords?: boolean;
override hidden: HiddenMap = {};
}
6 changes: 6 additions & 0 deletions schemas/app/PrintSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
"label": "Display Amount In Words",
"fieldtype": "Check",
"section": "Customizations"
},
{
"fieldname": "displayTime",
"label": "Display Time In Invoice",
"fieldtype": "Check",
"section": "Customizations"
}
]
}
21 changes: 21 additions & 0 deletions src/utils/printTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]!;
Expand Down
6 changes: 5 additions & 1 deletion templates/Basic.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
<!-- Invoice Details -->
<section class="w-1/3">
<h2 class="text-2xl font-semibold">{{ doc.name }}</h2>
<p class="py-2 text-base">{{ doc.date }}</p>

<div class="flex gap-2">
<p class="py-2 text-base">{{ doc.date }}</p>
<p class="py-2 text-base">{{ doc?.time }}</p>
</div>
</section>

<!-- Party Details -->
Expand Down
6 changes: 5 additions & 1 deletion templates/Business.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ <h3 class="w-1/3 font-semibold">
</h3>
<div class="w-2/3 text-gray-800">
<p class="font-semibold">{{ doc.name }}</p>
<p>{{ doc.date }}</p>

<div class="flex gap-2">
<p>{{ doc.date }}</p>
<p>{{doc?.time }}</p>
</div>
</div>
</section>

Expand Down
6 changes: 5 additions & 1 deletion templates/Minimal.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
<p class="font-semibold text-xl" :style="{ color: print.color }">
{{ print.companyName }}
</p>
<p>{{ doc.date }}</p>

<div class="flex gap-2">
<p>{{ doc.date }}</p>
<p>{{ doc?.time }}</p>
</div>
</div>
</section>

Expand Down

0 comments on commit 8462dc4

Please sign in to comment.