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
|
|
|
}
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
var total = form.$.taxableBase + form.$.tax;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
|
|
|
if (total === null)
|
|
|
|
total = 0;
|
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
var credit = form.$.credit;
|
|
|
|
var debt = form.$.debt;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
|
|
|
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(
|
2016-01-15 12:31:08 +00:00
|
|
|
_('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;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.payAmount.value = 'ALL';
|
2016-01-15 12:31:08 +00:00
|
|
|
|
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';
|
2016-01-15 12:31:08 +00:00
|
|
|
|
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';
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var methods = [];
|
|
|
|
|
2019-03-13 08:57:18 +00:00
|
|
|
if (totalDebt <= 0) {
|
2016-01-15 12:31:08 +00:00
|
|
|
methods = ['balance'];
|
|
|
|
selectedMethod = 'BALANCE';
|
2019-03-13 08:57:18 +00:00
|
|
|
} else {
|
2016-01-15 12:31:08 +00:00
|
|
|
methods = ['card', 'transfer', 'later'];
|
|
|
|
|
2019-03-13 08:57:18 +00:00
|
|
|
if (!creditExceededCond) {
|
|
|
|
methods.push('credit');
|
2016-01-15 12:31:08 +00:00
|
|
|
selectedMethod = 'CREDIT';
|
2019-03-13 08:57:18 +00:00
|
|
|
} else
|
2016-01-15 12:31:08 +00:00
|
|
|
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';
|
2016-01-15 12:31:08 +00:00
|
|
|
|
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) {
|
2016-01-15 12:31:08 +00:00
|
|
|
var id = this.displayedInfo;
|
2022-05-28 15:49:46 +00:00
|
|
|
|
2016-01-15 12:31:08 +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) {
|
2016-01-15 12:31:08 +00:00
|
|
|
case 'BALANCE':
|
2022-05-28 15:49:46 +00:00
|
|
|
id = 'balanceMethod';
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case 'CREDIT':
|
2022-05-28 15:49:46 +00:00
|
|
|
id = 'creditMethod';
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case 'CARD':
|
2022-05-28 15:49:46 +00:00
|
|
|
id = 'cardMethod';
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
case 'TRANSFER':
|
2022-05-28 15:49:46 +00:00
|
|
|
id = 'transferMethod';
|
2016-01-15 12:31:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
id = null;
|
|
|
|
}
|
2022-05-28 15:49:46 +00:00
|
|
|
|
2016-01-15 12:31:08 +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);
|
2015-12-15 15:22:46 +00:00
|
|
|
|
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
|
|
|
},
|
2016-10-20 08:37:08 +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;
|
2016-01-15 12:31:08 +00:00
|
|
|
else
|
2022-05-28 01:18:06 +00:00
|
|
|
var payAmount = this.$.totalAmount.value;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-05-30 01:30:33 +00:00
|
|
|
var tpv = new Hedera.Tpv({
|
|
|
|
conn: this.conn,
|
|
|
|
hash: this.hash
|
|
|
|
});
|
2022-10-03 12:49:41 +00:00
|
|
|
tpv.pay(payAmount, this.$.order.companyFk);
|
2019-03-13 08:57:18 +00:00
|
|
|
} else
|
2022-10-03 12:49:41 +00:00
|
|
|
this.hash.setAll({form: 'ecomerce/orders'});
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|