447 lines
16 KiB
Vue
Raw Normal View History

2021-05-20 15:18:43 +03:00
<template>
<div>
<h1 class="text-white">
2021-05-28 10:38:30 +03:00
{{ translations.currencies.title }}
2021-05-20 15:18:43 +03:00
</h1>
<div class="card">
<div class="card-header wizard-header p-3">
<el-steps :active="active" finish-status="success" align-center>
2021-05-25 19:52:39 +03:00
<el-step :title="translations.company.title"></el-step>
2021-05-20 15:18:43 +03:00
<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>
</div>
<div class="card-body">
<div class="document-loading" v-if="pageLoad">
<div>
<i class="fas fa-spinner fa-pulse fa-7x"></i>
</div>
</div>
2021-09-08 11:40:03 +03:00
2021-05-20 15:18:43 +03:00
<div class="d-flex justify-content-end mb-3">
<base-button
type="success"
native-type="button"
class="btn-sm"
2021-05-28 15:45:19 +03:00
@click="onAddItem()"
>{{ translations.currencies.add_new }}</base-button
>
2021-05-20 15:18:43 +03:00
</div>
<div class="row flex-column">
<form ref="form">
<table class="table table-flush table-hover" id="tbl-currencies">
<thead class="thead-light">
<tr class="row table-head-line">
<th class="col-xs-4 col-sm-4 col-md-3">
{{ translations.currencies.name }}
</th>
<th class="col-md-3 d-none d-md-block">
{{ translations.currencies.code }}
</th>
<th class="col-md-2 d-none d-md-block">
{{ translations.currencies.rate }}
</th>
<th class="col-xs-4 col-sm-4 col-md-2">
{{ translations.currencies.enabled }}
</th>
<th class="col-xs-4 col-sm-4 col-md-2 text-center">
{{ translations.currencies.actions }}
</th>
</tr>
</thead>
2021-09-08 11:40:03 +03:00
2021-05-20 15:18:43 +03:00
<tbody>
<tr
v-for="(item, index) in currencies"
:key="index"
class="row align-items-center border-top-1"
>
<td class="col-xs-4 col-sm-4 col-md-3">
<a href="javascript:void(0);"> {{ item.name }} </a>
</td>
<td class="col-md-3 d-none d-md-block">{{ item.code }}</td>
<td class="col-md-2 d-none d-md-block">{{ item.rate }}</td>
<td class="col-xs-4 col-sm-4 col-md-2">
<label class="custom-toggle d-inline-block" name="staus-1">
<input
type="checkbox"
:checked="item.enabled"
2021-05-28 15:45:19 +03:00
@input="onSwitchUpdate(item)"
2021-05-20 15:18:43 +03:00
/>
<span
class="custom-toggle-slider rounded-circle status-green"
:data-label-on="translations.currencies.yes"
:data-label-off="translations.currencies.no"
>
</span>
</label>
</td>
<td class="col-xs-4 col-sm-4 col-md-2 text-center">
<div class="dropdown">
<a
class="btn btn-neutral btn-sm text-light items-align-center py-2"
href="#"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
<i class="fa fa-ellipsis-h text-muted"></i>
</a>
<div
class="dropdown-menu dropdown-menu-right dropdown-menu-arrow"
>
<button
type="button"
class="dropdown-item"
2021-05-28 15:45:19 +03:00
@click="onEditItem(item, index)"
2021-05-20 15:18:43 +03:00
>
{{ translations.currencies.edit }}
</button>
<div class="dropdown-divider"></div>
<button
type="button"
class="dropdown-item"
2021-05-28 15:45:19 +03:00
@click="onClickDelete(item)"
2021-05-20 15:18:43 +03:00
>
{{ translations.currencies.delete }}
</button>
</div>
</div>
</td>
2021-05-28 15:45:19 +03:00
<td class="w-100 p-0 current-tab" v-if="current_tab == index">
2021-05-20 15:18:43 +03:00
<div class="row pt-3 pb-3">
<div
class="form-container col-12 d-flex justify-content-between align-items-start"
>
<base-input
:label="translations.currencies.name"
name="name"
data-name="name"
:placeholder="translations.currencies.name"
prepend-icon="fas fa-font"
form-classes="col-md-3"
2021-05-21 15:05:48 +03:00
class="required"
2021-05-20 15:18:43 +03:00
v-model="model.name"
2021-05-24 10:48:58 +03:00
:error="onFailErrorGet('name')"
2021-05-20 15:18:43 +03:00
/>
<base-input
:label="translations.currencies.code"
2021-05-21 15:05:48 +03:00
class="required"
2021-05-20 15:18:43 +03:00
form-classes="col-md-3"
2021-05-24 10:48:58 +03:00
:error="onFailErrorGet('code')"
2021-05-20 15:18:43 +03:00
>
<el-select
name="code"
v-model="model.select"
2021-05-28 15:45:19 +03:00
@change="onChangeCodeItem(model.select)"
2021-05-20 15:18:43 +03:00
filterable
>
<template slot="prefix">
<span
class="el-input__suffix-inner el-select-icon"
>
<i
:class="'select-icon-position el-input__icon fa fa-code'"
></i>
</span>
</template>
<el-option
v-for="option in currency_codes"
:key="option"
:label="option"
:value="option"
>
</el-option> </el-select
></base-input>
<base-input
:label="translations.currencies.rate"
name="rate"
data-name="rate"
:placeholder="translations.currencies.rate"
prepend-icon="fas fa-percentage"
form-classes="col-md-3"
2021-05-21 15:05:48 +03:00
class="required"
2021-05-20 15:18:43 +03:00
v-model="model.rate"
2021-05-24 10:48:58 +03:00
:error="onFailErrorGet('rate')"
2021-05-20 15:18:43 +03:00
/>
<div class="mt-4 col-md-3 current-tab-btn">
2021-05-26 18:45:39 +03:00
<base-button
type="white"
native-type="button"
2021-05-28 15:45:19 +03:00
@click="onCancelItem()"
2021-05-26 18:45:39 +03:00
>
{{ translations.currencies.cancel }}</base-button
>
2021-05-20 15:18:43 +03:00
<base-button
type="success"
native-type="button"
2021-05-28 15:45:19 +03:00
@click="onEditForm(item)"
2021-05-20 15:18:43 +03:00
>
{{ translations.currencies.save }}</base-button
>
</div>
</div>
</div>
</td>
</tr>
2021-05-28 15:45:19 +03:00
<tr v-if="new_datas">
<td class="p-0">
<div class="row pt-3 pb-3">
<div
class="form-container col-12 d-flex justify-content-between align-items-start"
2021-05-20 15:18:43 +03:00
>
<base-input
:label="translations.currencies.name"
name="name"
data-name="name"
:placeholder="translations.currencies.name"
prepend-icon="fas fa-font"
2021-05-21 15:05:48 +03:00
class="required"
v-model="model.name"
2021-05-24 10:48:58 +03:00
:error="onFailErrorGet('name')"
/>
2021-05-28 10:38:30 +03:00
<base-input
:label="translations.currencies.code"
class="required"
:error="onFailErrorGet('code')"
>
<el-select
name="code"
v-model="model.select"
required="required"
2021-05-28 15:45:19 +03:00
@change="onChangeCodeItem(model.select)"
filterable
>
<template slot="prefix">
<span
class="el-input__suffix-inner el-select-icon"
>
<i
:class="'select-icon-position el-input__icon fa fa-code'"
></i>
</span>
</template>
<el-option
v-for="option in currency_codes"
:key="option"
:label="option"
:value="option"
>
</el-option> </el-select
></base-input>
<base-input
:label="translations.currencies.rate"
name="rate"
data-name="rate"
:placeholder="translations.currencies.rate"
prepend-icon="fas fa-percentage"
2021-05-21 15:05:48 +03:00
class="required"
v-model="model.rate"
2021-05-24 10:48:58 +03:00
:error="onFailErrorGet('rate')"
/>
<div>
<div class="d-flex">
<akaunting-radio-group
name="enabled"
:text="translations.currencies.enabled"
:enable="translations.currencies.yes"
:disable="translations.currencies.no"
:value="model.enabled"
>
</akaunting-radio-group>
</div>
</div>
<div class="mt-4">
<base-button
type="success"
native-type="button"
@click="onSubmitForm()"
>{{ translations.currencies.save }}</base-button
>
</div>
</div>
2021-05-20 15:18:43 +03:00
</div>
</td>
</tr>
</tbody>
</table>
2021-05-20 15:18:43 +03:00
</form>
</div>
<notifications></notifications>
2021-09-08 11:40:03 +03:00
2021-05-20 15:18:43 +03:00
<form id="form-dynamic-component" method="POST" action="#"></form>
2021-09-08 11:40:03 +03:00
2021-05-20 15:18:43 +03:00
<component
v-bind:is="component"
2021-05-28 15:45:19 +03:00
@deleted="onDeleteCurrency($event)"
2021-05-20 15:18:43 +03:00
></component>
</div>
<div class="card-footer">
<div class="row">
<div class="col-md-12 d-flex justify-content-between">
<base-button type="white" native-type="submit" @click="prev()">{{
translations.currencies.previous
}}</base-button>
2021-09-08 11:40:03 +03:00
2021-05-20 15:18:43 +03:00
<base-button type="white" native-type="submit" @click="next()">{{
translations.currencies.next
}}</base-button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import { Step, Steps, Select, Option } from "element-ui";
import AkauntingRadioGroup from "./../../components/forms/AkauntingRadioGroup";
import BulkAction from "./../../plugins/bulk-action";
import MixinsGlobal from "./../../mixins/global";
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: "Currencies",
2021-05-20 15:18:43 +03:00
2021-05-30 17:17:37 +03:00
mixins: [MixinsGlobal, WizardAction],
2021-05-20 15:18:43 +03:00
2021-05-30 17:17:37 +03:00
components: {
[Step.name]: Step,
[Steps.name]: Steps,
[Select.name]: Select,
[Option.name]: Option,
AkauntingRadioGroup,
2021-05-20 15:18:43 +03:00
},
2021-05-30 17:17:37 +03:00
props: {
currencies: {
type: [Object, Array],
},
2021-05-30 17:17:37 +03:00
currency_codes: {
type: [Object, Array],
},
2021-05-20 15:18:43 +03:00
2021-05-30 17:17:37 +03:00
translations: {
type: [Object, Array],
},
pageLoad: {
type: [Boolean, String]
}
2021-05-20 15:18:43 +03:00
},
2021-05-30 17:17:37 +03:00
data() {
return {
active: 1,
bulk_action: new BulkAction(url + "/settings/currencies"),
};
2021-05-20 15:18:43 +03:00
},
2021-05-30 17:17:37 +03:00
methods: {
onSwitchUpdate(item) {
this.onStatus(item.id, event);
2021-05-20 15:18:43 +03:00
2021-05-30 17:17:37 +03:00
this.onStatusControl(this.currencies, item.id, event);
},
onClickDelete(item) {
this.confirmDelete(
`${
new URL(url).protocol +
"//" +
location.host +
location.pathname +
"/" +
item.id
}`,
this.translations.currencies.title,
`Confirm Delete <strong>${item.name}</strong> ${this.translations.currencies.title}?`,
this.translations.currencies.cancel,
this.translations.currencies.delete
);
},
onDeleteCurrency(event) {
this.onEjetItem(event, this.currencies, event.currency_id);
},
onChangeCodeItem(code) {
const formData = new FormData(this.$refs["form"]);
const data = {
rate: "",
precision: "",
symbol: "",
symbol_first: "",
decimal_mark: "",
thousands_separator: "",
};
for (let [key, val] of formData.entries()) {
Object.assign(data, {
[key]: val,
});
}
window.axios({
method: "GET",
url: url + "/settings/currencies/config",
params: {
code: code,
},
})
.then((response) => {
data.rate = response.data.rate;
data.precision = response.data.precision;
data.symbol = response.data.symbol;
data.symbol_first = response.data.symbol_first;
data.decimal_mark = response.data.decimal_mark;
data.thousands_separator = response.data.thousands_separator;
this.model.rate = response.data.rate;
}, this);
},
onEditForm(item) {
this.onSubmitEvent(
"PATCH",
url + "/wizard/currencies/" + item.id,
"",
this.currencies,
item.id
);
},
onSubmitForm() {
this.onSubmitEvent(
"POST",
url + "/wizard/currencies",
"",
this.currencies
);
},
prev() {
if (this.active-- > 2);
2021-05-30 17:35:19 +03:00
//history.back()
2021-05-30 17:17:37 +03:00
this.$router.push("/wizard/companies");
},
2021-05-28 15:45:19 +03:00
2021-05-30 17:17:37 +03:00
next() {
if (this.active++ > 2);
2021-05-30 17:35:19 +03:00
2021-05-30 17:17:37 +03:00
this.$router.push("/wizard/taxes");
},
2021-05-20 15:18:43 +03:00
},
};
</script>