Energie-Bonus aufgeteilt in Sofort + Neukunden
EnergyContractDetails.bonus war ein einzelnes Feld. Strom-/Gas- Verträge haben aber typischerweise zwei Boni (Sofort beim Wechsel + Neukunden-Bonus nach 12 Monaten), die getrennt verbucht werden müssen. Migration 20260524100000_split_energy_bonus: - ADD COLUMN IF NOT EXISTS instantBonus, newCustomerBonus - bestehende `bonus`-Werte → instantBonus (Annahme: Sofort) - DROP COLUMN IF EXISTS bonus UI: - ContractForm zeigt zwei Input-Felder - Detail-Ansicht zeigt beide einzeln + Gesamtbonus - Kostenvorschau listet beide einzeln, dann Gesamt, dann effektive Jahreskosten Cost-Calc: calculateCosts() bekommt beide Boni; CostCalculation liefert instantBonus, newCustomerBonus, totalBonus. PDF-Template: drei neue Variablen energyDetails.instantBonus, .newCustomerBonus, .totalBonus. Live-verifiziert auf dev: PUT mit beiden Werten → DB persistiert, GET liefert zurueck. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
-- Energie-Bonus in Sofort-Bonus + Neukunden-Bonus aufteilen.
|
||||
-- Bestehende Werte werden nach `instantBonus` migriert (Annahme: bei
|
||||
-- Bestandsverträgen war "Bonus" üblicherweise der Sofort-Bonus).
|
||||
-- Wer das anders hatte, kann die Werte über die UI nachträglich verschieben.
|
||||
--
|
||||
-- IF NOT EXISTS macht den Re-Deploy auf Prod sicher, falls jemand schon
|
||||
-- `prisma db push` gefahren hat.
|
||||
|
||||
ALTER TABLE `EnergyContractDetails`
|
||||
ADD COLUMN IF NOT EXISTS `instantBonus` DOUBLE NULL,
|
||||
ADD COLUMN IF NOT EXISTS `newCustomerBonus` DOUBLE NULL;
|
||||
|
||||
-- Daten kopieren, sofern die alte Spalte noch existiert und das Ziel leer ist
|
||||
SET @col_exists := (
|
||||
SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'EnergyContractDetails'
|
||||
AND COLUMN_NAME = 'bonus'
|
||||
);
|
||||
SET @sql := IF(
|
||||
@col_exists > 0,
|
||||
'UPDATE `EnergyContractDetails` SET `instantBonus` = `bonus` WHERE `bonus` IS NOT NULL AND `instantBonus` IS NULL',
|
||||
'SELECT "bonus-Spalte existiert nicht mehr, nichts zu migrieren"'
|
||||
);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- Alte Spalte droppen, falls vorhanden
|
||||
ALTER TABLE `EnergyContractDetails` DROP COLUMN IF EXISTS `bonus`;
|
||||
@@ -805,7 +805,14 @@ model EnergyContractDetails {
|
||||
basePrice Float? // €/Monat
|
||||
unitPrice Float? // €/kWh (Arbeitspreis) - bei HT/NT: HT-Preis
|
||||
unitPriceNt Float? // €/kWh NT-Preis (nur bei Zweitarifzähler)
|
||||
bonus Float?
|
||||
// Bonus wurde 2026-05-24 in zwei Felder aufgeteilt: Sofort-Bonus
|
||||
// (Auszahlung kurz nach Wechsel) + Neukunden-Bonus (Auszahlung am
|
||||
// Vertragsende / nach 12 Monaten). Beide werden im Detail als
|
||||
// Gesamtbonus aufsummiert und in der Kostenvorschau einzeln
|
||||
// dargestellt. Migration kopiert das alte `bonus` nach
|
||||
// `instantBonus` (Annahme: meistgenutzte Variante).
|
||||
instantBonus Float? // Sofort-Bonus
|
||||
newCustomerBonus Float? // Neukunden-Bonus
|
||||
previousProviderName String?
|
||||
previousCustomerNumber String?
|
||||
invoices Invoice[] // Rechnungen
|
||||
|
||||
@@ -164,7 +164,8 @@ export async function updateContract(req: AuthRequest, res: Response): Promise<v
|
||||
};
|
||||
const energyLabels: Record<string, string> = {
|
||||
meterId: 'Zähler', maloId: 'MaLo-ID', annualConsumption: 'Jahresverbrauch',
|
||||
basePrice: 'Grundpreis', unitPrice: 'Arbeitspreis', unitPriceNt: 'NT-Arbeitspreis', bonus: 'Bonus',
|
||||
basePrice: 'Grundpreis', unitPrice: 'Arbeitspreis', unitPriceNt: 'NT-Arbeitspreis',
|
||||
instantBonus: 'Sofort-Bonus', newCustomerBonus: 'Neukunden-Bonus',
|
||||
};
|
||||
|
||||
// Hauptfelder vergleichen
|
||||
|
||||
@@ -218,7 +218,8 @@ interface ContractCreateData {
|
||||
annualConsumption?: number;
|
||||
basePrice?: number;
|
||||
unitPrice?: number;
|
||||
bonus?: number;
|
||||
instantBonus?: number;
|
||||
newCustomerBonus?: number;
|
||||
previousProviderName?: string;
|
||||
previousCustomerNumber?: string;
|
||||
};
|
||||
@@ -710,7 +711,8 @@ export async function createFollowUpContract(previousContractId: number) {
|
||||
previousContract.energyDetails.annualConsumption ?? undefined,
|
||||
basePrice: previousContract.energyDetails.basePrice ?? undefined,
|
||||
unitPrice: previousContract.energyDetails.unitPrice ?? undefined,
|
||||
bonus: previousContract.energyDetails.bonus ?? undefined,
|
||||
instantBonus: previousContract.energyDetails.instantBonus ?? undefined,
|
||||
newCustomerBonus: previousContract.energyDetails.newCustomerBonus ?? undefined,
|
||||
previousProviderName: previousContract.providerName ?? undefined,
|
||||
previousCustomerNumber:
|
||||
previousContract.customerNumberAtProvider ?? undefined,
|
||||
@@ -898,7 +900,8 @@ export async function createRenewalContract(previousContractId: number) {
|
||||
basePrice: ed.basePrice,
|
||||
unitPrice: ed.unitPrice,
|
||||
unitPriceNt: ed.unitPriceNt,
|
||||
bonus: ed.bonus,
|
||||
instantBonus: ed.instantBonus,
|
||||
newCustomerBonus: ed.newCustomerBonus,
|
||||
previousProviderName: ed.previousProviderName,
|
||||
previousCustomerNumber: ed.previousCustomerNumber,
|
||||
},
|
||||
|
||||
@@ -87,7 +87,9 @@ export const CRM_FIELDS = [
|
||||
{ path: 'energyDetails.basePrice', label: 'Grundpreis (€/Monat)', group: 'Energie' },
|
||||
{ path: 'energyDetails.unitPrice', label: 'Arbeitspreis (€/kWh)', group: 'Energie' },
|
||||
{ path: 'energyDetails.unitPriceNt', label: 'NT-Arbeitspreis (€/kWh)', group: 'Energie' },
|
||||
{ path: 'energyDetails.bonus', label: 'Bonus (€)', group: 'Energie' },
|
||||
{ path: 'energyDetails.instantBonus', label: 'Sofort-Bonus (€)', group: 'Energie' },
|
||||
{ path: 'energyDetails.newCustomerBonus', label: 'Neukunden-Bonus (€)', group: 'Energie' },
|
||||
{ path: 'energyDetails.totalBonus', label: 'Gesamtbonus (€)', group: 'Energie' },
|
||||
// Internet/DSL/Glasfaser/Kabel
|
||||
{ path: 'internetDetails.downloadSpeed', label: 'Download-Speed (Mbit/s)', group: 'Internet' },
|
||||
{ path: 'internetDetails.uploadSpeed', label: 'Upload-Speed (Mbit/s)', group: 'Internet' },
|
||||
@@ -469,7 +471,11 @@ export async function generateFilledPdf(
|
||||
'energyDetails.basePrice': contract.energyDetails?.basePrice?.toString() || '',
|
||||
'energyDetails.unitPrice': contract.energyDetails?.unitPrice?.toString() || '',
|
||||
'energyDetails.unitPriceNt': contract.energyDetails?.unitPriceNt?.toString() || '',
|
||||
'energyDetails.bonus': contract.energyDetails?.bonus?.toString() || '',
|
||||
'energyDetails.instantBonus': contract.energyDetails?.instantBonus?.toString() || '',
|
||||
'energyDetails.newCustomerBonus': contract.energyDetails?.newCustomerBonus?.toString() || '',
|
||||
'energyDetails.totalBonus': (
|
||||
((contract.energyDetails?.instantBonus ?? 0) + (contract.energyDetails?.newCustomerBonus ?? 0)) || ''
|
||||
).toString(),
|
||||
// Internet
|
||||
'internetDetails.downloadSpeed': contract.internetDetails?.downloadSpeed?.toString() || '',
|
||||
'internetDetails.uploadSpeed': contract.internetDetails?.uploadSpeed?.toString() || '',
|
||||
|
||||
@@ -120,6 +120,33 @@ isolierte Instanz (keine Multi-Tenancy im Code), Provisioning + Abrechnung
|
||||
- **Live-verifiziert**: 4867 Datensätze + 1 Datei in 13.2s
|
||||
wiederhergestellt, Log-Modal zeigt den vollständigen Verlauf.
|
||||
|
||||
- [x] **🆕 Bonus-Feld aufgeteilt: Sofort-Bonus + Neukunden-Bonus (Strom/Gas)**
|
||||
- Bisher gab es ein einzelnes `bonus`-Feld auf `EnergyContractDetails`.
|
||||
Jetzt zwei Felder `instantBonus` (Sofort) und `newCustomerBonus`
|
||||
(Neukunden), die zusammen den Gesamtbonus ergeben.
|
||||
- **Migration** `20260524100000_split_energy_bonus`:
|
||||
`ADD COLUMN IF NOT EXISTS instantBonus`, `... newCustomerBonus`,
|
||||
`UPDATE` kopiert bestehendes `bonus` → `instantBonus`
|
||||
(Annahme: Bestandsverträge hatten primär Sofort-Bonus), dann
|
||||
`DROP COLUMN IF EXISTS bonus`. Idempotent.
|
||||
- **Form** (`ContractForm.tsx`): zwei Input-Felder „Sofort-Bonus (€)"
|
||||
+ „Neukunden-Bonus (€)" statt einem.
|
||||
- **Detail-Ansicht**: zeigt beide Felder einzeln und einen
|
||||
aggregierten „Gesamtbonus" (fett) darunter.
|
||||
- **Kostenvorschau**: listet Sofort + Neukunden einzeln auf
|
||||
(jeweils grün), dann „Gesamtbonus" (mittel grün, fett), danach
|
||||
Effektive Jahreskosten.
|
||||
- **Cost-Calc** (`energyCalculations.ts`): `calculateCosts()` nimmt
|
||||
jetzt beide Bonus-Werte; `CostCalculation` liefert `instantBonus`,
|
||||
`newCustomerBonus` + `totalBonus`.
|
||||
- **PDF-Template-Variablen**: drei neue Placeholder
|
||||
`energyDetails.instantBonus`, `.newCustomerBonus`, `.totalBonus`
|
||||
(alter `.bonus`-Placeholder entfernt).
|
||||
- **Audit-Log** unterscheidet jetzt beide Felder.
|
||||
- **Live-verifiziert** auf dev: PUT mit beiden Feldern → DB hat
|
||||
`instantBonus=75, newCustomerBonus=125`, GET liefert beide
|
||||
Werte zurück.
|
||||
|
||||
- [x] **🛡️ Pentest 2026-05-20 Pen-30-Befunde (MEDIUM+INFO)**
|
||||
- **30.13 MIME-Extension-XSS** (MEDIUM): `GET /api/files/download`
|
||||
lieferte hochgeladene Dateien via `res.sendFile` aus. Da multer
|
||||
|
||||
@@ -609,7 +609,8 @@ function EnergyConsumptionCalculation({
|
||||
basePrice,
|
||||
unitPrice,
|
||||
unitPriceNt,
|
||||
bonus,
|
||||
instantBonus,
|
||||
newCustomerBonus,
|
||||
hasMeter,
|
||||
contractMeters,
|
||||
}: {
|
||||
@@ -619,7 +620,8 @@ function EnergyConsumptionCalculation({
|
||||
endDate?: string;
|
||||
basePrice?: number;
|
||||
unitPrice?: number;
|
||||
bonus?: number;
|
||||
instantBonus?: number;
|
||||
newCustomerBonus?: number;
|
||||
unitPriceNt?: number;
|
||||
hasMeter?: boolean;
|
||||
contractMeters?: ContractMeter[];
|
||||
@@ -656,7 +658,7 @@ function EnergyConsumptionCalculation({
|
||||
const htKwh = consumption?.consumptionHt ?? consumption?.consumptionKwh ?? 0;
|
||||
const ntKwh = consumption?.consumptionNt;
|
||||
const costs = consumption && consumption.consumptionKwh > 0
|
||||
? calculateCosts(htKwh, basePrice, unitPrice, bonus, ntKwh, unitPriceNt)
|
||||
? calculateCosts(htKwh, basePrice, unitPrice, instantBonus, ntKwh, unitPriceNt, newCustomerBonus)
|
||||
: null;
|
||||
|
||||
const canCalculate = consumption && (consumption.type === 'exact' || consumption.type === 'projected');
|
||||
@@ -780,12 +782,24 @@ function EnergyConsumptionCalculation({
|
||||
<span className="font-mono">{formatNumber(costs.annualTotalCost)} €</span>
|
||||
</div>
|
||||
</div>
|
||||
{/* Bonus */}
|
||||
{costs.bonus != null && costs.bonus > 0 && (
|
||||
{/* Bonus – Sofort + Neukunden einzeln, dann Gesamt */}
|
||||
{costs.totalBonus != null && costs.totalBonus > 0 && (
|
||||
<>
|
||||
<div className="flex justify-between text-green-600">
|
||||
<span>Bonus</span>
|
||||
<span className="font-mono">- {formatNumber(costs.bonus)} €</span>
|
||||
{costs.instantBonus != null && costs.instantBonus > 0 && (
|
||||
<div className="flex justify-between text-green-600">
|
||||
<span>Sofort-Bonus</span>
|
||||
<span className="font-mono">- {formatNumber(costs.instantBonus)} €</span>
|
||||
</div>
|
||||
)}
|
||||
{costs.newCustomerBonus != null && costs.newCustomerBonus > 0 && (
|
||||
<div className="flex justify-between text-green-600">
|
||||
<span>Neukunden-Bonus</span>
|
||||
<span className="font-mono">- {formatNumber(costs.newCustomerBonus)} €</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex justify-between text-green-700 font-medium">
|
||||
<span>Gesamtbonus</span>
|
||||
<span className="font-mono">- {formatNumber(costs.totalBonus)} €</span>
|
||||
</div>
|
||||
<div className="border-t border-gray-300 pt-2">
|
||||
<div className="flex justify-between font-semibold">
|
||||
@@ -2565,10 +2579,25 @@ export default function ContractDetail() {
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
{c.energyDetails.bonus && (
|
||||
{/* Bonus: Sofort + Neukunden einzeln + Gesamtbonus */}
|
||||
{c.energyDetails.instantBonus != null && c.energyDetails.instantBonus > 0 && (
|
||||
<div>
|
||||
<dt className="text-sm text-gray-500">Bonus</dt>
|
||||
<dd>{c.energyDetails.bonus.toLocaleString('de-DE')} €</dd>
|
||||
<dt className="text-sm text-gray-500">Sofort-Bonus</dt>
|
||||
<dd>{c.energyDetails.instantBonus.toLocaleString('de-DE')} €</dd>
|
||||
</div>
|
||||
)}
|
||||
{c.energyDetails.newCustomerBonus != null && c.energyDetails.newCustomerBonus > 0 && (
|
||||
<div>
|
||||
<dt className="text-sm text-gray-500">Neukunden-Bonus</dt>
|
||||
<dd>{c.energyDetails.newCustomerBonus.toLocaleString('de-DE')} €</dd>
|
||||
</div>
|
||||
)}
|
||||
{((c.energyDetails.instantBonus ?? 0) + (c.energyDetails.newCustomerBonus ?? 0)) > 0 && (
|
||||
<div>
|
||||
<dt className="text-sm text-gray-500">Gesamtbonus</dt>
|
||||
<dd className="font-medium">
|
||||
{((c.energyDetails.instantBonus ?? 0) + (c.energyDetails.newCustomerBonus ?? 0)).toLocaleString('de-DE')} €
|
||||
</dd>
|
||||
</div>
|
||||
)}
|
||||
{c.energyDetails.previousProviderName && (
|
||||
@@ -2636,7 +2665,8 @@ export default function ContractDetail() {
|
||||
basePrice={c.energyDetails.basePrice}
|
||||
unitPrice={c.energyDetails.unitPrice}
|
||||
unitPriceNt={c.energyDetails.unitPriceNt}
|
||||
bonus={c.energyDetails.bonus}
|
||||
instantBonus={c.energyDetails.instantBonus}
|
||||
newCustomerBonus={c.energyDetails.newCustomerBonus}
|
||||
hasMeter={!!c.energyDetails.meter}
|
||||
contractMeters={c.energyDetails.contractMeters}
|
||||
/>
|
||||
|
||||
@@ -282,7 +282,8 @@ export default function ContractForm() {
|
||||
basePrice: c.energyDetails?.basePrice || '',
|
||||
unitPrice: c.energyDetails?.unitPrice || '',
|
||||
unitPriceNt: c.energyDetails?.unitPriceNt || '',
|
||||
bonus: c.energyDetails?.bonus || '',
|
||||
instantBonus: c.energyDetails?.instantBonus || '',
|
||||
newCustomerBonus: c.energyDetails?.newCustomerBonus || '',
|
||||
// Internet details
|
||||
downloadSpeed: c.internetDetails?.downloadSpeed || '',
|
||||
uploadSpeed: c.internetDetails?.uploadSpeed || '',
|
||||
@@ -522,7 +523,8 @@ export default function ContractForm() {
|
||||
basePrice: data.basePrice ? parseFloat(data.basePrice) : null,
|
||||
unitPrice: data.unitPrice ? parseFloat(data.unitPrice) : null,
|
||||
unitPriceNt: data.unitPriceNt ? parseFloat(data.unitPriceNt) : null,
|
||||
bonus: data.bonus ? parseFloat(data.bonus) : null,
|
||||
instantBonus: data.instantBonus ? parseFloat(data.instantBonus) : null,
|
||||
newCustomerBonus: data.newCustomerBonus ? parseFloat(data.newCustomerBonus) : null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1003,7 +1005,8 @@ export default function ContractForm() {
|
||||
{...register('unitPriceNt')}
|
||||
/>
|
||||
)}
|
||||
<Input label="Bonus (€)" type="number" step="0.01" {...register('bonus')} />
|
||||
<Input label="Sofort-Bonus (€)" type="number" step="0.01" {...register('instantBonus')} />
|
||||
<Input label="Neukunden-Bonus (€)" type="number" step="0.01" {...register('newCustomerBonus')} />
|
||||
</div>
|
||||
|
||||
{/* Hinweis für Zählerstände und Rechnungen */}
|
||||
|
||||
@@ -469,7 +469,8 @@ export interface EnergyContractDetails {
|
||||
basePrice?: number; // €/Monat
|
||||
unitPrice?: number; // €/kWh (Arbeitspreis) - bei HT/NT: HT-Preis
|
||||
unitPriceNt?: number; // €/kWh NT-Preis (nur bei Zweitarifzähler)
|
||||
bonus?: number;
|
||||
instantBonus?: number; // Sofort-Bonus
|
||||
newCustomerBonus?: number; // Neukunden-Bonus
|
||||
previousProviderName?: string;
|
||||
previousCustomerNumber?: string;
|
||||
invoices?: Invoice[]; // Rechnungen
|
||||
|
||||
@@ -23,8 +23,10 @@ export interface CostCalculation {
|
||||
annualConsumptionCostNt?: number; // NT-Verbrauch × unitPriceNt
|
||||
annualTotalCost: number; // Summe
|
||||
monthlyPayment: number; // annualTotalCost / 12
|
||||
bonus?: number;
|
||||
effectiveAnnualCost: number; // annualTotalCost - bonus
|
||||
instantBonus?: number; // Sofort-Bonus
|
||||
newCustomerBonus?: number; // Neukunden-Bonus
|
||||
totalBonus?: number; // Summe = instantBonus + newCustomerBonus
|
||||
effectiveAnnualCost: number; // annualTotalCost - totalBonus
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,9 +209,10 @@ export function calculateCosts(
|
||||
consumptionKwh: number,
|
||||
basePrice?: number,
|
||||
unitPrice?: number,
|
||||
bonus?: number,
|
||||
instantBonus?: number,
|
||||
consumptionNtKwh?: number,
|
||||
unitPriceNt?: number
|
||||
unitPriceNt?: number,
|
||||
newCustomerBonus?: number,
|
||||
): CostCalculation | null {
|
||||
// Mindestens ein Preis muss vorhanden sein
|
||||
if (basePrice == null && unitPrice == null) {
|
||||
@@ -221,7 +224,8 @@ export function calculateCosts(
|
||||
const annualConsumptionCost = consumptionKwh * (unitPrice ?? 0);
|
||||
const annualConsumptionCostNt = (consumptionNtKwh ?? 0) * (unitPriceNt ?? 0);
|
||||
const annualTotalCost = annualBaseCost + annualConsumptionCost + annualConsumptionCostNt;
|
||||
const effectiveAnnualCost = annualTotalCost - (bonus ?? 0);
|
||||
const totalBonus = (instantBonus ?? 0) + (newCustomerBonus ?? 0);
|
||||
const effectiveAnnualCost = annualTotalCost - totalBonus;
|
||||
const monthlyPayment = effectiveAnnualCost / 12;
|
||||
|
||||
return {
|
||||
@@ -230,7 +234,9 @@ export function calculateCosts(
|
||||
annualConsumptionCostNt: annualConsumptionCostNt > 0 ? annualConsumptionCostNt : undefined,
|
||||
annualTotalCost,
|
||||
monthlyPayment,
|
||||
bonus: bonus ?? undefined,
|
||||
instantBonus: instantBonus && instantBonus > 0 ? instantBonus : undefined,
|
||||
newCustomerBonus: newCustomerBonus && newCustomerBonus > 0 ? newCustomerBonus : undefined,
|
||||
totalBonus: totalBonus > 0 ? totalBonus : undefined,
|
||||
effectiveAnnualCost,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user