Module: HrLite::Money
- Defined in:
- lib/hr_lite/money.rb
Overview
Central rounding discipline. Each statutory line rounds by its own rule exactly once; nets are plain subtraction of already-rounded lines.
Class Method Summary collapse
-
.ceil_rupee(value) ⇒ Object
Next rupee (ESIC rounds contributions UP).
- .d(value) ⇒ Object
-
.format(amount) ⇒ Object
Indian digit grouping: 12,34,567 — not the western 1,234,567.
-
.round2(value) ⇒ Object
Paise precision (earnings proration).
-
.round_rupee(value) ⇒ Object
Nearest rupee, half-up (PF, TDS monthly).
-
.round_to_10(value) ⇒ Object
Section 288B: annual tax to the nearest ten rupees.
Class Method Details
.ceil_rupee(value) ⇒ Object
Next rupee (ESIC rounds contributions UP).
19 20 21 |
# File 'lib/hr_lite/money.rb', line 19 def ceil_rupee(value) d(value).ceil(0) end |
.d(value) ⇒ Object
7 8 9 10 11 |
# File 'lib/hr_lite/money.rb', line 7 def d(value) return BigDecimal(0) if value.nil? value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s) end |
.format(amount) ⇒ Object
Indian digit grouping: 12,34,567 — not the western 1,234,567. It lives here rather than only in the view helper because the slip PDF is rendered by HOST code (config.render_pdf), where engine helpers are out of scope — which is why the PDF printed a bare "75000.0" next to the web slip's "₹75,000.00".
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/hr_lite/money.rb', line 38 def format(amount) return "—" if amount.nil? whole, fraction = round2(amount).to_s("F").split(".") sign = whole.start_with?("-") ? "-" : "" whole = whole.delete_prefix("-") if whole.length > 3 head = whole[0..-4].reverse.scan(/\d{1,2}/).join(",").reverse whole = "#{head},#{whole[-3..]}" end "#{sign}#{HrLite.config.currency_symbol}#{whole}.#{fraction.ljust(2, '0')}" end |
.round2(value) ⇒ Object
Paise precision (earnings proration).
24 25 26 |
# File 'lib/hr_lite/money.rb', line 24 def round2(value) d(value).round(2) end |
.round_rupee(value) ⇒ Object
Nearest rupee, half-up (PF, TDS monthly).
14 15 16 |
# File 'lib/hr_lite/money.rb', line 14 def round_rupee(value) d(value).round(0, BigDecimal::ROUND_HALF_UP) end |
.round_to_10(value) ⇒ Object
Section 288B: annual tax to the nearest ten rupees.
29 30 31 |
# File 'lib/hr_lite/money.rb', line 29 def round_to_10(value) (d(value) / 10).round(0, BigDecimal::ROUND_HALF_UP) * 10 end |