feat: Schedule to compute items cost.

This commit is contained in:
Ahmed Bouhuolia
2020-08-19 01:30:12 +02:00
parent 52d01b4ed8
commit c2a60e6ba5
4 changed files with 175 additions and 175 deletions

View File

@@ -1,3 +1,4 @@
import { Container } from 'typedi';
import {
InventoryTransaction,
Item,
@@ -5,7 +6,6 @@ import {
} from '@/models';
import InventoryAverageCost from '@/services/Inventory/InventoryAverageCost';
import InventoryCostLotTracker from '@/services/Inventory/InventoryCostLotTracker';
import { option } from 'commander';
type TCostMethod = 'FIFO' | 'LIFO' | 'AVG';
@@ -33,6 +33,23 @@ export default class InventoryService {
await costMethodComputer.computeItemCost()
}
/**
* SChedule item cost compute job.
* @param {number} itemId
* @param {Date} startingDate
*/
static async scheduleComputeItemCost(itemId: number, startingDate: Date|string) {
const agenda = Container.get('agenda');
// Delete the scheduled job in case has the same given data.
await agenda.cancel({
name: 'compute-item-cost',
});
return agenda.schedule('in 3 seconds', 'compute-item-cost', {
startingDate, itemId,
});
}
/**
* Records the inventory transactions.
* @param {Bill} bill
@@ -89,10 +106,6 @@ export default class InventoryService {
.delete();
}
revertInventoryLotsCost(fromDate?: Date) {
}
/**
* Retrieve the lot number after the increment.
*/
@@ -102,7 +115,7 @@ export default class InventoryService {
.where('key', LOT_NUMBER_KEY)
.increment('value', 1);
if (effectRows) {
if (effectRows === 0) {
await Option.tenant().query()
.insert({
key: LOT_NUMBER_KEY,