From c7d32e86115830e3a494c1d60e69122ea5e65c6a Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 2 Dec 2011 22:15:58 +0100 Subject: [PATCH 1/6] Added an invoice comment field to the task to store what the comment was --- stoptime.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index aa22496..c2a8154 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -113,6 +113,7 @@ module StopTime::Models # [name] description (String) # [fixed_cost] fixed cost of the task (Float) # [hourly_rate] hourly rate for the task (Float) + # [invoice_comment] extra comment for the invoice (String) # [created_at] time of creation (Time) # [updated_at] time of last update (Time) # @@ -447,6 +448,16 @@ module StopTime::Models end end + class InvoiceCommentsSupport < V 1.91 # :nodoc: + def self.up + add_column(Task.table_name, :invoice_comment, :string) + end + + def self.down + remove_column(Task.table_name, :invoice_comment) + end + end + end # StopTime::Models # = The Stop… Camping Time! controllers From e4202b80485fe7c9c870f6c846471fe89e98662f Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 2 Dec 2011 22:16:27 +0100 Subject: [PATCH 2/6] Added Task#comment_or_name to return the comment if set and the task is billed --- stoptime.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index c2a8154..ad4d327 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -184,6 +184,16 @@ module StopTime::Models end end end + + # Returns an invoice comment if the task is billed and if it is + # set, otherwise the name. + def comment_or_name + if billed? and self.invoice_comment.present? + self.invoice_comment + else + self.name + end + end end # == The time entry class From e53374a713ab66a7a4800965875b934474191510 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 2 Dec 2011 22:17:27 +0100 Subject: [PATCH 3/6] Changed Invoice#summary to use the task as the key, not just its name --- stoptime.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index ad4d327..755baff 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -249,15 +249,16 @@ module StopTime::Models has_many :time_entries, :through => :tasks belongs_to :customer - # Returns a a time and cost summary of the contained tasks. - # See also Task#summary. + # Returns a time and cost summary of the contained tasks (Hash of + # Task to Array). + # See also Task#summary for the specification of the array. def summary summ = {} - tasks.each { |task| summ[task.name] = task.summary } + tasks.each { |task| summ[task] = task.summary } return summ end - # Returns the invoice period based on the contained tasks. + # Returns the invoice period based on the contained tasks (Array of Time). # See also Task#bill_period. def period # FIXME: maybe should be updated_at? From 194b0033d10e006081a574ef1a5a0b70991094b8 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 2 Dec 2011 22:18:55 +0100 Subject: [PATCH 4/6] Changed invoice_select_form and CustomersNInvoicesX to actually set task invoice comments --- stoptime.rb | 31 +++++++++++++++++++++++-------- templates/sass/style.sass | 3 +++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index 755baff..b508239 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -786,13 +786,17 @@ module StopTime::Controllers task.time_entries = task.time_entries - tasks[task] task.save bill_task.time_entries = tasks[task] + bill_task.invoice_comment = @input["task_#{task.id}_comment"] bill_task.save invoice.tasks << bill_task end # Then, handle the fixed cost tasks. @input["tasks"].each do |task| - invoice.tasks << Task.find(task) + task = Task.find(task) + task.invoice_comment = @input["task_#{task.id}_comment"] + task.save + invoice.tasks << task end unless @input["tasks"].blank? invoice.save @@ -1603,9 +1607,10 @@ module StopTime::Views # Form for selecting fixed cost tasks and registered time for tasks with # an hourly rate that need to be billed. def invoice_select_form + h2 "Registered Time" form :action => R(CustomersNInvoices, @customer.id), :method => :post do + h3 "Projects/Tasks with an Hourly Rate" unless @hourly_rate_tasks.empty? - h2 "Registered Time" table.invoice_select do col.flag {} col.date {} @@ -1626,11 +1631,15 @@ module StopTime::Views @hourly_rate_tasks.keys.each do |task| tr.task do td { _form_input_checkbox("tasks[]", task.id) } - td task.name, :colspan => 6 + td task.name, :colspan => 3 + td do + input :type => :text, :name => "task_#{task.id}_comment", + :id => "tasks_#{task.id}_comment", :value => task.name + end end @hourly_rate_tasks[task].each do |entry| tr do - td { _form_input_checkbox("time_entries[]", entry.id) } + td.indent { _form_input_checkbox("time_entries[]", entry.id) } td { label entry.date.to_date, :for => "time_entries[]_#{entry.id}" } td { entry.start.to_formatted_s(:time_only) } @@ -1645,22 +1654,28 @@ module StopTime::Views end unless @fixed_cost_tasks.empty? - h2 "Fixed Cost Projects/Tasks" + h3 "Fixed Cost Projects/Tasks" table.tasks do col.flag {} col.task {} + col.comment {} col.hours {} col.amount {} tr do - th "" + th "Bill?" th "Project/Task" - th "Registered time" - th "Amount" + th "Comment" + th.right "Registered time" + th.right "Amount" end @fixed_cost_tasks.keys.each do |task| tr do td { _form_input_checkbox("tasks[]", task.id) } td { label task.name, :for => "tasks[]_#{task.id}" } + td do + input :type => :text, :name => "task_#{task.id}_comment", + :id => "tasks_#{task.id}_comment", :value => task.name + end td.right { "%.2fh" % @fixed_cost_tasks[task] } td.right { task.fixed_cost } end diff --git a/templates/sass/style.sass b/templates/sass/style.sass index 0e73e31..cc7614b 100644 --- a/templates/sass/style.sass +++ b/templates/sass/style.sass @@ -21,6 +21,9 @@ $dark-red: #990000 .billed text-decoration: line-through +.indent + padding-left: 20px + /* Basic elements */ a text-decoration: none From f40b429d10838bb634bba40c16d811f49aee8957 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 2 Dec 2011 22:20:21 +0100 Subject: [PATCH 5/6] Adapted the invoice view to show the task invoice comment --- stoptime.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index b508239..e84b63a 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1211,18 +1211,18 @@ module StopTime::Views col.hours {} col.amount {} tr do + summary = task.summary td do - a task.name, + a summary[0].present ? summary[0] : task.name, :href => R(CustomersNTasksN, customer.id, task.id) end - summary = task.summary case task.type when "fixed_rate" td "" - td.right { "€ %.2f" % summary[2] } + td.right { "€ %.2f" % summary[3] } when "hourly_rate" - td.right { "%.2fh" % summary[0] } - td.right { "€ %.2f" % summary[2] } + td.right { "%.2fh" % summary[1] } + td.right { "€ %.2f" % summary[3] } end end end @@ -1561,8 +1561,8 @@ module StopTime::Views subtotal = 0.0 @tasks.each do |task, line| tr do - td { task } - if line[0].nil? and line[1].nil? + td { task.comment_or_name } + if line[1].nil? td.right "–" td.right "–" else From 351753b422b6c1d3c3da7d8b6d880d10b437f77d Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 2 Dec 2011 22:21:53 +0100 Subject: [PATCH 6/6] Adapt the invoice (PDF) template to show the task invoice comments --- templates/invoice.tex.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/invoice.tex.erb b/templates/invoice.tex.erb index 7cab371..248d843 100644 --- a/templates/invoice.tex.erb +++ b/templates/invoice.tex.erb @@ -91,11 +91,11 @@ \begin{ihtable} <% subtotal = 0.0 @tasks.each do |task, line| - if line[0].nil? and line[1].nil? -%> \ifcitem{<%= task %>}% + if line[2].nil? +%> \ifcitem{<%= task.comment_or_name %>}% {<%= number_with_precision(line[2]) %>}<% else -%> \ihitem{<%= task %>}% +%> \ihitem{<%= task.comment_or_name %>}% {<%= number_with_precision(line[0]) %>}{<%= number_with_precision(line[1]) %>}% {<%= number_with_precision(line[2]) %>}<% end