From e40e11ab0c1b23f3c5581d2b2aac44c04f8232b4 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 27 Jul 2009 16:33:00 +0100 Subject: [PATCH] bug 3481: Allow Item Temporary Locations for Processing and Shelving. Allows temporary locations corresponding to 'in processing' and 'shelving' so that newly-created items, and newly-returned items do not show immediately as a available. Three new system preferences govern the usage of these features. NewItemsDefaultLocation. If system pref NewItemsDefaultLocation is set to a location code, all newly catalogued items will be set to the location set in this preference. Location code must be a valid LOC authorized value type. InProcessingToShelvingCart. if the system pref InProcessingToShelvingCart is turned on, any items run through returns.pl with a location code for 'PROC', will be modified to have a new location code of 'CART'. ReturnToShelvingCart. If the syspref ReturnToShelvingCart is turned on, all items returned other than confirmed holds will have a new location code of 'CART'. Any item issued is automatically taken of the shelving cart. Adds a cron script shelf_to_cart.pl which should be run hourly. Updates all items with a location of CART to the item's permanent location. The original location code is stored in the new items column 'permanent_location'. Original Author: PTFS Contractor This work co-sponsored by Middletown Township Public Library, Middletown, NJ USA and East Brunswick Public Library, East Brunswick, NJ USA Signed-off-by: Colin Campbell Signed-off-by: Galen Charlton --- C4/Circulation.pm | 3 + C4/Items.pm | 27 ++++++++ C4/Reserves.pm | 8 +++ cataloguing/additem.pl | 20 ++++-- circ/returns.pl | 17 +++++ .../data/mysql/en/mandatory/sysprefs.sql | 3 + .../unimarc_standard_systemprefs.sql | 3 + installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 10 +++ kohaversion.pl | 2 +- misc/cronjobs/cart_to_shelf.pl | 69 +++++++++++++++++++ 11 files changed, 156 insertions(+), 7 deletions(-) create mode 100755 misc/cronjobs/cart_to_shelf.pl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b1a6e265ae..30b22e0718 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1000,6 +1000,9 @@ sub AddIssue { C4::Context->userenv->{'branch'} # branchcode ); $sth->finish; + if ( C4::Context->preference('ReturnToShelvingCart') ) { ## ReturnToShelvingCart is on, anything issued should be taken off the cart. + CartToShelf( '', $barcode ); + } $item->{'issues'}++; ModItem({ issues => $item->{'issues'}, holdingbranch => C4::Context->userenv->{'branch'}, diff --git a/C4/Items.pm b/C4/Items.pm index 91337566e1..3bf48d7470 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -19,6 +19,7 @@ package C4::Items; use strict; +use Carp; use C4::Context; use C4::Koha; use C4::Biblio; @@ -62,6 +63,8 @@ BEGIN { GetItemsInfo get_itemnumbers_of GetItemnumberFromBarcode + + CartToShelf ); } @@ -153,6 +156,30 @@ sub GetItem { return $data; } # sub GetItem +sub CartToShelf { + my ( $itemnumber, $barcode ) = @_; + + my ( $field, $value ); + + if ( $itemnumber ) { + $field = 'itemnumber'; + $value = $itemnumber; + } elsif ( $barcode ) { + $field = 'barcode'; + $value = $barcode; + } else { + $barcode ||= 'UNDEFINED'; + $itemnumber ||= 'UNDEFINED'; + croak "FAILED CartToShelf( $itemnumber, $barcode )"; + } + + my $sql = "UPDATE items SET items.location = items.permanent_location WHERE $field = ?"; + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare( $sql ); + $sth->execute( $value ); +} + =head2 AddItemFromMarc =over 4 diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 9ee753c9e0..861003633b 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -937,6 +937,10 @@ sub ModReserveStatus { "; my $sth_set = $dbh->prepare($query); $sth_set->execute( $newstatus, $itemnumber ); + + if ( C4::Context->preference("ReturnToShelvingCart") && $newstatus ) { + CartToShelf( $itemnumber ); + } } =item ModReserveAffect @@ -995,6 +999,10 @@ sub ModReserveAffect { $sth->execute( $itemnumber, $borrowernumber,$biblionumber); _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber ) if ( !$transferToDo && !$already_on_shelf ); + if ( C4::Context->preference("ReturnToShelvingCart") ) { + CartToShelf( $itemnumber ); + } + return; } diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index f98ee552b7..d5bf07e731 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -198,12 +198,20 @@ if ($op eq "additem") { } # Adding the item - my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber); - - # We count the item only if it was really added - # That way, all items are added, even if there was some already existing barcodes - # FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode - $i++ unless ($exist_itemnumber); + if (!$exist_itemnumber) { + my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber); + + # We count the item only if it was really added + # That way, all items are added, even if there was some already existing barcodes + # FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode + $i++; + if ( C4::Context->preference('NewItemsDefaultLocation') ) { + my $item = GetItem( $oldbibitemnum ); + $item->{'permanent_location'} = $item->{'location'}; + $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation'); + ModItem( $item, $oldbiblionumber, $oldbibitemnum ); + } + } # Preparing the next iteration $oldbarcode = $barcodevalue; diff --git a/circ/returns.pl b/circ/returns.pl index dc2ad39411..cadfc7d88a 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -179,6 +179,23 @@ if ($barcode) { $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter'); $itemnumber = GetItemnumberFromBarcode($barcode); + if ( C4::Context->preference("InProcessingToShelvingCart") ) { + my $item = GetItem( '', $barcode ); + if ( $item->{'location'} eq 'PROC' ) { + $item->{'location'} = 'CART'; + ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} ); + } + } + + if ( C4::Context->preference("ReturnToShelvingCart") ) { + my $item = GetItem( '', $barcode ); + $item->{'location'} = 'CART'; + ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} ); + } + +# +# save the return +# ( $returned, $messages, $issueinformation, $borrower ) = AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode); # do the return diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index b7dd84663a..31b74d96e5 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -251,3 +251,6 @@ INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('S INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelAutoPrint', '0', '', 'If this setting is turned on, a print dialog will automatically pop up for the quick spine label printer.', 'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSPrivateKey','','See: http://aws.amazon.com. Note that this is required after 2009/08/15 in order to retrieve any enhanced content other than book covers from Amazon.','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','100','Fine Limit above which user canmot renew books via OPAC','','Integer'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'NewItemsDefaultLocation', '', '', 'If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )', ''); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'InProcessingToShelvingCart', '0', '', 'If set, when any item with a location code of PROC is ''checked in'', it''s location code will be changed to CART.', 'YesNo'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ReturnToShelvingCart', '0', '', 'If set, when any item is ''checked in'', it''s location code will be changed to CART.', 'YesNo'); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql index ef148d557a..5c1c42cef7 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql @@ -253,3 +253,6 @@ INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('S INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelAutoPrint', '0', '', 'If this setting is turned on, a print dialog will automatically pop up for the quick spine label printer.', 'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSPrivateKey','','Voir: http://aws.amazon.com. Notez que cela est nécessaire après le 15 Aout 2009 pour pouvoir utiliser les webservices Amazon autre que les couvertures de livre.','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','100','amende limite ci-dessus le lecteur ne peut pas renouveler par l\'OPAC','','Integer'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'NewItemsDefaultLocation', '', '', 'Ce qui permit tous les nouveaux exemplaires reçus à l\'emplacement de la valeur donnée', ''); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'InProcessingToShelvingCart', '0', '', 'Si défini, quand un exemplaire avec localisation de PROC est renvoyé son code sera modifié pour CART.', 'YesNo'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ReturnToShelvingCart', '0', '', 'Si défini, quand un exemplaire est renvoyé son code sera modifié pour CART.' 'YesNo'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 591ab58a99..1650802548 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1183,6 +1183,7 @@ CREATE TABLE `items` ( `paidfor` mediumtext, `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `location` varchar(80) default NULL, + `permanent_location` varchar(80) default NULL, `onloan` date default NULL, `cn_source` varchar(10) default NULL, `cn_sort` varchar(30) default NULL, diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e80e8600d5..c2089c5d72 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -2510,6 +2510,16 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n"; } +$DBversion = '3.01.00.043'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE items ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location'); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'NewItemsDefaultLocation', '', '', 'If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )', '')"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'InProcessingToShelvingCart', '0', '', 'If set, when any item with a location code of PROC is ''checked in'', it''s location code will be changed to CART.', 'YesNo')"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ReturnToShelvingCart', '0', '', 'If set, when any item is ''checked in'', it''s location code will be changed to CART.', 'YesNo')"); + SetVersion ($DBversion); + print "Upgrade to $DBversion done (amended Item added NewItemsDefaultLocation, InProcessingToShelvingCart, ReturnToShelvingCart sysprefs)\n"; +} + =item DropAllForeignKeys($table) Drop all foreign keys of the table $table diff --git a/kohaversion.pl b/kohaversion.pl index 5367044592..9701165cce 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -10,7 +10,7 @@ use strict; sub kohaversion { - our $VERSION = '3.01.00.042'; + our $VERSION = '3.01.00.043'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install diff --git a/misc/cronjobs/cart_to_shelf.pl b/misc/cronjobs/cart_to_shelf.pl new file mode 100755 index 0000000000..5b2b7436a6 --- /dev/null +++ b/misc/cronjobs/cart_to_shelf.pl @@ -0,0 +1,69 @@ +#!/usr/bin/perl +#----------------------------------- +# Copyright 2009 PTFS Inc. +# +# This file is part of Koha. +# +# 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 2 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, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA +#----------------------------------- + +=head1 NAME + +cart_to_shelf.pl cron script to set items with location of CART to original shelving location after X hours. + Execute without options for help. + +=cut + +use strict; +use warnings; + +BEGIN { + + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/../kohalib.pl" }; +} +use C4::Context; +use Getopt::Long; + +my $hours = 0; + +GetOptions( 'h|hours=s' => \$hours, ); + +my $usage = << 'ENDUSAGE'; +longoverdue.pl : This cron script will set any item of the location CART ( Shelving Cart ) to it's original shelving location + after the given numer of hours has passed. + +This script takes the following parameters : + + --hours | -h The number of hours that need to pass before the location is updated. + + examples : + $PERL5LIB/misc/cronjobs/cart_to_shelf.pl --hours 24 + Would make any item that has a location of CART for more than 24 hours change to it's original shelving location. + +ENDUSAGE + +unless ($hours) { + print $usage; + die "ERROR: No --hours (-h) option defined"; +} + +my $query = +"UPDATE items SET location = permanent_location WHERE location = 'CART' AND TIMESTAMPDIFF(HOUR, items.timestamp, NOW() ) > ?"; + +my $dbh = C4::Context->dbh; +my $sth = $dbh->prepare($query); +$sth->execute($hours); -- 2.39.5