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

feat: create and save POS print templates with matched sizes

This commit is contained in:
AbleKSaju 2025-01-03 09:38:46 +05:30
parent 7e496e823c
commit e6f95393d8
7 changed files with 59 additions and 30 deletions

View File

@ -13,7 +13,16 @@ export async function getTemplates() {
const filePath = path.join(paths.root, file);
const template = await fs.readFile(filePath, 'utf-8');
const { mtime } = await fs.stat(filePath);
templates.push({ template, file, modified: mtime.toISOString() });
const width = file?.split('-')[1]?.split('.')[0] === 'POS' ? 8 : 0;
const height = file?.split('-')[1]?.split('.')[0] === 'POS' ? 22 : 0;
templates.push({
template,
file,
modified: mtime.toISOString(),
width,
height,
});
}
return templates;

View File

@ -39,12 +39,8 @@
:template="printProps.template"
:values="printProps.values"
:scale="scale"
:width="
templateName?.startsWith('POS')
? fyo.singles.PrintSettings?.posPrintWidth
: templateDoc?.width
"
:height="templateName.startsWith('POS') ? 22 : templateDoc?.height"
:width="templateDoc?.width"
:height="templateDoc?.height"
/>
</div>
</div>

View File

@ -53,13 +53,8 @@
:template="doc.template!"
:values="values!"
:scale="scale"
:height="doc.name.startsWith('POS') ? 20 : doc.height"
:width="
doc.name?.startsWith('POS') &&
fyo.singles.PrintSettings?.posPrintWidth
? fyo.singles.PrintSettings.posPrintWidth
: doc.width
"
:height="doc.height"
:width="doc.width"
/>
</div>

View File

@ -19,7 +19,13 @@ export type PrintTemplateHint = {
[key: string]: string | PrintTemplateHint | PrintTemplateHint[];
};
type PrintTemplateData = Record<string, unknown>;
type TemplateUpdateItem = { name: string; template: string; type: string };
type TemplateUpdateItem = {
name: string;
template: string;
type: string;
width: number;
height: number;
};
const printSettingsFields = [
'logo',
@ -44,20 +50,25 @@ export async function getPrintTemplatePropValues(
const totalTax = await (doc as Invoice)?.getTotalTax();
const paymentId = await (doc as SalesInvoice).getPaymentIds();
const paymentDoc = await fyo.doc.getDoc(ModelNameEnum.Payment, paymentId[0]);
if (paymentId.length) {
const paymentDoc = await fyo.doc.getDoc(
ModelNameEnum.Payment,
paymentId[0]
);
(values.doc as PrintTemplateData).paymentMethod = paymentDoc.paymentMethod;
(values.doc as PrintTemplateData).paymentMethod = paymentDoc.paymentMethod;
(values.doc as PrintTemplateData).paidAmount = doc.fyo.format(
paymentDoc.amount as Money,
ModelNameEnum.Currency
);
}
(values.doc as PrintTemplateData).subTotal = doc.fyo.format(
(doc.grandTotal as Money).sub(totalTax),
ModelNameEnum.Currency
);
(values.doc as PrintTemplateData).paidAmount = doc.fyo.format(
paymentDoc.amount as Money,
ModelNameEnum.Currency
);
const printSettings = await fyo.doc.getDoc(ModelNameEnum.PrintSettings);
const printValues = await getPrintTemplateDocValues(
printSettings,
@ -456,20 +467,29 @@ export async function updatePrintTemplates(fyo: Fyo) {
const isLogging = fyo.store.skipTelemetryLogging;
fyo.store.skipTelemetryLogging = true;
for (const { name, type, template } of updateList) {
for (const { name, type, template, width, height } of updateList) {
const doc = await getDocFromNameIfExistsElseNew(
ModelNameEnum.PrintTemplate,
name
);
await doc.set({ name, type, template, isCustom: false });
const updateData = {
name,
type,
template,
isCustom: false,
...(width ? { width } : {}),
...(height ? { height } : {}),
};
await doc.set(updateData);
await doc.sync();
}
fyo.store.skipTelemetryLogging = isLogging;
}
function getPrintTemplateUpdateList(
{ file, template, modified: modifiedString }: TemplateFile,
{ file, template, modified: modifiedString, width, height }: TemplateFile,
nameModifiedMap: Record<string, Date>,
fyo: Fyo
): TemplateUpdateItem[] {
@ -483,6 +503,8 @@ function getPrintTemplateUpdateList(
}
templateList.push({
height,
width,
name,
type,
template,

View File

@ -827,6 +827,7 @@ export const printSizes = [
'B7',
'B8',
'B9',
'POS',
'Letter',
'Legal',
'Executive',
@ -923,6 +924,10 @@ export const paperSizeMap: Record<
width: 4.4,
height: 6.2,
},
POS: {
width: 8,
height: 22,
},
Letter: {
width: 21.59,
height: 27.94,

View File

@ -18,7 +18,6 @@
<!-- Company Contacts -->
<p class="mt-1 text-base">{{ print.phone }}</p>
<p class="text-base">{{ print.email }}</p>
<p class="text-base">VAT: 100202308100003</p>
</header>
<!-- Invoice Details -->
@ -134,9 +133,6 @@
</section>
<div class="w-full mt-3 flex pb-5 flex-col justify-center items-center">
<p class="w-11/12 text-sm text-center">
No Cash Refund Exchange Only..Keep bill for Exchange
</p>
<p class="pt-1 text-lg">***** Thank You Visit Again *****</p>
</div>
</main>

View File

@ -56,7 +56,13 @@ export type PropertyEnum<T extends Record<string, any>> = {
[key in keyof Required<T>]: key;
};
export type TemplateFile = { file: string; template: string; modified: string };
export type TemplateFile = {
file: string;
template: string;
modified: string;
width: number;
height: number;
};
export interface Keys extends ModMap {
pressed: Set<string>;