Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| PickingOrderCalculateTotalSeparatedHeightService | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
| calculate | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\PickingOrder\Services; |
| 4 | |
| 5 | use App\Events\ServiceProcessed; |
| 6 | use App\Models\PickingOrder\PickingOrder; |
| 7 | use App\Models\StockIO\StockIOProduct; |
| 8 | use App\Models\User; |
| 9 | use App\Helper\AppHelper; |
| 10 | use Domain\StockIO\Enums\StockProductStatusEnum; |
| 11 | |
| 12 | readonly class PickingOrderCalculateTotalSeparatedHeightService |
| 13 | { |
| 14 | /** |
| 15 | * @param PickingOrder $pickingOrder |
| 16 | * @param User $user |
| 17 | * @return float |
| 18 | */ |
| 19 | public function calculate(PickingOrder $pickingOrder, User $user): float |
| 20 | { |
| 21 | |
| 22 | $separatedWeight = $pickingOrder->load(['stockIOProducts' => function ($query) { |
| 23 | $query->where('stock_io_products.status', '<>', StockProductStatusEnum::CANCELED); |
| 24 | }, |
| 25 | 'stockIOProducts.pickedItems', 'stockIOProducts.product.measure']) |
| 26 | ->stockIOProducts->sum(function (StockIOProduct $stockIOProduct) { |
| 27 | return round($stockIOProduct->pickedItems->sum('amount') * $stockIOProduct->product->measure->getAttribute('gross_weight'), 4); |
| 28 | }); |
| 29 | |
| 30 | ServiceProcessed::dispatch(self::class, $user); |
| 31 | return $separatedWeight; |
| 32 | } |
| 33 | } |