diff --git a/app/Services/TaxInvoiceService.php b/app/Services/TaxInvoiceService.php index 862a46b..796cba6 100644 --- a/app/Services/TaxInvoiceService.php +++ b/app/Services/TaxInvoiceService.php @@ -3,6 +3,7 @@ namespace App\Services; use App\Models\Tenants\TaxInvoice; +use App\Models\Tenants\Tenant; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Support\Facades\DB; @@ -276,26 +277,61 @@ public function checkStatus(int $id): TaxInvoice // ========================================================================= /** - * 공급자 설정 조회 (BarobillSetting 기반) + * 공급자 설정 조회 (BarobillSetting 기반, 미설정 시 Tenant 정보 Fallback) */ public function getSupplierSettings(): array { $setting = $this->barobillService->getSetting(); - if (! $setting) { + if ($setting && $this->hasSupplierData($setting)) { + return [ + 'business_number' => $setting->corp_num, + 'company_name' => $setting->corp_name, + 'representative_name' => $setting->ceo_name, + 'address' => $setting->addr, + 'business_type' => $setting->biz_type, + 'business_item' => $setting->biz_class, + 'contact_name' => $setting->contact_name, + 'contact_phone' => $setting->contact_tel, + 'contact_email' => $setting->contact_id, + ]; + } + + // BarobillSetting 미설정 시 Tenant 정보를 기본값으로 반환 + return $this->getSupplierSettingsFromTenant(); + } + + /** + * BarobillSetting에 공급자 정보가 입력되어 있는지 확인 + */ + private function hasSupplierData($setting): bool + { + return ! empty($setting->corp_num) || ! empty($setting->corp_name); + } + + /** + * Tenant 정보에서 공급자 설정 기본값 조회 + */ + private function getSupplierSettingsFromTenant(): array + { + $tenant = Tenant::find($this->tenantId()); + + if (! $tenant) { return []; } + $options = $tenant->options ?? []; + return [ - 'business_number' => $setting->corp_num, - 'company_name' => $setting->corp_name, - 'representative_name' => $setting->ceo_name, - 'address' => $setting->addr, - 'business_type' => $setting->biz_type, - 'business_item' => $setting->biz_class, - 'contact_name' => $setting->contact_name, - 'contact_phone' => $setting->contact_tel, - 'contact_email' => $setting->contact_id, + 'business_number' => $tenant->business_num ?? '', + 'company_name' => $tenant->company_name ?? '', + 'representative_name' => $tenant->ceo_name ?? '', + 'address' => $tenant->address ?? '', + 'business_type' => $options['business_type'] ?? '', + 'business_item' => $options['business_category'] ?? '', + 'contact_name' => $options['tax_invoice_contact'] ?? '', + 'contact_phone' => $tenant->phone ?? '', + 'contact_email' => $options['tax_invoice_email'] ?? '', ]; }