2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

incr: update print templates to display correct currency

This commit is contained in:
18alantom 2022-10-03 13:48:31 +05:30
parent 6ee1365e45
commit 25236560df
5 changed files with 223 additions and 153 deletions

View File

@ -1,15 +1,8 @@
<script>
import { fyo } from 'src/initFyo';
export default {
name: 'Base',
props: { doc: Object, printSettings: Object },
data: () => ({ party: null, companyAddress: null, partyAddress: null }),
methods: {
format(row, fieldname) {
const value = row.get(fieldname);
return fyo.format(value, fyo.getField(row.schemaName, fieldname));
},
},
async mounted() {
await this.printSettings.loadLink('address');
this.companyAddress = this.printSettings.getLink('address');
@ -17,8 +10,49 @@ export default {
await this.doc.loadLink('party');
this.party = this.doc.getLink('party');
this.partyAddress = this.party.getLink('address')?.addressDisplay ?? null;
if (this.fyo.store.isDevelopment) {
window.bt = this;
}
},
methods: {
getFormattedField(fieldname, doc) {
doc ??= this.doc;
const field = doc.fieldMap[fieldname];
const value = doc.get(fieldname);
if (Array.isArray(value)) {
return this.getFormattedChildDocList(fieldname);
}
return this.fyo.format(value, field, doc);
},
getFormattedChildDocList(fieldname) {
const formattedDocs = [];
for (const childDoc of this.doc?.[fieldname] ?? {}) {
formattedDocs.push(this.getFormattedChildDoc(childDoc));
}
return formattedDocs;
},
getFormattedChildDoc(childDoc) {
const formattedChildDoc = {};
for (const field of childDoc?.schema?.fields) {
if (field.meta) {
continue;
}
formattedChildDoc[field.fieldname] = this.getFormattedField(
field.fieldname,
childDoc
);
}
return formattedChildDoc;
},
},
computed: {
currency() {
return this.doc.isMultiCurrency
? this.doc.currency
: this.fyo.singles.SystemSettings.currency;
},
isSalesInvoice() {
return this.doc.schemaName === 'SalesInvoice';
},
@ -28,6 +62,46 @@ export default {
totalDiscount() {
return this.doc.getTotalDiscount();
},
formattedTotalDiscount() {
if (!this.totalDiscount?.float) {
return '';
}
const totalDiscount = this.fyo.format(this.totalDiscount, {
fieldname: 'Total Discount',
fieldtype: 'Currency',
currency: this.currency,
});
return `- ${totalDiscount}`;
},
printObject() {
return {
isSalesInvoice: this.isSalesInvoice,
font: this.printSettings.font,
color: this.printSettings.color,
showHSN: this.showHSN,
displayLogo: this.printSettings.displayLogo,
discountAfterTax: this.doc.discountAfterTax,
logo: this.printSettings.logo,
companyName: this.fyo.singles.AccountingSettings.companyName,
email: this.printSettings.email,
phone: this.printSettings.phone,
address: this.companyAddress?.addressDisplay,
gstin: this.fyo.singles?.AccountingSettings?.gstin,
invoiceName: this.doc.name,
date: this.getFormattedField('date'),
partyName: this.party?.name,
partyAddress: this.partyAddress,
partyGSTIN: this.party?.gstin,
terms: this.doc.terms,
netTotal: this.getFormattedField('netTotal'),
items: this.getFormattedField('items'),
taxes: this.getFormattedField('taxes'),
grandTotal: this.getFormattedField('grandTotal'),
totalDiscount: this.formattedTotalDiscount,
};
},
},
};
</script>

View File

@ -1,36 +1,31 @@
<template>
<div
class="bg-white border h-full"
:style="{ 'font-family': printSettings.font }"
:style="{ 'font-family': printObject.font }"
>
<div>
<div class="px-6 pt-6" v-if="printSettings">
<div class="px-6 pt-6">
<div class="flex text-sm text-gray-900 border-b pb-4">
<div class="w-1/3">
<div v-if="printSettings.displayLogo">
<div v-if="printObject.displayLogo">
<img
class="h-12 max-w-32 object-contain"
:src="printSettings.logo"
:src="printObject.logo"
/>
</div>
<div class="text-xl text-gray-700 font-semibold" v-else>
{{ fyo.singles.AccountingSettings.companyName }}
{{ printObject.companyName }}
</div>
</div>
<div class="w-1/3">
<div>{{ printSettings.email }}</div>
<div class="mt-1">{{ printSettings.phone }}</div>
<div>{{ printObject.email }}</div>
<div class="mt-1">{{ printObject.phone }}</div>
</div>
<div class="w-1/3">
<div v-if="companyAddress">{{ companyAddress.addressDisplay }}</div>
<div
v-if="
fyo.singles.AccountingSettings &&
fyo.singles.AccountingSettings.gstin
"
>
GSTIN: {{ fyo.singles.AccountingSettings.gstin }}
<div v-if="printObject.address">
{{ printObject.address }}
</div>
<div v-if="printObject.gstin">GSTIN: {{ printObject.gstin }}</div>
</div>
</div>
</div>
@ -38,27 +33,27 @@
<div class="flex justify-between">
<div class="w-1/3">
<h1 class="text-2xl font-semibold">
{{ doc.name }}
{{ printObject.invoiceName }}
</h1>
<div class="py-2 text-base">
{{ fyo.format(doc.date, 'Date') }}
{{ printObject.date }}
</div>
</div>
<div class="w-1/3" v-if="party">
<div class="w-1/3" v-if="printObject.partyName">
<div class="py-1 text-right text-lg font-semibold">
{{ party.name }}
{{ printObject.partyName }}
</div>
<div
v-if="partyAddress"
v-if="printObject.partyAddress"
class="mt-1 text-xs text-gray-600 text-right"
>
{{ partyAddress }}
{{ printObject.partyAddress }}
</div>
<div
v-if="party && party.gstin"
v-if="printObject.partyGSTIN"
class="mt-1 text-xs text-gray-600 text-right"
>
GSTIN: {{ party.gstin }}
GSTIN: {{ printObject.partyGSTIN }}
</div>
</div>
</div>
@ -67,64 +62,67 @@
<div>
<div class="text-gray-600 w-full flex border-b">
<div class="py-4 w-5/12">Item</div>
<div class="py-4 text-right w-2/12" v-if="showHSN">HSN/SAC</div>
<div class="py-4 text-right w-2/12" v-if="printObject.showHSN">
HSN/SAC
</div>
<div class="py-4 text-right w-1/12">Quantity</div>
<div class="py-4 text-right w-3/12">Rate</div>
<div class="py-4 text-right w-3/12">Amount</div>
</div>
<div
class="flex py-1 text-gray-900 w-full border-b"
v-for="row in doc.items"
v-for="row in printObject.items"
:key="row.name"
>
<div class="w-5/12 py-4">{{ row.item }}</div>
<div class="w-2/12 text-right py-4" v-if="showHSN">
<div class="w-2/12 text-right py-4" v-if="printObject.showHSN">
{{ row.hsnCode }}
</div>
<div class="w-1/12 text-right py-4">
{{ format(row, 'quantity') }}
</div>
<div class="w-3/12 text-right py-4">{{ format(row, 'rate') }}</div>
<div class="w-3/12 text-right py-4">
{{ format(row, 'amount') }}
</div>
<div class="w-1/12 text-right py-4">{{ row.quantity }}</div>
<div class="w-3/12 text-right py-4">{{ row.rate }}</div>
<div class="w-3/12 text-right py-4">{{ row.amount }}</div>
</div>
</div>
</div>
</div>
<div class="px-6 mt-2 flex justify-end text-base">
<div class="w-1/2 bg-pink">
<div class="text-sm tracking-widest text-gray-600 mt-2">Notes</div>
<div class="w-1/2">
<div
class="text-sm tracking-widest text-gray-600 mt-2"
v-if="printObject.terms"
>
Notes
</div>
<div class="my-4 text-lg whitespace-pre-line">
{{ doc.terms }}
{{ printObject.terms }}
</div>
</div>
<div class="w-1/2">
<div class="flex pl-2 justify-between py-3 border-b">
<div>{{ t`Subtotal` }}</div>
<div>{{ fyo.format(doc.netTotal, 'Currency') }}</div>
<div>{{ printObject.netTotal }}</div>
</div>
<div
class="flex pl-2 justify-between py-3 border-b"
v-if="totalDiscount?.float > 0 && !doc.discountAfterTax"
v-if="printObject.totalDiscount && !printObject.discountAfterTax"
>
<div>{{ t`Discount` }}</div>
<div>{{ `- ${fyo.format(totalDiscount, 'Currency')}` }}</div>
<div>{{ printObject.totalDiscount }}</div>
</div>
<div
class="flex pl-2 justify-between py-3"
v-for="tax in doc.taxes"
v-for="tax in printObject.taxes"
:key="tax.name"
>
<div>{{ tax.account }}</div>
<div>{{ fyo.format(tax.amount, 'Currency') }}</div>
<div>{{ tax.amount }}</div>
</div>
<div
class="flex pl-2 justify-between py-3 border-t"
v-if="totalDiscount?.float > 0 && doc.discountAfterTax"
v-if="printObject.totalDiscount && printObject.discountAfterTax"
>
<div>{{ t`Discount` }}</div>
<div>{{ `- ${fyo.format(totalDiscount, 'Currency')}` }}</div>
<div>{{ printObject.totalDiscount }}</div>
</div>
<div
class="
@ -139,7 +137,7 @@
"
>
<div>{{ t`Grand Total` }}</div>
<div>{{ fyo.format(doc.grandTotal, 'Currency') }}</div>
<div>{{ printObject.grandTotal }}</div>
</div>
</div>
</div>
@ -147,11 +145,10 @@
</template>
<script>
import Base from './BaseTemplate.vue';
import BaseTemplate from './BaseTemplate.vue';
export default {
name: 'Default',
extends: Base,
props: ['doc', 'printSettings'],
extends: BaseTemplate,
};
</script>

View File

@ -1,65 +1,58 @@
<template>
<div
class="bg-white border h-full"
:style="{ 'font-family': printSettings.font }"
:style="{ 'font-family': printObject.font }"
>
<div class="bg-gray-100 px-12 py-10">
<div class="flex items-center">
<div class="flex items-center rounded h-16">
<div class="mr-4" v-if="printSettings.displayLogo">
<img
class="h-12 max-w-32 object-contain"
:src="printSettings.logo"
/>
<div class="mr-4" v-if="printObject.displayLogo">
<img class="h-12 max-w-32 object-contain" :src="printObject.logo" />
</div>
</div>
<div>
<div
class="font-semibold text-xl"
:style="{ color: printSettings.color }"
:style="{ color: printObject.color }"
>
{{ fyo.singles.AccountingSettings.companyName }}
{{ printObject.companyName }}
</div>
<div class="text-sm text-gray-800" v-if="companyAddress">
{{ companyAddress.addressDisplay }}
<div class="text-sm text-gray-800" v-if="printObject.address">
{{ printObject.address }}
</div>
<div
class="text-sm text-gray-800"
v-if="
fyo.singles.AccountingSettings &&
fyo.singles.AccountingSettings.gstin
"
>
GSTIN: {{ fyo.singles.AccountingSettings.gstin }}
<div class="text-sm text-gray-800" v-if="printObject.gstin">
GSTIN: {{ printObject.gstin }}
</div>
</div>
</div>
<div class="mt-8 text-lg">
<div class="flex">
<div class="w-1/3 font-semibold">
{{ isSalesInvoice ? 'Invoice' : 'Bill' }}
{{ printObject.isSalesInvoice ? 'Invoice' : 'Bill' }}
</div>
<div class="w-2/3 text-gray-800">
<div class="font-semibold">
{{ doc.name }}
{{ printObject.invoiceName }}
</div>
<div>
{{ fyo.format(doc.date, 'Date') }}
{{ printObject.date }}
</div>
</div>
</div>
<div class="mt-4 flex">
<div class="w-1/3 font-semibold">
{{ isSalesInvoice ? 'Customer' : 'Supplier' }}
{{ printObject.isSalesInvoice ? 'Customer' : 'Supplier' }}
</div>
<div class="w-2/3 text-gray-800" v-if="party">
<div class="w-2/3 text-gray-800" v-if="printObject.partyName">
<div class="font-semibold">
{{ party.name }}
{{ printObject.partyName }}
</div>
<div v-if="partyAddress">
{{ partyAddress }}
<div v-if="printObject.partyAddress">
{{ printObject.partyAddress }}
</div>
<div v-if="printObject.partyGSTIN">
GSTIN: {{ printObject.partyGSTIN }}
</div>
<div v-if="party && party.gstin">GSTIN: {{ party.gstin }}</div>
</div>
</div>
</div>
@ -67,21 +60,23 @@
<div class="px-12 py-12 text-lg">
<div class="mb-4 flex font-semibold">
<div class="w-4/12">Item</div>
<div class="w-2/12 text-right" v-if="showHSN">HSN/SAC</div>
<div class="w-2/12 text-right" v-if="printObject.showHSN">HSN/SAC</div>
<div class="w-2/12 text-right">Quantity</div>
<div class="w-3/12 text-right">Rate</div>
<div class="w-3/12 text-right">Amount</div>
</div>
<div
class="flex py-1 text-gray-800"
v-for="row in doc.items"
v-for="row in printObject.items"
:key="row.name"
>
<div class="w-4/12">{{ row.item }}</div>
<div class="w-2/12 text-right" v-if="showHSN">{{ row.hsnCode }}</div>
<div class="w-2/12 text-right">{{ format(row, 'quantity') }}</div>
<div class="w-3/12 text-right">{{ format(row, 'rate') }}</div>
<div class="w-3/12 text-right">{{ format(row, 'amount') }}</div>
<div class="w-2/12 text-right" v-if="printObject.showHSN">
{{ row.hsnCode }}
</div>
<div class="w-2/12 text-right">{{ row.quantity }}</div>
<div class="w-3/12 text-right">{{ row.rate }}</div>
<div class="w-3/12 text-right">{{ row.amount }}</div>
</div>
<div class="mt-12">
<div class="flex -mx-3">
@ -89,67 +84,70 @@
<div class="text-right">
<div class="text-gray-800">{{ t`Subtotal` }}</div>
<div class="text-xl mt-2">
{{ fyo.format(doc.netTotal, 'Currency') }}
{{ printObject.netTotal }}
</div>
</div>
<div
class="text-right"
v-if="totalDiscount?.float > 0 && !doc.discountAfterTax"
v-if="printObject.totalDiscount && !printObject.discountAfterTax"
>
<div class="text-gray-800">{{ t`Discount` }}</div>
<div class="text-xl mt-2">
{{ `- ${fyo.format(totalDiscount, 'Currency')}` }}
{{ printObject.totalDiscount }}
</div>
</div>
<div class="text-right" v-for="tax in doc.taxes" :key="tax.name">
<div
class="text-right"
v-for="tax in printObject.taxes"
:key="tax.name"
>
<div class="text-gray-800">
{{ tax.account }}
</div>
<div class="text-xl mt-2">
{{ fyo.format(tax.amount, 'Currency') }}
{{ tax.amount }}
</div>
</div>
<div
class="text-right"
v-if="totalDiscount?.float > 0 && !doc.discountAfterTax"
v-if="printObject.totalDiscount && printObject.discountAfterTax"
>
<div class="text-gray-800">{{ t`Discount` }}</div>
<div class="text-xl mt-2">
{{ `- ${fyo.format(totalDiscount, 'Currency')}` }}
{{ printObject.totalDiscount }}
</div>
</div>
</div>
<div
class="py-3 px-4 text-right text-white"
:style="{ backgroundColor: printSettings.color }"
:style="{ backgroundColor: printObject.color }"
>
<div>
<div>{{ t`Grand Total` }}</div>
<div class="text-2xl mt-2 font-semibold">
{{ fyo.format(doc.grandTotal, 'Currency') }}
{{ printObject.grandTotal }}
</div>
</div>
</div>
</div>
<div class="mt-12" v-if="doc.terms">
<div class="mt-12" v-if="printObject.terms">
<div class="text-lg font-semibold">Notes</div>
<div class="mt-4 text-lg whitespace-pre-line">
{{ doc.terms }}
{{ printObject.terms }}
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import Base from './BaseTemplate.vue';
import BaseTemplate from './BaseTemplate.vue';
export default {
name: 'Business',
extends: Base,
extends: BaseTemplate,
};
</script>

View File

@ -1,65 +1,60 @@
<template>
<div
class="bg-white border h-full"
:style="{ 'font-family': printSettings.font }"
:style="{ 'font-family': printObject.font }"
>
<div class="flex items-center justify-between px-12 py-10 border-b">
<div class="flex items-center">
<div class="flex items-center rounded h-16">
<div class="mr-4" v-if="printSettings.displayLogo">
<img
class="h-12 max-w-32 object-contain"
:src="printSettings.logo"
/>
<div class="mr-4" v-if="printObject.displayLogo">
<img class="h-12 max-w-32 object-contain" :src="printObject.logo" />
</div>
</div>
<div>
<div
class="font-semibold text-xl"
:style="{ color: printSettings.color }"
:style="{ color: printObject.color }"
>
{{ fyo.singles.AccountingSettings.companyName }}
{{ printObject.companyName }}
</div>
<div>
{{ fyo.format(doc.date, 'Date') }}
{{ printObject.date }}
</div>
</div>
</div>
<div class="text-right">
<div
class="font-semibold text-xl"
:style="{ color: printSettings.color }"
:style="{ color: printObject.color }"
>
{{
doc.schemaName === 'SalesInvoice'
? t`Sales Invoice`
: t`Purchase Invoice`
printObject.isSalesInvoice ? t`Sales Invoice` : t`Purchase Invoice`
}}
</div>
<div>
{{ doc.name }}
{{ printObject.invoiceName }}
</div>
</div>
</div>
<div class="flex px-12 py-10 border-b">
<div class="w-1/2" v-if="party">
<div class="w-1/2" v-if="printObject.partyName">
<div
class="uppercase text-sm font-semibold tracking-widest text-gray-800"
>
{{ isSalesInvoice ? 'To' : 'From' }}
{{ printObject.isSalesInvoice ? 'To' : 'From' }}
</div>
<div class="mt-4 text-black leading-relaxed text-lg">
{{ party.name }} <br />
{{ partyAddress ? partyAddress : '' }}
{{ printObject.partyName }} <br />
{{ printObject.partyAddress ?? '' }}
</div>
<div
class="mt-4 text-black leading-relaxed text-lg"
v-if="party && party.gstin"
v-if="printObject.partyGSTIN"
>
GSTIN: {{ party.gstin }}
GSTIN: {{ printObject.partyGSTIN }}
</div>
</div>
<div class="w-1/2" v-if="companyAddress">
<div class="w-1/2" v-if="printObject.address">
<div
class="
uppercase
@ -70,19 +65,16 @@
ml-8
"
>
{{ isSalesInvoice ? 'From' : 'To' }}
{{ printObject.isSalesInvoice ? 'From' : 'To' }}
</div>
<div class="mt-4 ml-8 text-black leading-relaxed text-lg">
{{ companyAddress.addressDisplay }}
{{ printObject.address }}
</div>
<div
class="mt-4 ml-8 text-black leading-relaxed text-lg"
v-if="
fyo.singles.AccountingSettings &&
fyo.singles.AccountingSettings.gstin
"
v-if="printObject.gstin"
>
GSTIN: {{ fyo.singles.AccountingSettings.gstin }}
GSTIN: {{ printObject.gstin }}
</div>
</div>
</div>
@ -99,74 +91,79 @@
"
>
<div class="w-4/12">Item</div>
<div class="w-2/12 text-right" v-if="showHSN">HSN/SAC</div>
<div class="w-2/12 text-right" v-if="printObject.showHSN">HSN/SAC</div>
<div class="w-2/12 text-right">Quantity</div>
<div class="w-3/12 text-right">Rate</div>
<div class="w-3/12 text-right">Amount</div>
</div>
<div class="flex py-1 text-lg" v-for="row in doc.items" :key="row.name">
<div
class="flex py-1 text-lg"
v-for="row in printObject.items"
:key="row.name"
>
<div class="w-4/12">{{ row.item }}</div>
<div class="w-2/12 text-right" v-if="showHSN">{{ row.hsnCode }}</div>
<div class="w-2/12 text-right">{{ format(row, 'quantity') }}</div>
<div class="w-3/12 text-right">{{ format(row, 'rate') }}</div>
<div class="w-3/12 text-right">{{ format(row, 'amount') }}</div>
<div class="w-2/12 text-right" v-if="printObject.showHSN">
{{ row.hsnCode }}
</div>
<div class="w-2/12 text-right">{{ row.quantity }}</div>
<div class="w-3/12 text-right">{{ row.rate }}</div>
<div class="w-3/12 text-right">{{ row.amount }}</div>
</div>
</div>
<div class="flex px-12 py-10">
<div class="w-1/2" v-if="doc.terms">
<div class="w-1/2" v-if="printObject.terms">
<div
class="uppercase text-sm tracking-widest font-semibold text-gray-800"
>
Notes
</div>
<div class="mt-4 text-lg whitespace-pre-line">
{{ doc.terms }}
{{ printObject.terms }}
</div>
</div>
<div class="w-1/2 text-lg">
<div class="flex pl-2 justify-between py-1">
<div>{{ t`Subtotal` }}</div>
<div>{{ fyo.format(doc.netTotal, 'Currency') }}</div>
<div>{{ printObject.netTotal }}</div>
</div>
<div
class="flex pl-2 justify-between py-1"
v-if="totalDiscount?.float > 0 && !doc.discountAfterTax"
v-if="printObject.totalDiscount && !printObject.discountAfterTax"
>
<div>{{ t`Discount` }}</div>
<div>{{ `- ${fyo.format(totalDiscount, 'Currency')}` }}</div>
<div>{{ printObject.totalDiscount }}</div>
</div>
<div
class="flex pl-2 justify-between py-1"
v-for="tax in doc.taxes"
v-for="tax in printObject.taxes"
:key="tax.name"
>
<div>{{ tax.account }}</div>
<div>{{ fyo.format(tax.amount, 'Currency') }}</div>
<div>{{ tax.amount }}</div>
</div>
<div
class="flex pl-2 justify-between py-1"
v-if="totalDiscount?.float > 0 && doc.discountAfterTax"
v-if="printObject.totalDiscount && printObject.discountAfterTax"
>
<div>{{ t`Discount` }}</div>
<div>{{ `- ${fyo.format(totalDiscount, 'Currency')}` }}</div>
<div>{{ printObject.totalDiscount }}</div>
</div>
<div
class="flex pl-2 justify-between py-1 font-semibold"
:style="{ color: printSettings.color }"
:style="{ color: printObject.color }"
>
<div>{{ t`Grand Total` }}</div>
<div>{{ fyo.format(doc.grandTotal, 'Currency') }}</div>
<div>{{ printObject.grandTotal }}</div>
</div>
</div>
</div>
</div>
</template>
<script>
import Base from './BaseTemplate.vue';
import BaseTemplate from './BaseTemplate.vue';
export default {
name: 'Minimal',
extends: Base,
extends: BaseTemplate,
};
</script>

View File

@ -185,10 +185,14 @@
<div>{{ tax.account }}</div>
<div>
{{
fyo.format(tax.amount, {
fieldtype: 'Currency',
currency: doc.currency,
})
fyo.format(
tax.amount,
{
fieldtype: 'Currency',
fieldname: 'amount',
},
tax
)
}}
</div>
</div>