1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use super::{Money, Amount, BillProduct};

/// Maps a `BillProduct` to an amount.
#[derive(Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize))]
pub struct BillItem<P> {
    pub amount: Amount,
    pub product: P,
}

impl<P:BillProduct> BillItem<P> {
    /// `price * amount`
    pub fn gross(&self) -> Money {
        self.product.price() * self.amount
    }

    /// `price * tax * amount`, tax being less than 1.0
    pub fn tax(&self) -> Money {
        self.product.price() * **self.product.tax() * self.amount
    }

    /// `gross + tax`
    pub fn net(&self) -> Money {
        self.gross() + self.tax()
    }
}