-
Notifications
You must be signed in to change notification settings - Fork 0
/
Invoice.cs
111 lines (100 loc) · 2.75 KB
/
Invoice.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
namespace DataMiner
{
class Invoice
{
Dictionary<Product, int> order = new Dictionary<Product, int>();
string invoiceNumber;
Customer customer;
DateTime transactionTime;
public Customer Customer
{
get
{
return customer;
}
private set
{
customer = value;
}
}
public DateTime TransactionTime
{
get
{
return transactionTime;
}
private set
{
transactionTime = value;
}
}
public string InvoiceNumber
{
get
{
return invoiceNumber;
}
private set
{
invoiceNumber = value;
}
}
public Dictionary<Product, int> Order
{
get
{
return order;
}
}
public Invoice(string invoiceNumber, Customer customer, DateTime transactionTime)
{
InvoiceNumber = invoiceNumber;
Customer = customer;
TransactionTime = transactionTime;
}
/// <summary>
/// Adds a product to an invoice
/// </summary>
/// <param name="product">The product to be added</param>
/// <param name="quantity">How many of the product to add (default is one)</param>
public void AddProduct(Product product, int quantity)
{
KeyValuePair<Product, int> foundPair = new KeyValuePair<Product, int>();
foreach (KeyValuePair<Product, int> pair in order)
{
if (pair.Key == product)
foundPair = pair;
}
order.Remove(product);
order.Add(product, foundPair.Value + quantity);
}
/// <summary>
/// Find the total quantity of products on an invoice
/// </summary>
/// <returns>The quantity of items</returns>
public int TotalQuantity()
{
int total = 0;
foreach (KeyValuePair<Product, int> item in order)
{
total += item.Value;
}
return total;
}
/// <summary>
/// Find the total value of products on an invoice
/// </summary>
/// <returns>The value of items</returns>
public float TotalValue()
{
float total = 0.0f;
foreach (KeyValuePair<Product, int> item in order)
{
total += item.Key.UnitPrice * item.Value;
}
return total;
}
}
}