diff --git a/main/getPrintTemplates.ts b/main/getPrintTemplates.ts index 062fec1a..d56ca2cc 100644 --- a/main/getPrintTemplates.ts +++ b/main/getPrintTemplates.ts @@ -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; diff --git a/src/pages/PrintView/PrintView.vue b/src/pages/PrintView/PrintView.vue index 3689f651..4f514a17 100644 --- a/src/pages/PrintView/PrintView.vue +++ b/src/pages/PrintView/PrintView.vue @@ -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" /> diff --git a/src/pages/TemplateBuilder/TemplateBuilder.vue b/src/pages/TemplateBuilder/TemplateBuilder.vue index 77b4bcb3..f106a6ed 100644 --- a/src/pages/TemplateBuilder/TemplateBuilder.vue +++ b/src/pages/TemplateBuilder/TemplateBuilder.vue @@ -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" /> diff --git a/src/utils/printTemplates.ts b/src/utils/printTemplates.ts index c6bf210b..cba52f01 100644 --- a/src/utils/printTemplates.ts +++ b/src/utils/printTemplates.ts @@ -19,7 +19,13 @@ export type PrintTemplateHint = { [key: string]: string | PrintTemplateHint | PrintTemplateHint[]; }; type PrintTemplateData = Record; -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, fyo: Fyo ): TemplateUpdateItem[] { @@ -483,6 +503,8 @@ function getPrintTemplateUpdateList( } templateList.push({ + height, + width, name, type, template, diff --git a/src/utils/ui.ts b/src/utils/ui.ts index d1a15882..a00fffc1 100644 --- a/src/utils/ui.ts +++ b/src/utils/ui.ts @@ -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, diff --git a/templates/POS.template.html b/templates/Business-POS.template.html similarity index 96% rename from templates/POS.template.html rename to templates/Business-POS.template.html index 5775fbda..0a7188d0 100644 --- a/templates/POS.template.html +++ b/templates/Business-POS.template.html @@ -18,7 +18,6 @@

{{ print.phone }}

{{ print.email }}

-

VAT: 100202308100003

@@ -134,9 +133,6 @@
-

- No Cash Refund Exchange Only..Keep bill for Exchange -

***** Thank You Visit Again *****

diff --git a/utils/types.ts b/utils/types.ts index ad0aa83b..c3b4f6dd 100644 --- a/utils/types.ts +++ b/utils/types.ts @@ -56,7 +56,13 @@ export type PropertyEnum> = { [key in keyof Required]: 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;