Andrew Wallo 6 months ago
parent
commit
e79292e437

+ 1
- 1
app/Filament/Company/Clusters/Settings/Pages/CompanyDefault.php View File

65
     public function mount(): void
65
     public function mount(): void
66
     {
66
     {
67
         $this->record = CompanyDefaultModel::firstOrNew([
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
         abort_unless(static::canView($this->record), 404);
71
         abort_unless(static::canView($this->record), 404);

+ 1
- 1
app/Filament/Company/Clusters/Settings/Pages/CompanyProfile.php View File

68
     public function mount(): void
68
     public function mount(): void
69
     {
69
     {
70
         $this->record = CompanyProfileModel::firstOrNew([
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
         abort_unless(static::canView($this->record), 404);
74
         abort_unless(static::canView($this->record), 404);

+ 1
- 1
app/Filament/Company/Clusters/Settings/Pages/Localization.php View File

69
     public function mount(): void
69
     public function mount(): void
70
     {
70
     {
71
         $this->record = LocalizationModel::firstOrNew([
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
         abort_unless(static::canView($this->record), 404);
75
         abort_unless(static::canView($this->record), 404);

+ 2
- 1
app/Listeners/SyncWithCompanyDefaults.php View File

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

+ 4
- 4
app/Providers/MacroServiceProvider.php View File

8
 use App\Enums\Setting\DateFormat;
8
 use App\Enums\Setting\DateFormat;
9
 use App\Models\Accounting\AccountSubtype;
9
 use App\Models\Accounting\AccountSubtype;
10
 use App\Models\Setting\Localization;
10
 use App\Models\Setting\Localization;
11
+use App\Services\CompanySettingsService;
11
 use App\Utilities\Accounting\AccountCode;
12
 use App\Utilities\Accounting\AccountCode;
12
 use App\Utilities\Currency\CurrencyAccessor;
13
 use App\Utilities\Currency\CurrencyAccessor;
13
 use App\Utilities\Currency\CurrencyConverter;
14
 use App\Utilities\Currency\CurrencyConverter;
433
         });
434
         });
434
 
435
 
435
         Carbon::macro('toDefaultDateFormat', function () {
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
             return $this->setTimezone($timezone)->format($dateFormat);
441
             return $this->setTimezone($timezone)->format($dateFormat);
442
         });
442
         });

+ 7
- 1
app/Services/CompanySettingsService.php View File

5
 use App\Enums\Setting\DateFormat;
5
 use App\Enums\Setting\DateFormat;
6
 use App\Enums\Setting\WeekStart;
6
 use App\Enums\Setting\WeekStart;
7
 use App\Models\Company;
7
 use App\Models\Company;
8
+use App\Models\Setting\Currency;
8
 use Illuminate\Support\Facades\Cache;
9
 use Illuminate\Support\Facades\Cache;
9
 
10
 
10
 class CompanySettingsService
11
 class CompanySettingsService
30
                 return self::getDefaultSettings();
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
             return [
39
             return [
34
                 'default_language' => $company->locale->language ?? config('transmatic.source_locale'),
40
                 'default_language' => $company->locale->language ?? config('transmatic.source_locale'),
35
                 'default_timezone' => $company->locale->timezone ?? config('app.timezone'),
41
                 'default_timezone' => $company->locale->timezone ?? config('app.timezone'),
36
-                'default_currency' => $company->currency_code ?? 'USD',
42
+                'default_currency' => $defaultCurrency,
37
                 'default_date_format' => $company->locale->date_format->value ?? DateFormat::DEFAULT,
43
                 'default_date_format' => $company->locale->date_format->value ?? DateFormat::DEFAULT,
38
                 'default_week_start' => $company->locale->week_start->value ?? WeekStart::DEFAULT,
44
                 'default_week_start' => $company->locale->week_start->value ?? WeekStart::DEFAULT,
39
             ];
45
             ];

+ 3
- 8
app/Utilities/Currency/CurrencyAccessor.php View File

5
 use Akaunting\Money\Currency as ISOCurrencies;
5
 use Akaunting\Money\Currency as ISOCurrencies;
6
 use App\Facades\Forex;
6
 use App\Facades\Forex;
7
 use App\Models\Setting\Currency;
7
 use App\Models\Setting\Currency;
8
-use Illuminate\Support\Facades\Cache;
8
+use App\Services\CompanySettingsService;
9
 
9
 
10
 class CurrencyAccessor
10
 class CurrencyAccessor
11
 {
11
 {
53
 
53
 
54
     public static function getDefaultCurrency(): ?string
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
         if ($companyId === null) {
58
         if ($companyId === null) {
60
             return 'USD';
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
 }

Loading…
Cancel
Save