diff --git a/backend/controllers/billingController.js b/backend/controllers/billingController.js index 1de5752a..b544f652 100644 --- a/backend/controllers/billingController.js +++ b/backend/controllers/billingController.js @@ -1,11 +1,16 @@ import fs from 'fs'; import multer from 'multer'; import path from 'path'; +import { fileURLToPath } from 'url'; import billingService from '../services/billingService.js'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const BILLING_TEMPLATE_UPLOAD_DIR = path.resolve(__dirname, '..', 'uploads', 'billing-templates'); + const storage = multer.diskStorage({ destination: (req, file, cb) => { - const dir = 'uploads/billing-templates'; + const dir = BILLING_TEMPLATE_UPLOAD_DIR; fs.mkdirSync(dir, { recursive: true }); cb(null, dir); }, diff --git a/backend/services/billingService.js b/backend/services/billingService.js index 43b26262..c39523b9 100644 --- a/backend/services/billingService.js +++ b/backend/services/billingService.js @@ -613,8 +613,23 @@ class BillingService { return { status: 404, response: { success: false, error: 'Abrechnungslauf nicht gefunden' } }; } await checkAccess(userToken, run.clubId); + if (!run.template) { + console.warn('[billing.generateRun] Vorlage fehlt für Run', { + runId: run.id, + clubId: run.clubId, + templateId: run.templateId + }); + return { status: 404, response: { success: false, error: 'Vorlage für diesen Abrechnungslauf nicht gefunden. Bitte neuen Abrechnungslauf mit aktueller Vorlage erstellen.' } }; + } const resolvedTemplatePath = this._resolveExistingFilePath(run.template?.pdfStoragePath); if (!resolvedTemplatePath) { + console.warn('[billing.generateRun] Vorlagen-PDF nicht gefunden', { + runId: run.id, + clubId: run.clubId, + templateId: run.templateId, + storedPath: run.template?.pdfStoragePath, + cwd: process.cwd() + }); return { status: 404, response: { success: false, error: 'Vorlagen-PDF nicht gefunden' } }; } const computed = await this._collectTrainingSessions(run.clubId, run.periodStart, run.periodEnd);