feat: add opening quantity, cost and date to items.

This commit is contained in:
a.bouhuolia
2020-12-23 21:31:17 +02:00
parent b07bb2df53
commit 47b40f6940
9 changed files with 146 additions and 18 deletions

View File

@@ -168,7 +168,7 @@ export default {
/**
* Items service.
*/
items: {
item: {
onCreated: 'onItemCreated',
onEdited: 'onItemEdited',
onDeleted: 'onItemDeleted',

View File

@@ -0,0 +1,32 @@
import { Container } from 'typedi';
import { EventSubscriber, On } from 'event-dispatch';
import events from 'subscribers/events';
import ItemsService from 'services/Items/ItemsService';
@EventSubscriber()
export default class ItemsSubscriber{
itemsService: ItemsService;
constructor() {
this.itemsService = Container.get(ItemsService);
};
/**
* Handle writing opening item inventory transaction.
*/
@On(events.item.onCreated)
handleWriteOpeningInventoryTransaction({ tenantId, item }) {
// Can't continue if the opeing cost, quantity or opening date was empty.
if (!item.openingCost || !item.openingQuantity || !item.openingDate) {
return;
}
// Records the opeing items inventory transaction once the item created.
this.itemsService.recordOpeningItemsInventoryTransaction(
tenantId,
item.id,
item.openingQuantity,
item.openingCost,
item.openingDate,
)
}
}