Skip to content

Commit 077123c

Browse files
authored
Merge pull request #23 from RST-J/add-tax-calculation-method
Add support for vertical VAT calculation
2 parents d2b3712 + 0ebf972 commit 077123c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/secretariat/constants.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ module Secretariat
6262
:EXPORT => 'Export outside the EU'
6363
}
6464

65+
# For the background of vertical and horizontal tax calculation see https://hilfe.pacemo.de/de-form/articles/3489851-rundungsfehler-bei-rechnungen
66+
# 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.
67+
TAX_CALCULATION_METHODS = %i[HORIZONTAL VERTICAL UNKNOWN].freeze
68+
6569
UNIT_CODES = {
6670
:PIECE => "C62",
6771
:DAY => "DAY",

lib/secretariat/invoice.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ module Secretariat
4141
:grand_total_amount,
4242
:due_amount,
4343
:paid_amount,
44+
:tax_calculation_method,
4445
:attachments,
45-
4646
keyword_init: true
4747
) do
4848

@@ -70,7 +70,14 @@ def taxes
7070
taxes[line_item.tax_percent].tax_amount += BigDecimal(line_item.tax_amount)
7171
taxes[line_item.tax_percent].base_amount += BigDecimal(line_item.net_amount) * line_item.quantity
7272
end
73-
taxes.values
73+
if tax_calculation_method == :VERTICAL
74+
taxes.values.map do |tax|
75+
tax.tax_amount = (tax.base_amount * tax.tax_percent / 100).round(2)
76+
tax
77+
end
78+
else
79+
taxes.values
80+
end
7481
end
7582

7683
def payment_code
@@ -171,7 +178,7 @@ def to_xml(version: 1, validate: true)
171178
xml.text(issue_date.strftime("%Y%m%d"))
172179
end
173180
end
174-
181+
175182
end
176183
transaction = by_version(version, 'SpecifiedSupplyChainTradeTransaction', 'SupplyChainTradeTransaction')
177184
xml['rsm'].send(transaction) do

0 commit comments

Comments
 (0)