Skip to content

Commit

Permalink
Merge pull request #3 from Skulli/feature_invoice_types
Browse files Browse the repository at this point in the history
can set different type for a bill
  • Loading branch information
Skulli authored Jun 27, 2024
2 parents f316a5e + 6d27cfe commit dc33831
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
23 changes: 23 additions & 0 deletions lib/secretariat/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,27 @@ module Secretariat
CARTON: "CT",
CAN: "CA"
}

INVOICE_TYPES = {
INVOICE: {
code: "380",
name: "Rechnung"
},
CREDIT_NOTE: {
code: "381",
name: "Gutschrift"
},
CORRECTION: {
code: "384",
name: "Korrekturrechnung"
},
PART_INVOICE: {
code: "326",
name: "Teilrechnung"
},
REVERSED_INVOICE: {
code: "457",
name: "Stornorechnung"
}
}
end
14 changes: 11 additions & 3 deletions lib/secretariat/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module Secretariat
:project_name,
:invoice_start,
:invoice_end,
:invoice_type,
keyword_init: true) do
include Versioner

Expand Down Expand Up @@ -155,10 +156,17 @@ def to_xml(version: 1, skip_validation: false, mode: :zugferd)

xml["rsm"].send(header) do
xml["ram"].ID id
if version == 1
xml["ram"].Name "RECHNUNG"
if !invoice_type.nil?
if version == 1
xml["ram"].Name INVOICE_TYPES[invoice_type][:name]
end
xml["ram"].TypeCode INVOICE_TYPES[invoice_type][:code]
else
if version == 1
xml["ram"].Name "RECHNUNG"
end
xml["ram"].TypeCode "380"
end
xml["ram"].TypeCode "380" # TODO: make configurable
xml["ram"].IssueDateTime do
xml["udt"].DateTimeString(format: "102") do
xml.text(issue_date.strftime("%Y%m%d"))
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/secretariat/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
grand_total_amount: 29,
due_amount: 0,
paid_amount: 29,
buyer_reference: "REF-112233"
buyer_reference: "REF-112233",
invoice_type: :INVOICE
)
}

Expand Down

0 comments on commit dc33831

Please sign in to comment.