use crate::rates::RegulatoryRates;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum InvoiceType {
Initial,
CreditNote,
Correction {
original_invoice_id: String,
reason: Option<String>,
},
Cancellation {
original_invoice_id: String,
},
Final,
}
impl InvoiceType {
#[must_use]
pub fn rechnungsart(&self) -> &'static str {
match self {
Self::Initial => "ABSCHLAGSRECHNUNG",
Self::CreditNote => "GUTSCHRIFT",
Self::Correction { .. } => "KORREKTURRECHNUNG",
Self::Cancellation { .. } => "STORNORECHNUNG",
Self::Final => "SCHLUSSRECHNUNG",
}
}
#[must_use]
pub fn original_invoice_id(&self) -> Option<&str> {
match self {
Self::Correction {
original_invoice_id,
..
}
| Self::Cancellation {
original_invoice_id,
} => Some(original_invoice_id),
_ => None,
}
}
#[must_use]
pub fn is_reversal(&self) -> bool {
matches!(self, Self::Cancellation { .. })
}
}
#[allow(clippy::derivable_impls)]
impl Default for InvoiceType {
fn default() -> Self {
Self::Initial
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct BillingContext {
pub malo_id: String,
pub lf_mp_id: String,
pub rechnungsnummer: String,
pub period_from: time::Date,
pub period_to: time::Date,
pub invoice_type: InvoiceType,
pub regulatory_rates: RegulatoryRates,
pub contract_id: Option<String>,
}
impl BillingContext {
#[must_use]
pub fn days(&self) -> i64 {
let diff = self.period_to - self.period_from;
diff.whole_days() + 1 }
}