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

@@ -127,20 +127,38 @@ export default class InventoryService {
inventoryEntries: IInventoryTransaction[],
deleteOld: boolean,
): Promise<void> {
inventoryEntries.forEach(async (entry: IInventoryTransaction) => {
await this.recordInventoryTransaction(
tenantId,
entry,
deleteOld,
);
});
}
/**
*
* @param {number} tenantId
* @param {IInventoryTransaction} inventoryEntry
* @param {boolean} deleteOld
*/
async recordInventoryTransaction(
tenantId: number,
inventoryEntry: IInventoryTransaction,
deleteOld: boolean = false,
) {
const { InventoryTransaction, Item } = this.tenancy.models(tenantId);
inventoryEntries.forEach(async (entry: any) => {
if (deleteOld) {
await this.deleteInventoryTransactions(
tenantId,
entry.transactionId,
entry.transactionType,
);
}
await InventoryTransaction.query().insert({
...entry,
lotNumber: entry.lotNumber,
});
if (deleteOld) {
await this.deleteInventoryTransactions(
tenantId,
inventoryEntry.transactionId,
inventoryEntry.transactionType,
);
}
await InventoryTransaction.query().insert({
...inventoryEntry,
lotNumber: inventoryEntry.lotNumber,
});
}