refactor: branches and warehouses modules

This commit is contained in:
Ahmed Bouhuolia
2025-02-26 14:19:47 +02:00
parent 95bb4fc8e3
commit b7d0b6c24a
105 changed files with 2939 additions and 3361 deletions

View File

@@ -1,30 +1,34 @@
// import { Service, Inject } from 'typedi';
// import { IWarehouse } from '@/interfaces';
// import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Injectable } from '@nestjs/common';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
import { ItemEntry } from '@/modules/TransactionItemEntry/models/ItemEntry';
import { Warehouse } from '../models/Warehouse.model';
import { SaleReceipt } from '@/modules/SaleReceipts/models/SaleReceipt';
// @Service()
// export class ReceiptActivateWarehouses {
// @Inject()
// tenancy: HasTenancyService;
@Injectable()
export class ReceiptActivateWarehouses {
constructor(
private readonly saleReceiptModel: TenantModelProxy<typeof SaleReceipt>,
private readonly itemEntryModel: TenantModelProxy<typeof ItemEntry>,
) {}
// /**
// * Updates all sale receipts transactions with the primary warehouse.
// * @param {number} tenantId
// * @param {number} primaryWarehouse
// * @returns {Promise<void>}
// */
// public updateReceiptsWithWarehouse = async (
// tenantId: number,
// primaryWarehouse: IWarehouse
// ): Promise<void> => {
// const { SaleReceipt, ItemEntry } = this.tenancy.models(tenantId);
// // Updates the vendor credits transactions with primary warehouse.
// await SaleReceipt.query().update({ warehouseId: primaryWarehouse.id });
// // Update the sale invoices entries with primary warehouse.
// await ItemEntry.query().where('referenceType', 'SaleReceipt').update({
// warehouseId: primaryWarehouse.id,
// });
// };
// }
/**
* Updates all sale receipts transactions with the primary warehouse.
* @param {Warehouse} primaryWarehouse
* @returns {Promise<void>}
*/
public updateReceiptsWithWarehouse = async (
primaryWarehouse: Warehouse,
): Promise<void> => {
// Updates the vendor credits transactions with primary warehouse.
await this.saleReceiptModel().query().update({
warehouseId: primaryWarehouse.id,
});
// Update the sale invoices entries with primary warehouse.
await this.itemEntryModel()
.query()
.where('referenceType', 'SaleReceipt')
.update({
warehouseId: primaryWarehouse.id,
});
};
}