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:
parent
7e496e823c
commit
e6f95393d8
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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>
|
@ -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>;
|
||||
|
Loading…
Reference in New Issue
Block a user