diff --git a/stoptime.rb b/stoptime.rb index 55193af..2732803 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -1058,6 +1058,7 @@ module StopTime::Controllers @company = @invoice.company_info @tasks = @invoice.summary + @vat = @invoice.vat_summary @period = @invoice.period if @format == "html" @@ -1833,28 +1834,29 @@ module StopTime::Views end end unless task.fixed_cost? end - if @company.vatno.blank? - vat = 0 - else + vattotal = 0.0 + if @company.vatno.present? tr.total do td { i "Sub-total" } td "" td "" td.right { "€ %.2f" % subtotal } end - vat = subtotal * @config["vat_rate"]/100.0 - tr do - td { i "VAT %d%%" % @config["vat_rate"] } - td "" - td "" - td.right { "€ %.2f" % vat } + @vat.keys.sort.each do |rate| + vattotal += @vat[rate] + tr do + td { i "VAT %d%%" % rate } + td "" + td "" + td.right { "€ %.2f" % @vat[rate] } + end end end tr.total do td { b "Total" } td "" td "" - td.right { "€ %.2f" % (subtotal + vat) } + td.right { "€ %.2f" % (subtotal + vattotal) } end end diff --git a/templates/invoice.tex.erb b/templates/invoice.tex.erb index aaed31b..cdc2692 100644 --- a/templates/invoice.tex.erb +++ b/templates/invoice.tex.erb @@ -84,7 +84,7 @@ \newcommand{\ihsubtotal}[1]{\cmidrule[.0em]{4-4}% \textit{Subtotaal}&&&\currency~#1\\} \newcommand{\ihnosubtotal}[1]{\cmidrule[.0em]{4-4}&&&\\} -\newcommand{\ihvat}[1]{\textit{Btw-heffing <%= "%d\\%%" % @config["vat_rate"] %>}&&&\currency~#1\\} +\newcommand{\ihvat}[2]{\textit{Btw-heffing #1}&&&\currency~#2\\} \newcommand{\ihtotal}[1]{\cmidrule[.05em]{4-4}% \textbf{\totaltext}&&&\textbf{\currency~#1}} @@ -108,15 +108,17 @@ <% end subtotal += line[2] end + vattotal = 0.0 if @company.vatno.blank? - vat = 0 %> \ihnosubtotal{} <% else - vat = subtotal * @config["vat_rate"]/100.0 %> - \ihsubtotal{<%= number_with_precision(subtotal) %>} - \ihvat{<%= number_with_precision(vat) %>}<% +%> \ihsubtotal{<%= number_with_precision(subtotal) %>}<% + @vat.keys.sort.each do |rate| + vattotal += @vat[rate] %> + \ihvat{<%= "%d\\%%" % rate %>}{<%= number_with_precision(@vat[rate]) %>}<% + end end %> - \ihtotal{<%= number_with_precision(subtotal + vat) %>} + \ihtotal{<%= number_with_precision(subtotal + vattotal) %>} \end{ihtable} \vspace{2em}