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