Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| StockOutputConcludeService | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
2.01 | |
0.00% |
0 / 1 |
| conclude | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
2.01 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\StockIO\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\StockIO\StockIO; |
| 7 | use App\Models\StockIO\StockIOProduct; |
| 8 | use App\Models\User; |
| 9 | use Domain\StockIO\Enums\StockStatusEnum; |
| 10 | use Domain\StockIO\Exceptions\StockStatusException; |
| 11 | use Domain\StockIO\Services\StockIOProductConcludeService; |
| 12 | |
| 13 | readonly 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 | } |