1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3pub enum TaxSystem {
4 Vat,
5 Gst,
6 Sst,
7 Consumption,
8}
9
10impl TaxSystem {
11 pub fn as_str(self) -> &'static str {
12 match self {
13 Self::Vat => "VAT",
14 Self::Gst => "GST",
15 Self::Sst => "SST",
16 Self::Consumption => "CONSUMPTION",
17 }
18 }
19
20 pub fn parse(s: &str) -> Option<Self> {
21 match s.trim().to_ascii_uppercase().as_str() {
22 "VAT" | "VAT/CGST" => Some(Self::Vat),
23 "GST" => Some(Self::Gst),
24 "SST" | "SALES" | "SERVICE" => Some(Self::Sst),
25 "CONSUMPTION" | "CT" => Some(Self::Consumption),
26 _ => None,
27 }
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, Eq)]
33pub struct TaxCategory {
34 pub system: TaxSystem,
35 pub code: String,
36 pub percent: rust_decimal::Decimal,
37}
38
39impl TaxCategory {
40 pub fn vat(code: impl Into<String>, percent: rust_decimal::Decimal) -> Self {
41 Self {
42 system: TaxSystem::Vat,
43 code: code.into(),
44 percent,
45 }
46 }
47
48 pub fn sst(code: impl Into<String>, percent: rust_decimal::Decimal) -> Self {
49 Self {
50 system: TaxSystem::Sst,
51 code: code.into(),
52 percent,
53 }
54 }
55
56 pub fn gst(code: impl Into<String>, percent: rust_decimal::Decimal) -> Self {
57 Self {
58 system: TaxSystem::Gst,
59 code: code.into(),
60 percent,
61 }
62 }
63}