Skip to content

Commit

Permalink
Add invoice period
Browse files Browse the repository at this point in the history
  • Loading branch information
datyv authored and corny committed Mar 18, 2024
1 parent e441926 commit dd379cd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/xrechnung.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
require "xrechnung/price"
require "xrechnung/invoice_line"
require "xrechnung/invoice_document_reference"
require "xrechnung/invoice_period"
require "builder"

module Xrechnung
Expand Down Expand Up @@ -168,6 +169,10 @@ class Document
# @return [Xrechnung::InvoiceDocumentReference]
member :billing_reference, type: Xrechnung::InvoiceDocumentReference, optional: true

# @!attribute invoice_period
# @return [Xrechnung::InvoicePeriod]
member :invoice_period, type: Xrechnung::InvoicePeriod, optional: true

# Contract reference BT-12
#
# Eine eindeutige Bezeichnung des Vertrages (z. B. Vertragsnummer).
Expand Down Expand Up @@ -260,11 +265,15 @@ def to_xml(indent: 2, target: "")
xml.cbc :Note, note
end

xml.cbc :TaxPointDate, tax_point_date
xml.cbc :TaxPointDate, tax_point_date unless tax_point_date.nil?
xml.cbc :DocumentCurrencyCode, document_currency_code
xml.cbc :TaxCurrencyCode, tax_currency_code
xml.cbc :BuyerReference, buyer_reference

unless members[:invoice_period][:optional] && invoice_period.nil?
invoice_period&.to_xml(xml)
end

xml.cac :OrderReference do
xml.cbc :ID, purchase_order_reference
unless members[:sales_order_reference][:optional] && sales_order_reference.nil?
Expand Down
10 changes: 10 additions & 0 deletions lib/xrechnung/invoice_line.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "xrechnung/invoice_period"

module Xrechnung
class InvoiceLine
include MemberContainer
Expand All @@ -6,6 +8,10 @@ class InvoiceLine
# @return [Integer]
member :id, type: Integer

# @!attribute invoice_period
# @return [Xrechnung::InvoicePeriod]
member :invoice_period, type: Xrechnung::InvoicePeriod, optional: true

# @!attribute invoiced_quantity
# @return [Xrechnung::Quantity]
member :invoiced_quantity, type: Xrechnung::Quantity
Expand Down Expand Up @@ -33,6 +39,10 @@ def to_xml(xml)
xml.cbc :ID, id
xml.cbc :InvoicedQuantity, invoiced_quantity.amount_to_s, unitCode: invoiced_quantity.unit_code
xml.cbc :LineExtensionAmount, *line_extension_amount.xml_args

unless members[:invoice_period][:optional] && invoice_period.nil?
invoice_period&.to_xml(xml)
end
item&.to_xml(xml)
price&.to_xml(xml)
end
Expand Down
20 changes: 20 additions & 0 deletions lib/xrechnung/invoice_period.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Xrechnung
class InvoicePeriod
include MemberContainer

# @!attribute start_date
# @return [Date]
member :start_date, type: Date

# @!attribute end_date
# @return [Date]
member :end_date, type: Date

def to_xml(xml)
xml.cac :InvoicePeriod do
xml.cbc :StartDate, start_date
xml.cbc :EndDate, end_date
end
end
end
end
8 changes: 8 additions & 0 deletions spec/fixtures/xrechnung.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
<cbc:TaxCurrencyCode>EUR</cbc:TaxCurrencyCode>
<cbc:BuyerReference>9900 0000 - 1234 56 - 23</cbc:BuyerReference>
<cac:InvoicePeriod>
<cbc:StartDate>2021-04-01</cbc:StartDate>
<cbc:EndDate>2021-04-30</cbc:EndDate>
</cac:InvoicePeriod>
<cac:OrderReference>
<cbc:ID>0815-99-1</cbc:ID>
</cac:OrderReference>
Expand Down Expand Up @@ -182,6 +186,10 @@
<cbc:ID>1</cbc:ID>
<cbc:InvoicedQuantity unitCode="XPP">5.00</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID="EUR">1285.70</cbc:LineExtensionAmount>
<cac:InvoicePeriod>
<cbc:StartDate>2021-04-07</cbc:StartDate>
<cbc:EndDate>2021-04-13</cbc:EndDate>
</cac:InvoicePeriod>
<cac:Item>
<cbc:Description>Dichtungsfolie 2.5 mm stark, 1.5 m breit</cbc:Description>
<cbc:Name>Dichtungsfolie</cbc:Name>
Expand Down
5 changes: 5 additions & 0 deletions spec/xrechnung_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
doc.billing_reference.id = "Vorangegangene Rechnung 23423"
doc.billing_reference.issue_date = Date.new(2020, 4, 23)

doc.invoice_period = Xrechnung::InvoicePeriod.new
doc.invoice_period.start_date = Date.new(2021, 4, 1)
doc.invoice_period.end_date = Date.new(2021, 4, 30)

doc.contract_document_reference_id = "23871349"
doc.project_reference_id = "Bauvorhaben Glücksstraße 4"

Expand Down Expand Up @@ -84,6 +88,7 @@

doc.invoice_lines << Xrechnung::InvoiceLine.new(
id: 1,
invoice_period: Xrechnung::InvoicePeriod.new(start_date: Date.new(2021, 4, 7), end_date: Date.new(2021, 4, 13)),
invoiced_quantity: Xrechnung::Quantity.new(5, "XPP"),
line_extension_amount: 1285.70,
item: Xrechnung::Item.new(
Expand Down

0 comments on commit dd379cd

Please sign in to comment.