Add new filter options and metrics to product filters and pages; enhance SQL schema for financial calculations

This commit is contained in:
2025-03-27 16:27:13 -04:00
parent 8b8845b423
commit 957c7b5eb1
17 changed files with 2216 additions and 482 deletions

View File

@@ -57,25 +57,16 @@ const TEMP_TABLES = [
'temp_daily_sales',
'temp_product_stats',
'temp_category_sales',
'temp_category_stats'
'temp_category_stats',
'temp_beginning_inventory',
'temp_monthly_inventory'
];
// Add cleanup function for temporary tables
async function cleanupTemporaryTables(connection) {
// List of possible temporary tables that might exist
const tempTables = [
'temp_sales_metrics',
'temp_purchase_metrics',
'temp_forecast_dates',
'temp_daily_sales',
'temp_product_stats',
'temp_category_sales',
'temp_category_stats'
];
try {
// Drop each temporary table if it exists
for (const table of tempTables) {
for (const table of TEMP_TABLES) {
await connection.query(`DROP TABLE IF EXISTS ${table}`);
}
} catch (err) {
@@ -534,7 +525,7 @@ async function calculateMetrics() {
await connection.query(`
UPDATE calculate_history
SET
status = 'error',
status = 'failed',
end_time = NOW(),
duration_seconds = EXTRACT(EPOCH FROM (NOW() - start_time))::INTEGER,
error_message = $1