mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: writing inventory cost lot of opening item quantity transaction.
This commit is contained in:
@@ -10,7 +10,9 @@ export interface IInventoryTransaction {
|
|||||||
transactionType: string,
|
transactionType: string,
|
||||||
transactionId: number,
|
transactionId: number,
|
||||||
lotNumber: string,
|
lotNumber: string,
|
||||||
entryId: number
|
entryId: number,
|
||||||
|
createdAt?: Date,
|
||||||
|
updatedAt?: Date,
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IInventoryLotCost {
|
export interface IInventoryLotCost {
|
||||||
@@ -18,11 +20,12 @@ export interface IInventoryLotCost {
|
|||||||
date: Date,
|
date: Date,
|
||||||
direction: string,
|
direction: string,
|
||||||
itemId: number,
|
itemId: number,
|
||||||
|
quantity: number,
|
||||||
rate: number,
|
rate: number,
|
||||||
remaining: number,
|
remaining: number,
|
||||||
cost: number,
|
cost: number,
|
||||||
lotNumber: string|number,
|
lotNumber: string|number,
|
||||||
transactionType: string,
|
transactionType: string,
|
||||||
transactionId: string,
|
transactionId: number,
|
||||||
entryId: number
|
entryId: number
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
EventDispatcher,
|
EventDispatcher,
|
||||||
EventDispatcherInterface,
|
EventDispatcherInterface,
|
||||||
} from 'decorators/eventDispatcher';
|
} from 'decorators/eventDispatcher';
|
||||||
import { IInventoryTransaction, IItem, IItemEntry } from 'interfaces'
|
import { IInventoryLotCost, IInventoryTransaction, IItem, IItemEntry } from 'interfaces'
|
||||||
import InventoryAverageCost from 'services/Inventory/InventoryAverageCost';
|
import InventoryAverageCost from 'services/Inventory/InventoryAverageCost';
|
||||||
import InventoryCostLotTracker from 'services/Inventory/InventoryCostLotTracker';
|
import InventoryCostLotTracker from 'services/Inventory/InventoryCostLotTracker';
|
||||||
import TenancyService from 'services/Tenancy/TenancyService';
|
import TenancyService from 'services/Tenancy/TenancyService';
|
||||||
@@ -146,7 +146,7 @@ export default class InventoryService {
|
|||||||
tenantId: number,
|
tenantId: number,
|
||||||
inventoryEntry: IInventoryTransaction,
|
inventoryEntry: IInventoryTransaction,
|
||||||
deleteOld: boolean = false,
|
deleteOld: boolean = false,
|
||||||
) {
|
): Promise<IInventoryTransaction> {
|
||||||
const { InventoryTransaction, Item } = this.tenancy.models(tenantId);
|
const { InventoryTransaction, Item } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
if (deleteOld) {
|
if (deleteOld) {
|
||||||
@@ -156,7 +156,7 @@ export default class InventoryService {
|
|||||||
inventoryEntry.transactionType,
|
inventoryEntry.transactionType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await InventoryTransaction.query().insert({
|
return InventoryTransaction.query().insert({
|
||||||
...inventoryEntry,
|
...inventoryEntry,
|
||||||
lotNumber: inventoryEntry.lotNumber,
|
lotNumber: inventoryEntry.lotNumber,
|
||||||
});
|
});
|
||||||
@@ -182,6 +182,23 @@ export default class InventoryService {
|
|||||||
.delete();
|
.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records the inventory cost lot transaction.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IInventoryLotCost} inventoryLotEntry
|
||||||
|
* @return {Promise<IInventoryLotCost>}
|
||||||
|
*/
|
||||||
|
async recordInventoryCostLotTransaction(
|
||||||
|
tenantId: number,
|
||||||
|
inventoryLotEntry: IInventoryLotCost,
|
||||||
|
): Promise<void> {
|
||||||
|
const { InventoryCostLotTracker } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
|
return InventoryCostLotTracker.query().insert({
|
||||||
|
...inventoryLotEntry,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the lot number after the increment.
|
* Retrieve the lot number after the increment.
|
||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { defaultTo, difference } from 'lodash';
|
import { defaultTo, difference, omit } from 'lodash';
|
||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import {
|
import {
|
||||||
EventDispatcher,
|
EventDispatcher,
|
||||||
@@ -283,11 +283,11 @@ export default class ItemsService implements IItemsService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Records the opening items inventory transaction.
|
* Records the opening items inventory transaction.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId -
|
||||||
* @param itemId
|
* @param itemId -
|
||||||
* @param openingQuantity
|
* @param openingQuantity -
|
||||||
* @param openingCost
|
* @param openingCost -
|
||||||
* @param openingDate
|
* @param openingDate -
|
||||||
*/
|
*/
|
||||||
public async recordOpeningItemsInventoryTransaction(
|
public async recordOpeningItemsInventoryTransaction(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
@@ -299,7 +299,10 @@ export default class ItemsService implements IItemsService {
|
|||||||
// Gets the next inventory lot number.
|
// Gets the next inventory lot number.
|
||||||
const lotNumber = this.inventoryService.getNextLotNumber(tenantId);
|
const lotNumber = this.inventoryService.getNextLotNumber(tenantId);
|
||||||
|
|
||||||
await this.inventoryService.recordInventoryTransaction(tenantId, {
|
// Records the inventory transaction.
|
||||||
|
const inventoryTransaction = await this.inventoryService.recordInventoryTransaction(
|
||||||
|
tenantId,
|
||||||
|
{
|
||||||
date: openingDate,
|
date: openingDate,
|
||||||
quantity: openingQuantity,
|
quantity: openingQuantity,
|
||||||
rate: openingCost,
|
rate: openingCost,
|
||||||
@@ -307,6 +310,13 @@ export default class ItemsService implements IItemsService {
|
|||||||
transactionType: 'OpeningItem',
|
transactionType: 'OpeningItem',
|
||||||
itemId,
|
itemId,
|
||||||
lotNumber,
|
lotNumber,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// Records the inventory cost lot transaction.
|
||||||
|
await this.inventoryService.recordInventoryCostLotTransaction(tenantId, {
|
||||||
|
...omit(inventoryTransaction, ['updatedAt', 'createdAt']),
|
||||||
|
cost: openingQuantity * openingCost,
|
||||||
|
remaining: 0,
|
||||||
});
|
});
|
||||||
await this.inventoryService.incrementNextLotNumber(tenantId);
|
await this.inventoryService.incrementNextLotNumber(tenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user