Overdue Notice Enhancement

This development is sponsored by the Halland County Library in Sweden. Their goals are to : 
*manage a reminder fee when a reminder is sent 
*manage different reminder delays depending on whether the item is reserved or not, and is free of charge or has a rental fee.
This work will be based on a previous development inLibro did to manage invoices and fixed costs that goes along (http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11092) . We will re-work it for a better integration. 
The requirements were thought to comply Halland County Library needs but also to be flexible and fulfil different settings. We also paid attention to keep Koha's behaviour, so libraries can keep their original set up if they doesn't need these new features. 
To sum it up, the purpose of this development is to : 
*improve the management of the replacement cost and manage fixed costs for each item lost (processing fee) 
*manage a fee for each reminder sent 
*create new tags to manage fees/fines within the notice template tool 
*manage more than 3 notification levels 
*enhance the notice triggers tools with two new options : item type and on-hold status
We cut out the development in 5 features independant from each other. It will help the testing and the upstream to Koha main. 
 
 
 
 
= Changings in the overdue_notices.pl script =
==1 How do I know which letter should be sent?==
===1.1 Current===
The overdue_notice.pl script looks at the components of the rules in this order :
* for each branch
** for each rule of this branch
*** for each period (delay 1, 2, 3)
**** for every borrower who has a current loan
******the script looks for a copy that meets the rule (-t) or a period (without -t).
===1.2 Now===
The overdue_notice.pl script will look at the issues in the database (table issues) and look if a rule applies.
It will test each components of the rule in this order :
*Library branch
**User Category
***Item type
****"Reserved" status
*****Delay
******for every borrower who has a current loan
*******the script looks for a copy that meets the rule (-t) or a period (without -t).
The rules will apply from the most specific to the most general. 
To help you to understand, you can ask yourself these questions :
Is there a rule for :
*this library, this patron type, this item type, the « on-hold » status checked?
If not, is there a rule for :
*this library, this patron type, this item type?
If not, is there a rule for :
*this library, this patron type, all item types, the « on-hold » status checked ? 
If not, is there a rule for :
*this library, this patron type, all item types ? 
If not, is there a rule for :
*this library, all patron types, this item type, the « on-hold » status checked ? 
If not, is there a rule for :
*this library, all patron types, this item type ? 
If not, is there a rule for :
*this library, all patron types, all item types, the « on-hold » status checked ? 
If not, is there a rule for :
*this library, all patron types, all item types ? 
If not, is there a rule for :
*all libraries, this patron type, this item type, the « on-hold » status checked ? 
If not, is there a rule for :
*all libraries, this patron type, this item type ? 
If not, is there a rule for :
*all libraries, this patron type, all item types, the « on-hold » status checked ? 
If not, is there a rule for : 
*all libraries, this patron type, all item types ? 
If not, is there a rule for :
*all libraries, all patron types, this item type, the « on-hold » status checked ? 
If not, is there a rule for :
*all libraries, all patron types, this item type ? 
If not, is there a rule for :
*all libraries, all patron types, all item types, the « on-hold » status checked ? 
If not, is there a rule for :
*all libraries, all patron types, all item types ? 
Than, when the script find a rule that applies, it deals with the delay. 
The script compares the overdue delay with the rule's delay. If the overdue delay is equal or greater to the rule's delay, the issue is placed in the notification. 
For the same user, overdue items will be grouped by letter code and branch.
==2 How are the rules by library implemented?==
===2.1 Current===
The tool "Overdue notice / status triggers" can define rules for a default library and rules for specific libraries.
The default rules and the specific rules are mutually exclusive. If a rule does not exist for a specific library, overdue notice does not look at the rule of the default library.
The rules of the default library match the rules that apply to all libraries EXCEPT if at least one rule is set up for a specific library. In this case, only the rules of that specific library apply.
===2.2 Now===
The overdue_notices.pl script looks at the rules from the more specific to the more general. If a rule does not exist for a specific library, the script will look at the rules for the default library. If a library wants to avoid this control, they will have to set up a "no notification" rule.
==3 How does the script find on-hold items?==
The script looks at the biblionumber to know whether the issue is on hold or not. This way, no matter what kind of hold the patron put on the item (the next available item or a specific item), the script will be able to retreive the hold.
However, if a library manage holds on specific items to allow users to put hold on specific serial issues, the script will not be able to apply different rules (“on-hold” rule or “not on-hold” rule) if a specific item is on hold or not.
For example :
On one specific serial title :
*copy n3 is late.
*a hold is placed on copy n4.
*the script applies the “on-hold” rule because it relies on the biblionumber of the copy n4 which is the same of copy n3.
==4 What happens when the script groups messages that have the same letter code but different transport types?==
If at time “t”, we have an issue that matches a 7 days rule and another issue that match a 14 days rule. 
1. The issues whose rules have the same letter code will be group together in the same notification.
2. The notifications that have the same transport types will be grouped as well.
For example:
*Branch A / Item type A / User category A / 7 days / ODUE / Email
*Branch A / Item type A / User category A / 14 days / ODUE / Email
Because the two rules have the same ODUE letter code, at time t, the script will group the issues that match these rules.
Because both rules also have the same type of transportation (email), at time t, the script will send only one email.
===Comments :===
The issues will not be grouped if the rules that apply are rules for different libraries. The issues from the library A will be sent with the issues from the library A, the issues from the library B with those from the library B, etc.
===Limitation :===
When the invoice is generated, it is based on fines which have already been generated and the script only displays those. The script will check the date of entry into the database. So it is mandatory to run the fines.pl script just before running overdue_notices.pl the same day. Otherwise, the invoice will be empty. It only displays the today's entries .
=Complete Overdue_notices.pl test plan=
TEST 	THE PATRON HAS 	OVERDUE RULES (library / patron category / item type / on hold – delay – letter code) 	I SHOULD GET
classic rules 	1 DVD from Midway (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Midway
classic rules 	1 DVD from Centerville (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Centerville
classic rules 	1 CD à Midway (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Midway
classic rules 	1 CD from Centerville (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Centerville
classic rules 	2 DVD from Midway (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 DVD from Centerville (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Midway & 1 ODUE letter from Centerville
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Midway (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Centerville (7 days late) 	* / * / * - 7j. - ODUE 	1 ODUE letter from Midway & 1 ODUE letter from Centerville
classic rules 	1 DVD from Midway (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUEDVD letter from Midway
classic rules 	1 DVD from Centerville (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUEDVD letter from Centerville
classic rules 	1 CD from Midway (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUE letter from Midway
classic rules 	1 CD from Centerville (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUE letter from Centerville
classic rules 	2 DVD from Midway (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUEDVD letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 DVD from Centerville (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUEDVD letter from Midway & 1 ODUEDVD letter from Centerville
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Midway (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUEDVD letter from Midway & 1 ODUE letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Centerville (7 days late) 	* / * / DVD – 7j. - ODUEDVD 	1 ODUEDVD letter from Midway & 1 ODUE letter from Centerville
classic rules 	1 DVD from Midway (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUEBDVD letter from Midway
classic rules 	1 DVD from Centerville (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUEBDVD letter from Centerville
classic rules 	1 CD from Midway (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUE letter from Midway
classic rules 	1 CD from Centerville (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUE letter from Centerville
classic rules 	2 DVD from Midway (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUEBDVD letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 DVD from Centerville (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUEBDVD letter from Midway & 1 ODUEBDVD letter from Centerville
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Midway (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUEBDVD letter from Midway & 1 ODUE letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Centerville (7 days late) 	* / BOARD / DVD – 7j. ODUEBDVD 	1 ODUEBDVD letter from Midway & 1 ODUE letter from Centerville
classic rules 	1 DVD from Midway (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUEMIDBDVD letter from Midway
classic rules 	1 DVD from Centerville (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUEBDVD letter from Centerville
classic rules 	1 CD from Midway (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUE letter from Midway
classic rules 	1 CD from Centerville (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUE letter from Centerville
classic rules 	2 DVD from Midway (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUEMIDBDVD letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 DVD from Centerville (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUEMIDBDVD letter from Midway & 1 ODUEBDVD letter from Centerville
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Midway (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUEMIDBDVD letter from Midway & 1 ODUE letter from Midway
classic rules 	1 DVD from Midway (7 days late) & 1 CD from Centerville (7 days late) 	MIDWAY / BOARD / DVD – 7j. ODUEMIDBDVD 	1 ODUEMIDBDVD letter from Midway & 1 ODUE letter from Centerville
letter merging 	1 DVD from Midway (7 days late) & 1 CD from Midway (7 days late)& 1 DVD from Centerville (7 days late) 	Midway / * / DVD – 7j – ODUE & Midway / * / CD – 7j – ODUE & Centerville / * / DVD – 7j – ODUE 	1 letter from Midway & 1 letter from Centerville
letter merging 	1 DVD from Midway (7 days late) & 1 CD from Midway (7 days late) & 1 DVD from Centerville (7 days late)	Midway / * / DVD – 7j – ODUE & Midway / * / CD – 7j – ODUECD & Centerville / * / DVD – 7j – ODUE 	1 letter for the DVD from Midway & 1 letter for the CD from Midway & 1 letter for the DVD from Centerville
letter merging 	1 DVD from Midway (7 days late) & 1 CD from Midway (14 days late) & 1 DVD from Centerville (7 days late)	Midway / * / DVD – 7j – ODUE & Midway / * / CD – 7j – ODUE & Midway / * / CD – 14j – ODUE & Centerville / * / DVD – 7j – ODUE 	1 letter from Midway (with 7 and 14 days late items) & 1 letter from Centerville
letter merging 	1 DVD from Midway (7 days late) & 1 CD from Midway (14 days late) & 1 DVD from Centerville (7 days late)	Midway / * / DVD – 7j – ODUE & Midway / * / CD – 7j – ODUECD & Midway / * / CD – 14j – ODUECD & Centerville / * / DVD – 7j – ODUE	1 letter for the DVD from Midway & 1 letter pour le CD from Midway & 1 letter from Centerville
on hold status 	1 DVD from Midway (7 days late) – on hold 	MIDWAY / * / DVD – 7j – ODUE 	No letter
on hold status 	1 DVD from Midway (7 days late) – on hold 	MIDWAY / * / DVD– on hold – 7j – ODUE 	1 letter
on hold status 	1 DVD from Midway (7 days late) – on hold & 1 DVD from Midway (7 days late) – not on hold 	MIDWAY / * / DVD – on hold – 7j – ODUE & MIDWAY / * / DVD – 7j – ODUE 	1 letter with 2 items
on hold status 	1 DVD from Midway (7 days late) – on hold & 1 DVD from Midway (7 days late) – not on hold 	MIDWAY / * / DVD – on hold – 7j - ODUE & MIDWAY / * / DVD – 7j – ODUECD 	2 letters with 1 item each
Restrict option	1 DVD from Midway (7 days late) 	MIDWAY / * / DVD – 7j – restrict – ODUE 	1 letter and the borrower account is restricted
Category:RFCs