Class: YDIM::Html::View::InvoiceList

Inherits:
HtmlGrid::List show all
Defined in:
lib/ydim/html/view/invoices.rb

Direct Known Subclasses

AutoInvoiceList

Constant Summary collapse

COMPONENTS =
{
	[0,0]		=>	:unique_id,
	[1,0]		=>	:name,
	[2,0]		=>	:email,
	[3,0]		=>	:description,
	[4,0]		=>	:formatted_date,
	[5,0]		=>	:toggle_payment_received,
	[6,0]		=>	:total_netto,
	[7,0]		=>	:total_brutto,
	[8,0]		=>	:currency,
	[9,0]		=>	:send_invoice,
	[10,0]	=>	:pdf,
	[11,0]	=>	:toggle_deleted,
}
CSS_ID =
'invoices'
CSS_MAP =
{
	[6,0,2]	=>	'right',
}
SORT_DEFAULT =
nil

Constants inherited from HtmlGrid::List

HtmlGrid::List::STRIPED_BG

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HtmlGrid::List

ajax_inputs

Class Method Details



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ydim/html/view/invoices.rb', line 31

def debitor_links(*names)
	names.each { |name|
		define_method(name) { |model|
			link = HtmlGrid::Link.new(name, model, @session, self)
			link.href = @lookandfeel._event_url(:debitor, 
																					{:unique_id => model.debitor_id})
			str = model.send("debitor_#{name}").to_s
			if(str.length > 30)
				str = str[0,27] << '...'
			end
			link.value = str
			link
		}
	}
end

.toggle(name, on, off) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ydim/html/view/invoices.rb', line 46

def toggle(name, on, off)
	define_method("toggle_#{name}") { |model|
		current = model.send(name)
		key = current ? off : on
		link = HtmlGrid::Link.new(key, model, @session, self)
		args = {
			:unique_id				=>	model.unique_id,
			name							=>	!current,
		}
		url = @lookandfeel._event_url("ajax_#{css_id}", args)
		link.href = "javascript: reload_list('#{css_id}', '#{url}')"
		link
	}
end

Instance Method Details

#column_position(key, offset) ⇒ Object



100
101
102
103
# File 'lib/ydim/html/view/invoices.rb', line 100

def column_position(key, offset)
	pos = components.index(key)
	[pos.at(0) + offset.at(0), pos.at(1) + offset.at(1)]
end


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ydim/html/view/invoices.rb', line 69

def compose_footer(offset)
	garbage = false
	netto = 0.0
	brutto = 0.0
	total = @model.each { |invoice|
		garbage = true if(invoice.deleted)
		netto += invoice.total_netto
		brutto += invoice.total_brutto
	}
	if(garbage)
		button = HtmlGrid::Button.new(:collect_garbage, @model, @session, self)
		url = @lookandfeel._event_url(:ajax_collect_garbage)
		button.set_attribute('onClick', "reload_list('invoices', '#{url}');")
		@grid.add(button, *offset)
		@grid.set_colspan(*offset)
	else
		label = HtmlGrid::LabelText.new(:total, @model, @session, self)
		lpos = column_position(:name, offset)
		@grid.add(label, *lpos)
		@grid.set_colspan(*lpos.push(2))
		total(:total_netto, netto, offset)
		total(:total_brutto, brutto, offset)
		lpos = column_position(:currency, offset)
		@grid.add(Html.config.currency, *lpos)
	end
end

#formatted_date(model) ⇒ Object



104
105
106
107
108
109
110
# File 'lib/ydim/html/view/invoices.rb', line 104

def formatted_date(model)
	if(date = model.date)
		link = date(model)
		link.value = @lookandfeel.format_date(date)
		link
	end
end

#pdf(model) ⇒ Object



111
112
113
114
115
# File 'lib/ydim/html/view/invoices.rb', line 111

def pdf(model)
	link = HtmlGrid::Link.new(:pdf, model, @session, self)
	link.href = @lookandfeel._event_url(:pdf, {:unique_id => model.unique_id})
	link
end

#row_css(model, bg_flag) ⇒ Object



66
67
68
# File 'lib/ydim/html/view/invoices.rb', line 66

def row_css(model, bg_flag)
   [super, model.status].compact.join(' ')
end

#send_invoice(model) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/ydim/html/view/invoices.rb', line 116

def send_invoice(model)
	if(model.status == 'is_due')
		link = HtmlGrid::Link.new(:send_invoice, model, @session, self)
		link.href = @lookandfeel._event_url(:send_invoice, 
																				{:unique_id => model.unique_id})
		link
	end
end

#total(key, total, offset) ⇒ Object



95
96
97
98
99
# File 'lib/ydim/html/view/invoices.rb', line 95

def total(key, total, offset)
	tpos = column_position(key, offset)
	@grid.add(number_format(format(total)), *tpos)
	@grid.add_attribute('class', 'right total', *tpos)
end