From 97f8b3abfff5acefe8a5b948b3c63ef7e5cb851e Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Mon, 12 May 2008 05:29:36 -0500 Subject: [PATCH] Make dropbox mode obey Calendar module according to CircControl branch. Signed-off-by: Joshua Ferraro --- C4/Circulation.pm | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b2cf346417..1711181001 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1171,8 +1171,10 @@ Returns a book. C<$barcode> is the bar code of the book being returned. C<$branch> is the code of the branch where the book is being returned. C<$exemptfine> indicates that overdue charges for the item will be removed. C<$dropbox> -indicates that the check-in date is assumed to be yesterday. If overdue +indicates that the check-in date is assumed to be yesterday, or the last +non-holiday as defined in C4::Calendar . If overdue charges are applied and C<$dropbox> is true, the last charge will be removed. +This assumes that the fines accrual script has run for _today_. C<&AddReturn> returns a list of four items: @@ -1245,6 +1247,7 @@ sub AddReturn { # check if the book is in a permanent collection.... my $hbr = $iteminformation->{C4::Context->preference("HomeOrHoldingBranch")}; my $branches = GetBranches(); + # FIXME -- This 'PE' attribute is largely undocumented. afaict, there's no user interface that reflects this functionality. if ( $hbr && $branches->{$hbr}->{'PE'} ) { $messages->{'IsPermanent'} = $hbr; } @@ -1269,11 +1272,20 @@ sub AddReturn { # case of a return of document (deal with issues and holdingbranch) if ($doreturn) { + my $circControlBranch; if($dropbox) { # don't allow dropbox mode to create an invalid entry in issues ( issuedate > returndate) undef($dropbox) if ( $iteminformation->{'issuedate'} eq C4::Dates->today('iso') ); + if (C4::Context->preference('CircControl') eq 'ItemHomeBranch' ) { + $circControlBranch = $iteminformation->{homebranch}; + } elsif ( C4::Context->preference('CircControl') eq 'PatronLibrary') { + $circControlBranch = $borrower->{branchcode}; + } else { # CircControl must be PickupLibrary. + $circControlBranch = $iteminformation->{holdingbranch}; + # FIXME - is this right ? are we sure that the holdingbranch is still the pickup branch? + } } - MarkIssueReturned($borrower->{'borrowernumber'}, $iteminformation->{'itemnumber'},$dropbox); + MarkIssueReturned($borrower->{'borrowernumber'}, $iteminformation->{'itemnumber'},$circControlBranch); $messages->{'WasReturned'} = 1; # FIXME is the "= 1" right? } @@ -1371,15 +1383,16 @@ sub AddReturn { =over 4 -MarkIssueReturned($borrowernumber, $itemnumber); +MarkIssueReturned($borrowernumber, $itemnumber, $dropbox_branch); =back Unconditionally marks an issue as being returned by moving the C row to C and setting C to the current date, or -yesterday if C is true. Assumes you've -already checked that yesterday > issuedate. +the last non-holiday date of the branccode specified in +C . Assumes you've already checked that +it's safe to do this, i.e. last non-holiday > issuedate. Ideally, this function would be internal to C, not exported, but it is currently needed by one @@ -1388,14 +1401,14 @@ routine in C. =cut sub MarkIssueReturned { - my ($borrowernumber, $itemnumber, $dropbox) = @_; + my ($borrowernumber, $itemnumber, $dropbox_branch ) = @_; my $dbh = C4::Context->dbh; my $query = "UPDATE issues SET returndate="; my @bind = ($borrowernumber,$itemnumber); - if($dropbox) { - my @datearr = localtime( time() ); - my @yesterdayarr = Add_Delta_Days( $datearr[5] + 1900 , $datearr[4] + 1, $datearr[3] , -1 ); - unshift @bind, sprintf("%0.4d-%0.2d-%0.2d",@yesterdayarr) ; + if($dropbox_branch) { + my $calendar = C4::Calendar->new( branchcode => $dropbox_branch ); + my $dropboxdate = $calendar->addDate(C4::Dates->new(), -1 ); + unshift @bind, $dropboxdate->output('iso') ; $query .= " ? " } else { $query .= " now() "; -- 2.39.5