diff --git a/routes/admin.js b/routes/admin.js index 913e67a..4c4b93a 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -204,7 +204,8 @@ router.post('/members/:id/update', requireAdmin, async (req, res) => { const { salutation, title, first_name, last_name, birth_date, email, phone, street, address_addition, zip, city, - bank_name, account_holder, iban, tariff_id, status + bank_name, account_holder, iban, tariff_id, status, + agreed_price, agreed_duration } = req.body; try { await db.query(` diff --git a/routes/api.js b/routes/api.js index 3d8a355..162416e 100644 --- a/routes/api.js +++ b/routes/api.js @@ -127,15 +127,17 @@ router.post('/submit-membership', async (req, res) => { INSERT INTO memberships (tariff_id, salutation, title, first_name, last_name, birth_date, email, phone, street, address_addition, zip, city, bank_name, account_holder, iban, - sepa_accepted, agb_accepted, datenschutz_accepted, data_correct, guardian_consent, is_minor, access_token) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + sepa_accepted, agb_accepted, datenschutz_accepted, data_correct, guardian_consent, is_minor, access_token, + agreed_price, agreed_duration) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `, [ tariff_id, salutation, title || '', first_name, last_name, birth_date, email, phone || '', street, address_addition || '', zip, city, bank_name || '', account_holder || '', iban || '', sepa_accepted ? 1 : 0, agb_accepted ? 1 : 0, datenschutz_accepted ? 1 : 0, data_correct ? 1 : 0, - guardian_consent ? 1 : 0, is_minor, access_token + guardian_consent ? 1 : 0, is_minor, access_token, + tariffs[0].price_monthly, tariffs[0].duration_months ]); res.json({ success: true }); diff --git a/routes/billing.js b/routes/billing.js index d750625..9df71a6 100644 --- a/routes/billing.js +++ b/routes/billing.js @@ -13,6 +13,9 @@ function calcInvoiceAmount(member, period) { // Pausiert → 0€ if (member.status === 'paused') return 0; + // Vereinbarten Preis verwenden (nicht den aktuellen Tarif-Preis!) + const price = parseFloat(member.agreed_price || member.price_monthly); + // Erster Monat (anteilig)? const firstPeriod = member.first_payment_date ? member.first_payment_date.toISOString().substring(0, 7) @@ -22,7 +25,7 @@ function calcInvoiceAmount(member, period) { return parseFloat(member.first_payment_amt); } - return parseFloat(member.price_monthly); + return price; } // Periode als lesbarer Text: "2026-04" → "April 2026" @@ -74,7 +77,8 @@ router.get('/', requireAdmin, async (req, res) => { // Vorschau: Mitglieder die noch keine Rechnung für diese Periode haben const [eligible] = await db.query(` - SELECT m.*, t.price_monthly, t.name as tariff_name + SELECT m.*, t.price_monthly, t.name as tariff_name, + COALESCE(m.agreed_price, t.price_monthly) as agreed_price FROM memberships m JOIN tariffs t ON m.tariff_id = t.id WHERE m.status IN ('active','paused') @@ -119,7 +123,8 @@ router.post('/run', requireAdmin, async (req, res) => { // Alle aktiven/pausierten Mitglieder im Vertragszeitraum const [members] = await db.query(` - SELECT m.*, t.price_monthly, t.name as tariff_name + SELECT m.*, t.price_monthly, t.name as tariff_name, + COALESCE(m.agreed_price, t.price_monthly) as agreed_price FROM memberships m JOIN tariffs t ON m.tariff_id = t.id WHERE m.status IN ('active','paused') diff --git a/views/admin/billing.ejs b/views/admin/billing.ejs index 3cd6ebf..0e37840 100644 --- a/views/admin/billing.ejs +++ b/views/admin/billing.ejs @@ -200,7 +200,12 @@ <%= m.last_name %>, <%= m.first_name %> <%= m.tariff_name %> - <%= Number(m.price_monthly).toFixed(2).replace('.', ',') %> € + + <%= Number(m.agreed_price || m.price_monthly).toFixed(2).replace('.', ',') %> € + <% if (m.agreed_price && Number(m.agreed_price) !== Number(m.price_monthly)) { %> +
Tarif: <%= Number(m.price_monthly).toFixed(2).replace('.', ',') %> € + <% } %> + <% }) %> diff --git a/views/admin/member-detail.ejs b/views/admin/member-detail.ejs index 9061fa8..e82e430 100644 --- a/views/admin/member-detail.ejs +++ b/views/admin/member-detail.ejs @@ -146,6 +146,23 @@ +
+
+ +
+ + +
+
+
+ + +
+