Customizing Overdue Fine Calculations in Koha: A Detailed Guide
Here’s a more detailed guide on how to modify the overdue.pm file in Koha step by step, including navigating the filesystem, editing the code, and testing the changes.
Step-by-Step Detailed Guide
Step 1: Access the Koha Server
To make changes to the Koha installation, you first need to access the server where Koha is hosted. You can use SSH to log in to the server.
ssh skysivan@koha_server_ip (10.21.1.10)
- Replace username with your actual username (often
skyorkohaorroot). - Replace koha_server_ip 10.21.1.10 with the IP address or hostname of the Koha server.
Once logged in, you’ll be in the server's home directory or wherever the default shell points.
Step 2: Navigate to the Koha Directory
Koha is installed under /usr/share/koha, but the overdue.pm file is in a subdirectory. To navigate to this directory, run the following command:
cd /usr/share/koha/lib/C4/
Here’s what’s happening:
/usr/share/koha/: Main directory for Koha installation.lib/: Contains all the Perl library files for Koha.C4/: Contains C4 modules, which handle core functionalities, including overdue and fines.
If you want to list the contents of this directory to check if overdue.pm exists, run:
sudo ls /usr/share/koha/lib/C4/
You should see something like this (the output will vary based on your Koha version and installed modules):
C4.pm Overdue.pm ...
If overdue.pm is listed here, you're in the right place.
Step 3: Open the overdue.pm File for Editing
Next, open the overdue.pm file in a text editor. You can use nano for simplicity or vim if you're more comfortable with it.
sudo nano /usr/share/koha/lib/C4/Overdue.pm
sudo: Runs the command as the root user (if required).nano: The text editor./usr/share/koha/lib/C4/Overdue.pm: Full path to the file.
Once opened, you can start navigating through the code.
Step 4: Locate Line 350 in the File
You need to find the line in the code where the fine amount is calculated. According to your original question, the target line is:
$amount = $charge_periods * $issuing_rule->{fine};
To quickly find line 350, press Ctrl + _ in nano (this opens the "go to line" prompt), and type 350, then press Enter.
If you can’t locate line 350 directly, you can also scroll through the file and look for the section that calculates fines.
Step 5: Replace the Fine Calculation Logic
Once you’ve located the line, replace it with the new fine calculation logic as per your requirements. Here's the code to replace:
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;
}
Explanation:
- First condition (
$charge_periods <= 15): If thecharge_periodsis less than or equal to 15, the fine is simply$charge_periods * 1(i.e., 1 unit per day overdue). - Second condition (
$charge_periods > 15 && $charge_periods <= 30): If thecharge_periodsis greater than 15 but less than or equal to 30, the fine is calculated as \$15 for the first 15 days, plus \$2 for each additional day over 15 days. - Third condition (
$charge_periods > 30): If thecharge_periodsexceeds 30 days, the fine is calculated as \$45 for the first 30 days, plus \$5 for each additional day over 30.
Step 6: Save and Exit the File
After making the changes, save and close the file.
In nano:
- Press Ctrl + X to exit.
- When asked to save the changes, press Y for "Yes".
- Press Enter to confirm the filename and save the file.
If you're using vim, press Esc, then type :wq and press Enter to save and quit.
Step 7: Test the Changes
Now, it’s time to test your modifications. You’ll need to test whether the fine calculation is working as expected after the code change.
Test Methods:
- Direct Test in Koha: If you have access to Koha’s web interface, simulate overdue loans of various periods (e.g., 10, 20, 40 days) and check that the fine amounts appear as expected based on the rules you defined.
- Use Koha's Testing Functionality: You can create custom test cases that simulate overdue books and calculate fines.
Example test:
my $charge_periods = 10;
my $issuing_rule = { fine => 1 };
my $amount = 0;
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;
}
print "Fine: $amount\n";
Step 8: Check for Errors
If something went wrong, Koha should log the errors. To view them in real-time, run the following command:
sudo tail -f /var/log/koha/koha-error_log
Step 9: Verify the Changes in Production
Once you have confirmed everything works in the test environment, you can move forward with the changes on the production server. If you're using version control (e.g., Git), commit your changes:
git add /usr/share/koha/lib/C4/Overdue.pm
git commit -m "Modified fine calculation logic based on charge periods"
git push
Step 10: Optional – Restart Koha Services
Sometimes, after making code changes, you may need to restart Koha services to apply the changes. To do this, use the following command:
sudo systemctl restart koha-common
Conclusion
You’ve now modified the fine calculation logic in Koha. To summarize:
- You located the
overdue.pmfile. - You replaced the fine calculation code with the new rules.
- You tested the changes in a test environment.
- Finally, you verified the code and restarted the services.
Let me know if you need any further details or assistance with testing!