mirror of
https://github.com/frappe/books.git
synced 2025-01-09 01:44:15 +00:00
feat: create and save POS print templates with matched sizes
This commit is contained in:
parent
7e496e823c
commit
e6f95393d8
@ -13,7 +13,16 @@ export async function getTemplates() {
|
|||||||
const filePath = path.join(paths.root, file);
|
const filePath = path.join(paths.root, file);
|
||||||
const template = await fs.readFile(filePath, 'utf-8');
|
const template = await fs.readFile(filePath, 'utf-8');
|
||||||
const { mtime } = await fs.stat(filePath);
|
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;
|
return templates;
|
||||||
|
@ -39,12 +39,8 @@
|
|||||||
:template="printProps.template"
|
:template="printProps.template"
|
||||||
:values="printProps.values"
|
:values="printProps.values"
|
||||||
:scale="scale"
|
:scale="scale"
|
||||||
:width="
|
:width="templateDoc?.width"
|
||||||
templateName?.startsWith('POS')
|
:height="templateDoc?.height"
|
||||||
? fyo.singles.PrintSettings?.posPrintWidth
|
|
||||||
: templateDoc?.width
|
|
||||||
"
|
|
||||||
:height="templateName.startsWith('POS') ? 22 : templateDoc?.height"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -53,13 +53,8 @@
|
|||||||
:template="doc.template!"
|
:template="doc.template!"
|
||||||
:values="values!"
|
:values="values!"
|
||||||
:scale="scale"
|
:scale="scale"
|
||||||
:height="doc.name.startsWith('POS') ? 20 : doc.height"
|
:height="doc.height"
|
||||||
:width="
|
:width="doc.width"
|
||||||
doc.name?.startsWith('POS') &&
|
|
||||||
fyo.singles.PrintSettings?.posPrintWidth
|
|
||||||
? fyo.singles.PrintSettings.posPrintWidth
|
|
||||||
: doc.width
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -19,7 +19,13 @@ export type PrintTemplateHint = {
|
|||||||
[key: string]: string | PrintTemplateHint | PrintTemplateHint[];
|
[key: string]: string | PrintTemplateHint | PrintTemplateHint[];
|
||||||
};
|
};
|
||||||
type PrintTemplateData = Record<string, unknown>;
|
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 = [
|
const printSettingsFields = [
|
||||||
'logo',
|
'logo',
|
||||||
@ -44,20 +50,25 @@ export async function getPrintTemplatePropValues(
|
|||||||
const totalTax = await (doc as Invoice)?.getTotalTax();
|
const totalTax = await (doc as Invoice)?.getTotalTax();
|
||||||
const paymentId = await (doc as SalesInvoice).getPaymentIds();
|
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(
|
(values.doc as PrintTemplateData).subTotal = doc.fyo.format(
|
||||||
(doc.grandTotal as Money).sub(totalTax),
|
(doc.grandTotal as Money).sub(totalTax),
|
||||||
ModelNameEnum.Currency
|
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 printSettings = await fyo.doc.getDoc(ModelNameEnum.PrintSettings);
|
||||||
const printValues = await getPrintTemplateDocValues(
|
const printValues = await getPrintTemplateDocValues(
|
||||||
printSettings,
|
printSettings,
|
||||||
@ -456,20 +467,29 @@ export async function updatePrintTemplates(fyo: Fyo) {
|
|||||||
|
|
||||||
const isLogging = fyo.store.skipTelemetryLogging;
|
const isLogging = fyo.store.skipTelemetryLogging;
|
||||||
fyo.store.skipTelemetryLogging = true;
|
fyo.store.skipTelemetryLogging = true;
|
||||||
for (const { name, type, template } of updateList) {
|
for (const { name, type, template, width, height } of updateList) {
|
||||||
const doc = await getDocFromNameIfExistsElseNew(
|
const doc = await getDocFromNameIfExistsElseNew(
|
||||||
ModelNameEnum.PrintTemplate,
|
ModelNameEnum.PrintTemplate,
|
||||||
name
|
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();
|
await doc.sync();
|
||||||
}
|
}
|
||||||
fyo.store.skipTelemetryLogging = isLogging;
|
fyo.store.skipTelemetryLogging = isLogging;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPrintTemplateUpdateList(
|
function getPrintTemplateUpdateList(
|
||||||
{ file, template, modified: modifiedString }: TemplateFile,
|
{ file, template, modified: modifiedString, width, height }: TemplateFile,
|
||||||
nameModifiedMap: Record<string, Date>,
|
nameModifiedMap: Record<string, Date>,
|
||||||
fyo: Fyo
|
fyo: Fyo
|
||||||
): TemplateUpdateItem[] {
|
): TemplateUpdateItem[] {
|
||||||
@ -483,6 +503,8 @@ function getPrintTemplateUpdateList(
|
|||||||
}
|
}
|
||||||
|
|
||||||
templateList.push({
|
templateList.push({
|
||||||
|
height,
|
||||||
|
width,
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
template,
|
template,
|
||||||
|
@ -827,6 +827,7 @@ export const printSizes = [
|
|||||||
'B7',
|
'B7',
|
||||||
'B8',
|
'B8',
|
||||||
'B9',
|
'B9',
|
||||||
|
'POS',
|
||||||
'Letter',
|
'Letter',
|
||||||
'Legal',
|
'Legal',
|
||||||
'Executive',
|
'Executive',
|
||||||
@ -923,6 +924,10 @@ export const paperSizeMap: Record<
|
|||||||
width: 4.4,
|
width: 4.4,
|
||||||
height: 6.2,
|
height: 6.2,
|
||||||
},
|
},
|
||||||
|
POS: {
|
||||||
|
width: 8,
|
||||||
|
height: 22,
|
||||||
|
},
|
||||||
Letter: {
|
Letter: {
|
||||||
width: 21.59,
|
width: 21.59,
|
||||||
height: 27.94,
|
height: 27.94,
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
<!-- Company Contacts -->
|
<!-- Company Contacts -->
|
||||||
<p class="mt-1 text-base">{{ print.phone }}</p>
|
<p class="mt-1 text-base">{{ print.phone }}</p>
|
||||||
<p class="text-base">{{ print.email }}</p>
|
<p class="text-base">{{ print.email }}</p>
|
||||||
<p class="text-base">VAT: 100202308100003</p>
|
|
||||||
</header>
|
</header>
|
||||||
<!-- Invoice Details -->
|
<!-- Invoice Details -->
|
||||||
|
|
||||||
@ -134,9 +133,6 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div class="w-full mt-3 flex pb-5 flex-col justify-center items-center">
|
<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>
|
<p class="pt-1 text-lg">***** Thank You Visit Again *****</p>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
@ -56,7 +56,13 @@ export type PropertyEnum<T extends Record<string, any>> = {
|
|||||||
[key in keyof Required<T>]: key;
|
[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 {
|
export interface Keys extends ModMap {
|
||||||
pressed: Set<string>;
|
pressed: Set<string>;
|
||||||
|
Loading…
Reference in New Issue
Block a user