added address format

This commit is contained in:
Cihan Şentürk 2024-07-23 11:00:39 +03:00 committed by GitHub
parent 9ab96cdf2c
commit bad6a8a620
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 37 additions and 51 deletions

View File

@ -39,6 +39,7 @@ class Setting extends FormRequest
'expense_category' => 'required|integer',
'income_category' => 'required|integer',
'payment_method' => 'required|string|payment_method',
'address_format' => 'required|string',
];
break;

View File

@ -544,27 +544,13 @@ class Company extends Eloquent implements Ownable
public function getLocationAttribute()
{
$location = [];
if (setting('company.city')) {
$location[] = setting('company.city');
}
if (setting('company.zip_code')) {
$location[] = setting('company.zip_code');
}
if (setting('company.state')) {
$location[] = setting('company.state');
}
$country = setting('company.country');
if ($country && array_key_exists($country, trans('countries'))) {
$location[] = trans('countries.' . $country);
$trans_country = trans('countries.' . $country);
}
return implode(', ', $location);
return $this->getFormattedAddress(setting('company.city'), $trans_country ?? null, setting('company.state'), setting('company.zip_code'));
}
/**

View File

@ -312,25 +312,11 @@ class Contact extends Model
public function getLocationAttribute()
{
$location = [];
if ($this->city) {
$location[] = $this->city;
}
if ($this->state) {
$location[] = $this->state;
}
if ($this->zip_code) {
$location[] = $this->zip_code;
}
if ($this->country && array_key_exists($this->country, trans('countries'))) {
$location[] = trans('countries.' . $this->country);
$country = trans('countries.' . $this->country);
}
return implode(', ', $location);
return $this->getFormattedAddress($this->city, $country ?? null, $this->state, $this->zip_code);
}
/**

View File

@ -7,6 +7,7 @@ use App\Interfaces\Utility\DocumentNumber;
use App\Models\Common\Media as MediaModel;
use App\Models\Setting\Tax;
use App\Scopes\Document as Scope;
use App\Traits\Contacts;
use App\Traits\Currencies;
use App\Traits\DateTime;
use App\Traits\Documents;
@ -20,7 +21,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
class Document extends Model
{
use HasFactory, Documents, Cloneable, Currencies, DateTime, Media, Recurring;
use HasFactory, Documents, Cloneable, Contacts, Currencies, DateTime, Media, Recurring;
public const INVOICE_TYPE = 'invoice';
public const INVOICE_RECURRING_TYPE = 'invoice-recurring';
@ -475,25 +476,11 @@ class Document extends Model
public function getContactLocationAttribute()
{
$location = [];
if ($this->contact_city) {
$location[] = $this->contact_city;
}
if ($this->contact_zip_code) {
$location[] = $this->contact_zip_code;
}
if ($this->contact_state) {
$location[] = $this->contact_state;
}
if ($this->contact_country && array_key_exists($this->contact_country, trans('countries'))) {
$location[] = trans('countries.' . $this->contact_country);
$country = trans('countries.' . $this->contact_country);
}
return implode(', ', $location);
return $this->getFormattedAddress($this->contact_city, $country ?? null, $this->contact_state, $this->contact_zip_code);
}
/**

View File

@ -76,4 +76,17 @@ trait Contacts
'contact.type.' . $index => implode(',', $types),
])->save();
}
public function getFormattedAddress($city = null, $country = null, $state = null, $zip_code = null)
{
$address_format = setting('default.address_format');
$formatted_address = str_replace(
["{city}", "{country}", "{state}", "{zip_code}", "\n"],
[$city, $country, $state, $zip_code, '<br>'],
$address_format
);
return $formatted_address;
}
}

View File

@ -155,6 +155,7 @@ return [
'list_limit' => env('SETTING_FALLBACK_DEFAULT_LIST_LIMIT', '25'),
'payment_method' => env('SETTING_FALLBACK_DEFAULT_PAYMENT_METHOD', 'offline-payments.cash.1'),
'select_limit' => env('SETTING_FALLBACK_DEFAULT_SELECT_LIMIT', '10'),
'address_format' => env('SETTING_FALLBACK_DEFAULT_ADDRESS_FORMAT', "{city}, {state} {zip_code} \n{country}"),
],
'email' => [
'protocol' => env('SETTING_FALLBACK_EMAIL_PROTOCOL', 'mail'),

View File

@ -113,6 +113,8 @@ return [
'use_gravatar' => 'Use Gravatar',
'income_category' => 'Income Category',
'expense_category' => 'Expense Category',
'address_format' => 'Address Format',
'address_tags' => '<strong>Available Tags:</strong> :tags',
'form_description' => [
'general' => 'Select the default account, tax, and payment method to create records swiftly. Dashboard and Reports are shown under the default currency.',

View File

@ -90,7 +90,7 @@
@if (! $hideAddress)
<div class="flex flex-col text-sm sm:mb-5">
<div class="font-medium">{{ trans('general.address') }}</div>
<span>{{ $contact->address }}<br>{{ $contact->location }}</span>
<span>{{ $contact->address }}<br>{!! $contact->location !!}</span>
</div>
@endif
@stack('address_input_end')

View File

@ -43,9 +43,19 @@
</x-slot>
<x-slot name="body">
<x-form.group.locale :clearable="'false'" not-required />
<x-form.group.locale :clearable="'false'" not-required />
<x-form.group.select name="list_limit" label="{{ trans('settings.default.list_limit') }}" :options="['10' => '10', '25' => '25', '50' => '50', '100' => '100']" :clearable="'false'" :selected="setting('default.list_limit')" not-required />
<x-form.group.textarea name="address_format" label="{{ trans('settings.default.address_format') }}" :value="setting('default.address_format')" form-group-class="sm:col-span-6" not-required />
<div class="sm:col-span-6">
<div class="bg-gray-200 rounded-md p-3">
<small>
{!! trans('settings.default.address_tags', ['tags' => '{city}, {state}, {zip_code}, {country}']) !!}
</small>
</div>
</div>
</x-slot>
</x-form.section>