diff --git a/packages/server/src/modules/FinancialStatements/common/FinancialSheetCommon.module.ts b/packages/server/src/modules/FinancialStatements/common/FinancialSheetCommon.module.ts index fbca79cdd..7a2b24250 100644 --- a/packages/server/src/modules/FinancialStatements/common/FinancialSheetCommon.module.ts +++ b/packages/server/src/modules/FinancialStatements/common/FinancialSheetCommon.module.ts @@ -4,14 +4,15 @@ import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service'; import { TableSheetPdf } from './TableSheetPdf'; import { TemplateInjectableModule } from '@/modules/TemplateInjectable/TemplateInjectable.module'; import { ChromiumlyTenancyModule } from '@/modules/ChromiumlyTenancy/ChromiumlyTenancy.module'; +import { InventoryCostModule } from '@/modules/InventoryCost/InventoryCost.module'; @Module({ - imports: [TemplateInjectableModule, ChromiumlyTenancyModule], - providers: [ - FinancialSheetMeta, - TenancyContext, - TableSheetPdf, + imports: [ + TemplateInjectableModule, + ChromiumlyTenancyModule, + InventoryCostModule, ], + providers: [FinancialSheetMeta, TenancyContext, TableSheetPdf], exports: [FinancialSheetMeta, TableSheetPdf], }) export class FinancialSheetCommonModule {} diff --git a/packages/server/src/modules/FinancialStatements/common/FinancialSheetMeta.ts b/packages/server/src/modules/FinancialStatements/common/FinancialSheetMeta.ts index f4dac4f7c..079a3210e 100644 --- a/packages/server/src/modules/FinancialStatements/common/FinancialSheetMeta.ts +++ b/packages/server/src/modules/FinancialStatements/common/FinancialSheetMeta.ts @@ -1,10 +1,14 @@ import { Injectable } from '@nestjs/common'; import { IFinancialSheetCommonMeta } from '../types/Report.types'; import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service'; +import { InventoryComputeCostService } from '@/modules/InventoryCost/commands/InventoryComputeCost.service'; @Injectable() export class FinancialSheetMeta { - constructor(private readonly tenancyContext: TenancyContext) {} + constructor( + private readonly tenancyContext: TenancyContext, + private readonly inventoryComputeCostService: InventoryComputeCostService, + ) {} /** * Retrieves the common meta data of the financial sheet. @@ -17,10 +21,8 @@ export class FinancialSheetMeta { const baseCurrency = tenantMetadata.baseCurrency; const dateFormat = tenantMetadata.dateFormat; - // const isCostComputeRunning = - // this.inventoryService.isItemsCostComputeRunning(); - - const isCostComputeRunning = false; + const isCostComputeRunning = + await this.inventoryComputeCostService.isItemsCostComputeRunning(); return { organizationName, diff --git a/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts b/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts index b6b7bb579..1bbd610ae 100644 --- a/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts +++ b/packages/server/src/modules/InventoryCost/processors/ComputeItemCost.processor.ts @@ -68,6 +68,12 @@ export class ComputeItemCostProcessor extends WorkerHost { } catch (error) { console.error(`[error] Error computing item cost for item ${itemId}:`, error); console.error('Error stack:', error instanceof Error ? error.stack : 'No stack trace'); + // Reset cost_compute_running when job fails so it does not stay true indefinitely + try { + await this.inventoryComputeCostService.markItemsCostComputeRunning(false); + } catch (markError) { + console.error('[error] Failed to mark cost compute as not running:', markError); + } throw error; } } diff --git a/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts b/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts index 7625b8fa3..c4bfa4417 100644 --- a/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts +++ b/packages/server/src/modules/SaleInvoices/SalesInvoicesCost.ts @@ -114,7 +114,6 @@ export class SaleInvoicesCost { */ scheduleWriteJournalEntries(startingDate?: Date) { // const agenda = Container.get('agenda'); - // return agenda.schedule('in 3 seconds', 'rewrite-invoices-journal-entries', { // startingDate, // tenantId, @@ -123,12 +122,11 @@ export class SaleInvoicesCost { /** * Writes cost GL entries from the inventory cost lots. - * @param {number} tenantId - - * @param {Date} startingDate - + * @param {Date} startingDate - Starting date. * @returns {Promise} */ - public writeCostLotsGLEntries = (startingDate: Date) => { - return this.uow.withTransaction(async (trx: Knex.Transaction) => { + public writeCostLotsGLEntries = async (startingDate: Date) => { + await this.uow.withTransaction(async (trx: Knex.Transaction) => { // Triggers event `onInventoryCostLotsGLEntriesBeforeWrite`. await this.eventPublisher.emitAsync( events.inventory.onCostLotsGLEntriesBeforeWrite, @@ -146,5 +144,10 @@ export class SaleInvoicesCost { } as IInventoryCostLotsGLEntriesWriteEvent, ); }); + // Signal that cost entries have been written so cost_compute_running can be set to false. + await this.eventPublisher.emitAsync( + events.inventory.onInventoryCostEntriesWritten, + {}, + ); }; } diff --git a/packages/webapp/src/containers/FinancialStatements/FinancialReportPage.tsx b/packages/webapp/src/containers/FinancialStatements/FinancialReportPage.tsx index 3cef4d64b..a2c6c9aa3 100644 --- a/packages/webapp/src/containers/FinancialStatements/FinancialReportPage.tsx +++ b/packages/webapp/src/containers/FinancialStatements/FinancialReportPage.tsx @@ -18,12 +18,21 @@ export default function FinancialReportPage(props) { } export const FinancialComputeAlert = styled.div` + --x-background-color: #fdecda; + --x-text-color: #342515; + --x-button-text-color: #824400; + + .bp4-dark & { + --x-background-color: rgba(200, 118, 25, 0.2); + --x-text-color: rgba(255, 255, 255, 0.8); + --x-button-text-color: rgba(255, 255, 255, 0.8); + } position: relative; padding: 8px 20px; border-radius: 2px; - color: #342515; + background-color: var(--x-background-color); + color: var(--x-text-color); font-size: 13px; - background-color: var(--color-financial-report-background); button { font-size: 12px; @@ -32,7 +41,7 @@ export const FinancialComputeAlert = styled.div` &, &:hover { - color: #824400; + color: var(--x-button-text-color); text-decoration: underline; } } @@ -40,7 +49,7 @@ export const FinancialComputeAlert = styled.div` margin-right: 6px; position: relative; top: -2px; - fill: #975f19; + fill: var(--x-text-color); } `;