Show payments and paid bills on billing dashboards.
Deploy Ladill Care / deploy (push) Successful in 1m21s
Deploy Ladill Care / deploy (push) Successful in 1m21s
Cashiers and other bills.view roles get today's collections breakdown and a recent paid-invoice list under the existing metric cards. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -80,6 +80,14 @@ class DashboardController extends Controller
|
||||
? $this->patientQueueForMember($request, $organization->id, $owner, $member, $branchScope)
|
||||
: [collect(), collect(), null];
|
||||
|
||||
$showBillingPanel = $canBills;
|
||||
$paymentStats = $showBillingPanel
|
||||
? $this->reports->todayPaymentStats($owner, $organization->id, $branchScope)
|
||||
: null;
|
||||
$recentPaidBills = $showBillingPanel
|
||||
? $this->reports->recentPaidBills($owner, $organization->id, $branchScope)
|
||||
: collect();
|
||||
|
||||
return view('care.dashboard', [
|
||||
'organization' => $organization,
|
||||
'member' => $member,
|
||||
@@ -98,6 +106,9 @@ class DashboardController extends Controller
|
||||
'inConsultation' => $inConsultation,
|
||||
'practitionerId' => $practitionerId,
|
||||
'specialtyModules' => $this->specialtyModules->enabledModulesForMember($organization, $member),
|
||||
'showBillingPanel' => $showBillingPanel,
|
||||
'paymentStats' => $paymentStats,
|
||||
'recentPaidBills' => $recentPaidBills,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,70 @@ class ReportService
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Today's payment collections for billing dashboards (cashiers / bills.view).
|
||||
*
|
||||
* @return array{
|
||||
* collected_minor: int,
|
||||
* payment_count: int,
|
||||
* cash_minor: int,
|
||||
* other_minor: int
|
||||
* }
|
||||
*/
|
||||
public function todayPaymentStats(
|
||||
string $ownerRef,
|
||||
int $organizationId,
|
||||
?int $branchId = null,
|
||||
): array {
|
||||
$today = now()->startOfDay();
|
||||
|
||||
$base = Payment::owned($ownerRef)
|
||||
->where('status', Payment::STATUS_PAID)
|
||||
->whereHas('bill', function (Builder $q) use ($organizationId, $branchId) {
|
||||
$q->where('organization_id', $organizationId);
|
||||
if ($branchId) {
|
||||
$q->where('branch_id', $branchId);
|
||||
}
|
||||
})
|
||||
->whereDate('paid_at', $today);
|
||||
|
||||
$collected = (int) (clone $base)->sum('amount_minor');
|
||||
$count = (clone $base)->count();
|
||||
$cash = (int) (clone $base)->where('method', Payment::METHOD_CASH)->sum('amount_minor');
|
||||
|
||||
return [
|
||||
'collected_minor' => $collected,
|
||||
'payment_count' => $count,
|
||||
'cash_minor' => $cash,
|
||||
'other_minor' => max(0, $collected - $cash),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Recently paid invoices for billing dashboards.
|
||||
*
|
||||
* @return Collection<int, Bill>
|
||||
*/
|
||||
public function recentPaidBills(
|
||||
string $ownerRef,
|
||||
int $organizationId,
|
||||
?int $branchId = null,
|
||||
int $limit = 10,
|
||||
): Collection {
|
||||
return Bill::owned($ownerRef)
|
||||
->where('organization_id', $organizationId)
|
||||
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
|
||||
->where('status', Bill::STATUS_PAID)
|
||||
->with('patient')
|
||||
->withMax([
|
||||
'payments as last_paid_at' => fn ($q) => $q->where('status', Payment::STATUS_PAID),
|
||||
], 'paid_at')
|
||||
->orderByDesc('last_paid_at')
|
||||
->orderByDesc('id')
|
||||
->limit($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user