From f184e4d444f7f9d66032534aeb690900b6193404 Mon Sep 17 00:00:00 2001 From: Juan Felipe Zapata Moreno Date: Wed, 25 Feb 2026 13:35:53 -0600 Subject: [PATCH] =?UTF-8?q?feat:=20agregar=20soporte=20para=20subcategor?= =?UTF-8?q?=C3=ADas=20en=20el=20controlador=20de=20inventario=20y=20solici?= =?UTF-8?q?tudes,=20incluyendo=20validaciones=20en=20las=20reglas=20de=20a?= =?UTF-8?q?lmacenamiento=20y=20actualizaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/App/InventoryController.php | 6 +++--- app/Http/Controllers/App/SubcategoryController.php | 1 - app/Http/Requests/App/InventoryStoreRequest.php | 1 + app/Http/Requests/App/InventoryUpdateRequest.php | 1 + app/Services/ProductService.php | 2 ++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/App/InventoryController.php b/app/Http/Controllers/App/InventoryController.php index 97eaba0..cb5f5ea 100644 --- a/app/Http/Controllers/App/InventoryController.php +++ b/app/Http/Controllers/App/InventoryController.php @@ -24,7 +24,7 @@ public function __construct( public function index(Request $request) { - $products = Inventory::with(['category', 'price', 'unitOfMeasure'])->withCount('serials') + $products = Inventory::with(['category', 'subcategory', 'price', 'unitOfMeasure'])->withCount('serials') ->where('is_active', true); @@ -61,7 +61,7 @@ public function index(Request $request) public function show(Inventory $inventario) { return ApiResponse::OK->response([ - 'model' => $inventario->load(['category', 'price', 'unitOfMeasure'])->loadCount('serials') + 'model' => $inventario->load(['category', 'subcategory', 'price', 'unitOfMeasure'])->loadCount('serials') ]); } @@ -96,7 +96,7 @@ public function destroy(Inventory $inventario) public function getProductsByWarehouse(Request $request, int $warehouseId) { $query = Inventory::query() - ->with(['category', 'price', 'unitOfMeasure']) + ->with(['category', 'subcategory', 'price', 'unitOfMeasure']) ->where('is_active', true) ->whereHas('warehouses', function ($q) use ($warehouseId) { $q->where('warehouse_id', $warehouseId) diff --git a/app/Http/Controllers/App/SubcategoryController.php b/app/Http/Controllers/App/SubcategoryController.php index f72b7ed..89a1a0d 100644 --- a/app/Http/Controllers/App/SubcategoryController.php +++ b/app/Http/Controllers/App/SubcategoryController.php @@ -12,7 +12,6 @@ class SubcategoryController extends Controller public function index(Category $category) { $subcategorias = $category->subcategories() - ->where('is_active', true) ->orderBy('name') ->paginate(config('app.pagination')); diff --git a/app/Http/Requests/App/InventoryStoreRequest.php b/app/Http/Requests/App/InventoryStoreRequest.php index 927b97e..222fd83 100644 --- a/app/Http/Requests/App/InventoryStoreRequest.php +++ b/app/Http/Requests/App/InventoryStoreRequest.php @@ -25,6 +25,7 @@ public function rules(): array 'sku' => ['nullable', 'string', 'max:50', 'unique:inventories,sku'], 'barcode' => ['nullable', 'string', 'unique:inventories,barcode'], 'category_id' => ['required', 'exists:categories,id'], + 'subcategory_id' => ['nullable', 'exists:subcategories,id'], 'unit_of_measure_id' => ['required', 'exists:units_of_measurement,id'], 'track_serials' => ['nullable', 'boolean'], diff --git a/app/Http/Requests/App/InventoryUpdateRequest.php b/app/Http/Requests/App/InventoryUpdateRequest.php index c984507..ff23a4c 100644 --- a/app/Http/Requests/App/InventoryUpdateRequest.php +++ b/app/Http/Requests/App/InventoryUpdateRequest.php @@ -27,6 +27,7 @@ public function rules(): array 'sku' => ['nullable', 'string', 'max:50'], 'barcode' => ['nullable', 'string', 'unique:inventories,barcode,' . $inventoryId], 'category_id' => ['nullable', 'exists:categories,id'], + 'subcategory_id' => ['nullable', 'exists:subcategories,id'], 'unit_of_measure_id' => ['nullable', 'exists:units_of_measurement,id'], 'track_serials' => ['nullable', 'boolean'], diff --git a/app/Services/ProductService.php b/app/Services/ProductService.php index d276df3..3fced45 100644 --- a/app/Services/ProductService.php +++ b/app/Services/ProductService.php @@ -15,6 +15,7 @@ public function createProduct(array $data) 'sku' => $data['sku'], 'barcode' => $data['barcode'] ?? null, 'category_id' => $data['category_id'], + 'subcategory_id' => $data['subcategory_id'] ?? null, 'unit_of_measure_id' => $data['unit_of_measure_id'], 'track_serials' => $data['track_serials'] ?? false, ]); @@ -40,6 +41,7 @@ public function updateProduct(Inventory $inventory, array $data) 'sku' => $data['sku'] ?? null, 'barcode' => $data['barcode'] ?? null, 'category_id' => $data['category_id'] ?? null, + 'subcategory_id' => $data['subcategory_id'] ?? null, 'unit_of_measure_id' => $data['unit_of_measure_id'] ?? null, 'track_serials' => $data['track_serials'] ?? null, ], fn($value) => $value !== null);