Andrew Wallo 6 meses atrás
pai
commit
cd3825ceb2

+ 4
- 11
app/Filament/Company/Resources/Sales/EstimateResource/Widgets/EstimateOverview.php Ver arquivo

@@ -25,17 +25,10 @@ class EstimateOverview extends EnhancedStatsOverviewWidget
25 25
 
26 26
         if ($activeTab === 'draft') {
27 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 Ver arquivo

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

+ 27
- 15
app/Filament/Company/Resources/Sales/InvoiceResource/Widgets/InvoiceOverview.php Ver arquivo

@@ -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
         ];

+ 5
- 2
app/Providers/Filament/CompanyPanelProvider.php Ver arquivo

@@ -40,6 +40,7 @@ use App\Http\Middleware\ConfigureCurrentCompany;
40 40
 use App\Livewire\UpdatePassword;
41 41
 use App\Livewire\UpdateProfileInformation;
42 42
 use App\Models\Company;
43
+use App\Services\CompanySettingsService;
43 44
 use App\Support\FilamentComponentConfigurator;
44 45
 use Exception;
45 46
 use Filament\Actions;
@@ -274,11 +275,13 @@ class CompanyPanelProvider extends PanelProvider
274 275
         });
275 276
 
276 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 280
             $table
278 281
                 ->paginationPageOptions([5, 10, 25, 50, 100])
279 282
                 ->filtersFormWidth(MaxWidth::Small)
280 283
                 ->filtersTriggerAction(fn (Tables\Actions\Action $action) => $action->slideOver());
281
-        }, isImportant: true);
284
+        });
282 285
 
283 286
         Tables\Columns\TextColumn::configureUsing(function (Tables\Columns\TextColumn $column): void {
284 287
             $column->placeholder('–');
@@ -296,7 +299,7 @@ class CompanyPanelProvider extends PanelProvider
296 299
             $select
297 300
                 ->native(false)
298 301
                 ->selectablePlaceholder($isSelectable);
299
-        }, isImportant: true);
302
+        });
300 303
     }
301 304
 
302 305
     protected function hasRequiredRule(Select $component): bool

+ 25
- 8
app/Services/CompanySettingsService.php Ver arquivo

@@ -9,11 +9,21 @@ use Illuminate\Support\Facades\Cache;
9 9
 
10 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 24
         $cacheKey = "company_settings_{$companyId}";
15 25
 
16
-        return Cache::rememberForever($cacheKey, function () use ($companyId) {
26
+        $settings = Cache::rememberForever($cacheKey, function () use ($companyId) {
17 27
             $company = Company::with(['locale'])->find($companyId);
18 28
 
19 29
             if (! $company) {
@@ -28,12 +38,19 @@ class CompanySettingsService
28 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 47
     public static function invalidateSettings(int $companyId): void
34 48
     {
35 49
         $cacheKey = "company_settings_{$companyId}";
50
+
36 51
         Cache::forget($cacheKey);
52
+
53
+        unset(self::$requestCache[$companyId]);
37 54
     }
38 55
 
39 56
     public static function getDefaultSettings(): array
@@ -47,34 +64,34 @@ class CompanySettingsService
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 69
         $settings = self::getSettings($companyId);
53 70
 
54 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 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 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 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 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 96
         return self::getSpecificSetting($companyId, 'default_week_start', WeekStart::DEFAULT);
80 97
     }

Carregando…
Cancelar
Salvar