2015-07-07 15:27:47 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
Hedera.Confirm = new Class
|
2015-07-07 15:27:47 +00:00
|
|
|
({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Hedera.Form
|
2015-12-10 13:48:43 +00:00
|
|
|
|
|
|
|
,open: function ()
|
|
|
|
{
|
|
|
|
this.close ();
|
|
|
|
this.isOpen = true;
|
|
|
|
|
2017-04-05 14:06:07 +00:00
|
|
|
Hedera.BasketChecker.check (this.conn, this.hash,
|
2015-12-10 13:48:43 +00:00
|
|
|
this.onBasketCheck.bind (this));
|
|
|
|
}
|
|
|
|
|
|
|
|
,onBasketCheck: function (isOk)
|
|
|
|
{
|
|
|
|
if (isOk)
|
|
|
|
this.loadUi ();
|
|
|
|
}
|
2015-07-07 15:27:47 +00:00
|
|
|
|
2015-07-17 14:34:42 +00:00
|
|
|
,onOrderReady: function (form)
|
|
|
|
{
|
|
|
|
if (form.row < 0)
|
|
|
|
return;
|
2017-04-08 11:42:27 +00:00
|
|
|
|
|
|
|
var order = form.params;
|
2015-07-17 14:34:42 +00:00
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
if (order.method != 'PICKUP')
|
2015-07-17 14:34:42 +00:00
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
Vn.Node.show (this.$('address'));
|
2015-07-17 14:34:42 +00:00
|
|
|
Vn.Node.setText (this.$('method'), _('Agency'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
Vn.Node.hide (this.$('address'));
|
2015-07-17 14:34:42 +00:00
|
|
|
Vn.Node.setText (this.$('method'), _('Warehouse'));
|
|
|
|
}
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
var total = order.taxBase + order.vat;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
|
|
|
if (total === null)
|
|
|
|
total = 0;
|
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
var totalDebt = order.debt + total;
|
|
|
|
var exceededCredit = totalDebt - order.credit;
|
2016-01-15 12:31:08 +00:00
|
|
|
var creditExceededCond = exceededCredit > 0;
|
|
|
|
|
|
|
|
if (creditExceededCond)
|
|
|
|
Htk.Toast.showWarning (
|
|
|
|
_('You have exceeded your credit.'));
|
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
var lot = {
|
2017-04-07 11:00:33 +00:00
|
|
|
totalDebt: totalDebt,
|
2017-04-08 11:42:27 +00:00
|
|
|
exceededCredit: exceededCredit,
|
2017-04-07 11:00:33 +00:00
|
|
|
payAmount: 'ALL'
|
2017-04-08 11:42:27 +00:00
|
|
|
};
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
if (order.credit > 0)
|
2016-01-15 12:31:08 +00:00
|
|
|
{
|
|
|
|
this.$('credit-info').style.display = 'table-row';
|
|
|
|
|
|
|
|
if (creditExceededCond)
|
|
|
|
{
|
|
|
|
this.$('amount-selector').style.display = 'block';
|
|
|
|
this.$('exceeded-info').style.display = 'table-row';
|
2017-04-08 11:42:27 +00:00
|
|
|
lot.payAmount = 'EXCEEDED';
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var methods = [];
|
|
|
|
|
|
|
|
if (totalDebt <= 0)
|
|
|
|
{
|
|
|
|
methods = ['balance'];
|
2017-04-08 11:42:27 +00:00
|
|
|
lot.payMethod = 'BALANCE';
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
methods = ['card', 'transfer', 'later'];
|
|
|
|
|
|
|
|
if (!creditExceededCond)
|
|
|
|
{
|
|
|
|
methods.push ('credit');
|
2017-04-08 11:42:27 +00:00
|
|
|
lot.payMethod = 'CREDIT';
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
else
|
2017-04-08 11:42:27 +00:00
|
|
|
lot.payMethod = 'CARD';
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < methods.length; i++)
|
|
|
|
this.$(methods[i] +'-method').style.display = 'block';
|
2017-04-08 11:42:27 +00:00
|
|
|
|
|
|
|
this.$('lot').assign (lot);
|
2015-07-17 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 12:31:08 +00:00
|
|
|
,onPayMethodChange: function (payMethod)
|
2015-07-07 15:27:47 +00:00
|
|
|
{
|
2016-01-15 12:31:08 +00:00
|
|
|
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');
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,disableButtons: function (disable)
|
|
|
|
{
|
|
|
|
this.$('modify').disabled = disable;
|
|
|
|
this.$('confirm').disabled = disable;
|
|
|
|
}
|
|
|
|
|
|
|
|
,onModifyClick: function ()
|
|
|
|
{
|
|
|
|
window.history.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
,onConfirmClick: function ()
|
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
console.log (this.$('lot').params);
|
2015-08-17 18:02:14 +00:00
|
|
|
this.disableButtons (true);
|
2015-07-17 14:34:42 +00:00
|
|
|
this.$('confirm-query').execute ();
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 14:34:42 +00:00
|
|
|
,onConfirm: function (query, resultSet)
|
2015-07-07 15:27:47 +00:00
|
|
|
{
|
2015-12-15 15:22:46 +00:00
|
|
|
this.disableButtons (false);
|
|
|
|
|
2016-01-15 12:31:08 +00:00
|
|
|
if (resultSet.fetchResult ())
|
2015-12-15 15:22:46 +00:00
|
|
|
this.$('success-dialog').show ();
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
2016-10-20 08:37:08 +00:00
|
|
|
|
|
|
|
,onDialogResponse: function ()
|
2015-12-15 15:22:46 +00:00
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
var lot = this.$('lot').params;
|
|
|
|
|
2016-01-15 12:31:08 +00:00
|
|
|
if (this.$('pay-method').value === 'CARD')
|
|
|
|
{
|
|
|
|
if (this.$('pay-amount').value === 'EXCEEDED')
|
2017-04-08 11:42:27 +00:00
|
|
|
var payAmount = lot.exceededCredit;
|
2016-01-15 12:31:08 +00:00
|
|
|
else
|
2017-04-08 11:42:27 +00:00
|
|
|
var payAmount = lot.totalDebt;
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2017-04-05 14:06:07 +00:00
|
|
|
var tpv = new Hedera.Tpv ({
|
|
|
|
conn: this.conn,
|
|
|
|
hash: this.hash
|
|
|
|
});
|
2017-04-08 11:42:27 +00:00
|
|
|
tpv.pay (payAmount, this.$('order').get ('company'));
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
2015-07-07 15:27:47 +00:00
|
|
|
else
|
2017-04-08 11:42:27 +00:00
|
|
|
this.hash.params = {form: 'ecomerce/orders'};
|
2015-07-07 15:27:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|