Merge pull request #119 from bigcapitalhq/fix-delete-journals-manual-journal

fix(server): deleting ledger entries of manual journal
This commit is contained in:
Ahmed Bouhuolia
2023-05-12 00:14:36 +02:00
committed by GitHub
4 changed files with 16 additions and 24 deletions

View File

@@ -10,7 +10,7 @@ export class LedgerRevert {
private tenancy: HasTenancyService; private tenancy: HasTenancyService;
@Inject() @Inject()
ledgerStorage: LedgerStorageService; private ledgerStorage: LedgerStorageService;
/** /**
* Reverts the jouranl entries. * Reverts the jouranl entries.

View File

@@ -5,18 +5,13 @@ import {
ICreditNoteDeletedPayload, ICreditNoteDeletedPayload,
ICreditNoteEditedPayload, ICreditNoteEditedPayload,
ICreditNoteOpenedPayload, ICreditNoteOpenedPayload,
IRefundCreditNoteOpenedPayload,
} from '@/interfaces'; } from '@/interfaces';
import CreditNoteGLEntries from './CreditNoteGLEntries'; import CreditNoteGLEntries from './CreditNoteGLEntries';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@Service() @Service()
export default class CreditNoteGLEntriesSubscriber { export default class CreditNoteGLEntriesSubscriber {
@Inject() @Inject()
creditNoteGLEntries: CreditNoteGLEntries; private creditNoteGLEntries: CreditNoteGLEntries;
@Inject()
tenancy: HasTenancyService;
/** /**
* Attaches events with handlers. * Attaches events with handlers.

View File

@@ -1,11 +1,10 @@
import { difference, sumBy, omit, map } from 'lodash'; import { difference } from 'lodash';
import { Service, Inject } from 'typedi'; import { Service, Inject } from 'typedi';
import { ServiceError } from '@/exceptions'; import { ServiceError } from '@/exceptions';
import { import {
IManualJournalDTO, IManualJournalDTO,
IManualJournalEntry, IManualJournalEntry,
IManualJournal, IManualJournal,
IManualJournalEntryDTO,
} from '@/interfaces'; } from '@/interfaces';
import TenancyService from '@/services/Tenancy/TenancyService'; import TenancyService from '@/services/Tenancy/TenancyService';
import { ERRORS } from './constants'; import { ERRORS } from './constants';
@@ -286,7 +285,7 @@ export class CommandManualJournalValidators {
public validateJournalCurrencyWithAccountsCurrency = async ( public validateJournalCurrencyWithAccountsCurrency = async (
tenantId: number, tenantId: number,
manualJournalDTO: IManualJournalDTO, manualJournalDTO: IManualJournalDTO,
baseCurrency: string, baseCurrency: string
) => { ) => {
const { Account } = this.tenancy.models(tenantId); const { Account } = this.tenancy.models(tenantId);

View File

@@ -3,25 +3,20 @@ import * as R from 'ramda';
import { import {
IManualJournal, IManualJournal,
IManualJournalEntry, IManualJournalEntry,
IAccount,
ILedgerEntry, ILedgerEntry,
} from '@/interfaces'; } from '@/interfaces';
import { Knex } from 'knex'; import { Knex } from 'knex';
import Ledger from '@/services/Accounting/Ledger'; import Ledger from '@/services/Accounting/Ledger';
import LedgerStorageService from '@/services/Accounting/LedgerStorageService'; import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
import HasTenancyService from '@/services/Tenancy/TenancyService'; import HasTenancyService from '@/services/Tenancy/TenancyService';
import { LedgerRevert } from '@/services/Accounting/LedgerStorageRevert';
@Service() @Service()
export class ManualJournalGLEntries { export class ManualJournalGLEntries {
@Inject() @Inject()
ledgerStorage: LedgerStorageService; private ledgerStorage: LedgerStorageService;
@Inject() @Inject()
ledgerRevert: LedgerRevert; private tenancy: HasTenancyService;
@Inject()
tenancy: HasTenancyService;
/** /**
* Create manual journal GL entries. * Create manual journal GL entries.
@@ -77,7 +72,7 @@ export class ManualJournalGLEntries {
manualJournalId: number, manualJournalId: number,
trx?: Knex.Transaction trx?: Knex.Transaction
): Promise<void> => { ): Promise<void> => {
return this.ledgerRevert.revertGLEntries( return this.ledgerStorage.deleteByReference(
tenantId, tenantId,
manualJournalId, manualJournalId,
'Journal', 'Journal',
@@ -86,7 +81,7 @@ export class ManualJournalGLEntries {
}; };
/** /**
* * Retrieves the ledger of the given manual journal.
* @param {IManualJournal} manualJournal * @param {IManualJournal} manualJournal
* @returns {Ledger} * @returns {Ledger}
*/ */
@@ -97,11 +92,13 @@ export class ManualJournalGLEntries {
}; };
/** /**
* * Retrieves the common entry details of the manual journal
* @param {IManualJournal} manualJournal * @param {IManualJournal} manualJournal
* @returns {} * @returns {Partial<ILedgerEntry>}
*/ */
private getManualJournalCommonEntry = (manualJournal: IManualJournal) => { private getManualJournalCommonEntry = (
manualJournal: IManualJournal
): Partial<ILedgerEntry> => {
return { return {
transactionNumber: manualJournal.journalNumber, transactionNumber: manualJournal.journalNumber,
referenceNumber: manualJournal.reference, referenceNumber: manualJournal.reference,
@@ -118,7 +115,8 @@ export class ManualJournalGLEntries {
}; };
/** /**
* * Retrieves the ledger entry of the given manual journal and
* its associated entry.
* @param {IManualJournal} manualJournal - * @param {IManualJournal} manualJournal -
* @param {IManualJournalEntry} entry - * @param {IManualJournalEntry} entry -
* @returns {ILedgerEntry} * @returns {ILedgerEntry}
@@ -149,7 +147,7 @@ export class ManualJournalGLEntries {
); );
/** /**
* * Retrieves the ledger of the given manual journal.
* @param {IManualJournal} manualJournal * @param {IManualJournal} manualJournal
* @returns {ILedgerEntry[]} * @returns {ILedgerEntry[]}
*/ */