has('sistema_origen')) { $query->where('sistema_origen', $request->sistema_origen); } return response()->json($query->orderBy('prioridad', 'desc')->get()); } public function store(Request $request): JsonResponse { $validated = $request->validate([ 'sistema_origen' => 'required|string|max:50', 'cuenta_padre_codigo' => 'nullable|string|max:20', 'rango_inicio' => 'nullable|string|max:20', 'rango_fin' => 'nullable|string|max:20', 'patron_regex' => 'nullable|string|max:255', 'reporte_contable_id' => 'required|exists:reportes_contables,id', 'categoria_contable_id' => 'required|exists:categorias_contables,id', 'prioridad' => 'integer', 'activo' => 'boolean', ]); $regla = ReglaMapeo::create($validated); return response()->json($regla->load(['reporteContable', 'categoriaContable']), 201); } public function show(ReglaMapeo $reglaMapeo): JsonResponse { return response()->json($reglaMapeo->load(['reporteContable', 'categoriaContable'])); } public function update(Request $request, ReglaMapeo $reglaMapeo): JsonResponse { $validated = $request->validate([ 'sistema_origen' => 'string|max:50', 'cuenta_padre_codigo' => 'nullable|string|max:20', 'rango_inicio' => 'nullable|string|max:20', 'rango_fin' => 'nullable|string|max:20', 'patron_regex' => 'nullable|string|max:255', 'reporte_contable_id' => 'exists:reportes_contables,id', 'categoria_contable_id' => 'exists:categorias_contables,id', 'prioridad' => 'integer', 'activo' => 'boolean', ]); $reglaMapeo->update($validated); return response()->json($reglaMapeo->load(['reporteContable', 'categoriaContable'])); } public function destroy(ReglaMapeo $reglaMapeo): JsonResponse { $reglaMapeo->delete(); return response()->json(['message' => 'Regla de mapeo eliminada']); } }