Skip to content

Commit 25f4433

Browse files
committed
address BG-3 Warning and gross price error
1 parent 3a34ca7 commit 25f4433

2 files changed

Lines changed: 41 additions & 24 deletions

File tree

lib/secretariat/invoice.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module Secretariat
2323
:service_period_start,
2424
:service_period_end,
2525
:invoice_type,
26+
:invoice_reference_id,
27+
:invoice_reference_date,
2628
:seller,
2729
:buyer,
2830
:buyer_reference,
@@ -321,6 +323,18 @@ def to_xml(version: 1, validate: true, mode: :zugferd)
321323
Helpers.currency_element(xml, 'ram', 'TotalPrepaidAmount', paid_amount, currency_code, add_currency: version == 1)
322324
Helpers.currency_element(xml, 'ram', 'DuePayableAmount', due_amount, currency_code, add_currency: version == 1)
323325
end
326+
327+
if invoice_reference_id && invoice_reference_date
328+
invoice_reference = by_version(version, 'InvoiceReferencedDocument', 'InvoiceReferencedDocument')
329+
xml['ram'].send(invoice_reference) do
330+
xml['ram'].IssuerAssignedID invoice_reference_id
331+
xml['ram'].FormattedIssueDateTime do
332+
xml['qdt'].DateTimeString(format: '102') do
333+
xml.text(invoice_reference_date.strftime('%Y%m%d'))
334+
end
335+
end
336+
end
337+
end
324338
end
325339
if version == 1
326340
line_items.each_with_index do |item, i|

lib/secretariat/line_item.rb

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,35 +129,38 @@ def to_xml(xml, line_item_index, version: 2, validate: true)
129129
agreement = by_version(version, 'SpecifiedSupplyChainTradeAgreement', 'SpecifiedLineTradeAgreement')
130130

131131
xml['ram'].send(agreement) do
132-
xml['ram'].GrossPriceProductTradePrice do
133-
Helpers.currency_element(xml, 'ram', 'ChargeAmount', gross_amount, currency_code, add_currency: version == 1, digits: 4)
134-
if version >= 2 && discount_amount
135-
xml['ram'].BasisQuantity(unitCode: unit_code) do
136-
xml.text(Helpers.format(BASIS_QUANTITY, digits: 4))
137-
end
138-
xml['ram'].AppliedTradeAllowanceCharge do
139-
xml['ram'].ChargeIndicator do
140-
xml['udt'].Indicator 'false'
132+
if gross_based
133+
xml['ram'].GrossPriceProductTradePrice do
134+
Helpers.currency_element(xml, 'ram', 'ChargeAmount', gross_amount, currency_code, add_currency: version == 1, digits: 4)
135+
if version >= 2 && discount_amount
136+
xml['ram'].BasisQuantity(unitCode: unit_code) do
137+
xml.text(Helpers.format(BASIS_QUANTITY, digits: 4))
138+
end
139+
xml['ram'].AppliedTradeAllowanceCharge do
140+
xml['ram'].ChargeIndicator do
141+
xml['udt'].Indicator 'false'
142+
end
143+
Helpers.currency_element(xml, 'ram', 'ActualAmount', discount_amount, currency_code, add_currency: version == 1)
144+
xml['ram'].Reason discount_reason
141145
end
142-
Helpers.currency_element(xml, 'ram', 'ActualAmount', discount_amount, currency_code, add_currency: version == 1)
143-
xml['ram'].Reason discount_reason
144146
end
145-
end
146-
if version == 1 && discount_amount
147-
xml['ram'].AppliedTradeAllowanceCharge do
148-
xml['ram'].ChargeIndicator do
149-
xml['udt'].Indicator 'false'
147+
if version == 1 && discount_amount
148+
xml['ram'].AppliedTradeAllowanceCharge do
149+
xml['ram'].ChargeIndicator do
150+
xml['udt'].Indicator 'false'
151+
end
152+
Helpers.currency_element(xml, 'ram', 'ActualAmount', discount_amount, currency_code, add_currency: version == 1)
153+
xml['ram'].Reason discount_reason
150154
end
151-
Helpers.currency_element(xml, 'ram', 'ActualAmount', discount_amount, currency_code, add_currency: version == 1)
152-
xml['ram'].Reason discount_reason
153155
end
154156
end
155-
end
156-
xml['ram'].NetPriceProductTradePrice do
157-
Helpers.currency_element(xml, 'ram', 'ChargeAmount', net_amount, currency_code, add_currency: version == 1, digits: 4)
158-
if version >= 2
159-
xml['ram'].BasisQuantity(unitCode: unit_code) do
160-
xml.text(Helpers.format(BASIS_QUANTITY, digits: 4))
157+
else
158+
xml['ram'].NetPriceProductTradePrice do
159+
Helpers.currency_element(xml, 'ram', 'ChargeAmount', net_amount, currency_code, add_currency: version == 1, digits: 4)
160+
if version >= 2
161+
xml['ram'].BasisQuantity(unitCode: unit_code) do
162+
xml.text(Helpers.format(BASIS_QUANTITY, digits: 4))
163+
end
161164
end
162165
end
163166
end

0 commit comments

Comments
 (0)