diff --git a/app/Filament/Pages/Company.php b/app/Filament/Pages/Company.php deleted file mode 100644 index de386c0..0000000 --- a/app/Filament/Pages/Company.php +++ /dev/null @@ -1,503 +0,0 @@ -user()->company; - - if (! $company) { - return; - } - - $this->isVerificationStage = in_array($company->verificationRequest?->status, [ - VerificationStatus::PENDING, - VerificationStatus::REJECTED, - ]) || $company->verificationRequest()->pending()->exists(); - - $this->verificationRequest = $company->verificationRequest() - ->latest() - ->first(); - - $this->company = $company; - - $this->form->fill($company->toArray()); - - $documents = [ - 'director_nik', - 'deed_incorporation', - 'trade_license', - 'tax_id_number', - 'taxable_enterprise', - 'annual_tax_return', - 'domicile_certificate', - 'profile', - ]; - - $mediaItems = $company->getMedia('companies'); - - foreach ($documents as $docType) { - $media = $mediaItems - ->where('custom_properties.doc_type', str($docType)->replace('_docs', '')->slug('-')) - ->sortByDesc('created_at') - ->first(); - - if ($media) { - $path = $media->getPathRelativeToRoot(); - $this->data["{$docType}_docs"] = [$path]; - $this->originalDocuments["{$docType}_docs"] = [$path]; - } - } - } - - public static function form(Schema $schema): Schema - { - $documents = [ - [ - 'title' => 'Akta Pendirian', - 'text_name' => 'deed_incorporation', - 'placeholder' => '*****', - 'max' => 150, - 'max_size' => 1024 * 10, - 'file_name' => 'deed_incorporation_docs', - 'accept' => ['application/pdf'], - 'folder' => 'companies/deed-incorporation/', - ], - [ - 'title' => 'SIUP / NIB', - 'text_name' => 'trade_license', - 'placeholder' => '*****', - 'max' => 150, - 'max_size' => 1024 * 10, - 'file_name' => 'trade_license_docs', - 'accept' => ['application/pdf'], - 'folder' => 'companies/trade-license/', - ], - [ - 'title' => 'NPWP', - 'text_name' => 'tax_id_number', - 'placeholder' => '*****', - 'max' => 150, - 'max_size' => 1024 * 10, - 'file_name' => 'tax_id_number_docs', - 'accept' => ['application/pdf'], - 'folder' => 'companies/tax-id-number/', - ], - [ - 'title' => 'PKP', - 'text_name' => 'taxable_enterprise', - 'placeholder' => '*****', - 'max' => 150, - 'max_size' => 1024 * 10, - 'file_name' => 'taxable_enterprise_docs', - 'accept' => ['application/pdf'], - 'folder' => 'companies/taxable-enterprise/', - ], - [ - 'title' => 'SPT Tahunan', - 'text_name' => 'annual_tax_return', - 'placeholder' => '*****', - 'max' => 150, - 'max_size' => 1024 * 10, - 'file_name' => 'annual_tax_return_docs', - 'accept' => ['application/pdf'], - 'folder' => 'companies/annual-tax-return/', - ], - [ - 'title' => 'Suket Domisili', - 'text_name' => 'domicile_certificate', - 'placeholder' => '*****', - 'max' => 150, - 'max_size' => 1024 * 10, - 'file_name' => 'domicile_certificate_docs', - 'accept' => ['application/pdf'], - 'folder' => 'companies/domicile-certificate/', - ], - [ - 'title' => 'Profil Perusahaan', - 'text_name' => 'profile', - 'placeholder' => '*****', - 'max' => 150, - 'max_size' => 1024 * 10, - 'file_name' => 'profile_docs', - 'accept' => ['application/pdf'], - 'folder' => 'companies/profile/', - ], - ]; - - return $schema - ->components([ - Section::make(fn () => CheerfulNotification::getByKey('company.section.title')) - ->description(fn () => CheerfulNotification::getByKey('company.section.description')) - ->icon(fn () => CheerfulNotification::getNotifStyle() === NotifStyle::CHEERFUL ? 'heroicon-o-building-office-2' : null) - ->schema([ - TextInput::make('name') - ->label('Nama') - ->placeholder('PT ABC Indonesia Abadi') - ->autocomplete(false) - ->autofocus() - ->required() - ->maxLength(100), - - TextInput::make('director_name') - ->label('Nama Direktur') - ->placeholder('John Doe') - ->autocomplete(false) - ->required() - ->maxLength(150), - - TextInput::make('email') - ->label('Alamat Surel') - ->placeholder('johndoe@example.com') - ->autocomplete(false) - ->required() - ->maxLength(254), - - TextInput::make('phone_number') - ->label('Nomor Telepon') - ->placeholder('08xx xxxx xxxx') - ->autocomplete(false) - ->maxLength(20) - ->tel(), - - Textarea::make('address') - ->label('Alamat') - ->placeholder('Jl. Kebontoro, Jakarta Pusat') - ->autocomplete(false) - ->required() - ->columnSpanFull(), - ]) - ->columns(2) - ->columnSpan(2), - - Group::make() - ->schema( - array_merge( - [ - Section::make(fn () => CheerfulNotification::getByKey('company.nik_section.title')) - ->icon(fn () => CheerfulNotification::getNotifStyle() === NotifStyle::CHEERFUL ? 'heroicon-o-user' : null) - ->schema([ - TextInput::make('director_nik') - ->hiddenLabel() - ->placeholder('32***') - ->autocomplete(false) - ->required() - ->maxLength(16) - ->rule('digits:16') - ->inputMode('numeric') - ->regex('/^[0-9]+$/'), - - AdvancedFileUpload::make('director_nik_docs') - ->hiddenLabel() - ->disk(config('filesystems.default')) - ->acceptedFileTypes(['image/*']) - ->maxSize(1024 * 3) - ->directory('companies/director-nik/'.now()->toDateString()) - ->helperText('Format yang diterima: JPEG, PNG. Ukuran maksimum: 3 MB.') - ->required(), - ]), - ], - - collect($documents) - ->map(function (array $doc): Section { - return Section::make(fn () => CheerfulNotification::getByKey('general.empty_msg', ['doc__title' => $doc['title']])) - ->icon(fn () => CheerfulNotification::getNotifStyle() === NotifStyle::CHEERFUL ? 'heroicon-o-document-text' : null) - ->schema([ - TextInput::make($doc['text_name']) - ->hiddenLabel() - ->placeholder($doc['placeholder']) - ->autocomplete(false) - ->required() - ->maxLength($doc['max']), - - AdvancedFileUpload::make($doc['file_name']) - ->hiddenLabel() - ->disk(config('filesystems.default')) - ->acceptedFileTypes($doc['accept']) - ->maxSize($doc['max_size']) - ->directory($doc['folder'].now()->toDateString()) - ->helperText('Format yang diterima: '.implode(', ', array_map(fn ($t) => strtoupper(str_replace('application/', '', $t)), $doc['accept'])).'. Ukuran maksimum: '.($doc['max_size'] / 1024).' MB.') - ->required(), - ]); - })->toArray() - ) - ) - ->columns(2), - ]) - ->statePath('data'); - } - - public function save(): void - { - $this->mountAction('save'); - } - - public function saveAction(): Action - { - $needsReview = $this->company?->verificationRequest?->status !== null; - - return Action::make('save') - ->label('Simpan') - ->modalHeading(fn () => CheerfulNotification::getByKey('company.save.title')) - ->modalDescription(fn () => CheerfulNotification::getByKey('company.save.description')) - ->modal($needsReview) - ->schema( - $needsReview - ? [ - Textarea::make('change_reason') - ->label('Alasan') - ->placeholder('Jelaskan alasan perubahan data ini...') - ->autocomplete(false) - ->autofocus() - ->required(), - ] - : [] - ) - ->action(function (array $data = []) use ($needsReview) { - try { - $this->performSave($data, $needsReview); - } catch (ValidationException $e) { - $this->unmountAction(); - - throw $e; - } - }) - ->modalWidth(Width::Large); - } - - public function performSave(array $data, bool $needsReview = false): void - { - if ($needsReview) { - $existingRequest = DataChangeRequest::where('entity_type', CompanyModel::class) - ->where('entity_id', $this->company->id) - ->where('status', DataChangeStatus::PENDING) - ->exists(); - - if ($existingRequest) { - CheerfulNotification::warning( - CheerfulNotification::getByKey('data_change.existing.title'), - CheerfulNotification::getByKey('data_change.existing.body') - ) - ->send(); - - return; - } - - $state = $this->form->getState(); - - $data = array_merge($state, $data); - - $fieldLabels = CompanyModel::dataChangeEntryLabels(); - - $editableFields = [ - 'name', - 'email', - 'phone_number', - 'address', - 'director_name', - 'director_nik', - 'deed_incorporation', - 'trade_license', - 'tax_id_number', - 'taxable_enterprise', - 'annual_tax_return', - 'domicile_certificate', - 'profile', - ]; - - $changedFields = []; - $oldData = []; - - foreach ($editableFields as $field) { - if ($this->company->{$field} !== ($data[$field] ?? null)) { - $label = $fieldLabels[$field] ?? $field; - $changedFields[$label] = $data[$field] ?? null; - $oldData[$label] = $this->company->{$field}; - } - } - - $documents = [ - 'director_nik_docs', - 'deed_incorporation_docs', - 'trade_license_docs', - 'tax_id_number_docs', - 'taxable_enterprise_docs', - 'annual_tax_return_docs', - 'domicile_certificate_docs', - 'profile_docs', - ]; - - foreach ($documents as $field) { - $newValue = $this->data[$field] ?? []; - $oldValue = $this->originalDocuments[$field] ?? []; - - // Compare as arrays since file uploads are often arrays - if (json_encode($newValue) !== json_encode($oldValue)) { - $label = $fieldLabels[$field] ?? $field; - $changedFields[$label] = $newValue; - $oldData[$label] = $oldValue; - } - } - - if (empty($changedFields)) { - CheerfulNotification::info( - CheerfulNotification::getByKey('data_change.no_change.title'), - CheerfulNotification::getByKey('data_change.no_change.body') - ) - ->send(); - - return; - } - - $dataChangeRequest = DataChangeRequest::create([ - 'user_id' => auth()->id(), - 'entity_type' => CompanyModel::class, - 'entity_id' => $this->company->id, - 'old_data' => $oldData, - 'new_data' => $changedFields, - 'change_reason' => $data['change_reason'], - ]); - - CheerfulNotification::success( - CheerfulNotification::getByKey('data_change.success.title'), - CheerfulNotification::getByKey('data_change.success.body') - ) - ->send(); - - User::superAdmin() - ->get() - ->each(function ($admin) use ($dataChangeRequest): void { - $admin->notify(new BroadcastNotification([ - 'title' => CheerfulNotification::getByKey('data_change.admin_notify.title'), - 'body' => CheerfulNotification::getByKey('data_change.admin_notify.body', ['name' => auth()->user()->name]), - 'action' => [ - Action::make('view') - ->label('Lihat') - ->url(DataChangesResource::getUrl('view', ['record' => $dataChangeRequest->id])), - ], - ])); - }); - } else { - $data = $this->form->getState(); - - $company = CompanyModel::updateOrCreate([ - 'id' => $this->company?->id, - ], [ - 'user_id' => auth()->id(), - 'name' => $data['name'], - 'email' => $data['email'], - 'phone_number' => $data['phone_number'], - 'address' => $data['address'], - 'director_name' => $data['director_name'], - 'director_nik' => $data['director_nik'], - 'deed_incorporation' => $data['deed_incorporation'], - 'trade_license' => $data['trade_license'], - 'tax_id_number' => $data['tax_id_number'], - 'taxable_enterprise' => $data['taxable_enterprise'], - 'annual_tax_return' => $data['annual_tax_return'], - 'domicile_certificate' => $data['domicile_certificate'], - 'profile' => $data['profile'], - ]); - - $this->company = $company; - - $documents = [ - 'director_nik_docs', - 'deed_incorporation_docs', - 'trade_license_docs', - 'tax_id_number_docs', - 'taxable_enterprise_docs', - 'annual_tax_return_docs', - 'domicile_certificate_docs', - 'profile_docs', - ]; - - foreach ($documents as $field) { - if (empty($this->data[$field])) { - continue; - } - - foreach ((array) $this->data[$field] as $filePath) { - $fullPath = Storage::disk(config('filesystems.default'))->path($filePath); - - if (! file_exists($fullPath)) { - continue; - } - - $company - ->addMediaFromDisk($filePath, config('filesystems.default')) - ->preservingOriginal() - ->withCustomProperties([ - 'feature' => 'companies', - 'date' => now()->toDateString(), - 'doc_type' => str($field) - ->replace('_docs', '') - ->slug('-'), - ]) - ->toMediaCollection('companies'); - } - } - - if ($this->company) { - CheerfulNotification::update()->send(); - } else { - CheerfulNotification::create()->send(); - } - } - } -} diff --git a/app/Filament/Pages/Company/Actions/SaveCompanyAction.php b/app/Filament/Pages/Company/Actions/SaveCompanyAction.php new file mode 100644 index 0000000..1fd7ead --- /dev/null +++ b/app/Filament/Pages/Company/Actions/SaveCompanyAction.php @@ -0,0 +1,40 @@ +label('Simpan') + ->modalHeading(fn () => CheerfulNotification::getByKey('company.save.title')) + ->modalDescription(fn () => CheerfulNotification::getByKey('company.save.description')) + ->modal(fn (): bool => (bool) ($this->getLivewire()?->needsCompanyReview())) + ->schema(fn (): array => ($this->getLivewire()?->needsCompanyReview()) + ? [ + Textarea::make('change_reason') + ->label('Alasan') + ->placeholder('Jelaskan alasan perubahan data ini...') + ->autocomplete(false) + ->autofocus() + ->required(), + ] + : []) + ->action(function (array $data = []): void { + $this->getLivewire()?->handleCompanySave($data); + }) + ->modalWidth(Width::Large); + } +} diff --git a/app/Filament/Pages/Company/Concerns/HasCompanyActions.php b/app/Filament/Pages/Company/Concerns/HasCompanyActions.php new file mode 100644 index 0000000..43ee7e5 --- /dev/null +++ b/app/Filament/Pages/Company/Concerns/HasCompanyActions.php @@ -0,0 +1,14 @@ +user()->can('View:Company'); + } + + public function mount(): void + { + $company = Filament::auth()->user()?->company; + + if (! $company) { + return; + } + + $this->isVerificationStage = in_array($company->verificationRequest?->status, [ + VerificationStatus::PENDING, + VerificationStatus::REJECTED, + ]) || $company->verificationRequest()->pending()->exists(); + + $this->verificationRequest = $company->verificationRequest() + ->latest() + ->first(); + + $this->company = $company; + + $this->form->fill($company->toArray()); + + $documents = [ + 'director_nik', + 'deed_incorporation', + 'trade_license', + 'tax_id_number', + 'taxable_enterprise', + 'annual_tax_return', + 'domicile_certificate', + 'profile', + ]; + + $mediaItems = $company->getMedia('companies'); + + foreach ($documents as $docType) { + $media = $mediaItems + ->where('custom_properties.doc_type', str($docType)->replace('_docs', '')->slug('-')) + ->sortByDesc('created_at') + ->first(); + + if ($media) { + $path = $media->getPathRelativeToRoot(); + $this->data["{$docType}_docs"] = [$path]; + $this->originalDocuments["{$docType}_docs"] = [$path]; + } + } + } + + public static function form(Schema $schema): Schema + { + return CompanyForm::configure($schema); + } + + public function save(): void + { + $this->mountAction('save'); + } + + public function needsCompanyReview(): bool + { + return $this->company?->verificationRequest?->status !== null; + } + + public function handleCompanySave(array $data = []): void + { + try { + $company = CompanySaveService::handle( + existingCompany: $this->company, + formState: $this->form->getState(), + pageData: $this->data, + originalDocuments: $this->originalDocuments, + needsReview: $this->needsCompanyReview(), + actionData: $data, + ); + + if ($this->needsCompanyReview()) { + return; + } + + $this->company = $company; + + CheerfulNotification::update()->send(); + } catch (ValidationException $e) { + $this->unmountAction(); + + throw $e; + } + } +} diff --git a/app/Filament/Pages/Company/Schemas/CompanyForm.php b/app/Filament/Pages/Company/Schemas/CompanyForm.php new file mode 100644 index 0000000..1e06729 --- /dev/null +++ b/app/Filament/Pages/Company/Schemas/CompanyForm.php @@ -0,0 +1,195 @@ +components([ + Section::make(fn () => CheerfulNotification::getByKey('company.section.title')) + ->description(fn () => CheerfulNotification::getByKey('company.section.description')) + ->icon(fn () => CheerfulNotification::getNotifStyle() === NotifStyle::CHEERFUL ? 'heroicon-o-building-office-2' : null) + ->schema([ + TextInput::make('name') + ->label('Nama') + ->placeholder('PT ABC Indonesia Abadi') + ->autocomplete(false) + ->autofocus() + ->required() + ->maxLength(100), + + TextInput::make('director_name') + ->label('Nama Direktur') + ->placeholder('John Doe') + ->autocomplete(false) + ->required() + ->maxLength(150), + + TextInput::make('email') + ->label('Alamat Surel') + ->placeholder('johndoe@example.com') + ->autocomplete(false) + ->required() + ->maxLength(254), + + TextInput::make('phone_number') + ->label('Nomor Telepon') + ->placeholder('08xx xxxx xxxx') + ->autocomplete(false) + ->maxLength(20) + ->tel(), + + Textarea::make('address') + ->label('Alamat') + ->placeholder('Jl. Kebontoro, Jakarta Pusat') + ->autocomplete(false) + ->required() + ->columnSpanFull(), + ]) + ->columns(2) + ->columnSpan(2), + + Group::make() + ->schema( + array_merge( + [ + Section::make('NIk Direktur') + ->schema([ + TextInput::make('director_nik') + ->hiddenLabel() + ->placeholder('32***') + ->autocomplete(false) + ->required() + ->maxLength(16) + ->rule('digits:16') + ->inputMode('numeric') + ->regex('/^[0-9]+$/'), + + AdvancedFileUpload::make('director_nik_docs') + ->hiddenLabel() + ->disk(config('filesystems.default')) + ->acceptedFileTypes(['image/*']) + ->maxSize(1024 * 3) + ->directory('companies/director-nik/'.now()->toDateString()) + ->helperText('Format yang diterima: JPEG, PNG. Ukuran maksimum: 3 MB.') + ->required(), + ]), + ], + + collect($documents) + ->map(function (array $doc): Section { + return Section::make(fn () => $doc['title']) + ->schema([ + TextInput::make($doc['text_name']) + ->hiddenLabel() + ->placeholder($doc['placeholder']) + ->autocomplete(false) + ->required() + ->maxLength($doc['max']), + + AdvancedFileUpload::make($doc['file_name']) + ->hiddenLabel() + ->disk(config('filesystems.default')) + ->acceptedFileTypes($doc['accept']) + ->maxSize($doc['max_size']) + ->directory($doc['folder'].now()->toDateString()) + ->helperText('Format yang diterima: '.implode(', ', array_map(fn ($t) => strtoupper(str_replace('application/', '', $t)), $doc['accept'])).'. Ukuran maksimum: '.($doc['max_size'] / 1024).' MB.') + ->required(), + ]); + })->toArray() + ) + ) + ->columns(2), + ]) + ->statePath('data'); + } + + public static function getDocuments(): array + { + return [ + [ + 'title' => 'Akta Pendirian', + 'text_name' => 'deed_incorporation', + 'placeholder' => '*****', + 'max' => 150, + 'max_size' => 1024 * 10, + 'file_name' => 'deed_incorporation_docs', + 'accept' => ['application/pdf'], + 'folder' => 'companies/deed-incorporation/', + ], + [ + 'title' => 'SIUP / NIB', + 'text_name' => 'trade_license', + 'placeholder' => '*****', + 'max' => 150, + 'max_size' => 1024 * 10, + 'file_name' => 'trade_license_docs', + 'accept' => ['application/pdf'], + 'folder' => 'companies/trade-license/', + ], + [ + 'title' => 'NPWP', + 'text_name' => 'tax_id_number', + 'placeholder' => '*****', + 'max' => 150, + 'max_size' => 1024 * 10, + 'file_name' => 'tax_id_number_docs', + 'accept' => ['application/pdf'], + 'folder' => 'companies/tax-id-number/', + ], + [ + 'title' => 'PKP', + 'text_name' => 'taxable_enterprise', + 'placeholder' => '*****', + 'max' => 150, + 'max_size' => 1024 * 10, + 'file_name' => 'taxable_enterprise_docs', + 'accept' => ['application/pdf'], + 'folder' => 'companies/taxable-enterprise/', + ], + [ + 'title' => 'SPT Tahunan', + 'text_name' => 'annual_tax_return', + 'placeholder' => '*****', + 'max' => 150, + 'max_size' => 1024 * 10, + 'file_name' => 'annual_tax_return_docs', + 'accept' => ['application/pdf'], + 'folder' => 'companies/annual-tax-return/', + ], + [ + 'title' => 'Suket Domisili', + 'text_name' => 'domicile_certificate', + 'placeholder' => '*****', + 'max' => 150, + 'max_size' => 1024 * 10, + 'file_name' => 'domicile_certificate_docs', + 'accept' => ['application/pdf'], + 'folder' => 'companies/domicile-certificate/', + ], + [ + 'title' => 'Profil Perusahaan', + 'text_name' => 'profile', + 'placeholder' => '*****', + 'max' => 150, + 'max_size' => 1024 * 10, + 'file_name' => 'profile_docs', + 'accept' => ['application/pdf'], + 'folder' => 'companies/profile/', + ], + ]; + } +} diff --git a/app/Filament/Pages/Company/Services/CompanySaveService.php b/app/Filament/Pages/Company/Services/CompanySaveService.php new file mode 100644 index 0000000..f74423f --- /dev/null +++ b/app/Filament/Pages/Company/Services/CompanySaveService.php @@ -0,0 +1,213 @@ +where('entity_id', $company->id) + ->where('status', DataChangeStatus::PENDING) + ->exists(); + + if ($existingRequest) { + CheerfulNotification::warning( + CheerfulNotification::getByKey('data_change.existing.title'), + CheerfulNotification::getByKey('data_change.existing.body') + )->send(); + + return; + } + + $data = array_merge($formState, $actionData); + $fieldLabels = CompanyModel::dataChangeEntryLabels(); + + $editableFields = [ + 'name', + 'email', + 'phone_number', + 'address', + 'director_name', + 'director_nik', + 'deed_incorporation', + 'trade_license', + 'tax_id_number', + 'taxable_enterprise', + 'annual_tax_return', + 'domicile_certificate', + 'profile', + ]; + + $changedFields = []; + $oldData = []; + + foreach ($editableFields as $field) { + if ($company->{$field} !== ($data[$field] ?? null)) { + $label = $fieldLabels[$field] ?? $field; + $changedFields[$label] = $data[$field] ?? null; + $oldData[$label] = $company->{$field}; + } + } + + $documents = [ + 'director_nik_docs', + 'deed_incorporation_docs', + 'trade_license_docs', + 'tax_id_number_docs', + 'taxable_enterprise_docs', + 'annual_tax_return_docs', + 'domicile_certificate_docs', + 'profile_docs', + ]; + + foreach ($documents as $field) { + $newValue = $pageData[$field] ?? []; + $oldValue = $originalDocuments[$field] ?? []; + + // Compare as arrays since file uploads are often arrays + if (json_encode($newValue) !== json_encode($oldValue)) { + $label = $fieldLabels[$field] ?? $field; + $changedFields[$label] = $newValue; + $oldData[$label] = $oldValue; + } + } + + if (empty($changedFields)) { + CheerfulNotification::info( + CheerfulNotification::getByKey('data_change.no_change.title'), + CheerfulNotification::getByKey('data_change.no_change.body') + )->send(); + + return; + } + + $dataChangeRequest = DataChangeRequest::create([ + 'user_id' => auth()->id(), + 'entity_type' => CompanyModel::class, + 'entity_id' => $company->id, + 'old_data' => $oldData, + 'new_data' => $changedFields, + 'change_reason' => $data['change_reason'] ?? null, + ]); + + CheerfulNotification::success( + CheerfulNotification::getByKey('data_change.success.title'), + CheerfulNotification::getByKey('data_change.success.body') + )->send(); + + User::query() + ->superAdmin() + ->get() + ->each(function ($admin) use ($dataChangeRequest): void { + $admin->notify(new BroadcastNotification([ + 'title' => CheerfulNotification::getByKey('data_change.admin_notify.title'), + 'body' => CheerfulNotification::getByKey('data_change.admin_notify.body', ['name' => auth()->user()->name]), + 'action' => [ + Action::make('view') + ->label('Lihat') + ->url(DataChangesResource::getUrl('view', ['record' => $dataChangeRequest->id])), + ], + ])); + }); + } + + private static function saveCompanyDirectly(?CompanyModel $existingCompany, array $formState, array $pageData): CompanyModel + { + $company = CompanyModel::updateOrCreate([ + 'id' => $existingCompany?->id, + ], [ + 'user_id' => auth()->id(), + 'name' => $formState['name'], + 'email' => $formState['email'], + 'phone_number' => $formState['phone_number'], + 'address' => $formState['address'], + 'director_name' => $formState['director_name'], + 'director_nik' => $formState['director_nik'], + 'deed_incorporation' => $formState['deed_incorporation'], + 'trade_license' => $formState['trade_license'], + 'tax_id_number' => $formState['tax_id_number'], + 'taxable_enterprise' => $formState['taxable_enterprise'], + 'annual_tax_return' => $formState['annual_tax_return'], + 'domicile_certificate' => $formState['domicile_certificate'], + 'profile' => $formState['profile'], + ]); + + $documents = [ + 'director_nik_docs', + 'deed_incorporation_docs', + 'trade_license_docs', + 'tax_id_number_docs', + 'taxable_enterprise_docs', + 'annual_tax_return_docs', + 'domicile_certificate_docs', + 'profile_docs', + ]; + + foreach ($documents as $field) { + if (empty($pageData[$field])) { + continue; + } + + foreach ((array) $pageData[$field] as $filePath) { + $fullPath = Storage::disk(config('filesystems.default'))->path($filePath); + + if (! file_exists($fullPath)) { + continue; + } + + $company + ->addMediaFromDisk($filePath, config('filesystems.default')) + ->preservingOriginal() + ->withCustomProperties([ + 'feature' => 'companies', + 'date' => now()->toDateString(), + 'doc_type' => str($field) + ->replace('_docs', '') + ->slug('-'), + ]) + ->toMediaCollection('companies'); + } + } + + return $company; + } +} diff --git a/lang/id/notif.php b/lang/id/notif.php index 20367f2..ab5dbf6 100644 --- a/lang/id/notif.php +++ b/lang/id/notif.php @@ -539,12 +539,6 @@ 'formal' => 'Kelola informasi detail perusahaan Anda di sini.', ], ], - 'nik_section' => [ - 'title' => [ - 'cheerful' => 'NIK Direktur ๐Ÿ‘คโœจ', - 'formal' => 'NIK Direktur', - ], - ], 'save' => [ 'title' => [ 'cheerful' => 'Ajukan Perubahan Profil ๐Ÿ“โœจ', @@ -580,42 +574,6 @@ 'cheerful' => 'Lengkapi profil perusahaanmu dan pantau status verifikasinya di sini. Semangat! ๐Ÿ’ช', 'formal' => 'Informasi umum perusahaan serta status verifikasinya.', ], - 'director_nik' => [ - 'cheerful' => 'NIK Direktur ๐Ÿ‘คโœจ', - 'formal' => 'NIK Direktur', - ], - 'establishment_deed' => [ - 'cheerful' => 'Akta Pendirian Perusahaan ๐Ÿ“„โœจ', - 'formal' => 'Akta Pendirian', - ], - 'siup_nib' => [ - 'cheerful' => 'SIUP/NIB Perusahaan ๐Ÿ“„โœจ', - 'formal' => 'SIUP/NIB', - ], - 'npwp' => [ - 'cheerful' => 'NPWP Perusahaan ๐Ÿงพโœจ', - 'formal' => 'NPWP', - ], - 'pkp' => [ - 'cheerful' => 'PKP (Pengusaha Kena Pajak) ๐Ÿงพโœจ', - 'formal' => 'PKP (Pengusaha Kena Pajak)', - ], - 'annual_tax' => [ - 'cheerful' => 'SPT Tahunan Perusahaan ๐Ÿ“‘โœจ', - 'formal' => 'SPT Tahunan', - ], - 'domicile' => [ - 'cheerful' => 'Surat Keterangan Domisili ๐Ÿ โœจ', - 'formal' => 'Surat Keterangan Domisili', - ], - 'company_profile' => [ - 'cheerful' => 'Profil Perusahaan ๐Ÿ—๏ธโœจ', - 'formal' => 'Profil Perusahaan', - ], - 'media_title' => [ - 'cheerful' => 'Profil Media Rekanan ๐Ÿ“ฐโœจ', - 'formal' => 'Informasi Media', - ], 'media_desc' => [ 'cheerful' => 'Detail media rekanan perusahaanmu. Lengkapi datanya biar makin kredibel! ๐Ÿคโœจ', 'formal' => 'Detail media rekanan yang terhubung dengan perusahaan.',