Class: ZATCA::UBL::CommonAggregateComponents::TaxTotal

Inherits:
BaseComponent
  • Object
show all
Defined in:
lib/zatca/ubl/common_aggregate_components/tax_total.rb

Constant Summary

Constants inherited from BaseComponent

BaseComponent::ArrayOfBaseComponentOrNil

Instance Attribute Summary

Attributes inherited from BaseComponent

#attributes, #index, #value

Instance Method Summary collapse

Methods inherited from BaseComponent

#[], build, #build_xml, #dig, #find_nested_element_by_path, #generate_xml, #schema, #to_h, #to_xml

Constructor Details

#initialize(tax_amount:, tax_subtotal_amount: nil, taxable_amount: nil, rounding_amount: nil, tax_category: nil, currency_id: "SAR") ⇒ TaxTotal

<cac:TaxTotal> <cbc:TaxAmount currencyID=“SAR”>144.9</cbc:TaxAmount> <cac:TaxSubtotal>

<cbc:TaxableAmount currencyID="SAR">966.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID="SAR">144.90</cbc:TaxAmount>
<cac:TaxCategory>
    <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5305">S</cbc:ID>
    <cbc:Percent>15.00</cbc:Percent>
    <cac:TaxScheme>
        <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5153">VAT</cbc:ID>
    </cac:TaxScheme>
</cac:TaxCategory>

</cac:TaxSubtotal> </cac:TaxTotal>



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zatca/ubl/common_aggregate_components/tax_total.rb', line 17

def initialize(
  tax_amount:, tax_subtotal_amount: nil, taxable_amount: nil,
  rounding_amount: nil, tax_category: nil, currency_id: "SAR"
)
  super()

  @tax_amount = tax_amount
  @tax_subtotal_amount = tax_subtotal_amount
  @taxable_amount = taxable_amount
  @rounding_amount = rounding_amount
  @tax_category = tax_category || ZATCA::UBL::CommonAggregateComponents::TaxCategory.new
  @currency_id = currency_id
end

Instance Method Details

#elementsObject



51
52
53
54
55
56
57
# File 'lib/zatca/ubl/common_aggregate_components/tax_total.rb', line 51

def elements
  [
    ZATCA::UBL::BaseComponent.new(name: "cbc:TaxAmount", value: @tax_amount, attributes: {"currencyID" => @currency_id}),
    rounding_amount_element,
    tax_subtotal_element
  ]
end

#nameObject



31
32
33
# File 'lib/zatca/ubl/common_aggregate_components/tax_total.rb', line 31

def name
  "cac:TaxTotal"
end

#rounding_amount_elementObject



45
46
47
48
49
# File 'lib/zatca/ubl/common_aggregate_components/tax_total.rb', line 45

def rounding_amount_element
  if @rounding_amount.present?
    ZATCA::UBL::BaseComponent.new(name: "cbc:RoundingAmount", value: @rounding_amount, attributes: {"currencyID" => @currency_id})
  end
end

#tax_subtotal_elementObject



35
36
37
38
39
40
41
42
43
# File 'lib/zatca/ubl/common_aggregate_components/tax_total.rb', line 35

def tax_subtotal_element
  if @taxable_amount.present? && @tax_subtotal_amount.present? && @tax_category.present?
    ZATCA::UBL::BaseComponent.new(name: "cac:TaxSubtotal", elements: [
      ZATCA::UBL::BaseComponent.new(name: "cbc:TaxableAmount", value: @taxable_amount, attributes: {"currencyID" => @currency_id}),
      ZATCA::UBL::BaseComponent.new(name: "cbc:TaxAmount", value: @tax_subtotal_amount, attributes: {"currencyID" => @currency_id}),
      @tax_category
    ])
  end
end