
Vn.Orders = new Class
({
	Extends: Vn.Module

	,activate: function ()
	{
		this.payPopup = new Htk.Popup ();
		this.payPopup.setChildNode (this.$('balance-popup'));

		Vn.Tpv.check (this.conn);
	}

	,onBasketClick: function ()
	{
		this.hash.set ({'form': 'ecomerce/basket'});
	}

	,onShowClick: function  (column, ticketId)
	{
		this.hash.set ({
			'form': 'ecomerce/ticket',
			'ticket': ticketId
		});
	}

	// TPV
	
	,balanceConditionalFunc: function (field, value)
	{
		var className = 'balance-amount ';
	
		if (value > 0)
			className += 'positive-balance';
		else
			className += 'negative-balance';
			
		field.node.className = className;
	}
	
	,onPayButtonClick: function ()
	{
		this.payPopup.show (this.$('pay-button'));
	}
	
	,onCompanyPayClick: function (column, value, row)
	{
		var model = this.$('balance');
		var company = model.get (row, 'id');
		var amount = model.get (row, 'amount');

		amount = amount <= 0 ? null : amount;

		var defaultAmountStr = '';
		
		if (amount !== null)
			defaultAmountStr = Vn.Value.format (amount, '%.2d');

		var amount = parseFloat (prompt (_('AmountToPay:'), defaultAmountStr));
	
		Vn.Tpv.pay (this.conn, amount, company);
	}
});

