WIP: Allocate landed cost.

This commit is contained in:
a.bouhuolia
2021-07-24 03:10:32 +02:00
parent 70aea9bf2d
commit cf2ebe9597
30 changed files with 602 additions and 218 deletions

View File

@@ -23,20 +23,20 @@ export default class BillSubscriber {
* Handles writing journal entries once bill created.
*/
@On(events.bill.onCreated)
async handlerWriteJournalEntriesOnCreate({ tenantId, bill }) {
async handlerWriteJournalEntriesOnCreate({ tenantId, billId }) {
// Writes the journal entries for the given bill transaction.
this.logger.info('[bill] writing bill journal entries.', { tenantId });
await this.billsService.recordJournalTransactions(tenantId, bill);
await this.billsService.recordJournalTransactions(tenantId, billId);
}
/**
* Handles the overwriting journal entries once bill edited.
*/
@On(events.bill.onEdited)
async handleOverwriteJournalEntriesOnEdit({ tenantId, bill }) {
async handleOverwriteJournalEntriesOnEdit({ tenantId, billId }) {
// Overwrite the journal entries for the given bill transaction.
this.logger.info('[bill] overwriting bill journal entries.', { tenantId });
await this.billsService.recordJournalTransactions(tenantId, bill, true);
await this.billsService.recordJournalTransactions(tenantId, billId, true);
}
/**

View File

@@ -0,0 +1,37 @@
import { Container } from 'typedi';
import { On, EventSubscriber } from 'event-dispatch';
import events from 'subscribers/events';
import TenancyService from 'services/Tenancy/TenancyService';
import BillsService from 'services/Purchases/Bills';
@EventSubscriber()
export default class BillLandedCostSubscriber {
logger: any;
tenancy: TenancyService;
billsService: BillsService;
/**
* Constructor method.
*/
constructor() {
this.logger = Container.get('logger');
this.tenancy = Container.get(TenancyService);
this.billsService = Container.get(BillsService);
}
/**
* Marks the rewrite bill journal entries once the landed cost transaction
* be deleted or created.
*/
@On(events.billLandedCost.onCreated)
@On(events.billLandedCost.onDeleted)
public async handleRewriteBillJournalEntries({
tenantId,
billId,
bilLandedCostId,
}) {
// Overwrite the journal entries for the given bill transaction.
this.logger.info('[bill] overwriting bill journal entries.', { tenantId });
await this.billsService.recordJournalTransactions(tenantId, billId, true);
}
}