- 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>
66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Cuenta;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CuentaController extends Controller
|
|
{
|
|
public function updateClasificacion(Request $request, Cuenta $cuenta): JsonResponse
|
|
{
|
|
if (!$request->user()->canAccessCliente($cuenta->balanza->cliente_id)) {
|
|
return response()->json(['message' => 'No autorizado'], 403);
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'reporte_contable_id' => 'required|exists:reportes_contables,id',
|
|
'categoria_contable_id' => 'required|exists:categorias_contables,id',
|
|
'requiere_revision' => 'boolean',
|
|
'nota_revision' => 'nullable|string',
|
|
]);
|
|
|
|
$cuenta->update([
|
|
'reporte_contable_id' => $validated['reporte_contable_id'],
|
|
'categoria_contable_id' => $validated['categoria_contable_id'],
|
|
'requiere_revision' => $validated['requiere_revision'] ?? false,
|
|
'nota_revision' => $validated['nota_revision'] ?? null,
|
|
]);
|
|
|
|
return response()->json($cuenta->load(['categoriaContable', 'reporteContable']));
|
|
}
|
|
|
|
public function toggleExclusion(Request $request, Cuenta $cuenta): JsonResponse
|
|
{
|
|
if (!$request->user()->canAccessCliente($cuenta->balanza->cliente_id)) {
|
|
return response()->json(['message' => 'No autorizado'], 403);
|
|
}
|
|
|
|
$cuenta->update(['excluida' => !$cuenta->excluida]);
|
|
|
|
// Recalcular cuenta padre si existe
|
|
if ($cuenta->cuentaPadre) {
|
|
$cuenta->cuentaPadre->recalcularSaldoDesdeHijos();
|
|
}
|
|
|
|
return response()->json($cuenta);
|
|
}
|
|
|
|
public function anomalias(Request $request): JsonResponse
|
|
{
|
|
$user = $request->user();
|
|
|
|
$query = Cuenta::where('requiere_revision', true)
|
|
->with(['balanza.cliente', 'categoriaContable', 'reporteContable']);
|
|
|
|
if (!$user->isAdmin() && !$user->isAnalista()) {
|
|
$query->whereHas('balanza', function ($q) use ($user) {
|
|
$q->where('cliente_id', $user->cliente_id);
|
|
});
|
|
}
|
|
|
|
return response()->json($query->get());
|
|
}
|
|
}
|