Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ShippingPackagingRemoveProductService
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 execute
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace Domain\ShippingPackaging\Services;
4
5use App\Events\ServiceProcessed;
6use App\Models\PickedItem;
7use App\Models\ShippingPackaging\ShippingPackaging;
8use App\Models\User;
9use Domain\Shared\Interfaces\DataTransferObjectInterface;
10use Domain\ShippingPackaging\DTOs\ShippingPackagingAddProductDTO;
11use Domain\ShippingPackaging\DTOs\ShippingPackagingRemoveProductDTO;
12use Domain\ShippingPackaging\Exceptions\ShippingPackingException;
13use DomainException;
14use Exception;
15use Illuminate\Database\Eloquent\Builder;
16use Symfony\Component\HttpKernel\Exception\HttpException;
17
18readonly 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}