Hedera.Ticket = new Class
({
	Extends: Hedera.Form

	,onTicketChange: function (ticket)
	{
		if (!ticket.value)
			return;

		var params = {ticket: ticket.value};
		this.conn.execQuery ('CALL myTicketLogAccess (#ticket)', params);
	}

	,onTicketReady: function (form)
	{
		if (form.get ('method') != 'PICKUP')
			Vn.Node.setText (this.$('method'), _('Agency'));
		else
			Vn.Node.setText (this.$('method'), _('Warehouse'));
	}

	,onPrintClick: function ()
	{
		var params = {ticket: this.hash.get ('ticket')};
		this.gui.openReport ('delivery-note', params);
	}
	
	,subtotalRenderer: function (column, form)
	{
		column.value = this.subtotal (form);
	}
	
	,repeaterFunc: function (scope, form)
	{
		scope.$.subtotal.value = this.subtotal (form);
	}

	,subtotal: function (form)
	{
		var row = form.$;
		return row.quantity * row.price * ((100 - row.discount) / 100);
	}

	,onPackagesChanged: function (model)
	{
		this.$.packages.node.style.display =
			model.numRows > 0 ? 'block' : 'none';
	}
});