Files
Torch2196 4c3dc94ff2 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>
2026-01-31 22:24:00 -06:00

88 lines
2.5 KiB
PHP

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