[Koha-patches] [PATCH] Author: PTFS Contractor <dbavousett at ptfs.com> Date: Thu May 7 17:11:06 2009 -0400

Colin Campbell colin.campbell at ptfs-europe.com
Sun Jul 26 18:26:00 CEST 2009


Allow Item Temporary Locations.

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'.

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 <colin.campbell at ptfs-europe.com>
---
 C4/Circulation.pm                                  |    3 +
 C4/Items.pm                                        |   24 +++++++
 C4/Reserves.pm                                     |    8 ++
 cataloguing/additem.pl                             |   20 ++++--
 circ/returns.pl                                    |   17 +++++
 installer/data/mysql/en/mandatory/sysprefs.sql     |    3 +
 .../1-Obligatoire/unimarc_standard_systemprefs.sql |    3 +
 installer/data/mysql/kohastructure.sql             |    1 +
 installer/data/mysql/updatedatabase.pl             |   11 +++
 kohaversion.pl                                     |    2 +-
 misc/cronjobs/cart_to_shelf.pl                     |   69 ++++++++++++++++++++
 11 files changed, 154 insertions(+), 7 deletions(-)
 create mode 100755 misc/cronjobs/cart_to_shelf.pl

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index e2c9e94..c739155 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -1011,6 +1011,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 6c58365..29dedba 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -62,6 +62,8 @@ BEGIN {
         GetItemsInfo
         get_itemnumbers_of
         GetItemnumberFromBarcode
+
+        CartToShelf
     );
 }
 
@@ -153,6 +155,28 @@ 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 {
+        die();
+    }
+
+    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 fca00f6..69d8072 100644
--- a/C4/Reserves.pm
+++ b/C4/Reserves.pm
@@ -941,6 +941,10 @@ sub ModReserveStatus {
     ";
     my $sth_set = $dbh->prepare($query);
     $sth_set->execute( $newstatus, $itemnumber );
+
+    if ( C4::Context->preference("ReturnToShelvingCart") && $newstatus ) {
+      CartToShelf( $itemnumber );
+    }
 }
 
 =item ModReserveAffect
@@ -999,6 +1003,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 f98ee55..d5bf07e 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 dc2ad39..cadfc7d 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 a978fad..a14eaaf 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -245,3 +245,6 @@ INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('v
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo');
+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 424b716..4e8104f 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
@@ -247,3 +247,6 @@ INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('v
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Autoriser l''affichage MARC labellis des notices bibliographiques','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Autoriser l''affichage de la vue MARC des notices bibliographiques','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Ne pas lancer le rapport sur les retards tant qu''il n''y a pas de filtre','','YesNo');
+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 2b2e0c9..dcfad5e 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -1178,6 +1178,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 58497c8..11674b9 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -2467,6 +2467,17 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\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 87fd2cc..9701165 100644
--- a/kohaversion.pl
+++ b/kohaversion.pl
@@ -10,7 +10,7 @@
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.01.00.037';
+    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 0000000..5b2b743
--- /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);
-- 
1.6.2.5




More information about the Koha-patches mailing list