Skip to main content

core_invoice/
profile.rs

1use crate::tax::TaxSystem;
2
3/// Usage specification (BT-24). Not a ladder: Peppol BIS and PINT are siblings.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum Profile {
6    /// CEN EN 16931-1 core (2017+A1 until 2026 artefacts exist).
7    En16931,
8    /// Peppol BIS Billing 3.0 (EU VAT CIUS).
9    PeppolBis3,
10    /// Peppol International base (tax is not only VAT).
11    Pint,
12    /// PINT-MY specialisation (SST, TIN/BRN schemes).
13    PintMy,
14}
15
16impl Profile {
17    pub fn slug(self) -> &'static str {
18        match self {
19            Self::En16931 => "en16931",
20            Self::PeppolBis3 => "peppol",
21            Self::Pint => "pint",
22            Self::PintMy => "pint-my",
23        }
24    }
25
26    pub fn parse(s: &str) -> Option<Self> {
27        match s.trim().to_ascii_lowercase().as_str() {
28            "en16931" | "en-16931" | "core" => Some(Self::En16931),
29            "peppol" | "bis3" | "peppol-bis-3" => Some(Self::PeppolBis3),
30            "pint" => Some(Self::Pint),
31            "pint-my" | "pintmy" | "my" => Some(Self::PintMy),
32            _ => None,
33        }
34    }
35
36    pub fn specification_id(self) -> &'static str {
37        match self {
38            Self::En16931 => "urn:cen.eu:en16931:2017",
39            Self::PeppolBis3 => {
40                "urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0"
41            }
42            Self::Pint => "urn:peppol:pint:billing-1",
43            Self::PintMy => "urn:peppol:pint:billing-1@my-1",
44        }
45    }
46
47    /// Tax systems this profile accepts.
48    pub fn tax_systems(self) -> &'static [TaxSystem] {
49        match self {
50            Self::En16931 | Self::PeppolBis3 => &[TaxSystem::Vat],
51            Self::Pint | Self::PintMy => &[
52                TaxSystem::Vat,
53                TaxSystem::Gst,
54                TaxSystem::Sst,
55                TaxSystem::Consumption,
56            ],
57        }
58    }
59
60    pub fn allows(self, system: TaxSystem) -> bool {
61        self.tax_systems().contains(&system)
62    }
63}