forked from verdnatura/hedera-web
146 lines
3.1 KiB
JavaScript
146 lines
3.1 KiB
JavaScript
import './style.scss';
|
|
|
|
export default new Class({
|
|
Extends: Hedera.Form,
|
|
Template: require('./ui.xml'),
|
|
|
|
async open() {
|
|
const isOk = await Hedera.BasketChecker.check(this.conn, this.hash);
|
|
if (isOk) await Hedera.Form.prototype.open.call(this);
|
|
},
|
|
|
|
onOrderReady(form) {
|
|
if (form.row < 0)
|
|
return;
|
|
|
|
if (form.$.method != 'PICKUP') {
|
|
Vn.Node.show(this.$.address);
|
|
Vn.Node.setText(this.$.method, _('Agency'));
|
|
} else {
|
|
Vn.Node.hide(this.$.address);
|
|
Vn.Node.setText(this.$.method, _('Warehouse'));
|
|
}
|
|
|
|
var total = form.$.taxableBase + form.$.tax;
|
|
|
|
if (total === null)
|
|
total = 0;
|
|
|
|
var credit = form.$.credit;
|
|
var debt = form.$.debt;
|
|
|
|
var totalDebt = debt + total;
|
|
var exceededCredit = totalDebt - credit;
|
|
var creditExceededCond = exceededCredit > 0;
|
|
|
|
if (creditExceededCond)
|
|
Htk.Toast.showWarning(
|
|
_('You have exceeded your credit.'));
|
|
|
|
this.$.debt.value = debt;
|
|
this.$.totalDebt.value = totalDebt;
|
|
this.$.totalAmount.value = totalDebt;
|
|
this.$.creditExcess.value = exceededCredit;
|
|
this.$.excessAmount.value = exceededCredit;
|
|
|
|
this.$.payAmount.value = 'ALL';
|
|
|
|
if (credit > 0) {
|
|
this.$.creditInfo.style.display = 'table-row';
|
|
|
|
if (creditExceededCond) {
|
|
this.$.amountSelector.style.display = 'block';
|
|
this.$.exceededInfo.style.display = 'table-row';
|
|
this.$.payAmount.value = 'EXCEEDED';
|
|
}
|
|
}
|
|
|
|
var methods = [];
|
|
let selectedMethod;
|
|
|
|
if (totalDebt <= 0) {
|
|
methods = ['balance'];
|
|
selectedMethod = 'BALANCE';
|
|
} else {
|
|
methods = ['card', 'transfer', 'later'];
|
|
|
|
if (!creditExceededCond) {
|
|
methods.push('credit');
|
|
selectedMethod = 'CREDIT';
|
|
} else
|
|
selectedMethod = 'CARD';
|
|
}
|
|
|
|
for (var i = 0; i < methods.length; i++)
|
|
this.$[`${methods[i]}Method`].style.display = 'block';
|
|
|
|
this.$.payMethod.value = selectedMethod;
|
|
},
|
|
|
|
onPayMethodChange(payMethod) {
|
|
var id = this.displayedInfo;
|
|
|
|
if (id)
|
|
Vn.Node.removeClass(this.$[id], 'selected');
|
|
|
|
switch (payMethod.value) {
|
|
case 'BALANCE':
|
|
id = 'balanceMethod';
|
|
break;
|
|
case 'CREDIT':
|
|
id = 'creditMethod';
|
|
break;
|
|
case 'CARD':
|
|
id = 'cardMethod';
|
|
break;
|
|
case 'TRANSFER':
|
|
id = 'transferMethod';
|
|
break;
|
|
default:
|
|
id = null;
|
|
}
|
|
|
|
this.displayedInfo = id;
|
|
|
|
if (id)
|
|
Vn.Node.addClass(this.$[id], 'selected');
|
|
},
|
|
|
|
disableButtons(disable) {
|
|
this.$.modify.disabled = disable;
|
|
this.$.confirm.disabled = disable;
|
|
},
|
|
|
|
onModifyClick() {
|
|
window.history.back();
|
|
},
|
|
|
|
async onConfirmClick() {
|
|
this.disableButtons(true);
|
|
await this.$.confirmQuery.execute();
|
|
},
|
|
|
|
onConfirm(query, resultSet) {
|
|
this.disableButtons(false);
|
|
|
|
if (resultSet.fetchResult())
|
|
this.$.successDialog.show();
|
|
},
|
|
|
|
async onDialogResponse() {
|
|
if (this.$.payMethod.value === 'CARD') {
|
|
if (this.$.payAmount.value === 'EXCEEDED')
|
|
var payAmount = this.$.excessAmount.value;
|
|
else
|
|
var payAmount = this.$.totalAmount.value;
|
|
|
|
var tpv = new Hedera.Tpv({
|
|
conn: this.conn,
|
|
hash: this.hash
|
|
});
|
|
await tpv.pay(payAmount, this.$.order.companyFk);
|
|
} else
|
|
this.hash.setAll({form: 'ecomerce/orders'});
|
|
}
|
|
});
|