bug 2893: extend conditions handled by AllowNotForLoanOverride
[koha.git] / C4 / Circulation.pm
index e6389ee..f4cea86 100644 (file)
@@ -771,12 +771,20 @@ sub CanBookBeIssued {
             $sth->execute($item->{'itemtype'});
             my $notforloan=$sth->fetchrow_hashref();
             $sth->finish();
-            if ($notforloan->{'notforloan'} == 1){
-                $issuingimpossible{NOT_FOR_LOAN} = 1;
+            if ($notforloan->{'notforloan'}) {
+                if (!C4::Context->preference("AllowNotForLoanOverride")) {
+                    $issuingimpossible{NOT_FOR_LOAN} = 1;
+                } else {
+                    $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
+                }
             }
         }
         elsif ($biblioitem->{'notforloan'} == 1){
-            $issuingimpossible{NOT_FOR_LOAN} = 1;
+            if (!C4::Context->preference("AllowNotForLoanOverride")) {
+                $issuingimpossible{NOT_FOR_LOAN} = 1;
+            } else {
+                $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
+            }
         }
     }
     if ( $item->{'wthdrawn'} && $item->{'wthdrawn'} == 1 )
@@ -790,7 +798,7 @@ sub CanBookBeIssued {
     }
     if ( C4::Context->preference("IndependantBranches") ) {
         my $userenv = C4::Context->userenv;
-        if ( ($userenv) && ( $userenv->{flags} != 1 ) ) {
+        if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
             $issuingimpossible{NOTSAMEBRANCH} = 1
               if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} );
         }
@@ -845,12 +853,6 @@ sub CanBookBeIssued {
 "$res->{'reservedate'} : $resborrower->{'firstname'} $resborrower->{'surname'} ($resborrower->{'cardnumber'})";
         }
     }
-    if ( C4::Context->preference("LibraryName") eq "Horowhenua Library Trust" ) {
-        if ( $borrower->{'categorycode'} eq 'W' ) {
-            my %emptyhash;
-            return ( \%emptyhash, \%needsconfirmation );
-        }
-       }
        return ( \%issuingimpossible, \%needsconfirmation );
 }
 
@@ -2101,22 +2103,6 @@ sub AddRenewal {
     my $branch  = (@_) ? shift : $item->{homebranch};  # opac-renew doesn't send branch
     my $datedue = shift;
     my $lastreneweddate = shift;
-
-    # If the due date wasn't specified, calculate it by adding the
-    # book's loan length to today's date.
-    unless ($datedue && $datedue->output('iso')) {
-
-        my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return undef;
-        my $loanlength = GetLoanLength(
-            $borrower->{'categorycode'},
-             (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} ,
-                       $item->{homebranch}                     # item's homebranch determines loanlength OR do we want the branch specified by the AddRenewal argument?
-        );
-               #FIXME -- use circControl?
-               $datedue =  CalcDateDue(C4::Dates->new(),$loanlength,$branch,$borrower);        # this branch is the transactional branch.
-                                                               # The question of whether to use item's homebranch calendar is open.
-    }
-
     # $lastreneweddate defaults to today.
     unless (defined $lastreneweddate) {
         $lastreneweddate = strftime( "%Y-%m-%d", localtime );
@@ -2134,21 +2120,22 @@ sub AddRenewal {
     $sth->finish;
 
     # If the due date wasn't specified, calculate it by adding the
-    # book's loan length to due's date.
-    unless (@_ and $datedue = shift and $datedue->output('iso')) {
+    # book's loan length to today's date or the current due date
+    # based on the value of the RenewalPeriodBase syspref.
+    unless ($datedue && $datedue->output('iso')) {
 
         my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return undef;
         my $loanlength = GetLoanLength(
             $borrower->{'categorycode'},
              (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} ,
-                       $item->{homebranch}                     # item's homebranch determines loanlength OR do we want the branch specified by the AddRenewal argument?
+                       $item->{homebranch}     # item's homebranch determines loanlength OR do we want the branch specified by the AddRenewal argument?
         );
 
         $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
                                         C4::Dates->new($issuedata->{date_due}, 'iso') :
                                         C4::Dates->new();
         #FIXME -- use circControl?
-        $datedue =  CalcDateDue($datedue,$loanlength,$branch); # this branch is the transactional branch.
+        $datedue =  CalcDateDue($datedue,$loanlength,$branch,$borrower);    # this branch is the transactional branch.
         # The question of whether to use item's homebranch calendar is open.
     }