Andrew Wallo 6 月之前
父節點
當前提交
cd3825ceb2

+ 4
- 11
app/Filament/Company/Resources/Sales/EstimateResource/Widgets/EstimateOverview.php 查看文件

25
 
25
 
26
         if ($activeTab === 'draft') {
26
         if ($activeTab === 'draft') {
27
             return [
27
             return [
28
-                EnhancedStatsOverviewWidget\EnhancedStat::make('Active Estimates', '-')
29
-                    ->suffix('')
30
-                    ->description(''),
31
-                EnhancedStatsOverviewWidget\EnhancedStat::make('Accepted Estimates', '-')
32
-                    ->suffix('')
33
-                    ->description(''),
34
-                EnhancedStatsOverviewWidget\EnhancedStat::make('Converted Estimates', '-')
35
-                    ->suffix('')
36
-                    ->description(''),
37
-                EnhancedStatsOverviewWidget\EnhancedStat::make('Average Estimate Total', '-')
38
-                    ->suffix(''),
28
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Active Estimates', '-'),
29
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Accepted Estimates', '-'),
30
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Converted Estimates', '-'),
31
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Average Estimate Total', '-'),
39
             ];
32
             ];
40
         }
33
         }
41
 
34
 

+ 1
- 1
app/Filament/Company/Resources/Sales/InvoiceResource.php 查看文件

331
                     ->preload(),
331
                     ->preload(),
332
                 Tables\Filters\SelectFilter::make('status')
332
                 Tables\Filters\SelectFilter::make('status')
333
                     ->options(InvoiceStatus::class)
333
                     ->options(InvoiceStatus::class)
334
-                    ->native(false),
334
+                    ->multiple(),
335
                 Tables\Filters\TernaryFilter::make('has_payments')
335
                 Tables\Filters\TernaryFilter::make('has_payments')
336
                     ->label('Has payments')
336
                     ->label('Has payments')
337
                     ->queries(
337
                     ->queries(

+ 27
- 15
app/Filament/Company/Resources/Sales/InvoiceResource/Widgets/InvoiceOverview.php 查看文件

24
         $activeTab = $this->activeTab;
24
         $activeTab = $this->activeTab;
25
 
25
 
26
         if ($activeTab === 'draft') {
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
             return [
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
             ? (int) round($totalValidInvoiceAmount / $totalValidInvoiceCount)
73
             ? (int) round($totalValidInvoiceAmount / $totalValidInvoiceCount)
68
             : 0;
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
         return [
89
         return [
78
             EnhancedStatsOverviewWidget\EnhancedStat::make('Total Unpaid', CurrencyConverter::formatCentsToMoney($amountUnpaid))
90
             EnhancedStatsOverviewWidget\EnhancedStat::make('Total Unpaid', CurrencyConverter::formatCentsToMoney($amountUnpaid))
81
             EnhancedStatsOverviewWidget\EnhancedStat::make('Due Within 30 Days', CurrencyConverter::formatCentsToMoney($amountDueWithin30Days))
93
             EnhancedStatsOverviewWidget\EnhancedStat::make('Due Within 30 Days', CurrencyConverter::formatCentsToMoney($amountDueWithin30Days))
82
                 ->suffix(CurrencyAccessor::getDefaultCurrency()),
94
                 ->suffix(CurrencyAccessor::getDefaultCurrency()),
83
             EnhancedStatsOverviewWidget\EnhancedStat::make('Average Payment Time', $averagePaymentTimeFormatted)
95
             EnhancedStatsOverviewWidget\EnhancedStat::make('Average Payment Time', $averagePaymentTimeFormatted)
84
-                ->suffix('days'),
96
+                ->suffix($averagePaymentTimeSuffix),
85
             EnhancedStatsOverviewWidget\EnhancedStat::make('Average Invoice Total', CurrencyConverter::formatCentsToMoney($averageInvoiceTotal))
97
             EnhancedStatsOverviewWidget\EnhancedStat::make('Average Invoice Total', CurrencyConverter::formatCentsToMoney($averageInvoiceTotal))
86
                 ->suffix(CurrencyAccessor::getDefaultCurrency()),
98
                 ->suffix(CurrencyAccessor::getDefaultCurrency()),
87
         ];
99
         ];

+ 5
- 2
app/Providers/Filament/CompanyPanelProvider.php 查看文件

40
 use App\Livewire\UpdatePassword;
40
 use App\Livewire\UpdatePassword;
41
 use App\Livewire\UpdateProfileInformation;
41
 use App\Livewire\UpdateProfileInformation;
42
 use App\Models\Company;
42
 use App\Models\Company;
43
+use App\Services\CompanySettingsService;
43
 use App\Support\FilamentComponentConfigurator;
44
 use App\Support\FilamentComponentConfigurator;
44
 use Exception;
45
 use Exception;
45
 use Filament\Actions;
46
 use Filament\Actions;
274
         });
275
         });
275
 
276
 
276
         Tables\Table::configureUsing(static function (Tables\Table $table): void {
277
         Tables\Table::configureUsing(static function (Tables\Table $table): void {
278
+            $table::$defaultDateDisplayFormat = CompanySettingsService::getDefaultDateFormat(session('current_company_id') ?? auth()->user()->current_company_id);
279
+
277
             $table
280
             $table
278
                 ->paginationPageOptions([5, 10, 25, 50, 100])
281
                 ->paginationPageOptions([5, 10, 25, 50, 100])
279
                 ->filtersFormWidth(MaxWidth::Small)
282
                 ->filtersFormWidth(MaxWidth::Small)
280
                 ->filtersTriggerAction(fn (Tables\Actions\Action $action) => $action->slideOver());
283
                 ->filtersTriggerAction(fn (Tables\Actions\Action $action) => $action->slideOver());
281
-        }, isImportant: true);
284
+        });
282
 
285
 
283
         Tables\Columns\TextColumn::configureUsing(function (Tables\Columns\TextColumn $column): void {
286
         Tables\Columns\TextColumn::configureUsing(function (Tables\Columns\TextColumn $column): void {
284
             $column->placeholder('–');
287
             $column->placeholder('–');
296
             $select
299
             $select
297
                 ->native(false)
300
                 ->native(false)
298
                 ->selectablePlaceholder($isSelectable);
301
                 ->selectablePlaceholder($isSelectable);
299
-        }, isImportant: true);
302
+        });
300
     }
303
     }
301
 
304
 
302
     protected function hasRequiredRule(Select $component): bool
305
     protected function hasRequiredRule(Select $component): bool

+ 25
- 8
app/Services/CompanySettingsService.php 查看文件

9
 
9
 
10
 class CompanySettingsService
10
 class CompanySettingsService
11
 {
11
 {
12
-    public static function getSettings(int $companyId): array
12
+    protected static array $requestCache = [];
13
+
14
+    public static function getSettings(?int $companyId = null): array
13
     {
15
     {
16
+        if (! $companyId) {
17
+            return self::getDefaultSettings();
18
+        }
19
+
20
+        if (isset(self::$requestCache[$companyId])) {
21
+            return self::$requestCache[$companyId];
22
+        }
23
+
14
         $cacheKey = "company_settings_{$companyId}";
24
         $cacheKey = "company_settings_{$companyId}";
15
 
25
 
16
-        return Cache::rememberForever($cacheKey, function () use ($companyId) {
26
+        $settings = Cache::rememberForever($cacheKey, function () use ($companyId) {
17
             $company = Company::with(['locale'])->find($companyId);
27
             $company = Company::with(['locale'])->find($companyId);
18
 
28
 
19
             if (! $company) {
29
             if (! $company) {
28
                 'default_week_start' => $company->locale->week_start->value ?? WeekStart::DEFAULT,
38
                 'default_week_start' => $company->locale->week_start->value ?? WeekStart::DEFAULT,
29
             ];
39
             ];
30
         });
40
         });
41
+
42
+        self::$requestCache[$companyId] = $settings;
43
+
44
+        return $settings;
31
     }
45
     }
32
 
46
 
33
     public static function invalidateSettings(int $companyId): void
47
     public static function invalidateSettings(int $companyId): void
34
     {
48
     {
35
         $cacheKey = "company_settings_{$companyId}";
49
         $cacheKey = "company_settings_{$companyId}";
50
+
36
         Cache::forget($cacheKey);
51
         Cache::forget($cacheKey);
52
+
53
+        unset(self::$requestCache[$companyId]);
37
     }
54
     }
38
 
55
 
39
     public static function getDefaultSettings(): array
56
     public static function getDefaultSettings(): array
47
         ];
64
         ];
48
     }
65
     }
49
 
66
 
50
-    public static function getSpecificSetting(int $companyId, string $key, $default = null)
67
+    public static function getSpecificSetting(?int $companyId, string $key, $default = null)
51
     {
68
     {
52
         $settings = self::getSettings($companyId);
69
         $settings = self::getSettings($companyId);
53
 
70
 
54
         return $settings[$key] ?? $default;
71
         return $settings[$key] ?? $default;
55
     }
72
     }
56
 
73
 
57
-    public static function getDefaultLanguage(int $companyId): string
74
+    public static function getDefaultLanguage(?int $companyId = null): string
58
     {
75
     {
59
         return self::getSpecificSetting($companyId, 'default_language', config('transmatic.source_locale'));
76
         return self::getSpecificSetting($companyId, 'default_language', config('transmatic.source_locale'));
60
     }
77
     }
61
 
78
 
62
-    public static function getDefaultTimezone(int $companyId): string
79
+    public static function getDefaultTimezone(?int $companyId = null): string
63
     {
80
     {
64
         return self::getSpecificSetting($companyId, 'default_timezone', config('app.timezone'));
81
         return self::getSpecificSetting($companyId, 'default_timezone', config('app.timezone'));
65
     }
82
     }
66
 
83
 
67
-    public static function getDefaultCurrency(int $companyId): string
84
+    public static function getDefaultCurrency(?int $companyId = null): string
68
     {
85
     {
69
         return self::getSpecificSetting($companyId, 'default_currency', 'USD');
86
         return self::getSpecificSetting($companyId, 'default_currency', 'USD');
70
     }
87
     }
71
 
88
 
72
-    public static function getDefaultDateFormat(int $companyId): string
89
+    public static function getDefaultDateFormat(?int $companyId = null): string
73
     {
90
     {
74
         return self::getSpecificSetting($companyId, 'default_date_format', DateFormat::DEFAULT);
91
         return self::getSpecificSetting($companyId, 'default_date_format', DateFormat::DEFAULT);
75
     }
92
     }
76
 
93
 
77
-    public static function getDefaultWeekStart(int $companyId): string
94
+    public static function getDefaultWeekStart(?int $companyId = null): string
78
     {
95
     {
79
         return self::getSpecificSetting($companyId, 'default_week_start', WeekStart::DEFAULT);
96
         return self::getSpecificSetting($companyId, 'default_week_start', WeekStart::DEFAULT);
80
     }
97
     }

Loading…
取消
儲存