Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
StockIOProductConcludeService
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
3.33
0.00% covered (danger)
0.00%
0 / 1
 conclude
66.67% covered (warning)
66.67%
6 / 9
0.00% covered (danger)
0.00%
0 / 1
3.33
1<?php
2
3namespace Domain\StockIO\Services;
4
5use App\Events\ServiceProcessed;
6use App\Models\StockIO\StockIOProduct;
7use App\Models\User;
8use Domain\StockIO\Enums\StockProductStatusEnum;
9use Illuminate\Support\Facades\DB;
10use Throwable;
11
12readonly class StockIOProductConcludeService
13{
14    /**
15     * @param StockIOProduct $stockIOProduct
16     * @param User $user
17     * @return void
18     * @throws Throwable
19     */
20    public function conclude(StockIOProduct $stockIOProduct, User $user): void
21    {
22        try {
23            DB::beginTransaction();
24
25            if($stockIOProduct->status <> StockProductStatusEnum::CANCELED){
26                $stockIOProduct->setAttribute('status', StockProductStatusEnum::CONCLUDED);
27                $stockIOProduct->save();
28            }
29
30            DB::commit();
31        } catch (Throwable $throwable) {
32            DB::rollBack();
33            throw $throwable;
34        }
35
36        ServiceProcessed::dispatch(self::class, $user);
37    }
38}