zugferd_code_lists/zugferd_2_3_3/
allowance.rs

1#![allow(non_camel_case_types)]
2
3#[cfg_attr(feature = "specta", derive(specta::Type))]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
6pub enum Allowance {
7    /// Bonus for works ahead of schedule
8    BonusForWorksAheadSchedule,
9    /// Other bonus
10    OtherBonus,
11    /// Manufacturer’s consumer discount
12    ManufacturerSConsumerDiscount,
13    /// Due to military status
14    DueToMilitaryStatus,
15    /// Due to work accident
16    DueToWorkAccident,
17    /// Special agreement
18    SpecialAgreement,
19    /// Production error discount
20    ProductionErrorDiscount,
21    /// New outlet discount
22    NewOutletDiscount,
23    /// Sample discount
24    SampleDiscount,
25    /// End-of-range discount
26    EndRangeDiscount,
27    /// Incoterm discount
28    IncotermDiscount,
29    /// Point of sales threshold allowance
30    PointSalesThresholdAllowance,
31    /// Material surcharge/deduction
32    MaterialSurchargeDeduction,
33    /// Discount
34    Discount,
35    /// Special rebate
36    SpecialRebate,
37    /// Fixed long term
38    FixedLongTerm,
39    /// Temporary
40    Temporary,
41    /// Standard
42    Standard,
43    /// Yearly turnover
44    YearlyTurnover,
45}
46
47impl std::fmt::Display for Allowance {
48    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49        write!(f, "{}", <Self as crate::Code>::code(*self))
50    }
51}
52
53impl std::str::FromStr for Allowance {
54    type Err = crate::ParseError<Self>;
55    fn from_str(s: &str) -> Result<Self, Self::Err> {
56        <Self as crate::FromCode>::from_code(s)
57            .ok_or_else(|| crate::ParseError::<Self>::new(s.to_owned()))
58    }
59}
60
61impl crate::Code for Allowance {
62    fn code(self) -> &'static str {
63        match self {
64            Allowance::BonusForWorksAheadSchedule => "41",
65            Allowance::OtherBonus => "42",
66            Allowance::ManufacturerSConsumerDiscount => "60",
67            Allowance::DueToMilitaryStatus => "62",
68            Allowance::DueToWorkAccident => "63",
69            Allowance::SpecialAgreement => "64",
70            Allowance::ProductionErrorDiscount => "65",
71            Allowance::NewOutletDiscount => "66",
72            Allowance::SampleDiscount => "67",
73            Allowance::EndRangeDiscount => "68",
74            Allowance::IncotermDiscount => "70",
75            Allowance::PointSalesThresholdAllowance => "71",
76            Allowance::MaterialSurchargeDeduction => "88",
77            Allowance::Discount => "95",
78            Allowance::SpecialRebate => "100",
79            Allowance::FixedLongTerm => "102",
80            Allowance::Temporary => "103",
81            Allowance::Standard => "104",
82            Allowance::YearlyTurnover => "105",
83        }
84    }
85}
86
87impl crate::Description for Allowance {
88    fn description(self) -> &'static str {
89        match self {
90            Allowance::BonusForWorksAheadSchedule => "Bonus for works ahead of schedule",
91            Allowance::OtherBonus => "Other bonus",
92            Allowance::ManufacturerSConsumerDiscount => "Manufacturer’s consumer discount",
93            Allowance::DueToMilitaryStatus => "Due to military status",
94            Allowance::DueToWorkAccident => "Due to work accident",
95            Allowance::SpecialAgreement => "Special agreement",
96            Allowance::ProductionErrorDiscount => "Production error discount",
97            Allowance::NewOutletDiscount => "New outlet discount",
98            Allowance::SampleDiscount => "Sample discount",
99            Allowance::EndRangeDiscount => "End-of-range discount",
100            Allowance::IncotermDiscount => "Incoterm discount",
101            Allowance::PointSalesThresholdAllowance => "Point of sales threshold allowance",
102            Allowance::MaterialSurchargeDeduction => "Material surcharge/deduction",
103            Allowance::Discount => "Discount",
104            Allowance::SpecialRebate => "Special rebate",
105            Allowance::FixedLongTerm => "Fixed long term",
106            Allowance::Temporary => "Temporary",
107            Allowance::Standard => "Standard",
108            Allowance::YearlyTurnover => "Yearly turnover",
109        }
110    }
111}
112
113impl crate::FromCode for Allowance {
114    fn from_code(code: &str) -> Option<Self>
115    where
116        Self: Sized,
117    {
118        match code {
119            "41" => Some(Allowance::BonusForWorksAheadSchedule),
120            "42" => Some(Allowance::OtherBonus),
121            "60" => Some(Allowance::ManufacturerSConsumerDiscount),
122            "62" => Some(Allowance::DueToMilitaryStatus),
123            "63" => Some(Allowance::DueToWorkAccident),
124            "64" => Some(Allowance::SpecialAgreement),
125            "65" => Some(Allowance::ProductionErrorDiscount),
126            "66" => Some(Allowance::NewOutletDiscount),
127            "67" => Some(Allowance::SampleDiscount),
128            "68" => Some(Allowance::EndRangeDiscount),
129            "70" => Some(Allowance::IncotermDiscount),
130            "71" => Some(Allowance::PointSalesThresholdAllowance),
131            "88" => Some(Allowance::MaterialSurchargeDeduction),
132            "95" => Some(Allowance::Discount),
133            "100" => Some(Allowance::SpecialRebate),
134            "102" => Some(Allowance::FixedLongTerm),
135            "103" => Some(Allowance::Temporary),
136            "104" => Some(Allowance::Standard),
137            "105" => Some(Allowance::YearlyTurnover),
138            _ => None,
139        }
140    }
141}