Ich möchte für den Mieterstrom die Gesetzlichen Steuern (Offshore, EEG usw.) speichern (c# mit onion) und zusätzlich noch die Kosten pro kWh Netzanteil und PV Anteil. Beim Netzanteil sind die steuern schon inkludiert bei PV nicht und muss mit 19% angegeben werden, die gesetzlichen Steuern (Offshore, EEG) beziehen sich nur auf den Netzanteil. Und bei PV gibt es zusätzlich noch einen Grundbetrag der in euro pro Jahr angegen werden soll. Wie könnte ein Modell für so eine Invoice aussehen?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Hier ist ein praxistaugliches Domain‑Modell (C# / Onion) für eine Mieterstrom‑Rechnung, das deine Anforderungen abbildet:
Netzanteil: Preis pro kWh ist bereits brutto inkl. gesetzlicher Umlagen/Abgaben (Offshore, EEG, …). Keine weitere Steuerberechnung.
PV‑Anteil: Preis pro kWh netto, darauf 19% USt. Zusätzlich ein jährlicher PV‑Grundbetrag (netto), anteilig je Rechnungsperiode, ebenfalls mit 19% USt.
Gesetzliche Umlagen/Abgaben werden nur dem Netzanteil zugeordnet und als Breakdown mitgespeichert (für Transparenz/Reporting), aber nicht zusätzlich berechnet.
Levy (Umlage/Abgabe): Name, Betrag/kWh, nur für Netzanteil, “included”.
Domain‑Service: InvoiceFactory/InvoiceCalculator erzeugt Positionen und Summen inkl. USt und Anteiligkeit.
Beispiel C# Domain (vereinfacht)
csharp
// Domain (Core) Layer
public enum InvoiceLineKind { GridEnergy, PvEnergy, PvBaseFee }
public sealed record Levy(string Code, string Name, decimal AmountPerKWh);
public sealed record GridTariff(
decimal PricePerKWhGross, // Brutto, inkl. USt und Umlagen
IReadOnlyCollection<Levy> Levies);
public sealed record PvTariff(
decimal PricePerKWhNet, // Netto
decimal VatRate, // z.B. 0.19m (19%)
decimal AnnualBaseFeeNet); // Netto/Jahr
public sealed class Invoice
{
public Guid Id { get; }
public Guid CustomerId { get; }
public DateOnly PeriodStart { get; }
public DateOnly PeriodEnd { get; } // exklusiv
private readonly List<InvoiceLine> _lines = new();
public IReadOnlyList<InvoiceLine> Lines => _lines;
public Invoice(Guid id, Guid customerId, DateOnly start, DateOnly end)
{
Id = id; CustomerId = customerId; PeriodStart = start; PeriodEnd = end;
}
public void AddLine(InvoiceLine line) => _lines.Add(line);
public decimal TotalGross => Math.Round(Lines.Sum(l => l.Gross), 2, MidpointRounding.AwayFromZero);
public decimal TotalVat => Math.Round(Lines.Sum(l => l.VatAmount), 2, MidpointRounding.AwayFromZero);
public decimal TotalNet => Math.Round(TotalGross - TotalVat, 2, MidpointRounding.AwayFromZero);
}
public sealed class InvoiceLine
{
public InvoiceLineKind Kind { get; }
public string Description { get; }
public decimal Quantity { get; } // kWh oder 1 (für Grundbetrag)
public string Unit { get; } // "kWh" oder "-"
public decimal UnitPrice { get; } // Für Grid = Brutto/kWh; Für PV = Netto
public decimal? VatRate { get; } // null => Preis ist bereits brutto (Grid)
public bool PriceIncludesVat { get; } // Grid=true, PV=false
public IReadOnlyCollection<Levy> IncludedLevies { get; }
public InvoiceLine(InvoiceLineKind kind, string description, decimal quantity, string unit,
decimal unitPrice, decimal? vatRate, bool priceIncludesVat,
IReadOnlyCollection<Levy>? includedLevies = null)
{
Kind = kind; Description = description; Quantity = quantity; Unit = unit;
UnitPrice = unitPrice; VatRate = vatRate; PriceIncludesVat = priceIncludesVat;
IncludedLevies = includedLevies ?? Array.Empty<Levy>();
}
public decimal Net => Round2(Quantity * UnitPrice); // Für Grid entspricht Net=Gross (keine zusätzliche USt)
public decimal VatAmount => PriceIncludesVat ? 0m : Round2(Net * (VatRate ?? 0m));
public decimal Gross => PriceIncludesVat ? Net : Round2(Net + VatAmount);
private static decimal Round2(decimal v) => Math.Round(v, 2, MidpointRounding.AwayFromZero);
}
public static class InvoiceFactory
{
public static Invoice Create(
Guid customerId,
DateOnly start, DateOnly end,
GridTariff gridTariff,
PvTariff pvTariff,
decimal gridConsumptionKWh,
decimal pvConsumptionKWh)
{
var invoice = new Invoice(Guid.NewGuid(), customerId, start, end);
// 1) Netzanteil (brutto/kWh, Umlagen enthalten, keine extra USt)
if (gridConsumptionKWh > 0)
{
invoice.AddLine(new InvoiceLine(
kind: InvoiceLineKind.GridEnergy,
description: "Netzanteil Strom (inkl. Umlagen/Steuern)",
quantity: gridConsumptionKWh,
unit: "kWh",
unitPrice: gridTariff.PricePerKWhGross,
vatRate: null,
priceIncludesVat: true,
includedLevies: gridTariff.Levies
));
}
// 2) PV‑Anteil (netto/kWh, +19% USt)
if (pvConsumptionKWh > 0)
{
invoice.AddLine(new InvoiceLine(
kind: InvoiceLineKind.PvEnergy,
description: "PV‑Anteil Strom",
quantity: pvConsumptionKWh,
unit: "kWh",
unitPrice: pvTariff.PricePerKWhNet,
vatRate: pvTariff.VatRate,
priceIncludesVat: false
));
}
// 3) PV‑Grundbetrag (netto/Jahr, anteilig, +19% USt)
var days = (end.ToDateTime(TimeOnly.MinValue) - start.ToDateTime(TimeOnly.MinValue)).TotalDays;
if (days <= 0) return invoice;
int yearDays = DateTime.IsLeapYear(start.Year) ? 366 : 365;
decimal fraction = (decimal)days / yearDays;
var proratedBaseNet = Math.Round(pvTariff.AnnualBaseFeeNet * fraction, 2, MidpointRounding.AwayFromZero);
if (proratedBaseNet > 0)
{
invoice.AddLine(new InvoiceLine(
kind: InvoiceLineKind.PvBaseFee,
description: $"PV‑Grundbetrag anteilig für {days:0} Tage",
quantity: 1m,
unit: "-",
unitPrice: proratedBaseNet,
vatRate: pvTariff.VatRate,
priceIncludesVat: false
));
}
return invoice;
}
}
Beispielverwendung und Ergebnis
csharp
var gridTariff = new GridTariff(
PricePerKWhGross: 0.32m,
Levies: new [] {
new Levy("OFF", "Offshore‑Netzumlage", 0.004m),
new Levy("EEG", "EEG‑Umlage", 0.000m) // Beispielwert
});
var pvTariff = new PvTariff(
PricePerKWhNet: 0.22m,
VatRate: 0.19m,
AnnualBaseFeeNet: 60m);
var invoice = InvoiceFactory.Create(
customerId: Guid.NewGuid(),
start: new DateOnly(2025, 01, 01),
end: new DateOnly(2025, 03, 31), // exklusiv => 89 Tage (Jan 1..Mar 30)
gridTariff: gridTariff,
pvTariff: pvTariff,
gridConsumptionKWh: 800m,
pvConsumptionKWh: 400m);
// Summen
var gross = invoice.TotalGross; // 800*0.32 + (400*0.22*1.19) + (60 * 89/365)*1.19
var vat = invoice.TotalVat; // USt auf PV-Energie + PV-Grundbetrag
Hinweise zur Darstellung/Transparenz
Netzanteil:
UnitPrice ist brutto/kWh.
IncludedLevies ermöglicht die Aufschlüsselung je kWh, ohne sie doppelt zu berechnen.
PV‑Anteil und PV‑Grundbetrag:
Immer netto hinterlegt, USt separat berechnet (19%).
Summen:
TotalVat enthält nur die PV‑USt.
TotalGross ist die Zahl, die du kassierst.
Runden:
Pro Position auf 2 Nachkommastellen runden (AwayFromZero). Falls du energiewirtschaftliche Anforderungen hast (z. B. 3–4 Nachkommastellen bei kWh oder kWh‑Preisen, Rundung erst am Positionsende), passe das an.