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 static $currencies;
|
||||
|
||||
public function account()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -135,11 +135,15 @@ export default {
|
||||
change() {
|
||||
//this.$emit('change', this.model);
|
||||
//this.$emit('interface', this.model);
|
||||
|
||||
this.$emit('input', this.model);
|
||||
},
|
||||
|
||||
input(event) {
|
||||
this.model = event;
|
||||
|
||||
this.$emit('input', event);
|
||||
|
||||
//this.$emit('change', this.model);
|
||||
//this.$emit('interface', this.model);
|
||||
}
|
||||
@ -147,6 +151,10 @@ export default {
|
||||
|
||||
watch: {
|
||||
dynamicCurrency: function (currency) {
|
||||
if (!currency) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.money = {
|
||||
decimal: currency.decimal_mark,
|
||||
thousands: currency.thousands_separator,
|
||||
|
@ -40,7 +40,9 @@ const app = new Vue({
|
||||
},
|
||||
|
||||
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:{
|
||||
@ -59,10 +61,13 @@ const app = new Vue({
|
||||
let transactions = this.form.transactions;
|
||||
|
||||
let cleared_amount = 0;
|
||||
let closing_balance = parseFloat(this.form.closing_balance);
|
||||
let difference = 0;
|
||||
let income_total = 0;
|
||||
let expense_total = 0;
|
||||
|
||||
this.totals.closing_balance = closing_balance;
|
||||
|
||||
if (transactions) {
|
||||
// get all transactions.
|
||||
Object.keys(transactions).forEach(function(transaction) {
|
||||
|
@ -4,6 +4,7 @@ return [
|
||||
|
||||
'reconcile' => 'Reconcile',
|
||||
'reconciled' => 'Reconciled',
|
||||
'opening_balance' => 'Opening Balance',
|
||||
'closing_balance' => 'Closing Balance',
|
||||
'unreconciled' => 'Unreconciled',
|
||||
'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::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') }}
|
||||
|
||||
@ -83,7 +83,7 @@
|
||||
@endif
|
||||
<td class="col-md-1 text-right d-none d-md-block">
|
||||
<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',
|
||||
'v-model' => 'form.transactions.' . $item->type . '_' . $item->id,
|
||||
'id' => 'transaction-' . $item->id . '-'. $item->type,
|
||||
@ -100,6 +100,12 @@
|
||||
@if ($transactions->count())
|
||||
<table class="table">
|
||||
<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">
|
||||
<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">
|
||||
|
@ -55,7 +55,7 @@
|
||||
@endif
|
||||
<td class="col-md-1 text-right d-none d-md-block">
|
||||
<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',
|
||||
'v-model' => 'form.transactions.' . $item->type . '_' . $item->id,
|
||||
'id' => 'transaction-' . $item->id . '-'. $item->type,
|
||||
@ -70,34 +70,40 @@
|
||||
</tbody>
|
||||
</table>
|
||||
@if ($transactions->count())
|
||||
<table class="table">
|
||||
<tbody>
|
||||
<tr class="row">
|
||||
<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">
|
||||
{{ 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 id="closing-balance-total" v-if="totals.closing_balance" v-html="totals.closing_balance"></span>
|
||||
<span v-else>@money($reconciliation->closing_balance, $account->currency_code, true)</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="row">
|
||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.cleared_amount') }}:</th>
|
||||
<td id="cleared-amount" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||
{{ 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 id="cleared-amount-total" v-if="totals.cleared_amount" v-html="totals.cleared_amount"></span>
|
||||
<span v-else>@money(0, $account->currency_code, true)</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr :class="difference" class="row">
|
||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('general.difference') }}:</th>
|
||||
<td id="difference" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||
{{ 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>
|
||||
<table class="table">
|
||||
<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">
|
||||
<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">
|
||||
{{ 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 id="closing-balance-total" v-if="totals.closing_balance" v-html="totals.closing_balance"></span>
|
||||
<span v-else>@money($reconciliation->closing_balance, $account->currency_code, true)</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="row">
|
||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('reconciliations.cleared_amount') }}:</th>
|
||||
<td id="cleared-amount" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||
{{ 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 id="cleared-amount-total" v-if="totals.cleared_amount" v-html="totals.cleared_amount"></span>
|
||||
<span v-else>@money(0, $account->currency_code, true)</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr :class="difference" class="row">
|
||||
<th class="col-md-9 col-lg-11 text-right d-none d-md-block">{{ trans('general.difference') }}:</th>
|
||||
<td id="difference" class="col-md-3 col-lg-1 text-right d-none d-md-block">
|
||||
{{ 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
|
||||
</div>
|
||||
|
||||
|
@ -49,6 +49,10 @@
|
||||
@change="{{ $attributes['change'] }}($event)"
|
||||
@endif
|
||||
|
||||
@if (!empty($attributes['input']))
|
||||
@input="{{ $attributes['input'] }}"
|
||||
@endif
|
||||
|
||||
@if (!empty($attributes['v-model']))
|
||||
@interface="form.errors.clear('{{ $attributes['v-model'] }}'); {{ $attributes['v-model'] . ' = $event' }}"
|
||||
@elseif (!empty($attributes['data-field']))
|
||||
|
Loading…
x
Reference in New Issue
Block a user