Bug 23207: Add automatic checkin feature

This patch adds the posibility to set an itemtype with automatic
checkin. It means that when the checkout is due, it will
automatically check in.

To test:
1. apply patches
2. updatedatabase
3. go to koha administration -> item types and edin an item type (from
   now on called itemtype1)
CHECK => there is a checkbox almost at the end called automatic checkin
4. check that checkbox and save
5. checkout 2 items from itemtype1 and one item from another itemtype
   (from now on called itemtype2)
6. go to mysql database console (koha-mysql) and manually set date_due = current_timestamp
   in issues table for the item of itemtype2 and only one of the items of
itemtype1
7. run cronjob at misc/cronjobs/automatic_checkin.pl
8. go to mysql database console again and select * from issues
SUCCESS => All issues are present except for the issue of itemtype1
which had it's date_due set to current_timestamp. That one was
automatically checked in.
9. prove t/db_dependent/Koha/Checkouts.t

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Hasina Akhter <HasinaA@pascolibraries.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Agustin Moyano 2020-12-04 18:47:31 -03:00 committed by Jonathan Druart
parent 6b1b2be4c3
commit 7439579b8b
5 changed files with 68 additions and 0 deletions

View file

@ -22,6 +22,7 @@ use Modern::Perl;
use Carp;
use C4::Context;
use C4::Circulation;
use Koha::Checkout;
use Koha::Database;
use Koha::DateUtils;
@ -62,6 +63,33 @@ sub calculate_dropbox_date {
return $dropbox_date;
}
=head3 automatic_checkin
my $automatic_checkins = Koha::Checkouts->automatic_checkin()
Checks in every due issue which itemtype has automatic_checkin enabled
=cut
sub automatic_checkin {
my ($self, $params) = @_;
my $current_date = dt_from_string;
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
my $due_checkouts = $self->search(
{ date_due => { '<=' => $dtf->format_datetime($current_date) } },
{ prefetch => 'item'}
);
while(my $checkout = $due_checkouts->next) {
if($checkout->item->itemtype->automatic_checkin) {
C4::Circulation::AddReturn($checkout->item->barcode, $checkout->branchcode);
}
}
}
=head3 type
=cut

View file

@ -99,6 +99,7 @@ if ( $op eq 'add_form' ) {
my $searchcategory = $input->param('searchcategory');
my $rentalcharge_daily_calendar = $input->param('rentalcharge_daily_calendar') // 0;
my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0;
my $automatic_checkin = $input->param('automatic_checkin') // 0;
if ( $itemtype and $is_a_modif ) { # it's a modification
$itemtype->description($description);
@ -118,6 +119,7 @@ if ( $op eq 'add_form' ) {
$itemtype->searchcategory($searchcategory);
$itemtype->rentalcharge_daily_calendar($rentalcharge_daily_calendar);
$itemtype->rentalcharge_hourly_calendar($rentalcharge_hourly_calendar);
$itemtype->automatic_checkin($automatic_checkin);
eval {
$itemtype->store;
@ -150,6 +152,7 @@ if ( $op eq 'add_form' ) {
searchcategory => $searchcategory,
rentalcharge_daily_calendar => $rentalcharge_daily_calendar,
rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar,
automatic_checkin => $automatic_checkin,
}
);
eval {

View file

@ -17,3 +17,4 @@
koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/holds/build_holds_queue.pl
koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/automatic_checkin.pl

View file

@ -380,6 +380,15 @@ Item types &rsaquo; Administration &rsaquo; Koha
</select>
<span class="hint">Select 'All libraries' if all libraries use this item type. Otherwise, select the specific libraries that use this item type.</span>
</li>
<li>
<label for="automatic_checkin">Automatic checkin: </label>
[% IF itemtype.automatic_checkin %]
<input type="checkbox" id="automatic_checkin" name="automatic_checkin" checked="checked" value="1" />
[% ELSE %]
<input type="checkbox" id="automatic_checkin" name="automatic_checkin" value="1" />
[% END %]
<span class="hint">If checked, items will be checked in automatically after a period of time. Useful for materials where you really don't care for fisical return, like museum passes, etc.</span>
</li>
<li>
<label for="summary">Summary: </label>
<textarea id="summary" name="summary" cols="55" rows="5">[% itemtype.summary | html %]</textarea>

View file

@ -0,0 +1,27 @@
#!/usr/bin/perl
# This file is part of Koha.
#
# Copyright (C) 2020 Theke Solutions
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::Checkouts;
use Koha::Script -cron;
use C4::Log;
cronlogaction();
Koha::Checkouts->automatic_checkin;