X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FCirculation.pm;h=df3245de15f3eacf87ba96bef867306e22a50426;hb=7b71c6588587784665c724da99a9add1b54464bb;hp=3fc124f81194e6cdd2d968703b3b6239b53841b9;hpb=f7644ec91f2d151535f8f5125c4057a9213d766e;p=koha.git diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 3fc124f811..df3245de15 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -564,7 +564,7 @@ sub itemissues { $data->{'borrower'} = $data2->{'borrowernumber'}; } else { - $data->{'date_due'} = ($data->{'wthdrawn'} eq '1') ? 'Cancelled' : 'Available'; + $data->{'date_due'} = ($data->{'withdrawn'} eq '1') ? 'Cancelled' : 'Available'; } @@ -826,9 +826,15 @@ sub CanBookBeIssued { $needsconfirmation{PATRON_CANT} = 1; } else { if($max_loans_allowed){ - $needsconfirmation{TOO_MANY} = 1; - $needsconfirmation{current_loan_count} = $current_loan_count; - $needsconfirmation{max_loans_allowed} = $max_loans_allowed; + if ( C4::Context->preference("AllowTooManyOverride") ) { + $needsconfirmation{TOO_MANY} = 1; + $needsconfirmation{current_loan_count} = $current_loan_count; + $needsconfirmation{max_loans_allowed} = $max_loans_allowed; + } else { + $issuingimpossible{TOO_MANY} = 1; + $issuingimpossible{current_loan_count} = $current_loan_count; + $issuingimpossible{max_loans_allowed} = $max_loans_allowed; + } } } @@ -873,7 +879,7 @@ sub CanBookBeIssued { } } } - if ( $item->{'wthdrawn'} && $item->{'wthdrawn'} > 0 ) + if ( $item->{'withdrawn'} && $item->{'withdrawn'} > 0 ) { $issuingimpossible{WTHDRAWN} = 1; } @@ -887,11 +893,13 @@ sub CanBookBeIssued { $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' ); $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' ); } - if ( C4::Context->preference("IndependantBranches") ) { + if ( C4::Context->preference("IndependentBranches") ) { my $userenv = C4::Context->userenv; if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) { - $issuingimpossible{ITEMNOTSAMEBRANCH} = 1 - if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ); + if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){ + $issuingimpossible{ITEMNOTSAMEBRANCH} = 1; + $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")}; + } $needsconfirmation{BORRNOTSAMEBRANCH} = GetBranchName( $borrower->{'branchcode'} ) if ( $borrower->{'branchcode'} ne $userenv->{branch} ); } @@ -1671,7 +1679,7 @@ The book's home branch is a permanent collection. If you have borrowed this book, you are not allowed to return it. The value is the code for the book's home branch. -=item C +=item C This book has been withdrawn/cancelled. The value should be ignored. @@ -1764,8 +1772,8 @@ sub AddReturn { return ( $doreturn, $messages, $issue, $borrower ); } - if ( $item->{'wthdrawn'} ) { # book has been cancelled - $messages->{'wthdrawn'} = 1; + if ( $item->{'withdrawn'} ) { # book has been cancelled + $messages->{'withdrawn'} = 1; $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems"); } @@ -1785,19 +1793,36 @@ sub AddReturn { } if ($borrowernumber) { - if($issue->{'overdue'}){ - my ( $amount, $type, $unitcounttotal ) = C4::Overdues::CalcFine( $item, $borrower->{categorycode},$branch, $datedue, $today ); + if( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'}){ + # we only need to calculate and change the fines if we want to do that on return + # Should be on for hourly loans + my $control = C4::Context->preference('CircControl'); + my $control_branchcode = + ( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch} + : ( $control eq 'PatronLibrary' ) ? $borrower->{branchcode} + : $issue->{branchcode}; + + my ( $amount, $type, $unitcounttotal ) = + C4::Overdues::CalcFine( $item, $borrower->{categorycode}, + $control_branchcode, $datedue, $today ); + $type ||= q{}; - if ( $amount > 0 && ( C4::Context->preference('finesMode') eq 'production' )) { - C4::Overdues::UpdateFine( - $issue->{itemnumber}, - $issue->{borrowernumber}, - $amount, $type, output_pref($datedue) - ); - } + + if ( $amount > 0 + && C4::Context->preference('finesMode') eq 'production' ) + { + C4::Overdues::UpdateFine( $issue->{itemnumber}, + $issue->{borrowernumber}, + $amount, $type, output_pref($datedue) ); + } } - MarkIssueReturned($borrowernumber, $item->{'itemnumber'}, $circControlBranch, '', $borrower->{'privacy'}); - $messages->{'WasReturned'} = 1; # FIXME is the "= 1" right? This could be the borrower hash. + + MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, + $circControlBranch, '', $borrower->{'privacy'} ); + + # FIXME is the "= 1" right? This could be the borrower hash. + $messages->{'WasReturned'} = 1; + } ModItem({ onloan => undef }, $issue->{'biblionumber'}, $item->{'itemnumber'}); @@ -1859,7 +1884,7 @@ sub AddReturn { # find reserves..... # if we don't have a reserve with the status W, we launch the Checkreserves routine my ($resfound, $resrec); - ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'} ) unless ( $item->{'wthdrawn'} ); + ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'} ) unless ( $item->{'withdrawn'} ); if ($resfound) { $resrec->{'ResFound'} = $resfound; $messages->{'ResFound'} = $resrec; @@ -1967,6 +1992,7 @@ sub MarkIssueReturned { if ( $privacy == 2) { # The default of 0 does not work due to foreign key constraints # The anonymisation will fail quietly if AnonymousPatron is not a valid entry + # FIXME the above is unacceptable - bug 9942 relates my $anonymouspatron = (C4::Context->preference('AnonymousPatron')) ? C4::Context->preference('AnonymousPatron') : 0; my $sth_ano = $dbh->prepare("UPDATE old_issues SET borrowernumber=? WHERE borrowernumber = ? @@ -2401,8 +2427,8 @@ SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )- FROM issues LEFT JOIN items USING (itemnumber) LEFT OUTER JOIN branches USING (branchcode) -WhERE returndate is NULL -AND ( TO_DAYS( NOW() )-TO_DAYS( date_due ) ) < ? +WHERE returndate is NULL +HAVING days_until_due > 0 AND days_until_due < ? END_SQL my @bind_parameters = ( $params->{'days_in_advance'} ); @@ -2460,8 +2486,9 @@ sub CanBookBeRenewed { $error = "too_many"; } - my $resstatus = C4::Reserves::GetReserveStatus($itemnumber); - if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) { + my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber ); + + if ( $resfound ) { # '' when no hold was found $renewokay = 0; $error = "on_reserve"; } @@ -2821,7 +2848,7 @@ sub DeleteTransfer { =head2 AnonymiseIssueHistory - $rows = AnonymiseIssueHistory($date,$borrowernumber) + ($rows,$err_history_not_deleted) = AnonymiseIssueHistory($date,$borrowernumber) This function write NULL instead of C<$borrowernumber> given on input arg into the table issues. if C<$borrowernumber> is not set, it will delete the issue history for all borrower older than C<$date>. @@ -2829,7 +2856,7 @@ if C<$borrowernumber> is not set, it will delete the issue history for all borro If c<$borrowernumber> is set, it will delete issue history for only that borrower, regardless of their opac privacy setting (force delete). -return the number of affected rows. +return the number of affected rows and a value that evaluates to true if an error occurred deleting the history. =cut @@ -2856,8 +2883,9 @@ sub AnonymiseIssueHistory { } my $sth = $dbh->prepare($query); $sth->execute(@bind_params); + my $anonymisation_err = $dbh->err; my $rows_affected = $sth->rows; ### doublecheck row count return function - return $rows_affected; + return ($rows_affected, $anonymisation_err); } =head2 SendCirculationAlert @@ -3223,28 +3251,31 @@ $code is either itemtype or collection code depending on what the pref BranchTra sub CreateBranchTransferLimit { my ( $toBranch, $fromBranch, $code ) = @_; - + return unless defined($toBranch) && defined($fromBranch); my $limitType = C4::Context->preference("BranchTransferLimitsType"); my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("INSERT INTO branch_transfer_limits ( $limitType, toBranch, fromBranch ) VALUES ( ?, ?, ? )"); - $sth->execute( $code, $toBranch, $fromBranch ); + return $sth->execute( $code, $toBranch, $fromBranch ); } =head2 DeleteBranchTransferLimits -DeleteBranchTransferLimits($frombranch); + my $result = DeleteBranchTransferLimits($frombranch); -Deletes all the branch transfer limits for one branch +Deletes all the library transfer limits for one library. Returns the +number of limits deleted, 0e0 if no limits were deleted, or undef if +no arguments are supplied. =cut sub DeleteBranchTransferLimits { my $branch = shift; + return unless defined $branch; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("DELETE FROM branch_transfer_limits WHERE fromBranch = ?"); - $sth->execute($branch); + return $sth->execute($branch); } sub ReturnLostItem{