BugFixing : 3306
[koha.git] / C4 / Circulation.pm
index 4c547c4..7c9fe89 100644 (file)
@@ -979,7 +979,7 @@ sub AddIssue {
         unless ($datedue) {
             my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'};
             my $loanlength = GetLoanLength( $borrower->{'categorycode'}, $itype, $branch );
-            $datedue = CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $loanlength, $branch );
+            $datedue = CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $loanlength, $branch, $borrower );
 
             # if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
             if ( C4::Context->preference('ReturnBeforeExpiry') && $datedue->output('iso') gt $borrower->{dateexpiry} ) {
@@ -995,7 +995,7 @@ sub AddIssue {
         );
         $item->{'issues'}++;
         ModItem({ issues           => $item->{'issues'},
-                  holdingbranch    => C4::Context->userenv->{branch} or $item->{'holdingbranch'},
+                  holdingbranch    => C4::Context->userenv->{branch},
                   itemlost         => 0,
                   datelastborrowed => C4::Dates->new()->output('iso'),
                   onloan           => $datedue->output('iso'),
@@ -1312,10 +1312,11 @@ sub AddReturn {
        $branch ||=C4::Context->userenv->{'branch'};
     
     # get information on item
-    my $iteminformation = GetItemIssue( GetItemnumberFromBarcode($barcode));
+    my $itemnumber = GetItemnumberFromBarcode($barcode);
+    my $iteminformation = GetItemIssue( $itemnumber );
     my $biblio = GetBiblioItemData($iteminformation->{'biblioitemnumber'});
 #     use Data::Dumper;warn Data::Dumper::Dumper($iteminformation);  
-    unless ($iteminformation->{'itemnumber'} ) {
+    unless ( $iteminformation->{'itemnumber'} or $itemnumber) {
         $messages->{'BadBarcode'} = $barcode;
         $doreturn = 0;
     } else {
@@ -1327,7 +1328,7 @@ sub AddReturn {
         
         # even though item is not on loan, it may still
         # be transferred; therefore, get current branch information
-        my $curr_iteminfo = GetItem($iteminformation->{'itemnumber'});
+        my $curr_iteminfo = GetItem($itemnumber);
         $iteminformation->{'homebranch'} = $curr_iteminfo->{'homebranch'};
         $iteminformation->{'holdingbranch'} = $curr_iteminfo->{'holdingbranch'};
         $iteminformation->{'itemlost'} = $curr_iteminfo->{'itemlost'};
@@ -1341,7 +1342,7 @@ sub AddReturn {
         }
                
                    # if independent branches are on and returning to different branch, refuse the return
-        if ($hbr ne $branch && C4::Context->preference("IndependantBranches")){
+        if ($hbr ne $branch && C4::Context->preference("IndependantBranches") && $iteminformation->{borrowernumber}){
                          $messages->{'Wrongbranch'} = 1;
                          $doreturn=0;
                    }
@@ -1372,8 +1373,8 @@ sub AddReturn {
             
             
             # We update the holdingbranch from circControlBranch variable
-            UpdateHoldingbranch($circControlBranch,$iteminformation->{'itemnumber'});
-            $iteminformation->{'holdingbranch'} = $circControlBranch;
+            UpdateHoldingbranch($branch,$iteminformation->{'itemnumber'});
+            $iteminformation->{'holdingbranch'} = $branch;
         
             
             ModDateLastSeen( $iteminformation->{'itemnumber'} );
@@ -1420,8 +1421,8 @@ sub AddReturn {
     
     # find reserves.....
     #     if we don't have a reserve with the status W, we launch the Checkreserves routine
-        my ( $resfound, $resrec ) =
-        C4::Reserves::CheckReserves( $iteminformation->{'itemnumber'} );
+        my ( $resfound, $resrec ) = 
+        C4::Reserves::CheckReserves( $itemnumber, $barcode );
         if ($resfound) {
             $resrec->{'ResFound'}   = $resfound;
             $messages->{'ResFound'} = $resrec;
@@ -1970,7 +1971,7 @@ sub AddRenewal {
                        $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);  # this branch is the transactional branch.
+               $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.
     }