Skip to content

Commit ad96843

Browse files
fix(DashboardManagerService): update contract date queries and invoice status checks for improved accuracy
1 parent f0349bb commit ad96843

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

app/Services/DashboardManagerService.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,22 @@ private function getNewPatientsByMonth(): array
113113
private function getContractsData(): array
114114
{
115115
$totalContracts = Contract::count();
116-
$activeContracts = Contract::whereStartDate('<=', now())
117-
->whereEndDate('>=', now())
116+
$activeContracts = Contract::where('start_date', '<=', Carbon::today())
117+
->where('end_date', '>=', Carbon::today())
118118
->count();
119119

120120
$contractsByType = Contract::selectRaw('contract_type, COUNT(id) as total')
121121
->groupBy('contract_type')
122122
->get()
123123
->pluck('total', 'contract_type');
124124

125-
$currentMonth = now()->format('Y-m');
126-
$totalEarningsCurrentMonth = Contract::whereStartDate('<=', now()->endOfMonth())
127-
->whereEndDate('>=', now()->startOfMonth())
128-
->get()
129-
->sum(function ($contract) use ($currentMonth) {
130-
return $contract->getTotalEarningsAttribute($currentMonth);
131-
});
132-
133125
return [
134126
'total_contracts' => $totalContracts,
135127
'active_contracts' => $activeContracts,
136128
'contracts_by_type' => [
137129
'labels' => $contractsByType->keys()->all(),
138130
'data' => $contractsByType->values()->all(),
139131
],
140-
'total_earnings_current_month' => round($totalEarningsCurrentMonth, 2),
141132
];
142133
}
143134

@@ -150,9 +141,9 @@ private function getInvoicesData(): array
150141
{
151142
$totalInvoices = Invoice::count();
152143
$totalAmount = Invoice::sum('amount');
153-
$pendingInvoices = Invoice::whereStatus('!=', 'paid')->count();
154-
$paidInvoices = Invoice::whereStatus('=', 'paid')->count();
155-
$pendingAmount = Invoice::whereStatus('!=', 'paid')->sum('amount');
144+
$pendingInvoices = Invoice::where('status', '!=', 'paid')->count();
145+
$paidInvoices = Invoice::whereStatus('paid')->count();
146+
$pendingAmount = Invoice::where('status', '!=', 'paid')->sum('amount');
156147

157148
return [
158149
'total_invoices' => $totalInvoices,
@@ -177,6 +168,7 @@ private function getEmployeePaymentsData(): array
177168
$endMonthDate = Carbon::now()->endOfMonth();
178169

179170
$paymentsByMonth = EmployeePayment::selectRaw("DATE_FORMAT(payment_date, '%Y-%m') as month, SUM(amount) as total")
171+
->whereNotNull('payment_date')
180172
->whereBetween('payment_date', [$startMonthDate, $endMonthDate])
181173
->groupBy('month')
182174
->orderBy('month')

0 commit comments

Comments
 (0)