akaunting/resources/assets/js/views/banking/reconciliations.js

107 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-11-16 10:21:14 +03:00
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('./../../bootstrap');
import Vue from 'vue';
2020-01-03 12:10:07 +03:00
import DashboardPlugin from './../../plugins/dashboard-plugin';
2019-11-16 10:21:14 +03:00
import Global from './../../mixins/global';
import Form from './../../plugins/form';
import BulkAction from './../../plugins/bulk-action';
2020-01-03 12:10:07 +03:00
// plugin setup
Vue.use(DashboardPlugin);
2019-11-16 10:21:14 +03:00
const app = new Vue({
el: '#app',
2019-12-31 17:36:07 +03:00
2019-11-16 10:21:14 +03:00
mixins: [
Global
],
2019-12-31 17:36:07 +03:00
2019-11-16 10:21:14 +03:00
data: function () {
return {
form: new Form('reconciliation'),
2020-02-18 17:14:06 +03:00
bulk_action: new BulkAction('reconciliations'),
reconcile: true,
difference: null,
totals: {
closing_balance: 0,
cleared_amount: 0,
difference: 0,
},
currency: null,
2019-11-16 10:21:14 +03:00
}
2020-02-18 17:14:06 +03:00
},
mounted() {
this.totals.closing_balance = parseFloat(document.getElementById('closing_balance').value);
},
methods:{
onReconcilition() {
let form = document.getElementById('form-create-reconciliation');
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;
},
onCalculate() {
this.reconcile = true;
this.difference = null;
let transactions = this.form.transactions;
let cleared_amount = 0;
let difference = 0;
let income_total = 0;
let expense_total = 0;
if (transactions) {
// get all transactions.
Object.keys(transactions).forEach(function(transaction) {
if (!transactions[transaction]) {
return;
}
let type = transaction.split('_');
if (type[0] == 'income') {
income_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value);
} else {
expense_total += parseFloat(document.getElementById('transaction-' + type[1] + '-' + type[0]).value);
}
});
cleared_amount = parseFloat(this.form.opening_balance) + parseFloat(income_total - expense_total);
}
difference = parseFloat(this.form.closing_balance) - cleared_amount;
if (difference != 0) {
this.difference = 'table-danger';
this.reconcile = true;
} else {
this.difference = 'table-success';
this.reconcile = false;
}
this.totals.cleared_amount = cleared_amount;
this.totals.difference = difference;
},
onReconcileSubmit() {
this.form.reconcile = 1;
this.form.submit();
}
},
2019-11-16 10:21:14 +03:00
});