mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
refactor: manual journal.
This commit is contained in:
@@ -2,7 +2,7 @@ import { sumBy, chain } from 'lodash';
|
||||
import JournalPoster from "./JournalPoster";
|
||||
import JournalEntry from "./JournalEntry";
|
||||
import { AccountTransaction } from 'models';
|
||||
import { IInventoryTransaction } from 'interfaces';
|
||||
import { IInventoryTransaction, IManualJournal } from 'interfaces';
|
||||
import AccountsService from '../Accounts/AccountsService';
|
||||
import { IInventoryTransaction, IInventoryTransaction } from '../../interfaces';
|
||||
|
||||
@@ -120,6 +120,11 @@ export default class JournalCommands{
|
||||
this.journal.credit(creditEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number|number[]} referenceId
|
||||
* @param {string} referenceType
|
||||
*/
|
||||
async revertJournalEntries(
|
||||
referenceId: number|number[],
|
||||
referenceType: string
|
||||
@@ -135,6 +140,36 @@ export default class JournalCommands{
|
||||
this.journal.removeEntries();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Writes journal entries from manual journal model object.
|
||||
* @param {IManualJournal} manualJournalObj
|
||||
* @param {number} manualJournalId
|
||||
*/
|
||||
async manualJournal(manualJournalObj: IManualJournal, manualJournalId: number) {
|
||||
manualJournalObj.entries.forEach((entry) => {
|
||||
const jouranlEntry = new JournalEntry({
|
||||
debit: entry.debit,
|
||||
credit: entry.credit,
|
||||
account: entry.account,
|
||||
referenceType: 'Journal',
|
||||
referenceId: manualJournalId,
|
||||
contactType: entry.contactType,
|
||||
contactId: entry.contactId,
|
||||
note: entry.note,
|
||||
date: manualJournalObj.date,
|
||||
userId: manualJournalObj.userId,
|
||||
draft: !manualJournalObj.status,
|
||||
index: entry.index,
|
||||
});
|
||||
if (entry.debit) {
|
||||
this.journal.debit(jouranlEntry);
|
||||
} else {
|
||||
this.journal.credit(jouranlEntry);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and revert accounts balance journal entries that associated
|
||||
* to the given inventory transactions.
|
||||
|
||||
Reference in New Issue
Block a user