From 7439579b8b75a8b1b1a146b55c03b108df0c621d Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 4 Dec 2020 18:47:31 -0300 Subject: [PATCH] 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 Signed-off-by: Hasina Akhter Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Checkouts.pm | 28 +++++++++++++++++++ admin/itemtypes.pl | 3 ++ debian/koha-common.cron.hourly | 1 + .../prog/en/modules/admin/itemtypes.tt | 9 ++++++ misc/cronjobs/automatic_checkin.pl | 27 ++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100755 misc/cronjobs/automatic_checkin.pl diff --git a/Koha/Checkouts.pm b/Koha/Checkouts.pm index 5037e3fdf4..a7b50603d0 100644 --- a/Koha/Checkouts.pm +++ b/Koha/Checkouts.pm @@ -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 diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index a1c8001ce2..48e80f79dd 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -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 { diff --git a/debian/koha-common.cron.hourly b/debian/koha-common.cron.hourly index 4db64bbaa2..0b8c2c8bdb 100644 --- a/debian/koha-common.cron.hourly +++ b/debian/koha-common.cron.hourly @@ -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 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt index cef07a000a..1988fc4206 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -380,6 +380,15 @@ Item types › Administration › Koha Select 'All libraries' if all libraries use this item type. Otherwise, select the specific libraries that use this item type. +
  • + + [% IF itemtype.automatic_checkin %] + + [% ELSE %] + + [% END %] + 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. +
  • diff --git a/misc/cronjobs/automatic_checkin.pl b/misc/cronjobs/automatic_checkin.pl new file mode 100755 index 0000000000..4eff2d5083 --- /dev/null +++ b/misc/cronjobs/automatic_checkin.pl @@ -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 . + +use Modern::Perl; +use Koha::Checkouts; +use Koha::Script -cron; +use C4::Log; + +cronlogaction(); + +Koha::Checkouts->automatic_checkin; \ No newline at end of file -- 2.39.5