From 46719ef361cdaca9ebd231d8736bc3e6beba92d7 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 8 Dec 2024 14:20:11 +0200 Subject: [PATCH] fix: discount transactions GL entries --- .../src/database/seeds/data/accounts.js | 60 ++++++-- packages/server/src/interfaces/SaleInvoice.ts | 5 + packages/server/src/models/Bill.ts | 12 +- packages/server/src/models/CreditNote.ts | 2 +- packages/server/src/models/SaleEstimate.ts | 2 +- packages/server/src/models/SaleInvoice.ts | 14 +- packages/server/src/models/SaleReceipt.ts | 2 +- packages/server/src/models/VendorCredit.ts | 2 +- .../src/repositories/AccountRepository.ts | 133 ++++++++++++++++-- .../services/Purchases/Bills/BillGLEntries.ts | 87 +++++++++++- .../Sales/Invoices/InvoiceGLEntries.ts | 90 +++++++++++- .../Purchases/Bills/BillForm/utils.tsx | 2 +- .../CreditNotes/CreditNoteForm/utils.tsx | 5 +- .../CreditNotes/CreditNoteForm/utils.tsx | 5 +- .../Sales/Estimates/EstimateForm/utils.tsx | 5 +- .../Sales/Invoices/InvoiceForm/utils.tsx | 2 +- .../Sales/Receipts/ReceiptForm/utils.tsx | 5 +- 17 files changed, 375 insertions(+), 58 deletions(-) diff --git a/packages/server/src/database/seeds/data/accounts.js b/packages/server/src/database/seeds/data/accounts.js index 5d21686c31..35430bbed5 100644 --- a/packages/server/src/database/seeds/data/accounts.js +++ b/packages/server/src/database/seeds/data/accounts.js @@ -1,3 +1,14 @@ +export const OtherExpensesAccount = { + name: 'Other Expenses', + slug: 'other-expenses', + account_type: 'other-expense', + code: '40011', + description: '', + active: 1, + index: 1, + predefined: 1, +}; + export const TaxPayableAccount = { name: 'Tax Payable', slug: 'tax-payable', @@ -39,8 +50,38 @@ export const StripeClearingAccount = { code: '100020', active: true, index: 1, - predefined: true, -} + predefined: true, +}; + +export const DiscountExpenseAccount = { + name: 'Discount', + slug: 'discount', + account_type: 'other-income', + code: '40008', + active: true, + index: 1, + predefined: true, +}; + +export const PurchaseDiscountAccount = { + name: 'Purchase Discount', + slug: 'purchase-discount', + account_type: 'other-expense', + code: '40009', + active: true, + index: 1, + predefined: true, +}; + +export const OtherChargesAccount = { + name: 'Other Charges', + slug: 'other-charges', + account_type: 'other-income', + code: '40010', + active: true, + index: 1, + predefined: true, +}; export default [ { @@ -231,17 +272,7 @@ export default [ }, // Expenses - { - name: 'Other Expenses', - slug: 'other-expenses', - account_type: 'other-expense', - parent_account_id: null, - code: '40001', - description: '', - active: 1, - index: 1, - predefined: 1, - }, + OtherExpensesAccount, { name: 'Cost of Goods Sold', slug: 'cost-of-goods-sold', @@ -358,4 +389,7 @@ export default [ }, UnearnedRevenueAccount, PrepardExpenses, + DiscountExpenseAccount, + PurchaseDiscountAccount, + OtherChargesAccount, ]; diff --git a/packages/server/src/interfaces/SaleInvoice.ts b/packages/server/src/interfaces/SaleInvoice.ts index 897ac84990..c97153d8d2 100644 --- a/packages/server/src/interfaces/SaleInvoice.ts +++ b/packages/server/src/interfaces/SaleInvoice.ts @@ -80,6 +80,11 @@ export interface ISaleInvoice { pdfTemplateId?: number; paymentMethods?: Array; + + adjustment?: number; + + discount?: number; + discountAmount?: number; } export enum DiscountType { diff --git a/packages/server/src/models/Bill.ts b/packages/server/src/models/Bill.ts index 41e6364d4b..2d6299ce74 100644 --- a/packages/server/src/models/Bill.ts +++ b/packages/server/src/models/Bill.ts @@ -1,6 +1,7 @@ import { Model, raw, mixin } from 'objection'; import { castArray, defaultTo, difference } from 'lodash'; import moment from 'moment'; +import * as R from 'ramda'; import TenantModel from 'models/TenantModel'; import BillSettings from './Bill.Settings'; import ModelSetting from './ModelSetting'; @@ -133,12 +134,11 @@ export default class Bill extends mixin(TenantModel, [ get total() { const adjustmentAmount = defaultTo(this.adjustment, 0); - return this.isInclusiveTax - ? this.subtotal - this.discountAmount - adjustmentAmount - : this.subtotal + - this.taxAmountWithheld - - this.discountAmount - - adjustmentAmount; + return R.compose( + R.add(adjustmentAmount), + R.subtract(this.discountAmount), + R.when(R.always(this.isInclusiveTax), R.add(this.taxAmountWithheld)) + )(this.subtotal); } /** diff --git a/packages/server/src/models/CreditNote.ts b/packages/server/src/models/CreditNote.ts index b2cee85722..cdbbf90525 100644 --- a/packages/server/src/models/CreditNote.ts +++ b/packages/server/src/models/CreditNote.ts @@ -107,7 +107,7 @@ export default class CreditNote extends mixin(TenantModel, [ * @returns {number} */ get total() { - return this.subtotal - this.discountAmount - this.adjustment; + return this.subtotal - this.discountAmount + this.adjustment; } /** diff --git a/packages/server/src/models/SaleEstimate.ts b/packages/server/src/models/SaleEstimate.ts index 83df38c1e0..fce0f334b2 100644 --- a/packages/server/src/models/SaleEstimate.ts +++ b/packages/server/src/models/SaleEstimate.ts @@ -116,7 +116,7 @@ export default class SaleEstimate extends mixin(TenantModel, [ get total() { const adjustmentAmount = defaultTo(this.adjustment, 0); - return this.subtotal - this.discountAmount - adjustmentAmount; + return this.subtotal - this.discountAmount + adjustmentAmount; } /** diff --git a/packages/server/src/models/SaleInvoice.ts b/packages/server/src/models/SaleInvoice.ts index 7e874d2dee..098d4a20df 100644 --- a/packages/server/src/models/SaleInvoice.ts +++ b/packages/server/src/models/SaleInvoice.ts @@ -1,4 +1,5 @@ import { mixin, Model, raw } from 'objection'; +import * as R from 'ramda'; import { castArray, defaultTo, takeWhile } from 'lodash'; import moment from 'moment'; import TenantModel from 'models/TenantModel'; @@ -147,9 +148,7 @@ export default class SaleInvoice extends mixin(TenantModel, [ * @returns {number | null} */ get discountPercentage(): number | null { - return this.discountType === DiscountType.Percentage - ? this.discount - : null; + return this.discountType === DiscountType.Percentage ? this.discount : null; } /** @@ -158,11 +157,12 @@ export default class SaleInvoice extends mixin(TenantModel, [ */ get total() { const adjustmentAmount = defaultTo(this.adjustment, 0); - const differencies = this.discountAmount + adjustmentAmount; - return this.isInclusiveTax - ? this.subtotal - differencies - : this.subtotal + this.taxAmountWithheld - differencies; + return R.compose( + R.add(adjustmentAmount), + R.subtract(R.__, this.discountAmount), + R.when(R.always(this.isInclusiveTax), R.add(this.taxAmountWithheld)) + )(this.subtotal); } /** diff --git a/packages/server/src/models/SaleReceipt.ts b/packages/server/src/models/SaleReceipt.ts index 8bef046ed8..220bb4d839 100644 --- a/packages/server/src/models/SaleReceipt.ts +++ b/packages/server/src/models/SaleReceipt.ts @@ -108,7 +108,7 @@ export default class SaleReceipt extends mixin(TenantModel, [ get total() { const adjustmentAmount = defaultTo(this.adjustment, 0); - return this.subtotal - this.discountAmount - adjustmentAmount; + return this.subtotal - this.discountAmount + adjustmentAmount; } /** diff --git a/packages/server/src/models/VendorCredit.ts b/packages/server/src/models/VendorCredit.ts index 24f96afa83..0c4b3d4235 100644 --- a/packages/server/src/models/VendorCredit.ts +++ b/packages/server/src/models/VendorCredit.ts @@ -73,7 +73,7 @@ export default class VendorCredit extends mixin(TenantModel, [ * @returns {number} */ get total() { - return this.subtotal - this.discountAmount - this.adjustment; + return this.subtotal - this.discountAmount + this.adjustment; } /** diff --git a/packages/server/src/repositories/AccountRepository.ts b/packages/server/src/repositories/AccountRepository.ts index 53b26e284e..43e320b229 100644 --- a/packages/server/src/repositories/AccountRepository.ts +++ b/packages/server/src/repositories/AccountRepository.ts @@ -3,7 +3,11 @@ import TenantRepository from '@/repositories/TenantRepository'; import { IAccount } from '@/interfaces'; import { Knex } from 'knex'; import { + DiscountExpenseAccount, + OtherChargesAccount, + OtherExpensesAccount, PrepardExpenses, + PurchaseDiscountAccount, StripeClearingAccount, TaxPayableAccount, UnearnedRevenueAccount, @@ -188,9 +192,9 @@ export default class AccountRepository extends TenantRepository { /** * Finds or creates the unearned revenue. - * @param {Record} extraAttrs - * @param {Knex.Transaction} trx - * @returns + * @param {Record} extraAttrs + * @param {Knex.Transaction} trx + * @returns */ public async findOrCreateUnearnedRevenue( extraAttrs: Record = {}, @@ -219,9 +223,9 @@ export default class AccountRepository extends TenantRepository { /** * Finds or creates the prepard expenses account. - * @param {Record} extraAttrs - * @param {Knex.Transaction} trx - * @returns + * @param {Record} extraAttrs + * @param {Knex.Transaction} trx + * @returns */ public async findOrCreatePrepardExpenses( extraAttrs: Record = {}, @@ -249,12 +253,11 @@ export default class AccountRepository extends TenantRepository { return result; } - /** * Finds or creates the stripe clearing account. - * @param {Record} extraAttrs - * @param {Knex.Transaction} trx - * @returns + * @param {Record} extraAttrs + * @param {Knex.Transaction} trx + * @returns */ public async findOrCreateStripeClearing( extraAttrs: Record = {}, @@ -281,4 +284,114 @@ export default class AccountRepository extends TenantRepository { } return result; } + + /** + * Finds or creates the discount expense account. + * @param {Record} extraAttrs + * @param {Knex.Transaction} trx + * @returns + */ + public async findOrCreateDiscountAccount( + extraAttrs: Record = {}, + trx?: Knex.Transaction + ) { + // Retrieves the given tenant metadata. + const tenantMeta = await TenantMetadata.query().findOne({ + tenantId: this.tenantId, + }); + const _extraAttrs = { + currencyCode: tenantMeta.baseCurrency, + ...extraAttrs, + }; + + let result = await this.model + .query(trx) + .findOne({ slug: DiscountExpenseAccount.slug, ..._extraAttrs }); + + if (!result) { + result = await this.model.query(trx).insertAndFetch({ + ...DiscountExpenseAccount, + ..._extraAttrs, + }); + } + return result; + } + + public async findOrCreatePurchaseDiscountAccount( + extraAttrs: Record = {}, + trx?: Knex.Transaction + ) { + // Retrieves the given tenant metadata. + const tenantMeta = await TenantMetadata.query().findOne({ + tenantId: this.tenantId, + }); + const _extraAttrs = { + currencyCode: tenantMeta.baseCurrency, + ...extraAttrs, + }; + + let result = await this.model + .query(trx) + .findOne({ slug: PurchaseDiscountAccount.slug, ..._extraAttrs }); + + if (!result) { + result = await this.model.query(trx).insertAndFetch({ + ...PurchaseDiscountAccount, + ..._extraAttrs, + }); + } + return result; + } + + public async findOrCreateOtherChargesAccount( + extraAttrs: Record = {}, + trx?: Knex.Transaction + ) { + // Retrieves the given tenant metadata. + const tenantMeta = await TenantMetadata.query().findOne({ + tenantId: this.tenantId, + }); + const _extraAttrs = { + currencyCode: tenantMeta.baseCurrency, + ...extraAttrs, + }; + + let result = await this.model + .query(trx) + .findOne({ slug: OtherChargesAccount.slug, ..._extraAttrs }); + + if (!result) { + result = await this.model.query(trx).insertAndFetch({ + ...OtherChargesAccount, + ..._extraAttrs, + }); + } + return result; + } + + public async findOrCreateOtherExpensesAccount( + extraAttrs: Record = {}, + trx?: Knex.Transaction + ) { + // Retrieves the given tenant metadata. + const tenantMeta = await TenantMetadata.query().findOne({ + tenantId: this.tenantId, + }); + const _extraAttrs = { + currencyCode: tenantMeta.baseCurrency, + ...extraAttrs, + }; + + let result = await this.model + .query(trx) + .findOne({ slug: OtherExpensesAccount.slug, ..._extraAttrs }); + + if (!result) { + result = await this.model.query(trx).insertAndFetch({ + ...OtherExpensesAccount, + ..._extraAttrs, + }); + } + return result; + } } diff --git a/packages/server/src/services/Purchases/Bills/BillGLEntries.ts b/packages/server/src/services/Purchases/Bills/BillGLEntries.ts index 9c1352e9a6..e023a562eb 100644 --- a/packages/server/src/services/Purchases/Bills/BillGLEntries.ts +++ b/packages/server/src/services/Purchases/Bills/BillGLEntries.ts @@ -52,10 +52,22 @@ export class BillGLEntries { {}, trx ); + // Find or create other expenses account. + const otherExpensesAccount = await accountRepository.findOrCreateOtherExpensesAccount( + {}, + trx + ); + // Find or create purchase discount account. + const purchaseDiscountAccount = await accountRepository.findOrCreatePurchaseDiscountAccount( + {}, + trx + ); const billLedger = this.getBillLedger( bill, APAccount.id, - taxPayableAccount.id + taxPayableAccount.id, + purchaseDiscountAccount.id, + otherExpensesAccount.id ); // Commit the GL enties on the storage. await this.ledgerStorage.commit(tenantId, billLedger, trx); @@ -240,6 +252,51 @@ export class BillGLEntries { return nonZeroTaxEntries.map(transformTaxEntry); }; + /** + * Retrieves the purchase discount GL entry. + * @param {IBill} bill + * @param {number} purchaseDiscountAccountId + * @returns {ILedgerEntry} + */ + private getPurchaseDiscountEntry = ( + bill: IBill, + purchaseDiscountAccountId: number + ) => { + const commonEntry = this.getBillCommonEntry(bill); + + return { + ...commonEntry, + credit: bill.discountAmount, + accountId: purchaseDiscountAccountId, + accountNormal: AccountNormal.DEBIT, + index: 1, + indexGroup: 40, + }; + }; + + /** + * Retrieves the purchase other charges GL entry. + * @param {IBill} bill + * @param {number} otherChargesAccountId + * @returns {ILedgerEntry} + */ + private getAdjustmentEntry = ( + bill: IBill, + otherExpensesAccountId: number + ) => { + const commonEntry = this.getBillCommonEntry(bill); + + return { + ...commonEntry, + debit: bill.adjustment < 0 ? bill.adjustment : 0, + credit: bill.adjustment > 0 ? bill.adjustment : 0, + accountId: otherExpensesAccountId, + accountNormal: AccountNormal.DEBIT, + index: 1, + indexGroup: 40, + }; + }; + /** * Retrieves the given bill GL entries. * @param {IBill} bill @@ -249,7 +306,9 @@ export class BillGLEntries { private getBillGLEntries = ( bill: IBill, payableAccountId: number, - taxPayableAccountId: number + taxPayableAccountId: number, + purchaseDiscountAccountId: number, + otherExpensesAccountId: number ): ILedgerEntry[] => { const payableEntry = this.getBillPayableEntry(payableAccountId, bill); @@ -262,8 +321,21 @@ export class BillGLEntries { ); const taxEntries = this.getBillTaxEntries(bill, taxPayableAccountId); + const purchaseDiscountEntry = this.getPurchaseDiscountEntry( + bill, + purchaseDiscountAccountId + ); + const adjustmentEntry = this.getAdjustmentEntry(bill, otherExpensesAccountId); + // Allocate cost entries journal entries. - return [payableEntry, ...itemsEntries, ...landedCostEntries, ...taxEntries]; + return [ + payableEntry, + ...itemsEntries, + ...landedCostEntries, + ...taxEntries, + purchaseDiscountEntry, + adjustmentEntry, + ]; }; /** @@ -275,14 +347,17 @@ export class BillGLEntries { private getBillLedger = ( bill: IBill, payableAccountId: number, - taxPayableAccountId: number + taxPayableAccountId: number, + purchaseDiscountAccountId: number, + otherExpensesAccountId: number ) => { const entries = this.getBillGLEntries( bill, payableAccountId, - taxPayableAccountId + taxPayableAccountId, + purchaseDiscountAccountId, + otherExpensesAccountId ); - return new Ledger(entries); }; } diff --git a/packages/server/src/services/Sales/Invoices/InvoiceGLEntries.ts b/packages/server/src/services/Sales/Invoices/InvoiceGLEntries.ts index 61c575f678..6c671e861e 100644 --- a/packages/server/src/services/Sales/Invoices/InvoiceGLEntries.ts +++ b/packages/server/src/services/Sales/Invoices/InvoiceGLEntries.ts @@ -44,18 +44,31 @@ export class SaleInvoiceGLEntries { // Find or create the A/R account. const ARAccount = await accountRepository.findOrCreateAccountReceivable( - saleInvoice.currencyCode, {}, trx + saleInvoice.currencyCode, + {}, + trx ); // Find or create tax payable account. const taxPayableAccount = await accountRepository.findOrCreateTaxPayable( {}, trx ); + // Find or create the discount expense account. + const discountAccount = await accountRepository.findOrCreateDiscountAccount( + {}, + trx + ); + // Find or create the other charges account. + const otherChargesAccount = + await accountRepository.findOrCreateOtherChargesAccount({}, trx); + // Retrieves the ledger of the invoice. const ledger = this.getInvoiceGLedger( saleInvoice, ARAccount.id, - taxPayableAccount.id + taxPayableAccount.id, + discountAccount.id, + otherChargesAccount.id ); // Commits the ledger entries to the storage as UOW. await this.ledegrRepository.commit(tenantId, ledger, trx); @@ -107,12 +120,16 @@ export class SaleInvoiceGLEntries { public getInvoiceGLedger = ( saleInvoice: ISaleInvoice, ARAccountId: number, - taxPayableAccountId: number + taxPayableAccountId: number, + discountAccountId: number, + otherChargesAccountId: number ): ILedger => { const entries = this.getInvoiceGLEntries( saleInvoice, ARAccountId, - taxPayableAccountId + taxPayableAccountId, + discountAccountId, + otherChargesAccountId ); return new Ledger(entries); }; @@ -127,6 +144,7 @@ export class SaleInvoiceGLEntries { ): Partial => ({ credit: 0, debit: 0, + currencyCode: saleInvoice.currencyCode, exchangeRate: saleInvoice.exchangeRate, @@ -249,6 +267,50 @@ export class SaleInvoiceGLEntries { return nonZeroTaxEntries.map(transformTaxEntry); }; + /** + * Retrieves the invoice discount GL entry. + * @param {ISaleInvoice} saleInvoice + * @param {number} discountAccountId + * @returns {ILedgerEntry} + */ + private getInvoiceDiscountEntry = ( + saleInvoice: ISaleInvoice, + discountAccountId: number + ): ILedgerEntry => { + const commonEntry = this.getInvoiceGLCommonEntry(saleInvoice); + + return { + ...commonEntry, + debit: saleInvoice.discountAmount, + accountId: discountAccountId, + accountNormal: AccountNormal.CREDIT, + index: 1, + } as ILedgerEntry; + }; + + /** + * Retrieves the invoice adjustment GL entry. + * @param {ISaleInvoice} saleInvoice + * @param {number} adjustmentAccountId + * @returns {ILedgerEntry} + */ + private getAdjustmentEntry = ( + saleInvoice: ISaleInvoice, + otherChargesAccountId: number + ): ILedgerEntry => { + const commonEntry = this.getInvoiceGLCommonEntry(saleInvoice); + const adjustmentAmount = Math.abs(saleInvoice.adjustment); + + return { + ...commonEntry, + debit: saleInvoice.adjustment < 0 ? adjustmentAmount : 0, + credit: saleInvoice.adjustment > 0 ? adjustmentAmount : 0, + accountId: otherChargesAccountId, + accountNormal: AccountNormal.CREDIT, + index: 1, + }; + }; + /** * Retrieves the invoice GL entries. * @param {ISaleInvoice} saleInvoice @@ -258,7 +320,9 @@ export class SaleInvoiceGLEntries { public getInvoiceGLEntries = ( saleInvoice: ISaleInvoice, ARAccountId: number, - taxPayableAccountId: number + taxPayableAccountId: number, + discountAccountId: number, + otherChargesAccountId: number ): ILedgerEntry[] => { const receivableEntry = this.getInvoiceReceivableEntry( saleInvoice, @@ -271,6 +335,20 @@ export class SaleInvoiceGLEntries { saleInvoice, taxPayableAccountId ); - return [receivableEntry, ...creditEntries, ...taxEntries]; + const discountEntry = this.getInvoiceDiscountEntry( + saleInvoice, + discountAccountId + ); + const adjustmentEntry = this.getAdjustmentEntry( + saleInvoice, + otherChargesAccountId + ); + return [ + receivableEntry, + ...creditEntries, + ...taxEntries, + discountEntry, + adjustmentEntry, + ]; }; } diff --git a/packages/webapp/src/containers/Purchases/Bills/BillForm/utils.tsx b/packages/webapp/src/containers/Purchases/Bills/BillForm/utils.tsx index 35296368a8..b570b132ca 100644 --- a/packages/webapp/src/containers/Purchases/Bills/BillForm/utils.tsx +++ b/packages/webapp/src/containers/Purchases/Bills/BillForm/utils.tsx @@ -415,7 +415,7 @@ export const useBillTotal = () => { return R.compose( R.when(R.always(isExclusiveTax), R.add(totalTaxAmount)), R.subtract(R.__, discountAmount), - R.subtract(R.__, adjustmentAmount), + R.add(R.__, adjustmentAmount), )(subtotal); }; diff --git a/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/utils.tsx b/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/utils.tsx index e796d85d31..7724629be1 100644 --- a/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/utils.tsx +++ b/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/utils.tsx @@ -259,7 +259,10 @@ export const useVendorCreditTotal = () => { const discountAmount = useVendorCreditDiscountAmount(); const adjustment = useVendorCreditAdjustment(); - return subtotal - discountAmount - adjustment; + return R.compose( + R.subtract(R.__, discountAmount), + R.add(R.__, adjustment), + )(subtotal); }; /** diff --git a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/utils.tsx b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/utils.tsx index 8a772f4ce4..470cc3f5cf 100644 --- a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/utils.tsx @@ -263,7 +263,10 @@ export const useCreditNoteTotal = () => { const discountAmount = useCreditNoteDiscountAmount(); const adjustmentAmount = useCreditNoteAdjustmentAmount(); - return subtotal - discountAmount - adjustmentAmount; + return R.compose( + R.subtract(R.__, discountAmount), + R.add(R.__, adjustmentAmount), + )(subtotal); }; /** diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx index 3669bf868a..1bca08342c 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx @@ -299,7 +299,10 @@ export const useEstimateTotal = () => { const discount = useEstimateDiscount(); const adjustment = useEstimateAdjustment(); - return subtotal - discount - adjustment; + return R.compose( + R.subtract(R.__, discount), + R.add(R.__, adjustment), + )(subtotal); }; /** diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx index 93fb588416..530a70dd41 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/utils.tsx @@ -455,7 +455,7 @@ export const useInvoiceTotal = () => { return R.compose( R.when(R.always(isExclusiveTax), R.add(totalTaxAmount)), R.subtract(R.__, discountAmount), - R.subtract(R.__, adjustmentAmount), + R.add(R.__, adjustmentAmount), )(subtotal); }; diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx index c7365c6805..bca99c9f6a 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx @@ -284,7 +284,10 @@ export const useReceiptTotal = () => { const adjustmentAmount = useReceiptAdjustmentAmount(); const discountAmount = useReceiptDiscountAmount(); - return subtotal - discountAmount - adjustmentAmount; + return R.compose( + R.add(R.__, adjustmentAmount), + R.subtract(R.__, discountAmount), + )(subtotal); }; /**