Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| StockOIResource | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
1 | |
0.00% |
0 / 1 |
| toArray | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Domain\StockIO\Resources; |
| 4 | |
| 5 | use App\Models\Transferable\Transferable; |
| 6 | use Domain\Integration\Resources\IntegrationResource; |
| 7 | use Domain\PickingOrder\Resources\PickingOrderResource; |
| 8 | use Domain\PickingOrder\Services\StockOutputPickedListService; |
| 9 | use Domain\Shared\Enums\SectorEnum; |
| 10 | use Domain\StockIO\Enums\StockStatusEnum; |
| 11 | use Domain\StockIO\Enums\StockTypeEnum; |
| 12 | use Domain\Team\Resources\TeamResource; |
| 13 | use Domain\Transferable\Resources\TransferableItemsResource; |
| 14 | use Domain\User\Resources\UserResource; |
| 15 | use Illuminate\Database\Eloquent\Collection; |
| 16 | use Illuminate\Http\Request; |
| 17 | use Illuminate\Http\Resources\Json\JsonResource; |
| 18 | |
| 19 | /** |
| 20 | * @property StockStatusEnum $status |
| 21 | * @property ?string $observation |
| 22 | * @property Collection $items |
| 23 | * @property StockTypeEnum $type |
| 24 | * @property array $data |
| 25 | * @property int $id |
| 26 | * @property Transferable|null $transferable |
| 27 | * @property string $created_at |
| 28 | * @property bool $urgent |
| 29 | * @property int $reason |
| 30 | * @property SectorEnum $sector |
| 31 | */ |
| 32 | class StockOIResource extends JsonResource |
| 33 | { |
| 34 | public function toArray(Request $request): array |
| 35 | { |
| 36 | return [ |
| 37 | 'id' => $this->id, |
| 38 | 'transferable_id' => $this->whenLoaded('transferable', $this->transferable?->getKey()), |
| 39 | 'urgent' => $this->urgent, |
| 40 | 'observation' => $this->observation, |
| 41 | 'status' => $this->status->value, |
| 42 | 'type' => $this->type->value, |
| 43 | 'reason'=> $this->reason, |
| 44 | 'sector' => $this->sector->value, |
| 45 | 'team'=> TeamResource::make($this->whenLoaded('team')), |
| 46 | 'created_at' => (string) $this->created_at, |
| 47 | 'responsible' => UserResource::make($this->whenLoaded('responsible')), |
| 48 | 'items' => TransferableItemsResource::collection($this->whenLoaded('items')), |
| 49 | 'products_separation' => StockIOProductResource::collection($this->whenLoaded('stockIOProducts')), |
| 50 | 'products_remaining' => $this->whenLoaded('stockIOProducts', function () { |
| 51 | return (new StockOutputPickedListService())->list($this->resource); |
| 52 | }), |
| 53 | 'picking_orders' => PickingOrderResource::collection($this->whenLoaded('pickingOrders')), |
| 54 | 'integration' => IntegrationResource::make($this->whenLoaded('integration')), |
| 55 | ]; |
| 56 | } |
| 57 | } |