Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add payment details in print templates #1120

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions src/utils/printTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,8 @@ export async function getPrintTemplatePropValues(
paymentId = await (doc as SalesInvoice).getPaymentIds();

if (paymentId && paymentId.length) {
const paymentDoc = await fyo.doc.getDoc(
ModelNameEnum.Payment,
paymentId[0]
);

(values.doc as PrintTemplateData).paymentMethod =
paymentDoc.paymentMethod;

(values.doc as PrintTemplateData).paidAmount = doc.fyo.format(
paymentDoc.amount as Money,
ModelNameEnum.Currency
);
const paymentDetails = await getPaymentDetails(doc, paymentId);
(values.doc as PrintTemplateData).paymentDetails = paymentDetails;
}
}

Expand Down Expand Up @@ -133,6 +123,28 @@ export async function getPrintTemplatePropValues(

return values;
}
async function getPaymentDetails(doc: Doc, paymentId: string[]) {
const paymentIds = paymentId.sort();
const paymentDetails = [];
let outstandingAmount = doc.grandTotal as Money;

for (const payment of paymentIds) {
const paymentDoc = await doc.fyo.doc.getDoc(ModelNameEnum.Payment, payment);
outstandingAmount = outstandingAmount.sub(paymentDoc.amount as Money);

paymentDetails.push({
amount: doc.fyo.format(paymentDoc.amount, ModelNameEnum.Currency),
amountPaid: doc.fyo.format(paymentDoc.amountPaid, ModelNameEnum.Currency),
paymentMethod: paymentDoc.paymentMethod as string,
outstandingAmount: doc.fyo.format(
outstandingAmount,
ModelNameEnum.Currency
),
});
}

return paymentDetails;
}

function getDate(dateString: string): string {
const date = new Date(dateString);
Expand Down
56 changes: 28 additions & 28 deletions templates/Business-POS.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ <h4 class="font-semibold text-xl">Invoice</h4>
<section class="font-bold w-auto flex border-b border-t border-black">
<div class="py-1 w-4">{{ t`SI` }}</div>
<div class="py-1 w-2/5">{{ t`Item` }}</div>
<div class="py-1 text-right w-2/12" v-if="doc.showHSN">
{{ t`HSN/SAC` }}
</div>
<div class="py-1 w-1/12">{{ t`Qty` }}</div>
<div class="py-1 text-right w-3/12">{{ t`Price` }}</div>
<div class="py-1 text-right w-3/12">{{ t`Amount` }}</div>
Expand All @@ -59,9 +56,6 @@ <h4 class="font-semibold text-xl">Invoice</h4>
>
<div class="w-4 py-1">{{ index + 1 }}</div>
<div class="w-2/5 py-1">{{ row.item }}</div>
<div class="w-2/12 text-right py-1" v-if="doc.showHSN">
{{ row.hsnCode }}
</div>
<div class="w-1/12 py-1 text-left">{{ row.quantity }}</div>
<div class="w-3/12 text-right py-1">{{ row.rate }}</div>
<div class="w-3/12 text-right py-1">{{ row.amount }}</div>
Expand All @@ -74,18 +68,29 @@ <h4 class="font-semibold text-xl">Invoice</h4>
</section>

<!-- Grand Total -->
<section class="flex justify-between border-b border-black pt-3">
<section class="flex justify-between pt-3">
<p class="font-semibold text-lg">Net Total To Pay</p>
<p class="font-semibold text-xl">{{ doc.grandTotal }}</p>
</section>
</section>

<!-- Tax Breakdown -->
<section class="mx-2">
<p class="flex justify-center font-semibold text-lg mt-2">Vat Summary</p>
<section v-if="doc.taxes.length" class="mx-2">
<p
class="
flex
justify-center
font-semibold
border-t border-black
text-lg
mt-2
"
>
Tax Summary
</p>

<div class="flex justify-between pl-5 text-base">
<p>Total Ex.Vat</p>
<p>Total Ex.Tax</p>
<p>{{doc.subTotal}}</p>
</div>

Expand All @@ -99,35 +104,30 @@ <h4 class="font-semibold text-xl">Invoice</h4>
</div>
</section>

<section class="mx-1 pt-2 text-sm mr-1">
<div class="grid grid-cols-4 grid-rows-1">
<!-- Discounts & Payments -->
<section class="mx-1 pt-2 text-sm mr-1 border-b border-black">
<div class="grid grid-cols-3 grid-rows-1">
<div>{{ t`Payment` }}</div>
<div class="text-right">{{ t`Tendered` }}</div>
<div class="text-right">{{ t`Amount` }}</div>
<div class="text-right">{{ t`Balance` }}</div>
</div>

<div
class="
w-auto
grid grid-cols-4 grid-rows-2
border-b border-t border-black
text-xs
gap-y-1
"
class="w-auto grid grid-cols-3 grid-rows-1 border-t border-black text-xs"
>
<div>{{ t`Discount` }}</div>
<div class="text-right font-medium">
{{ doc.totalDiscount ? doc.totalDiscount : '00.00'}}
</div>
<div class="text-right font-medium">
{{ doc.totalDiscount ? doc.totalDiscount : '00.00'}}
</div>
<div class="row-start-2">{{ doc.paymentMethod }}</div>
<div class="row-start-2 font-medium text-right">{{ doc.paidAmount }}</div>
<div class="row-start-2 font-medium text-right">{{ doc.grandTotal }}</div>
<div class="row-start-2 font-medium text-right">
{{ doc.outstandingAmount }}
</div>

<div v-for="(row,index) in doc.paymentDetails">
<div class="w-auto grid grid-cols-3 border-black text-xs">
<div class="row-start-2">{{ row.paymentMethod }}</div>
<div class="row-start-2 font-medium text-right">{{ row.amount }}</div>
<div class="row-start-2 font-medium text-right">
{{ row.outstandingAmount }}
</div>
</div>
</div>
</section>
Expand Down