2022-11-16 01:44:39 +00:00
|
|
|
import './style.scss';
|
2015-07-07 15:27:47 +00:00
|
|
|
|
2022-11-16 01:44:39 +00:00
|
|
|
export default new Class({
|
2019-03-13 08:57:18 +00:00
|
|
|
Extends: Hedera.Form,
|
2022-11-16 01:44:39 +00:00
|
|
|
Template: require('./ui.xml'),
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
async open() {
|
2023-02-15 13:07:09 +00:00
|
|
|
const basket = new Hedera.Basket(this.app);
|
|
|
|
try {
|
2023-02-23 13:32:13 +00:00
|
|
|
await basket.checkOrder(this.hash.$.id);
|
2023-02-15 13:07:09 +00:00
|
|
|
} catch (err) {
|
|
|
|
Htk.Toast.showError(err.message);
|
|
|
|
}
|
|
|
|
await Hedera.Form.prototype.open.call(this);
|
2019-03-13 08:57:18 +00:00
|
|
|
},
|
2015-07-07 15:27:47 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onOrderReady(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 = [];
|
2022-11-17 22:31:48 +00:00
|
|
|
let selectedMethod;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
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
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onPayMethodChange(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
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onModifyClick() {
|
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
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
async onConfirmClick() {
|
2023-01-30 10:08:26 +00:00
|
|
|
Vn.Node.disableInputs(this.node);
|
|
|
|
try {
|
|
|
|
await this.conn.execQuery(
|
|
|
|
'CALL myOrder_confirm(#id)',
|
|
|
|
this.$.params.$
|
|
|
|
);
|
2023-02-15 13:07:09 +00:00
|
|
|
Hedera.Basket.unload();
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.successDialog.show();
|
2023-01-30 10:08:26 +00:00
|
|
|
} finally {
|
|
|
|
Vn.Node.disableInputs(this.node, false);
|
|
|
|
}
|
2019-03-13 08:57:18 +00:00
|
|
|
},
|
2016-10-20 08:37:08 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
async onDialogResponse() {
|
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-11-28 08:51:31 +00:00
|
|
|
await 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
|
|
|
}
|
|
|
|
});
|