Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
StockOutputConcludeService
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
2.01
0.00% covered (danger)
0.00%
0 / 1
 conclude
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
2.01
1<?php
2
3namespace Domain\StockIO\Services;
4
5use App\Events\ServiceProcessed;
6use App\Models\StockIO\StockIO;
7use App\Models\StockIO\StockIOProduct;
8use App\Models\User;
9use Domain\StockIO\Enums\StockStatusEnum;
10use Domain\StockIO\Exceptions\StockStatusException;
11use Domain\StockIO\Services\StockIOProductConcludeService;
12
13readonly class StockOutputConcludeService
14{
15    /**
16     * @param StockIO $stockIO
17     * @param User $user
18     * @return void
19     */
20    public function conclude(StockIO $stockIO, User $user): void
21    {
22        if (!$stockIO->isReleasedForBilling()) {
23            throw new StockStatusException(__('Output is not in released for billing status.'));
24        }
25        $stockIO->setAttribute('status', StockStatusEnum::CONCLUDED->value);
26        $stockIO->save();
27
28        $stockIO->stockIOProducts()->each(function ($stockIOProduct) use ($user){
29            (new StockIOProductConcludeService())->conclude($stockIOProduct, $user);
30        });        
31
32        ServiceProcessed::dispatch(self::class, $user);
33    }
34
35}