Support alternative invoice template configuration
This commit is contained in:
parent
70c0ad4a54
commit
25b052e864
|
@ -8,3 +8,6 @@
|
||||||
|
|
||||||
# The invoice ID format (see strftime(3) and %N for the sequence number)
|
# The invoice ID format (see strftime(3) and %N for the sequence number)
|
||||||
#invoice_id: %Y%N
|
#invoice_id: %Y%N
|
||||||
|
|
||||||
|
# The invoice template used (without the .tex.erb suffix)
|
||||||
|
#invoice_template: invoice
|
||||||
|
|
11
stoptime.rb
11
stoptime.rb
|
@ -137,9 +137,10 @@ module StopTime::Models
|
||||||
|
|
||||||
# The default configuration. Note that the configuration of the root
|
# The default configuration. Note that the configuration of the root
|
||||||
# will be merged with this configuration.
|
# will be merged with this configuration.
|
||||||
DefaultConfig = { "invoice_id" => "%Y%N",
|
DefaultConfig = { "invoice_id" => "%Y%N",
|
||||||
"hourly_rate" => 20.0,
|
"invoice_template" => "invoice",
|
||||||
"vat_rate" => 21.0 }
|
"hourly_rate" => 20.0,
|
||||||
|
"vat_rate" => 21.0 }
|
||||||
|
|
||||||
# Creates a new configuration object and loads the configuation.
|
# Creates a new configuration object and loads the configuation.
|
||||||
# by reading the file @config.yaml@ on disk, parsing it, and
|
# by reading the file @config.yaml@ on disk, parsing it, and
|
||||||
|
@ -1165,7 +1166,7 @@ module StopTime::Controllers
|
||||||
|
|
||||||
# Generates a LaTex document for the invoice with the given _number_.
|
# Generates a LaTex document for the invoice with the given _number_.
|
||||||
def _generate_invoice_tex(number)
|
def _generate_invoice_tex(number)
|
||||||
template = TEMPLATE_DIR + "invoice.tex.erb"
|
template = TEMPLATE_DIR + "#{@config["invoice_template"]}.tex.erb"
|
||||||
tex_file = PUBLIC_DIR + "invoices/#{number}.tex"
|
tex_file = PUBLIC_DIR + "invoices/#{number}.tex"
|
||||||
|
|
||||||
I18n.with_locale :nl do
|
I18n.with_locale :nl do
|
||||||
|
@ -1173,7 +1174,7 @@ module StopTime::Controllers
|
||||||
File.open(tex_file, "w") { |f| f.write(erb.result(binding)) }
|
File.open(tex_file, "w") { |f| f.write(erb.result(binding)) }
|
||||||
end
|
end
|
||||||
rescue Exception => err
|
rescue Exception => err
|
||||||
tex_file.delete
|
tex_file.delete if File.exist? tex_file
|
||||||
raise err
|
raise err
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue