1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the G.L.S.R. Apps package. |
7
|
|
|
* |
8
|
|
|
* (c) Dev-Int Création <[email protected]>. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Administration\Domain\Supplier\Handler; |
15
|
|
|
|
16
|
|
|
use Administration\Domain\Protocol\Repository\SupplierRepositoryProtocol; |
17
|
|
|
use Administration\Domain\Supplier\Command\EditSupplier; |
18
|
|
|
use Administration\Domain\Supplier\Model\Supplier; |
19
|
|
|
use Core\Domain\Protocol\Common\Command\CommandHandlerProtocol; |
20
|
|
|
|
21
|
|
|
class EditSupplierHandler implements CommandHandlerProtocol |
22
|
|
|
{ |
23
|
|
|
private SupplierRepositoryProtocol $repository; |
24
|
|
|
|
25
|
|
|
public function __construct(SupplierRepositoryProtocol $repository) |
26
|
|
|
{ |
27
|
|
|
$this->repository = $repository; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function __invoke(EditSupplier $command): void |
31
|
|
|
{ |
32
|
|
|
$supplierToUpdate = $this->repository->findOneByUuid($command->uuid()->toString()); |
33
|
|
|
|
34
|
|
|
if (null === $supplierToUpdate) { |
35
|
|
|
throw new \DomainException('Supplier provided does not exist!'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$supplier = $this->updateSupplier($command, $supplierToUpdate); |
39
|
|
|
|
40
|
|
|
$this->repository->add($supplier); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function updateSupplier(EditSupplier $command, Supplier $supplier): Supplier |
44
|
|
|
{ |
45
|
|
|
if ($supplier->name() !== $command->name()) { |
|
|
|
|
46
|
|
|
$supplier->renameSupplier($command->name()); |
47
|
|
|
} |
48
|
|
|
if ($supplier->address() !== $command->address() |
49
|
|
|
|| ($supplier->zipCode() !== $command->zipCode()) |
50
|
|
|
|| ($supplier->town() !== $command->town()) |
51
|
|
|
|| ($supplier->country() !== $command->country()) |
52
|
|
|
) { |
53
|
|
|
$supplier->rewriteAddress([ |
54
|
|
|
$command->address(), |
55
|
|
|
$command->zipCode(), |
56
|
|
|
$command->town(), |
57
|
|
|
$command->country(), |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
if ($supplier->phone() !== $command->phone()) { |
|
|
|
|
61
|
|
|
$supplier->changePhoneNumber($command->phone()); |
62
|
|
|
} |
63
|
|
|
if ($supplier->facsimile() !== $command->facsimile()) { |
|
|
|
|
64
|
|
|
$supplier->changeFacsimileNumber($command->facsimile()); |
65
|
|
|
} |
66
|
|
|
if ($supplier->email() !== $command->email()) { |
|
|
|
|
67
|
|
|
$supplier->rewriteEmail($command->email()); |
68
|
|
|
} |
69
|
|
|
if ($supplier->contact() !== $command->contact()) { |
70
|
|
|
$supplier->renameContact($command->contact()); |
71
|
|
|
} |
72
|
|
|
if ($supplier->cellPhone() !== $command->cellPhone()) { |
|
|
|
|
73
|
|
|
$supplier->changeCellphoneNumber($command->cellPhone()); |
74
|
|
|
} |
75
|
|
|
if ($supplier->familyLog() !== $command->familyLog()) { |
|
|
|
|
76
|
|
|
$supplier->reassignFamilyLog($command->familyLog()); |
77
|
|
|
} |
78
|
|
|
if ($supplier->delayDelivery() !== $command->delayDelivery()) { |
79
|
|
|
$supplier->changeDelayDelivery($command->delayDelivery()); |
80
|
|
|
} |
81
|
|
|
if ($supplier->orderDays() !== $command->orderDays()) { |
82
|
|
|
$supplier->reassignOrderDays($command->orderDays()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $supplier; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|