Don't show both addresses if they're the same

This commit is contained in:
Hillel Coren 2018-02-14 14:05:40 +02:00
parent 1aa59512fe
commit 7bc91e5b0b
3 changed files with 31 additions and 4 deletions

View File

@ -386,6 +386,29 @@ class Client extends EntityModel
return $this->hasAddress() && env('GOOGLE_MAPS_ENABLED') !== false; 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 * @return bool
*/ */

View File

@ -56,7 +56,7 @@ class ClientPresenter extends EntityPresenter
return sprintf('%s: %s %s', trans('texts.payment_terms'), trans('texts.payment_terms_net'), $client->defaultDaysDue()); 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 = ''; $str = '';
$prefix = $addressType == ADDRESS_BILLING ? '' : 'shipping_'; $prefix = $addressType == ADDRESS_BILLING ? '' : 'shipping_';
@ -75,7 +75,7 @@ class ClientPresenter extends EntityPresenter
$str .= e($country->getName()) . '<br/>'; $str .= e($country->getName()) . '<br/>';
} }
if ($str) { if ($str && $showHeader) {
$str = '<b>' . trans('texts.' . $addressType) . '</b><br/>' . $str; $str = '<b>' . trans('texts.' . $addressType) . '</b><br/>' . $str;
} }

View File

@ -154,8 +154,12 @@
<div class="col-md-3"> <div class="col-md-3">
<h3>{{ trans('texts.address') }}</h3> <h3>{{ trans('texts.address') }}</h3>
{!! $client->present()->address(ADDRESS_BILLING) !!}<br/> @if ($client->addressesMatch())
{!! $client->present()->address(ADDRESS_SHIPPING) !!} {!! $client->present()->address(ADDRESS_BILLING) !!}
@else
{!! $client->present()->address(ADDRESS_BILLING, true) !!}<br/>
{!! $client->present()->address(ADDRESS_SHIPPING, true) !!}
@endif
</div> </div>