fix: expense writing journal entries.

fix: delete expense from the storage.
This commit is contained in:
Ahmed Bouhuolia
2020-10-05 20:14:31 +02:00
parent 99e6fe273f
commit 63c4567e08
5 changed files with 73 additions and 49 deletions

View File

@@ -138,16 +138,18 @@ export default class JournalCommands{
const paymentJournalEntry = new JournalEntry({
credit: expense.totalAmount,
account: expense.paymentAccountId,
index: 1,
...mixinEntry,
});
this.journal.credit(paymentJournalEntry);
expense.categories.forEach((category: IExpenseCategory) => {
expense.categories.forEach((category: IExpenseCategory, index) => {
const expenseJournalEntry = new JournalEntry({
account: category.expenseAccountId,
debit: category.amount,
note: category.description,
...mixinEntry,
index: index + 2,
});
this.journal.debit(expenseJournalEntry);
});

View File

@@ -143,16 +143,15 @@ export default class ExpensesService implements IExpensesService {
}
}
private async revertJournalEntries(
public async revertJournalEntries(
tenantId: number,
expenseId: number|number[],
) {
const journal = new JournalPoster(tenantId);
const journalCommands = new JournalCommands(journal);
if (revertOld) {
await journalCommands.revertJournalEntries(expenseId, 'Expense');
}
await journalCommands.revertJournalEntries(expenseId, 'Expense');
return Promise.all([
journal.saveBalance(),
journal.deleteEntries(),

View File

@@ -14,7 +14,7 @@ export default class JournalPosterService {
* @param {string} referenceType - The transaction reference type.
* @return {Promise}
*/
async deleteJournalTransactions(
async revertJournalTransactions(
tenantId: number,
referenceId: number,
referenceType: string