diff --git a/app/Models/Client.php b/app/Models/Client.php index ed98781ff4..de128945ad 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -386,6 +386,29 @@ class Client extends EntityModel return $this->hasAddress() && env('GOOGLE_MAPS_ENABLED') !== false; } + /** + * @return bool + */ + public function addressesMatch() + { + $fields = [ + 'address1', + 'address2', + 'city', + 'state', + 'postal_code', + 'country_id', + ]; + + foreach ($fields as $field) { + if ($this->$field != $this->{'shipping_' . $field}) { + return false; + } + } + + return true; + } + /** * @return bool */ diff --git a/app/Ninja/Presenters/ClientPresenter.php b/app/Ninja/Presenters/ClientPresenter.php index e968cc8807..75ca8b4e56 100644 --- a/app/Ninja/Presenters/ClientPresenter.php +++ b/app/Ninja/Presenters/ClientPresenter.php @@ -56,7 +56,7 @@ class ClientPresenter extends EntityPresenter return sprintf('%s: %s %s', trans('texts.payment_terms'), trans('texts.payment_terms_net'), $client->defaultDaysDue()); } - public function address($addressType = ADDRESS_BILLING) + public function address($addressType = ADDRESS_BILLING, $showHeader = false) { $str = ''; $prefix = $addressType == ADDRESS_BILLING ? '' : 'shipping_'; @@ -75,7 +75,7 @@ class ClientPresenter extends EntityPresenter $str .= e($country->getName()) . '
'; } - if ($str) { + if ($str && $showHeader) { $str = '' . trans('texts.' . $addressType) . '
' . $str; } diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index 0857c38ad8..b59c26f98a 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -154,8 +154,12 @@

{{ trans('texts.address') }}

- {!! $client->present()->address(ADDRESS_BILLING) !!}
- {!! $client->present()->address(ADDRESS_SHIPPING) !!} + @if ($client->addressesMatch()) + {!! $client->present()->address(ADDRESS_BILLING) !!} + @else + {!! $client->present()->address(ADDRESS_BILLING, true) !!}
+ {!! $client->present()->address(ADDRESS_SHIPPING, true) !!} + @endif