From 2e5985b32b0ca9f112ff1b0aae2f02ae096d53a6 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sat, 8 Nov 2014 12:06:19 +0100 Subject: [PATCH 1/5] Discern customer tasks and active tasks --- stoptime.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index 3324fc2..c51a9c1 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -895,18 +895,22 @@ module StopTime::Controllers # {Views#overview}. def get @tasks = {} - @tasks_summary = {} @task_count = 0 + @active_tasks = {} + @active_tasks_summary = {} Customer.all.each do |customer| - tasks = customer.active_tasks + tasks = customer.unbilled_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 + active_tasks = customer.active_tasks + @active_tasks[customer] = active_tasks + @active_tasks_summary[customer] = + active_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 end render :overview end @@ -1789,7 +1793,7 @@ module StopTime::Views col.task col.hours col.amount - @tasks[customer].each do |task| + @active_tasks[customer].each do |task| tr do summary = task.summary td do @@ -1803,8 +1807,8 @@ module StopTime::Views end tr do td { b "Total" } - td.text_right { "%.2fh" % @tasks_summary[customer][0] } - td.text_right { "€ %.2f" % @tasks_summary[customer][1] } + td.text_right { "%.2fh" % @active_tasks_summary[customer][0] } + td.text_right { "€ %.2f" % @active_tasks_summary[customer][1] } end end end From 4cf1517b438f16ed0344ef09a72b703d33c25fda Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sat, 8 Nov 2014 12:06:33 +0100 Subject: [PATCH 2/5] Show message if there are tasks but no active tasks Show links to the task form of each of these tasks so that time can be registered there. --- stoptime.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index c51a9c1..332b961 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1788,6 +1788,16 @@ module StopTime::Views text! "No projects/tasks found! Create one " + "#{a "here", :href => R(CustomersNTasksNew, customer.id)}." end + elsif @active_tasks[customer].empty? + p do + text! "No active projects/tasks found! " + + "Register time on one of these tasks: " + br + @tasks[customer].each do |task| + a task.name, :href => R(CustomersNTasksN, customer.id, task.id) + text! "·" unless task == @tasks[customer].last + end + end else table.table.table_condensed do col.task From ac551fcf7a037e7f5d9af6ec3169effcb13d5672 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 5 Jun 2015 22:26:59 +0200 Subject: [PATCH 3/5] Add helper method for LaTeX-escaping strings in ERB --- stoptime.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index 332b961..b16a9d6 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1386,6 +1386,27 @@ module StopTime::Controllers # private + # Escapes the given string such that it can be used as in in + # LaTeX. + # + # @param [String] string the given string + def _escape_latex(string) + escape_chars = { '#' => '\#', + '$' => '\$', + '%' => '\%', + '&' => '\&', + '\\' => '\textbackslash{}', + '^' => '\textasciicircum{}', + '_' => '\_', + '{' => '\{', + '}' => '\}', + '~' => '\textasciitilde{}' } + regexp_str = escape_chars.keys.map { |c| Regexp.escape(c) }.join('|') + regexp = Regexp.new(regexp_str) + string.to_s.gsub(regexp, escape_chars) + end + alias_method :l, :_escape_latex + # Generates a LaTex document for the invoice with the given number. # # @param [Fixnum] number number of the invoice From 15b91d98ae45b15795194f0db264925fcc1e5292 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 5 Jun 2015 22:30:02 +0200 Subject: [PATCH 4/5] Escape strings in the invoice template --- templates/invoice.tex.erb | 80 +++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/templates/invoice.tex.erb b/templates/invoice.tex.erb index 7c7b515..38eaa04 100644 --- a/templates/invoice.tex.erb +++ b/templates/invoice.tex.erb @@ -1,6 +1,6 @@ \documentclass[a4paper,oneside,dutch]{isodoc} -% rubber: clean <%= @number %>.out +% rubber: clean <%=l @number %>.out \usepackage{array} \usepackage[utf8]{inputenc} @@ -10,13 +10,13 @@ dutch, fill, %% Company info. - company=<%= @company.name %>, - who=<%= @company.contact_name %>, - street=<%= @company.address_street %>, - zip=<%= @company.address_postal_code %>, - city=<%= @company.address_city %>, - country=<%= @company.country %>, - countrycode=<%= @company.country_code %>, + company=<%=l @company.name %>, + who=<%=l @company.contact_name %>, + street=<%=l @company.address_street %>, + zip=<%=l @company.address_postal_code %>, + city=<%=l @company.address_city %>, + country=<%=l @company.country %>, + countrycode=<%=l @company.country_code %>, logoaddress={\hspace{-4.4em} \begin{tabular}{l@{\ }l} <% if @company.name.blank? %> \addresstext: & \who\\ @@ -33,38 +33,38 @@ %% Footer. <% unless @company.website.blank? %> footer,<% end %> areacode=31, - phone=<%= @company.phone %>, - cellphone=<%= @company.cell %>, - email=<%= @company.email %>, - website=<%= @company.website %>, + phone=<%=l @company.phone %>, + cellphone=<%=l @company.cell %>, + email=<%=l @company.email %>, + website=<%=l @company.website %>, %% Addressee info. %foreign, - to={<%= @customer.name %>\\<% unless @customer.financial_contact.blank? -%><%= @customer.financial_contact -%>\\<% end %><%= @customer.address_street%>\\ - <%= @customer.address_postal_code %> <%= @customer.address_city %>}, + to={<%=l @customer.name %>\\<% unless @customer.financial_contact.blank? +%><%=l @customer.financial_contact +%>\\<% end %><%=l @customer.address_street%>\\ + <%=l @customer.address_postal_code %> <%=l @customer.address_city %>}, % Headlines. - date=<%= @invoice.created_at.to_formatted_s(:day_code) %>, - ourref=<%= @number %>, + date=<%=l @invoice.created_at.to_formatted_s(:day_code) %>, + ourref=<%=l @number %>, <% period = @period.map { |p| I18n.l p, :format => :month_and_year }.uniq case period.length - when 1 %> subject=Factuur <%= period.first %>,<% - when 2 %> subject=Factuur <%= period.join(" t/m ") %>,<% + when 1 %> subject=Factuur <%=l period.first %>,<% + when 2 %> subject=Factuur <%=l period.join(" t/m ") %>,<% end %> yourref=, %% Payment data. term=30, - accountname=<%= @company.accountname %>, -<% unless @company.accountiban.blank? %> iban=<%= @company.accountiban %>, -<% end %><% unless @company.bank_bic.blank? %> bic=<%= @company.bank_bic %>, -<% end %><% unless @company.vatno.blank? %> vatno=<%= @company.vatno %>, -<% end %><% unless @company.chamber.blank? %> chamber=<%= @company.chamber %> + accountname=<%=l @company.accountname %>, +<% unless @company.accountiban.blank? %> iban=<%=l @company.accountiban %>, +<% end %><% unless @company.bank_bic.blank? %> bic=<%=l @company.bank_bic %>, +<% end %><% unless @company.vatno.blank? %> vatno=<%=l @company.vatno %>, +<% end %><% unless @company.chamber.blank? %> chamber=<%=l @company.chamber %> <% end %>} \setlength{\parindent}{0pt} \setlength{\parskip}{\medskipamount} <% if @company.bank_name.present? %> -\renewcommand{\accountnotext}{<%= @company.bank_name %> rekeningnr} +\renewcommand{\accountnotext}{<%=l @company.bank_name %> rekeningnr} <% end %>\newcommand{\addresstext}{adres} \newcommand{\addresswhotext}{t.n.v.} \renewcommand{\chambertext}{KvK-nr} @@ -105,14 +105,14 @@ <% subtotal = 0.0 @tasks.each do |task, line| if line[1].blank? -%> \ifcitem{<%= task.comment_or_name %>}% - {<%= number_with_precision(line[0]) %>}% - {<%= number_with_precision(line[2]) %>} +%> \ifcitem{<%=l task.comment_or_name %>}% + {<%=l number_with_precision(line[0]) %>}% + {<%=l number_with_precision(line[2]) %>} <% else -%> \ihitem{<%= task.comment_or_name %>}% - {<%= number_with_precision(line[0]) %>}% - {<%= number_with_precision(line[1]) %>}% - {<%= number_with_precision(line[2]) %>} +%> \ihitem{<%=l task.comment_or_name %>}% + {<%=l number_with_precision(line[0]) %>}% + {<%=l number_with_precision(line[1]) %>}% + {<%=l number_with_precision(line[2]) %>} <% end subtotal += line[2] end @@ -120,13 +120,13 @@ if @company.vatno.blank? %> \ihnosubtotal{} <% else -%> \ihsubtotal{<%= number_with_precision(subtotal) %>}<% +%> \ihsubtotal{<%=l number_with_precision(subtotal) %>}<% @vat.keys.sort.each do |rate| vattotal += @vat[rate] %> - \ihvat{<%= "%d\\%%" % rate %>}{<%= number_with_precision(@vat[rate]) %>}<% + \ihvat{<%= "%d\\%%" % rate %>}{<%=l number_with_precision(@vat[rate]) %>}<% end end %> - \ihtotal{<%= number_with_precision(subtotal + vattotal) %>} + \ihtotal{<%=l number_with_precision(subtotal + vattotal) %>} \end{ihtable} \vspace{2em} @@ -148,11 +148,11 @@ \begin{istable} <% @invoice.tasks.each do |task| -%> \istask{<%= task.comment_or_name %>}<% +%> \istask{<%=l task.comment_or_name %>}<% task.time_entries.each do |time_entry| %> - \isitem{<%= time_entry.comment || "Geen opmerking" %>}% - {<%= time_entry.date.to_date %>}% - {<%= number_with_precision(time_entry.hours_total) %>}<% + \isitem{<%=l time_entry.comment || "Geen opmerking" %>}% + {<%=l time_entry.date.to_date %>}% + {<%=l number_with_precision(time_entry.hours_total) %>}<% end %>\\[\medskipamount]<% end %> \end{istable} From 9928fc6f2a997419e7ce8b2dd7bc13cfec29140e Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 5 Jun 2015 22:36:00 +0200 Subject: [PATCH 5/5] Bump version to 1.12 --- stoptime.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stoptime.rb b/stoptime.rb index b16a9d6..341f2a4 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -54,7 +54,7 @@ end module StopTime # The version of the application - VERSION = '1.10' + VERSION = '1.12' puts "Starting Stop… Camping Time! version #{VERSION}" # @return [Hash{String=>Object}] The parsed configuration.