Bug 2720 - Overdues which debar automatically should undebar automatically when returned

This patch adds a more extensible and flexible debarments system to Koha. The fields
borrowers.debarred and borrowers.debarredcomment are retained for compatibility and
speed.

This system supports having debarments for multiple reasons. There are currently
three types of debarments:
OVERDUES    - Generated by overdue_notices.pl if the notice should debar a patron
SUSPENSION  - A punative debarment generated on checkin via an issuing rule
MANUAL      - A debarment created manually by a librarian

OVERDUE debarments are cleared automatically when all overdue items have been returned,
if the new system preference AutoRemoveOverduesRestrictions is enabled. It is disabled
by default to retain current default functionality.

Whenever a borrowers debarments are modified, the system updates the borrowers debarment
fields with the highest expiration from all the borrowers debarments, and concatenates
the comments from the debarments together.

Test plan:
 1) Apply patch
 2) Run updatedatabase.pl
 3) Verify the borrower_debarments table has been created and
    populated with the pre-existing debarments
 4) Run t/db_dependent/Borrower_Debarments.t
 5) Manually debar a patron, with an expiration date
 6) Verify the patron cannot be issued to
 7) Add another manual debarment with a different expiration date
 8) Verify the 'restricted' message lists the date farthest into the future
 9) Add another manual debarment with no expiration date
10) Verify the borrower is now debarred indefinitely
11) Delete the indefinite debarment
12) Verify the debarment message lists an expiration date dagain
13) Enable the new system preference AutoRemoveOverduesRestrictions
14) Set an overdue notice to debar after 1 day of being overdue
15) Check out an item to a patron and backdate the due date to yesterday
16) Run overdue_notices.pl
17) Verify the OVERDUES debarment was created
18) Return the item
19) Verify the OVERDUES debarment was removed
20) Disable AutoRemoveOverduesRestrictions
21) Repeat steps 15 though 18, verify the OVERDUES debarment was *not* removed
22) Add issuing rules so that an overdue item causes a temporary debarment
23) Check out an item to a patron and backdate the due date by a year
24) Return the item
25) Verify the SUSPENSION debarment was added to the patron

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) improve data entry form for manual restrictions

This follow-up to Bug 2720 makes some template changes which I think
make the interface a little more consistent and streamlined.

Instead of incorporating the manual entry form into the table it is
broken out and follows standard form structure. This lets the table be
hidden altogether if there are no existing restrictions.

The manual entry form is hidden by default and shown when you click a
link to add a manual restriction.

These changes have been applied to both the include file used for
circulation and patron detail and to the patron entry form template.

To test, add and remove manual restrictions from the circulation page,
the patron detail page, and the patron edit page. All operations should
work correctly.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) improve unit tests

Create the patron.
Use a transaction.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) improve readability of a template

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) change license version to GPLv3+

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) fix the "remove" links

If there are more than one restriction, the "remove" links don't display
the JavaScript alert.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: DBRev 3.13.00.035

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) add foreign key from new table to borrowers

Foreign keys should be added as a matter of course for new tables.

Argubably, borrower_debarments.manager_id could also be linked to
borrowers, but this patch does not do that.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) add new table to kohastructure.sql

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) update DBIx::Class schema classes

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 2720: (follow-up) fix error that prevented sysprefs from being loaded

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 7688: (follow-up) have Serials.t create its test subscription

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9044: Provide item selection in record detail page (staff client)

This patch add a column in the items table of catalogue/detail.pl that
contains checkboxes for item selection and a drop-down list of actions
that can be executed for the selection of items.

Currently available actions are:
- Delete selected items: redirect to batch items deletion
- Modify selected items: redirect to batch items modification

Item selection is only enabled if the new syspref
StaffDetailItemSelection is ON.
Actions are not displayed if user doesn't have the right permissions.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
Further testing notes on last patch.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9044: (follow-up) Add a blank option + add missing 'for' attributes

Signed-off-by: Pierre Angot et Leila Arkab <tredok.pierre@gmail.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9044: QA followup

1/ Remove filter and sort for the checkboxes column.
2/ Enable the pref by default.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9044: (follow-up) change dropdown list into links list

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
That's the one I sign.

Comment: At first I don't know where to find links, until
I selected an item.
Works as described. No koha-qa errors.

Solved merge conflict on updatedatabase.pl

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9044: (follow-up) set the number of filters according to number of columns

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Filters now shows correctly. No errors

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script.
This feature is a little controversial as it removes
the batch edit/delete options from the menu and moves them
to the item table, additionally controlled by a system
preference. Maybe later on, we can think about the UI a bit
more, but it works nicely.

Tested with.
- SeparateHoldings and SeparateHoldingsBranch activated/deactivated.
- Search filters.
- None, both, or one of the permissions.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9044: DBRev 3.13.00.036

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9044: (follow-up) restore the toolbar menu items

This patch adds the following items back to the cataloging
toolbar:

- Edit items in batch
- Delete items in a batch

My rationale: the question of the best UI for selecting items for
batch operations is not yet settled.  Adding the ability to select
items from the bib details page is indeed useful, but as currently
implemented, it can hide the availability of the batch
edit/deletion operations if no item is yet selected.  Although
having both the toolbar items and the links that display when an
item is selected is a bit redundant, for now I think we can live
with that until we get more eyes on the UI.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Bug 9456 - Add callnumber column to the cart

This patch adds call-number sorting to the staff client cart. Sortining is enabled
on the 'Items' column which uses a custom sorting routine to sort the callnumbers.
If the sort is ascending, each column will be sorted by the highest ordered
callnumber for that row. Likewise, if the sort is descending the table will be
sorted by the lowest valued callnumber for that row.

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>