diff --git a/app/assets/FCSCLogo.png b/app/assets/FCSCLogo.png new file mode 100644 index 0000000..0148d29 Binary files /dev/null and b/app/assets/FCSCLogo.png differ diff --git a/app/controllers/calculation.controller.js b/app/controllers/calculation.controller.js index 466dd81..2496ac1 100644 --- a/app/controllers/calculation.controller.js +++ b/app/controllers/calculation.controller.js @@ -272,8 +272,6 @@ exports.survey_auto_submit = async (req, res) => { const result3 = await autoSubmissionService.verifyCompleteness(year, quarter); - // Or verify entire year - // await autoSubmissionService.verifyCompleteness(year); res.json({ success: true, autoFillMissingSubmissions: result , verifyCompleteness: result3 }); diff --git a/app/controllers/establishment.controller.js b/app/controllers/establishment.controller.js index b8b91e7..b8a92a4 100644 --- a/app/controllers/establishment.controller.js +++ b/app/controllers/establishment.controller.js @@ -1089,10 +1089,11 @@ exports.requestOTPForLogin = async (req, res) => { const hashedOtp = await bcrypt.hash(otp, 10); // Store OTP in the correct model with WHERE clause + const otp_expiry = new Date(Date.now() + 10 * 60 * 1000); await userModel.update( { login_otp: hashedOtp, - login_otp_expires_at: new Date(Date.now() + 10 * 60 * 1000), + login_otp_expires_at: otp_expiry, }, { where: { email: registered_email } @@ -1101,8 +1102,10 @@ exports.requestOTPForLogin = async (req, res) => { const placeHolderData = { username: loggingUser.name, verfication_code: otp, + otp_expiry: otp_expiry, support_email: process.env.SUPPORT_EMAIL, - support_phone: process.env.SUPPORT_PHONE + support_phone: process.env.SUPPORT_PHONE, + logo_url: `${process.env.APP_BASE_URL}/assets/FCSCLogo.png` }; await sendEmailService(registered_email, "sign_in_verification_code", placeHolderData); diff --git a/app/services/auto_fill_missing_quarterly_submissions_service.js b/app/services/auto_fill_missing_quarterly_submissions_service.js index 1d4d0fe..1d682d8 100644 --- a/app/services/auto_fill_missing_quarterly_submissions_service.js +++ b/app/services/auto_fill_missing_quarterly_submissions_service.js @@ -269,27 +269,27 @@ class AutoFillSubmissionService { product.product_id, product.unit_id, product.annual_installed_capacity, - // Previous = Current from source (shift forward) + // Previous = Current from source + product.current_quantity_period_one || 0, + product.current_quantity_period_two || 0, + product.current_quantity_period_three || 0, + product.current_cost_period_one || 0, + product.current_cost_period_two || 0, + product.current_cost_period_three || 0, + // Current = Current from source + product.current_quantity_period_one || 0, + product.current_quantity_period_two || 0, + product.current_quantity_period_three || 0, + product.current_cost_period_one || 0, + product.current_cost_period_two || 0, + product.current_cost_period_three || 0, + // Forecast = Current from source product.current_quantity_period_one || 0, product.current_quantity_period_two || 0, product.current_quantity_period_three || 0, product.current_cost_period_one || 0, product.current_cost_period_two || 0, product.current_cost_period_three || 0, - // Current = Forecast from source (use forecast values) - product.forecast_quantity_period_one || 0, - product.forecast_quantity_period_two || 0, - product.forecast_quantity_period_three || 0, - product.forecast_cost_period_one || 0, - product.forecast_cost_period_two || 0, - product.forecast_cost_period_three || 0, - // Forecast = Same as current (or could apply growth rate) - product.forecast_quantity_period_one || 0, - product.forecast_quantity_period_two || 0, - product.forecast_quantity_period_three || 0, - product.forecast_cost_period_one || 0, - product.forecast_cost_period_two || 0, - product.forecast_cost_period_three || 0, // Totals this.calculateTotal( product.current_quantity_period_one, @@ -302,24 +302,24 @@ class AutoFillSubmissionService { product.current_cost_period_three ), this.calculateTotal( - product.forecast_quantity_period_one, - product.forecast_quantity_period_two, - product.forecast_quantity_period_three + product.current_quantity_period_one, + product.current_quantity_period_two, + product.current_quantity_period_three ), this.calculateTotal( - product.forecast_cost_period_one, - product.forecast_cost_period_two, - product.forecast_cost_period_three + product.current_cost_period_one, + product.current_cost_period_two, + product.current_cost_period_three ), this.calculateTotal( - product.forecast_quantity_period_one, - product.forecast_quantity_period_two, - product.forecast_quantity_period_three + product.current_quantity_period_one, + product.current_quantity_period_two, + product.current_quantity_period_three ), this.calculateTotal( - product.forecast_cost_period_one, - product.forecast_cost_period_two, - product.forecast_cost_period_three + product.current_cost_period_one, + product.current_cost_period_two, + product.current_cost_period_three ), // Other fields product.variation_reason_master_id, @@ -469,6 +469,40 @@ class AutoFillSubmissionService { } } + // HELPER : calculation log + async logRecord(calculation_type, reference_year, reference_month = null, status = 'Started', logId = null, records_processed = 0, error_message = null, useConnection = null) { + + const connection = useConnection || await this.pool.getConnection(); + try { + if (!logId) { + const [result] = await connection.query( + `INSERT INTO calculation_log (calculation_type, reference_year, reference_month, status) + VALUES (?, ?, ?, ?)`, + [calculation_type, reference_year, reference_month, status] + ); + return result.insertId; + } + + if(records_processed == 0) + { + status = 'Failed'; + } + + await connection.query( + `UPDATE calculation_log + SET status=?, records_processed=?, error_message=?, completed_at=NOW() + WHERE id=?`, + [status, records_processed, error_message?.substring(0,65535) || null, logId] + ); + + } catch (err) { + console.error('[LOG ERROR]', err.message); + logger.error(` Log record error: ${err.message} `); + } finally { + if (!useConnection) connection.release(); + } + } + // Close pool async close() { await this.pool.end(); diff --git a/server.js b/server.js index 77e68ef..4e016c7 100644 --- a/server.js +++ b/server.js @@ -56,6 +56,11 @@ app.set("trust proxy", 1); app.use(express.json()); app.use(cookieParser()); +app.use( + "/assets", + express.static(path.join(__dirname, "app/assets")) +); + /** * ========================= * HELMET + SECURITY HEADERS