|
@@ -24,16 +24,22 @@ class InvoiceOverview extends EnhancedStatsOverviewWidget
|
24
|
24
|
$activeTab = $this->activeTab;
|
25
|
25
|
|
26
|
26
|
if ($activeTab === 'draft') {
|
|
27
|
+ $draftInvoices = $this->getPageTableQuery();
|
|
28
|
+
|
|
29
|
+ $totalDraftCount = $draftInvoices->count();
|
|
30
|
+ $totalDraftAmount = $draftInvoices->get()->sumMoneyInDefaultCurrency('total');
|
|
31
|
+
|
|
32
|
+ $averageDraftTotal = $totalDraftCount > 0
|
|
33
|
+ ? (int) round($totalDraftAmount / $totalDraftCount)
|
|
34
|
+ : 0;
|
|
35
|
+
|
27
|
36
|
return [
|
28
|
|
- EnhancedStatsOverviewWidget\EnhancedStat::make('Total Unpaid', '-')
|
29
|
|
- ->suffix('')
|
30
|
|
- ->description(''),
|
31
|
|
- EnhancedStatsOverviewWidget\EnhancedStat::make('Due Within 30 Days', '-')
|
32
|
|
- ->suffix(''),
|
33
|
|
- EnhancedStatsOverviewWidget\EnhancedStat::make('Average Payment Time', '-')
|
34
|
|
- ->suffix(''),
|
35
|
|
- EnhancedStatsOverviewWidget\EnhancedStat::make('Average Invoice Total', '-')
|
36
|
|
- ->suffix(''),
|
|
37
|
+ EnhancedStatsOverviewWidget\EnhancedStat::make('Total Unpaid', '-'),
|
|
38
|
+ EnhancedStatsOverviewWidget\EnhancedStat::make('Due Within 30 Days', '-'),
|
|
39
|
+ EnhancedStatsOverviewWidget\EnhancedStat::make('Average Payment Time', '-'),
|
|
40
|
+ EnhancedStatsOverviewWidget\EnhancedStat::make('Average Invoice Total', CurrencyConverter::formatCentsToMoney($averageDraftTotal))
|
|
41
|
+ ->suffix(CurrencyAccessor::getDefaultCurrency())
|
|
42
|
+ ->description($totalDraftCount . ' draft invoices'),
|
37
|
43
|
];
|
38
|
44
|
}
|
39
|
45
|
|
|
@@ -67,12 +73,18 @@ class InvoiceOverview extends EnhancedStatsOverviewWidget
|
67
|
73
|
? (int) round($totalValidInvoiceAmount / $totalValidInvoiceCount)
|
68
|
74
|
: 0;
|
69
|
75
|
|
70
|
|
- $averagePaymentTime = $this->getPageTableQuery()
|
71
|
|
- ->whereNotNull('paid_at')
|
72
|
|
- ->selectRaw('AVG(TIMESTAMPDIFF(DAY, approved_at, paid_at)) as avg_days')
|
73
|
|
- ->value('avg_days');
|
|
76
|
+ $averagePaymentTimeFormatted = '-';
|
|
77
|
+ $averagePaymentTimeSuffix = null;
|
74
|
78
|
|
75
|
|
- $averagePaymentTimeFormatted = Number::format($averagePaymentTime ?? 0, maxPrecision: 1);
|
|
79
|
+ if ($activeTab !== 'unpaid') {
|
|
80
|
+ $averagePaymentTime = $this->getPageTableQuery()
|
|
81
|
+ ->whereNotNull('paid_at')
|
|
82
|
+ ->selectRaw('AVG(TIMESTAMPDIFF(DAY, approved_at, paid_at)) as avg_days')
|
|
83
|
+ ->value('avg_days');
|
|
84
|
+
|
|
85
|
+ $averagePaymentTimeFormatted = Number::format($averagePaymentTime ?? 0, maxPrecision: 1);
|
|
86
|
+ $averagePaymentTimeSuffix = 'days';
|
|
87
|
+ }
|
76
|
88
|
|
77
|
89
|
return [
|
78
|
90
|
EnhancedStatsOverviewWidget\EnhancedStat::make('Total Unpaid', CurrencyConverter::formatCentsToMoney($amountUnpaid))
|
|
@@ -81,7 +93,7 @@ class InvoiceOverview extends EnhancedStatsOverviewWidget
|
81
|
93
|
EnhancedStatsOverviewWidget\EnhancedStat::make('Due Within 30 Days', CurrencyConverter::formatCentsToMoney($amountDueWithin30Days))
|
82
|
94
|
->suffix(CurrencyAccessor::getDefaultCurrency()),
|
83
|
95
|
EnhancedStatsOverviewWidget\EnhancedStat::make('Average Payment Time', $averagePaymentTimeFormatted)
|
84
|
|
- ->suffix('days'),
|
|
96
|
+ ->suffix($averagePaymentTimeSuffix),
|
85
|
97
|
EnhancedStatsOverviewWidget\EnhancedStat::make('Average Invoice Total', CurrencyConverter::formatCentsToMoney($averageInvoiceTotal))
|
86
|
98
|
->suffix(CurrencyAccessor::getDefaultCurrency()),
|
87
|
99
|
];
|