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);