2
0
mirror of https://github.com/frappe/books.git synced 2025-01-08 01:14:39 +00:00

Merge pull request #1062 from AbleKSaju/feat-time-in-templates

feat: option to display time in print templates
This commit is contained in:
Akshay 2025-01-02 16:05:48 +05:30 committed by GitHub
commit 8462dc4482
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 43 additions and 3 deletions

View File

@ -11,6 +11,7 @@ export class PrintSettings extends Doc {
color?: string;
font?: string;
displayLogo?: boolean;
displayTime?: boolean;
amountInWords?: boolean;
override hidden: HiddenMap = {};
}

View File

@ -120,6 +120,12 @@
"label": "Display Amount In Words",
"fieldtype": "Check",
"section": "Customizations"
},
{
"fieldname": "displayTime",
"label": "Display Time In Invoice",
"fieldtype": "Check",
"section": "Customizations"
}
]
}

View File

@ -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]!;

View File

@ -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 -->

View File

@ -31,7 +31,11 @@
</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>

View File

@ -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>