xrechnung 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ module Xrechnung
2
+ # <cac:PaymentMeans>
3
+ # <cbc:PaymentMeansCode>30</cbc:PaymentMeansCode>
4
+ # <cac:PayeeFinancialAccount>
5
+ # <cbc:ID>DE12500105170648489890</cbc:ID>
6
+ # <cbc:Name>Harry Hirsch</cbc:Name>
7
+ # <cac:FinancialInstitutionBranch>
8
+ # <cbc:ID>XUFUXHB</cbc:ID>
9
+ # </cac:FinancialInstitutionBranch>
10
+ # </cac:PayeeFinancialAccount>
11
+ # </cac:PaymentMeans>
12
+ class PaymentMeans
13
+ include MemberContainer
14
+
15
+ # @!attribute payment_means_code
16
+ # @return [Integer]
17
+ member :payment_means_code, type: Integer
18
+
19
+ # @!attribute payee_financial_account
20
+ # @return [Xrechnung::PayeeFinancialAccount]
21
+ member :payee_financial_account, type: Xrechnung::PayeeFinancialAccount
22
+
23
+ # noinspection RubyResolve
24
+ def to_xml(xml)
25
+ xml.cbc :PaymentMeansCode, payment_means_code
26
+ payee_financial_account&.to_xml(xml)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ module Xrechnung
2
+ class PostalAddress
3
+ include MemberContainer
4
+
5
+ # @!attribute street_name
6
+ # @return [String]
7
+ member :street_name, type: String
8
+
9
+ # @!attribute additional_street_name
10
+ # @return [String]
11
+ member :additional_street_name, type: String
12
+
13
+ # @!attribute city_name
14
+ # @return [String]
15
+ member :city_name, type: String
16
+
17
+ # @!attribute postal_zone
18
+ # @return [String]
19
+ member :postal_zone, type: String
20
+
21
+ # @!attribute country_subentity
22
+ # @return [String]
23
+ member :country_subentity, type: String
24
+
25
+ # @!attribute country_id
26
+ # @return [String]
27
+ member :country_id, type: String
28
+
29
+ # noinspection RubyResolve
30
+ def to_xml(xml)
31
+ xml.cac :PostalAddress do
32
+ xml.cbc :StreetName, street_name if street_name
33
+ xml.cbc :AdditionalStreetName, additional_street_name if additional_street_name
34
+ xml.cbc :CityName, city_name if city_name
35
+ xml.cbc :PostalZone, postal_zone if postal_zone
36
+ xml.cbc :CountrySubentity, country_subentity if country_subentity
37
+
38
+ xml.cac :Country do
39
+ xml.cbc :IdentificationCode, country_id
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ module Xrechnung
2
+ class Price
3
+ include MemberContainer
4
+
5
+ # @!attribute price_amount
6
+ # @return [Xrechnung::Currency]
7
+ member :price_amount, type: Xrechnung::Currency
8
+
9
+ # @!attribute base_quantity
10
+ # @return [Xrechnung::Quantity]
11
+ member :base_quantity, type: Xrechnung::Quantity
12
+
13
+ # @!attribute allowance_charge
14
+ # @return [Xrechnung::AllowanceCharge]
15
+ member :allowance_charge, type: Xrechnung::AllowanceCharge
16
+
17
+ def initialize(**kwargs)
18
+ kwargs[:price_amount] = Currency::EUR(kwargs[:price_amount])
19
+ super(**kwargs)
20
+ end
21
+
22
+ # noinspection RubyResolve
23
+ def to_xml(xml)
24
+ xml.cac :Price do
25
+ xml.cbc :PriceAmount, *price_amount.xml_args
26
+ xml.cbc :BaseQuantity, *base_quantity.xml_args
27
+ allowance_charge&.to_xml(xml)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ module Xrechnung
2
+ Quantity = Struct.new(:amount, :unit_code) do
3
+ def amount_to_s
4
+ format("%0.2f", amount)
5
+ end
6
+
7
+
8
+ def xml_args
9
+ [amount_to_s, unitCode: unit_code]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ module Xrechnung
2
+ # <cbc:ID>S</cbc:ID>
3
+ # <cbc:Percent>16.00</cbc:Percent>
4
+ # <cac:TaxScheme>
5
+ # <cbc:ID>VAT</cbc:ID>
6
+ # </cac:TaxScheme>
7
+ #
8
+ class TaxCategory
9
+ include MemberContainer
10
+
11
+ # • S (Standard rate)
12
+ # • Z (Zero rated goods)
13
+ # • E (Exempt from tax)
14
+ # • AE (VAT Reverse Charge)
15
+ # • K (VAT exempt for EEA intra-community supply of goods and services)
16
+ # • G (Free export item, tax not charged)
17
+ # • O (Services outside scope of tax)
18
+ # • L (Canary Islands general indirect tax)
19
+ # • M (Tax for production, services and importation in Ceuta and Melilla)
20
+ # @!attribute id
21
+ # @return [String]
22
+ member :id, type: String
23
+
24
+ # @!attribute percent
25
+ # @return [BigDecimal]
26
+ member :percent, type: BigDecimal, transform_value: ->(v) { BigDecimal(v, 0) }
27
+
28
+ # @!attribute tax_scheme_id
29
+ # @return [String]
30
+ member :tax_scheme_id, type: String, default: "VAT"
31
+
32
+ # noinspection RubyResolve
33
+ def to_xml(xml, root_tag_name: :TaxCategory)
34
+ xml.cac root_tag_name do
35
+ xml.cbc :ID, id
36
+ xml.cbc :Percent, format("%.2f", percent)
37
+ xml.cac :TaxScheme do
38
+ xml.cbc :ID, tax_scheme_id
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ module Xrechnung
2
+ # <cac:TaxSubtotal>
3
+ # <cbc:TaxableAmount currencyID="EUR">1294.30</cbc:TaxableAmount>
4
+ # <cbc:TaxAmount currencyID="EUR">207.09</cbc:TaxAmount>
5
+ # <cac:TaxCategory>
6
+ # <cbc:ID>S</cbc:ID>
7
+ # <cbc:Percent>16.00</cbc:Percent>
8
+ # <cac:TaxScheme>
9
+ # <cbc:ID>VAT</cbc:ID>
10
+ # </cac:TaxScheme>
11
+ # </cac:TaxCategory>
12
+ # </cac:TaxSubtotal>
13
+ #
14
+ #
15
+ class TaxSubtotal
16
+ include MemberContainer
17
+
18
+ # @!attribute taxable_amount
19
+ # @return [Xrechnung::Currency]
20
+ member :taxable_amount, type: Xrechnung::Currency
21
+
22
+ # @!attribute tax_amount
23
+ # @return [Xrechnung::Currency]
24
+ member :tax_amount, type: Xrechnung::Currency
25
+
26
+ # @!attribute tax_category
27
+ # @return [Xrechnung::TaxCategory]
28
+ member :tax_category, type: Xrechnung::TaxCategory
29
+
30
+ # @!attribute taxable_amount
31
+ # @return [Xrechnung::Currency]
32
+
33
+ def initialize(*args)
34
+ super
35
+ self.taxable_amount ||= Currency::EUR(0)
36
+ end
37
+
38
+ # noinspection RubyResolve
39
+ def to_xml(xml)
40
+ xml.cac :TaxSubtotal do
41
+ xml.cbc :TaxableAmount, *taxable_amount.xml_args
42
+ xml.cbc :TaxAmount, *tax_amount.xml_args
43
+ tax_category&.to_xml(xml)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,46 @@
1
+ module Xrechnung
2
+ # <cbc:TaxAmount currencyID="EUR">297.09</cbc:TaxAmount>
3
+ # <cac:TaxSubtotal>
4
+ # <cbc:TaxableAmount currencyID="EUR">1294.30</cbc:TaxableAmount>
5
+ # <cbc:TaxAmount currencyID="EUR">207.09</cbc:TaxAmount>
6
+ # <cac:TaxCategory>
7
+ # <cbc:ID>S</cbc:ID>
8
+ # <cbc:Percent>16.00</cbc:Percent>
9
+ # <cac:TaxScheme>
10
+ # <cbc:ID>VAT</cbc:ID>
11
+ # </cac:TaxScheme>
12
+ # </cac:TaxCategory>
13
+ # </cac:TaxSubtotal>
14
+ # <cac:TaxSubtotal>
15
+ # <cbc:TaxableAmount currencyID="EUR">1285.70</cbc:TaxableAmount>
16
+ # <cbc:TaxAmount currencyID="EUR">90.00</cbc:TaxAmount>
17
+ # <cac:TaxCategory>
18
+ # <cbc:ID>S</cbc:ID>
19
+ # <cbc:Percent>7.00</cbc:Percent>
20
+ # <cac:TaxScheme>
21
+ # <cbc:ID>VAT</cbc:ID>
22
+ # </cac:TaxScheme>
23
+ # </cac:TaxCategory>
24
+ # </cac:TaxSubtotal>
25
+ #
26
+ class TaxTotal
27
+ include MemberContainer
28
+
29
+ # @!attribute tax_amount
30
+ # @return [Xrechnung::Currency]
31
+ member :tax_amount, type: Xrechnung::Currency
32
+
33
+ # @!attribute tax_subtotals
34
+ # @return [Array]
35
+ member :tax_subtotals, type: Array, default: []
36
+
37
+ # noinspection RubyResolve
38
+ def to_xml(xml)
39
+ xml.cbc :TaxAmount, *tax_amount.xml_args
40
+ tax_subtotals.each do |tax_subtotal|
41
+ tax_subtotal&.to_xml(xml)
42
+ end
43
+ xml.target!
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Xrechnung
2
+ VERSION = "0.1.0"
3
+ end
data/xrechnung.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/xrechnung/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "xrechnung"
5
+ spec.version = Xrechnung::VERSION
6
+ spec.authors = ["Julian Kornberger"]
7
+ spec.email = ["jk+github@digineo.de"]
8
+
9
+ spec.summary = %q{Library to create invoices in the XRechnung format.}
10
+ spec.homepage = "https://github.com/digineo/xrechnung"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/digineo/xrechnung"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "builder", "~> 3.2"
26
+
27
+ spec.add_development_dependency "httparty"
28
+ spec.add_development_dependency "rubyzip", "~> 2.0"
29
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xrechnung
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julian Kornberger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubyzip
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ description:
56
+ email:
57
+ - jk+github@digineo.de
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".github/workflows/validate-fixtures.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/xrechnung.rb
75
+ - lib/xrechnung/allowance_charge.rb
76
+ - lib/xrechnung/contact.rb
77
+ - lib/xrechnung/currency.rb
78
+ - lib/xrechnung/id.rb
79
+ - lib/xrechnung/invoice_document_reference.rb
80
+ - lib/xrechnung/invoice_line.rb
81
+ - lib/xrechnung/item.rb
82
+ - lib/xrechnung/legal_monetary_total.rb
83
+ - lib/xrechnung/member_container.rb
84
+ - lib/xrechnung/party.rb
85
+ - lib/xrechnung/party_legal_entity.rb
86
+ - lib/xrechnung/party_tax_scheme.rb
87
+ - lib/xrechnung/payee_financial_account.rb
88
+ - lib/xrechnung/payment_means.rb
89
+ - lib/xrechnung/postal_address.rb
90
+ - lib/xrechnung/price.rb
91
+ - lib/xrechnung/quantity.rb
92
+ - lib/xrechnung/tax_category.rb
93
+ - lib/xrechnung/tax_subtotal.rb
94
+ - lib/xrechnung/tax_total.rb
95
+ - lib/xrechnung/version.rb
96
+ - xrechnung.gemspec
97
+ homepage: https://github.com/digineo/xrechnung
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ homepage_uri: https://github.com/digineo/xrechnung
102
+ source_code_uri: https://github.com/digineo/xrechnung
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 2.3.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.1.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Library to create invoices in the XRechnung format.
122
+ test_files: []