1use crate::amount::Amount;
2use crate::profile::Profile;
3use crate::tax::TaxCategory;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct Party {
7 pub name: String,
8 pub country: String,
9 pub tax_id: Option<String>,
10 pub id_scheme: Option<String>,
12}
13
14impl Party {
15 pub fn new(name: impl Into<String>, country: impl Into<String>) -> Self {
16 Self {
17 name: name.into(),
18 country: country.into(),
19 tax_id: None,
20 id_scheme: None,
21 }
22 }
23}
24
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct Line {
27 pub id: String,
28 pub name: String,
29 pub net: Amount,
30 pub tax: TaxCategory,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct Invoice {
35 pub profile: Profile,
36 pub number: String,
37 pub currency: String,
38 pub seller: Party,
39 pub buyer: Party,
40 pub lines: Vec<Line>,
41 pub tax_total: Amount,
42 pub payable: Amount,
43}
44
45impl Invoice {
46 pub fn line_net_sum(&self) -> Amount {
47 self.lines
48 .iter()
49 .fold(Amount::ZERO, |acc, line| acc.saturating_add(line.net))
50 }
51}