Step-by-step breakdown of how Koha calculates incremental fines for overdue items, especially with a tiered/incremental fine logic like the one used in your custom CalcFine function:
✅ Step-by-Step Custom Incremental Fine Structures in Koha Library System
1. Check if the Item is Overdue
return (0, 0, 0) unless (DateTime->compare($due_dt, $end_date) == -1);
-
If the item is not overdue, no fine is charged.
-
DateTime->compare()checks if the return date is later than the due date.
2. Determine the Item Type and Fetch Circulation Rules
$itemtype = $item->{itemtype} || $item->{itype};
$issuing_rule = Koha::CirculationRules->get_effective_rules(...);
-
This pulls the rules like:
-
fine -
chargeperiod -
firstremind(grace period) -
overduefinescap -
recall_overdue_fine -
cap_fine_to_replacement_price
-
3. Calculate Overdue Time (in units: days/hours)
my $chargeable_units = get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);
my $units_minus_grace = $chargeable_units - ($issuing_rule->{firstremind} || 0);
-
get_chargeable_units()calculates total overdue time. -
firstremindis subtracted ifFinesIncludeGracePeriodis disabled. -
If
units_minus_graceis zero or negative → No fine.
4. Determine How Many Fine Periods Apply
my $charge_periods = $units / $issuing_rule->{chargeperiod};
$charge_periods = ceil(...) or floor(...) based on `chargeperiod_charge_at`
-
Example: 20 days overdue,
chargeperiod= 1 → 20 charge periods.
5. Check for Recalls (Optional Path)
if (recall exists and issuing_rule->{recall_overdue_fine}) {
$amount = $charge_periods * recall_overdue_fine;
}
-
If the item or biblio is recalled and
recall_overdue_fineis set, use this amount per unit.
6. Apply Custom Incremental Fine Formula
If no recall, calculate based on custom tiered rate:
if ($charge_periods <= 15) {
$amount = $charge_periods * 1;
} elsif ($charge_periods > 15 && $charge_periods <= 30) {
$amount = 15 + ($charge_periods - 15) * 2;
} else {
$amount = 45 + ($charge_periods - 30) * 5;
}
🔢 Breakdown of Formula:
-
Day 1–15 → ₹1/day →
15 -
Day 16–30 → ₹2/day →
15 * 1 + 15 * 2 = ₹45 -
Day 31+ → ₹5/day →
45 + (extra days * 5)
Example:
-
40 overdue days →
15*1 + 15*2 + 10*5 = ₹15 + ₹30 + ₹50 = ₹95
7. Apply Overdue Cap (if any)
if ($amount > $issuing_rule->{overduefinescap}) {
$amount = $issuing_rule->{overduefinescap};
}
-
Maximum fine allowed per rule.
8. Apply Replacement Price Cap (if allowed)
if ($issuing_rule->{cap_fine_to_replacement_price} && $amount > $item->{replacementprice}) {
$amount = $item->{replacementprice};
}
-
This prevents fine from exceeding the item's value.
✅ Return Values
return ($amount, $units_minus_grace, $chargeable_units);
-
Final fine amount
-
Effective overdue units (after grace)
-
Total overdue time (raw)
💡 Summary Table (Incremental Fine Logic)
| Days Overdue | Rate per Day | Cumulative Fine |
|---|---|---|
| 1–15 | ₹1 | 15 * 1 = ₹15 |
| 16–30 | ₹2 | ₹15 + 15 * 2 = ₹45 |
| 31+ | ₹5 | ₹45 + (days - 30) * 5 |
Would you like this logic formatted for configuration as a policy document or admin guide for library staff?
Koha Incremental Fine Calculation Formula
Step-by-Step Overview
- Check if the item is overdue:
If the return date is after the due date, continue. - Determine overdue days:
Overdue Days = Return Date - Due Date - Apply Grace Period:
Chargeable Days = Overdue Days - First Reminder (grace days) - Calculate Fine Based on Tiers:
- Days 1–15: ₹1 per day
- Days 16–30: ₹2 per day
- Days 31+: ₹5 per day
- Apply Fine Caps:
- If
fine > overduefinescap, cap tooverduefinescap - If enabled, also cap fine to item's
replacementprice
- If
Fine Tier Breakdown
| Days Overdue | Rate per Day | Cumulative Fine |
|---|---|---|
| 1–15 | ₹1 | Up to ₹15 |
| 16–30 | ₹2 | ₹15 + (days - 15) × ₹2 |
| 31+ | ₹5 | ₹45 + (days - 30) × ₹5 |
* This stepped fine model is a custom enhancement and may differ from Koha's default flat-rate fines.
No comments:
Post a Comment