fix: database migrations FK relations.

fix: database columns indexing.
This commit is contained in:
Ahmed Bouhuolia
2020-10-03 12:08:11 +02:00
parent 1250eccc0d
commit 0114ed9f8b
86 changed files with 788 additions and 801 deletions

View File

@@ -2,9 +2,12 @@ import { sumBy, chain } from 'lodash';
import JournalPoster from "./JournalPoster";
import JournalEntry from "./JournalEntry";
import { AccountTransaction } from 'models';
import { IInventoryTransaction, IManualJournal } from 'interfaces';
import AccountsService from '../Accounts/AccountsService';
import { IInventoryTransaction, IInventoryTransaction } from '../../interfaces';
import {
IInventoryTransaction,
IManualJournal,
IExpense,
IExpenseCategory,
} from 'interfaces';
interface IInventoryCostEntity {
date: Date,
@@ -120,6 +123,36 @@ export default class JournalCommands{
this.journal.credit(creditEntry);
}
/**
* Writes journal entries of expense model object.
* @param {IExpense} expense
*/
expense(expense: IExpense) {
const mixinEntry = {
referenceType: 'Expense',
referenceId: expense.id,
date: expense.paymentDate,
userId: expense.userId,
draft: !expense.publishedAt,
};
const paymentJournalEntry = new JournalEntry({
credit: expense.totalAmount,
account: expense.paymentAccountId,
...mixinEntry,
});
this.journal.credit(paymentJournalEntry);
expense.categories.forEach((category: IExpenseCategory) => {
const expenseJournalEntry = new JournalEntry({
account: category.expenseAccountId,
debit: category.amount,
note: category.description,
...mixinEntry,
});
this.journal.debit(expenseJournalEntry);
});
}
/**
*
* @param {number|number[]} referenceId