Add "From/To Account Rate" fields in transfer create/edit page

This commit is contained in:
Cüneyt Şentürk
2021-03-18 20:00:55 +03:00
parent 84e0e51620
commit a9ab37d4dd
7 changed files with 149 additions and 15 deletions

View File

@ -28,7 +28,64 @@ const app = new Vue({
data: function () {
return {
form: new Form('transfer'),
bulk_action: new BulkAction('transfers')
bulk_action: new BulkAction('transfers'),
show_rate: false,
}
},
methods: {
async onChangeFromAccount(from_account_id) {
if (!from_account_id) {
return;
}
let from_promise = Promise.resolve(window.axios.get(url + '/banking/accounts/currency', {
params: {
account_id: from_account_id
}
}));
from_promise.then(response => {
this.currency = response.data;
this.form.currency_code = response.data.currency_code;
this.form.currency_rate = response.data.currency_rate;
this.form.from_currency_code = response.data.currency_code;
this.form.from_account_rate = response.data.currency_rate;
})
.catch(error => {
})
.finally(() => {
this.show_rate = false;
if (this.form.to_currency_code && this.form.from_currency_code != this.form.to_currency_code) {
this.show_rate = true;
}
});
},
async onChangeToAccount(to_account_id) {
if (!to_account_id) {
return;
}
let to_promise = Promise.resolve(window.axios.get(url + '/banking/accounts/currency', {
params: {
account_id: to_account_id
}
}));
to_promise.then(response => {
this.form.to_currency_code = response.data.currency_code;
this.form.to_account_rate = response.data.currency_rate;
})
.catch(error => {
})
.finally(() => {
this.show_rate = false;
if (this.form.from_currency_code && this.form.from_currency_code != this.form.to_currency_code) {
this.show_rate = true;
}
});
},
}
});

View File

@ -3,7 +3,9 @@
return [
'from_account' => 'From Account',
'from_account_rate' => 'From Account Rate',
'to_account' => 'To Account',
'to_account_rate' => 'To Account Rate',
'messages' => [
'delete' => ':from to :to (:amount)',

View File

@ -17,9 +17,19 @@
<div class="card-body">
<div class="row">
{{ Form::selectGroup('from_account_id', trans('transfers.from_account'), 'university', $accounts, null, ['required' => 'required', 'change' => 'onChangeAccount']) }}
{{ Form::selectGroup('from_account_id', trans('transfers.from_account'), 'university', $accounts, null, ['required' => 'required', 'change' => 'onChangeFromAccount']) }}
{{ Form::selectGroup('to_account_id', trans('transfers.to_account'), 'university', $accounts) }}
{{ Form::selectGroup('to_account_id', trans('transfers.to_account'), 'university', $accounts, null, ['required' => 'required', 'change' => 'onChangeToAccount']) }}
<div class="d-none w-100" :class="[{'d-flex' : show_rate}]">
{!! Form::hidden('from_currency_code', null, ['id' => 'from_currency_code', 'v-model' => 'form.from_currency_code']) !!}
{{ Form::textGroup('from_account_rate', trans('transfers.from_account_rate'), 'sliders-h', []) }}
{!! Form::hidden('to_currency_code', null, ['id' => 'to_currency_code', 'v-model' => 'form.to_currency_code']) !!}
{{ Form::textGroup('to_account_rate', trans('transfers.to_account_rate'), 'sliders-h', []) }}
</div>
{{ Form::moneyGroup('amount', trans('general.amount'), 'money-bill-alt', ['required' => 'required', 'currency' => $currency, 'dynamic-currency' => 'currency'], 0) }}
@ -46,5 +56,8 @@
@endsection
@push('scripts_start')
<script type="text/javascript">
</script>
<script src="{{ asset('public/js/banking/transfers.js?v=' . version('short')) }}"></script>
@endpush

View File

@ -18,9 +18,19 @@
<div class="card-body">
<div class="row">
{{ Form::selectGroup('from_account_id', trans('transfers.from_account'), 'university', $accounts, $transfer->from_account_id, ['required' => 'required', 'change' => 'onChangeAccount']) }}
{{ Form::selectGroup('from_account_id', trans('transfers.from_account'), 'university', $accounts, $transfer->from_account_id, ['required' => 'required', 'change' => 'onChangeFromAccount']) }}
{{ Form::selectGroup('to_account_id', trans('transfers.to_account'), 'university', $accounts, $transfer->to_account_id) }}
{{ Form::selectGroup('to_account_id', trans('transfers.to_account'), 'university', $accounts, $transfer->to_account_id, ['required' => 'required', 'change' => 'onChangeToAccount']) }}
<div class="d-none w-100" :class="[{'d-flex' : show_rate}]">
{!! Form::hidden('from_currency_code', $transfer->from_currency_code, ['id' => 'from_currency_code', 'v-model' => 'form.from_currency_code']) !!}
{{ Form::textGroup('from_account_rate', trans('transfers.from_account_rate'), 'sliders-h', [], $transfer->from_account_rate) }}
{!! Form::hidden('to_currency_code', $transfer->to_currency_code, ['id' => 'to_currency_code', 'v-model' => 'form.to_currency_code']) !!}
{{ Form::textGroup('to_account_rate', trans('transfers.to_account_rate'), 'sliders-h', [], $transfer->to_account_rate) }}
</div>
{{ Form::moneyGroup('amount', trans('general.amount'), 'money-bill-alt', ['required' => 'required', 'currency' => $currency, 'dynamic-currency' => 'currency'], $transfer->amount) }}