mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
refactor: warehouse transfers
This commit is contained in:
@@ -4,18 +4,18 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||||||
import { InventoryTransaction } from '../models/InventoryTransaction';
|
import { InventoryTransaction } from '../models/InventoryTransaction';
|
||||||
import { InventoryCostLotTracker } from '../models/InventoryCostLotTracker';
|
import { InventoryCostLotTracker } from '../models/InventoryCostLotTracker';
|
||||||
import { Item } from '../../Items/models/Item';
|
import { Item } from '../../Items/models/Item';
|
||||||
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InventoryItemCostService {
|
export class InventoryItemCostService {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(InventoryTransaction.name)
|
|
||||||
private readonly inventoryTransactionModel: typeof InventoryTransaction,
|
|
||||||
|
|
||||||
@Inject(InventoryCostLotTracker.name)
|
@Inject(InventoryCostLotTracker.name)
|
||||||
private readonly inventoryCostLotTrackerModel: typeof InventoryCostLotTracker,
|
private readonly inventoryCostLotTrackerModel: TenantModelProxy<
|
||||||
|
typeof InventoryCostLotTracker
|
||||||
|
>,
|
||||||
|
|
||||||
@Inject(Item.name)
|
@Inject(Item.name)
|
||||||
private readonly itemModel: typeof Item,
|
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,12 +64,12 @@ export class InventoryItemCostService {
|
|||||||
builder.groupBy('item_id');
|
builder.groupBy('item_id');
|
||||||
builder.select(['item_id']);
|
builder.select(['item_id']);
|
||||||
};
|
};
|
||||||
const INValuationOper = this.inventoryCostLotTrackerModel
|
const INValuationOper = this.inventoryCostLotTrackerModel()
|
||||||
.query()
|
.query()
|
||||||
.onBuild(commonBuilder)
|
.onBuild(commonBuilder)
|
||||||
.where('direction', 'IN');
|
.where('direction', 'IN');
|
||||||
|
|
||||||
const OUTValuationOper = this.inventoryCostLotTrackerModel
|
const OUTValuationOper = this.inventoryCostLotTrackerModel()
|
||||||
.query()
|
.query()
|
||||||
.onBuild(commonBuilder)
|
.onBuild(commonBuilder)
|
||||||
.where('direction', 'OUT');
|
.where('direction', 'OUT');
|
||||||
@@ -104,7 +104,7 @@ export class InventoryItemCostService {
|
|||||||
date: Date,
|
date: Date,
|
||||||
): Promise<Map<number, IInventoryItemCostMeta>> => {
|
): Promise<Map<number, IInventoryItemCostMeta>> => {
|
||||||
// Retrieves the inventory items.
|
// Retrieves the inventory items.
|
||||||
const items = await this.itemModel
|
const items = await this.itemModel()
|
||||||
.query()
|
.query()
|
||||||
.whereIn('id', itemsId)
|
.whereIn('id', itemsId)
|
||||||
.where('type', 'inventory');
|
.where('type', 'inventory');
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import { TenantModelProxy } from '../../System/models/TenantBaseModel';
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InventoryItemsQuantitySyncService {
|
export class InventoryItemsQuantitySyncService {
|
||||||
|
/**
|
||||||
|
* @param {TenantModelProxy<typeof Item>} itemModel - Item model.
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(Item.name)
|
@Inject(Item.name)
|
||||||
private readonly itemModel: TenantModelProxy<typeof Item>,
|
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||||
|
|||||||
@@ -15,14 +15,23 @@ import { IItemEntryTransactionType } from '../../TransactionItemEntry/ItemEntry.
|
|||||||
import { ItemEntry } from '../../TransactionItemEntry/models/ItemEntry';
|
import { ItemEntry } from '../../TransactionItemEntry/models/ItemEntry';
|
||||||
|
|
||||||
export class InventoryTransactionsService {
|
export class InventoryTransactionsService {
|
||||||
|
/**
|
||||||
|
* @param {EventEmitter2} eventEmitter - Event emitter.
|
||||||
|
* @param {TenantModelProxy<typeof InventoryTransaction>} inventoryTransactionModel - Inventory transaction model.
|
||||||
|
* @param {TenantModelProxy<typeof InventoryCostLotTracker>} inventoryCostLotTracker - Inventory cost lot tracker model.
|
||||||
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private readonly eventEmitter: EventEmitter2,
|
private readonly eventEmitter: EventEmitter2,
|
||||||
|
|
||||||
@Inject(InventoryTransaction.name)
|
@Inject(InventoryTransaction.name)
|
||||||
private readonly inventoryTransactionModel: typeof InventoryTransaction,
|
private readonly inventoryTransactionModel: TenantModelProxy<
|
||||||
|
typeof InventoryTransaction
|
||||||
|
>,
|
||||||
|
|
||||||
@Inject(InventoryCostLotTracker.name)
|
@Inject(InventoryCostLotTracker.name)
|
||||||
private readonly inventoryCostLotTracker: typeof InventoryCostLotTracker,
|
private readonly inventoryCostLotTracker: TenantModelProxy<
|
||||||
|
typeof InventoryCostLotTracker
|
||||||
|
>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,9 +84,11 @@ export class InventoryTransactionsService {
|
|||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this.inventoryTransactionModel.query(trx).insertGraph({
|
return this.inventoryTransactionModel()
|
||||||
...inventoryEntry,
|
.query(trx)
|
||||||
});
|
.insertGraph({
|
||||||
|
...inventoryEntry,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,7 +148,7 @@ export class InventoryTransactionsService {
|
|||||||
.where({ transactionId, transactionType });
|
.where({ transactionId, transactionType });
|
||||||
|
|
||||||
// Deletes the inventory transactions by the given transaction type and id.
|
// Deletes the inventory transactions by the given transaction type and id.
|
||||||
await this.inventoryTransactionModel
|
await this.inventoryTransactionModel()
|
||||||
.query(trx)
|
.query(trx)
|
||||||
.where({ transactionType, transactionId })
|
.where({ transactionType, transactionId })
|
||||||
.delete();
|
.delete();
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ export class Item extends TenantBaseModel {
|
|||||||
// const WarehouseTransferEntry = require('../../Warehouses/');
|
// const WarehouseTransferEntry = require('../../Warehouses/');
|
||||||
const {
|
const {
|
||||||
InventoryAdjustmentEntry,
|
InventoryAdjustmentEntry,
|
||||||
} = require('../../InventoryAdjutments/models/InventoryAdjustment');
|
} = require('../../InventoryAdjutments/models/InventoryAdjustmentEntry');
|
||||||
const { TaxRate } = require('../../TaxRates/models/TaxRate.model');
|
const { TaxRateModel } = require('../../TaxRates/models/TaxRate.model');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
@@ -171,7 +171,7 @@ export class Item extends TenantBaseModel {
|
|||||||
*/
|
*/
|
||||||
sellTaxRate: {
|
sellTaxRate: {
|
||||||
relation: Model.BelongsToOneRelation,
|
relation: Model.BelongsToOneRelation,
|
||||||
modelClass: TaxRate,
|
modelClass: TaxRateModel,
|
||||||
join: {
|
join: {
|
||||||
from: 'items.sellTaxRateId',
|
from: 'items.sellTaxRateId',
|
||||||
to: 'tax_rates.id',
|
to: 'tax_rates.id',
|
||||||
@@ -183,7 +183,7 @@ export class Item extends TenantBaseModel {
|
|||||||
*/
|
*/
|
||||||
purchaseTaxRate: {
|
purchaseTaxRate: {
|
||||||
relation: Model.BelongsToOneRelation,
|
relation: Model.BelongsToOneRelation,
|
||||||
modelClass: TaxRate,
|
modelClass: TaxRateModel,
|
||||||
join: {
|
join: {
|
||||||
from: 'items.purchaseTaxRateId',
|
from: 'items.purchaseTaxRateId',
|
||||||
to: 'tax_rates.id',
|
to: 'tax_rates.id',
|
||||||
|
|||||||
@@ -28,9 +28,8 @@ export class WarehouseTransferApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a warehouse transfer transaction.
|
* Creates a warehouse transfer transaction.
|
||||||
* @param {number} tenantId
|
* @param {ICreateWarehouseTransferDTO} createWarehouseTransferDTO
|
||||||
* @param {ICreateWarehouseTransferDTO} createWarehouseTransferDTO
|
* @returns {Promise<ModelObject<WarehouseTransfer>>}
|
||||||
* @returns {}
|
|
||||||
*/
|
*/
|
||||||
public createWarehouseTransfer = (
|
public createWarehouseTransfer = (
|
||||||
createWarehouseTransferDTO: ICreateWarehouseTransferDTO,
|
createWarehouseTransferDTO: ICreateWarehouseTransferDTO,
|
||||||
@@ -42,7 +41,6 @@ export class WarehouseTransferApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits warehouse transfer transaction.
|
* Edits warehouse transfer transaction.
|
||||||
* @param {number} tenantId -
|
|
||||||
* @param {number} warehouseTransferId - number
|
* @param {number} warehouseTransferId - number
|
||||||
* @param {IEditWarehouseTransferDTO} editWarehouseTransferDTO
|
* @param {IEditWarehouseTransferDTO} editWarehouseTransferDTO
|
||||||
*/
|
*/
|
||||||
@@ -108,8 +106,8 @@ export class WarehouseTransferApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the warehouse transfer order as initiated.
|
* Marks the warehouse transfer order as initiated.
|
||||||
* @param {number} warehouseTransferId
|
* @param {number} warehouseTransferId
|
||||||
* @returns {Promise<IWarehouseTransfer>}
|
* @returns {Promise<ModelObject<WarehouseTransfer>>}
|
||||||
*/
|
*/
|
||||||
public initiateWarehouseTransfer = (
|
public initiateWarehouseTransfer = (
|
||||||
warehouseTransferId: number,
|
warehouseTransferId: number,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { WarehouseTransferTransformer } from './WarehouseTransferTransfomer';
|
import { WarehouseTransferTransformer } from './WarehouseTransferTransfomer';
|
||||||
import { IGetWarehousesTransfersFilterDTO } from '../../Warehouses/Warehouse.types';
|
import { IGetWarehousesTransfersFilterDTO } from '../../Warehouses/Warehouse.types';
|
||||||
import { TransformerInjectable } from '../../Transformer/TransformerInjectable.service';
|
import { TransformerInjectable } from '../../Transformer/TransformerInjectable.service';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
|
||||||
import { DynamicListService } from '../../DynamicListing/DynamicList.service';
|
import { DynamicListService } from '../../DynamicListing/DynamicList.service';
|
||||||
import { TenantModelProxy } from '../../System/models/TenantBaseModel';
|
import { TenantModelProxy } from '../../System/models/TenantBaseModel';
|
||||||
import { WarehouseTransfer } from '../models/WarehouseTransfer';
|
import { WarehouseTransfer } from '../models/WarehouseTransfer';
|
||||||
|
|||||||
Reference in New Issue
Block a user