[Koha-patches] [PATCH 28/55] (MT 2259) BranchTransferLimit restriction on return
Henri-Damien LAURENT
henridamien.laurent at biblibre.com
Wed Mar 10 22:26:10 CET 2010
Branch transfer limit is now used to prevent circulation of an item into a library which DONOT have rights to transfer to the HomeOrHoldingBranch library
If this happens, librarian can override
---
C4/Circulation.pm | 56 +++++++++++++-------
circ/returns.pl | 8 +++-
.../prog/en/modules/circ/circulation.tmpl | 6 ++-
.../prog/en/modules/circ/returns.tmpl | 11 ++++-
4 files changed, 58 insertions(+), 23 deletions(-)
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index be7e8f1..5f23199 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -33,6 +33,7 @@ use C4::Accounts;
use C4::ItemCirculationAlertPreference;
use C4::Message;
use C4::Debug;
+use YAML;
use Date::Calc qw(
Today
Today_and_Now
@@ -814,13 +815,21 @@ sub CanBookBeIssued {
{
$issuingimpossible{RESTRICTED} = 1;
}
+ my $userenv = C4::Context->userenv;
+ my $branch=$userenv->{branch};
+ my $hbr= $item->{ C4::Context->preference("HomeOrHoldingBranch") };
if ( C4::Context->preference("IndependantBranches") ) {
- my $userenv = C4::Context->userenv;
if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
$issuingimpossible{NOTSAMEBRANCH} = 1
- if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} );
+ if ( $hbr ne $branch );
}
}
+ my $branchtransferfield=C4::Context->preference("BranchTransferLimitsType") eq "ccode" ? "ccode" : "itype";
+ if ( C4::Context->preference("UseBranchTransferLimits")
+ and !IsBranchTransferAllowed( $branch, $hbr, $item->{ $branchtransferfield } ) ) {
+ $needsconfirmation{BRANCH_TRANSFER_NOT_ALLOWED} = $hbr;
+ }
+
#
# CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
@@ -1379,8 +1388,8 @@ patron who last borrowed the book.
=cut
sub AddReturn {
- my ( $barcode, $branch, $exemptfine, $dropbox ) = @_;
- if ($branch and not GetBranchDetail($branch)) {
+ my ( $barcode, $branch, $exemptfine, $dropbox, $force) = @_;
+ if ( $branch and not GetBranchDetail($branch) ) {
warn "AddReturn error: branch '$branch' not found. Reverting to " . C4::Context->userenv->{'branch'};
undef $branch;
}
@@ -1423,9 +1432,17 @@ sub AddReturn {
my $branches = GetBranches(); # a potentially expensive call for a non-feature.
$branches->{$hbr}->{PE} and $messages->{'IsPermanent'} = $hbr;
}
-
+ my $branchtransferfield=C4::Context->preference("BranchTransferLimitsType") eq "ccode" ? "ccode" : "itype";
+ $debug && warn "$branch, $hbr, ",C4::Context->preference("BranchTransferLimitsType")," ,",$item->{ $branchtransferfield } ;
+ $debug && warn Dump($item);
+ $debug && warn IsBranchTransferAllowed( $branch, $hbr, $item->{ C4::Context->preference("BranchTransferLimitsType") } );
# if indy branches and returning to different branch, refuse the return
- if ($hbr ne $branch && C4::Context->preference("IndependantBranches")){
+ if ( !$force && ($hbr ne $branch)
+ && (C4::Context->preference("IndependantBranches")
+ or ( C4::Context->preference("UseBranchTransferLimits")
+ and !IsBranchTransferAllowed( $branch, $hbr, $item->{$branchtransferfield } ) )
+ )
+ ){
$messages->{'Wrongbranch'} = {
Wrongbranch => $branch,
Rightbranch => $hbr,
@@ -1436,7 +1453,6 @@ sub AddReturn {
# FIXME - even in an indy branches situation, there should
# still be an option for the library to accept the item
# and transfer it to its owning library.
- return ( $doreturn, $messages, $issue, $borrower );
}
if ( $item->{'wthdrawn'} ) { # book has been cancelled
@@ -1459,15 +1475,15 @@ sub AddReturn {
$messages->{'WasReturned'} = 1; # FIXME is the "= 1" right? This could be the borrower hash.
}
- ModItem({ onloan => undef }, $issue->{'biblionumber'}, $item->{'itemnumber'});
+ ModItem( { onloan => undef }, $issue->{'biblionumber'}, $item->{'itemnumber'} );
+ # the holdingbranch is updated if the document is returned to another location.
+ # this is always done regardless of whether the item was on loan or not
+ if ( $item->{'holdingbranch'} ne $branch ) {
+ UpdateHoldingbranch( $branch, $item->{'itemnumber'} );
+ $item->{'holdingbranch'} = $branch; # update item data holdingbranch too
+ }
}
- # the holdingbranch is updated if the document is returned to another location.
- # this is always done regardless of whether the item was on loan or not
- if ($item->{'holdingbranch'} ne $branch) {
- UpdateHoldingbranch($branch, $item->{'itemnumber'});
- $item->{'holdingbranch'} = $branch; # update item data holdingbranch too
- }
ModDateLastSeen( $item->{'itemnumber'} );
# check if we have a transfer for this document
@@ -1542,12 +1558,12 @@ 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 ($doreturn and ($branch ne $hbr) and not $messages->{'WrongTransfer'} and ($validTransfert ne 1) ){
- if ( C4::Context->preference("AutomaticItemReturn" ) or
- (C4::Context->preference("UseBranchTransferLimits") and
- ! IsBranchTransferAllowed($branch, $hbr, $item->{C4::Context->preference("BranchTransferLimitsType")} )
- )) {
- $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $hbr;
+ if ( $doreturn and ( $branch ne $hbr ) and not $messages->{'WrongTransfer'} and ( $validTransfert ne 1 ) ) {
+ if (C4::Context->preference("AutomaticItemReturn")
+ or ( C4::Context->preference("UseBranchTransferLimits")
+ and !IsBranchTransferAllowed( $branch, $hbr, $item->{ $branchtransferfield } ) )
+ ) {
+ $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'}, $branch, $hbr;
$debug and warn "item: " . Dumper($item);
ModItemTransfer($item->{'itemnumber'}, $branch, $hbr);
$messages->{'WasTransfered'} = 1;
diff --git a/circ/returns.pl b/circ/returns.pl
index 72cf8b4..0b08219 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -45,6 +45,7 @@ use C4::Overdues qw/CheckBorrowerDebarred/;
use C4::Branch; # GetBranches GetBranchName
use C4::Koha; # FIXME : is it still useful ?
use C4::RotatingCollections;
+use C4::Debug;
my $query = new CGI;
@@ -171,11 +172,16 @@ my $barcode = $query->param('barcode');
my $exemptfine = $query->param('exemptfine');
my $dropboxmode = $query->param('dropboxmode');
my $dotransfer = $query->param('dotransfer');
+my $override = $query->param('override');
my $calendar = C4::Calendar->new( branchcode => $userenv_branch );
#dropbox: get last open day (today - 1)
my $today = C4::Dates->new();
my $today_iso = $today->output('iso');
my $dropboxdate = $calendar->addDate($today, -1);
+if ($debug){
+ use YAML;
+ warn Dump($query->Vars);
+}
if ($dotransfer){
# An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
my $transferitem = $query->param('transferitem');
@@ -206,7 +212,7 @@ if ($barcode) {
# save the return
#
( $returned, $messages, $issueinformation, $borrower ) =
- AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode); # do the return
+ AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode,$override); # do the return
# get biblio description
my $biblio = GetBiblioFromItemNumber($itemnumber);
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
index c8d1cbc..0300c41 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
@@ -235,8 +235,12 @@ function refocus(calendar) {
<li>Too many checked out (already checked out / max : <!-- TMPL_VAR name="TOO_MANY" -->)</li>
<!-- /TMPL_IF -->
+<!-- TMPL_IF NAME="BRANCH_TRANSFER_NOT_ALLOWED" -->
+ <li>Item should be at <!--TMPL_VAR Name="BRANCH_TRANSFER_NOT_ALLOWED"-->.<br /> It should not be checked out in this library.</li>
+<!-- /TMPL_IF -->
+
<!-- TMPL_IF NAME="PATRON_CANT" -->
- <li>This patron can't check out this item per library circulation policy</i>
+ <li>This patron can't check out this item per library circulation policy</li>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="NOT_FOR_LOAN_FORCING" -->
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tmpl
index fef7c57..b8bab7f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tmpl
@@ -59,7 +59,16 @@ function Dopop(link) {
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="wrongbranch" -->
-<div class="dialog alert"><h3>Cannot Check In</h3><p>This item must be checked in at its home library. <strong>NOT CHECKED IN</strong></p>
+<div class="dialog alert"><h3>Cannot Check In</h3><p>This item must be checked in at its home library: <!-- TMPL_VAR Name="homebranch" -->. <strong>NOT CHECKED IN</strong></p>
+ <form method="post" action="returns.pl" class="confirm">
+
+ <input type="hidden" name="barcode" value="<!-- TMPL_VAR Name="barcode" -->" />
+ <input type="hidden" name="exemptfine" value="<!-- TMPL_VAR Name="exemptfine" -->" />
+ <input type="hidden" name="dropboxmode" value="<!-- TMPL_VAR Name="dropboxmode" -->" />
+ <input type="submit" name="override" value="Check-In" class="submit" />
+ <input type="submit" name="cancel" value="Cancel" class="submit" />
+ <input type="submit" name="OK" value="OK" class="submit" />
+ </form>
</div>
<!-- /TMPL_IF -->
<!-- case of a mistake in transfer loop -->
--
1.6.3.3
More information about the Koha-patches
mailing list