Skip to content

Commit

Permalink
feat: add totalExcludingTax property and update GL entry calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Dec 12, 2024
1 parent 8cd1b36 commit d640dc1
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/server/src/interfaces/ItemEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface IItemEntry {
amount: number;

total: number;
totalExcludingTax?: number;

subtotalInclusingTax: number;
subtotalExcludingTax: number;
discountAmount: number;
Expand Down
8 changes: 8 additions & 0 deletions packages/server/src/models/ItemEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ export default class ItemEntry extends TenantModel {
return this.subtotal - this.discountAmount;
}

/**
* Total (excluding tax).
* @returns {number}
*/
get totalExcludingTax() {
return this.subtotalExcludingTax - this.discountAmount;
}

/**
* Item entry amount.
* Amount of item entry that may include or exclude tax.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ export default class CreditNoteGLEntries {
index: number
): ILedgerEntry => {
const commonEntry = this.getCreditNoteCommonEntry(creditNote);
const localAmount = entry.amount * creditNote.exchangeRate;
const totalLocal = entry.totalExcludingTax * creditNote.exchangeRate;

return {
...commonEntry,
debit: localAmount,
debit: totalLocal,
accountId: entry.sellAccountId || entry.item.sellAccountId,
note: entry.description,
index: index + 2,
Expand Down
5 changes: 2 additions & 3 deletions packages/server/src/services/Purchases/Bills/BillGLEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ export class BillGLEntries {
private getBillItemEntry = R.curry(
(bill: IBill, entry: IItemEntry, index: number): ILedgerEntry => {
const commonJournalMeta = this.getBillCommonEntry(bill);

const localAmount = bill.exchangeRate * entry.subtotalExcludingTax;
const totalLocal = bill.exchangeRate * entry.totalExcludingTax;
const landedCostAmount = sumBy(entry.allocatedCostEntries, 'cost');

return {
...commonJournalMeta,
debit: localAmount + landedCostAmount,
debit: totalLocal + landedCostAmount,
accountId:
['inventory'].indexOf(entry.item.type) !== -1
? entry.item.inventoryAccountId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export default class VendorCreditGLEntries {
index: number
): ILedgerEntry => {
const commonEntity = this.getVendorCreditGLCommonEntry(vendorCredit);
const localAmount = entry.amount * vendorCredit.exchangeRate;
const totalLocal = entry.totalExcludingTax * vendorCredit.exchangeRate;

return {
...commonEntity,
credit: localAmount,
credit: totalLocal,
index: index + 2,
itemId: entry.itemId,
itemQuantity: entry.quantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class SaleInvoiceGLEntries {
index: number
): ILedgerEntry => {
const commonEntry = this.getInvoiceGLCommonEntry(saleInvoice);
const localAmount = entry.total * saleInvoice.exchangeRate;
const localAmount = entry.totalExcludingTax * saleInvoice.exchangeRate;

return {
...commonEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ export class SaleReceiptGLEntries {
};

/**
* Retrieve receipt income item GL entry.
* @param {ISaleReceipt} saleReceipt -
* @param {IItemEntry} entry -
* @param {number} index -
* Retrieve receipt income item G/L entry.
* @param {ISaleReceipt} saleReceipt -
* @param {IItemEntry} entry -
* @param {number} index -
* @returns {ILedgerEntry}
*/
private getReceiptIncomeItemEntry = R.curry(
Expand All @@ -156,11 +156,11 @@ export class SaleReceiptGLEntries {
index: number
): ILedgerEntry => {
const commonEntry = this.getIncomeGLCommonEntry(saleReceipt);
const itemIncome = entry.amount * saleReceipt.exchangeRate;
const totalLocal = entry.totalExcludingTax * saleReceipt.exchangeRate;

return {
...commonEntry,
credit: itemIncome,
credit: totalLocal,
accountId: entry.item.sellAccountId,
note: entry.description,
index: index + 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export function ReceiptPaperTemplate({
</Text>
</Stack>
),
thStyle: { width: '60%' },
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
Expand Down

0 comments on commit d640dc1

Please sign in to comment.