diff --git a/app/Models/Presenters/CompanyPresenter.php b/app/Models/Presenters/CompanyPresenter.php index 7c3be7c066..c3aeec5595 100644 --- a/app/Models/Presenters/CompanyPresenter.php +++ b/app/Models/Presenters/CompanyPresenter.php @@ -28,7 +28,29 @@ class CompanyPresenter extends EntityPresenter public function address() { - + $str = ''; + $company = $this->entity; + + if ($address1 = $company->address1) { + $str .= e($address1) . '
'; + } + if ($address2 = $company->address2) { + $str .= e($address2) . '
'; + } + if ($cityState = $this->getCityState()) { + $str .= e($cityState) . '
'; + } + if ($country = $company->country) { + $str .= e($country->name) . '
'; + } + if ($company->work_phone) { + $str .= ctrans('texts.work_phone') . ": ". e($company->work_phone) .'
'; + } + if ($company->work_email) { + $str .= ctrans('texts.work_email') . ": ". e($company->work_email) .'
'; + } + + return $str; } } diff --git a/app/Models/Presenters/EntityPresenter.php b/app/Models/Presenters/EntityPresenter.php index 5f8c94c145..25b4fc99da 100644 --- a/app/Models/Presenters/EntityPresenter.php +++ b/app/Models/Presenters/EntityPresenter.php @@ -97,4 +97,37 @@ class EntityPresenter extends Presenter } + public function getCityState() + { + $client = $this->entity; + $swap = $client->country && $client->country->swap_postal_code; + + $city = e($client->city); + $state = e($client->state); + $postalCode = e($client->postal_code); + + if ($city || $state || $postalCode) { + return $this->cityStateZip($city, $state, $postalCode, $swap); + } else { + return false; + } + } + + public function cityStateZip($city, $state, $postalCode, $swap) + { + $str = $city; + + if ($state) { + if ($str) { + $str .= ', '; + } + $str .= $state; + } + + if ($swap) { + return $postalCode . ' ' . $str; + } else { + return $str . ' ' . $postalCode; + } + } } diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php index c55cbd00a7..6b159a0c24 100644 --- a/database/factories/CompanyFactory.php +++ b/database/factories/CompanyFactory.php @@ -10,5 +10,13 @@ $factory->define(App\Models\Company::class, function (Faker $faker) { 'ip' => $faker->ipv4, 'db' => config('database.default'), 'settings' => new CompanySettings(CompanySettings::defaults()), + 'address1' => $faker->secondaryAddress, + 'address2' => $faker->address, + 'city' => $faker->city, + 'state' => $faker->state, + 'postal_code' => $faker->postcode, + 'country_id' => 4, + 'work_phone' => $faker->phoneNumber, + 'work_email' => $faker->safeEmail, ]; });