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) ⇒ 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)

    nil for standard/zero, :reverse_charge for AE

  • 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



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

#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

#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.



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_amountObject

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_percentObject



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