Merge branch 'feature/02ad0e-improve-main-overview' into development (closes: #02ad0e)

This commit is contained in:
Paul van Tilburg 2014-11-01 18:10:09 +01:00
commit 8314996c09
1 changed files with 21 additions and 3 deletions

View File

@ -222,6 +222,12 @@ module StopTime::Models
def unbilled_tasks def unbilled_tasks
tasks.where("invoice_id IS NULL").order("name ASC") tasks.where("invoice_id IS NULL").order("name ASC")
end end
# Returns a list of tasks that are active, i.e. that have not been
# billed and are either fixed cost or have some registered time.
def active_tasks
unbilled_tasks.select { |task| task.fixed_cost? or task.time_entries.present? }
end
end end
# == The task class # == The task class
@ -753,10 +759,17 @@ module StopTime::Controllers
# Views#overview. # Views#overview.
def get def get
@tasks = {} @tasks = {}
@tasks_summary = {}
@task_count = 0 @task_count = 0
Customer.all.each do |customer| Customer.all.each do |customer|
tasks = customer.unbilled_tasks.sort_by { |t| t.name } tasks = customer.active_tasks
@tasks[customer] = tasks @tasks[customer] = tasks
@tasks_summary[customer] = tasks.inject([0.0, 0.0]) do |summ, task|
task_summ = task.summary
summ[0] += task_summ[0]
summ[1] += task_summ[2]
summ
end
@task_count += tasks.count @task_count += tasks.count
end end
render :overview render :overview
@ -1578,8 +1591,8 @@ module StopTime::Views
end end
else else
div.row do div.row do
div.span6 do @tasks.keys.sort_by { |c| c.name }.each do |customer|
@tasks.keys.sort_by { |c| c.name }.each do |customer| div.span6 do
inv_klass = "text_info" inv_klass = "text_info"
inv_klass = "text_warning" if customer.invoices.any? { |inv| inv.past_due? } inv_klass = "text_warning" if customer.invoices.any? { |inv| inv.past_due? }
inv_klass = "text_error" if customer.invoices.any? { |inv| inv.way_past_due? } inv_klass = "text_error" if customer.invoices.any? { |inv| inv.way_past_due? }
@ -1608,6 +1621,11 @@ module StopTime::Views
td.text_right { "€ %.2f" % summary[2] } td.text_right { "€ %.2f" % summary[2] }
end end
end end
tr do
td { b "Total" }
td.text_right { "%.2fh" % @tasks_summary[customer][0] }
td.text_right { "€ %.2f" % @tasks_summary[customer][1] }
end
end end
end end
end end