-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to set company location (#1223)
- Loading branch information
Showing
13 changed files
with
373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/Services/Company/Adminland/Company/UpdateCompanyLocation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace App\Services\Company\Adminland\Company; | ||
|
||
use Carbon\Carbon; | ||
use App\Jobs\LogAccountAudit; | ||
use App\Services\BaseService; | ||
use App\Models\Company\Company; | ||
|
||
class UpdateCompanyLocation extends BaseService | ||
{ | ||
protected Company $company; | ||
|
||
protected array $data; | ||
|
||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'company_id' => 'required|integer|exists:companies,id', | ||
'author_id' => 'required|integer|exists:employees,id', | ||
'location' => 'required|string|max:255', | ||
]; | ||
} | ||
|
||
/** | ||
* Update the company's location. | ||
* | ||
* @param array $data | ||
* @return Company | ||
*/ | ||
public function execute(array $data): Company | ||
{ | ||
$this->data = $data; | ||
$this->validate(); | ||
$this->updateLocation(); | ||
$this->log(); | ||
|
||
return $this->company; | ||
} | ||
|
||
private function validate(): void | ||
{ | ||
$this->validateRules($this->data); | ||
|
||
$this->author($this->data['author_id']) | ||
->inCompany($this->data['company_id']) | ||
->asAtLeastAdministrator() | ||
->canExecuteService(); | ||
|
||
$this->company = Company::find($this->data['company_id']); | ||
} | ||
|
||
private function updateLocation(): void | ||
{ | ||
Company::where('id', $this->company->id)->update([ | ||
'location' => $this->data['location'], | ||
]); | ||
} | ||
|
||
private function log(): void | ||
{ | ||
LogAccountAudit::dispatch([ | ||
'company_id' => $this->company->id, | ||
'action' => 'company_location_updated', | ||
'author_id' => $this->author->id, | ||
'author_name' => $this->author->name, | ||
'audited_at' => Carbon::now(), | ||
'objects' => json_encode([ | ||
'location' => $this->data['location'], | ||
]), | ||
])->onQueue('low'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
database/migrations/2021_07_30_202600_add_company_location_to_companies.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class AddCompanyLocationToCompanies extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
// necessary for SQLlite | ||
Schema::enableForeignKeyConstraints(); | ||
|
||
Schema::table('companies', function (Blueprint $table) { | ||
$table->string('location')->after('currency')->nullable(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
resources/js/Pages/Adminland/General/Partials/Location.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<style lang="scss" scoped> | ||
.title { | ||
min-width: 230px; | ||
} | ||
</style> | ||
|
||
<template> | ||
<div class="bb bb-gray"> | ||
<h3 class="ph3 fw5"> | ||
{{ $t('account.general_location_information') }} | ||
|
||
<help :url="$page.props.help_links.account_general_location" :top="'2px'" /> | ||
</h3> | ||
|
||
<!-- location of the company --> | ||
<ul v-if="!editMode" class="list ph3"> | ||
<li class="mb3 flex items-start"> | ||
<span class="dib title mr3">{{ $t('account.general_location_label') }}</span> | ||
<span v-if="localLocation" class="fw6">{{ localLocation }}</span> | ||
<span v-else class="fw6">{{ $t('account.general_location_blank') }}</span> | ||
</li> | ||
</ul> | ||
|
||
<div v-if="!editMode" class="ph3 mb3"> | ||
<a data-cy="update-currency-company-button" class="btn tc relative dib" @click.prevent="displayEditMode()"> | ||
{{ $t('account.general_location_cta') }} | ||
</a> | ||
</div> | ||
|
||
<!-- change date --> | ||
<div v-if="editMode" class="ph3"> | ||
<form @submit.prevent="submit"> | ||
<errors :errors="form.errors" :class="'mb3'" /> | ||
|
||
<ul class="list pl0"> | ||
<li class="mb3 flex-ns items-center"> | ||
<span class="dib-ns db mb0-ns mb2 title">{{ $t('account.general_location_label') }}</span> | ||
<span> | ||
<text-input | ||
:id="'name'" | ||
:ref="'setLocation'" | ||
v-model="form.location" | ||
:name="'name'" | ||
:extra-class-upper-div="'mb0'" | ||
:errors="$page.props.errors.title" | ||
:required="true" | ||
:autofocus="true" | ||
:maxlength="191" | ||
autocomplete="off" | ||
@esc-key-pressed="editMode = false" | ||
/> | ||
</span> | ||
</li> | ||
</ul> | ||
|
||
<!-- Actions --> | ||
<div class="mt4 mb3"> | ||
<div class="flex-ns justify-between"> | ||
<div> | ||
<a href="#" class="btn dib tc w-auto-ns w-100 pv2 ph3" @click.prevent="editMode = false"> | ||
{{ $t('app.cancel') }} | ||
</a> | ||
</div> | ||
<loading-button :class="'btn add w-auto-ns w-100 pv2 ph3'" :state="loadingState" :text="$t('app.update')" /> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Errors from '@/Shared/Errors'; | ||
import LoadingButton from '@/Shared/LoadingButton'; | ||
import Help from '@/Shared/Help'; | ||
import TextInput from '@/Shared/TextInput'; | ||
export default { | ||
components: { | ||
Errors, | ||
Help, | ||
LoadingButton, | ||
TextInput, | ||
}, | ||
props: { | ||
information: { | ||
type: Object, | ||
default: null, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
localLocation: '', | ||
editMode: false, | ||
form: { | ||
id: 0, | ||
location: null, | ||
errors: [], | ||
}, | ||
loadingState: '', | ||
}; | ||
}, | ||
mounted: function() { | ||
this.localLocation = this.information.location; | ||
}, | ||
methods: { | ||
displayEditMode() { | ||
this.editMode = true; | ||
if (this.localLocation) { | ||
this.form.location = this.localLocation; | ||
} | ||
this.$nextTick(() => { | ||
this.$refs.setLocation.focus(); | ||
}); | ||
}, | ||
submit() { | ||
axios.post('/' + this.$page.props.auth.company.id + '/account/general/location', this.form) | ||
.then(response => { | ||
this.localLocation = this.form.location; | ||
this.editMode = false; | ||
this.flash(this.$t('account.general_location_success'), 'success'); | ||
}) | ||
.catch(error => { | ||
this.editMode = true; | ||
this.form.errors = error.response.data; | ||
}); | ||
}, | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.