Module: ZATCA::UBL::InvoiceSubtypeBuilder

Extended by:
InvoiceSubtypeBuilder
Included in:
InvoiceSubtypeBuilder
Defined in:
lib/zatca/ubl/invoice_subtype_builder.rb

Instance Method Summary collapse

Instance Method Details

#build(simplified:, third_party:, nominal:, exports:, summary:, self_billed:) ⇒ String

Builds the invoice subtype code based on the provided parameters.

Examples:

InvoiceSubtypeBuilder.build(
  simplified: true,
  third_party: false,
  nominal: true,
  exports: false,
  summary: false,
  self_billed: true
)
# => "0201001"

InvoiceSubtypeBuilder.build(
  simplified: false,
  third_party: true,
  nominal: true,
  exports: true,
  summary: true,
  self_billed: false
)
# => "0111110"

Parameters:

  • simplified (Boolean)

    Specifies whether the invoice is a simplified tax invoice.

  • third_party (Boolean)

    Specifies whether the invoice is a third-party invoice transaction.

  • nominal (Boolean)

    Specifies whether the invoice is a nominal invoice transaction.

  • exports (Boolean)

    Specifies whether the invoice is an exports invoice transaction.

  • summary (Boolean)

    Specifies whether the invoice is a summary invoice transaction.

  • self_billed (Boolean)

    Specifies whether the invoice is a self-billed invoice.

Returns:

  • (String)

    The generated invoice subtype code.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zatca/ubl/invoice_subtype_builder.rb', line 35

def build(
  simplified:,
  third_party:,
  nominal:,
  exports:,
  summary:,
  self_billed:
)
  subtype_prefix = simplified ? "02" : "01"

  values = [third_party, nominal, exports, summary, self_billed]
  values = values.map { |v| v ? "1" : "0" }

  subtype_prefix + values.join
end