USt-Behandlung: Netto-Preise, VatResolver und Steuer-Ausweis im MAN-Kreis

Einwand/Entscheidung 12.06.2026: Legacy fakturierte brutto (Steuer
inkludiert, z. B. 199 Euro; steuerbefreite Kunden mit Netto-Ausweis
167,23). Alle neuen Preise sind netto; die Steuer wird zur
Rechnungsstellung sauber validiert und ausgewiesen.

- VatResolver + VatTreatment: DE grundsaetzlich immer mit Steuer, EU nur
  mit (formal plausibler) USt-ID befreit (Reverse Charge inkl.
  Pflichthinweis), Drittlaender grundsaetzlich befreit;
  EU-Laenderliste + vat_rate in config/billing.php
- Schema: billing_addresses.vat_id + invoice_billing_addresses.vat_id
  (Snapshot pro Rechnung), invoices.tax_note; Profil-Formular schreibt
  die vorhandene USt-ID jetzt auch an die Rechnungsadresse
- ManualInvoiceService: rechnet auf Netto-Vertragsbasis
  (legacy_conditions.net_cents bzw. Netto-Katalogpreis) und bestimmt
  Steuer/is_netto/tax_note pro Rechnung ueber den VatResolver
- legacy:grandfather-subscriptions: leitet net_cents aus der letzten
  Legacy-Rechnung ab (brutto / 1,19 bzw. is_netto-Betrag direkt);
  fuer DE-Bestandskunden bleibt der Bruttobetrag unveraendert
  (199 brutto -> 167,23 netto + 31,77 USt = 199,00)
- Doku: Decision-Update 2.1 (Netto-Klarstellung), Phase-9-Plan,
  Checkliste, 05-DATABASE-MERGE 5.6; offen: VIES-Validierung der USt-ID

Tests: VatResolverTest (Datasets fuer alle Faelle), Reverse-Charge/
EU-/Drittland-Rechnungen, Netto-Ableitung; Suite 490 passed, 4 skipped.
Pint clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-12 10:58:43 +00:00
parent 1cd4d8e33a
commit 894a9436b0
19 changed files with 497 additions and 46 deletions

View file

@ -22,14 +22,19 @@ use Illuminate\Support\Facades\Log;
* weitergeschaltet. Neue Abschlüsse laufen ausschließlich über Stripe
* (STR-Kreis) und werden hier bewusst ausgeklammert.
*
* Konditions-Overrides pro Vereinbarung über `legacy_conditions` (JSON):
* `amount_cents`, `tax_cents`, `total_cents`, `interval` (monthly|yearly).
* Ohne Override gilt der Netto-Preis der `payment_option` plus
* `billing.vat_rate`.
* Preisbasis ist immer NETTO (Entscheidung 12.06.2026): `legacy_conditions.
* net_cents` (von der Grandfather-Migration aus den Brutto-/Netto-Beträgen
* der letzten Legacy-Rechnung abgeleitet), sonst der Netto-Preis der
* `payment_option`. Die Steuer wird zur Rechnungsstellung über den
* `VatResolver` bestimmt und sauber ausgewiesen (DE immer mit Steuer,
* EU nur mit gültiger USt-ID befreit, Drittland befreit).
*/
class ManualInvoiceService
{
public function __construct(private readonly InvoiceNumberGenerator $numbers) {}
public function __construct(
private readonly InvoiceNumberGenerator $numbers,
private readonly VatResolver $vat,
) {}
/**
* @return Collection<int, UserPaymentOption>
@ -87,9 +92,14 @@ class ManualInvoiceService
return null;
}
[$amountCents, $taxCents, $totalCents] = $this->resolveAmounts($option);
$netCents = $this->resolveNetCents($option);
return DB::transaction(function () use ($option, $user, $billingAddress, $amountCents, $taxCents, $totalCents, $interval, $asOf): Invoice {
// USt zur Rechnungsstellung bestimmen: DE immer mit Steuer, EU nur
// mit gültiger USt-ID befreit (Reverse Charge), Drittland befreit.
$treatment = $this->vat->resolve($billingAddress->country_code, $billingAddress->vat_id);
$taxCents = $this->vat->taxCentsFor($netCents, $treatment);
return DB::transaction(function () use ($option, $user, $billingAddress, $netCents, $taxCents, $treatment, $interval, $asOf): Invoice {
// Adresse pro Rechnung einfrieren (Snapshot-Tabelle).
$addressSnapshot = InvoiceBillingAddress::query()->create([
'salutation_key' => $billingAddress->salutation_key,
@ -100,6 +110,7 @@ class ManualInvoiceService
'postal_code' => $billingAddress->postal_code,
'city' => $billingAddress->city,
'country_code' => $billingAddress->country_code,
'vat_id' => $billingAddress->vat_id,
]);
$invoice = Invoice::query()->create([
@ -107,10 +118,12 @@ class ManualInvoiceService
'invoice_billing_address_id' => $addressSnapshot->id,
'number' => $this->numbers->nextManualNumber(),
'status' => InvoiceStatus::Open->value,
'amount_cents' => $amountCents,
'amount_cents' => $netCents,
'tax_cents' => $taxCents,
'total_cents' => $totalCents,
'total_cents' => $netCents + $taxCents,
'currency' => $option->paymentOption?->currency ?? 'EUR',
'is_netto' => $treatment->isTaxExempt(),
'tax_note' => $treatment->taxNote(),
'invoice_date' => $asOf,
'due_date' => $asOf->copy()->addDays((int) config('billing.manual_due_days', 14)),
]);
@ -135,22 +148,14 @@ class ManualInvoiceService
}
/**
* @return array{0: int, 1: int, 2: int} [amount_cents, tax_cents, total_cents]
* Netto-Vertragsbasis der Vereinbarung. Alle neuen Preise sind netto;
* für Grandfathered-Vereinbarungen liefert die Migration `net_cents`
* (aus den Brutto-/Netto-Beträgen der letzten Legacy-Rechnung).
*/
private function resolveAmounts(UserPaymentOption $option): array
private function resolveNetCents(UserPaymentOption $option): int
{
$conditions = $option->legacy_conditions ?? [];
if (isset($conditions['amount_cents'], $conditions['total_cents'])) {
$amount = (int) $conditions['amount_cents'];
$total = (int) $conditions['total_cents'];
return [$amount, (int) ($conditions['tax_cents'] ?? $total - $amount), $total];
}
$amount = (int) ($conditions['amount_cents'] ?? $option->paymentOption?->price_cents ?? 0);
$tax = (int) round($amount * (float) config('billing.vat_rate', 0.19));
return [$amount, $tax, $amount + $tax];
return (int) ($conditions['net_cents'] ?? $option->paymentOption?->price_cents ?? 0);
}
}