ubl 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d85586554b03950c5f00fc767da60c5cc179650d76c9afab96f40752dc83269b
4
- data.tar.gz: b767d4c66653121049e27d3208e6d518efe8093b240f8b05b852f82ce98b0605
3
+ metadata.gz: f257c1e68bac4286b082be4900f49a27fc736a69dc7cafa7de79cca2219e9035
4
+ data.tar.gz: 15be033154369701934e55ddc4ae34a2270032f129e8f9409927a4b06174f00e
5
5
  SHA512:
6
- metadata.gz: 84c1e2c7e3335681e7aef44f3404cbe2d520d9003882a2991ed47c5e8ef21c4ab18d7db484048b626e97d51761f81b329fe10e2d0a93daff5ef3eb327cf96dcd
7
- data.tar.gz: 73332157c0330f6d1c7c1ba28e76e4bfc164d51c6fccba007ac36d37f927241897906725b9d7624632eeb2a9bd0a9209e3254c7f1213fdd6057b4e17002fe3af
6
+ metadata.gz: 63d7d62032fc619e8756655f2e737cc17bb5f54b9452478bdf15aadb3c040430f54a1db90e647fe5696182c719f33f2d22ff3649d5ade31c38ed8f8758f8f99d
7
+ data.tar.gz: 8e9ef76a121e0288be720acd30d14bb38747c0ed5e19f22abed25ec5768ba57ca4640d17dd547ce0b9f7be988d139cac7a667a4e3085ee4dac871c39b82c37fd
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/ubl.svg)](https://badge.fury.io/rb/ubl)
2
+
1
3
  # Ubl
2
4
 
3
5
  Generate UBL invoices and credit notes for Peppol
@@ -16,9 +18,42 @@ if bundler is not being used to manage dependencies, install the gem by executin
16
18
  gem install ubl
17
19
  ```
18
20
 
19
- ## usage
21
+ ## Example
22
+
23
+ ```ruby
24
+ require "ubl"
25
+
26
+ invoice = Ubl::Invoice.new
27
+ invoice.invoice_nr = "INV-2025-001"
28
+ invoice.issue_date = Date.new(2025, 6, 28)
29
+ invoice.due_date = Date.new(2025, 7, 28)
30
+ invoice.currency = "EUR"
31
+ invoice.pdffile = __dir__ + "/invoice_test.pdf"
32
+
33
+ invoice.add_supplier(
34
+ name: "ACME Corp",
35
+ country: "BE",
36
+ vat_id: "BE0123456749",
37
+ address: "Main Street 123",
38
+ city: "Brussels",
39
+ postal_code: "1000"
40
+ )
41
+
42
+ invoice.add_customer(
43
+ name: "Customer Ltd",
44
+ country: "BE",
45
+ vat_id: "BE0123456749",
46
+ address: "Customer Lane 456",
47
+ city: "Antwerpen",
48
+ postal_code: "1012"
49
+ )
50
+
51
+ invoice.add_line(name: "Consulting Services", quantity: 10, unit_price: 100.0, tax_rate: 21.0)
52
+ invoice.add_line(name: "Software License", quantity: 1, unit_price: 500.0, tax_rate: 21.0)
53
+
54
+ invoice.build
55
+ ```
20
56
 
21
- todo: write usage instructions here
22
57
 
23
58
  ## development
24
59
 
data/lib/ubl/builder.rb CHANGED
@@ -5,8 +5,6 @@ require "date"
5
5
  require "base64"
6
6
 
7
7
  module Ubl
8
- class Error < StandardError; end
9
-
10
8
  class UblBuilder
11
9
  attr_accessor :invoice_nr, :issue_date, :due_date, :currency, :supplier,
12
10
  :customer, :invoice_lines, :tax_total, :legal_monetary_total, :pdffile
@@ -15,8 +13,8 @@ module Ubl
15
13
  CUSTOMIZATION_UBL_BE = "urn:cen.eu:en16931:2017#conformant#urn:UBL.BE:1.0.0.20180214"
16
14
  PROFILE_ID = "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"
17
15
 
18
- def initialize(ubl_be = false)
19
- @ubl_be = ubl_be
16
+ def initialize(extension = nil)
17
+ @ubl_be = extension == "UBL_BE"
20
18
  @issue_date = Date.today
21
19
  @due_date = @issue_date + 30
22
20
  @currency = "EUR"
data/lib/ubl/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ubl
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.4"
5
5
  end
data/lib/ubl.rb ADDED
@@ -0,0 +1,72 @@
1
+ require_relative "ubl/builder"
2
+
3
+ ##
4
+ # The Invoice and CreditNote class generates UBL (Universal Business Language) compliant XML
5
+ # documents following PEPPOL standards.
6
+ module Ubl
7
+ class Invoice < UblBuilder
8
+ ##
9
+ # Creates a new Invoice instance.
10
+ #
11
+ # == Parameters
12
+ # * +extension+ - (String) Optional. Set to +"UBL_BE"+ to generate UBL.BE compliant invoices
13
+ # for Belgian requirements. Defaults to +nil+ for standard PEPPOL format.
14
+ #
15
+ def initialize(extension = nil)
16
+ super
17
+ end
18
+
19
+ def build
20
+ builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
21
+ xml.Invoice(namespaces) do
22
+ build_header(xml) do |xml|
23
+ xml["cbc"].InvoiceTypeCode "380"
24
+ end
25
+
26
+ build_document_reference(xml, "CommercialInvoice")
27
+
28
+ build_party(xml, @supplier, "AccountingSupplierParty")
29
+ build_party(xml, @customer, "AccountingCustomerParty")
30
+
31
+ build_tax_total(xml)
32
+ build_monetary_total(xml)
33
+ build_invoice_lines(xml)
34
+ end
35
+ end
36
+ builder.to_xml
37
+ end
38
+ end
39
+
40
+ class CreditNote < UblBuilder
41
+ ##
42
+ # Creates a new CreditNote instance.
43
+ #
44
+ # == Parameters
45
+ # * +extension+ - (String) Optional. Set to +"UBL_BE"+ to generate UBL.BE compliant
46
+ # credit notes for Belgian requirements. Defaults to +nil+ for standard PEPPOL format.
47
+ #
48
+ def initialize(extension = nil)
49
+ super
50
+ end
51
+
52
+ def build
53
+ builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
54
+ xml.CreditNote(namespaces.merge("xmlns" => "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2")) do
55
+ build_header(xml) do |xml|
56
+ xml["cbc"].CreditNoteTypeCode "381"
57
+ end
58
+
59
+ build_document_reference(xml, "CreditNote")
60
+
61
+ build_party(xml, @supplier, "AccountingSupplierParty")
62
+ build_party(xml, @customer, "AccountingCustomerParty")
63
+
64
+ build_tax_total(xml)
65
+ build_monetary_total(xml)
66
+ build_invoice_lines(xml)
67
+ end
68
+ end
69
+ builder.to_xml
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - roel4d
@@ -48,8 +48,7 @@ files:
48
48
  - LICENSE.txt
49
49
  - README.md
50
50
  - Rakefile
51
- - lib/credit_note.rb
52
- - lib/invoice.rb
51
+ - lib/ubl.rb
53
52
  - lib/ubl/builder.rb
54
53
  - lib/ubl/version.rb
55
54
  - sig/ubl.rbs
data/lib/credit_note.rb DELETED
@@ -1,29 +0,0 @@
1
- require_relative "ubl/builder"
2
-
3
- module Ubl
4
- class CreditNote < UblBuilder
5
- def initialize(ubl_be)
6
- super
7
- end
8
-
9
- def build
10
- builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
11
- xml.CreditNote(namespaces.merge("xmlns" => "urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2")) do
12
- build_header(xml) do |xml|
13
- xml["cbc"].CreditNoteTypeCode "381"
14
- end
15
-
16
- build_document_reference(xml, "CreditNote")
17
-
18
- build_party(xml, @supplier, "AccountingSupplierParty")
19
- build_party(xml, @customer, "AccountingCustomerParty")
20
-
21
- build_tax_total(xml)
22
- build_monetary_total(xml)
23
- build_invoice_lines(xml)
24
- end
25
- end
26
- builder.to_xml
27
- end
28
- end
29
- end
data/lib/invoice.rb DELETED
@@ -1,29 +0,0 @@
1
- require_relative "ubl/builder"
2
-
3
- module Ubl
4
- class Invoice < UblBuilder
5
- def initialize(ubl_be)
6
- super
7
- end
8
-
9
- def build
10
- builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
11
- xml.Invoice(namespaces) do
12
- build_header(xml) do |xml|
13
- xml["cbc"].InvoiceTypeCode "380"
14
- end
15
-
16
- build_document_reference(xml, "CommercialInvoice")
17
-
18
- build_party(xml, @supplier, "AccountingSupplierParty")
19
- build_party(xml, @customer, "AccountingCustomerParty")
20
-
21
- build_tax_total(xml)
22
- build_monetary_total(xml)
23
- build_invoice_lines(xml)
24
- end
25
- end
26
- builder.to_xml
27
- end
28
- end
29
- end