|
@@ -2,13 +2,10 @@
|
2
|
2
|
|
3
|
3
|
namespace App\Listeners;
|
4
|
4
|
|
5
|
|
-use App\Enums\Setting\DateFormat;
|
6
|
|
-use App\Enums\Setting\Font;
|
7
|
5
|
use App\Enums\Setting\PrimaryColor;
|
8
|
6
|
use App\Enums\Setting\RecordsPerPage;
|
9
|
|
-use App\Enums\Setting\TableSortDirection;
|
10
|
|
-use App\Enums\Setting\WeekStart;
|
11
|
7
|
use App\Events\CompanyConfigured;
|
|
8
|
+use App\Services\CompanySettingsService;
|
12
|
9
|
use App\Utilities\Currency\ConfigureCurrencies;
|
13
|
10
|
use Filament\Facades\Filament;
|
14
|
11
|
use Filament\Forms\Components\DatePicker;
|
|
@@ -26,46 +23,39 @@ class ConfigureCompanyDefault
|
26
|
23
|
public function handle(CompanyConfigured $event): void
|
27
|
24
|
{
|
28
|
25
|
$company = $event->company;
|
|
26
|
+ $companyId = $company->id;
|
29
|
27
|
|
30
|
|
- session([
|
31
|
|
- 'current_company_id' => $company->id,
|
32
|
|
- 'default_language' => $company->locale->language ?? config('transmatic.source_locale'),
|
33
|
|
- 'default_timezone' => $company->locale->timezone ?? config('app.timezone'),
|
34
|
|
- 'default_pagination_page_option' => $company->appearance->records_per_page->value ?? RecordsPerPage::DEFAULT,
|
35
|
|
- 'default_sort' => $company->appearance->table_sort_direction->value ?? TableSortDirection::DEFAULT,
|
36
|
|
- 'default_primary_color' => $company->appearance->primary_color->value ?? PrimaryColor::DEFAULT,
|
37
|
|
- 'default_font' => $company->appearance->font->value ?? Font::DEFAULT,
|
38
|
|
- 'default_date_format' => $company->locale->date_format->value ?? DateFormat::DEFAULT,
|
39
|
|
- 'default_week_start' => $company->locale->week_start->value ?? WeekStart::DEFAULT,
|
40
|
|
- ]);
|
|
28
|
+ session(['current_company_id' => $companyId]);
|
|
29
|
+
|
|
30
|
+ $settings = CompanySettingsService::getSettings($companyId);
|
41
|
31
|
|
42
|
|
- app()->setLocale(session('default_language'));
|
43
|
|
- locale_set_default(session('default_language'));
|
44
|
|
- config(['app.timezone' => session('default_timezone')]);
|
45
|
|
- date_default_timezone_set(session('default_timezone'));
|
|
32
|
+ app()->setLocale($settings['default_language']);
|
|
33
|
+ locale_set_default($settings['default_language']);
|
|
34
|
+ config(['app.timezone' => $settings['default_timezone']]);
|
|
35
|
+ date_default_timezone_set($settings['default_timezone']);
|
46
|
36
|
|
47
|
37
|
$paginationPageOptions = RecordsPerPage::caseValues();
|
48
|
38
|
|
49
|
|
- Table::configureUsing(static function (Table $table) use ($paginationPageOptions): void {
|
|
39
|
+ Table::configureUsing(static function (Table $table) use ($settings, $paginationPageOptions): void {
|
50
|
40
|
|
51
|
41
|
$table
|
52
|
42
|
->paginationPageOptions($paginationPageOptions)
|
53
|
|
- ->defaultSort(column: 'id', direction: session('default_sort'))
|
54
|
|
- ->defaultPaginationPageOption(session('default_pagination_page_option'));
|
|
43
|
+ ->defaultSort(column: 'id', direction: $settings['default_sort'])
|
|
44
|
+ ->defaultPaginationPageOption($settings['default_pagination_page_option']);
|
55
|
45
|
}, isImportant: true);
|
56
|
46
|
|
57
|
47
|
FilamentColor::register([
|
58
|
|
- 'primary' => PrimaryColor::from(session('default_primary_color'))->getColor(),
|
|
48
|
+ 'primary' => PrimaryColor::from($settings['default_primary_color'])->getColor(),
|
59
|
49
|
]);
|
60
|
50
|
|
61
|
51
|
Filament::getPanel('company')
|
62
|
|
- ->font(session('default_font'))
|
|
52
|
+ ->font($settings['default_font'])
|
63
|
53
|
->brandName($company->name);
|
64
|
54
|
|
65
|
|
- DatePicker::configureUsing(static function (DatePicker $component) {
|
|
55
|
+ DatePicker::configureUsing(static function (DatePicker $component) use ($settings) {
|
66
|
56
|
$component
|
67
|
|
- ->displayFormat(session('default_date_format'))
|
68
|
|
- ->firstDayOfWeek(session('default_week_start'));
|
|
57
|
+ ->displayFormat($settings['default_date_format'])
|
|
58
|
+ ->firstDayOfWeek($settings['default_week_start']);
|
69
|
59
|
});
|
70
|
60
|
|
71
|
61
|
Tab::configureUsing(static function (Tab $tab) {
|