mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: add opening quantity, cost and date to items.
This commit is contained in:
@@ -168,7 +168,7 @@ export default {
|
||||
/**
|
||||
* Items service.
|
||||
*/
|
||||
items: {
|
||||
item: {
|
||||
onCreated: 'onItemCreated',
|
||||
onEdited: 'onItemEdited',
|
||||
onDeleted: 'onItemDeleted',
|
||||
|
||||
32
server/src/subscribers/items.ts
Normal file
32
server/src/subscribers/items.ts
Normal 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,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user