Merge pull request #1477 from cuneytsenturk/master
Reconciliations multi currency and calculate fixed.
This commit is contained in:
commit
f7c8f4b785
@ -40,6 +40,8 @@ class Transaction extends Model
|
|||||||
*/
|
*/
|
||||||
public $cloneable_relations = ['recurring'];
|
public $cloneable_relations = ['recurring'];
|
||||||
|
|
||||||
|
public static $currencies;
|
||||||
|
|
||||||
public function account()
|
public function account()
|
||||||
{
|
{
|
||||||
return $this->belongsTo('App\Models\Banking\Account')->withDefault(['name' => trans('general.na')]);
|
return $this->belongsTo('App\Models\Banking\Account')->withDefault(['name' => trans('general.na')]);
|
||||||
@ -245,6 +247,49 @@ class Transaction extends Model
|
|||||||
$this->attributes['currency_rate'] = (double) $value;
|
$this->attributes['currency_rate'] = (double) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert amount to double.
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function getPriceAttribute()
|
||||||
|
{
|
||||||
|
if (empty($this->currencies)) {
|
||||||
|
$this->currencies = \App\Models\Setting\Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
$amount = $this->amount;
|
||||||
|
|
||||||
|
// Convert amount if not same currency
|
||||||
|
if ($this->account->currency_code != $this->currency_code) {
|
||||||
|
$default_currency = setting('default.currency', 'USD');
|
||||||
|
|
||||||
|
$default_amount = $this->amount;
|
||||||
|
|
||||||
|
if ($default_currency != $this->currency_code) {
|
||||||
|
$default_amount_model = new Transaction();
|
||||||
|
|
||||||
|
$default_amount_model->default_currency_code = $default_currency;
|
||||||
|
$default_amount_model->amount = $this->amount;
|
||||||
|
$default_amount_model->currency_code = $this->currency_code;
|
||||||
|
$default_amount_model->currency_rate = $this->currency_rate;
|
||||||
|
|
||||||
|
$default_amount = $default_amount_model->getAmountConvertedToDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
$transfer_amount = new Transaction();
|
||||||
|
|
||||||
|
$transfer_amount->default_currency_code = $this->currency_code;
|
||||||
|
$transfer_amount->amount = $default_amount;
|
||||||
|
$transfer_amount->currency_code = $this->account->currency_code;
|
||||||
|
$transfer_amount->currency_rate = $this->currencies[$this->account->currency_code];
|
||||||
|
|
||||||
|
$amount = $transfer_amount->getAmountConvertedFromDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $amount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current balance.
|
* Get the current balance.
|
||||||
*
|
*
|
||||||
|
@ -135,11 +135,15 @@ export default {
|
|||||||
change() {
|
change() {
|
||||||
//this.$emit('change', this.model);
|
//this.$emit('change', this.model);
|
||||||
//this.$emit('interface', this.model);
|
//this.$emit('interface', this.model);
|
||||||
|
|
||||||
|
this.$emit('input', this.model);
|
||||||
},
|
},
|
||||||
|
|
||||||
input(event) {
|
input(event) {
|
||||||
this.model = event;
|
this.model = event;
|
||||||
|
|
||||||
|
this.$emit('input', event);
|
||||||
|
|
||||||
//this.$emit('change', this.model);
|
//this.$emit('change', this.model);
|
||||||
//this.$emit('interface', this.model);
|
//this.$emit('interface', this.model);
|
||||||
}
|
}
|
||||||
@ -147,6 +151,10 @@ export default {
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
dynamicCurrency: function (currency) {
|
dynamicCurrency: function (currency) {
|
||||||
|
if (!currency) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.money = {
|
this.money = {
|
||||||
decimal: currency.decimal_mark,
|
decimal: currency.decimal_mark,
|
||||||
thousands: currency.thousands_separator,
|
thousands: currency.thousands_separator,
|
||||||
|
@ -40,7 +40,9 @@ const app = new Vue({
|
|||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.totals.closing_balance = parseFloat(document.getElementById('closing_balance').value);
|
if (document.getElementById('closing_balance') != null) {
|
||||||
|
this.totals.closing_balance = parseFloat(document.getElementById('closing_balance').value);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods:{
|
methods:{
|
||||||
@ -59,10 +61,13 @@ const app = new Vue({
|
|||||||
let transactions = this.form.transactions;
|
let transactions = this.form.transactions;
|
||||||
|
|
||||||
let cleared_amount = 0;
|
let cleared_amount = 0;
|
||||||
|
let closing_balance = parseFloat(this.form.closing_balance);
|
||||||
let difference = 0;
|
let difference = 0;
|
||||||
let income_total = 0;
|
let income_total = 0;
|
||||||
let expense_total = 0;
|
let expense_total = 0;
|
||||||
|
|
||||||
|
this.totals.closing_balance = closing_balance;
|
||||||
|
|
||||||
if (transactions) {
|
if (transactions) {
|
||||||
// get all transactions.
|
// get all transactions.
|
||||||
Object.keys(transactions).forEach(function(transaction) {
|
Object.keys(transactions).forEach(function(transaction) {
|
||||||
|
@ -4,6 +4,7 @@ return [
|
|||||||
|
|
||||||
'reconcile' => 'Reconcile',
|
'reconcile' => 'Reconcile',
|
||||||
'reconciled' => 'Reconciled',
|
'reconciled' => 'Reconciled',
|
||||||
|
'opening_balance' => 'Opening Balance',
|
||||||
'closing_balance' => 'Closing Balance',
|
'closing_balance' => 'Closing Balance',
|
||||||
'unreconciled' => 'Unreconciled',
|
'unreconciled' => 'Unreconciled',
|
||||||
'transactions' => 'Transactions',
|
'transactions' => 'Transactions',
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
{{ Form::dateGroup('ended_at', trans('reconciliations.end_date'), 'calendar', ['id' => 'ended_at', 'class' => 'form-control datepicker', 'required' => 'required', 'date-format' => 'Y-m-d', 'autocomplete' => 'off'], request('ended_at', Date::now()->endOfMonth()->toDateString()), 'col-xl-3') }}
|
{{ Form::dateGroup('ended_at', trans('reconciliations.end_date'), 'calendar', ['id' => 'ended_at', 'class' => 'form-control datepicker', 'required' => 'required', 'date-format' => 'Y-m-d', 'autocomplete' => 'off'], request('ended_at', Date::now()->endOfMonth()->toDateString()), 'col-xl-3') }}
|
||||||
|
|
||||||
{{ Form::moneyGroup('closing_balance', trans('reconciliations.closing_balance'), 'balance-scale', ['required' => 'required', 'autofocus' => 'autofocus', 'currency' => $currency, 'dynamic-currency' => 'currency'], request('closing_balance', 0.00), 'col-xl-2') }}
|
{{ Form::moneyGroup('closing_balance', trans('reconciliations.closing_balance'), 'balance-scale', ['required' => 'required', 'autofocus' => 'autofocus', 'currency' => $currency, 'dynamic-currency' => 'currency', 'input' => 'onCalculate'], request('closing_balance', 0.00), 'col-xl-2') }}
|
||||||
|
|
||||||
{{ Form::selectAddNewGroup('account_id', trans_choice('general.accounts', 1), 'university', $accounts, request('account_id', setting('default.account')), ['required' => 'required', 'path' => route('modals.accounts.create'), 'change' => 'onChangeAccount'], 'col-xl-2') }}
|
{{ Form::selectAddNewGroup('account_id', trans_choice('general.accounts', 1), 'university', $accounts, request('account_id', setting('default.account')), ['required' => 'required', 'path' => route('modals.accounts.create'), 'change' => 'onChangeAccount'], 'col-xl-2') }}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@
|
|||||||
@endif
|
@endif
|
||||||
<td class="col-md-1 text-right d-none d-md-block">
|
<td class="col-md-1 text-right d-none d-md-block">
|
||||||
<div class="custom-control custom-checkbox">
|
<div class="custom-control custom-checkbox">
|
||||||
{{ Form::checkbox($item->type . '_' . $item->id, $item->amount, $item->reconciled, [
|
{{ Form::checkbox($item->type . '_' . $item->id, $item->price, $item->reconciled, [
|
||||||
'data-field' => 'transactions',
|
'data-field' => 'transactions',
|
||||||
'v-model' => 'form.transactions.' . $item->type . '_' . $item->id,
|
'v-model' => 'form.transactions.' . $item->type . '_' . $item->id,
|
||||||
'id' => 'transaction-' . $item->id . '-'. $item->type,
|
'id' => 'transaction-' . $item->id . '-'. $item->type,
|
||||||
@ -100,6 +100,12 @@
|
|||||||
@if ($transactions->count())
|
@if ($transactions->count())
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<tr class="row">
|
||||||
|
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.opening_balance') }}:</th>
|
||||||
|
<td id="closing-balance" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||||
|
<span>@money($opening_balance, $account->currency_code, true)</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr class="row">
|
<tr class="row">
|
||||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.closing_balance') }}:</th>
|
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.closing_balance') }}:</th>
|
||||||
<td id="closing-balance" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
<td id="closing-balance" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
@endif
|
@endif
|
||||||
<td class="col-md-1 text-right d-none d-md-block">
|
<td class="col-md-1 text-right d-none d-md-block">
|
||||||
<div class="custom-control custom-checkbox">
|
<div class="custom-control custom-checkbox">
|
||||||
{{ Form::checkbox($item->type . '_' . $item->id, $item->amount, $item->reconciled, [
|
{{ Form::checkbox($item->type . '_' . $item->id, $item->price, $item->reconciled, [
|
||||||
'data-field' => 'transactions',
|
'data-field' => 'transactions',
|
||||||
'v-model' => 'form.transactions.' . $item->type . '_' . $item->id,
|
'v-model' => 'form.transactions.' . $item->type . '_' . $item->id,
|
||||||
'id' => 'transaction-' . $item->id . '-'. $item->type,
|
'id' => 'transaction-' . $item->id . '-'. $item->type,
|
||||||
@ -70,34 +70,40 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@if ($transactions->count())
|
@if ($transactions->count())
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="row">
|
<tr class="row">
|
||||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.closing_balance') }}:</th>
|
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.opening_balance') }}:</th>
|
||||||
<td id="closing-balance" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
<td id="closing-balance" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||||
{{ Form::moneyGroup('closing_balance_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.closing_balance', 'currency' => $currency, 'masked' => 'true'], $reconciliation->closing_balance, 'text-right d-none') }}
|
<span>@money($opening_balance, $account->currency_code, true)</span>
|
||||||
<span id="closing-balance-total" v-if="totals.closing_balance" v-html="totals.closing_balance"></span>
|
</td>
|
||||||
<span v-else>@money($reconciliation->closing_balance, $account->currency_code, true)</span>
|
</tr>
|
||||||
</td>
|
<tr class="row">
|
||||||
</tr>
|
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.closing_balance') }}:</th>
|
||||||
<tr class="row">
|
<td id="closing-balance" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.cleared_amount') }}:</th>
|
{{ Form::moneyGroup('closing_balance_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.closing_balance', 'currency' => $currency, 'masked' => 'true'], $reconciliation->closing_balance, 'text-right d-none') }}
|
||||||
<td id="cleared-amount" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
<span id="closing-balance-total" v-if="totals.closing_balance" v-html="totals.closing_balance"></span>
|
||||||
{{ Form::moneyGroup('cleared_amount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.cleared_amount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
|
<span v-else>@money($reconciliation->closing_balance, $account->currency_code, true)</span>
|
||||||
<span id="cleared-amount-total" v-if="totals.cleared_amount" v-html="totals.cleared_amount"></span>
|
</td>
|
||||||
<span v-else>@money(0, $account->currency_code, true)</span>
|
</tr>
|
||||||
</td>
|
<tr class="row">
|
||||||
</tr>
|
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.cleared_amount') }}:</th>
|
||||||
<tr :class="difference" class="row">
|
<td id="cleared-amount" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('general.difference') }}:</th>
|
{{ Form::moneyGroup('cleared_amount_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.cleared_amount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
|
||||||
<td id="difference" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
<span id="cleared-amount-total" v-if="totals.cleared_amount" v-html="totals.cleared_amount"></span>
|
||||||
{{ Form::moneyGroup('difference_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.difference', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
|
<span v-else>@money(0, $account->currency_code, true)</span>
|
||||||
<span id="difference-total" v-if="totals.difference" v-html="totals.difference"></span>
|
</td>
|
||||||
<span v-else>@money(0, $account->currency_code, true)</span>
|
</tr>
|
||||||
</td>
|
<tr :class="difference" class="row">
|
||||||
</tr>
|
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('general.difference') }}:</th>
|
||||||
</tbody>
|
<td id="difference" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||||
</table>
|
{{ Form::moneyGroup('difference_total', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.difference', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
|
||||||
|
<span id="difference-total" v-if="totals.difference" v-html="totals.difference"></span>
|
||||||
|
<span v-else>@money(0, $account->currency_code, true)</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -49,6 +49,10 @@
|
|||||||
@change="{{ $attributes['change'] }}($event)"
|
@change="{{ $attributes['change'] }}($event)"
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if (!empty($attributes['input']))
|
||||||
|
@input="{{ $attributes['input'] }}"
|
||||||
|
@endif
|
||||||
|
|
||||||
@if (!empty($attributes['v-model']))
|
@if (!empty($attributes['v-model']))
|
||||||
@interface="form.errors.clear('{{ $attributes['v-model'] }}'); {{ $attributes['v-model'] . ' = $event' }}"
|
@interface="form.errors.clear('{{ $attributes['v-model'] }}'); {{ $attributes['v-model'] . ' = $event' }}"
|
||||||
@elseif (!empty($attributes['data-field']))
|
@elseif (!empty($attributes['data-field']))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user