1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* part-db version 0.1 |
5
|
|
|
* Copyright (C) 2005 Christoph Lechner |
6
|
|
|
* http://www.cl-projects.de/ |
7
|
|
|
* |
8
|
|
|
* part-db version 0.2+ |
9
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
10
|
|
|
* http://code.google.com/p/part-db/ |
11
|
|
|
* |
12
|
|
|
* Part-DB Version 0.4+ |
13
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
14
|
|
|
* https://github.com/jbtronics |
15
|
|
|
* |
16
|
|
|
* This program is free software; you can redistribute it and/or |
17
|
|
|
* modify it under the terms of the GNU General Public License |
18
|
|
|
* as published by the Free Software Foundation; either version 2 |
19
|
|
|
* of the License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU General Public License |
27
|
|
|
* along with this program; if not, write to the Free Software |
28
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
namespace App\Entity\Parts\PartTraits; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use App\Entity\Parts\Part; |
36
|
|
|
use App\Entity\PriceInformations\Orderdetail; |
37
|
|
|
use App\Security\Annotations\ColumnSecurity; |
38
|
|
|
use Doctrine\Common\Collections\Collection; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* This trait collects all aspects of a part related to orders and priceinformations. |
42
|
|
|
* @package App\Entity\Parts\PartTraits |
43
|
|
|
*/ |
44
|
|
|
trait OrderTrait |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @var Orderdetail[] The details about how and where you can order this part. |
48
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\PriceInformations\Orderdetail", mappedBy="part", cascade={"persist", "remove"}, orphanRemoval=false) |
49
|
|
|
* @Assert\Valid() |
50
|
|
|
* @ColumnSecurity(prefix="orderdetails", type="collection") |
51
|
|
|
*/ |
52
|
|
|
protected $orderdetails; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var int |
56
|
|
|
* @ORM\Column(type="integer") |
57
|
|
|
* @ColumnSecurity(prefix="order", type="integer") |
58
|
|
|
*/ |
59
|
|
|
protected $order_quantity = 0; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var bool |
63
|
|
|
* @ORM\Column(type="boolean") |
64
|
|
|
* @ColumnSecurity(prefix="order", type="boolean") |
65
|
|
|
*/ |
66
|
|
|
protected $manual_order = false; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var Orderdetail |
70
|
|
|
* @ORM\OneToOne(targetEntity="App\Entity\PriceInformations\Orderdetail") |
71
|
|
|
* @ORM\JoinColumn(name="order_orderdetails_id", referencedColumnName="id") |
72
|
|
|
* |
73
|
|
|
* @ColumnSecurity(prefix="order", type="object") |
74
|
|
|
*/ |
75
|
|
|
protected $order_orderdetail; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get the selected order orderdetails of this part. |
79
|
|
|
* @return Orderdetail the selected order orderdetails |
80
|
|
|
*/ |
81
|
|
|
public function getOrderOrderdetails(): ?Orderdetail |
82
|
|
|
{ |
83
|
|
|
return $this->order_orderdetail; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the order quantity of this part. |
88
|
|
|
* @return int the order quantity |
89
|
|
|
*/ |
90
|
|
|
public function getOrderQuantity(): int |
91
|
|
|
{ |
92
|
|
|
return $this->order_quantity; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Check if this part is marked for manual ordering. |
97
|
|
|
* |
98
|
|
|
* @return bool the "manual_order" attribute |
99
|
|
|
*/ |
100
|
|
|
public function isMarkedForManualOrder(): bool |
101
|
|
|
{ |
102
|
|
|
return $this->manual_order; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get all orderdetails of this part. |
107
|
|
|
* |
108
|
|
|
* @param bool $hide_obsolete If true, obsolete orderdetails will NOT be returned |
109
|
|
|
* |
110
|
|
|
* @return Collection|Orderdetail[] * all orderdetails as a one-dimensional array of Orderdetails objects |
111
|
|
|
* (empty array if there are no ones) |
112
|
|
|
* * the array is sorted by the suppliers names / minimum order quantity |
113
|
|
|
* |
114
|
|
|
*/ |
115
|
|
|
public function getOrderdetails(bool $hide_obsolete = false) : Collection |
116
|
|
|
{ |
117
|
|
|
//If needed hide the obsolete entries |
118
|
|
|
if ($hide_obsolete) { |
119
|
|
|
$orderdetails = $this->orderdetails; |
120
|
|
|
foreach ($orderdetails as $key => $details) { |
121
|
|
|
if ($details->getObsolete()) { |
122
|
|
|
unset($orderdetails[$key]); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $orderdetails; |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $this->orderdetails; |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Adds the given orderdetail to list of orderdetails. |
134
|
|
|
* The orderdetail is assigned to this part. |
135
|
|
|
* @param Orderdetail $orderdetail The orderdetail that should be added. |
136
|
|
|
* @return self |
137
|
|
|
*/ |
138
|
|
|
public function addOrderdetail(Orderdetail $orderdetail) : self |
139
|
|
|
{ |
140
|
|
|
$orderdetail->setPart($this); |
141
|
|
|
$this->orderdetails->add($orderdetail); |
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Removes the given orderdetail from the list of orderdetails. |
147
|
|
|
* @param Orderdetail $orderdetail |
148
|
|
|
* @return OrderTrait |
149
|
|
|
*/ |
150
|
|
|
public function removeOrderdetail(Orderdetail $orderdetail) : self |
151
|
|
|
{ |
152
|
|
|
$this->orderdetails->removeElement($orderdetail); |
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Set the "manual_order" attribute. |
158
|
|
|
* |
159
|
|
|
* @param bool $new_manual_order the new "manual_order" attribute |
160
|
|
|
* @param int $new_order_quantity the new order quantity |
161
|
|
|
* @param int|null $new_order_orderdetails_id * the ID of the new order orderdetails |
162
|
|
|
* * or Zero for "no order orderdetails" |
163
|
|
|
* * or NULL for automatic order orderdetails |
164
|
|
|
* (if the part has exactly one orderdetails, |
165
|
|
|
* set this orderdetails as order orderdetails. |
166
|
|
|
* Otherwise, set "no order orderdetails") |
167
|
|
|
* |
168
|
|
|
* @return self |
169
|
|
|
*/ |
170
|
|
|
public function setManualOrder(bool $new_manual_order, int $new_order_quantity = 1, ?Orderdetail $new_order_orderdetail = null): Part |
171
|
|
|
{ |
172
|
|
|
//Assert::greaterThan($new_order_quantity, 0, 'The new order quantity must be greater zero. Got %s!'); |
173
|
|
|
|
174
|
|
|
$this->manual_order = $new_manual_order; |
175
|
|
|
|
176
|
|
|
//TODO; |
177
|
|
|
$this->order_orderdetail = $new_order_orderdetail; |
178
|
|
|
$this->order_quantity = $new_order_quantity; |
179
|
|
|
|
180
|
|
|
return $this; |
|
|
|
|
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Check if this part is obsolete. |
185
|
|
|
* |
186
|
|
|
* A Part is marked as "obsolete" if all their orderdetails are marked as "obsolete". |
187
|
|
|
* If a part has no orderdetails, the part isn't marked as obsolete. |
188
|
|
|
* |
189
|
|
|
* @return bool true, if this part is obsolete. false, if this part isn't obsolete |
190
|
|
|
*/ |
191
|
|
|
public function isObsolete(): bool |
192
|
|
|
{ |
193
|
|
|
$all_orderdetails = $this->getOrderdetails(); |
194
|
|
|
|
195
|
|
|
if (0 === count($all_orderdetails)) { |
196
|
|
|
return false; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
foreach ($all_orderdetails as $orderdetails) { |
200
|
|
|
if (!$orderdetails->getObsolete()) { |
201
|
|
|
return false; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
return true; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
} |