From ee58b00d2c186ddadd6a216a474a01abdcfc9ae4 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Wed, 9 Nov 2011 14:07:03 +0100 Subject: [PATCH] Added support for not adding VAT in views and template. --- stoptime.rb | 30 +++++++++++++++++------------- templates/invoice.tex.erb | 29 ++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/stoptime.rb b/stoptime.rb index 490b349..5702f85 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -35,7 +35,7 @@ unless defined? PUBLIC_DIR # FIXME: this should be configurable. HourlyRate = 20.0 - VATRate = 19.0 + VATRate = 0.0 end module StopTime @@ -872,18 +872,22 @@ module StopTime::Views end subtotal += line[2] end - tr do - td { i "Sub-total" } - td "" - td "" - td { "€ %.2f" % subtotal } - end - vat = subtotal * VATRate/100 - tr do - td { i "VAT #{VATRate}%" } - td "" - td "" - td { "€ %.2f" % vat } + if VATRate.zero? + vat = 0 + else + tr do + td { i "Sub-total" } + td "" + td "" + td { "€ %.2f" % subtotal } + end + vat = subtotal * VATRate/100 + tr do + td { i "VAT #{VATRate}%" } + td "" + td "" + td { "€ %.2f" % vat } + end end tr do td { b "Total amount" } diff --git a/templates/invoice.tex.erb b/templates/invoice.tex.erb index a75b607..c47f54f 100644 --- a/templates/invoice.tex.erb +++ b/templates/invoice.tex.erb @@ -82,17 +82,28 @@ \invoice{ \hypersetup{pdftitle=\invoicetext\ naar\ \toname\ gedateerd \date\ (\ourref)} + % FIXME: localise the dot/comma stuff in numbers. \begin{ihtable} - <% subtotal = 0.0 %> - <% tasks.each do |task, line| %> - \ihitem{<%= task.name %>}{<%= "%.2f" % line[0] %>}% - {<%= "%.2f" % line[1] %>}{<%= "%.2f" % line[2] %>} - <% subtotal += line[2] %> - <% end %> +<% subtotal = 0.0 + @tasks.each do |task, line| + if line[0].nil? and line[1].nil? +%> \ifcitem{<%= task %>}% + {<%= "%.2f" % line[2] %>}<% + else +%> \ihitem{<%= task %>}% + {<%= "%.2f" % line[0] %>}{<%= "%.2f" % line[1] %>}% + {<%= "%.2f" % line[2] %>}<% + end + subtotal += line[2] + end + if VATRate.zero? + vat = 0 %> + \ihnosubtotal{} <% + else + vat = subtotal * VATRate/100 %> \ihsubtotal{<%= "%.2f" % subtotal %>} - %\inosubtotal - <% vat = subtotal * VATRate/100 %> - \ihvat{<%= "%.2f" % vat %>} + \ihvat{<%= "%.2f" % vat %>} <% + end %> \ihtotal{<%= "%.2f" % (subtotal + vat) %>} \end{ihtable} \vspace{2em}