Skip to content

Commit dc33831

Browse files
authored
Merge pull request #3 from Skulli/feature_invoice_types
can set different type for a bill
2 parents f316a5e + 6d27cfe commit dc33831

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lib/secretariat/constants.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,27 @@ module Secretariat
8383
CARTON: "CT",
8484
CAN: "CA"
8585
}
86+
87+
INVOICE_TYPES = {
88+
INVOICE: {
89+
code: "380",
90+
name: "Rechnung"
91+
},
92+
CREDIT_NOTE: {
93+
code: "381",
94+
name: "Gutschrift"
95+
},
96+
CORRECTION: {
97+
code: "384",
98+
name: "Korrekturrechnung"
99+
},
100+
PART_INVOICE: {
101+
code: "326",
102+
name: "Teilrechnung"
103+
},
104+
REVERSED_INVOICE: {
105+
code: "457",
106+
name: "Stornorechnung"
107+
}
108+
}
86109
end

lib/secretariat/invoice.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module Secretariat
4646
:project_name,
4747
:invoice_start,
4848
:invoice_end,
49+
:invoice_type,
4950
keyword_init: true) do
5051
include Versioner
5152

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

156157
xml["rsm"].send(header) do
157158
xml["ram"].ID id
158-
if version == 1
159-
xml["ram"].Name "RECHNUNG"
159+
if !invoice_type.nil?
160+
if version == 1
161+
xml["ram"].Name INVOICE_TYPES[invoice_type][:name]
162+
end
163+
xml["ram"].TypeCode INVOICE_TYPES[invoice_type][:code]
164+
else
165+
if version == 1
166+
xml["ram"].Name "RECHNUNG"
167+
end
168+
xml["ram"].TypeCode "380"
160169
end
161-
xml["ram"].TypeCode "380" # TODO: make configurable
162170
xml["ram"].IssueDateTime do
163171
xml["udt"].DateTimeString(format: "102") do
164172
xml.text(issue_date.strftime("%Y%m%d"))

spec/lib/secretariat/invoice_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
grand_total_amount: 29,
5757
due_amount: 0,
5858
paid_amount: 29,
59-
buyer_reference: "REF-112233"
59+
buyer_reference: "REF-112233",
60+
invoice_type: :INVOICE
6061
)
6162
}
6263

0 commit comments

Comments
 (0)