Andrew Wallo il y a 6 mois
Parent
révision
e79292e437

+ 1
- 1
app/Filament/Company/Clusters/Settings/Pages/CompanyDefault.php Voir le fichier

@@ -65,7 +65,7 @@ class CompanyDefault extends Page
65 65
     public function mount(): void
66 66
     {
67 67
         $this->record = CompanyDefaultModel::firstOrNew([
68
-            'company_id' => auth()->user()->currentCompany->id,
68
+            'company_id' => auth()->user()->current_company_id,
69 69
         ]);
70 70
 
71 71
         abort_unless(static::canView($this->record), 404);

+ 1
- 1
app/Filament/Company/Clusters/Settings/Pages/CompanyProfile.php Voir le fichier

@@ -68,7 +68,7 @@ class CompanyProfile extends Page
68 68
     public function mount(): void
69 69
     {
70 70
         $this->record = CompanyProfileModel::firstOrNew([
71
-            'company_id' => auth()->user()->currentCompany->id,
71
+            'company_id' => auth()->user()->current_company_id,
72 72
         ]);
73 73
 
74 74
         abort_unless(static::canView($this->record), 404);

+ 1
- 1
app/Filament/Company/Clusters/Settings/Pages/Localization.php Voir le fichier

@@ -69,7 +69,7 @@ class Localization extends Page
69 69
     public function mount(): void
70 70
     {
71 71
         $this->record = LocalizationModel::firstOrNew([
72
-            'company_id' => auth()->user()->currentCompany->id,
72
+            'company_id' => auth()->user()->current_company_id,
73 73
         ]);
74 74
 
75 75
         abort_unless(static::canView($this->record), 404);

+ 2
- 1
app/Listeners/SyncWithCompanyDefaults.php Voir le fichier

@@ -34,7 +34,7 @@ class SyncWithCompanyDefaults
34 34
             return;
35 35
         }
36 36
 
37
-        $companyId = auth()->user()->currentCompany->id;
37
+        $companyId = auth()->user()->current_company_id;
38 38
 
39 39
         if (! $companyId) {
40 40
             return;
@@ -47,6 +47,7 @@ class SyncWithCompanyDefaults
47 47
     {
48 48
         $modelName = class_basename($model);
49 49
 
50
+        /** @var CompanyDefault $default */
50 51
         $default = CompanyDefault::firstOrNew([
51 52
             'company_id' => $companyId,
52 53
         ]);

+ 4
- 4
app/Providers/MacroServiceProvider.php Voir le fichier

@@ -8,6 +8,7 @@ use App\Enums\Accounting\AdjustmentComputation;
8 8
 use App\Enums\Setting\DateFormat;
9 9
 use App\Models\Accounting\AccountSubtype;
10 10
 use App\Models\Setting\Localization;
11
+use App\Services\CompanySettingsService;
11 12
 use App\Utilities\Accounting\AccountCode;
12 13
 use App\Utilities\Currency\CurrencyAccessor;
13 14
 use App\Utilities\Currency\CurrencyConverter;
@@ -433,10 +434,9 @@ class MacroServiceProvider extends ServiceProvider
433 434
         });
434 435
 
435 436
         Carbon::macro('toDefaultDateFormat', function () {
436
-            $localization = Localization::firstOrFail();
437
-
438
-            $dateFormat = $localization->date_format->value ?? DateFormat::DEFAULT;
439
-            $timezone = $localization->timezone ?? Carbon::now()->timezoneName;
437
+            $companyId = auth()->user()?->current_company_id;
438
+            $dateFormat = CompanySettingsService::getDefaultDateFormat($companyId);
439
+            $timezone = CompanySettingsService::getDefaultTimezone($companyId);
440 440
 
441 441
             return $this->setTimezone($timezone)->format($dateFormat);
442 442
         });

+ 7
- 1
app/Services/CompanySettingsService.php Voir le fichier

@@ -5,6 +5,7 @@ namespace App\Services;
5 5
 use App\Enums\Setting\DateFormat;
6 6
 use App\Enums\Setting\WeekStart;
7 7
 use App\Models\Company;
8
+use App\Models\Setting\Currency;
8 9
 use Illuminate\Support\Facades\Cache;
9 10
 
10 11
 class CompanySettingsService
@@ -30,10 +31,15 @@ class CompanySettingsService
30 31
                 return self::getDefaultSettings();
31 32
             }
32 33
 
34
+            $defaultCurrency = Currency::query()
35
+                ->where('company_id', $companyId)
36
+                ->where('enabled', true)
37
+                ->value('code') ?? 'USD';
38
+
33 39
             return [
34 40
                 'default_language' => $company->locale->language ?? config('transmatic.source_locale'),
35 41
                 'default_timezone' => $company->locale->timezone ?? config('app.timezone'),
36
-                'default_currency' => $company->currency_code ?? 'USD',
42
+                'default_currency' => $defaultCurrency,
37 43
                 'default_date_format' => $company->locale->date_format->value ?? DateFormat::DEFAULT,
38 44
                 'default_week_start' => $company->locale->week_start->value ?? WeekStart::DEFAULT,
39 45
             ];

+ 3
- 8
app/Utilities/Currency/CurrencyAccessor.php Voir le fichier

@@ -5,7 +5,7 @@ namespace App\Utilities\Currency;
5 5
 use Akaunting\Money\Currency as ISOCurrencies;
6 6
 use App\Facades\Forex;
7 7
 use App\Models\Setting\Currency;
8
-use Illuminate\Support\Facades\Cache;
8
+use App\Services\CompanySettingsService;
9 9
 
10 10
 class CurrencyAccessor
11 11
 {
@@ -53,17 +53,12 @@ class CurrencyAccessor
53 53
 
54 54
     public static function getDefaultCurrency(): ?string
55 55
     {
56
-        $companyId = auth()->user()?->currentCompany?->id;
57
-        $cacheKey = "default_currency_{$companyId}";
56
+        $companyId = auth()->user()?->current_company_id;
58 57
 
59 58
         if ($companyId === null) {
60 59
             return 'USD';
61 60
         }
62 61
 
63
-        return Cache::rememberForever($cacheKey, function () {
64
-            return Currency::query()
65
-                ->where('enabled', true)
66
-                ->value('code');
67
-        });
62
+        return CompanySettingsService::getDefaultCurrency($companyId);
68 63
     }
69 64
 }

Chargement…
Annuler
Enregistrer