refactor: dynamic list to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-12 18:22:48 +02:00
parent ddaea20d16
commit 270b421a6c
117 changed files with 4232 additions and 1493 deletions

View File

@@ -1,82 +1,73 @@
// import { Knex } from 'knex';
// import { Inject, Service } from 'typedi';
// import InventoryService from '@/services/Inventory/Inventory';
// import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Knex } from 'knex';
import { Bill } from '../models/Bill';
import { Injectable } from '@nestjs/common';
import { ItemsEntriesService } from '@/modules/Items/ItemsEntries.service';
import { InventoryService } from '@/modules/InventoryCost/Inventory';
// @Service()
// export class BillInventoryTransactions {
// @Inject()
// private tenancy: HasTenancyService;
@Injectable()
export class BillInventoryTransactions {
constructor(
private readonly itemsEntriesService: ItemsEntriesService,
private readonly inventoryService: InventoryService,
// @Inject()
// private itemsEntriesService: ItemsEntriesService;
private readonly bill: typeof Bill
) {}
// @Inject()
// private inventoryService: InventoryService;
/**
* Records the inventory transactions from the given bill input.
* @param {number} billId - Bill id.
* @return {Promise<void>}
*/
public async recordInventoryTransactions(
billId: number,
override?: boolean,
trx?: Knex.Transaction
): Promise<void> {
// Retireve bill with assocaited entries and allocated cost entries.
const bill = await this.bill.query(trx)
.findById(billId)
.withGraphFetched('entries.allocatedCostEntries');
// /**
// * Records the inventory transactions from the given bill input.
// * @param {Bill} bill - Bill model object.
// * @param {number} billId - Bill id.
// * @return {Promise<void>}
// */
// public async recordInventoryTransactions(
// tenantId: number,
// billId: number,
// override?: boolean,
// trx?: Knex.Transaction
// ): Promise<void> {
// const { Bill } = this.tenancy.models(tenantId);
// Loads the inventory items entries of the given sale invoice.
const inventoryEntries =
await this.itemsEntriesService.filterInventoryEntries(
bill.entries
);
const transaction = {
transactionId: bill.id,
transactionType: 'Bill',
exchangeRate: bill.exchangeRate,
// // Retireve bill with assocaited entries and allocated cost entries.
// const bill = await Bill.query(trx)
// .findById(billId)
// .withGraphFetched('entries.allocatedCostEntries');
date: bill.billDate,
direction: 'IN',
entries: inventoryEntries,
createdAt: bill.createdAt,
// // Loads the inventory items entries of the given sale invoice.
// const inventoryEntries =
// await this.itemsEntriesService.filterInventoryEntries(
// tenantId,
// bill.entries
// );
// const transaction = {
// transactionId: bill.id,
// transactionType: 'Bill',
// exchangeRate: bill.exchangeRate,
warehouseId: bill.warehouseId,
};
await this.inventoryService.recordInventoryTransactionsFromItemsEntries(
transaction,
override,
trx
);
}
// date: bill.billDate,
// direction: 'IN',
// entries: inventoryEntries,
// createdAt: bill.createdAt,
// warehouseId: bill.warehouseId,
// };
// await this.inventoryService.recordInventoryTransactionsFromItemsEntries(
// tenantId,
// transaction,
// override,
// trx
// );
// }
// /**
// * Reverts the inventory transactions of the given bill id.
// * @param {number} tenantId - Tenant id.
// * @param {number} billId - Bill id.
// * @return {Promise<void>}
// */
// public async revertInventoryTransactions(
// tenantId: number,
// billId: number,
// trx?: Knex.Transaction
// ) {
// // Deletes the inventory transactions by the given reference id and type.
// await this.inventoryService.deleteInventoryTransactions(
// tenantId,
// billId,
// 'Bill',
// trx
// );
// }
// }
/**
* Reverts the inventory transactions of the given bill id.
* @param {number} tenantId - Tenant id.
* @param {number} billId - Bill id.
* @return {Promise<void>}
*/
public async revertInventoryTransactions(
billId: number,
trx?: Knex.Transaction
) {
// Deletes the inventory transactions by the given reference id and type.
await this.inventoryService.deleteInventoryTransactions(
billId,
'Bill',
trx
);
}
}