Skip to content

Commit

Permalink
feat: add local adjustment and discount properties to SaleInvoice and…
Browse files Browse the repository at this point in the history
… SaleReceipt interfaces.
  • Loading branch information
abouolia committed Dec 8, 2024
1 parent b9963aa commit 477da0e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
2 changes: 2 additions & 0 deletions packages/server/src/interfaces/SaleInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ export interface ISaleInvoice {
paymentMethods?: Array<PaymentIntegrationTransactionLink>;

adjustment?: number;
adjustmentLocal?: number | null;

discount?: number;
discountAmount?: number;
discountAmountLocal?: number | null;
}

export enum DiscountType {
Expand Down
3 changes: 3 additions & 0 deletions packages/server/src/interfaces/SaleReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export interface ISaleReceipt {
discountPercentage?: number | null;

adjustment?: number;
adjustmentLocal?: number | null;

discountAmountLocal?: number | null;
}

export interface ISalesReceiptsFilter {
Expand Down
23 changes: 11 additions & 12 deletions packages/server/src/services/Purchases/Bills/BillGLEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ export class BillGLEntries {
trx
);
// Find or create other expenses account.
const otherExpensesAccount = await accountRepository.findOrCreateOtherExpensesAccount(
{},
trx
);
const otherExpensesAccount =
await accountRepository.findOrCreateOtherExpensesAccount({}, trx);
// Find or create purchase discount account.
const purchaseDiscountAccount = await accountRepository.findOrCreatePurchaseDiscountAccount(
{},
trx
);
const purchaseDiscountAccount =
await accountRepository.findOrCreatePurchaseDiscountAccount({}, trx);
const billLedger = this.getBillLedger(
bill,
APAccount.id,
Expand Down Expand Up @@ -266,7 +262,7 @@ export class BillGLEntries {

return {
...commonEntry,
credit: bill.discountAmount,
credit: bill.discountAmountLocal,
accountId: purchaseDiscountAccountId,
accountNormal: AccountNormal.DEBIT,
index: 1,
Expand All @@ -288,8 +284,8 @@ export class BillGLEntries {

return {
...commonEntry,
debit: bill.adjustment < 0 ? bill.adjustment : 0,
credit: bill.adjustment > 0 ? bill.adjustment : 0,
debit: bill.adjustmentLocal < 0 ? bill.adjustmentLocal : 0,
credit: bill.adjustmentLocal > 0 ? bill.adjustmentLocal : 0,
accountId: otherExpensesAccountId,
accountNormal: AccountNormal.DEBIT,
index: 1,
Expand Down Expand Up @@ -325,7 +321,10 @@ export class BillGLEntries {
bill,
purchaseDiscountAccountId
);
const adjustmentEntry = this.getAdjustmentEntry(bill, otherExpensesAccountId);
const adjustmentEntry = this.getAdjustmentEntry(
bill,
otherExpensesAccountId
);

// Allocate cost entries journal entries.
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export class SaleInvoiceGLEntries {

return {
...commonEntry,
debit: saleInvoice.discountAmount,
debit: saleInvoice.discountAmountLocal,
accountId: discountAccountId,
accountNormal: AccountNormal.CREDIT,
index: 1,
Expand All @@ -299,12 +299,12 @@ export class SaleInvoiceGLEntries {
otherChargesAccountId: number
): ILedgerEntry => {
const commonEntry = this.getInvoiceGLCommonEntry(saleInvoice);
const adjustmentAmount = Math.abs(saleInvoice.adjustment);
const adjustmentAmount = Math.abs(saleInvoice.adjustmentLocal);

return {
...commonEntry,
debit: saleInvoice.adjustment < 0 ? adjustmentAmount : 0,
credit: saleInvoice.adjustment > 0 ? adjustmentAmount : 0,
debit: saleInvoice.adjustmentLocal < 0 ? adjustmentAmount : 0,
credit: saleInvoice.adjustmentLocal > 0 ? adjustmentAmount : 0,
accountId: otherChargesAccountId,
accountNormal: AccountNormal.CREDIT,
index: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class SaleReceiptGLEntries {

return {
...commonEntry,
debit: saleReceipt.discountAmount,
debit: saleReceipt.discountAmountLocal,
accountId: discountAccountId,
index: 1,
accountNormal: AccountNormal.CREDIT,
Expand All @@ -222,12 +222,12 @@ export class SaleReceiptGLEntries {
adjustmentAccountId: number
): ILedgerEntry => {
const commonEntry = this.getIncomeGLCommonEntry(saleReceipt);
const adjustmentAmount = Math.abs(saleReceipt.adjustment);
const adjustmentAmount = Math.abs(saleReceipt.adjustmentLocal);

return {
...commonEntry,
debit: saleReceipt.adjustment < 0 ? adjustmentAmount : 0,
credit: saleReceipt.adjustment > 0 ? adjustmentAmount : 0,
debit: saleReceipt.adjustmentLocal < 0 ? adjustmentAmount : 0,
credit: saleReceipt.adjustmentLocal > 0 ? adjustmentAmount : 0,
accountId: adjustmentAccountId,
accountNormal: AccountNormal.CREDIT,
index: 1,
Expand All @@ -253,7 +253,6 @@ export class SaleReceiptGLEntries {
saleReceipt,
otherChargesAccountId
);

return [depositEntry, ...creditEntries, discountEntry, adjustmentEntry];
};
}

0 comments on commit 477da0e

Please sign in to comment.