summaryrefslogtreecommitdiff
path: root/oop/11-point-of-sale/src/main/java/lk/ac/pdn/ceit/pos/entities/Bill.java
blob: c78f88b22ee4166da5702b6af6523977ab598da7 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package lk.ac.pdn.ceit.pos.entities;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class Bill {

    private List<LineItem> lineItems = new ArrayList<>();
    private Cashier cashier;

    private int id;
    private BigDecimal total = new BigDecimal("0.00");
    private BigDecimal tax;
    private BigDecimal cashByCustomer;
    private BigDecimal balance;

    public Bill() {
    }

    public Cashier getCashier() {
        return cashier;
    }

    public void setCashier(Cashier cashier) {
        this.cashier = cashier;
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }

    public BigDecimal getTotal() {
        return total;
    }

    public BigDecimal getTax() {
        return tax;
    }

    public void setTax(BigDecimal tax) {
        this.tax = tax;
    }

    public BigDecimal getCashByCustomer() {
        return cashByCustomer;
    }
    public void setCashByCustomer(BigDecimal cashByCustomer) {
        this.cashByCustomer = cashByCustomer;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    @Override
    public String toString() {
        return "Bill [id=" + id + ", total=" + total + ", tax=" + tax + ", cashByCustomer=" + cashByCustomer
                + ", balance=" + balance + "]";
    }

    public void addLineItem(LineItem lineItem) {
        lineItems.add(lineItem);

        // Update total
        for (LineItem _lineItem : lineItems) {
            total = total.add(_lineItem.getUnitPrice().multiply(BigDecimal.valueOf(_lineItem.getQuantity())));
        }
    }

    public List<LineItem> getLineItems() {
        // TODO: Do a deep copy and return to avoid external modification of line items.
        // We return an immutable copy to avoid external world adding LineItems.
        return List.copyOf(lineItems);
    }
}