Reconciliations date control edited

This commit is contained in:
Burak Civan 2021-06-18 15:26:58 +03:00
parent 1a6ba034bd
commit eaf42ed877
2 changed files with 122 additions and 116 deletions

View File

@ -4,118 +4,124 @@
* building robust, powerful web applications using Vue and Laravel. * building robust, powerful web applications using Vue and Laravel.
*/ */
require('./../../bootstrap'); require('./../../bootstrap');
import Vue from 'vue'; import Vue from 'vue';
import DashboardPlugin from './../../plugins/dashboard-plugin'; import DashboardPlugin from './../../plugins/dashboard-plugin';
import Global from './../../mixins/global'; import Global from './../../mixins/global';
import Form from './../../plugins/form'; import Form from './../../plugins/form';
import BulkAction from './../../plugins/bulk-action'; import BulkAction from './../../plugins/bulk-action';
// plugin setup // plugin setup
Vue.use(DashboardPlugin); Vue.use(DashboardPlugin);
const app = new Vue({ const app = new Vue({
el: '#app', el: '#app',
mixins: [ mixins: [
Global Global
], ],
data: function () { data: function () {
return { return {
form: new Form('reconciliation'), form: new Form('reconciliation'),
bulk_action: new BulkAction('reconciliations'), bulk_action: new BulkAction('reconciliations'),
reconcile: true, reconcile: true,
difference: null, difference: null,
totals: { totals: {
closing_balance: 0, closing_balance: 0,
cleared_amount: 0, cleared_amount: 0,
difference: 0, difference: 0,
}, },
} min_due_date: false
}, }
},
mounted() {
if (document.getElementById('closing_balance') != null) { 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);
}
if (this.form._method == 'PATCH') {
this.onCalculate(); if (this.form._method == 'PATCH') {
} this.onCalculate();
}, }
},
methods:{
onReconcilition() { methods:{
let form = document.getElementById('form-create-reconciliation'); setDueMinDate(date) {
this.min_due_date = date;
let path = form.action +'?started_at=' + this.form.started_at + '&ended_at=' + this.form.ended_at + '&closing_balance=' + this.form.closing_balance + '&account_id=' + this.form.account_id; },
window.location.href = path; onReconcilition() {
}, let form = document.getElementById('form-create-reconciliation');
onCalculate() { let path = form.action +'?started_at=' + this.form.started_at + '&ended_at=' + this.form.ended_at + '&closing_balance=' + this.form.closing_balance + '&account_id=' + this.form.account_id;
this.reconcile = true;
this.difference = null; window.location.href = path;
},
let transactions = this.form.transactions;
onCalculate() {
let cleared_amount = 0; this.reconcile = true;
let closing_balance = parseFloat(this.form.closing_balance); this.difference = null;
let difference = 0;
let income_total = 0; let transactions = this.form.transactions;
let expense_total = 0;
let cleared_amount = 0;
this.totals.closing_balance = closing_balance; let closing_balance = parseFloat(this.form.closing_balance);
let difference = 0;
if (transactions) { let income_total = 0;
// get all transactions. let expense_total = 0;
Object.keys(transactions).forEach(function(transaction) {
if (!transactions[transaction]) { this.totals.closing_balance = closing_balance;
return;
} if (transactions) {
// get all transactions.
let type = transaction.split('_'); Object.keys(transactions).forEach(function(transaction) {
if (!transactions[transaction]) {
if (type[0] == 'income') { return;
income_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value); }
} else {
expense_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value); let type = transaction.split('_');
}
}); if (type[0] == 'income') {
income_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value);
} else {
let transaction_total = income_total - expense_total; expense_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value);
}
cleared_amount = parseFloat(this.form.opening_balance) + transaction_total; });
}
if (cleared_amount > 0) { let transaction_total = income_total - expense_total;
difference = (parseFloat(this.form.closing_balance) - parseFloat(cleared_amount)).toFixed(this.currency.precision);
} else { cleared_amount = parseFloat(this.form.opening_balance) + transaction_total;
difference = (parseFloat(this.form.closing_balance) + parseFloat(cleared_amount)).toFixed(this.currency.precision); }
}
if (cleared_amount > 0) {
if (difference != 0) { difference = (parseFloat(this.form.closing_balance) - parseFloat(cleared_amount)).toFixed(this.currency.precision);
this.difference = 'table-danger'; } else {
this.reconcile = true; difference = (parseFloat(this.form.closing_balance) + parseFloat(cleared_amount)).toFixed(this.currency.precision);
} else { }
this.difference = 'table-success';
this.reconcile = false; if (difference != 0) {
} this.difference = 'table-danger';
this.reconcile = true;
this.totals.cleared_amount = parseFloat(cleared_amount); } else {
this.totals.difference = difference; this.difference = 'table-success';
}, this.reconcile = false;
}
onReconcileSubmit() {
this.form.reconcile = 1; this.totals.cleared_amount = parseFloat(cleared_amount);
this.totals.difference = difference;
this.form.submit(); },
}
}, onReconcileSubmit() {
}); this.form.reconcile = 1;
this.form.submit();
}
},
});

View File

@ -16,9 +16,9 @@
<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', 'show-date-format' => company_date_format(), 'date-format' => 'Y-m-d', 'autocomplete' => 'off'], request('started_at', Date::now()->firstOfMonth()->toDateString()), 'col-xl-3') }} {{ Form::dateGroup('started_at', trans('reconciliations.start_date'), 'calendar', ['id' => 'started_at', 'class' => 'form-control datepicker', 'required' => 'required', 'show-date-format' => company_date_format(), 'date-format' => 'Y-m-d', 'autocomplete' => 'off', 'change' => 'setDueMinDate'], 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', 'show-date-format' => company_date_format(), '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', 'show-date-format' => company_date_format(), 'date-format' => 'Y-m-d', 'autocomplete' => 'off', 'min-date' => 'form.started_at', 'min-date-dynamic' => 'min_due_date', 'data-value-min' => true], 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', 'input' => 'onCalculate'], 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') }}