Initial commit: Sistema de comisiones y gastos personales

This commit is contained in:
2026-04-19 09:59:57 -06:00
commit dc964d6bce
103 changed files with 15859 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers;
use App\Models\DailySale;
use App\Models\Month;
use App\Services\CommissionCalculator;
use Illuminate\Support\Facades\Auth;
class DashboardController extends Controller
{
/**
* Mostrar dashboard del usuario
*/
public function index()
{
$user = Auth::user();
// Obtener mes actual o último mes
$currentMonth = $user->getCurrentMonth();
// Si no hay mes abierto, buscar el último mes
if (!$currentMonth) {
$currentMonth = $user->months()
->orderBy('year', 'desc')
->orderByRaw("FIELD(name, 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre') DESC")
->first();
}
$data = null;
if ($currentMonth) {
$data = CommissionCalculator::calculateForMonth($user, $currentMonth);
}
// Últimos meses del usuario
$recentMonths = $user->months()
->orderBy('year', 'desc')
->orderByRaw("FIELD(name, 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre') DESC")
->limit(6)
->get();
return view('dashboard.index', compact('currentMonth', 'data', 'recentMonths'));
}
}