Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PurchaseOrderStoreItemService | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| store | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\PurchaseOrder\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\PurchaseOrder\PurchaseOrderItem; |
| 7 | use App\Models\User; |
| 8 | use Domain\Integration\Services\IntegrationStoreService; |
| 9 | use Domain\PurchaseOrder\DTOs\StorePurchaseOrderItemDTO; |
| 10 | use Illuminate\Support\Facades\DB; |
| 11 | use Throwable; |
| 12 | |
| 13 | readonly class PurchaseOrderStoreItemService |
| 14 | { |
| 15 | public function store(StorePurchaseOrderItemDTO $storePurchaseOrderItemDTO, User $user): PurchaseOrderItem |
| 16 | { |
| 17 | try { |
| 18 | DB::beginTransaction(); |
| 19 | |
| 20 | $purchaseOrderItem = new PurchaseOrderItem(); |
| 21 | $purchaseOrderItem->fill($storePurchaseOrderItemDTO->toArray()); |
| 22 | $purchaseOrderItem->purchaseOrder()->associate($storePurchaseOrderItemDTO->purchase_order_id); |
| 23 | $purchaseOrderItem->product()->associate($storePurchaseOrderItemDTO->product_id); |
| 24 | $purchaseOrderItem->save(); |
| 25 | |
| 26 | (new IntegrationStoreService())->store($storePurchaseOrderItemDTO->integration, $purchaseOrderItem, $user); |
| 27 | |
| 28 | DB::commit(); |
| 29 | } catch (Throwable $exception) { |
| 30 | DB::rollBack(); |
| 31 | throw $exception; |
| 32 | } |
| 33 | |
| 34 | ServiceProcessed::dispatch(self::class, $user); |
| 35 | return $purchaseOrderItem; |
| 36 | } |
| 37 | } |