Initial commit: Sistema de comisiones y gastos personales
This commit is contained in:
44
app/Http/Controllers/DashboardController.php
Executable file
44
app/Http/Controllers/DashboardController.php
Executable 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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user