feat: agregar soporte para subcategorías en el controlador de inventario y solicitudes, incluyendo validaciones en las reglas de almacenamiento y actualización

This commit is contained in:
Juan Felipe Zapata Moreno 2026-02-25 13:35:53 -06:00
parent 37f91d84f2
commit f184e4d444
5 changed files with 7 additions and 4 deletions

View File

@ -24,7 +24,7 @@ public function __construct(
public function index(Request $request) 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); ->where('is_active', true);
@ -61,7 +61,7 @@ public function index(Request $request)
public function show(Inventory $inventario) public function show(Inventory $inventario)
{ {
return ApiResponse::OK->response([ 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) public function getProductsByWarehouse(Request $request, int $warehouseId)
{ {
$query = Inventory::query() $query = Inventory::query()
->with(['category', 'price', 'unitOfMeasure']) ->with(['category', 'subcategory', 'price', 'unitOfMeasure'])
->where('is_active', true) ->where('is_active', true)
->whereHas('warehouses', function ($q) use ($warehouseId) { ->whereHas('warehouses', function ($q) use ($warehouseId) {
$q->where('warehouse_id', $warehouseId) $q->where('warehouse_id', $warehouseId)

View File

@ -12,7 +12,6 @@ class SubcategoryController extends Controller
public function index(Category $category) public function index(Category $category)
{ {
$subcategorias = $category->subcategories() $subcategorias = $category->subcategories()
->where('is_active', true)
->orderBy('name') ->orderBy('name')
->paginate(config('app.pagination')); ->paginate(config('app.pagination'));

View File

@ -25,6 +25,7 @@ public function rules(): array
'sku' => ['nullable', 'string', 'max:50', 'unique:inventories,sku'], 'sku' => ['nullable', 'string', 'max:50', 'unique:inventories,sku'],
'barcode' => ['nullable', 'string', 'unique:inventories,barcode'], 'barcode' => ['nullable', 'string', 'unique:inventories,barcode'],
'category_id' => ['required', 'exists:categories,id'], 'category_id' => ['required', 'exists:categories,id'],
'subcategory_id' => ['nullable', 'exists:subcategories,id'],
'unit_of_measure_id' => ['required', 'exists:units_of_measurement,id'], 'unit_of_measure_id' => ['required', 'exists:units_of_measurement,id'],
'track_serials' => ['nullable', 'boolean'], 'track_serials' => ['nullable', 'boolean'],

View File

@ -27,6 +27,7 @@ public function rules(): array
'sku' => ['nullable', 'string', 'max:50'], 'sku' => ['nullable', 'string', 'max:50'],
'barcode' => ['nullable', 'string', 'unique:inventories,barcode,' . $inventoryId], 'barcode' => ['nullable', 'string', 'unique:inventories,barcode,' . $inventoryId],
'category_id' => ['nullable', 'exists:categories,id'], 'category_id' => ['nullable', 'exists:categories,id'],
'subcategory_id' => ['nullable', 'exists:subcategories,id'],
'unit_of_measure_id' => ['nullable', 'exists:units_of_measurement,id'], 'unit_of_measure_id' => ['nullable', 'exists:units_of_measurement,id'],
'track_serials' => ['nullable', 'boolean'], 'track_serials' => ['nullable', 'boolean'],

View File

@ -15,6 +15,7 @@ public function createProduct(array $data)
'sku' => $data['sku'], 'sku' => $data['sku'],
'barcode' => $data['barcode'] ?? null, 'barcode' => $data['barcode'] ?? null,
'category_id' => $data['category_id'], 'category_id' => $data['category_id'],
'subcategory_id' => $data['subcategory_id'] ?? null,
'unit_of_measure_id' => $data['unit_of_measure_id'], 'unit_of_measure_id' => $data['unit_of_measure_id'],
'track_serials' => $data['track_serials'] ?? false, 'track_serials' => $data['track_serials'] ?? false,
]); ]);
@ -40,6 +41,7 @@ public function updateProduct(Inventory $inventory, array $data)
'sku' => $data['sku'] ?? null, 'sku' => $data['sku'] ?? null,
'barcode' => $data['barcode'] ?? null, 'barcode' => $data['barcode'] ?? null,
'category_id' => $data['category_id'] ?? null, 'category_id' => $data['category_id'] ?? null,
'subcategory_id' => $data['subcategory_id'] ?? null,
'unit_of_measure_id' => $data['unit_of_measure_id'] ?? null, 'unit_of_measure_id' => $data['unit_of_measure_id'] ?? null,
'track_serials' => $data['track_serials'] ?? null, 'track_serials' => $data['track_serials'] ?? null,
], fn($value) => $value !== null); ], fn($value) => $value !== null);