Files
bigcapital/server/src/services/Sales/JournalPosterService.ts
Ahmed Bouhuolia 899ea7a52d refactoring: bills service.
refactoring: bills payments made service.
2020-10-15 15:10:41 +02:00

33 lines
1.0 KiB
TypeScript

import { Service, Inject } from 'typedi';
import JournalPoster from 'services/Accounting/JournalPoster';
import TenancyService from 'services/Tenancy/TenancyService';
import JournalCommands from 'services/Accounting/JournalCommands';
@Service()
export default class JournalPosterService {
@Inject()
tenancy: TenancyService;
/**
* Deletes the journal transactions that associated to the given reference id.
* @param {number} tenantId - The given tenant id.
* @param {number} referenceId - The transaction reference id.
* @param {string} referenceType - The transaction reference type.
* @return {Promise}
*/
async revertJournalTransactions(
tenantId: number,
referenceId: number,
referenceType: string
) {
const journal = new JournalPoster(tenantId);
const journalCommand = new JournalCommands(journal);
await journalCommand.revertJournalEntries(referenceId, referenceType);
await Promise.all([
journal.deleteEntries(),
journal.saveBalance()
]);
}
}