From d1ac6ff9798f352ac96e01f60f4d4c48ae71fcc3 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sat, 1 Nov 2014 17:45:16 +0100 Subject: [PATCH 1/3] Show only active tasks in the overview view Active tasks are unbilled tasks that are tasks that are either fixed cost or that have time entries that should be billed. --- stoptime.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stoptime.rb b/stoptime.rb index 04873ee..063dbae 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -222,6 +222,12 @@ module StopTime::Models def unbilled_tasks tasks.where("invoice_id IS NULL").order("name ASC") 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 # == The task class @@ -755,7 +761,7 @@ module StopTime::Controllers @tasks = {} @task_count = 0 Customer.all.each do |customer| - tasks = customer.unbilled_tasks.sort_by { |t| t.name } + tasks = customer.active_tasks @tasks[customer] = tasks @task_count += tasks.count end From 35462ed0ddc64f88fee34e0ec3fb800757a482e2 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sat, 1 Nov 2014 17:47:13 +0100 Subject: [PATCH 2/3] Show a total of unbilled time and earned money (excl. VAT) per customer --- stoptime.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index 063dbae..379bb70 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -759,10 +759,17 @@ module StopTime::Controllers # Views#overview. def get @tasks = {} + @tasks_summary = {} @task_count = 0 Customer.all.each do |customer| tasks = customer.active_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 end render :overview @@ -1614,6 +1621,11 @@ module StopTime::Views td.text_right { "€ %.2f" % summary[2] } 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 From 49eb58ff51dd30f5fad8bdb715b241b4e0d58019 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sat, 1 Nov 2014 17:47:52 +0100 Subject: [PATCH 3/3] Build a span per customer so that they flow and use two columns in the overview --- stoptime.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index 379bb70..afad6aa 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1591,8 +1591,8 @@ module StopTime::Views end else 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_warning" if customer.invoices.any? { |inv| inv.past_due? } inv_klass = "text_error" if customer.invoices.any? { |inv| inv.way_past_due? }