diff --git a/app/Http/Controllers/InventoryController.php b/app/Http/Controllers/InventoryController.php index b8f4a76..fcb12a2 100644 --- a/app/Http/Controllers/InventoryController.php +++ b/app/Http/Controllers/InventoryController.php @@ -29,25 +29,40 @@ public function index(TypeInventoryRequest $request) $inventory = Inventory::where('type', $request->type) ->where('organization_id', auth()->user()->organization->id) ->paginate(10); - return response()->json([ - 'inventario' => InventoryCleanResource::collection($inventory), - 'meta' => [ + $filteredInventories = $inventory; + $response = [ + 'inventario' => InventoryCleanResource::collection($filteredInventories), + 'mensaje' => 'Inventario de '.$typeInventory.' obtenido correctamente', + 'estado' => 200 + ]; + if($request->is_available === "true"){ + $filteredInventories = $inventory->filter(function ($inventory) { + $inventory->productInputs = $inventory->productInputs->filter(function ($productInput) { + return $productInput->disponibility > 0; + }); + return $inventory->productInputs->isNotEmpty(); + }); + $response['inventario'] = $filteredInventories; + }else{ + $paginate_meta = [ 'total' => $inventory->total(), 'current_page' => $inventory->currentPage(), 'per_page' => $inventory->perPage(), 'last_page' => $inventory->lastPage(), 'from' => $inventory->firstItem(), 'to' => $inventory->lastItem() - ], - 'links' => [ + ]; + $paginate_links = [ 'prev_page_url' => $inventory->previousPageUrl() ? $inventory->previousPageUrl()."&type=".$request->type : null, 'next_page_url' => $inventory->nextPageUrl() ? $inventory->nextPageUrl()."&type=".$request->type : null, 'last_page_url' => $inventory->url($inventory->lastPage()) ? $inventory->url($inventory->lastPage())."&type=".$request->type : null, 'first_page_url' => $inventory->url(1) ? $inventory->url(1)."&type=".$request->type : null, - ], - 'mensaje' => 'Inventario de '.$typeInventory.' obtenido correctamente', - 'estado' => 200 - ], 200); + ]; + array_push($response, $paginate_meta); + array_push($response, $paginate_links); + } + + return response()->json($response, 200); } catch(Exception $e) { return response()->json([ 'mensaje' => 'Error al obtener el inventario', diff --git a/app/Http/Controllers/ProductInputController.php b/app/Http/Controllers/ProductInputController.php index e200eaa..42b426d 100644 --- a/app/Http/Controllers/ProductInputController.php +++ b/app/Http/Controllers/ProductInputController.php @@ -69,7 +69,10 @@ public function store(StoreProductInputRequest $request, EntryProductService $en public function show(ShowInventoryRequest $request) { try{ - $productInputs = Inventory::find($request->inventory_id)->productInputs()->paginate(10); + $productInputs = Inventory::find($request->inventory_id) + ->productInputs() + ->where('disponibility', '>', 0) + ->paginate(10); return response()->json([ 'entradas' => EntryProductResource::collection($productInputs), 'meta' => [ diff --git a/app/Http/Requests/Inventory/TypeInventoryRequest.php b/app/Http/Requests/Inventory/TypeInventoryRequest.php index d2ab3c0..4bc6c87 100644 --- a/app/Http/Requests/Inventory/TypeInventoryRequest.php +++ b/app/Http/Requests/Inventory/TypeInventoryRequest.php @@ -23,6 +23,7 @@ public function rules(): array { return [ 'type' => 'required|string|in:MP,PT', + 'is_available' => 'in:true,false|nullable', ]; } @@ -37,6 +38,7 @@ public function messages(): array 'type.required' => 'El tipo de inventario es requerido', 'type.string' => 'El tipo de inventario debe ser una cadena de caracteres', 'type.in' => 'El tipo de inventario debe ser MP o PT', + 'is_available.in' => 'El tipo de valor debe ser true o false', ]; } }