Initial commit: Horux Strategy Platform
- Laravel 11 backend with API REST - React 18 + TypeScript + Vite frontend - Multi-parser architecture for accounting systems (CONTPAQi, Aspel, SAP) - 27+ financial metrics calculation - PDF report generation with Browsershot - Complete documentation (10 documents) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
87
backend/app/Http/Controllers/Admin/UmbralController.php
Normal file
87
backend/app/Http/Controllers/Admin/UmbralController.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Umbral;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UmbralController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = Umbral::with('giro');
|
||||
|
||||
if ($request->has('giro_id')) {
|
||||
$query->where('giro_id', $request->giro_id);
|
||||
}
|
||||
|
||||
return response()->json($query->get());
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'metrica' => 'required|string|max:100',
|
||||
'muy_positivo' => 'nullable|numeric',
|
||||
'positivo' => 'nullable|numeric',
|
||||
'neutral' => 'nullable|numeric',
|
||||
'negativo' => 'nullable|numeric',
|
||||
'muy_negativo' => 'nullable|numeric',
|
||||
'giro_id' => 'nullable|exists:giros,id',
|
||||
]);
|
||||
|
||||
$umbral = Umbral::create($validated);
|
||||
|
||||
return response()->json($umbral->load('giro'), 201);
|
||||
}
|
||||
|
||||
public function show(Umbral $umbral): JsonResponse
|
||||
{
|
||||
return response()->json($umbral->load('giro'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Umbral $umbral): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'metrica' => 'string|max:100',
|
||||
'muy_positivo' => 'nullable|numeric',
|
||||
'positivo' => 'nullable|numeric',
|
||||
'neutral' => 'nullable|numeric',
|
||||
'negativo' => 'nullable|numeric',
|
||||
'muy_negativo' => 'nullable|numeric',
|
||||
'giro_id' => 'nullable|exists:giros,id',
|
||||
]);
|
||||
|
||||
$umbral->update($validated);
|
||||
|
||||
return response()->json($umbral->load('giro'));
|
||||
}
|
||||
|
||||
public function destroy(Umbral $umbral): JsonResponse
|
||||
{
|
||||
$umbral->delete();
|
||||
return response()->json(['message' => 'Umbral eliminado']);
|
||||
}
|
||||
|
||||
public function porMetrica(string $metrica, ?int $giroId = null): JsonResponse
|
||||
{
|
||||
// Buscar primero umbral específico del giro, luego el genérico
|
||||
$umbral = Umbral::where('metrica', $metrica)
|
||||
->where('giro_id', $giroId)
|
||||
->first();
|
||||
|
||||
if (!$umbral) {
|
||||
$umbral = Umbral::where('metrica', $metrica)
|
||||
->whereNull('giro_id')
|
||||
->first();
|
||||
}
|
||||
|
||||
if (!$umbral) {
|
||||
return response()->json(['message' => 'Umbral no encontrado'], 404);
|
||||
}
|
||||
|
||||
return response()->json($umbral);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user