From 889e110dd923baa587bad835d0306ef4d81389a8 Mon Sep 17 00:00:00 2001 From: elpatron Date: Thu, 9 Oct 2025 15:59:00 +0200 Subject: [PATCH] fix: Preisanzeige korrigieren - Cent zu Euro Konvertierung MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Preise wurden in Cent gespeichert aber fälschlicherweise als Euro angezeigt Lösung: Alle Backend-APIs konvertieren Preise korrekt von Cent zu Euro (/100) Betroffene Dateien: - bookings.ts: E-Mail-Templates und Preisberechnungen - cancellation.ts: Preisberechnungen für Stornierungen - email-templates.ts: HTML-E-Mail-Templates - email.ts: ICS-Kalender-Integration - caldav.ts: CalDAV-Kalender-Export Jetzt werden Preise konsistent in Euro angezeigt (z.B. 50.00€ statt 5000.00€) --- src/server/lib/email-templates.ts | 6 +++--- src/server/lib/email.ts | 4 ++-- src/server/routes/caldav.ts | 6 +++--- src/server/rpc/bookings.ts | 32 +++++++++++++++---------------- src/server/rpc/cancellation.ts | 8 ++++---- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/server/lib/email-templates.ts b/src/server/lib/email-templates.ts index ec01518..ddee85a 100644 --- a/src/server/lib/email-templates.ts +++ b/src/server/lib/email-templates.ts @@ -14,12 +14,12 @@ function renderTreatmentList( options: { showPrices: boolean } = { showPrices: true } ): string { const totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0); const treatmentItems = treatments.map(t => options.showPrices - ? `
  • ${t.name} - ${t.duration} Min - ${t.price.toFixed(2)} €
  • ` - : `
  • ${t.name} - ${t.duration} Min - ${t.price.toFixed(2)} €
  • ` + ? `
  • ${t.name} - ${t.duration} Min - ${(t.price / 100).toFixed(2)} €
  • ` + : `
  • ${t.name} - ${t.duration} Min - ${(t.price / 100).toFixed(2)} €
  • ` ).join(''); const totalLine = options.showPrices diff --git a/src/server/lib/email.ts b/src/server/lib/email.ts index 02b3f85..2521fca 100644 --- a/src/server/lib/email.ts +++ b/src/server/lib/email.ts @@ -72,10 +72,10 @@ function createICSFile(params: { // Build treatments list for SUMMARY and DESCRIPTION const treatmentNames = icsEscape(treatments.map(t => t.name).join(', ')); const totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0); const treatmentDetails = treatments.map(t => - `${icsEscape(t.name)} (${t.duration} Min, ${t.price.toFixed(2)} EUR)` + `${icsEscape(t.name)} (${t.duration} Min, ${(t.price / 100).toFixed(2)} EUR)` ).join('\\n'); const description = `Behandlungen:\\n${treatmentDetails}\\n\\nGesamt: ${totalDuration} Min, ${totalPrice.toFixed(2)} EUR\\n\\nTermin bei Stargirlnails Kiel`; diff --git a/src/server/routes/caldav.ts b/src/server/routes/caldav.ts index 1c6dddd..04b65ce 100644 --- a/src/server/routes/caldav.ts +++ b/src/server/routes/caldav.ts @@ -84,11 +84,11 @@ X-WR-TIMEZONE:Europe/Berlin treatmentNames = booking.treatments.map(t => t.name).join(', '); duration = booking.treatments.reduce((sum, t) => sum + (t.duration || 0), 0); - totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price || 0), 0); + totalPrice = booking.treatments.reduce((sum, t) => sum + ((t.price || 0) / 100), 0); // Build detailed treatment list for description treatmentDetails = booking.treatments - .map(t => `- ${t.name} (${t.duration} Min., ${t.price}€)`) + .map(t => `- ${t.name} (${t.duration} Min., ${(t.price / 100).toFixed(2)}€)`) .join('\\n'); if (booking.treatments.length > 1) { @@ -101,7 +101,7 @@ X-WR-TIMEZONE:Europe/Berlin duration = booking.bookedDurationMinutes || treatment?.duration || 60; treatmentDetails = `Behandlung: ${treatmentNames}`; if (treatment?.price) { - treatmentDetails += ` (${duration} Min., ${treatment.price}€)`; + treatmentDetails += ` (${duration} Min., ${(treatment.price / 100).toFixed(2)}€)`; } } diff --git a/src/server/rpc/bookings.ts b/src/server/rpc/bookings.ts index 1890887..b47cca2 100644 --- a/src/server/rpc/bookings.ts +++ b/src/server/rpc/bookings.ts @@ -367,9 +367,9 @@ const create = os treatments: input.treatments }); - const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); + const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); const totalDuration = input.treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = input.treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = input.treatments.reduce((sum, t) => sum + (t.price / 100), 0); await sendEmail({ to: input.customerEmail, @@ -394,9 +394,9 @@ const create = os }); const homepageUrl = generateUrl(); - const treatmentsText = input.treatments.map(t => ` - ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); + const treatmentsText = input.treatments.map(t => ` - ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); const totalDuration = input.treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = input.treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = input.treatments.reduce((sum, t) => sum + (t.price / 100), 0); const adminText = `Neue Buchungsanfrage eingegangen:\n\n` + `Name: ${input.customerName}\n` + @@ -483,9 +483,9 @@ const updateStatus = os treatments: booking.treatments }); - const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); + const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0); if (booking.customerEmail) { await sendEmailWithAGBAndCalendar({ @@ -512,9 +512,9 @@ const updateStatus = os treatments: booking.treatments }); - const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); + const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0); if (booking.customerEmail) { await sendEmail({ @@ -571,9 +571,9 @@ const remove = os treatments: booking.treatments }); - const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); + const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0); await sendEmail({ to: booking.customerEmail, @@ -693,8 +693,8 @@ const createManual = os treatments: input.treatments }); - const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); - const totalPrice = input.treatments.reduce((sum, t) => sum + t.price, 0); + const treatmentsText = input.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); + const totalPrice = input.treatments.reduce((sum, t) => sum + (t.price / 100), 0); await sendEmailWithAGBAndCalendar({ to: input.customerEmail!, @@ -874,8 +874,8 @@ export const router = { treatments: updated.treatments, }); - const treatmentsText = updated.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); - const totalPrice = updated.treatments.reduce((sum, t) => sum + t.price, 0); + const treatmentsText = updated.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); + const totalPrice = updated.treatments.reduce((sum, t) => sum + (t.price / 100), 0); await sendEmailWithAGBAndCalendar({ to: updated.customerEmail, @@ -929,9 +929,9 @@ export const router = { if (booking.customerEmail) { const bookingAccessToken = await queryClient.cancellation.createToken({ bookingId: booking.id }); - const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${t.price.toFixed(2)} €)`).join('\n'); + const treatmentsText = booking.treatments.map(t => `- ${t.name} (${t.duration} Min, ${(t.price / 100).toFixed(2)} €)`).join('\n'); const totalDuration = booking.treatments.reduce((sum, t) => sum + t.duration, 0); - const totalPrice = booking.treatments.reduce((sum, t) => sum + t.price, 0); + const totalPrice = booking.treatments.reduce((sum, t) => sum + (t.price / 100), 0); await sendEmail({ to: booking.customerEmail, diff --git a/src/server/rpc/cancellation.ts b/src/server/rpc/cancellation.ts index c518c30..24de5c7 100644 --- a/src/server/rpc/cancellation.ts +++ b/src/server/rpc/cancellation.ts @@ -137,7 +137,7 @@ const getBookingByToken = os // New bookings with treatments array treatments = booking.treatments; totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0); - totalPrice = treatments.reduce((sum, t) => sum + t.price, 0); + totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0); } else if (booking.treatmentId) { // Old bookings with single treatmentId (backward compatibility) const treatmentsKV = createKV("treatments"); @@ -151,7 +151,7 @@ const getBookingByToken = os price: treatment.price, }]; totalDuration = treatment.duration; - totalPrice = treatment.price; + totalPrice = treatment.price / 100; } else { // Fallback if treatment not found treatments = []; @@ -333,7 +333,7 @@ export const router = { // New bookings with treatments array treatments = booking.treatments; totalDuration = treatments.reduce((sum, t) => sum + t.duration, 0); - totalPrice = treatments.reduce((sum, t) => sum + t.price, 0); + totalPrice = treatments.reduce((sum, t) => sum + (t.price / 100), 0); } else if (booking.treatmentId) { // Old bookings with single treatmentId (backward compatibility) const treatmentsKV = createKV("treatments"); @@ -347,7 +347,7 @@ export const router = { price: treatment.price, }]; totalDuration = treatment.duration; - totalPrice = treatment.price; + totalPrice = treatment.price / 100; } else { // Fallback if treatment not found treatments = [];