1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//! German VAT (Umsatzsteuer) rules for EEG/KWKG feed-in settlements.
//!
//! The EEG itself does **not** regulate VAT — those rules come from the
//! Umsatzsteuergesetz (UStG) and BMF circulars. This module models the VAT
//! treatment of the **feed-in Gutschrift** (the payout the Netzbetreiber issues
//! to the Anlagenbetreiber).
//!
//! ## Terminology
//!
//! "Umsatzsteuer" (USt) is the legal term; "Mehrwertsteuer" (MwSt) is the
//! colloquial name. This library uses "Umsatzsteuer" throughout.
//!
//! ## The feed-in has exactly two VAT treatments
//!
//! | Status | Legal basis | EN 16931 category | USt on Vergütung |
//! |---|---|---|---|
//! | `Kleinunternehmer` | §19 UStG | `E` (Exempt) | **None** — tax not levied |
//! | `Regelbesteuerung` | §12 Abs. 1 UStG | `S` (Standard) | **19 %** |
//!
//! This is a **declared property of the operator**, not something the plant's
//! size decides — carry it in masterdata (see `einsd`'s `einspeiser.ust_status`).
//! [`VatStatus::default_for_plant`] only *suggests* the value an operator would
//! usually declare when seeding a new plant record; the stored value wins.
//!
//! ## Why not §12 Abs. 3 UStG?
//!
//! §12 Abs. 3 UStG (the 0 % Nullsteuersatz since 01.01.2023) taxes the **supply
//! and installation of the PV system itself** — the hardware transaction between
//! the installer and the operator. It does **not** apply to the operator's
//! ongoing feed-in of electricity, which is what an EEG settlement bills. Its
//! practical effect on this module is indirect: because a ≤30 kWp operator buys
//! the plant at 0 %, there is no input tax to reclaim, so almost all of them stay
//! **Kleinunternehmer (§19)** rather than opting into Regelbesteuerung. That is
//! why [`VatStatus::default_for_plant`] suggests `Kleinunternehmer` for a small
//! post-2023 solar plant — the 0 % on the feed-in comes from §19, never §12 Abs. 3.
//!
//! ## §19 UStG Kleinunternehmer
//!
//! Operators whose total annual turnover does not exceed **€ 25 000** (from
//! 01.01.2025; previously € 22 000) are treated as Kleinunternehmer and charge no
//! USt on any business income, including EEG feed-in. The Gutschrift shows the
//! §19 exemption reason (EN 16931 BT-120) and no USt.
//!
//! ## Regelbesteuerung
//!
//! All other operators (large plants exceeding the §19 turnover limit, commercial
//! operators, operators who opted into regular taxation) apply standard USt at
//! **19 %** on the Einspeisevergütung / Marktprämie. The Netzbetreiber pays the
//! gross amount (Netto + USt) and deducts the input tax.
//!
//! ## Usage in billing documents
//!
//! ```rust
//! use eeg_billing::ust::{VatStatus, ust_tax_layers};
//! use billing::{DocumentMeta, PricingModel};
//! use eeg_billing::{SettleInput, SettlementScheme, calculate_settlement};
//! use eeg_billing::tariff::EegSettleTariff;
//! use rust_decimal::dec;
//! use time::macros::date;
//!
//! let output = calculate_settlement(&SettleInput {
//! scheme: eeg_billing::SettlementScheme::FeedInTariff { verguetungssatz_ct: dec!(8.51) },
//! einspeisemenge_kwh: Some(dec!(500)),
//! leistung_kwp: Some(dec!(9.5)),
//! inbetriebnahme: Some(date!(2024-06-01)),
//! ..SettleInput::default()
//! });
//!
//! // A small post-2023 solar operator is, by default, a Kleinunternehmer (§19).
//! let vat = VatStatus::default_for_plant(true, dec!(9.5), Some(date!(2024-06-01)));
//! assert_eq!(vat, VatStatus::Kleinunternehmer);
//! assert!(vat.is_exempt());
//!
//! // EegSettleTariff itself adds no tax layer — VAT is the caller's to apply.
//! let tariff = EegSettleTariff::new(&output);
//! assert!(tariff.tax_layers().is_empty());
//!
//! // §19 charges nothing, but still contributes an exempt entry to the
//! // EN 16931 BG-23 breakdown, so the layer is present rather than omitted.
//! let layers = ust_tax_layers(vat);
//! assert_eq!(layers.len(), 1);
//! ```
//!
//! ## §100 EEG Übergangsregelung
//!
//! Plants commissioned **before 01.01.2023** are governed by the EEG version that
//! was in force at their commissioning date (§100 Abs. 1 EEG 2023):
//! "sind die Bestimmungen des EEG in der am 31. Dezember 2022 geltenden Fassung
//! anzuwenden."
//!
//! The Vergütungssatz is fixed at commissioning for the full 20-year Förderdauer.
//! VAT rules depend on the *current* UStG (not the EEG version) and the operator's
//! current tax status — these can change independently of the EEG Vergütungssatz.
use ;
use Decimal;
use dec;
use Date;
use date;
// ── VatStatus ─────────────────────────────────────────────────────────────────
/// The operator's German VAT (Umsatzsteuer) status for EEG feed-in settlement.
///
/// Determines whether USt appears on the feed-in Gutschrift and at what rate. A
/// feed-in has exactly two treatments — [`Kleinunternehmer`](Self::Kleinunternehmer)
/// (§19, 0 %) and [`Regelbesteuerung`](Self::Regelbesteuerung) (19 %).
// ── Tax layers ────────────────────────────────────────────────────────────────
/// Return the `billing::TaxLayer` list for a given VAT status.
///
/// Every status yields exactly one layer, including the exempt one. A supply
/// taxed at 0 % is still a taxable supply: EN 16931 BG-23 requires it to appear
/// in the VAT breakdown under its UNTDID 5305 category. Omitting the layer would
/// drop the turnover from the breakdown altogether, which understates the taxable
/// base on the invoice.
///
/// | Status | Rate | Category | Basis |
/// |---|---|---|---|
/// | `Regelbesteuerung` | 19 % | `S` (Standard) | §12 Abs. 1 UStG |
/// | `Kleinunternehmer` | 0 % | `E` (Exempt) | §19 UStG — tax not levied |
///
/// §19 UStG does not levy the tax at all and maps to `E`, which EN 16931 requires
/// to carry an exemption reason (BT-120).
///
/// Add the returned layers to a `BillingDocument` via `from_positions(…, tax_layers, …)`.
///
/// # Mixed-rate documents
///
/// A document combining supplies with different treatment — a PV feed-in credit at
/// 0 % beside NNE grid charges at 19 % — cannot use a single status. Build the
/// layers directly and restrict each to its own positions with
/// [`FixedRateTax::with_tag`], so each contributes its own breakdown entry.
///
/// # Example
///
/// ```rust
/// use eeg_billing::ust::{VatStatus, ust_tax_layers};
///
/// // Every status yields one layer — the exempt one included.
/// assert_eq!(ust_tax_layers(VatStatus::Kleinunternehmer).len(), 1);
/// assert_eq!(ust_tax_layers(VatStatus::Regelbesteuerung).len(), 1);
/// ```