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() || '',
|
||||
|
||||
Reference in New Issue
Block a user