Invoice/Bill add payment change method..

This commit is contained in:
Cüneyt Şentürk
2020-06-09 18:19:17 +03:00
parent 62f9cbf7c5
commit 11a862fea4
9 changed files with 315 additions and 214 deletions

View File

@ -33,7 +33,11 @@
{{ buttons.cancel.text }}
</button>
<button :disabled="form.loading" type="button" class="btn button-submit" :class="buttons.confirm.class" @click="onSubmit">
<a v-if="buttons.payment" :href="buttons.payment.url" class="btn btn-white" :class="buttons.payment.class">
{{ buttons.payment.text }}
</a>
<button :disabled="form.loading" type="button" class="btn button-submit" :class="buttons.confirm.class" @click="onSubmit">
<div class="aka-loader"></div><span>{{ buttons.confirm.text }}</span>
</button>
</div>
@ -217,7 +221,24 @@ export default {
})
.catch(error => {
});
}
},
// Change bank account get money and currency rate
async onChangePaymentAccount(account_id) {
let payment_account = Promise.resolve(window.axios.get(url + '/banking/accounts/currency', {
params: {
account_id: account_id
}
}));
payment_account.then(response => {
this.form.currency = response.data.currency_name;
this.form.currency_code = response.data.currency_code;
this.form.currency_rate = response.data.currency_rate;
})
.catch(error => {
});
},
}
})
});

View File

@ -38,15 +38,6 @@ const app = new Vue({
tax: 0,
total: 0
},
transaction_form: new Form('transaction'),
payment: {
modal: false,
amount: 0,
title: '',
message: '',
html: '',
errors: new Error()
},
transaction: [],
items: '',
discount: false,
@ -60,7 +51,9 @@ const app = new Vue({
},
mounted() {
this.colspan = document.getElementById("items").rows[0].cells.length - 1;
if ((document.getElementById('items') != null) && (document.getElementById('items').rows)) {
this.colspan = document.getElementById("items").rows[0].cells.length - 1;
}
this.form.items = [];
if (this.form.method) {
@ -322,51 +315,113 @@ const app = new Vue({
this.onCalculateTotal();
},
onPayment() {
this.payment.modal = true;
async onPayment() {
let bill_id = document.getElementById('bill_id').value;
let form = this.transaction_form;
this.transaction_form = new Form('transaction');
this.transaction_form.paid_at = form.paid_at;
this.transaction_form.account_id = form.account_id;
this.transaction_form.payment_method = form.payment_method;
},
addPayment() {
this.transaction_form.submit();
this.payment.errors = this.transaction_form.errors;
this.form.loading = true;
this.$emit("confirm");
},
closePayment() {
this.payment = {
let payment = {
modal: false,
amount: 0,
url: url + '/modals/bills/' + bill_id + '/transactions/create',
title: '',
message: '',
errors: this.transaction_form.errors
html: '',
buttons:{}
};
},
// Change bank account get money and currency rate
onChangePaymentAccount(account_id) {
axios.get(url + '/banking/accounts/currency', {
params: {
account_id: account_id
}
})
.then(response => {
this.transaction_form.currency = response.data.currency_name;
this.transaction_form.currency_code = response.data.currency_code;
this.transaction_form.currency_rate = response.data.currency_rate;
let payment_promise = Promise.resolve(window.axios.get(payment.url));
payment_promise.then(response => {
payment.modal = true;
payment.title = response.data.data.title;
payment.html = response.data.html;
payment.buttons = response.data.data.buttons;
this.component = Vue.component('add-new-component', (resolve, reject) => {
resolve({
template: '<div id="dynamic-component"><akaunting-modal-add-new :show="payment.modal" @submit="onSubmit" @cancel="onCancel" :buttons="payment.buttons" :title="payment.title" :is_component=true :message="payment.html"></akaunting-modal-add-new></div>',
mixins: [
Global
],
data: function () {
return {
form:{},
payment: payment,
}
},
methods: {
onSubmit(event) {
this.form = event;
this.loading = true;
let data = this.form.data();
FormData.prototype.appendRecursive = function(data, wrapper = null) {
for(var name in data) {
if (wrapper) {
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], wrapper + '[' + name + ']');
} else {
this.append(wrapper + '[' + name + ']', data[name]);
}
} else {
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], name);
} else {
this.append(name, data[name]);
}
}
}
};
let form_data = new FormData();
form_data.appendRecursive(data);
window.axios({
method: this.form.method,
url: this.form.action,
data: form_data,
headers: {
'X-CSRF-TOKEN': window.Laravel.csrfToken,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
if (response.data.success) {
if (response.data.redirect) {
this.form.loading = true;
window.location.href = response.data.redirect;
}
}
})
.catch(error => {
this.form.loading = false;
this.form.onFail(error);
this.method_show_html = error.message;
});
},
onCancel() {
this.payment.modal = false;
this.payment.html = null;
let documentClasses = document.body.classList;
documentClasses.remove("modal-open");
},
}
})
});
})
.catch(error => {
})
.finally(function () {
// always executed
});
},
}

View File

@ -38,15 +38,6 @@ const app = new Vue({
tax: 0,
total: 0
},
transaction_form: new Form('transaction'),
payment: {
modal: false,
amount: 0,
title: '',
message: '',
html: '',
errors: new Error()
},
transaction: [],
items: '',
discount: false,
@ -60,7 +51,10 @@ const app = new Vue({
},
mounted() {
this.colspan = document.getElementById("items").rows[0].cells.length - 1;
if ((document.getElementById('items') != null) && (document.getElementById('items').rows)) {
this.colspan = document.getElementById("items").rows[0].cells.length - 1;
}
this.form.items = [];
if (this.form.method) {
@ -322,51 +316,113 @@ const app = new Vue({
this.onCalculateTotal();
},
onPayment() {
this.payment.modal = true;
async onPayment() {
let invoice_id = document.getElementById('invoice_id').value;
let form = this.transaction_form;
this.transaction_form = new Form('transaction');
this.transaction_form.paid_at = form.paid_at;
this.transaction_form.account_id = form.account_id;
this.transaction_form.payment_method = form.payment_method;
},
addPayment() {
this.transaction_form.submit();
this.payment.errors = this.transaction_form.errors;
this.form.loading = true;
this.$emit("confirm");
},
closePayment() {
this.payment = {
let payment = {
modal: false,
amount: 0,
url: url + '/modals/invoices/' + invoice_id + '/transactions/create',
title: '',
message: '',
errors: this.transaction_form.errors
html: '',
buttons:{}
};
},
// Change bank account get money and currency rate
onChangePaymentAccount(account_id) {
axios.get(url + '/banking/accounts/currency', {
params: {
account_id: account_id
}
})
.then(response => {
this.transaction_form.currency = response.data.currency_name;
this.transaction_form.currency_code = response.data.currency_code;
this.transaction_form.currency_rate = response.data.currency_rate;
let payment_promise = Promise.resolve(window.axios.get(payment.url));
payment_promise.then(response => {
payment.modal = true;
payment.title = response.data.data.title;
payment.html = response.data.html;
payment.buttons = response.data.data.buttons;
this.component = Vue.component('add-new-component', (resolve, reject) => {
resolve({
template: '<div id="dynamic-component"><akaunting-modal-add-new :show="payment.modal" @submit="onSubmit" @cancel="onCancel" :buttons="payment.buttons" :title="payment.title" :is_component=true :message="payment.html"></akaunting-modal-add-new></div>',
mixins: [
Global
],
data: function () {
return {
form:{},
payment: payment,
}
},
methods: {
onSubmit(event) {
this.form = event;
this.loading = true;
let data = this.form.data();
FormData.prototype.appendRecursive = function(data, wrapper = null) {
for(var name in data) {
if (wrapper) {
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], wrapper + '[' + name + ']');
} else {
this.append(wrapper + '[' + name + ']', data[name]);
}
} else {
if ((typeof data[name] == 'object' || data[name].constructor === Array) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], name);
} else {
this.append(name, data[name]);
}
}
}
};
let form_data = new FormData();
form_data.appendRecursive(data);
window.axios({
method: this.form.method,
url: this.form.action,
data: form_data,
headers: {
'X-CSRF-TOKEN': window.Laravel.csrfToken,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
if (response.data.success) {
if (response.data.redirect) {
this.form.loading = true;
window.location.href = response.data.redirect;
}
}
})
.catch(error => {
this.form.loading = false;
this.form.onFail(error);
this.method_show_html = error.message;
});
},
onCancel() {
this.payment.modal = false;
this.payment.html = null;
let documentClasses = document.body.classList;
documentClasses.remove("modal-open");
},
}
})
});
})
.catch(error => {
})
.finally(function () {
// always executed
});
},
}