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,90 +1,82 @@
// import { Inject, Service } from 'typedi';
// import { Knex } from 'knex';
// import { ICreditNote } from '@/interfaces';
// import InventoryService from '@/services/Inventory/Inventory';
// import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
import { Injectable } from '@nestjs/common';
// @Service()
// export default class CreditNoteInventoryTransactions {
// @Inject()
// inventoryService: InventoryService;
import { InventoryService } from '@/modules/InventoryCost/Inventory';
import { ItemsEntriesService } from '@/modules/Items/ItemsEntries.service';
import { CreditNote } from '../models/CreditNote';
import { Knex } from 'knex';
@Injectable()
export class CreditNoteInventoryTransactions {
constructor(
private readonly inventoryService: InventoryService,
private readonly itemsEntriesService: ItemsEntriesService,
) {}
// @Inject()
// itemsEntriesService: ItemsEntriesService;
/**
* Creates credit note inventory transactions.
* @param {number} tenantId
* @param {ICreditNote} creditNote
*/
public createInventoryTransactions = async (
creditNote: CreditNote,
trx?: Knex.Transaction,
): Promise<void> => {
// Loads the inventory items entries of the given sale invoice.
const inventoryEntries =
await this.itemsEntriesService.filterInventoryEntries(creditNote.entries);
// /**
// * Creates credit note inventory transactions.
// * @param {number} tenantId
// * @param {ICreditNote} creditNote
// */
// public createInventoryTransactions = async (
// tenantId: number,
// creditNote: ICreditNote,
// trx?: Knex.Transaction
// ): Promise<void> => {
// // Loads the inventory items entries of the given sale invoice.
// const inventoryEntries =
// await this.itemsEntriesService.filterInventoryEntries(
// tenantId,
// creditNote.entries
// );
// const transaction = {
// transactionId: creditNote.id,
// transactionType: 'CreditNote',
// transactionNumber: creditNote.creditNoteNumber,
// exchangeRate: creditNote.exchangeRate,
// date: creditNote.creditNoteDate,
// direction: 'IN',
// entries: inventoryEntries,
// createdAt: creditNote.createdAt,
// warehouseId: creditNote.warehouseId,
// };
// // Writes inventory tranactions.
// await this.inventoryService.recordInventoryTransactionsFromItemsEntries(
// tenantId,
// transaction,
// false,
// trx
// );
// };
const transaction = {
transactionId: creditNote.id,
transactionType: 'CreditNote',
transactionNumber: creditNote.creditNoteNumber,
exchangeRate: creditNote.exchangeRate,
date: creditNote.creditNoteDate,
direction: 'IN',
entries: inventoryEntries,
createdAt: creditNote.createdAt,
warehouseId: creditNote.warehouseId,
};
// Writes inventory tranactions.
await this.inventoryService.recordInventoryTransactionsFromItemsEntries(
transaction,
false,
trx,
);
};
// /**
// * Edits vendor credit associated inventory transactions.
// * @param {number} tenantId
// * @param {number} creditNoteId
// * @param {ICreditNote} creditNote
// * @param {Knex.Transactions} trx
// */
// public editInventoryTransactions = async (
// tenantId: number,
// creditNoteId: number,
// creditNote: ICreditNote,
// trx?: Knex.Transaction
// ): Promise<void> => {
// // Deletes inventory transactions.
// await this.deleteInventoryTransactions(tenantId, creditNoteId, trx);
/**
* Edits vendor credit associated inventory transactions.
* @param {number} tenantId
* @param {number} creditNoteId
* @param {ICreditNote} creditNote
* @param {Knex.Transactions} trx
*/
public editInventoryTransactions = async (
creditNoteId: number,
creditNote: CreditNote,
trx?: Knex.Transaction,
): Promise<void> => {
// Deletes inventory transactions.
await this.deleteInventoryTransactions(creditNoteId, trx);
// // Re-write inventory transactions.
// await this.createInventoryTransactions(tenantId, creditNote, trx);
// };
// Re-write inventory transactions.
await this.createInventoryTransactions(creditNote, trx);
};
// /**
// * Deletes credit note associated inventory transactions.
// * @param {number} tenantId - Tenant id.
// * @param {number} creditNoteId - Credit note id.
// * @param {Knex.Transaction} trx -
// */
// public deleteInventoryTransactions = async (
// tenantId: number,
// creditNoteId: number,
// trx?: Knex.Transaction
// ): Promise<void> => {
// // Deletes the inventory transactions by the given reference id and type.
// await this.inventoryService.deleteInventoryTransactions(
// tenantId,
// creditNoteId,
// 'CreditNote',
// trx
// );
// };
// }
/**
* Deletes credit note associated inventory transactions.
* @param {number} tenantId - Tenant id.
* @param {number} creditNoteId - Credit note id.
* @param {Knex.Transaction} trx -
*/
public deleteInventoryTransactions = async (
creditNoteId: number,
trx?: Knex.Transaction,
): Promise<void> => {
// Deletes the inventory transactions by the given reference id and type.
await this.inventoryService.deleteInventoryTransactions(
creditNoteId,
'CreditNote',
trx,
);
};
}