Rename writeInvoicesJEntries.ts to WriteInvoicesJEntries.ts

This commit is contained in:
Ahmed Bouhuolia
2023-06-19 23:00:22 +02:00
committed by GitHub
parent ab5f9f50d0
commit a44d779670

View File

@@ -0,0 +1,50 @@
import { Container } from 'typedi';
import events from '@/subscribers/events';
import SalesInvoicesCost from '@/services/Sales/SalesInvoicesCost';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
export default class WriteInvoicesJournalEntries {
eventPublisher: EventPublisher;
/**
* Constructor method.
*/
constructor(agenda) {
const eventName = 'rewrite-invoices-journal-entries';
this.eventPublisher = Container.get(EventPublisher);
agenda.define(
eventName,
{ priority: 'normal', concurrency: 1 },
this.handler.bind(this)
);
agenda.on(`complete:${eventName}`, this.onJobCompleted.bind(this));
}
/**
* Handle the job execuation.
*/
public async handler(job, done: Function): Promise<void> {
const { startingDate, tenantId } = job.attrs.data;
const salesInvoicesCost = Container.get(SalesInvoicesCost);
try {
await salesInvoicesCost.writeCostLotsGLEntries(tenantId, startingDate);
done();
} catch (e) {
done(e);
}
}
/**
* Handle the job complete.
*/
async onJobCompleted(job) {
const { startingDate, itemId, tenantId } = job.attrs.data;
await this.eventPublisher.emitAsync(
events.inventory.onInventoryCostEntriesWritten,
{ startingDate, itemId, tenantId }
);
}
}