From 9c72711a2c632fb679d6be215f9fdd6a3b96faa2 Mon Sep 17 00:00:00 2001 From: koha Date: Wed, 4 Mar 2009 16:15:32 -0600 Subject: [PATCH] This patch allows the Branch Transfer Limits feature to limit transfers either by itemtype ( like the original commit ) or collection code ( new feature ). [Note inserted by RM: this patch is by Kyle Hall] Signed-off-by: Galen Charlton --- C4/Circulation.pm | 33 +++++++++------ admin/branch_transfer_limits.pl | 41 ++++++++++++------- circ/branchtransfers.pl | 13 +++++- .../data/mysql/en/mandatory/sysprefs.sql | 1 + .../unimarc_standard_systemprefs.sql | 2 +- installer/data/mysql/kohastructure.sql | 3 +- installer/data/mysql/updatedatabase.pl | 14 +++++++ .../modules/admin/branch_transfer_limits.tmpl | 10 ++--- .../prog/en/modules/circ/branchtransfers.tmpl | 2 +- 9 files changed, 82 insertions(+), 37 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index cf42490bdc..5337bf0bdf 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -279,13 +279,13 @@ sub transferbook { # if using Branch Transfer Limits if ( C4::Context->preference("UseBranchTransferLimits") == 1 ) { - if ( C4::Context->preference("item-level_itypes") ) { + if ( C4::Context->preference("item-level_itypes") && C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ) { if ( ! IsBranchTransferAllowed( $tbr, $fbr, $biblio->{'itype'} ) ) { $messages->{'NotAllowed'} = $tbr . "::" . $biblio->{'itype'}; $dotransfer = 0; } - } elsif ( ! IsBranchTransferAllowed( $tbr, $fbr, $biblio->{'itemtype'} ) ) { - $messages->{'NotAllowed'} = $tbr . "::" . $biblio->{'itemtype'}; + } elsif ( ! IsBranchTransferAllowed( $tbr, $fbr, $biblio->{ C4::Context->preference("BranchTransferLimitsType") } ) ) { + $messages->{'NotAllowed'} = $tbr . "::" . $biblio->{ C4::Context->preference("BranchTransferLimitsType") }; $dotransfer = 0; } } @@ -1547,7 +1547,7 @@ sub AddReturn { ModItemTransfer($iteminformation->{'itemnumber'}, C4::Context->userenv->{'branch'}, $iteminformation->{'homebranch'}); $messages->{'WasTransfered'} = 1; } elsif ( C4::Context->preference("UseBranchTransferLimits") == 1 - && ! IsTransferAllowed( $branch, $iteminformation->{'homebranch'}, $iteminformation->{'itemtype'} ) + && ! IsTransferAllowed( $branch, $iteminformation->{'homebranch'}, $iteminformation->{ C4::Context->preference("BranchTransferLimitsType") } ) ) { ModItemTransfer($iteminformation->{'itemnumber'}, C4::Context->userenv->{'branch'}, $iteminformation->{'homebranch'}); $messages->{'WasTransfered'} = 1; @@ -2630,19 +2630,22 @@ return $exist; =head2 IsBranchTransferAllowed -$allowed = IsBranchTransferAllowed( $toBranch, $fromBranch, $itemtype ); +$allowed = IsBranchTransferAllowed( $toBranch, $fromBranch, $code ); + +Code is either an itemtype or collection doe depending on the pref BranchTransferLimitsType =cut sub IsBranchTransferAllowed { - my ( $toBranch, $fromBranch, $itemtype ) = @_; - + my ( $toBranch, $fromBranch, $code ) = @_; + if ( $toBranch eq $fromBranch ) { return 1; } ## Short circuit for speed. + my $limitType = C4::Context->preference("BranchTransferLimitsType"); 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 $sth = $dbh->prepare("SELECT * FROM branch_transfer_limits WHERE toBranch = ? AND fromBranch = ? AND $limitType = ?"); + $sth->execute( $toBranch, $fromBranch, $code ); 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* @@ -2655,17 +2658,21 @@ sub IsBranchTransferAllowed { =head2 CreateBranchTransferLimit -CreateBranchTransferLimit( $toBranch, $fromBranch, $itemtype ); +CreateBranchTransferLimit( $toBranch, $fromBranch, $code ); + +$code is either itemtype or collection code depending on what the pref BranchTransferLimitsType is set to. =cut sub CreateBranchTransferLimit { - my ( $toBranch, $fromBranch, $itemtype ) = @_; + my ( $toBranch, $fromBranch, $code ) = @_; + + my $limitType = C4::Context->preference("BranchTransferLimitsType"); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("INSERT INTO branch_transfer_limits ( itemtype, toBranch, fromBranch ) VALUES ( ?, ?, ? )"); - $sth->execute( $itemtype, $toBranch, $fromBranch ); + my $sth = $dbh->prepare("INSERT INTO branch_transfer_limits ( $limitType, toBranch, fromBranch ) VALUES ( ?, ?, ? )"); + $sth->execute( $code, $toBranch, $fromBranch ); } =head2 DeleteBranchTransferLimits diff --git a/admin/branch_transfer_limits.pl b/admin/branch_transfer_limits.pl index c05b0f7832..2cee238e9e 100755 --- a/admin/branch_transfer_limits.pl +++ b/admin/branch_transfer_limits.pl @@ -40,13 +40,25 @@ my ($template, $loggedinuser, $cookie) my $dbh = C4::Context->dbh; -my @itemtypes; +# Set the template language for the correct limit type +my $limit_phrase = 'Collection Code'; +my $limitType = C4::Context->preference("BranchTransferLimitsType"); +if ( $limitType eq 'itemtype' ) { + $limit_phrase = 'Item Type'; +} + +my @codes; my @branchcodes; -my $sth = $dbh->prepare("SELECT itemtype FROM itemtypes"); +my $sth; +if ( $limitType eq 'ccode' ) { + $sth = $dbh->prepare('SELECT authorised_value AS ccode FROM authorised_values WHERE category = "CCODE"'); +} elsif ( $limitType eq 'itemtype' ) { + $sth = $dbh->prepare('SELECT itemtype FROM itemtypes'); +} $sth->execute(); while ( my $row = $sth->fetchrow_hashref ) { - push( @itemtypes, $row->{'itemtype'} ); + push( @codes, $row->{ $limitType } ); } $sth = $dbh->prepare("SELECT branchcode FROM branches"); @@ -59,12 +71,12 @@ while ( my $row = $sth->fetchrow_hashref ) { if ( $input->param('updateLimits') ) { DeleteBranchTransferLimits(); - foreach my $itemtype ( @itemtypes ) { + foreach my $code ( @codes ) { foreach my $toBranch ( @branchcodes ) { foreach my $fromBranch ( @branchcodes ) { - my $isSet = $input->param( $itemtype . "_" . $toBranch . "_" . $fromBranch ); + my $isSet = $input->param( $code . "_" . $toBranch . "_" . $fromBranch ); if ( $isSet ) { - CreateBranchTransferLimit( $toBranch, $fromBranch, $itemtype ); + CreateBranchTransferLimit( $toBranch, $fromBranch, $code ); } } } @@ -80,23 +92,23 @@ foreach my $branchcode ( @branchcodes ) { } ## Build the default data -my @itemtypes_loop; -foreach my $itemtype ( @itemtypes ) { +my @codes_loop; +foreach my $code ( @codes ) { my @to_branch_loop; my %row_data; - $row_data{ itemtype } = $itemtype; + $row_data{ code } = $code; $row_data{ to_branch_loop } = \@to_branch_loop; foreach my $toBranch ( @branchcodes ) { my @from_branch_loop; my %row_data; - $row_data{ itemtype } = $itemtype; + $row_data{ code } = $code; $row_data{ toBranch } = $toBranch; $row_data{ from_branch_loop } = \@from_branch_loop; foreach my $fromBranch ( @branchcodes ) { my %row_data; - my $isChecked = ! IsBranchTransferAllowed( $toBranch, $fromBranch, $itemtype ); - $row_data{ itemtype } = $itemtype; + my $isChecked = ! IsBranchTransferAllowed( $toBranch, $fromBranch, $code ); + $row_data{ code } = $code; $row_data{ toBranch } = $toBranch; $row_data{ fromBranch } = $fromBranch; $row_data{ isChecked } = $isChecked; @@ -107,13 +119,14 @@ foreach my $itemtype ( @itemtypes ) { push( @to_branch_loop, \%row_data ); } - push( @itemtypes_loop, \%row_data ); + push( @codes_loop, \%row_data ); } $template->param( - itemtypes_loop => \@itemtypes_loop, + codes_loop => \@codes_loop, branchcode_loop => \@branchcode_loop, + limit_phrase => $limit_phrase, ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index 92b139cf56..8ae283dfe6 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -193,6 +193,14 @@ if ($found) { ##################### +# Used for branch transfer limits error messages. +my $codeTypeDescription = 'Collection Code'; +my $codeType = C4::Context->preference("BranchTransferLimitsType"); +if ( $codeType eq 'itemtype' ) { + $codeTypeDescription = 'Item Type'; +} + + my @errmsgloop; foreach my $code ( keys %$messages ) { my %err; @@ -206,9 +214,10 @@ foreach my $code ( keys %$messages ) { warn $messages->{'NotAllowed'}; warn $branches->{ $messages->{'NotAllowed'} }->{'branchname'}; $err{errnotallowed} = 1; - my ( $tbr, $itemtype ) = split( /::/, $messages->{'NotAllowed'} ); + my ( $tbr, $typecode ) = split( /::/, $messages->{'NotAllowed'} ); $err{tbr} = $branches->{ $tbr }->{'branchname'}; - $err{itemtype} = $itemtype; + $err{code} = $typecode; + $err{codeType} = $codeTypeDescription; } if ( $code eq 'IsPermanent' ) { diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index 47a0c4bda2..c79a727e67 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -214,3 +214,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' 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'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice'); 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 47da5961a7..34691062d2 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 @@ -216,4 +216,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' 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'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', "Autorise le personnel á outrepasser la politique de réservation au moment d'une réservation",NULL,'YesNo'); - +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ('BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice'); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 2d4b41567a..a7e555f001 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2337,7 +2337,8 @@ 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, + itemtype varchar(4) NULL, + ccode varchar(10) NULL, PRIMARY KEY (limitId) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 30f1887a2e..85e5d79e10 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -2221,6 +2221,20 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.01.00.013"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `branch_transfer_limits` CHANGE `itemtype` `itemtype` VARCHAR( 4 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL"); + $dbh->do("ALTER TABLE `branch_transfer_limits` ADD `ccode` VARCHAR( 10 ) NULL ;"); + $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) + VALUES ( + 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice' + );"); + + print "Upgrade to $DBversion done ( Updated table for Branch Transfer Limits)\n"; + SetVersion ($DBversion); +} + + =item DropAllForeignKeys($table) Drop all foreign keys of the table $table 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 index c863f837d5..f47e6223dd 100644 --- 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 @@ -62,7 +62,7 @@

Library Transfer Limits

-
Check the boxes for the items that should not be transferable.
+
Check the boxes for the items that should not be transferable.
@@ -77,8 +77,8 @@ - - Limits for Item Type: + + Limits for : @@ -87,11 +87,11 @@ __" + name="__" type="checkbox" value="1" checked="checked" /> __" + name="__" type="checkbox" value="1" /> 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 8b2981aa54..1db6630a5c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tmpl @@ -143,7 +143,7 @@
  • Please return item to home library:
  • -
  • You cannot transfer items of type to
  • +
  • You cannot transfer items of to
  • Item is already at destination library.
  • -- 2.39.5