From 10b437009d18c2c828ce266138babab80fae6c83 Mon Sep 17 00:00:00 2001 From: Omar Bahareth Date: Wed, 29 Nov 2023 15:07:46 +0300 Subject: [PATCH] Support Billing References for Credit & Debit Notes --- lib/zatca/ubl/invoice.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/zatca/ubl/invoice.rb b/lib/zatca/ubl/invoice.rb index f84d342..49f61b7 100644 --- a/lib/zatca/ubl/invoice.rb +++ b/lib/zatca/ubl/invoice.rb @@ -24,6 +24,7 @@ class ZATCA::UBL::Invoice < ZATCA::UBL::BaseComponent option :uuid, type: Dry::Types["coercible.string"] option :note, type: Dry::Types["coercible.string"].optional, optional: true, default: proc {} option :instruction_note, type: Dry::Types["coercible.string"].optional, optional: true, default: proc {} + option :billing_reference, type: Dry::Types["coercible.string"].optional, optional: true, default: proc {} option :note_language_id, type: Dry::Types["coercible.string"].optional, optional: true, default: proc {} option :issue_date, type: Dry::Types["coercible.string"] option :issue_time, type: Dry::Types["coercible.string"] @@ -110,6 +111,9 @@ def elements ZATCA::UBL::BaseComponent.new(name: "cbc:DocumentCurrencyCode", value: currency_code), ZATCA::UBL::BaseComponent.new(name: "cbc:TaxCurrencyCode", value: currency_code), + # Billing reference for debit and credit notes + billing_reference_element, + # Line Count Numeric (Standard Invoice only) line_count_numeric_element, @@ -407,6 +411,16 @@ def instruction_note_element ZATCA::UBL::BaseComponent.new(name: "cbc:InstructionNote", value: instruction_note) end + def billing_reference_element + return nil if billing_reference.blank? + + ZATCA::UBL::BaseComponent.new(name: "cac:BillingReference", elements: [ + ZATCA::UBL::BaseComponent.new(name: "cac:InvoiceDocumentReference", elements: [ + ZATCA::UBL::BaseComponent.new(name: "cbc:ID", value: billing_reference) + ]) + ]) + end + def add_sequential_ids add_sequential_ids_to_allowance_charges add_sequential_ids_to_invoice_lines