1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\Dandomain\Pay\Model; |
4
|
|
|
|
5
|
|
|
use Brick\Math\BigDecimal; |
6
|
|
|
use Money\Money; |
7
|
|
|
|
8
|
|
|
class PaymentLine |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $productNumber; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
protected $quantity; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The price excl vat. |
27
|
|
|
* |
28
|
|
|
* @var Money |
29
|
|
|
*/ |
30
|
|
|
protected $price; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* This is the VAT percentage, i.e. 25 for Denmark. |
34
|
|
|
* |
35
|
|
|
* @var int |
36
|
|
|
*/ |
37
|
|
|
protected $vat; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Payment |
41
|
|
|
*/ |
42
|
|
|
protected $payment; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $productNumber |
46
|
|
|
* @param string $name |
47
|
|
|
* @param int $quantity |
48
|
|
|
* @param Money $price |
49
|
|
|
* @param int $vat |
50
|
|
|
*/ |
51
|
9 |
|
public function __construct(string $productNumber, string $name, int $quantity, Money $price, int $vat) |
52
|
|
|
{ |
53
|
9 |
|
$this->setProductNumber($productNumber) |
54
|
9 |
|
->setName($name) |
55
|
9 |
|
->setQuantity($quantity) |
56
|
9 |
|
->setPrice($price) |
57
|
9 |
|
->setVat($vat); |
58
|
9 |
|
} |
59
|
|
|
|
60
|
|
|
/****************** |
61
|
|
|
* Helper methods * |
62
|
|
|
*****************/ |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return Money |
66
|
|
|
*/ |
67
|
3 |
|
public function getPriceExclVat(): Money |
68
|
|
|
{ |
69
|
3 |
|
return $this->getPrice(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return Money |
74
|
|
|
*/ |
75
|
3 |
|
public function getPriceInclVat(): Money |
76
|
|
|
{ |
77
|
3 |
|
return $this->getPriceExclVat()->add($this->getVatAmount()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return Money |
82
|
|
|
*/ |
83
|
3 |
|
public function getVatAmount(): Money |
84
|
|
|
{ |
85
|
3 |
|
$multiplier = $this->getVat() / 100; |
86
|
|
|
|
87
|
3 |
|
return $this->getPriceExclVat()->multiply($multiplier); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/********************* |
91
|
|
|
* Getters / Setters * |
92
|
|
|
********************/ |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
6 |
|
public function getProductNumber(): string |
98
|
|
|
{ |
99
|
6 |
|
return $this->productNumber; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $productNumber |
104
|
|
|
* |
105
|
|
|
* @return PaymentLine |
106
|
|
|
*/ |
107
|
9 |
|
public function setProductNumber(string $productNumber): self |
108
|
|
|
{ |
109
|
9 |
|
$this->productNumber = $productNumber; |
110
|
|
|
|
111
|
9 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
6 |
|
public function getName(): string |
118
|
|
|
{ |
119
|
6 |
|
return $this->name; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param string $name |
124
|
|
|
* |
125
|
|
|
* @return PaymentLine |
126
|
|
|
*/ |
127
|
9 |
|
public function setName(string $name): self |
128
|
|
|
{ |
129
|
9 |
|
$this->name = $name; |
130
|
|
|
|
131
|
9 |
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return int |
136
|
|
|
*/ |
137
|
6 |
|
public function getQuantity(): int |
138
|
|
|
{ |
139
|
6 |
|
return $this->quantity; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param int $quantity |
144
|
|
|
* |
145
|
|
|
* @return PaymentLine |
146
|
|
|
*/ |
147
|
9 |
|
public function setQuantity(int $quantity): self |
148
|
|
|
{ |
149
|
9 |
|
$this->quantity = $quantity; |
150
|
|
|
|
151
|
9 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns the price excl vat. |
156
|
|
|
* |
157
|
|
|
* @return Money |
158
|
|
|
*/ |
159
|
6 |
|
public function getPrice(): Money |
160
|
|
|
{ |
161
|
6 |
|
return $this->price; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param Money $price |
166
|
|
|
* |
167
|
|
|
* @return PaymentLine |
168
|
|
|
*/ |
169
|
9 |
|
public function setPrice(Money $price): self |
170
|
|
|
{ |
171
|
9 |
|
$this->price = $price; |
172
|
|
|
|
173
|
9 |
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Returns the VAT percentage. |
178
|
|
|
* |
179
|
|
|
* @return int |
180
|
|
|
*/ |
181
|
6 |
|
public function getVat(): int |
182
|
|
|
{ |
183
|
6 |
|
return $this->vat; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param int $vat |
188
|
|
|
* |
189
|
|
|
* @return PaymentLine |
190
|
|
|
*/ |
191
|
9 |
|
public function setVat(int $vat): self |
192
|
|
|
{ |
193
|
9 |
|
$this->vat = $vat; |
194
|
|
|
|
195
|
9 |
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return Payment |
200
|
|
|
*/ |
201
|
3 |
|
public function getPayment(): Payment |
202
|
|
|
{ |
203
|
3 |
|
return $this->payment; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param Payment $payment |
208
|
|
|
* |
209
|
|
|
* @return PaymentLine |
210
|
|
|
*/ |
211
|
6 |
|
public function setPayment(Payment $payment): self |
212
|
|
|
{ |
213
|
6 |
|
$this->payment = $payment; |
214
|
|
|
|
215
|
6 |
|
return $this; |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|