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() { mounted() {
if (document.getElementById('closing_balance') != null) { 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);
} }
if (this.form._method == 'PATCH') { if (this.form._method == 'PATCH') {
this.onCalculate(); this.onCalculate();
} }
}, },
methods:{ methods:{
onReconcilition() { setDueMinDate(date) {
let form = document.getElementById('form-create-reconciliation'); 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; onReconcilition() {
let form = document.getElementById('form-create-reconciliation');
window.location.href = path; 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;
},
onCalculate() { window.location.href = path;
this.reconcile = true; },
this.difference = null;
let transactions = this.form.transactions; onCalculate() {
this.reconcile = true;
this.difference = null;
let cleared_amount = 0; let transactions = this.form.transactions;
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; let cleared_amount = 0;
let closing_balance = parseFloat(this.form.closing_balance);
let difference = 0;
let income_total = 0;
let expense_total = 0;
if (transactions) { this.totals.closing_balance = closing_balance;
// get all transactions.
Object.keys(transactions).forEach(function(transaction) {
if (!transactions[transaction]) {
return;
}
let type = transaction.split('_'); if (transactions) {
// get all transactions.
Object.keys(transactions).forEach(function(transaction) {
if (!transactions[transaction]) {
return;
}
if (type[0] == 'income') { let type = transaction.split('_');
income_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value);
} else { if (type[0] == 'income') {
expense_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value); income_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value);
} } else {
}); expense_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value);
}
});
let transaction_total = income_total - expense_total; let transaction_total = income_total - expense_total;
cleared_amount = parseFloat(this.form.opening_balance) + transaction_total; cleared_amount = parseFloat(this.form.opening_balance) + transaction_total;
} }
if (cleared_amount > 0) { if (cleared_amount > 0) {
difference = (parseFloat(this.form.closing_balance) - parseFloat(cleared_amount)).toFixed(this.currency.precision); difference = (parseFloat(this.form.closing_balance) - parseFloat(cleared_amount)).toFixed(this.currency.precision);
} else { } else {
difference = (parseFloat(this.form.closing_balance) + parseFloat(cleared_amount)).toFixed(this.currency.precision); difference = (parseFloat(this.form.closing_balance) + parseFloat(cleared_amount)).toFixed(this.currency.precision);
} }
if (difference != 0) { if (difference != 0) {
this.difference = 'table-danger'; this.difference = 'table-danger';
this.reconcile = true; this.reconcile = true;
} else { } else {
this.difference = 'table-success'; this.difference = 'table-success';
this.reconcile = false; this.reconcile = false;
} }
this.totals.cleared_amount = parseFloat(cleared_amount); this.totals.cleared_amount = parseFloat(cleared_amount);
this.totals.difference = difference; this.totals.difference = difference;
}, },
onReconcileSubmit() { onReconcileSubmit() {
this.form.reconcile = 1; this.form.reconcile = 1;
this.form.submit();
}
},
});
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') }}