Check the boxes for the items that should not be transferable.
++ + +
+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 @@
Check the boxes for the items that should not be transferable.
++ + +
+