Class: Einvoicing::AllowanceCharge

Inherits:
Data
  • Object
show all
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.

Examples:

A 10% commercial discount on a 20% VAT base

Einvoicing::AllowanceCharge.new(
  amount:      BigDecimal("100.00"),
  vat_rate:    0.20,
  reason:      "Remise commerciale",
  reason_code: "95",
  base_amount: BigDecimal("1000.00"),
  percentage:  10
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount:, vat_rate: 0.20, category: nil, reason: nil, reason_code: nil, base_amount: nil, percentage: nil, exemption_reason: nil, exemption_reason_code: nil) ⇒ AllowanceCharge

Returns a new instance of AllowanceCharge.

Parameters:

  • amount (Numeric)

    BT-92 / BT-99 — always positive

  • vat_rate (Numeric) (defaults to: 0.20)

    BT-96 / BT-103 — the rate the amount applies to

  • category (Symbol, nil) (defaults to: nil)

    a key of Einvoicing::Tax::CATEGORY_CODES; nil infers standard or zero-rated from the rate

  • reason (String, nil) (defaults to: nil)

    BT-97 / BT-104

  • reason_code (String, nil) (defaults to: nil)

    BT-98 / BT-105 (UNCL5189 / UNCL7161)

  • base_amount (Numeric, nil) (defaults to: nil)

    BT-93 / BT-100

  • percentage (Numeric, nil) (defaults to: nil)

    BT-94 / BT-101

  • exemption_reason (String, nil) (defaults to: nil)

    BT-120, carried into the VAT breakdown

  • exemption_reason_code (String, nil) (defaults to: nil)

    BT-121, carried into the VAT breakdown



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

def initialize(amount:, vat_rate: 0.20, category: nil, reason: nil,
               reason_code: nil, base_amount: nil, percentage: nil,
               exemption_reason: nil, exemption_reason_code: 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,
    exemption_reason:      exemption_reason,
    exemption_reason_code: exemption_reason_code
  )
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount

Returns:

  • (Object)

    the current value of amount



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def amount
  @amount
end

#base_amountObject (readonly)

Returns the value of attribute base_amount

Returns:

  • (Object)

    the current value of base_amount



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def base_amount
  @base_amount
end

#categoryObject (readonly)

Returns the value of attribute category

Returns:

  • (Object)

    the current value of category



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def category
  @category
end

#exemption_reasonObject (readonly)

Returns the value of attribute exemption_reason

Returns:

  • (Object)

    the current value of exemption_reason



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def exemption_reason
  @exemption_reason
end

#exemption_reason_codeObject (readonly)

Returns the value of attribute exemption_reason_code

Returns:

  • (Object)

    the current value of exemption_reason_code



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def exemption_reason_code
  @exemption_reason_code
end

#percentageObject (readonly)

Returns the value of attribute percentage

Returns:

  • (Object)

    the current value of percentage



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def percentage
  @percentage
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def reason
  @reason
end

#reason_codeObject (readonly)

Returns the value of attribute reason_code

Returns:

  • (Object)

    the current value of reason_code



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def reason_code
  @reason_code
end

#vat_rateObject (readonly)

Returns the value of attribute vat_rate

Returns:

  • (Object)

    the current value of vat_rate



22
23
24
# File 'lib/einvoicing/allowance_charge.rb', line 22

def vat_rate
  @vat_rate
end

Instance Method Details

#tax_category_codeObject

CII/UBL tax category code — delegates to shared Tax logic.



61
62
63
# File 'lib/einvoicing/allowance_charge.rb', line 61

def tax_category_code
  Tax.category_code_for(rate: vat_rate, category: category)
end

#vat_amountObject

VAT carried by this allowance/charge at its own rate.



52
53
54
# File 'lib/einvoicing/allowance_charge.rb', line 52

def vat_amount
  (amount * Tax.effective_rate(rate: vat_rate, category: category)).round(2, :half_up)
end

#vat_rate_percentObject



56
57
58
# File 'lib/einvoicing/allowance_charge.rb', line 56

def vat_rate_percent
  (Tax.effective_rate(rate: vat_rate, category: category) * 100).round(2)
end