diff --git a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheet.ts b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheet.ts index 8eab7581d..2fb7f2cf7 100644 --- a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheet.ts +++ b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheet.ts @@ -211,7 +211,7 @@ export class InventoryValuationSheet extends FinancialSheet { * Detarmines whether the items post filter is active. */ private isItemsPostFilter = (): boolean => { - return isEmpty(this.query.itemsIds); + return !isEmpty(this.query.itemsIds); }; /** diff --git a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheetService.ts b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheetService.ts index 059c6648d..560b77a8d 100644 --- a/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheetService.ts +++ b/packages/server/src/modules/FinancialStatements/modules/InventoryValuationSheet/InventoryValuationSheetService.ts @@ -18,7 +18,7 @@ export class InventoryValuationSheetService { private readonly inventoryValuationMeta: InventoryValuationMetaInjectable, private readonly eventPublisher: EventEmitter2, private readonly inventoryValuationSheetRepository: InventoryValuationSheetRepository, - ) {} + ) { } /** * Inventory valuation sheet. diff --git a/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.ts b/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.ts index 9110920fc..1cee9693a 100644 --- a/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.ts +++ b/packages/server/src/modules/FinancialStatements/modules/TrialBalanceSheet/TrialBalanceSheet.ts @@ -172,7 +172,10 @@ export class TrialBalanceSheet extends FinancialSheet { private filterNoneTransactions = ( accountNode: ITrialBalanceAccount ): boolean => { - return false === this.repository.totalAccountsLedger.isEmpty(); + const accountLedger = this.repository.totalAccountsLedger.whereAccountId( + accountNode.id, + ); + return !accountLedger.isEmpty(); }; /** diff --git a/packages/server/src/modules/InventoryCost/commands/InventoryComputeCost.service.ts b/packages/server/src/modules/InventoryCost/commands/InventoryComputeCost.service.ts index 9103e97a5..1865494a7 100644 --- a/packages/server/src/modules/InventoryCost/commands/InventoryComputeCost.service.ts +++ b/packages/server/src/modules/InventoryCost/commands/InventoryComputeCost.service.ts @@ -93,7 +93,7 @@ export class InventoryComputeCostService { */ async scheduleComputeItemCost(itemId: number, startingDate: Date | string) { const debounceKey = `inventory-cost-compute-debounce:${itemId}`; - const debounceTime = 1000 * 60; // 1 minute + const debounceTime = 1000 * 10; // 10 seconds // Generate a unique job ID or use a custom identifier const jobId = `task-${Date.now()}-${Math.random().toString(36).substring(2)}`; diff --git a/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts b/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts index 7bc9882c2..b6b7bb579 100644 --- a/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts +++ b/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts @@ -2,7 +2,8 @@ import { EventEmitter2 } from '@nestjs/event-emitter'; import { Processor, WorkerHost } from '@nestjs/bullmq'; import { Scope } from '@nestjs/common'; import { Job } from 'bullmq'; -import { ClsService } from 'nestjs-cls'; +import { ClsService, UseCls } from 'nestjs-cls'; +import * as moment from 'moment'; import { TenantJobPayload } from '@/interfaces/Tenant'; import { InventoryComputeCostService } from '../commands/InventoryComputeCost.service'; import { events } from '@/common/events/events'; @@ -14,7 +15,7 @@ import { Process } from '@nestjs/bull'; interface ComputeItemCostJobPayload extends TenantJobPayload { itemId: number; - startingDate: Date; + startingDate: Date | string; } @Processor({ name: ComputeItemCostQueue, @@ -39,28 +40,34 @@ export class ComputeItemCostProcessor extends WorkerHost { * @param {Job} job - The job to process */ @Process(ComputeItemCostQueueJob) + @UseCls() async process(job: Job) { const { itemId, startingDate, organizationId, userId } = job.data; - console.log(`Compute item cost for item ${itemId} started`); + // Parse startingDate using moment to handle both Date and string formats + const startingDateObj = moment(startingDate).toDate(); + console.log(`[info] Compute item cost for item ${itemId} started`, { + payload: job.data, + jobId: job.id + }); this.clsService.set('organizationId', organizationId); this.clsService.set('userId', userId); try { await this.inventoryComputeCostService.computeItemCost( - startingDate, + startingDateObj, itemId, ); // Emit job completed event await this.eventEmitter.emitAsync( events.inventory.onComputeItemCostJobCompleted, - { startingDate, itemId, organizationId, userId }, + { startingDate: startingDateObj, itemId, organizationId, userId }, ); - - console.log(`Compute item cost for item ${itemId} completed`); + console.log(`[info] Compute item cost for item ${itemId} completed successfully`); } catch (error) { - console.error('Error computing item cost:', error); + console.error(`[error] Error computing item cost for item ${itemId}:`, error); + console.error('Error stack:', error instanceof Error ? error.stack : 'No stack trace'); throw error; } } diff --git a/packages/server/src/modules/SaleInvoices/SaleInvoiceCostGLEntries.ts b/packages/server/src/modules/SaleInvoices/SaleInvoiceCostGLEntries.ts index a209e2290..78053973f 100644 --- a/packages/server/src/modules/SaleInvoices/SaleInvoiceCostGLEntries.ts +++ b/packages/server/src/modules/SaleInvoices/SaleInvoiceCostGLEntries.ts @@ -19,7 +19,7 @@ export class SaleInvoiceCostGLEntries { private readonly inventoryCostLotTracker: TenantModelProxy< typeof InventoryCostLotTracker >, - ) {} + ) { } /** * Writes journal entries from sales invoices. diff --git a/packages/server/src/modules/SaleInvoices/subscribers/InvoiceGLEntriesSubscriber.ts b/packages/server/src/modules/SaleInvoices/subscribers/InvoiceGLEntriesSubscriber.ts index 1917d1477..0c27afa51 100644 --- a/packages/server/src/modules/SaleInvoices/subscribers/InvoiceGLEntriesSubscriber.ts +++ b/packages/server/src/modules/SaleInvoices/subscribers/InvoiceGLEntriesSubscriber.ts @@ -10,7 +10,7 @@ import { events } from '@/common/events/events'; @Injectable() export class InvoiceGLEntriesSubscriber { - constructor(public readonly saleInvoiceGLEntries: SaleInvoiceGLEntries) {} + constructor(public readonly saleInvoiceGLEntries: SaleInvoiceGLEntries) { } /** * Records journal entries of the non-inventory invoice. diff --git a/packages/server/src/modules/TransactionsLocking/commands/CommandTransactionsLockingService.ts b/packages/server/src/modules/TransactionsLocking/commands/CommandTransactionsLockingService.ts index d5d43ef67..e70abb3b4 100644 --- a/packages/server/src/modules/TransactionsLocking/commands/CommandTransactionsLockingService.ts +++ b/packages/server/src/modules/TransactionsLocking/commands/CommandTransactionsLockingService.ts @@ -26,7 +26,7 @@ export class TransactionsLockingService { constructor( private readonly transactionsLockingRepo: TransactionsLockingRepository, private readonly eventPublisher: EventEmitter2, - ) {} + ) { } /** * Enable/disable all transacations locking. diff --git a/packages/webapp/src/components/Branches/BranchSelect.tsx b/packages/webapp/src/components/Branches/BranchSelect.tsx index 2641f2704..190c5122b 100644 --- a/packages/webapp/src/components/Branches/BranchSelect.tsx +++ b/packages/webapp/src/components/Branches/BranchSelect.tsx @@ -20,12 +20,3 @@ export function BranchSelect({ branches, ...rest }) { /> ); } - -/** - * - * @param {*} param0 - * @returns - */ -export function BranchSelectButton({ label, ...rest }) { - return