Reconciliations multi currency and calculate fixed.

This commit is contained in:
Cüneyt Şentürk 2020-06-08 19:08:13 +03:00
parent a884e06b72
commit d4923b4414
7 changed files with 118 additions and 37 deletions

View File

@ -96,6 +96,28 @@ class Transaction extends Model
return $query->whereIn($this->table . '.type', (array) $types); return $query->whereIn($this->table . '.type', (array) $types);
} }
/**
* Scope to include only income.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeIncome($query)
{
return $query->where($this->table . '.type', '=', 'income');
}
/**
* Scope to include only expense.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeExpense($query)
{
return $query->where($this->table . '.type', '=', 'expense');
}
/** /**
* Get only transfers. * Get only transfers.
* *
@ -196,6 +218,11 @@ class Transaction extends Model
return $query->where('reconciled', 0); return $query->where('reconciled', 0);
} }
public function onCloning($src, $child = null)
{
$this->document_id = null;
}
/** /**
* Convert amount to double. * Convert amount to double.
* *
@ -218,6 +245,23 @@ class Transaction extends Model
$this->attributes['currency_rate'] = (double) $value; $this->attributes['currency_rate'] = (double) $value;
} }
/**
* Convert amount to double.
*
* @param string $value
* @return void
*/
public function getPriceAttribute($value)
{
if ($this->account->currency_code != $this->currency_code) {
$this->default_currency_code = $this->account->currency_code;
return $this->convertFromDefault($this->amount, $this->currency_code, $this->currency_rate);
}
return $this->amount;
}
/** /**
* Get the current balance. * Get the current balance.
* *

View File

@ -10,7 +10,7 @@
</span> </span>
</div> </div>
<money :name="name" @input="input" :placeholder="placeholder" v-bind="money" :value="value" :disabled="disabled" :masked="masked" class="form-control"></money> <money :name="name" @input="input" :placeholder="placeholder" v-bind="money" :value="model" :disabled="disabled" :masked="masked" class="form-control"></money>
</div> </div>
<div class="invalid-feedback d-block" v-if="error" v-html="error"></div> <div class="invalid-feedback d-block" v-if="error" v-html="error"></div>
@ -133,10 +133,14 @@ 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);
} }
@ -144,6 +148,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,

View File

@ -40,7 +40,9 @@ const app = new Vue({
}, },
mounted() { mounted() {
if (document.getElementById('closing_balance') != null) {
this.totals.closing_balance = parseFloat(document.getElementById('closing_balance').value); 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) {
@ -79,10 +84,17 @@ const app = new Vue({
} }
}); });
cleared_amount = parseFloat(this.form.opening_balance) + parseFloat(income_total - expense_total);
let transaction_total = income_total - expense_total;
cleared_amount = parseFloat(this.form.opening_balance) + transaction_total;
} }
difference = parseFloat(this.form.closing_balance) - cleared_amount; if (cleared_amount > 0) {
difference = parseFloat(this.form.closing_balance) - parseFloat(cleared_amount);
} else {
difference = parseFloat(this.form.closing_balance) + parseFloat(cleared_amount);
}
if (difference != 0) { if (difference != 0) {
this.difference = 'table-danger'; this.difference = 'table-danger';
@ -92,7 +104,7 @@ const app = new Vue({
this.reconcile = false; this.reconcile = false;
} }
this.totals.cleared_amount = cleared_amount; this.totals.cleared_amount = parseFloat(cleared_amount);
this.totals.difference = difference; this.totals.difference = difference;
}, },

View File

@ -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',

View File

@ -16,11 +16,11 @@
<div class="card-body"> <div class="card-body">
<div class="row align-items-center"> <div class="row align-items-center">
{{ Form::dateGroup('started_at', trans('reconciliations.start_date'), 'calendar', ['id' => 'started_at', 'class' => 'form-control datepicker', 'required' => 'required', 'date-format' => 'Y-m-d', 'autocomplete' => 'off'], request('started_at'), 'col-xl-3') }} {{ Form::dateGroup('started_at', trans('reconciliations.start_date'), 'calendar', ['id' => 'started_at', 'class' => 'form-control datepicker', 'required' => 'required', 'date-format' => 'Y-m-d', 'autocomplete' => 'off'], request('started_at', Date::now()->firstOfMonth()->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'), '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], 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">

View File

@ -72,6 +72,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">

View File

@ -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="{{ $attributes['v-model'] . ' = $event' }}" @interface="{{ $attributes['v-model'] . ' = $event' }}"
@elseif (!empty($attributes['data-field'])) @elseif (!empty($attributes['data-field']))