fix(server): customer/vendor opening balance:

This commit is contained in:
Ahmed Bouhuolia
2026-01-23 17:43:22 +02:00
parent 17651e0768
commit ca910ee489
9 changed files with 495 additions and 552 deletions

View File

@@ -1,115 +1,116 @@
// import { Service } from 'typedi';
// import { IVendor, AccountNormal, ILedgerEntry } from '@/interfaces';
// import Ledger from '@/services/Accounting/Ledger';
import { Injectable } from '@nestjs/common';
import { AccountNormal } from '@/interfaces/Account';
import { ILedgerEntry } from '@/modules/Ledger/types/Ledger.types';
import { Ledger } from '@/modules/Ledger/Ledger';
import { Vendor } from './models/Vendor';
// @Service()
// export class VendorGLEntries {
// /**
// * Retrieves the opening balance GL common entry.
// * @param {IVendor} vendor -
// */
// private getOpeningBalanceGLCommonEntry = (vendor: IVendor) => {
// return {
// exchangeRate: vendor.openingBalanceExchangeRate,
// currencyCode: vendor.currencyCode,
@Injectable()
export class VendorGLEntries {
/**
* Retrieves the opening balance GL common entry.
* @param {Vendor} vendor -
*/
private getOpeningBalanceGLCommonEntry = (vendor: Vendor) => {
return {
exchangeRate: vendor.openingBalanceExchangeRate,
currencyCode: vendor.currencyCode,
// transactionType: 'VendorOpeningBalance',
// transactionId: vendor.id,
transactionType: 'VendorOpeningBalance',
transactionId: vendor.id,
// date: vendor.openingBalanceAt,
// userId: vendor.userId,
// contactId: vendor.id,
date: vendor.openingBalanceAt,
contactId: vendor.id,
// credit: 0,
// debit: 0,
credit: 0,
debit: 0,
// branchId: vendor.openingBalanceBranchId,
// };
// };
branchId: vendor.openingBalanceBranchId,
};
};
// /**
// * Retrieves the opening balance GL debit entry.
// * @param {number} costAccountId -
// * @param {IVendor} vendor
// * @returns {ILedgerEntry}
// */
// private getOpeningBalanceGLDebitEntry = (
// costAccountId: number,
// vendor: IVendor
// ): ILedgerEntry => {
// const commonEntry = this.getOpeningBalanceGLCommonEntry(vendor);
/**
* Retrieves the opening balance GL debit entry.
* @param {number} costAccountId -
* @param {Vendor} vendor
* @returns {ILedgerEntry}
*/
private getOpeningBalanceGLDebitEntry = (
costAccountId: number,
vendor: Vendor
): ILedgerEntry => {
const commonEntry = this.getOpeningBalanceGLCommonEntry(vendor);
// return {
// ...commonEntry,
// accountId: costAccountId,
// accountNormal: AccountNormal.DEBIT,
// debit: vendor.localOpeningBalance,
// credit: 0,
// index: 2,
// };
// };
return {
...commonEntry,
accountId: costAccountId,
accountNormal: AccountNormal.DEBIT,
debit: vendor.localOpeningBalance,
credit: 0,
index: 2,
};
};
// /**
// * Retrieves the opening balance GL credit entry.
// * @param {number} APAccountId
// * @param {IVendor} vendor
// * @returns {ILedgerEntry}
// */
// private getOpeningBalanceGLCreditEntry = (
// APAccountId: number,
// vendor: IVendor
// ): ILedgerEntry => {
// const commonEntry = this.getOpeningBalanceGLCommonEntry(vendor);
/**
* Retrieves the opening balance GL credit entry.
* @param {number} APAccountId
* @param {Vendor} vendor
* @returns {ILedgerEntry}
*/
private getOpeningBalanceGLCreditEntry = (
APAccountId: number,
vendor: Vendor
): ILedgerEntry => {
const commonEntry = this.getOpeningBalanceGLCommonEntry(vendor);
// return {
// ...commonEntry,
// accountId: APAccountId,
// accountNormal: AccountNormal.CREDIT,
// credit: vendor.localOpeningBalance,
// index: 1,
// };
// };
return {
...commonEntry,
accountId: APAccountId,
accountNormal: AccountNormal.CREDIT,
credit: vendor.localOpeningBalance,
index: 1,
};
};
// /**
// * Retrieves the opening balance GL entries.
// * @param {number} APAccountId
// * @param {number} costAccountId -
// * @param {IVendor} vendor
// * @returns {ILedgerEntry[]}
// */
// public getOpeningBalanceGLEntries = (
// APAccountId: number,
// costAccountId: number,
// vendor: IVendor
// ): ILedgerEntry[] => {
// const debitEntry = this.getOpeningBalanceGLDebitEntry(
// costAccountId,
// vendor
// );
// const creditEntry = this.getOpeningBalanceGLCreditEntry(
// APAccountId,
// vendor
// );
// return [debitEntry, creditEntry];
// };
/**
* Retrieves the opening balance GL entries.
* @param {number} APAccountId
* @param {number} costAccountId -
* @param {Vendor} vendor
* @returns {ILedgerEntry[]}
*/
public getOpeningBalanceGLEntries = (
APAccountId: number,
costAccountId: number,
vendor: Vendor
): ILedgerEntry[] => {
const debitEntry = this.getOpeningBalanceGLDebitEntry(
costAccountId,
vendor
);
const creditEntry = this.getOpeningBalanceGLCreditEntry(
APAccountId,
vendor
);
return [debitEntry, creditEntry];
};
// /**
// * Retrieves the opening balance ledger.
// * @param {number} APAccountId
// * @param {number} costAccountId -
// * @param {IVendor} vendor
// * @returns {Ledger}
// */
// public getOpeningBalanceLedger = (
// APAccountId: number,
// costAccountId: number,
// vendor: IVendor
// ) => {
// const entries = this.getOpeningBalanceGLEntries(
// APAccountId,
// costAccountId,
// vendor
// );
// return new Ledger(entries);
// };
// }
/**
* Retrieves the opening balance ledger.
* @param {number} APAccountId
* @param {number} costAccountId -
* @param {Vendor} vendor
* @returns {Ledger}
*/
public getOpeningBalanceLedger = (
APAccountId: number,
costAccountId: number,
vendor: Vendor
) => {
const entries = this.getOpeningBalanceGLEntries(
APAccountId,
costAccountId,
vendor
);
return new Ledger(entries);
};
}