diff --git a/lib/secretariat/constants.rb b/lib/secretariat/constants.rb index ca7c80c..ddf359a 100644 --- a/lib/secretariat/constants.rb +++ b/lib/secretariat/constants.rb @@ -62,6 +62,10 @@ module Secretariat :EXPORT => 'Export outside the EU' } + # For the background of vertical and horizontal tax calculation see https://hilfe.pacemo.de/de-form/articles/3489851-rundungsfehler-bei-rechnungen + # The idea of introducing an unknown value is that this could be inferred from the given invoice total and line items by probing both variants and selecting the matching one - or reporting a taxation error if neither matches. + TAX_CALCULATION_METHODS = %i[HORIZONTAL VERTICAL UNKNOWN].freeze + UNIT_CODES = { :PIECE => "C62", :DAY => "DAY", diff --git a/lib/secretariat/invoice.rb b/lib/secretariat/invoice.rb index 1a2ff7f..5d33362 100644 --- a/lib/secretariat/invoice.rb +++ b/lib/secretariat/invoice.rb @@ -41,8 +41,8 @@ module Secretariat :grand_total_amount, :due_amount, :paid_amount, + :tax_calculation_method, :attachments, - keyword_init: true ) do @@ -70,7 +70,14 @@ def taxes taxes[line_item.tax_percent].tax_amount += BigDecimal(line_item.tax_amount) taxes[line_item.tax_percent].base_amount += BigDecimal(line_item.net_amount) * line_item.quantity end - taxes.values + if tax_calculation_method == :VERTICAL + taxes.values.map do |tax| + tax.tax_amount = (tax.base_amount * tax.tax_percent / 100).round(2) + tax + end + else + taxes.values + end end def payment_code @@ -171,7 +178,7 @@ def to_xml(version: 1, validate: true) xml.text(issue_date.strftime("%Y%m%d")) end end - + end transaction = by_version(version, 'SpecifiedSupplyChainTradeTransaction', 'SupplyChainTradeTransaction') xml['rsm'].send(transaction) do