398 lines
14 KiB
Vue
Raw Normal View History

2021-05-20 15:18:43 +03:00
<template>
2021-06-01 23:58:08 +03:00
<div>
<h1 class="text-white">
{{ translations.company.title }}
</h1>
<div class="card">
<div class="card-header wizard-header p-3">
<el-steps :active="active" finish-status="success" align-center>
<el-step :title="translations.company.title"></el-step>
<el-step :title="translations.currencies.title"></el-step>
<el-step :title="translations.taxes.title"></el-step>
<el-step :title="translations.finish.title"></el-step>
</el-steps>
2021-05-20 15:18:43 +03:00
</div>
2021-06-01 23:58:08 +03:00
<form ref="form" class="w-100 mb-0">
<div class="card-body">
<div class="document-loading" v-if="pageLoad">
<div>
<i class="fas fa-spinner fa-pulse fa-7x"></i>
</div>
</div>
<div class="row mb-0">
<div class="col-12 mb-4">
<base-input
:label="translations.company.api_key"
name="api_key"
data-name="api_key"
:placeholder="translations.company.api_key"
prepend-icon="fas fa-key"
v-model="company.api_key"
/>
<p class="mb-0 mt--3">
<small>
<div>
<a href="https://akaunting.com/dashboard" target="_blank">Click here</a>
to get your API key.
</div>
</small>
</p>
</div>
<div class="col-6">
<base-input
type="text"
:label="translations.company.tax_number"
name="tax_number"
data-name="tax_number"
:placeholder="translations.company.tax_number"
prepend-icon="fas fa-percent"
v-model="company.tax_number"
/>
</div>
2021-09-08 11:40:03 +03:00
2021-06-01 23:58:08 +03:00
<div class="col-6">
<akaunting-date
:title="translations.company.financial_start"
data-name="financial_start"
:placeholder="translations.company.financial_start"
icon="fas fa-calendar"
:date-config="{
dateFormat: 'd-m',
2021-06-02 12:26:45 +03:00
allowInput: false,
2021-06-01 23:58:08 +03:00
altInput: true,
2021-06-02 15:25:50 +03:00
altFormat: 'j F'
2021-06-01 23:58:08 +03:00
}"
v-model="real_date"
></akaunting-date>
</div>
2021-09-08 11:40:03 +03:00
2021-06-01 23:58:08 +03:00
<div class="col-12">
<base-input :label="translations.company.address">
<textarea
class="form-control"
name="address"
data-name="address"
rows="3"
:placeholder="translations.company.address"
v-model="company.address"
></textarea>
</base-input>
</div>
2021-09-08 11:40:03 +03:00
<div class="col-6">
<base-input :label="translations.company.country">
2021-10-02 15:25:59 +03:00
<el-select v-model="company.country" filterable>
<template slot="prefix">
<span class="el-input__suffix-inner el-select-icon">
<i :class="'select-icon-position el-input__icon fas fa-globe-americas'"></i>
</span>
</template>
<el-option
2021-09-08 11:40:03 +03:00
v-for="(country, index) in sortedCountries"
:key="index"
:label="country.value"
:value="country.key"
>
</el-option>
</el-select>
</base-input>
2021-10-02 15:25:59 +03:00
<input name="country" type="hidden" class="d-none" v-model="company.country"></input>
</div>
2021-09-08 11:40:03 +03:00
<div class="col-6 mb-0">
2021-06-01 23:58:08 +03:00
<label class="form-control-label">{{ translations.company.logo }}</label>
<akaunting-dropzone-file-upload
ref="dropzoneWizard"
2021-09-08 11:40:03 +03:00
class="form-file"
2021-06-01 23:58:08 +03:00
preview-classes="single"
:attachments="logo"
:v-model="logo"
>
</akaunting-dropzone-file-upload>
</div>
</div>
</div>
<div class="card-footer">
<div class="row">
<div class="col-md-12 text-right">
<base-button
id="button"
type="success"
native-type="button"
@click="onEditSave()"
>{{ translations.company.save }}</base-button>
<base-button type="white" native-type="submit" @click="next()">{{ translations.company.skip }}</base-button>
</div>
</div>
</div>
</form>
2021-05-20 15:18:43 +03:00
</div>
</div>
</template>
<script>
import { Step, Steps, Select, Option } from "element-ui";
2021-05-20 15:18:43 +03:00
import AkauntingDropzoneFileUpload from "./../../components/AkauntingDropzoneFileUpload";
import AkauntingDate from "./../../components/AkauntingDate";
2021-05-29 17:01:22 +03:00
import WizardAction from "./../../mixins/wizardAction";
2021-05-20 15:18:43 +03:00
export default {
2021-05-30 17:17:37 +03:00
name: "Company",
mixins: [WizardAction],
components: {
[Step.name]: Step,
[Steps.name]: Steps,
[Select.name]: Select,
[Option.name]: Option,
2021-05-30 17:17:37 +03:00
AkauntingDropzoneFileUpload,
AkauntingDate,
2021-05-20 15:18:43 +03:00
},
2021-05-30 17:17:37 +03:00
props: {
company: {
type: [Object, Array],
},
2021-09-08 11:40:03 +03:00
countries: {
type: [Object, Array],
},
2021-05-30 17:17:37 +03:00
translations: {
type: [Object, Array],
},
url: {
type: String,
default: "text",
},
pageLoad: {
type: [Boolean, String]
2021-06-02 12:26:45 +03:00
},
locale: {
type: String,
2021-06-02 15:25:50 +03:00
},
dateConfig: {
type: Object,
default: function () {
return {
2021-06-02 15:25:50 +03:00
};
},
description: "FlatPckr date configuration"
},
2021-05-28 15:45:19 +03:00
},
2021-05-30 17:17:37 +03:00
data() {
return {
active: 0,
logo: [],
real_date: "",
lang_data: '',
2021-09-08 11:40:03 +03:00
sorted_countries: [],
2021-05-30 17:17:37 +03:00
};
2021-05-26 18:31:17 +03:00
},
2021-05-30 17:17:37 +03:00
2021-06-02 12:26:45 +03:00
created() {
2021-09-08 11:40:03 +03:00
if (document.documentElement.lang) {
2021-06-02 12:26:45 +03:00
let lang_split = document.documentElement.lang.split("-");
2021-06-02 15:25:50 +03:00
if (lang_split[0] !== 'en') {
2021-09-08 11:40:03 +03:00
const lang = require(`flatpickr/dist/l10n/${lang_split[0]}.js`).default[lang_split[0]];
2021-09-08 11:40:03 +03:00
this.dateConfig.locale = lang;
2021-06-02 15:25:50 +03:00
}
2021-06-02 12:26:45 +03:00
}
2021-09-08 11:40:03 +03:00
this.setSortedCountries();
},
computed: {
sortedCountries() {
this.sorted_countries.sort(this.sortBy('value'));
return this.sorted_countries;
},
2021-06-02 12:26:45 +03:00
},
2021-05-30 17:17:37 +03:00
mounted() {
let company_data = this.company;
this.onDataWatch(company_data);
2021-05-25 19:52:39 +03:00
},
2021-05-28 14:16:40 +03:00
2021-05-30 17:17:37 +03:00
methods: {
2021-09-08 11:40:03 +03:00
sortBy(option) {
return (firstEl, secondEl) => {
let first_element = firstEl[option].toUpperCase(); // ignore upper and lowercase
let second_element = secondEl[option].toUpperCase(); // ignore upper and lowercase
if (first_element < second_element) {
return -1;
}
if (first_element > second_element) {
return 1;
}
// names must be equal
return 0;
}
},
setSortedCountries() {
// Reset sorted_countries
this.sorted_countries = [];
let created_options = this.countries;
// Option set sort_option data
if (!Array.isArray(created_options)) {
for (const [key, value] of Object.entries(created_options)) {
this.sorted_countries.push({
key: key.toString(),
value: value
});
}
} else {
created_options.forEach(function (option, index) {
if (typeof(option) == 'string') {
this.sorted_countries.push({
index: index,
key: index.toString(),
value: option
});
} else {
this.sorted_countries.push({
index: index,
key: option.id.toString(),
value: (option.title) ? option.title : (option.display_name) ? option.display_name : option.name
});
}
}, this);
}
},
2021-05-30 17:17:37 +03:00
onDataWatch(company) {
if (Object.keys(company).length) {
2021-06-02 01:07:15 +03:00
if (company.logo) {
let logo_arr = [{
id: company.logo.id,
name: company.logo.filename + "." + company.logo.extension,
path: company.logo.path,
type: company.logo.mime_type,
size: company.logo.size,
downloadPath: false,
}];
this.logo.push(logo_arr);
}
2021-05-30 17:17:37 +03:00
this.real_date = company.financial_start;
2021-05-29 08:15:18 +03:00
}
2021-05-30 17:17:37 +03:00
},
onEditSave() {
FormData.prototype.appendRecursive = function (data, wrapper = null) {
for (var name in data) {
if (name == "previewElement" || name == "previewTemplate") {
continue;
}
if (wrapper) {
if (
(typeof data[name] == "object" || Array.isArray(data[name])) &&
data[name] instanceof File != true &&
data[name] instanceof Blob != true
) {
this.appendRecursive(data[name], wrapper + "[" + name + "]");
} else {
this.append(wrapper + "[" + name + "]", data[name]);
}
} else {
if (
(typeof data[name] == "object" || Array.isArray(data[name])) &&
data[name] instanceof File != true &&
data[name] instanceof Blob != true
) {
this.appendRecursive(data[name], name);
} else {
this.append(name, data[name]);
}
}
}
};
const formData = new FormData(this.$refs["form"]);
2021-05-29 08:15:18 +03:00
2021-05-30 17:17:37 +03:00
let data_name = {};
2021-05-30 17:17:37 +03:00
for (let [key, val] of formData.entries()) {
Object.assign(data_name, {
[key]: val,
});
}
let logo = '';
if (this.$refs.dropzoneWizard.files[1]) {
logo = this.$refs.dropzoneWizard.files[1];
} else if (this.$refs.dropzoneWizard.files[0]) {
logo = this.$refs.dropzoneWizard.files[0];
}
Object.assign(data_name, {
["logo"]: logo,
["_prefix"]: "company",
["_token"]: window.Laravel.csrfToken,
["_method"]: "POST",
});
2021-05-30 17:17:37 +03:00
formData.appendRecursive(data_name);
window.axios({
method: "POST",
url: url + "/wizard/companies",
data: formData,
headers: {
"X-CSRF-TOKEN": window.Laravel.csrfToken,
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "multipart/form-data",
},
})
.then((response) => {
this.onSuccessMessage(response);
2021-09-08 11:40:03 +03:00
2021-05-30 17:17:37 +03:00
this.$router.push("/wizard/currencies");
}, this)
.catch((error) => {
}, this);
},
next() {
if (this.active++ > 2);
2021-09-08 11:40:03 +03:00
2021-05-30 17:17:37 +03:00
this.$router.push("/wizard/currencies");
},
2021-05-20 15:18:43 +03:00
},
2021-05-25 19:52:39 +03:00
2021-05-30 17:17:37 +03:00
watch: {
company: function (company) {
this.onDataWatch(company);
},
2021-05-25 19:52:39 +03:00
},
2021-05-20 15:18:43 +03:00
};
</script>