From 9cf047290377d8a610dddbf05b5655a6b0afff05 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Wed, 17 Dec 2008 14:09:24 -0600 Subject: [PATCH] Added 'Branch Transfer Limits' Feature requested by Geauga County Library System. Added syspref to updatedatabase. Updated kohastructure.sql with the limits table. Signed-off-by: Andrew Moore Signed-off-by: Galen Charlton --- C4/Circulation.pm | 79 +++++++++++- admin/branch_transfer_limits.pl | 120 ++++++++++++++++++ circ/branchtransfers.pl | 9 ++ installer/data/Pg/kohastructure.sql | 15 +++ .../data/mysql/en/mandatory/sysprefs.sql | 1 + .../unimarc_standard_systemprefs.sql | 2 +- installer/data/mysql/kohastructure.sql | 12 ++ installer/data/mysql/updatedatabase.pl | 17 +++ .../prog/en/modules/admin/admin-home.tmpl | 7 +- .../modules/admin/branch_transfer_limits.tmpl | 89 +++++++++++++ .../prog/en/modules/circ/branchtransfers.tmpl | 3 + 11 files changed, 349 insertions(+), 5 deletions(-) create mode 100755 admin/branch_transfer_limits.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tmpl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 455a90d923..d48d4f7f41 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -89,6 +89,9 @@ BEGIN { &GetTransfersFromTo &updateWrongTransfer &DeleteTransfer + &IsBranchTransferAllowed + &CreateBranchTransferLimit + &DeleteBranchTransferLimits ); } @@ -268,9 +271,23 @@ sub transferbook { my $hbr = $biblio->{'homebranch'}; my $fbr = $biblio->{'holdingbranch'}; + # if using Branch Transfer Limits + if ( C4::Context->preference("UseBranchTransferLimits") == 1 ) { + if ( C4::Context->preference("item-level_itypes") ) { + if ( ! IsBranchTransferAllowed( $tbr, $fbr, $biblio->{'itype'} ) ) { + $messages->{'NotAllowed'} = $tbr . "::" . $biblio->{'itype'}; + $dotransfer = 0; + } + } elsif ( ! IsBranchTransferAllowed( $tbr, $fbr, $biblio->{'itemtype'} ) ) { + $messages->{'NotAllowed'} = $tbr . "::" . $biblio->{'itemtype'}; + $dotransfer = 0; + } + } + # if is permanent... if ( $hbr && $branches->{$hbr}->{'PE'} ) { $messages->{'IsPermanent'} = $hbr; + $dotransfer = 0; } # can't transfer book if is already there.... @@ -1433,10 +1450,15 @@ sub AddReturn { #adding message if holdingbranch is non equal a userenv branch to return the document to homebranch #we check, if we don't have reserv or transfert for this document, if not, return it to homebranch . - if ( ($iteminformation->{'holdingbranch'} ne $iteminformation->{'homebranch'}) and not $messages->{'WrongTransfer'} and ($validTransfert ne 1) and ($reserveDone ne 1) ){ + if ( ( $branch ne $iteminformation->{'homebranch'}) and not $messages->{'WrongTransfer'} and ($validTransfert ne 1) and ($reserveDone ne 1) ){ if (C4::Context->preference("AutomaticItemReturn") == 1) { ModItemTransfer($iteminformation->{'itemnumber'}, C4::Context->userenv->{'branch'}, $iteminformation->{'homebranch'}); $messages->{'WasTransfered'} = 1; + } elsif ( C4::Context->preference("UseBranchTransferLimits") == 1 + && ! IsTransferAllowed( $branch, $iteminformation->{'homebranch'}, $iteminformation->{'itemtype'} ) + ) { + ModItemTransfer($iteminformation->{'itemnumber'}, C4::Context->userenv->{'branch'}, $iteminformation->{'homebranch'}); + $messages->{'WasTransfered'} = 1; } else { $messages->{'NeedsTransfer'} = 1; @@ -2444,7 +2466,60 @@ $sth->finish; return $exist; } -1; +=head2 IsBranchTransferAllowed + +$allowed = IsBranchTransferAllowed( $toBranch, $fromBranch, $itemtype ); + +=cut + +sub IsBranchTransferAllowed { + my ( $toBranch, $fromBranch, $itemtype ) = @_; + + if ( $toBranch eq $fromBranch ) { return 1; } ## Short circuit for speed. + + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare('SELECT * FROM branch_transfer_limits WHERE toBranch = ? AND fromBranch = ? AND itemtype = ?'); + $sth->execute( $toBranch, $fromBranch, $itemtype ); + my $limit = $sth->fetchrow_hashref(); + + ## If a row is found, then that combination is not allowed, if no matching row is found, then the combination *is allowed* + if ( $limit->{'limitId'} ) { + return 0; + } else { + return 1; + } +} + +=head2 CreateBranchTransferLimit + +CreateBranchTransferLimit( $toBranch, $fromBranch, $itemtype ); + +=cut + +sub CreateBranchTransferLimit { + my ( $toBranch, $fromBranch, $itemtype ) = @_; + + my $dbh = C4::Context->dbh; + + my $sth = $dbh->prepare("INSERT INTO branch_transfer_limits ( itemtype, toBranch, fromBranch ) VALUES ( ?, ?, ? )"); + $sth->execute( $itemtype, $toBranch, $fromBranch ); +} + +=head2 DeleteBranchTransferLimits + +DeleteBranchTransferLimits(); + +=cut + +sub DeleteBranchTransferLimits { + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("TRUNCATE TABLE branch_transfer_limits"); + $sth->execute(); +} + + + 1; __END__ diff --git a/admin/branch_transfer_limits.pl b/admin/branch_transfer_limits.pl new file mode 100755 index 0000000000..8c5c0646a5 --- /dev/null +++ b/admin/branch_transfer_limits.pl @@ -0,0 +1,120 @@ +#!/usr/bin/perl + +# Copyright 2000-2002 Katipo Communications +# +# 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 + +use strict; +use CGI; +use C4::Auth; +use C4::Context; +use C4::Output; +use C4::Koha; +use C4::Branch; + +my $input = new CGI; + +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "admin/branch_transfer_limits.tmpl", + query => $input, + type => "intranet", + flagsrequired => {borrowers => 1}, + debug => 1, + }); + +my $dbh = C4::Context->dbh; + +my @itemtypes; +my @branchcodes; + +my $sth = $dbh->prepare("SELECT itemtype FROM itemtypes"); +$sth->execute(); +while ( my $row = $sth->fetchrow_hashref ) { + push( @itemtypes, $row->{'itemtype'} ); +} + +$sth = $dbh->prepare("SELECT branchcode FROM branches"); +$sth->execute(); +while ( my $row = $sth->fetchrow_hashref ) { + push( @branchcodes, $row->{'branchcode'} ); +} + +## If Form Data Passed, Update the Database +if ( $input->param('updateLimits') ) { + DeleteBranchTransferLimits(); + + foreach my $itemtype ( @itemtypes ) { + foreach my $toBranch ( @branchcodes ) { + foreach my $fromBranch ( @branchcodes ) { + my $isSet = $input->param( $itemtype . "_" . $toBranch . "_" . $fromBranch ); + if ( $isSet ) { + CreateBranchTransferLimit( $toBranch, $fromBranch, $itemtype ); + } + } + } + } +} + +## Build branchcode loop +my @branchcode_loop; +foreach my $branchcode ( @branchcodes ) { + my %row_data; + $row_data{ branchcode } = $branchcode; + push ( @branchcode_loop, \%row_data ); +} + +## Build the default data +my @loop0; +foreach my $itemtype ( @itemtypes ) { + my @loop1; + my %row_data; + $row_data{ itemtype } = $itemtype; + $row_data{ loop1 } = \@loop1; + foreach my $toBranch ( @branchcodes ) { + my @loop2; + my %row_data; + $row_data{ itemtype } = $itemtype; + $row_data{ toBranch } = $toBranch; + $row_data{ loop2 } = \@loop2; + + foreach my $fromBranch ( @branchcodes ) { + my %row_data; + my $isChecked = ! IsBranchTransferAllowed( $toBranch, $fromBranch, $itemtype ); + $row_data{ itemtype } = $itemtype; + $row_data{ toBranch } = $toBranch; + $row_data{ fromBranch } = $fromBranch; + $row_data{ isChecked } = $isChecked; + + push( @loop2, \%row_data ); + } + + push( @loop1, \%row_data ); + } + + push( @loop0, \%row_data ); +} + + +$template->param( + loop0 => \@loop0, + branchcode_loop => \@branchcode_loop, + intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + intranetstylesheet => C4::Context->preference("intranetstylesheet"), + IntranetNav => C4::Context->preference("IntranetNav"), + ); + +output_html_with_http_headers $input, $cookie, $template->output; + diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index 36f4da3e95..457f896de1 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -202,6 +202,15 @@ foreach my $code ( keys %$messages ) { $err{errbadcode} = 1; } + if ( $code eq "NotAllowed" ) { + warn $messages->{'NotAllowed'}; + warn $branches->{ $messages->{'NotAllowed'} }->{'branchname'}; + $err{errnotallowed} = 1; + my ( $tbr, $itemtype ) = split( /::/, $messages->{'NotAllowed'} ); + $err{tbr} = $branches->{ $tbr }->{'branchname'}; + $err{itemtype} = $itemtype; + } + if ( $code eq 'IsPermanent' ) { $err{errispermanent} = 1; $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'}; diff --git a/installer/data/Pg/kohastructure.sql b/installer/data/Pg/kohastructure.sql index 6669613a53..9243ad59c2 100644 --- a/installer/data/Pg/kohastructure.sql +++ b/installer/data/Pg/kohastructure.sql @@ -1628,4 +1628,19 @@ ALTER TABLE reserves ADD CONSTRAINT reserves_ibfk_4 FOREIGN KEY (branchcode) REF ALTER TABLE virtualshelfcontents ADD CONSTRAINT virtualshelfcontents_ibfk_1 FOREIGN KEY (shelfnumber) REFERENCES virtualshelves (shelfnumber) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE virtualshelfcontents ADD CONSTRAINT virtualshelfcontents_ibfk_2 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE CASCADE; + +-- +-- Table for branch_transfer_limits +-- +CREATE SEQUENCE branch_transfer_limits_limitId_seq START 1; + +CREATE TABLE branch_transfer_limits ( +limitId int PRIMARY KEY DEFAULT nextval('branch_transfer_limits_limitId_seq'), +toBranch varchar(4) NOT NULL, +fromBranch varchar(4) NOT NULL, +itemtype varchar(4) NOT NULL, +PRIMARY KEY (limitId) +); + + --commit; diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index 9a7cffdb03..bc5f0077d4 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -212,3 +212,4 @@ INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowRenewalLimitOverride', '0', 'if ON, allows renewal limits to be overridden on the circulation screen',NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACDisplayRequestPriority','0','','Show patrons the priority level on holds in the OPAC','YesNo'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'UseBranchTransferLimits', '0', '', 'If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.', '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 3541e4ed6c..97a9573f47 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 @@ -214,4 +214,4 @@ INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('SMSSendDriver','','','Détermine le pilote utilisé par SMS::Send pour envoyer des SMS.','free'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowRenewalLimitOverride', '0', "S'il est activé, autorise le dépassement des limites du renouvellement sur la page de circulation",NULL,'YesNo'); INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACDisplayRequestPriority','0','','Afficher l\'ordre des réservation pour les adhérents à l\'opac','YesNo'); - +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'UseBranchTransferLimits', '0', '', 'If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.', 'YesNo'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index b2e7515e85..c6381b6e67 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2309,3 +2309,15 @@ CREATE TABLE `borrower_message_transport_preferences` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; +-- +-- Table structure for the table branch_transfer_limits +-- + +CREATE TABLE branch_transfer_limits ( + limitId int(8) NOT NULL auto_increment, + toBranch varchar(4) NOT NULL, + fromBranch varchar(4) NOT NULL, + itemtype varchar(4) NOT NULL, + PRIMARY KEY (limitId) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + \ No newline at end of file diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 6874eb9175..0f4d461283 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -2031,6 +2031,23 @@ if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) { } print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)\n"; SetVersion($DBversion); + +$DBversion = '3.01.00.008'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + + $dbh->do("CREATE TABLE branch_transfer_limits ( + limitId int(8) NOT NULL auto_increment, + toBranch varchar(4) NOT NULL, + fromBranch varchar(4) NOT NULL, + itemtype varchar(4) NOT NULL, + PRIMARY KEY (limitId) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8" + ); + + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'UseBranchTransferLimits', '0', '', 'If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.', 'YesNo')"); + + print "Upgrade to $DBversion done (added branch_transfer_limits table and UseBranchTransferLimits system preference)\n"; + SetVersion ($DBversion); } $DBversion = "3.01.00.003"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl index 59537654a9..e4f056b1c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tmpl @@ -46,8 +46,11 @@
Define road types (street, avenue, way, etc.). Road types display as authorized values when adding/editing patrons and can be used in geographic statistics.
Patron attribute types
Define extended attributes (identifiers and statistical categories) for patron records
-
Circulation and fines rules
-
Define circulation and fines rules for combinations of libraries, patron categories, and item types
+
Circulation and fines rules
+
Define circulation and fines rules for combinations of libraries, patron categories, and item types
+
Branch Transfer Limits
+
Limit the ability to transfer items between libraries based on the branch sending, the brand recieving, and the itemtype involved. These rules only go into effect if the preference UseBranchTransferLimits is set to ON.
+
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tmpl new file mode 100644 index 0000000000..1c7ba60a92 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branch_transfer_limits.tmpl @@ -0,0 +1,89 @@ + +Koha › Administration › Set Branch Transfer Limits + + + + + + + + + + +
+ +

Check the boxes for the items that should not be transferable.

+

+ + +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
To/From
Limits for Item Type:
+ __" + type="checkbox" + value="1" + checked + > +
+ + + +
+
+
+ + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tmpl index 234fe51307..8b2981aa54 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tmpl @@ -142,6 +142,9 @@
  • Please return item to home library:
  • + +
  • You cannot transfer items of type to
  • +
  • Item is already at destination library.
  • -- 2.39.5