Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/secretariat/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 10 additions & 3 deletions lib/secretariat/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ module Secretariat
:grand_total_amount,
:due_amount,
:paid_amount,
:tax_calculation_method,
:attachments,

keyword_init: true
) do

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading