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
//! [`billing::PricingModel`] implementation bridge for EEG/KWKG settlement.
//!
//! [`EegSettleTariff`] wraps a pre-computed [`SettleOutput`] and exposes it via
//! the [`billing::PricingModel`] trait with `type Usage = ()`, enabling EEG
//! settlement results to be used in `billing::BillingDocument` generation
//! alongside other pricing models.
//!
//! ## Workflow
//!
//! 1. Call [`crate::calculate_settlement`] to compute the settlement output.
//! 2. Handle non-billable status variants (`NoData`, `PriceMissing`).
//! 3. Wrap the output in [`EegSettleTariff`].
//! 4. Call `.settle(meta)` ([`billing::PricingModel`]) to produce a `BillingDocument`.
//!
//! ## Tax layers
//!
//! `EegSettleTariff::tax_layers()` intentionally returns an **empty** list.
//! The VAT treatment for EEG feed-in depends on the operator's declared tax status:
//! - **Regelbesteuerung (§12 Abs. 1 UStG, 19 %)**: standard-rated (category `S`)
//! - **Kleinunternehmer (§19 UStG)**: no VAT — category `E` (common for residential
//! rooftop PV, the default since the §12 Abs. 3 UStG 0 % hardware supply)
//!
//! The caller adds the appropriate tax layer (via [`crate::ust::ust_tax_layers`])
//! before calling `.settle()`.
//!
//! ## Example
//!
//! ```rust
//! use eeg_billing::{SettleInput, SettlementScheme, SettlementStatus, calculate_settlement};
//! use eeg_billing::tariff::EegSettleTariff;
//! use billing::{DocumentMeta, Period};
//! use rust_decimal::dec;
//!
//! let output = calculate_settlement(&SettleInput {
//! scheme: eeg_billing::SettlementScheme::FeedInTariff { verguetungssatz_ct: dec!(8.11) },
//! einspeisemenge_kwh: Some(dec!(500)),
//! ..SettleInput::default()
//! });
//!
//! assert_eq!(output.status, SettlementStatus::Calculated);
//!
//! let tariff = EegSettleTariff::new(&output);
//! use billing::PricingModel as _;
//! let doc = tariff.settle(
//! DocumentMeta {
//! invoice_number: "EEG-2026-07-001".into(),
//! period_label: "Juli 2026".into(),
//! period: Some(Period::from_display("2026-07-01", "2026-07-31")),
//! issuer_id: Some(billing::PartyIdentifier::new("9904234560001")), // NB MP-ID
//! issue_date: Some("2026-07-13".into()),
//! ..Default::default()
//! },
//! ).unwrap();
//!
//! assert_eq!(doc.net_total(), billing::Amount::parse("40.55000").unwrap());
//! ```
use ;
use dec;
use crate;
// ── EegSettleTariff ──────────────────────────────────────────────────────────
/// [`billing::PricingModel`] adapter for EEG/KWKG settlement results.
///
/// Wraps a pre-computed [`SettleOutput`] and exposes it through the `Tariff` trait
/// so EEG settlement can be composed with other billing positions and documents.
///
/// See [module-level docs](crate::tariff) for usage and VAT guidance.
// ── EegSettleTariffRegelbesteuerung ──────────────────────────────────────────
/// Convenience wrapper that includes 19 % Umsatzsteuer (Regelbesteuerung).
///
/// Correct for:
/// - Commercial operators (Gewerbetreibende)
/// - Operators who opted into Regelbesteuerung
/// - Plants > 30 kWp or commissioned before 01.01.2023
///
/// NOT for Kleinunternehmer (§19 UStG) operators — use
/// [`EegSettleTariffKleinunternehmer`] or [`EegSettleTariff`] for those.
/// Build the Umsatzsteuer layer, naming it with the rate as a percentage.
// ── Status check helpers ──────────────────────────────────────────────────────
/// Convenience alias: `EegSettleTariff` for Kleinunternehmer operators (§19 UStG).
///
/// Produces the same document as `EegSettleTariff` (empty tax layers), but the
/// name makes the VAT reasoning explicit in calling code. The §19 exemption note
/// (category `E`, BT-120) is added by [`crate::ust::ust_tax_layers`].
pub type EegSettleTariffKleinunternehmer<'a> = ;
/// Return `true` when the settlement output can be turned into a billing document.
///
/// `NoData` and `PriceMissing` produce empty documents (no positions to bill);
/// `Sanctioned` produces a EUR 0 audit line via `settlement_to_line_items()`.
/// `FoerderungBeendet` produces an empty document.
/// `Calculated` produces the normal positions.