Class: Einvoicing::AllowanceCharge
- Inherits:
-
Data
- Object
- Data
- Einvoicing::AllowanceCharge
- Defined in:
- lib/einvoicing/allowance_charge.rb
Overview
A document-level allowance (BG-20) or charge (BG-21).
The same shape covers both: whether it is deducted or added is decided by
the array it sits in on the invoice (allowances: or charges:), so the
amount itself is always expressed as a positive value.
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#base_amount ⇒ Object
readonly
Returns the value of attribute base_amount.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#percentage ⇒ Object
readonly
Returns the value of attribute percentage.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#reason_code ⇒ Object
readonly
Returns the value of attribute reason_code.
-
#vat_rate ⇒ Object
readonly
Returns the value of attribute vat_rate.
Instance Method Summary collapse
-
#initialize(amount:, vat_rate: 0.20, category: nil, reason: nil, reason_code: nil, base_amount: nil, percentage: nil) ⇒ AllowanceCharge
constructor
A new instance of AllowanceCharge.
-
#tax_category_code ⇒ Object
CII/UBL tax category code — delegates to shared Tax logic.
-
#vat_amount ⇒ Object
VAT carried by this allowance/charge at its own rate.
- #vat_rate_percent ⇒ Object
Constructor Details
#initialize(amount:, vat_rate: 0.20, category: nil, reason: nil, reason_code: nil, base_amount: nil, percentage: nil) ⇒ AllowanceCharge
Returns a new instance of AllowanceCharge.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/einvoicing/allowance_charge.rb', line 31 def initialize(amount:, vat_rate: 0.20, category: nil, reason: nil, reason_code: nil, base_amount: nil, percentage: nil) super( amount: BigDecimal(amount.to_s), vat_rate: vat_rate, category: category, reason: reason, reason_code: reason_code, base_amount: base_amount.nil? ? nil : BigDecimal(base_amount.to_s), percentage: percentage ) end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount
22 23 24 |
# File 'lib/einvoicing/allowance_charge.rb', line 22 def amount @amount end |
#base_amount ⇒ Object (readonly)
Returns the value of attribute base_amount
22 23 24 |
# File 'lib/einvoicing/allowance_charge.rb', line 22 def base_amount @base_amount end |
#category ⇒ Object (readonly)
Returns the value of attribute category
22 23 24 |
# File 'lib/einvoicing/allowance_charge.rb', line 22 def category @category end |
#percentage ⇒ Object (readonly)
Returns the value of attribute percentage
22 23 24 |
# File 'lib/einvoicing/allowance_charge.rb', line 22 def percentage @percentage end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason
22 23 24 |
# File 'lib/einvoicing/allowance_charge.rb', line 22 def reason @reason end |
#reason_code ⇒ Object (readonly)
Returns the value of attribute reason_code
22 23 24 |
# File 'lib/einvoicing/allowance_charge.rb', line 22 def reason_code @reason_code end |
#vat_rate ⇒ Object (readonly)
Returns the value of attribute vat_rate
22 23 24 |
# File 'lib/einvoicing/allowance_charge.rb', line 22 def vat_rate @vat_rate end |
Instance Method Details
#tax_category_code ⇒ Object
CII/UBL tax category code — delegates to shared Tax logic.
56 57 58 |
# File 'lib/einvoicing/allowance_charge.rb', line 56 def tax_category_code Tax.category_code_for(rate: vat_rate, category: category) end |
#vat_amount ⇒ Object
VAT carried by this allowance/charge at its own rate.
45 46 47 |
# File 'lib/einvoicing/allowance_charge.rb', line 45 def vat_amount (amount * BigDecimal(vat_rate.to_s)).round(2, :half_up) end |
#vat_rate_percent ⇒ Object
49 50 51 52 53 |
# File 'lib/einvoicing/allowance_charge.rb', line 49 def vat_rate_percent return BigDecimal("0") if category == :reverse_charge (BigDecimal(vat_rate.to_s) * 100).round(2) end |