hedera-web/forms/ecomerce/confirm/confirm.js

152 lines
3.1 KiB
JavaScript
Raw Normal View History

2015-07-07 15:27:47 +00:00
2019-03-13 08:57:18 +00:00
Hedera.Confirm = new Class({
Extends: Hedera.Form,
2015-12-10 13:48:43 +00:00
2019-03-13 08:57:18 +00:00
open: function() {
this.close();
2015-12-10 13:48:43 +00:00
this.isOpen = true;
2022-05-30 01:30:33 +00:00
Hedera.BasketChecker.check(this.conn, this.hash,
2019-03-13 08:57:18 +00:00
this.onBasketCheck.bind(this));
},
2015-12-10 13:48:43 +00:00
2019-03-13 08:57:18 +00:00
onBasketCheck: function(isOk) {
2015-12-10 13:48:43 +00:00
if (isOk)
2019-03-13 08:57:18 +00:00
this.loadUi();
},
2015-07-07 15:27:47 +00:00
2019-03-13 08:57:18 +00:00
onOrderReady: function(form) {
2015-07-17 14:34:42 +00:00
if (form.row < 0)
return;
2022-05-28 15:49:46 +00:00
if (form.$.method != 'PICKUP') {
2022-05-28 01:18:06 +00:00
Vn.Node.show(this.$.address);
Vn.Node.setText(this.$.method, _('Agency'));
2019-03-13 08:57:18 +00:00
} else {
2022-05-28 01:18:06 +00:00
Vn.Node.hide(this.$.address);
Vn.Node.setText(this.$.method, _('Warehouse'));
2015-07-17 14:34:42 +00:00
}
2022-05-28 15:49:46 +00:00
var total = form.$.taxableBase + form.$.tax;
if (total === null)
total = 0;
2022-05-28 15:49:46 +00:00
var credit = form.$.credit;
var debt = form.$.debt;
var totalDebt = debt + total;
var exceededCredit = totalDebt - credit;
var creditExceededCond = exceededCredit > 0;
if (creditExceededCond)
2019-03-13 08:57:18 +00:00
Htk.Toast.showWarning(
_('You have exceeded your credit.'));
2022-05-28 01:18:06 +00:00
this.$.debt.value = debt;
this.$.totalDebt.value = totalDebt;
this.$.totalAmount.value = totalDebt;
this.$.creditExcess.value = exceededCredit;
this.$.excessAmount.value = exceededCredit;
2022-05-28 01:18:06 +00:00
this.$.payAmount.value = 'ALL';
2019-03-13 08:57:18 +00:00
if (credit > 0) {
2022-05-28 01:18:06 +00:00
this.$.creditInfo.style.display = 'table-row';
2019-03-13 08:57:18 +00:00
if (creditExceededCond) {
2022-05-28 01:18:06 +00:00
this.$.amountSelector.style.display = 'block';
this.$.exceededInfo.style.display = 'table-row';
this.$.payAmount.value = 'EXCEEDED';
}
}
var methods = [];
2019-03-13 08:57:18 +00:00
if (totalDebt <= 0) {
methods = ['balance'];
selectedMethod = 'BALANCE';
2019-03-13 08:57:18 +00:00
} else {
methods = ['card', 'transfer', 'later'];
2019-03-13 08:57:18 +00:00
if (!creditExceededCond) {
methods.push('credit');
selectedMethod = 'CREDIT';
2019-03-13 08:57:18 +00:00
} else
selectedMethod = 'CARD';
}
for (var i = 0; i < methods.length; i++)
2022-05-28 15:49:46 +00:00
this.$[`${methods[i]}Method`].style.display = 'block';
2022-05-28 01:18:06 +00:00
this.$.payMethod.value = selectedMethod;
2019-03-13 08:57:18 +00:00
},
2015-07-17 14:34:42 +00:00
2019-03-13 08:57:18 +00:00
onPayMethodChange: function(payMethod) {
var id = this.displayedInfo;
2022-05-28 15:49:46 +00:00
if (id)
2022-05-28 15:49:46 +00:00
Vn.Node.removeClass(this.$[id], 'selected');
2019-03-13 08:57:18 +00:00
switch (payMethod.value) {
case 'BALANCE':
2022-05-28 15:49:46 +00:00
id = 'balanceMethod';
break;
case 'CREDIT':
2022-05-28 15:49:46 +00:00
id = 'creditMethod';
break;
case 'CARD':
2022-05-28 15:49:46 +00:00
id = 'cardMethod';
break;
case 'TRANSFER':
2022-05-28 15:49:46 +00:00
id = 'transferMethod';
break;
default:
id = null;
}
2022-05-28 15:49:46 +00:00
this.displayedInfo = id;
if (id)
2022-05-28 15:49:46 +00:00
Vn.Node.addClass(this.$[id], 'selected');
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2019-03-13 08:57:18 +00:00
disableButtons: function(disable) {
2022-05-28 01:18:06 +00:00
this.$.modify.disabled = disable;
this.$.confirm.disabled = disable;
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2019-03-13 08:57:18 +00:00
onModifyClick: function() {
2015-07-07 15:27:47 +00:00
window.history.back();
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2019-03-13 08:57:18 +00:00
onConfirmClick: function() {
this.disableButtons(true);
2022-05-28 01:18:06 +00:00
this.$.confirmQuery.execute();
2019-03-13 08:57:18 +00:00
},
2015-07-07 15:27:47 +00:00
2019-03-13 08:57:18 +00:00
onConfirm: function(query, resultSet) {
this.disableButtons(false);
2019-03-13 08:57:18 +00:00
if (resultSet.fetchResult())
2022-05-28 01:18:06 +00:00
this.$.successDialog.show();
2019-03-13 08:57:18 +00:00
},
2019-03-13 08:57:18 +00:00
onDialogResponse: function() {
2022-05-28 01:18:06 +00:00
if (this.$.payMethod.value === 'CARD') {
if (this.$.payAmount.value === 'EXCEEDED')
var payAmount = this.$.excessAmount.value;
else
2022-05-28 01:18:06 +00:00
var payAmount = this.$.totalAmount.value;
2022-05-30 01:30:33 +00:00
var tpv = new Hedera.Tpv({
conn: this.conn,
hash: this.hash
});
2022-05-28 15:49:46 +00:00
tpv.pay(payAmount, this.$.orderForm.$.companyFk);
2019-03-13 08:57:18 +00:00
} else
2022-05-30 01:30:33 +00:00
this.hash.setAll({'form': 'ecomerce/orders'});
2015-07-07 15:27:47 +00:00
}
});