feat: add local adjustment and discount properties to SaleInvoice and SaleReceipt interfaces.

This commit is contained in:
Ahmed Bouhuolia
2024-12-09 00:19:22 +02:00
parent b9963aa241
commit 477da0e7c0
5 changed files with 24 additions and 21 deletions

View File

@@ -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 {

View File

@@ -39,6 +39,9 @@ export interface ISaleReceipt {
discountPercentage?: number | null;
adjustment?: number;
adjustmentLocal?: number | null;
discountAmountLocal?: number | null;
}
export interface ISalesReceiptsFilter {

View File

@@ -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,
@@ -266,7 +262,7 @@ export class BillGLEntries {
return {
...commonEntry,
credit: bill.discountAmount,
credit: bill.discountAmountLocal,
accountId: purchaseDiscountAccountId,
accountNormal: AccountNormal.DEBIT,
index: 1,
@@ -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,
@@ -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 [

View File

@@ -281,7 +281,7 @@ export class SaleInvoiceGLEntries {
return {
...commonEntry,
debit: saleInvoice.discountAmount,
debit: saleInvoice.discountAmountLocal,
accountId: discountAccountId,
accountNormal: AccountNormal.CREDIT,
index: 1,
@@ -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,

View File

@@ -204,7 +204,7 @@ export class SaleReceiptGLEntries {
return {
...commonEntry,
debit: saleReceipt.discountAmount,
debit: saleReceipt.discountAmountLocal,
accountId: discountAccountId,
index: 1,
accountNormal: AccountNormal.CREDIT,
@@ -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,
@@ -253,7 +253,6 @@ export class SaleReceiptGLEntries {
saleReceipt,
otherChargesAccountId
);
return [depositEntry, ...creditEntries, discountEntry, adjustmentEntry];
};
}