Class: Xrechnung::Document
- Inherits:
-
Object
- Object
- Xrechnung::Document
- Includes:
- MemberContainer
- Defined in:
- lib/xrechnung.rb
Constant Summary collapse
- DEFAULT_CUSTOMIZATION_ID =
Default customization specs
"urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0"- DEFAULT_PROFILE_ID =
"urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"- COMMON_NAMESPACES =
{ "xmlns:ubl" => "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", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation" => "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd", }.freeze
Instance Attribute Summary collapse
- #accounting_customer_party ⇒ Xrechnung::Party
- #accounting_supplier_party ⇒ Xrechnung::Party
- #additional_document_references ⇒ Array
- #allowance_charges ⇒ Array
- #billing_reference ⇒ Xrechnung::InvoiceDocumentReference
- #buyer_reference ⇒ String
- #contract_document_reference_id ⇒ String
- #customization_id ⇒ String
- #document_currency_code ⇒ String
- #due_date ⇒ Date
- #id ⇒ String
- #invoice_lines ⇒ Array
- #invoice_period ⇒ Xrechnung::InvoicePeriod
- #invoice_type_code ⇒ Integer
- #issue_date ⇒ Date
- #legal_monetary_total ⇒ Xrechnung::LegalMonetaryTotal
- #notes ⇒ Array
- #payee_party ⇒ Xrechnung::PayeeParty
- #payment_means ⇒ Xrechnung::PaymentMeans
- #payment_terms_note ⇒ String
- #profile_id ⇒ String
- #project_reference_id ⇒ String
- #purchase_order_reference ⇒ String
- #sales_order_reference ⇒ String
- #tax_currency_code ⇒ String
- #tax_point_date ⇒ Date
- #tax_representative_party ⇒ Xrechnung::Party
- #tax_total ⇒ Xrechnung::TaxTotal
Instance Method Summary collapse
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #prepaid_amount=(value) ⇒ Object
- #to_xml(indent: 2, target: "") ⇒ Object
- #update_amounts ⇒ Object
Methods included from MemberContainer
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
307 308 309 310 |
# File 'lib/xrechnung.rb', line 307 def initialize(...) super self.legal_monetary_total ||= Xrechnung::LegalMonetaryTotal.new end |
Instance Attribute Details
#accounting_customer_party ⇒ Xrechnung::Party
151 |
# File 'lib/xrechnung.rb', line 151 member :accounting_customer_party, type: Xrechnung::Party |
#accounting_supplier_party ⇒ Xrechnung::Party
143 |
# File 'lib/xrechnung.rb', line 143 member :accounting_supplier_party, type: Xrechnung::Party |
#additional_document_references ⇒ Array
201 |
# File 'lib/xrechnung.rb', line 201 member :additional_document_references, type: Array, default: [] |
#allowance_charges ⇒ Array
297 |
# File 'lib/xrechnung.rb', line 297 member :allowance_charges, type: Array, default: [] |
#billing_reference ⇒ Xrechnung::InvoiceDocumentReference
196 |
# File 'lib/xrechnung.rb', line 196 member :billing_reference, type: Xrechnung::InvoiceDocumentReference, optional: true |
#buyer_reference ⇒ String
192 |
# File 'lib/xrechnung.rb', line 192 member :buyer_reference, type: String |
#contract_document_reference_id ⇒ String
213 |
# File 'lib/xrechnung.rb', line 213 member :contract_document_reference_id, type: String, optional: true |
#customization_id ⇒ String
48 |
# File 'lib/xrechnung.rb', line 48 member :customization_id, type: String, default: DEFAULT_CUSTOMIZATION_ID |
#document_currency_code ⇒ String
110 |
# File 'lib/xrechnung.rb', line 110 member :document_currency_code, type: String, default: "EUR" |
#due_date ⇒ Date
79 |
# File 'lib/xrechnung.rb', line 79 member :due_date, type: Date |
#id ⇒ String
63 |
# File 'lib/xrechnung.rb', line 63 member :id, type: String |
#invoice_lines ⇒ Array
286 |
# File 'lib/xrechnung.rb', line 286 member :invoice_lines, type: Array, default: [] |
#invoice_period ⇒ Xrechnung::InvoicePeriod
205 |
# File 'lib/xrechnung.rb', line 205 member :invoice_period, type: Xrechnung::InvoicePeriod, optional: true |
#invoice_type_code ⇒ Integer
97 |
# File 'lib/xrechnung.rb', line 97 member :invoice_type_code, type: Integer, default: 380 |
#issue_date ⇒ Date
71 |
# File 'lib/xrechnung.rb', line 71 member :issue_date, type: Date |
#legal_monetary_total ⇒ Xrechnung::LegalMonetaryTotal
277 |
# File 'lib/xrechnung.rb', line 277 member :legal_monetary_total, type: Xrechnung::LegalMonetaryTotal, is_private: true |
#notes ⇒ Array
119 |
# File 'lib/xrechnung.rb', line 119 member :notes, type: Array, default: [] |
#payee_party ⇒ Xrechnung::PayeeParty
248 |
# File 'lib/xrechnung.rb', line 248 member :payee_party, type: Xrechnung::PayeeParty, optional: true |
#payment_means ⇒ Xrechnung::PaymentMeans
239 |
# File 'lib/xrechnung.rb', line 239 member :payment_means, type: Xrechnung::PaymentMeans |
#payment_terms_note ⇒ String
259 |
# File 'lib/xrechnung.rb', line 259 member :payment_terms_note, type: String |
#profile_id ⇒ String
54 |
# File 'lib/xrechnung.rb', line 54 member :profile_id, type: String, default: DEFAULT_PROFILE_ID |
#project_reference_id ⇒ String
221 |
# File 'lib/xrechnung.rb', line 221 member :project_reference_id, type: String, optional: true |
#purchase_order_reference ⇒ String
127 |
# File 'lib/xrechnung.rb', line 127 member :purchase_order_reference, type: String |
#sales_order_reference ⇒ String
135 |
# File 'lib/xrechnung.rb', line 135 member :sales_order_reference, type: String, optional: true |
#tax_currency_code ⇒ String
173 |
# File 'lib/xrechnung.rb', line 173 member :tax_currency_code, type: String |
#tax_point_date ⇒ Date
160 |
# File 'lib/xrechnung.rb', line 160 member :tax_point_date, type: Date |
#tax_representative_party ⇒ Xrechnung::Party
230 |
# File 'lib/xrechnung.rb', line 230 member :tax_representative_party, type: Xrechnung::Party, optional: true |
#tax_total ⇒ Xrechnung::TaxTotal
268 |
# File 'lib/xrechnung.rb', line 268 member :tax_total, type: Xrechnung::TaxTotal, is_private: true |
Instance Method Details
#prepaid_amount=(value) ⇒ Object
312 313 314 |
# File 'lib/xrechnung.rb', line 312 def prepaid_amount=(value) legal_monetary_total.prepaid_amount = value end |
#to_xml(indent: 2, target: "") ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/xrechnung.rb', line 316 def to_xml(indent: 2, target: "") update_amounts xml = Builder::XmlMarkup.new(indent: indent, target: target) xml.instruct! :xml, version: "1.0", encoding: "UTF-8" xml.ubl :Invoice, COMMON_NAMESPACES do xml.cbc :CustomizationID, customization_id xml.cbc :ProfileID, profile_id xml.cbc :ID, id xml.cbc :IssueDate, issue_date xml.cbc :DueDate, due_date xml.cbc :InvoiceTypeCode, invoice_type_code notes.each do |note| xml.cbc :Note, note end xml.cbc :TaxPointDate, tax_point_date unless tax_point_date.nil? xml.cbc :DocumentCurrencyCode, document_currency_code xml.cbc :TaxCurrencyCode, tax_currency_code unless tax_currency_code.nil? xml.cbc :AccountingCost, buyer_accounting_reference unless buyer_accounting_reference.nil? xml.cbc :BuyerReference, buyer_reference invoice_period&.to_xml(xml) unless self.class.members[:invoice_period].optional && invoice_period.nil? unless purchase_order_reference.nil? && self.class.members[:sales_order_reference].optional && sales_order_reference.nil? xml.cac :OrderReference do xml.cbc :ID, purchase_order_reference unless self.class.members[:sales_order_reference].optional && sales_order_reference.nil? xml.cbc :SalesOrderID, sales_order_reference end end end unless self.class.members[:billing_reference].optional && billing_reference.nil? xml.cac :BillingReference do billing_reference&.to_xml(xml) end end unless self.class.members[:contract_document_reference_id].optional && contract_document_reference_id.nil? xml.cac :ContractDocumentReference do xml.cbc :ID, contract_document_reference_id end end unless self.class.members[:project_reference_id].optional && project_reference_id.nil? xml.cac :ProjectReference do xml.cbc :ID, project_reference_id end end additional_document_references.each { _1.to_xml(xml) } xml.cac :AccountingSupplierParty do accounting_supplier_party&.to_xml(xml) end xml.cac :AccountingCustomerParty do accounting_customer_party&.to_xml(xml) end unless self.class.members[:tax_representative_party].optional && tax_representative_party.nil? xml.cac :TaxRepresentativeParty do tax_representative_party&.to_xml(xml) end end if payment_means xml.cac :PaymentMeans do payment_means&.to_xml(xml) end end payee_party&.to_xml(xml) unless self.class.members[:payee_party].optional && payee_party.nil? unless payment_terms_note.blank? xml.cac :PaymentTerms do xml.cbc :Note, payment_terms_note end end allowance_charges.each { _1.to_xml(xml) } xml.cac :TaxTotal do tax_total&.to_xml(xml) end xml.cac :LegalMonetaryTotal do legal_monetary_total&.to_xml(xml) end invoice_lines.each { _1.to_xml(xml) } end target end |
#update_amounts ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/xrechnung.rb', line 416 def update_amounts self.tax_total = Xrechnung::TaxTotal.new invoice_lines.each do |invoice_line| tax_total.get_tax_subtotal(invoice_line.item.classified_tax_category).taxable_amount += invoice_line.line_extension_amount end allowance_charges.each do |ac| element = tax_total.get_tax_subtotal(ac.tax_category) if ac.charge_indicator element.taxable_amount += ac.amount else element.taxable_amount -= ac.amount end end tax_total.update_amounts currency_id = tax_total.tax_amount.currency_id zero = Xrechnung::Currency.new(currency_id: currency_id, value: BigDecimal(0)) legal_monetary_total.line_extension_amount = zero legal_monetary_total.allowance_total_amount = zero legal_monetary_total.charge_total_amount = zero legal_monetary_total.prepaid_amount ||= zero invoice_lines.each do |line| legal_monetary_total.line_extension_amount += line.line_extension_amount end allowance_charges.each do |ac| if ac.charge_indicator legal_monetary_total.charge_total_amount += ac.amount else legal_monetary_total.allowance_total_amount += ac.amount end end legal_monetary_total.tax_exclusive_amount = legal_monetary_total.line_extension_amount + legal_monetary_total.charge_total_amount - legal_monetary_total.allowance_total_amount legal_monetary_total.tax_inclusive_amount = legal_monetary_total.tax_exclusive_amount + tax_total.tax_amount legal_monetary_total.payable_amount = legal_monetary_total.tax_inclusive_amount - legal_monetary_total.prepaid_amount end |