1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* part-db version 0.1 |
7
|
|
|
* Copyright (C) 2005 Christoph Lechner |
8
|
|
|
* http://www.cl-projects.de/. |
9
|
|
|
* |
10
|
|
|
* part-db version 0.2+ |
11
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
12
|
|
|
* http://code.google.com/p/part-db/ |
13
|
|
|
* |
14
|
|
|
* Part-DB Version 0.4+ |
15
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
16
|
|
|
* https://github.com/jbtronics |
17
|
|
|
* |
18
|
|
|
* This program is free software; you can redistribute it and/or |
19
|
|
|
* modify it under the terms of the GNU General Public License |
20
|
|
|
* as published by the Free Software Foundation; either version 2 |
21
|
|
|
* of the License, or (at your option) any later version. |
22
|
|
|
* |
23
|
|
|
* This program is distributed in the hope that it will be useful, |
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26
|
|
|
* GNU General Public License for more details. |
27
|
|
|
* |
28
|
|
|
* You should have received a copy of the GNU General Public License |
29
|
|
|
* along with this program; if not, write to the Free Software |
30
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
namespace App\Entity; |
34
|
|
|
|
35
|
|
|
use Doctrine\ORM\Mapping as ORM; |
36
|
|
|
use Webmozart\Assert\Assert; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Class Pricedetail. |
40
|
|
|
* |
41
|
|
|
* @ORM\Entity() |
42
|
|
|
* @ORM\Table("pricedetails") |
43
|
|
|
*/ |
44
|
|
|
class Pricedetail extends DBElement |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @var Orderdetail |
48
|
|
|
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails") |
49
|
|
|
* @ORM\JoinColumn(name="orderdetails_id", referencedColumnName="id") |
50
|
|
|
*/ |
51
|
|
|
protected $orderdetail; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var float |
55
|
|
|
* @ORM\Column(type="decimal", precision=11, scale=5) |
56
|
|
|
*/ |
57
|
|
|
protected $price; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var int |
61
|
|
|
* @ORM\Column(type="integer") |
62
|
|
|
*/ |
63
|
|
|
protected $price_related_quantity; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var int |
67
|
|
|
* @ORM\Column(type="integer") |
68
|
|
|
*/ |
69
|
|
|
protected $min_discount_quantity; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var bool |
73
|
|
|
* @ORM\Column(type="boolean") |
74
|
|
|
*/ |
75
|
|
|
protected $manual_input; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @ORM\Column(type="datetimetz") |
79
|
|
|
*/ |
80
|
|
|
protected $last_modified; |
81
|
|
|
|
82
|
|
|
/******************************************************************************** |
83
|
|
|
* |
84
|
|
|
* Getters |
85
|
|
|
* |
86
|
|
|
*********************************************************************************/ |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the orderdetails of this pricedetails. |
90
|
|
|
* |
91
|
|
|
* @return Orderdetail the orderdetails object |
92
|
|
|
*/ |
93
|
|
|
public function getOrderdetails(): Orderdetail |
94
|
|
|
{ |
95
|
|
|
return $this->orderdetail; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getPrice() : float |
99
|
|
|
{ |
100
|
|
|
return (float) $this->price; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get the price for a single unit. |
105
|
|
|
* |
106
|
|
|
* @param int $multiplier The returned price (float or string) will be multiplied |
107
|
|
|
* with this multiplier. |
108
|
|
|
* |
109
|
|
|
* You will get the price for $multiplier parts. If you want the price which is stored |
110
|
|
|
* in the database, you have to pass the "price_related_quantity" count as $multiplier. |
111
|
|
|
* |
112
|
|
|
* @return float the price as a float number |
113
|
|
|
|
114
|
|
|
*/ |
115
|
|
|
public function getPricePerUnit(int $multiplier = 1) : float |
116
|
|
|
{ |
117
|
|
|
$price = ($this->price * $multiplier) / $this->price_related_quantity; |
118
|
|
|
|
119
|
|
|
return $price; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get the price related quantity. |
124
|
|
|
* |
125
|
|
|
* This is the quantity, for which the price is valid. |
126
|
|
|
* |
127
|
|
|
* @return int the price related quantity |
128
|
|
|
* |
129
|
|
|
* @see Pricedetails::setPriceRelatedQuantity() |
130
|
|
|
*/ |
131
|
|
|
public function getPriceRelatedQuantity(): int |
132
|
|
|
{ |
133
|
|
|
return $this->price_related_quantity; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get the minimum discount quantity. |
138
|
|
|
* |
139
|
|
|
* "Minimum discount quantity" means the minimum order quantity for which the price |
140
|
|
|
* of this orderdetails is valid. |
141
|
|
|
* |
142
|
|
|
* @return int the minimum discount quantity |
143
|
|
|
* |
144
|
|
|
* @see Pricedetails::setMinDiscountQuantity() |
145
|
|
|
*/ |
146
|
|
|
public function getMinDiscountQuantity(): int |
147
|
|
|
{ |
148
|
|
|
return $this->min_discount_quantity; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/******************************************************************************** |
152
|
|
|
* |
153
|
|
|
* Setters |
154
|
|
|
* |
155
|
|
|
*********************************************************************************/ |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set the price. |
159
|
|
|
* |
160
|
|
|
* @param float $new_price the new price as a float number |
161
|
|
|
* |
162
|
|
|
* * This is the price for "price_related_quantity" parts!! |
163
|
|
|
* * Example: if "price_related_quantity" is '10', |
164
|
|
|
* you have to set here the price for 10 parts! |
165
|
|
|
* |
166
|
|
|
* @return self |
167
|
|
|
*/ |
168
|
|
|
public function setPrice(float $new_price): self |
169
|
|
|
{ |
170
|
|
|
Assert::natural($new_price, 'The new price must be positive! Got %s!'); |
171
|
|
|
|
172
|
|
|
$this->price = $new_price; |
173
|
|
|
|
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Set the price related quantity. |
179
|
|
|
* |
180
|
|
|
* This is the quantity, for which the price is valid. |
181
|
|
|
* |
182
|
|
|
* Example: |
183
|
|
|
* If 100pcs costs 20$, you have to set the price to 20$ and the price related |
184
|
|
|
* quantity to 100. The single price (20$/100 = 0.2$) will be calculated automatically. |
185
|
|
|
* |
186
|
|
|
* @param int $new_price_related_quantity the price related quantity |
187
|
|
|
* |
188
|
|
|
* @return self |
189
|
|
|
*/ |
190
|
|
|
public function setPriceRelatedQuantity(int $new_price_related_quantity): self |
191
|
|
|
{ |
192
|
|
|
Assert::greaterThan($new_price_related_quantity, 0, |
193
|
|
|
'The new price related quantity must be greater zero! Got %s.'); |
194
|
|
|
|
195
|
|
|
$this->price_related_quantity = $new_price_related_quantity; |
196
|
|
|
|
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Set the minimum discount quantity. |
202
|
|
|
* |
203
|
|
|
* "Minimum discount quantity" means the minimum order quantity for which the price |
204
|
|
|
* of this orderdetails is valid. This way, you're able to use different prices |
205
|
|
|
* for different order quantities (quantity discount!). |
206
|
|
|
* |
207
|
|
|
* Example: |
208
|
|
|
* - 1-9pcs costs 10$: set price to 10$/pcs and minimum discount quantity to 1 |
209
|
|
|
* - 10-99pcs costs 9$: set price to 9$/pcs and minimum discount quantity to 10 |
210
|
|
|
* - 100pcs or more costs 8$: set price/pcs to 8$ and minimum discount quantity to 100 |
211
|
|
|
* |
212
|
|
|
* (Each of this examples would be an own Pricedetails-object. |
213
|
|
|
* So the orderdetails would have three Pricedetails for one supplier.) |
214
|
|
|
* |
215
|
|
|
* @param int $new_min_discount_quantity the minimum discount quantity |
216
|
|
|
* |
217
|
|
|
* @return self |
218
|
|
|
*/ |
219
|
|
|
public function setMinDiscountQuantity(int $new_min_discount_quantity): self |
220
|
|
|
{ |
221
|
|
|
Assert::greaterThan($new_min_discount_quantity, 0, |
222
|
|
|
'The new minimum discount quantity must be greater zero! Got %s.'); |
223
|
|
|
|
224
|
|
|
$this->min_discount_quantity = $new_min_discount_quantity; |
225
|
|
|
|
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Returns the ID as an string, defined by the element class. |
231
|
|
|
* This should have a form like P000014, for a part with ID 14. |
232
|
|
|
* |
233
|
|
|
* @return string The ID as a string; |
234
|
|
|
*/ |
235
|
|
|
public function getIDString(): string |
236
|
|
|
{ |
237
|
|
|
return 'PD'.sprintf('%06d', $this->getID()); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|