feat(FinancialReports): compute journal cost is running state.

This commit is contained in:
a.bouhuolia
2021-03-13 19:49:15 +02:00
parent 828f4bb32e
commit 88eaaa3968
27 changed files with 411 additions and 106 deletions

View File

@@ -1,8 +1,5 @@
import { Container } from 'typedi';
import {EventDispatcher} from "event-dispatch";
// import {
// EventDispatcher,
// } from 'decorators/eventDispatcher';
import events from 'subscribers/events';
import InventoryService from 'services/Inventory/Inventory';
@@ -11,7 +8,7 @@ export default class ComputeItemCostJob {
eventDispatcher: EventDispatcher;
/**
*
* Constructor method.
* @param agenda
*/
constructor(agenda) {

View File

@@ -1,13 +1,24 @@
import { Container } from 'typedi';
import {EventDispatcher} from "event-dispatch";
import events from 'subscribers/events';
import SalesInvoicesCost from 'services/Sales/SalesInvoicesCost';
export default class WriteInvoicesJournalEntries {
eventDispatcher: EventDispatcher;
/**
* Constructor method.
*/
constructor(agenda) {
const eventName = 'rewrite-invoices-journal-entries';
this.eventDispatcher = new EventDispatcher();
agenda.define(
'rewrite-invoices-journal-entries',
eventName,
{ priority: 'normal', concurrency: 1 },
this.handler.bind(this)
);
agenda.on(`complete:${eventName}`, this.onJobCompleted.bind(this));
}
public async handler(job, done: Function): Promise<void> {
@@ -36,4 +47,16 @@ export default class WriteInvoicesJournalEntries {
done(e);
}
}
/**
* Handle the job complete.
*/
async onJobCompleted(job) {
const { startingDate, itemId, tenantId } = job.attrs.data;
await this.eventDispatcher.dispatch(
events.inventory.onInventoryCostEntriesWritten,
{ startingDate, itemId, tenantId }
);
}
}