Bug 8918: Fix reserve priority in ILS-DI

The priority of new hold requests was not calculated when using ILS-DI.

A new routine is added, C4::Reserves::CalculatePriority(), to calculate
the priority prior to placing a request.

A separate bug report, 11640, covers the changes in reserves to
use this new routine more generally.

This patch does therefore only affect ILS-DI.

Note: ILS-DI already allows you to generate multiple holds on a biblio or
item for the same patron. This patch does not change that behavior.

Test plan:
[1] Place multiple holds using ILS-DI HoldTitle service:
    /cgi-bin/koha/ilsdi.pl?service=HoldTitle&patron_id=BORROWERNUMBER&bib_id=BIBLIONUMBER&request_location=test
    Check the priority.
[2] Do the same using HoldItem service:
    /cgi-bin/koha/ilsdi.pl?service=HoldItem&patron_id=BORROWERNUMBER&bib_id=BIBLIONUMBER&item_id=ITEMNUMBER
    Check the priority again.
[3] Use a biblio with multiple items. Place item level holds on both.
    Check in one of these items in another branch. Confirm transfer.
    Check in the other item in the original branch. Confirm hold.
    Now you have a waiting and a transit hold.
    Test HoldTitle and HoldItem service again a few times.
[4] Enable AllowHoldDateInFuture and add a future hold.
    Now test HoldTitle and HoldItem again and check if these holds are
    inserted before the future hold (lower priority).

January 29, 2014: Rebased this patch and amended it to make a distinction
between fixing the ILS-DI bug and using the new routine.
Updated commit message and test plan (marcelr).

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 3e344d7e0718e5a8ac810ca5235f68c1e6d3f370)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 8918: (follow-up) improve descriptions of two related sysprefs

Updating pref descriptions for ReservesNeedReturns and ILS-DI:AuthorizedIPs.
Just sideway related to this report, but not important enough to separate.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 5372082724002476bc7565f7c66a7e6aaa06c24b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 8918: Add a unit test for CalculatePriority

Rebased on January 29, 2014 (marcelr)
Added text on the two 'is'-statements.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 52924e7b0ecddcceec8d22299e8fa4c5f04a991a)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 8918: (follow-up)  more unit tests for CalculatePriority

Adding a few unit tests, including the following situations:
Placing a hold when there is a wait.
Placing a hold when there is a future hold.
Calculating priority with future date.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 9b9fd8597945d221d9d89d6ae6517c0c65179232)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 8918: (follow-up) allow t/db_dependent/Reserves.t to pass if marcflavour is UNIMARC

Set marcflavour to MARC21 to make tests pass.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Works for MARC21. But I would prefer a better fix for UNIMARC.
Will send a follow-up for that.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit adc09764bc90c34300444c5ea43bfd040f0d571d)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 8918: (follow-up) support creating brief UNIAMRC bibs in Reserves.t

Changed title and author field for UNIMARC.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Tested for MARC21, NORMARC and UNIMARC by adding temporary set_preference..

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 5f8bef581d5170a4a5c7a965379264d78935041f)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Bug 8918: (follow-up) tidy code and description of CalculatePriority()

This patch improves the formatting and the description of the new
CalculatePriority() routine.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit e51b44178141ddd32134758d20d388c648fb0dfd)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>