Hedera.Confirm = new Class ({ Extends: Hedera.Form ,open: function () { this.close (); this.isOpen = true; Hedera.BasketChecker.check (this.conn, this.hash, this.onBasketCheck.bind (this)); } ,onBasketCheck: function (isOk) { if (isOk) this.loadUi (); } ,onOrderReady: function (form) { if (form.row < 0) return; if (form.get ('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.get ('tax_base') + form.get ('vat'); if (total === null) total = 0; var credit = form.get ('credit'); var debt = form.get ('debt'); var totalDebt = debt + total; var exceededCredit = totalDebt - credit; var creditExceededCond = exceededCredit > 0; if (creditExceededCond) Htk.Toast.showWarning ( _('You have exceeded your credit.')); this.$('lot').assign ({ debt: debt, totalDebt: totalDebt, totalAmount: totalDebt, creditExcess: exceededCredit, excessAmount: exceededCredit, payAmount: 'ALL' }); this.$('pay-amount').value = 'ALL'; if (credit > 0) { this.$('credit-info').style.display = 'table-row'; if (creditExceededCond) { this.$('amount-selector').style.display = 'block'; this.$('exceeded-info').style.display = 'table-row'; lot.assign ({payAmount: 'EXCEEDED'}); } } var methods = []; 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'; lot.assign ({payAmount: selectedMethod}); } ,onPayMethodChange: function (payMethod) { var id = this.displayedInfo; if (id) Vn.Node.removeClass (this.$(id), 'selected'); switch (payMethod.value) { case 'BALANCE': id = 'balance-method'; break; case 'CREDIT': id = 'credit-method'; break; case 'CARD': id = 'card-method'; break; case 'TRANSFER': id = 'transfer-method'; break; default: id = null; } this.displayedInfo = id; if (id) Vn.Node.addClass (this.$(id), 'selected'); } ,disableButtons: function (disable) { this.$('modify').disabled = disable; this.$('confirm').disabled = disable; } ,onModifyClick: function () { window.history.back(); } ,onConfirmClick: function () { this.disableButtons (true); this.$('confirm-query').execute (); } ,onConfirm: function (query, resultSet) { this.disableButtons (false); if (resultSet.fetchResult ()) { Vn.Cookie.unset ('order'); this.$('success-dialog').show (); } } ,onDialogResponse: function () { if (this.$('pay-method').value === 'CARD') { if (this.$('pay-amount').value === 'EXCEEDED') var payAmount = this.$('excess-amount').value; else var payAmount = this.$('total-amount').value; var tpv = new Hedera.Tpv ({ conn: this.conn, hash: this.hash }); tpv.pay (payAmount, this.$('order-form').get ('company_id')); } else this.hash.setAll ({'form': 'ecomerce/orders'}); } });