1 | <?php declare(strict_types=1); |
||
23 | class Report implements ReportInterface |
||
24 | { |
||
25 | use ReportTrait; |
||
26 | use Timestampable; |
||
27 | |||
28 | const STATUS_ERROR = 'error'; |
||
29 | const STATUS_PENDING = 'pending'; |
||
30 | const STATUS_SUCCESSFUL = 'successful'; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | * |
||
35 | * @ORM\Column(type="integer") |
||
36 | * @ORM\GeneratedValue |
||
37 | * @ORM\Id |
||
38 | */ |
||
39 | protected $id; |
||
40 | |||
41 | /** |
||
42 | * @var ManufacturerInterface |
||
43 | * |
||
44 | * @FormAssert\NotBlank() |
||
45 | * |
||
46 | * @ORM\ManyToOne(targetEntity="Loevgaard\DandomainFoundation\Entity\Manufacturer") |
||
47 | * @ORM\JoinColumn(onDelete="CASCADE", nullable=false) |
||
48 | */ |
||
49 | protected $manufacturer; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | * |
||
54 | * @FormAssert\Choice(callback="getStatuses") |
||
55 | * |
||
56 | * @ORM\Column(type="string", length=191) |
||
57 | */ |
||
58 | protected $status; |
||
59 | |||
60 | /** |
||
61 | * @var string|null |
||
62 | * |
||
63 | * @ORM\Column(type="text", nullable=true) |
||
64 | */ |
||
65 | protected $error; |
||
66 | |||
67 | /** |
||
68 | * @var StockMovementInterface[]|ArrayCollection |
||
69 | * |
||
70 | * @ORM\ManyToMany(targetEntity="Loevgaard\DandomainStock\Entity\StockMovement") |
||
71 | * @ORM\JoinTable(name="ldc_reports_stock_movements") |
||
72 | * @ORM\OrderBy({"createdAt" = "ASC"}) |
||
73 | */ |
||
74 | protected $stockMovements; |
||
75 | |||
76 | public function __construct() |
||
81 | |||
82 | public function markAsError(?string $error = null) : void |
||
87 | |||
88 | public function markAsSuccess() : void |
||
93 | |||
94 | public function isStatus(string $status) : bool |
||
98 | |||
99 | public function isSuccessful() : bool |
||
103 | |||
104 | public function isError() : bool |
||
108 | |||
109 | /** |
||
110 | * Returns true if the report can be delivered to the consignor |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isDeliverable() : bool |
||
118 | |||
119 | /** |
||
120 | * @ORM\PrePersist() |
||
121 | * @ORM\PreUpdate() |
||
122 | */ |
||
123 | public function validate() : void |
||
130 | |||
131 | public static function getStatuses() : array |
||
139 | |||
140 | public function addStockMovement(StockMovementInterface $stockMovement) : ReportInterface |
||
148 | |||
149 | public function removeStockMovement(StockMovementInterface $stockMovement) : ReportInterface |
||
155 | |||
156 | public function clearStockMovements() : ReportInterface |
||
162 | |||
163 | /** |
||
164 | * Returns the total for all stock movements |
||
165 | * Returns a Money object with amount = 0 and $defaultCurrency if there are no stock movements |
||
166 | * |
||
167 | * @param string $defaultCurrency |
||
168 | * @return Money |
||
169 | * @throws \Loevgaard\DandomainStock\Exception\UnsetCurrencyException |
||
170 | */ |
||
171 | public function getTotal(string $defaultCurrency = 'DKK') : Money |
||
189 | |||
190 | /** |
||
191 | * @return int |
||
192 | */ |
||
193 | public function getId(): int |
||
197 | |||
198 | /** |
||
199 | * @param int $id |
||
200 | * @return ReportInterface |
||
201 | */ |
||
202 | public function setId(int $id) : ReportInterface |
||
207 | |||
208 | /** |
||
209 | * @return ManufacturerInterface |
||
210 | */ |
||
211 | public function getManufacturer(): ?ManufacturerInterface |
||
215 | |||
216 | /** |
||
217 | * @param ManufacturerInterface $manufacturer |
||
218 | * @return ReportInterface |
||
219 | */ |
||
220 | public function setManufacturer(ManufacturerInterface $manufacturer) : ReportInterface |
||
225 | |||
226 | /** |
||
227 | * @return string |
||
228 | */ |
||
229 | public function getStatus(): ?string |
||
233 | |||
234 | /** |
||
235 | * @param string $status |
||
236 | * @return ReportInterface |
||
237 | */ |
||
238 | public function setStatus(string $status) : ReportInterface |
||
243 | |||
244 | /** |
||
245 | * @return null|string |
||
246 | */ |
||
247 | public function getError(): ?string |
||
251 | |||
252 | /** |
||
253 | * @param null|string $error |
||
254 | * @return ReportInterface |
||
255 | */ |
||
256 | public function setError(?string $error) : ReportInterface |
||
261 | |||
262 | /** |
||
263 | * @return StockMovementInterface[]|ArrayCollection |
||
264 | */ |
||
265 | public function getStockMovements() : Collection |
||
269 | |||
270 | /** |
||
271 | * @param StockMovementInterface[]|Collection $stockMovements |
||
272 | * @return ReportInterface |
||
273 | */ |
||
274 | public function setStockMovements(Collection $stockMovements) : ReportInterface |
||
282 | } |
||
283 |