location brought from model

This commit is contained in:
Cihan Şentürk 2021-09-03 12:53:35 +03:00
parent 414e405168
commit 6154ff31fd
10 changed files with 65 additions and 154 deletions

View File

@ -31,10 +31,6 @@ abstract class DocumentTemplate extends Base
public $logo;
public $companyLocation;
public $contactLocation;
public $backgroundColor;
public $hideFooter;
@ -127,7 +123,7 @@ abstract class DocumentTemplate extends Base
* @return void
*/
public function __construct(
$type, $document, $item = false, $documentTemplate = '', $logo = '', $backgroundColor = '', $companyLocation = '', $contactLocation = '',
$type, $document, $item = false, $documentTemplate = '', $logo = '', $backgroundColor = '',
bool $hideFooter = false, bool $hideCompanyLogo = false, bool $hideCompanyDetails = false,
bool $hideCompanyName = false, bool $hideCompanyAddress = false, bool $hideCompanyTaxNumber = false, bool $hideCompanyPhone = false, bool $hideCompanyEmail = false, bool $hideContactInfo = false,
bool $hideContactName = false, bool $hideContactAddress = false, bool $hideContactTaxNumber = false, bool $hideContactPhone = false, bool $hideContactEmail = false,
@ -143,8 +139,6 @@ abstract class DocumentTemplate extends Base
$this->documentTemplate = $this->getDocumentTemplate($type, $documentTemplate);
$this->logo = $this->getLogo($logo);
$this->backgroundColor = $this->getBackgroundColor($type, $backgroundColor);
$this->companyLocation = $this->getCompanyLocation();
$this->contactLocation = $this->getContactLocation($document);
$this->hideFooter = $hideFooter;
$this->hideCompanyLogo = $hideCompanyLogo;
@ -652,50 +646,4 @@ abstract class DocumentTemplate extends Base
// @todo what return value invoice or always false??
return setting('invoice.hide_amount', $hideAmount);
}
protected function getCompanyLocation()
{
$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');
}
if (setting('company.country')) {
$location[] = trans('countries.' . setting('company.country'));
}
return implode(', ', $location);
}
protected function getContactLocation($document)
{
$location = [];
if ($document->contact->city) {
$location[] = $document->contact->city;
}
if ($document->contact->zip_code) {
$location[] = $document->contact->zip_code;
}
if ($document->contact->state) {
$location[] = $document->contact->state;
}
if ($document->contact->country) {
$location[] = trans('countries.' . $document->contact->country);
}
return implode(', ', $location);
}
}

View File

@ -25,6 +25,13 @@ class Company extends Eloquent implements Ownable
protected $table = 'companies';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['location'];
protected $dates = ['deleted_at'];
protected $fillable = ['domain', 'enabled', 'created_by'];
@ -446,6 +453,29 @@ class Company extends Eloquent implements Ownable
return $this->getMedia('company.logo')->last();
}
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');
}
if (setting('company.country')) {
$location[] = trans('countries.' . setting('company.country'));
}
return implode(', ', $location);
}
public function makeCurrent($force = false)
{
if (!$force && $this->isCurrent()) {

View File

@ -19,6 +19,13 @@ class Contact extends Model
protected $table = 'contacts';
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['location'];
/**
* Attributes that should be mass-assignable.
*

View File

@ -13,9 +13,9 @@
{{ company.address }}
</th>
</tr>
<tr v-if="company_data.locations">
<tr v-if="company.location">
<th class="text-right p-0">
{{ company_data.locations }}
{{ company.location }}
</th>
</tr>
<tr v-if="company.tax_number">
@ -60,18 +60,18 @@ import Form from './../plugins/form';
export default {
name: 'akaunting-company-edit',
components: {
[Select.name]: Select,
[Option.name]: Option,
[OptionGroup.name]: OptionGroup,
[ColorPicker.name]: ColorPicker,
AkauntingModalAddNew,
AkauntingModal,
AkauntingMoney,
AkauntingRadioGroup,
AkauntingSelect,
AkauntingDate,
},
components: {
[Select.name]: Select,
[Option.name]: Option,
[OptionGroup.name]: OptionGroup,
[ColorPicker.name]: ColorPicker,
AkauntingModalAddNew,
AkauntingModal,
AkauntingMoney,
AkauntingRadioGroup,
AkauntingSelect,
AkauntingDate,
},
props: {
buttonText: {
@ -94,9 +94,6 @@ export default {
default: {},
description: 'Company object'
},
countryText: {
type: [Array, Object],
},
companyForm: {
type: Object,
default: function () {
@ -120,7 +117,6 @@ export default {
buttons: this.companyForm.buttons,
},
company_html: '',
company_data: this.company,
};
},
@ -247,27 +243,5 @@ export default {
documentClasses.remove("modal-open");
},
},
created() {
let locations = [];
if (this.company.city) {
locations.push(this.company.city);
}
if (this.company.zip_code) {
locations.push(this.company.zip_code);
}
if (this.company.state) {
locations.push(this.company.state);
}
if (this.company.country) {
locations.push(this.countryText[this.company.country])
}
this.company.locations = locations.join(', ');
},
};
</script>

View File

@ -88,9 +88,9 @@
{{ contact.address }}
</th>
</tr>
<tr v-if="contact.locations">
<tr v-if="contact.location">
<th class="p-0" style="text-align:left; white-space: normal;">
{{ contact.locations }}
{{ contact.location }}
</th>
</tr>
<tr v-if="contact.tax_number">
@ -197,7 +197,7 @@ export default {
zip_code:'',
state:'',
country:'',
country_name:'',
location:'',
reference: ''
};
},
@ -241,10 +241,6 @@ export default {
default: 'Bill to',
description: ""
},
countryText: {
type: [Array, Object],
default: () => [],
},
taxNumberText: {
type: String,
default: 'Tax number',
@ -284,7 +280,6 @@ export default {
buttons: this.addNew.buttons,
},
add_new_html: '',
country_text_data: this.countryText,
};
},
@ -315,7 +310,7 @@ export default {
zip_code: '',
state: '',
country: '',
countryname: '',
location: '',
reference: ''
});
},
@ -345,7 +340,7 @@ export default {
zip_code: (contact.zip_code) ? contact.zip_code : '',
state: (contact.state) ? contact.state : '',
country: (contact.country) ? contact.country : '',
country_name: (contact.country_name) ? contact.country_name : '',
location: (contact.location) ? contact.location : '',
reference: (contact.reference) ? contact.reference : ''
});
}, this);
@ -361,26 +356,6 @@ export default {
this.contact_list.forEach(function (contact, index) {
if (contact_id == contact.id) {
this.contact = contact;
let locations = [];
if (this.contact.city) {
locations.push(this.contact.city);
}
if (this.contact.zip_code) {
locations.push(this.contact.zip_code);
}
if (this.contact.state) {
locations.push(this.contact.state);
}
if (this.contact.country) {
locations.push(this.country_text_data[this.contact.country]);
}
this.contact.locations = locations.join(', ');
}
}, this);
@ -616,7 +591,7 @@ export default {
zip_code: '',
state: '',
country: '',
country_name: '',
location: '',
reference: ''
});
@ -641,30 +616,9 @@ export default {
zip_code: (contact.zip_code) ? contact.zip_code : '',
state: (contact.state) ? contact.state : '',
country: (contact.country) ? contact.country : '',
country_name: (contact.country_name) ? contact.country_name : '',
location: (contact.location) ? contact.location : '',
reference: (contact.reference) ? contact.reference : ''
});
let locations = [];
if (contact.city) {
locations.push(contact.city);
}
if (contact.zip_code) {
locations.push(contact.zip_code);
}
if (contact.state) {
locations.push(contact.state);
}
if (contact.country) {
locations.push(this.country_text_data[contact.country])
}
this.contact.locations = locations.join(', ');
}, this);
}

View File

@ -26,7 +26,6 @@
<akaunting-company-edit company-id="{{ company_id() }}"
button-text="{{ trans('settings.company.edit_your_business_address') }}"
tax-number-text="{{ trans('general.tax_number') }}"
:country-text="{{ json_encode(trans('countries')) }}"
:company="{{ json_encode($company) }}"
:company-form="{{ json_encode([
'show' => true,

View File

@ -41,7 +41,7 @@
<p>
{!! nl2br(setting('company.address')) !!}
<br>
{!! $companyLocation !!}
{!! $document->company->location !!}
</p>
@endif
@ -115,7 +115,7 @@
<p>
{!! nl2br($document->contact_address) !!}
<br>
{!! $contactLocation !!}
{!! $document->contact->location !!}
</p>
@endif
@stack('address_input_end')

View File

@ -41,7 +41,7 @@
<p>
{!! nl2br(setting('company.address')) !!}
<br>
{!! $companyLocation !!}
{!! $document->company->location !!}
</p>
@endif
@ -89,7 +89,7 @@
<p>
{!! nl2br($document->contact_address) !!}
<br>
{!! $contactLocation !!}
{!! $document->contact->location !!}
</p>
@endif
@stack('address_input_end')

View File

@ -41,7 +41,7 @@
<strong class="text-white">
{!! nl2br(setting('company.address')) !!}
<br>
{!! $companyLocation !!}
{!! $document->company->location !!}
</strong><br><br>
@endif
@ -89,7 +89,7 @@
@if (!$hideContactAddress)
{!! nl2br($document->contact_address) !!}
<br>
{!! $contactLocation !!}
{!! $document->contact->location !!}
<br><br>
@endif
@stack('address_input_end')

View File

@ -4,7 +4,6 @@
no-matching-data-text="{{ trans('general.no_matching_data') }}"
search-route="{{ $search_route }}"
create-route="{{ $create_route }}"
:country-text="{{ json_encode(trans('countries')) }}"
:contacts="{{ json_encode($contacts) }}"
:selected="{{ json_encode($contact) }}"
add-contact-text="{{ is_array($textAddContact) ? trans($textAddContact[0], ['field' => trans_choice($textAddContact[1], 1)]) : trans($textAddContact) }}"