Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ShippingPackagingRemoveProductService | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| execute | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\ShippingPackaging\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\PickedItem; |
| 7 | use App\Models\ShippingPackaging\ShippingPackaging; |
| 8 | use App\Models\User; |
| 9 | use Domain\Shared\Interfaces\DataTransferObjectInterface; |
| 10 | use Domain\ShippingPackaging\DTOs\ShippingPackagingAddProductDTO; |
| 11 | use Domain\ShippingPackaging\DTOs\ShippingPackagingRemoveProductDTO; |
| 12 | use Domain\ShippingPackaging\Exceptions\ShippingPackingException; |
| 13 | use DomainException; |
| 14 | use Exception; |
| 15 | use Illuminate\Database\Eloquent\Builder; |
| 16 | use Symfony\Component\HttpKernel\Exception\HttpException; |
| 17 | |
| 18 | readonly class ShippingPackagingRemoveProductService extends ShippingPackagingProductService |
| 19 | { |
| 20 | |
| 21 | /** |
| 22 | * @param ShippingPackagingAddProductDTO $dto |
| 23 | * @param ShippingPackaging $shippingPackaging |
| 24 | * @param User $user |
| 25 | * @return void |
| 26 | * @throws Exception |
| 27 | */ |
| 28 | public function execute(DataTransferObjectInterface $dto, ShippingPackaging $shippingPackaging, User $user): void |
| 29 | { |
| 30 | if (!$dto instanceof ShippingPackagingRemoveProductDTO) { |
| 31 | throw new DomainException(__('The DTO is not from a valid instance')); |
| 32 | } |
| 33 | |
| 34 | $pickedItem = $this->fetchPickedItem($dto->stockOutputProduct, $dto->production_order); |
| 35 | |
| 36 | $shippingPackaging->products()->where('picked_item_id', $pickedItem->getKey())->delete(); |
| 37 | |
| 38 | ServiceProcessed::dispatch(self::class, $user); |
| 39 | } |
| 40 | } |