You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConfigureCompanyDefault.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Listeners;
  3. use App\Enums\Setting\DateFormat;
  4. use App\Enums\Setting\Font;
  5. use App\Enums\Setting\PrimaryColor;
  6. use App\Enums\Setting\RecordsPerPage;
  7. use App\Enums\Setting\TableSortDirection;
  8. use App\Enums\Setting\WeekStart;
  9. use App\Events\CompanyConfigured;
  10. use App\Utilities\Currency\ConfigureCurrencies;
  11. use Filament\Facades\Filament;
  12. use Filament\Forms\Components\DatePicker;
  13. use Filament\Forms\Components\Section;
  14. use Filament\Forms\Components\Tabs\Tab;
  15. use Filament\Resources\Components\Tab as ResourcesTab;
  16. use Filament\Support\Facades\FilamentColor;
  17. use Filament\Tables\Table;
  18. class ConfigureCompanyDefault
  19. {
  20. /**
  21. * Handle the event.
  22. */
  23. public function handle(CompanyConfigured $event): void
  24. {
  25. $company = $event->company;
  26. session([
  27. 'current_company_id' => $company->id,
  28. 'default_language' => $company->locale->language ?? config('transmatic.source_locale'),
  29. 'default_timezone' => $company->locale->timezone ?? config('app.timezone'),
  30. 'default_pagination_page_option' => $company->appearance->records_per_page->value ?? RecordsPerPage::DEFAULT,
  31. 'default_sort' => $company->appearance->table_sort_direction->value ?? TableSortDirection::DEFAULT,
  32. 'default_primary_color' => $company->appearance->primary_color->value ?? PrimaryColor::DEFAULT,
  33. 'default_font' => $company->appearance->font->value ?? Font::DEFAULT,
  34. 'default_date_format' => $company->locale->date_format->value ?? DateFormat::DEFAULT,
  35. 'default_week_start' => $company->locale->week_start->value ?? WeekStart::DEFAULT,
  36. ]);
  37. app()->setLocale(session('default_language'));
  38. locale_set_default(session('default_language'));
  39. config(['app.timezone' => session('default_timezone')]);
  40. date_default_timezone_set(session('default_timezone'));
  41. $paginationPageOptions = RecordsPerPage::caseValues();
  42. Table::configureUsing(static function (Table $table) use ($paginationPageOptions): void {
  43. $table
  44. ->paginationPageOptions($paginationPageOptions)
  45. ->defaultSort(column: 'id', direction: session('default_sort'))
  46. ->defaultPaginationPageOption(session('default_pagination_page_option'));
  47. }, isImportant: true);
  48. FilamentColor::register([
  49. 'primary' => PrimaryColor::from(session('default_primary_color'))->getColor(),
  50. ]);
  51. Filament::getPanel('company')
  52. ->font(session('default_font'))
  53. ->brandName($company->name);
  54. DatePicker::configureUsing(static function (DatePicker $component) {
  55. $component
  56. ->displayFormat(session('default_date_format'))
  57. ->firstDayOfWeek(session('default_week_start'));
  58. });
  59. Tab::configureUsing(static function (Tab $tab) {
  60. $label = $tab->getLabel();
  61. $translatedLabel = translate($label);
  62. $tab->label(ucwords($translatedLabel));
  63. }, isImportant: true);
  64. Section::configureUsing(static function (Section $section): void {
  65. $heading = $section->getHeading();
  66. $translatedHeading = translate($heading);
  67. $section->heading(ucfirst($translatedHeading));
  68. }, isImportant: true);
  69. ResourcesTab::configureUsing(static function (ResourcesTab $tab): void {
  70. $tab->localizeLabel();
  71. }, isImportant: true);
  72. ConfigureCurrencies::syncCurrencies();
  73. }
  74. }