Class: ZATCA::UBL::CommonAggregateComponents::AllowanceCharge

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

Constant Summary

Constants inherited from BaseComponent

BaseComponent::ArrayOfBaseComponentOrNil

Instance Attribute Summary collapse

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(charge_indicator:, allowance_charge_reason:, amount:, currency_id: "SAR", tax_category: nil, add_tax_category: true, add_id: true, tax_categories: []) ⇒ AllowanceCharge

<cac:AllowanceCharge>

<cbc:ID>1</cbc:ID>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:AllowanceChargeReason>discount</cbc:AllowanceChargeReason>
<cbc:Amount currencyID="SAR">2</cbc:Amount>
<cac:TaxCategory>
    <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5305">S</cbc:ID>
    <cbc:Percent>15</cbc:Percent>
    <cac:TaxScheme>
        <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5153">VAT</cbc:ID>
    </cac:TaxScheme>
</cac:TaxCategory>

</cac:AllowanceCharge>



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 18

def initialize(
  charge_indicator:, allowance_charge_reason:, amount:, currency_id: "SAR",
  tax_category: nil, add_tax_category: true, add_id: true, tax_categories: []
)
  super()

  @charge_indicator = charge_indicator.to_s

  @allowance_charge_reason = allowance_charge_reason
  @amount = amount
  @currency_id = currency_id

  @add_tax_category = add_tax_category
  @tax_category = tax_category
  @add_id = add_id

  if add_tax_category && @tax_category.blank?
    @tax_category = ZATCA::UBL::CommonAggregateComponents::TaxCategory.new
  end

  @tax_categories = if @tax_category.present? && tax_categories.blank?
    [@tax_category]
  else
    tax_categories
  end
end

Instance Attribute Details

#allowance_charge_reasonObject

Returns the value of attribute allowance_charge_reason.



2
3
4
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 2

def allowance_charge_reason
  @allowance_charge_reason
end

#amountObject

Returns the value of attribute amount.



2
3
4
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 2

def amount
  @amount
end

#charge_indicatorObject

Returns the value of attribute charge_indicator.



2
3
4
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 2

def charge_indicator
  @charge_indicator
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 2

def id
  @id
end

Instance Method Details

#elementsObject



55
56
57
58
59
60
61
62
63
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 55

def elements
  [
    id_element,
    ZATCA::UBL::BaseComponent.new(name: "cbc:ChargeIndicator", value: @charge_indicator),
    ZATCA::UBL::BaseComponent.new(name: "cbc:AllowanceChargeReason", value: @allowance_charge_reason),
    ZATCA::UBL::BaseComponent.new(name: "cbc:Amount", value: @amount, attributes: {"currencyID" => @currency_id}),
    *@tax_categories
  ]
end

#id_elementObject



49
50
51
52
53
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 49

def id_element
  if @add_id && index.present?
    ZATCA::UBL::BaseComponent.new(name: "cbc:ID", value: index)
  end
end

#nameObject



45
46
47
# File 'lib/zatca/ubl/common_aggregate_components/allowance_charge.rb', line 45

def name
  "cac:AllowanceCharge"
end