Class: Ubl::UblBuilder
- Inherits:
-
Object
- Object
- Ubl::UblBuilder
- Defined in:
- lib/ubl/builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#due_date ⇒ Object
Returns the value of attribute due_date.
-
#invoice_lines ⇒ Object
Returns the value of attribute invoice_lines.
-
#invoice_nr ⇒ Object
Returns the value of attribute invoice_nr.
-
#issue_date ⇒ Object
Returns the value of attribute issue_date.
-
#legal_monetary_total ⇒ Object
Returns the value of attribute legal_monetary_total.
-
#pdffile ⇒ Object
Returns the value of attribute pdffile.
-
#supplier ⇒ Object
Returns the value of attribute supplier.
-
#tax_total ⇒ Object
Returns the value of attribute tax_total.
Instance Method Summary collapse
- #add_customer(name:, country:, vat_id: nil, address: nil, city: nil, postal_code: nil) ⇒ Object
- #add_line(name:, quantity:, unit_price:, description: name, tax_rate: 21.0, unit: "ZZ") ⇒ Object
- #add_payment_means(iban:, bic:) ⇒ Object
- #add_supplier(name:, country:, vat_id: nil, address: nil, city: nil, postal_code: nil) ⇒ Object
-
#initialize(extension = nil) ⇒ UblBuilder
constructor
A new instance of UblBuilder.
- #namespaces ⇒ Object
Constructor Details
#initialize(extension = nil) ⇒ UblBuilder
Returns a new instance of UblBuilder.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ubl/builder.rb', line 13 def initialize(extension = nil) @ubl_be = extension == UBL_BE @issue_date = Date.today @due_date = @issue_date + 30 @currency = "EUR" @attachments = [] @invoice_lines = [] @tax_total = 0 @legal_monetary_total = 0 end |
Instance Attribute Details
#currency ⇒ Object
Returns the value of attribute currency.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def currency @currency end |
#customer ⇒ Object
Returns the value of attribute customer.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def customer @customer end |
#due_date ⇒ Object
Returns the value of attribute due_date.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def due_date @due_date end |
#invoice_lines ⇒ Object
Returns the value of attribute invoice_lines.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def invoice_lines @invoice_lines end |
#invoice_nr ⇒ Object
Returns the value of attribute invoice_nr.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def invoice_nr @invoice_nr end |
#issue_date ⇒ Object
Returns the value of attribute issue_date.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def issue_date @issue_date end |
#legal_monetary_total ⇒ Object
Returns the value of attribute legal_monetary_total.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def legal_monetary_total @legal_monetary_total end |
#pdffile ⇒ Object
Returns the value of attribute pdffile.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def pdffile @pdffile end |
#supplier ⇒ Object
Returns the value of attribute supplier.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def supplier @supplier end |
#tax_total ⇒ Object
Returns the value of attribute tax_total.
10 11 12 |
# File 'lib/ubl/builder.rb', line 10 def tax_total @tax_total end |
Instance Method Details
#add_customer(name:, country:, vat_id: nil, address: nil, city: nil, postal_code: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ubl/builder.rb', line 43 def add_customer(name:, country:, vat_id: nil, address: nil, city: nil, postal_code: nil) @customer = { name: name, country: country, vat_id: vat_id, address: address, city: city, postal_code: postal_code } end |
#add_line(name:, quantity:, unit_price:, description: name, tax_rate: 21.0, unit: "ZZ") ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ubl/builder.rb', line 61 def add_line(name:, quantity:, unit_price:, description: name, tax_rate: 21.0, unit: "ZZ") line_extension_amount = (quantity * unit_price).round(2) tax_amount = (line_extension_amount * (tax_rate / 100.0)).round(2) @invoice_lines << { id: (@invoice_lines.length + 1).to_s, description: description, name: name, quantity: quantity, unit: unit, unit_price: unit_price, line_extension_amount: line_extension_amount, tax_rate: tax_rate, tax_amount: tax_amount } calculate_totals end |
#add_payment_means(iban:, bic:) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/ubl/builder.rb', line 54 def add_payment_means(iban:, bic:) @payment_means = { iban: iban, bic: bic } end |
#add_supplier(name:, country:, vat_id: nil, address: nil, city: nil, postal_code: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ubl/builder.rb', line 32 def add_supplier(name:, country:, vat_id: nil, address: nil, city: nil, postal_code: nil) @supplier = { name: name, country: country, vat_id: vat_id, address: address, city: city, postal_code: postal_code } end |
#namespaces ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/ubl/builder.rb', line 24 def namespaces { "xmlns" => "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2", "xmlns:cac" => "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2", "xmlns:cbc" => "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" } end |