@@ -, +, @@ from sending it back to the branch of origin --- C4/Circulation.pm | 2 + C4/RotatingCollections.pm | 466 +++++++++++---------- circ/returns.pl | 24 +- installer/data/mysql/kohastructure.sql | 8 +- installer/data/mysql/updatedatabase.pl | 16 + .../intranet-tmpl/prog/en/modules/circ/returns.tt | 2 +- .../en/modules/rotating_collections/addItems.tt | 7 + .../rotating_collections/editCollections.tt | 10 +- .../prog/en/modules/tools/tools-home.tt | 2 - rotating_collections/addItems.pl | 132 +++--- rotating_collections/editCollections.pl | 149 +++---- rotating_collections/rotatingCollections.pl | 38 +- rotating_collections/transferCollection.pl | 84 ++-- 13 files changed, 507 insertions(+), 433 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -42,6 +42,7 @@ use C4::Koha qw( GetKohaAuthorisedValueLib ); use C4::Overdues qw(CalcFine UpdateFine); +use C4::RotatingCollections qw(GetCollectionItemBranches); use Algorithm::CheckDigits; use Data::Dumper; @@ -2006,6 +2007,7 @@ sub AddReturn { $messages->{'NeedsTransfer'} = 1; # TODO: instead of 1, specify branchcode that the transfer SHOULD go to, $item->{homebranch} } } + return ( $doreturn, $messages, $issue, $borrower ); } --- a/C4/RotatingCollections.pm +++ a/C4/RotatingCollections.pm @@ -1,9 +1,9 @@ package C4::RotatingCollections; -# $Id: RotatingCollections.pm,v 0.1 2007/04/20 kylemhall +# $Id: RotatingCollections.pm,v 0.1 2007/04/20 kylemhall # This package is inteded to keep track of what library -# Items of a certain collection should be at. +# Items of a certain collection should be at. # Copyright 2007 Kyle Hall # @@ -22,13 +22,11 @@ package C4::RotatingCollections; # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -use strict; -#use warnings; FIXME - Bug 2505 - -require Exporter; +use Modern::Perl; use C4::Context; use C4::Circulation; +use C4::Reserves qw(GetReserveStatus); use DBI; @@ -47,23 +45,26 @@ C4::RotatingCollections - Functions for managing rotating collections =cut -@ISA = qw( Exporter ); -@EXPORT = qw( - CreateCollection - UpdateCollection - DeleteCollection - - GetItemsInCollection +BEGIN { + require Exporter; + @ISA = qw( Exporter ); + @EXPORT = qw( + CreateCollection + UpdateCollection + DeleteCollection + + GetItemsInCollection + + GetCollection + GetCollections - GetCollection - GetCollections - - AddItemToCollection - RemoveItemFromCollection - TransferCollection + AddItemToCollection + RemoveItemFromCollection + TransferCollection - GetCollectionItemBranches -); + GetCollectionItemBranches + ); +} =head2 CreateCollection ( $success, $errorcode, $errormessage ) = CreateCollection( $title, $description ); @@ -81,27 +82,29 @@ C4::RotatingCollections - Functions for managing rotating collections =cut sub CreateCollection { - my ( $title, $description ) = @_; + my ( $title, $description ) = @_; - ## Check for all neccessary parameters - if ( ! $title ) { - return ( 0, 1, "No Title Given" ); - } - if ( ! $description ) { - return ( 0, 2, "No Description Given" ); - } + ## Check for all neccessary parameters + if ( !$title ) { + return ( 0, 1, "No Title Given" ); + } + if ( !$description ) { + return ( 0, 2, "No Description Given" ); + } - my $success = 1; + my $success = 1; - my $dbh = C4::Context->dbh; + my $dbh = C4::Context->dbh; - my $sth; - $sth = $dbh->prepare("INSERT INTO collections ( colId, colTitle, colDesc ) - VALUES ( NULL, ?, ? )"); - $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() ); + my $sth; + $sth = $dbh->prepare( + "INSERT INTO collections ( colId, colTitle, colDesc ) + VALUES ( NULL, ?, ? )" + ); + $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() ); + + return 1; - return 1; - } =head2 UpdateCollection @@ -123,30 +126,33 @@ Updates a collection =cut sub UpdateCollection { - my ( $colId, $title, $description ) = @_; - - ## Check for all neccessary parameters - if ( ! $colId ) { - return ( 0, 1, "No Id Given" ); - } - if ( ! $title ) { - return ( 0, 2, "No Title Given" ); - } - if ( ! $description ) { - return ( 0, 3, "No Description Given" ); - } - - my $dbh = C4::Context->dbh; - - my $sth; - $sth = $dbh->prepare("UPDATE collections + my ( $colId, $title, $description ) = @_; + + ## Check for all neccessary parameters + if ( !$colId ) { + return ( 0, 1, "No Id Given" ); + } + if ( !$title ) { + return ( 0, 2, "No Title Given" ); + } + if ( !$description ) { + return ( 0, 3, "No Description Given" ); + } + + my $dbh = C4::Context->dbh; + + my $sth; + $sth = $dbh->prepare( + "UPDATE collections SET colTitle = ?, colDesc = ? - WHERE colId = ?"); - $sth->execute( $title, $description, $colId ) or return ( 0, 4, $sth->errstr() ); - - return 1; - + WHERE colId = ?" + ); + $sth->execute( $title, $description, $colId ) + or return ( 0, 4, $sth->errstr() ); + + return 1; + } =head2 DeleteCollection @@ -165,21 +171,21 @@ sub UpdateCollection { =cut sub DeleteCollection { - my ( $colId ) = @_; + my ($colId) = @_; + + ## Paramter check + if ( !$colId ) { + return ( 0, 1, "No Collection Id Given" ); + } - ## Paramter check - if ( ! $colId ) { - return ( 0, 1, "No Collection Id Given" );; - } - - my $dbh = C4::Context->dbh; + my $dbh = C4::Context->dbh; - my $sth; + my $sth; - $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?"); - $sth->execute( $colId ) or return ( 0, 4, $sth->errstr() ); + $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?"); + $sth->execute($colId) or return ( 0, 4, $sth->errstr() ); - return 1; + return 1; } =head2 GetCollections @@ -198,17 +204,17 @@ sub DeleteCollection { sub GetCollections { - my $dbh = C4::Context->dbh; - - my $sth = $dbh->prepare("SELECT * FROM collections"); - $sth->execute() or return ( 1, $sth->errstr() ); - - my @results; - while ( my $row = $sth->fetchrow_hashref ) { - push( @results , $row ); - } - - return \@results; + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare("SELECT * FROM collections"); + $sth->execute() or return ( 1, $sth->errstr() ); + + my @results; + while ( my $row = $sth->fetchrow_hashref ) { + push( @results, $row ); + } + + return \@results; } =head2 GetItemsInCollection @@ -229,16 +235,17 @@ sub GetCollections { =cut sub GetItemsInCollection { - my ( $colId ) = @_; + my ($colId) = @_; + + ## Paramter check + if ( !$colId ) { + return ( 0, 0, 1, "No Collection Id Given" ); + } - ## Paramter check - if ( ! $colId ) { - return ( 0, 0, 1, "No Collection Id Given" );; - } + my $dbh = C4::Context->dbh; - my $dbh = C4::Context->dbh; - - my $sth = $dbh->prepare("SELECT + my $sth = $dbh->prepare( + "SELECT biblio.title, items.itemcallnumber, items.barcode @@ -246,15 +253,16 @@ sub GetItemsInCollection { WHERE collections.colId = collections_tracking.colId AND collections_tracking.itemnumber = items.itemnumber AND items.biblionumber = biblio.biblionumber - AND collections.colId = ? ORDER BY biblio.title"); - $sth->execute( $colId ) or return ( 0, 0, 2, $sth->errstr() ); - - my @results; - while ( my $row = $sth->fetchrow_hashref ) { - push( @results , $row ); - } - - return \@results; + AND collections.colId = ? ORDER BY biblio.title" + ); + $sth->execute($colId) or return ( 0, 0, 2, $sth->errstr() ); + + my @results; + while ( my $row = $sth->fetchrow_hashref ) { + push( @results, $row ); + } + + return \@results; } =head2 GetCollection @@ -271,23 +279,21 @@ Returns information about a collection =cut sub GetCollection { - my ( $colId ) = @_; - - my $dbh = C4::Context->dbh; - - my ( $sth, @results ); - $sth = $dbh->prepare("SELECT * FROM collections WHERE colId = ?"); - $sth->execute( $colId ) or return 0; - - my $row = $sth->fetchrow_hashref; - - return ( - $$row{'colId'}, - $$row{'colTitle'}, - $$row{'colDesc'}, - $$row{'colBranchcode'} - ); - + my ($colId) = @_; + + my $dbh = C4::Context->dbh; + + my ( $sth, @results ); + $sth = $dbh->prepare("SELECT * FROM collections WHERE colId = ?"); + $sth->execute($colId) or return 0; + + my $row = $sth->fetchrow_hashref; + + return ( + $$row{'colId'}, $$row{'colTitle'}, + $$row{'colDesc'}, $$row{'colBranchcode'} + ); + } =head2 AddItemToCollection @@ -307,31 +313,36 @@ Adds an item to a rotating collection. =cut sub AddItemToCollection { - my ( $colId, $itemnumber ) = @_; - - ## Check for all neccessary parameters - if ( ! $colId ) { - return ( 0, 1, "No Collection Given" ); - } - if ( ! $itemnumber ) { - return ( 0, 2, "No Itemnumber Given" ); - } - - if ( isItemInThisCollection( $itemnumber, $colId ) ) { - return ( 0, 2, "Item is already in the collection!" ); - } elsif ( isItemInAnyCollection( $itemnumber ) ) { - return ( 0, 3, "Item is already in a different collection!" ); - } - - my $dbh = C4::Context->dbh; - - my $sth; - $sth = $dbh->prepare("INSERT INTO collections_tracking ( collections_tracking_id, colId, itemnumber ) - VALUES ( NULL, ?, ? )"); - $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() ); - - return 1; - + my ( $colId, $itemnumber ) = @_; + + ## Check for all neccessary parameters + if ( !$colId ) { + return ( 0, 1, "No Collection Given" ); + } + if ( !$itemnumber ) { + return ( 0, 2, "No Itemnumber Given" ); + } + + if ( isItemInThisCollection( $itemnumber, $colId ) ) { + return ( 0, 2, "Item is already in the collection!" ); + } + elsif ( isItemInAnyCollection($itemnumber) ) { + return ( 0, 3, "Item is already in a different collection!" ); + } + + my $dbh = C4::Context->dbh; + + my $sth; + $sth = $dbh->prepare(" + INSERT INTO collections_tracking ( + colId, + itemnumber + ) VALUES ( ?, ? ) + "); + $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() ); + + return 1; + } =head2 RemoveItemFromCollection @@ -352,25 +363,27 @@ Removes an item to a collection =cut sub RemoveItemFromCollection { - my ( $colId, $itemnumber ) = @_; + my ( $colId, $itemnumber ) = @_; + + ## Check for all neccessary parameters + if ( !$itemnumber ) { + return ( 0, 2, "No Itemnumber Given" ); + } - ## Check for all neccessary parameters - if ( ! $itemnumber ) { - return ( 0, 2, "No Itemnumber Given" ); - } - - if ( ! isItemInThisCollection( $itemnumber, $colId ) ) { - return ( 0, 2, "Item is not in the collection!" ); - } + if ( !isItemInThisCollection( $itemnumber, $colId ) ) { + return ( 0, 2, "Item is not in the collection!" ); + } - my $dbh = C4::Context->dbh; + my $dbh = C4::Context->dbh; - my $sth; - $sth = $dbh->prepare("DELETE FROM collections_tracking - WHERE itemnumber = ?"); - $sth->execute( $itemnumber ) or return ( 0, 3, $sth->errstr() ); + my $sth; + $sth = $dbh->prepare( + "DELETE FROM collections_tracking + WHERE itemnumber = ?" + ); + $sth->execute($itemnumber) or return ( 0, 3, $sth->errstr() ); - return 1; + return 1; } =head2 TransferCollection @@ -391,36 +404,44 @@ Transfers a collection to another branch =cut sub TransferCollection { - my ( $colId, $colBranchcode ) = @_; + my ( $colId, $colBranchcode ) = @_; - ## Check for all neccessary parameters - if ( ! $colId ) { - return ( 0, 1, "No Id Given" ); - } - if ( ! $colBranchcode ) { - return ( 0, 2, "No Branchcode Given" ); - } + ## Check for all neccessary parameters + if ( !$colId ) { + return ( 0, 1, "No Id Given" ); + } + if ( !$colBranchcode ) { + return ( 0, 2, "No Branchcode Given" ); + } - my $dbh = C4::Context->dbh; + my $dbh = C4::Context->dbh; - my $sth; - $sth = $dbh->prepare("UPDATE collections + my $sth; + $sth = $dbh->prepare( + "UPDATE collections SET colBranchcode = ? - WHERE colId = ?"); - $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() ); - - $sth = $dbh->prepare("SELECT barcode FROM items, collections_tracking - WHERE items.itemnumber = collections_tracking.itemnumber - AND collections_tracking.colId = ?"); - $sth->execute( $colId ) or return ( 0, 4, $sth->errstr ); - my @results; - while ( my $item = $sth->fetchrow_hashref ) { - my ( $dotransfer, $messages, $iteminformation ) = transferbook( $colBranchcode, $item->{'barcode'}, my $ignore_reserves = 1); - } - - return 1; - + WHERE colId = ?" + ); + $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() ); + + $sth = $dbh->prepare(q{ + SELECT items.itemnumber, items.barcode FROM collections_tracking + LEFT JOIN items ON collections_tracking.itemnumber = items.itemnumber + LEFT JOIN issues ON items.itemnumber = issues.itemnumber + WHERE issues.borrowernumber IS NULL + AND collections_tracking.colId = ? + }); + $sth->execute($colId) or return ( 0, 4, $sth->errstr ); + my @results; + while ( my $item = $sth->fetchrow_hashref ) { + transferbook( $colBranchcode, $item->{barcode}, + my $ignore_reserves = 1 ) + unless ( GetReserveStatus( $item->{itemnumber} ) eq "Waiting" ); + } + + return 1; + } =head2 GetCollectionItemBranches @@ -430,27 +451,26 @@ sub TransferCollection { =cut sub GetCollectionItemBranches { - my ( $itemnumber ) = @_; + my ($itemnumber) = @_; - if ( ! $itemnumber ) { - return; - } + if ( !$itemnumber ) { + return; + } - my $dbh = C4::Context->dbh; + my $dbh = C4::Context->dbh; - my ( $sth, @results ); - $sth = $dbh->prepare("SELECT holdingbranch, colBranchcode FROM items, collections, collections_tracking + my ( $sth, @results ); + $sth = $dbh->prepare( +"SELECT holdingbranch, colBranchcode FROM items, collections, collections_tracking WHERE items.itemnumber = collections_tracking.itemnumber AND collections.colId = collections_tracking.colId - AND items.itemnumber = ?"); - $sth->execute( $itemnumber ); - - my $row = $sth->fetchrow_hashref; - - return ( - $$row{'holdingbranch'}, - $$row{'colBranchcode'}, - ); + AND items.itemnumber = ?" + ); + $sth->execute($itemnumber); + + my $row = $sth->fetchrow_hashref; + + return ( $$row{'holdingbranch'}, $$row{'colBranchcode'}, ); } =head2 isItemInThisCollection @@ -460,16 +480,18 @@ sub GetCollectionItemBranches { =cut sub isItemInThisCollection { - my ( $itemnumber, $colId ) = @_; - - my $dbh = C4::Context->dbh; - - my $sth = $dbh->prepare("SELECT COUNT(*) as inCollection FROM collections_tracking WHERE itemnumber = ? AND colId = ?"); - $sth->execute( $itemnumber, $colId ) or return( 0 ); - - my $row = $sth->fetchrow_hashref; - - return $$row{'inCollection'}; + my ( $itemnumber, $colId ) = @_; + + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare( +"SELECT COUNT(*) as inCollection FROM collections_tracking WHERE itemnumber = ? AND colId = ?" + ); + $sth->execute( $itemnumber, $colId ) or return (0); + + my $row = $sth->fetchrow_hashref; + + return $$row{'inCollection'}; } =head2 isItemInAnyCollection @@ -479,21 +501,23 @@ $inCollection = isItemInAnyCollection( $itemnumber ); =cut sub isItemInAnyCollection { - my ( $itemnumber ) = @_; - - my $dbh = C4::Context->dbh; - - my $sth = $dbh->prepare("SELECT itemnumber FROM collections_tracking WHERE itemnumber = ?"); - $sth->execute( $itemnumber ) or return( 0 ); - - my $row = $sth->fetchrow_hashref; - - $itemnumber = $row->{itemnumber}; - if ( $itemnumber ) { - return 1; - } else { - return 0; - } + my ($itemnumber) = @_; + + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare( + "SELECT itemnumber FROM collections_tracking WHERE itemnumber = ?"); + $sth->execute($itemnumber) or return (0); + + my $row = $sth->fetchrow_hashref; + + $itemnumber = $row->{itemnumber}; + if ($itemnumber) { + return 1; + } + else { + return 0; + } } 1; --- a/circ/returns.pl +++ a/circ/returns.pl @@ -600,20 +600,16 @@ $template->param( BlockReturnOfWithdrawnItems => C4::Context->preference("BlockReturnOfWithdrawnItems"), ); -### Comment out rotating collections for now to allow it a little more time to bake -### for 3.4; in particular, must ensure that it doesn't fight with transfers required -### to fill hold requests -### -- Galen Charlton 2010-10-06 -#my $itemnumber = GetItemnumberFromBarcode( $query->param('barcode') ); -#if ( $itemnumber ) { -# my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber ); -# if ( ! ( $holdingBranch eq $collectionBranch ) ) { -# $template->param( -# collectionItemNeedsTransferred => 1, -# collectionBranch => GetBranchName($collectionBranch), -# ); -# } -#} +my $itemnumber = GetItemnumberFromBarcode( $query->param('barcode') ); +if ( $itemnumber ) { + my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber ); + if ( ! ( $holdingBranch eq $collectionBranch ) ) { + $template->param( + collectionItemNeedsTransferred => 1, + collectionBranch => GetBranchName($collectionBranch), + ); + } +} # actually print the page! output_html_with_http_headers $query, $cookie, $template->output; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -480,11 +480,17 @@ CREATE TABLE collections ( colId integer(11) NOT NULL auto_increment, colTitle varchar(100) NOT NULL DEFAULT '', colDesc text NOT NULL, - colBranchcode varchar(4) DEFAULT NULL comment 'branchcode for branch where item should be held.', + colBranchcode varchar(10) DEFAULT NULL, -- 'branchcode for branch where item should be held.' PRIMARY KEY (colId) ) ENGINE=InnoDB DEFAULT CHARACTER SET utf8; -- +-- Constraints for table `collections` +-- +ALTER TABLE `collections` + ADD CONSTRAINT `collections_ibfk_1` FOREIGN KEY (`colBranchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE; + +-- -- Table: collections_tracking -- DROP TABLE IF EXISTS collections_tracking; --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -8603,6 +8603,22 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.17.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q{ + ALTER TABLE collections CHANGE colBranchcode colBranchcode VARCHAR( 10 ) NULL DEFAULT NULL + }); + $dbh->do(q{ + ALTER TABLE collections ADD INDEX ( colBranchcode ) + }); + $dbh->do(q{ + ALTER TABLE collections + ADD CONSTRAINT collections_ibfk_1 FOREIGN KEY (colBranchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE + }); + print "Upgrade to $DBversion done (Bug 8836 - Resurrect Rotating Collections)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -109,7 +109,7 @@ $(document).ready(function () { [% END %] [% IF ( collectionItemNeedsTransferred ) %] -
+ [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/addItems.tt @@ -1,6 +1,13 @@ [% INCLUDE 'doc-head-open.inc' %]Title | Description | Holding library | -- | + | + | |
---|---|---|---|---|---|---|
[% collectionsLoo.colTitle %] | @@ -60,6 +63,7 @@Delete |