|
@@ -29,6 +29,7 @@ class Dashboard extends Component
|
|
|
|
|
|
|
|
public $received = 0;
|
|
public $received = 0;
|
|
|
public $toPay = 0;
|
|
public $toPay = 0;
|
|
|
|
|
+ public $paid = 0;
|
|
|
|
|
|
|
|
public $courses = [];
|
|
public $courses = [];
|
|
|
public $fields = [];
|
|
public $fields = [];
|
|
@@ -199,6 +200,7 @@ class Dashboard extends Component
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
$currentMonth = now()->format('Y-m');
|
|
$currentMonth = now()->format('Y-m');
|
|
|
|
|
+ $currentDate = now()->format('Y-m-d');
|
|
|
Log::info('Calculating financial stats for month', ['month' => $currentMonth]);
|
|
Log::info('Calculating financial stats for month', ['month' => $currentMonth]);
|
|
|
|
|
|
|
|
$this->received = \App\Models\Record::where('type', 'IN')
|
|
$this->received = \App\Models\Record::where('type', 'IN')
|
|
@@ -208,8 +210,20 @@ class Dashboard extends Component
|
|
|
})
|
|
})
|
|
|
->sum('amount') ?? 0;
|
|
->sum('amount') ?? 0;
|
|
|
|
|
|
|
|
|
|
+ $this->paid = \App\Models\Record::where('type', 'OUT')
|
|
|
|
|
+ ->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
|
|
|
|
|
+ ->where('data_pagamento', '<=', $currentDate)
|
|
|
|
|
+ ->where(function ($query) {
|
|
|
|
|
+ $query->where('deleted', false)->orWhere('deleted', null);
|
|
|
|
|
+ })
|
|
|
|
|
+ ->sum('amount') ?? 0;
|
|
|
|
|
+
|
|
|
$this->toPay = \App\Models\Record::where('type', 'OUT')
|
|
$this->toPay = \App\Models\Record::where('type', 'OUT')
|
|
|
->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
|
|
->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
|
|
|
|
|
+ ->where(function ($query) use($currentDate) {
|
|
|
|
|
+ $query->where('data_pagamento', '>', $currentDate)
|
|
|
|
|
+ ->orWhereNull('data_pagamento');
|
|
|
|
|
+ })
|
|
|
->where(function ($query) {
|
|
->where(function ($query) {
|
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
$query->where('deleted', false)->orWhere('deleted', null);
|
|
|
})
|
|
})
|
|
@@ -218,6 +232,7 @@ class Dashboard extends Component
|
|
|
$endTime = microtime(true);
|
|
$endTime = microtime(true);
|
|
|
Log::info('Financial stats loaded successfully', [
|
|
Log::info('Financial stats loaded successfully', [
|
|
|
'received' => $this->received,
|
|
'received' => $this->received,
|
|
|
|
|
+ 'paid' => $this->paid,
|
|
|
'to_pay' => $this->toPay,
|
|
'to_pay' => $this->toPay,
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
|
|
|
]);
|
|
]);
|