View | Details | Raw Unified | Return to bug 20912
Collapse All | Expand All

(-)a/C4/Circulation.pm (-76 / +75 lines)
Lines 681-687 sub CanBookBeIssued { Link Here
681
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
681
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
682
    my $override_high_holds = $params->{override_high_holds} || 0;
682
    my $override_high_holds = $params->{override_high_holds} || 0;
683
683
684
    my $item = Koha::Items->find({barcode => $barcode });
684
    my $item_object = Koha::Items->find({barcode => $barcode });
685
685
686
    # MANDATORY CHECKS - unless item exists, nothing else matters
686
    # MANDATORY CHECKS - unless item exists, nothing else matters
687
    unless ( $item_object ) {
687
    unless ( $item_object ) {
Lines 689-704 sub CanBookBeIssued { Link Here
689
    }
689
    }
690
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
690
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
691
691
692
    my $item_unblessed = $item->unblessed; # Transition...
692
    my $item_unblessed = $item_object->unblessed; # Transition...
693
    my $issue = $item->checkout;
693
    my $issue = $item_object->checkout;
694
    my $biblio = $item->biblio;
694
    my $biblio = $item_object->biblio;
695
695
696
    my $biblioitem = $biblio->biblioitem;
696
    my $biblioitem = $biblio->biblioitem;
697
    my $effective_itemtype = $item->effective_itemtype;
697
    my $effective_itemtype = $item_object->effective_itemtype;
698
    my $dbh             = C4::Context->dbh;
698
    my $dbh             = C4::Context->dbh;
699
    my $patron_unblessed = $patron->unblessed;
699
    my $patron_unblessed = $patron->unblessed;
700
700
701
    my $library = Koha::Libraries->find( _GetCircControlBranch($item, $patron_unblessed) );
701
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
702
    #
702
    #
703
    # DUE DATE is OK ? -- should already have checked.
703
    # DUE DATE is OK ? -- should already have checked.
704
    #
704
    #
Lines 709-715 sub CanBookBeIssued { Link Here
709
    unless ( $duedate ) {
709
    unless ( $duedate ) {
710
        my $issuedate = $now->clone();
710
        my $issuedate = $now->clone();
711
711
712
        my $branch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
712
        my $branch = $circ_library;
713
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
713
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
714
714
715
        # Offline circ calls AddIssue directly, doesn't run through here
715
        # Offline circ calls AddIssue directly, doesn't run through here
Lines 719-725 sub CanBookBeIssued { Link Here
719
    my $fees = Koha::Charges::Fees->new(
719
    my $fees = Koha::Charges::Fees->new(
720
        {
720
        {
721
            patron    => $patron,
721
            patron    => $patron,
722
            library   => $library,
722
            library   => $circ_library,
723
            item      => $item_object,
723
            item      => $item_object,
724
            to_date   => $duedate,
724
            to_date   => $duedate,
725
        }
725
        }
Lines 738-754 sub CanBookBeIssued { Link Here
738
    #
738
    #
739
    # BORROWER STATUS
739
    # BORROWER STATUS
740
    #
740
    #
741
    if ( $patron->category->category_type eq 'X' && (  $item->barcode  )) {
741
    if ( $patron->category->category_type eq 'X' && (  $item_object->barcode  )) {
742
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
742
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
743
        &UpdateStats({
743
        &UpdateStats({
744
                     branch => C4::Context->userenv->{'branch'},
744
                     branch => C4::Context->userenv->{'branch'},
745
                     type => 'localuse',
745
                     type => 'localuse',
746
                     itemnumber => $item->itemnumber,
746
                     itemnumber => $item_object->itemnumber,
747
                     itemtype => $effective_itemtype,
747
                     itemtype => $effective_itemtype,
748
                     borrowernumber => $patron->borrowernumber,
748
                     borrowernumber => $patron->borrowernumber,
749
                     ccode => $item->ccode}
749
                     ccode => $item_object->ccode}
750
                    );
750
                    );
751
        ModDateLastSeen( $item->itemnumber ); # FIXME Move to Koha::Item
751
        ModDateLastSeen( $item_object->itemnumber ); # FIXME Move to Koha::Item
752
        return( { STATS => 1 }, {});
752
        return( { STATS => 1 }, {});
753
    }
753
    }
754
754
Lines 859-865 sub CanBookBeIssued { Link Here
859
        } else {
859
        } else {
860
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
860
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
861
                $patron->borrowernumber,
861
                $patron->borrowernumber,
862
                $item->itemnumber,
862
                $item_object->itemnumber,
863
            );
863
            );
864
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
864
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
865
                if ( $renewerror eq 'onsite_checkout' ) {
865
                if ( $renewerror eq 'onsite_checkout' ) {
Lines 901-907 sub CanBookBeIssued { Link Here
901
      and $issue
901
      and $issue
902
      and $issue->onsite_checkout
902
      and $issue->onsite_checkout
903
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
903
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
904
    my $toomany = TooMany( $patron_unblessed, $item->biblionumber, $item_unblessed, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
904
    my $toomany = TooMany( $patron_unblessed, $item_object->biblionumber, $item_unblessed, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
905
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
905
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
906
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
906
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
907
        if ( $toomany->{max_allowed} == 0 ) {
907
        if ( $toomany->{max_allowed} == 0 ) {
Lines 929-942 sub CanBookBeIssued { Link Here
929
    #
929
    #
930
    # ITEM CHECKING
930
    # ITEM CHECKING
931
    #
931
    #
932
    if ( $item->notforloan )
932
    if ( $item_object->notforloan )
933
    {
933
    {
934
        if(!C4::Context->preference("AllowNotForLoanOverride")){
934
        if(!C4::Context->preference("AllowNotForLoanOverride")){
935
            $issuingimpossible{NOT_FOR_LOAN} = 1;
935
            $issuingimpossible{NOT_FOR_LOAN} = 1;
936
            $issuingimpossible{item_notforloan} = $item->notforloan;
936
            $issuingimpossible{item_notforloan} = $item_object->notforloan;
937
        }else{
937
        }else{
938
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
938
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
939
            $needsconfirmation{item_notforloan} = $item->notforloan;
939
            $needsconfirmation{item_notforloan} = $item_object->notforloan;
940
        }
940
        }
941
    }
941
    }
942
    else {
942
    else {
Lines 969-985 sub CanBookBeIssued { Link Here
969
            }
969
            }
970
        }
970
        }
971
    }
971
    }
972
    if ( $item->withdrawn && $item->withdrawn > 0 )
972
    if ( $item_object->withdrawn && $item_object->withdrawn > 0 )
973
    {
973
    {
974
        $issuingimpossible{WTHDRAWN} = 1;
974
        $issuingimpossible{WTHDRAWN} = 1;
975
    }
975
    }
976
    if (   $item->restricted
976
    if (   $item_object->restricted
977
        && $item->restricted == 1 )
977
        && $item_object->restricted == 1 )
978
    {
978
    {
979
        $issuingimpossible{RESTRICTED} = 1;
979
        $issuingimpossible{RESTRICTED} = 1;
980
    }
980
    }
981
    if ( $item->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
981
    if ( $item_object->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
982
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->itemlost });
982
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item_object->itemlost });
983
        my $code = $av->count ? $av->next->lib : '';
983
        my $code = $av->count ? $av->next->lib : '';
984
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
984
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
985
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
985
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
Lines 988-996 sub CanBookBeIssued { Link Here
988
        my $userenv = C4::Context->userenv;
988
        my $userenv = C4::Context->userenv;
989
        unless ( C4::Context->IsSuperLibrarian() ) {
989
        unless ( C4::Context->IsSuperLibrarian() ) {
990
            my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch");
990
            my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch");
991
            if ( $item->$HomeOrHoldingBranch ne $userenv->{branch} ){
991
            if ( $item_object->$HomeOrHoldingBranch ne $userenv->{branch} ){
992
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
992
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
993
                $issuingimpossible{'itemhomebranch'} = $item->$HomeOrHoldingBranch;
993
                $issuingimpossible{'itemhomebranch'} = $item_object->$HomeOrHoldingBranch;
994
            }
994
            }
995
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
995
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
996
              if ( $patron->branchcode ne $userenv->{branch} );
996
              if ( $patron->branchcode ne $userenv->{branch} );
Lines 1002-1009 sub CanBookBeIssued { Link Here
1002
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
1002
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
1003
1003
1004
    if ( $rentalConfirmation ){
1004
    if ( $rentalConfirmation ){
1005
        my ($rentalCharge) = GetIssuingCharges( $item->itemnumber, $patron->borrowernumber );
1005
        my ($rentalCharge) = GetIssuingCharges( $item_object->itemnumber, $patron->borrowernumber );
1006
        my $itemtype = Koha::ItemTypes->find( $item->itype ); # GetItem sets effective itemtype
1006
        my $itemtype = Koha::ItemTypes->find( $item_object->itype ); # GetItem sets effective itemtype
1007
        $rentalCharge += $fees->accumulate_rentalcharge({ from => dt_from_string(), to => $duedate });
1007
        $rentalCharge += $fees->accumulate_rentalcharge({ from => dt_from_string(), to => $duedate });
1008
        if ( $rentalCharge > 0 ){
1008
        if ( $rentalCharge > 0 ){
1009
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
1009
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
Lines 1012-1018 sub CanBookBeIssued { Link Here
1012
1012
1013
    unless ( $ignore_reserves ) {
1013
    unless ( $ignore_reserves ) {
1014
        # See if the item is on reserve.
1014
        # See if the item is on reserve.
1015
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->itemnumber );
1015
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item_object->itemnumber );
1016
        if ($restype) {
1016
        if ($restype) {
1017
            my $resbor = $res->{'borrowernumber'};
1017
            my $resbor = $res->{'borrowernumber'};
1018
            if ( $resbor ne $patron->borrowernumber ) {
1018
            if ( $resbor ne $patron->borrowernumber ) {
Lines 1086-1092 sub CanBookBeIssued { Link Here
1086
    ) {
1086
    ) {
1087
        # Check if borrower has already issued an item from the same biblio
1087
        # Check if borrower has already issued an item from the same biblio
1088
        # Only if it's not a subscription
1088
        # Only if it's not a subscription
1089
        my $biblionumber = $item->biblionumber;
1089
        my $biblionumber = $item_object->biblionumber;
1090
        require C4::Serials;
1090
        require C4::Serials;
1091
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1091
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1092
        unless ($is_a_subscription) {
1092
        unless ($is_a_subscription) {
Lines 1317-1337 sub AddIssue { Link Here
1317
    # Stop here if the patron or barcode doesn't exist
1317
    # Stop here if the patron or barcode doesn't exist
1318
    if ( $borrower && $barcode && $barcodecheck ) {
1318
    if ( $borrower && $barcode && $barcodecheck ) {
1319
        # find which item we issue
1319
        # find which item we issue
1320
        my $item = Koha::Items->find({ barcode => $barcode })
1320
        my $item_object = Koha::Items->find({ barcode => $barcode })
1321
          or return;    # if we don't get an Item, abort.
1321
          or return;    # if we don't get an Item, abort.
1322
        my $item_unblessed = $item->unblessed;
1322
        my $item_unblessed = $item_object->unblessed;
1323
1323
1324
        my $branch = _GetCircControlBranch( $item_unblessed, $borrower );
1324
        my $branch = _GetCircControlBranch( $item_unblessed, $borrower );
1325
1325
1326
        # get actual issuing if there is one
1326
        # get actual issuing if there is one
1327
        my $actualissue = $item->checkout;
1327
        my $actualissue = $item_object->checkout;
1328
1328
1329
        # check if we just renew the issue.
1329
        # check if we just renew the issue.
1330
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1330
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1331
                and not $switch_onsite_checkout ) {
1331
                and not $switch_onsite_checkout ) {
1332
            $datedue = AddRenewal(
1332
            $datedue = AddRenewal(
1333
                $borrower->{'borrowernumber'},
1333
                $borrower->{'borrowernumber'},
1334
                $item->itemnumber,
1334
                $item_object->itemnumber,
1335
                $branch,
1335
                $branch,
1336
                $datedue,
1336
                $datedue,
1337
                $issuedate,    # here interpreted as the renewal date
1337
                $issuedate,    # here interpreted as the renewal date
Lines 1362-1374 sub AddIssue { Link Here
1362
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1362
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1363
                my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
1363
                my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
1364
                return unless $allowed;
1364
                return unless $allowed;
1365
                AddReturn( $item->barcode, C4::Context->userenv->{'branch'} );
1365
                AddReturn( $item_object->barcode, C4::Context->userenv->{'branch'} );
1366
            }
1366
            }
1367
1367
1368
            C4::Reserves::MoveReserve( $item->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1368
            C4::Reserves::MoveReserve( $item_object->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1369
1369
1370
            # Starting process for transfer job (checking transfert and validate it if we have one)
1370
            # Starting process for transfer job (checking transfert and validate it if we have one)
1371
            my ($datesent) = GetTransfers( $item->itemnumber );
1371
            my ($datesent) = GetTransfers( $item_object->itemnumber );
1372
            if ($datesent) {
1372
            if ($datesent) {
1373
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1373
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1374
                my $sth = $dbh->prepare(
1374
                my $sth = $dbh->prepare(
Lines 1379-1392 sub AddIssue { Link Here
1379
                    WHERE itemnumber= ? AND datearrived IS NULL"
1379
                    WHERE itemnumber= ? AND datearrived IS NULL"
1380
                );
1380
                );
1381
                $sth->execute( C4::Context->userenv->{'branch'},
1381
                $sth->execute( C4::Context->userenv->{'branch'},
1382
                    $item->itemnumber );
1382
                    $item_object->itemnumber );
1383
            }
1383
            }
1384
1384
1385
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1385
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1386
            unless ($auto_renew) {
1386
            unless ($auto_renew) {
1387
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1387
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1388
                    {   categorycode => $borrower->{categorycode},
1388
                    {   categorycode => $borrower->{categorycode},
1389
                        itemtype     => $item->effective_itemtype,
1389
                        itemtype     => $item_object->effective_itemtype,
1390
                        branchcode   => $branch
1390
                        branchcode   => $branch
1391
                    }
1391
                    }
1392
                );
1392
                );
Lines 1396-1402 sub AddIssue { Link Here
1396
1396
1397
            # Record in the database the fact that the book was issued.
1397
            # Record in the database the fact that the book was issued.
1398
            unless ($datedue) {
1398
            unless ($datedue) {
1399
                my $itype = $item->effective_itemtype;
1399
                my $itype = $item_object->effective_itemtype;
1400
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1400
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1401
1401
1402
            }
1402
            }
Lines 1411-1424 sub AddIssue { Link Here
1411
                auto_renew      => $auto_renew ? 1 : 0,
1411
                auto_renew      => $auto_renew ? 1 : 0,
1412
            };
1412
            };
1413
1413
1414
            $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
1414
            $issue = Koha::Checkouts->find( { itemnumber => $item_object->itemnumber } );
1415
            if ($issue) {
1415
            if ($issue) {
1416
                $issue->set($issue_attributes)->store;
1416
                $issue->set($issue_attributes)->store;
1417
            }
1417
            }
1418
            else {
1418
            else {
1419
                $issue = Koha::Checkout->new(
1419
                $issue = Koha::Checkout->new(
1420
                    {
1420
                    {
1421
                        itemnumber => $item->itemnumber,
1421
                        itemnumber => $item_object->itemnumber,
1422
                        %$issue_attributes,
1422
                        %$issue_attributes,
1423
                    }
1423
                    }
1424
                )->store;
1424
                )->store;
Lines 1426-1471 sub AddIssue { Link Here
1426
1426
1427
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1427
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1428
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1428
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1429
                CartToShelf( $item->itemnumber );
1429
                CartToShelf( $item_object->itemnumber );
1430
            }
1430
            }
1431
1431
1432
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1432
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1433
                UpdateTotalIssues( $item->biblionumber, 1 );
1433
                UpdateTotalIssues( $item_object->biblionumber, 1 );
1434
            }
1434
            }
1435
1435
1436
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1436
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1437
            if ( $item->itemlost ) {
1437
            if ( $item_object->itemlost ) {
1438
                if (
1438
                if (
1439
                    Koha::RefundLostItemFeeRules->should_refund(
1439
                    Koha::RefundLostItemFeeRules->should_refund(
1440
                        {
1440
                        {
1441
                            current_branch      => C4::Context->userenv->{branch},
1441
                            current_branch      => C4::Context->userenv->{branch},
1442
                            item_home_branch    => $item->homebranch,
1442
                            item_home_branch    => $item_object->homebranch,
1443
                            item_holding_branch => $item->holdingbranch,
1443
                            item_holding_branch => $item_object->holdingbranch,
1444
                        }
1444
                        }
1445
                    )
1445
                    )
1446
                  )
1446
                  )
1447
                {
1447
                {
1448
                    _FixAccountForLostAndReturned( $item->itemnumber, undef,
1448
                    _FixAccountForLostAndReturned( $item_object->itemnumber, undef,
1449
                        $item->barcode );
1449
                        $item_object->barcode );
1450
                }
1450
                }
1451
            }
1451
            }
1452
1452
1453
            ModItem(
1453
            ModItem(
1454
                {
1454
                {
1455
                    issues        => $item->issues + 1,
1455
                    issues        => $item_object->issues + 1,
1456
                    holdingbranch => C4::Context->userenv->{'branch'},
1456
                    holdingbranch => C4::Context->userenv->{'branch'},
1457
                    itemlost      => 0,
1457
                    itemlost      => 0,
1458
                    onloan        => $datedue->ymd(),
1458
                    onloan        => $datedue->ymd(),
1459
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1459
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1460
                },
1460
                },
1461
                $item->biblionumber,
1461
                $item_object->biblionumber,
1462
                $item->itemnumber,
1462
                $item_object->itemnumber,
1463
                { log_action => 0 }
1463
                { log_action => 0 }
1464
            );
1464
            );
1465
            ModDateLastSeen( $item->itemnumber );
1465
            ModDateLastSeen( $item_object->itemnumber );
1466
1466
1467
            # If it costs to borrow this book, charge it to the patron's account.
1467
            # If it costs to borrow this book, charge it to the patron's account.
1468
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->itemnumber, $borrower->{'borrowernumber'} );
1468
            my ( $charge, $itemtype ) = GetIssuingCharges( $item_object->itemnumber, $borrower->{'borrowernumber'} );
1469
            if ( $charge > 0 ) {
1469
            if ( $charge > 0 ) {
1470
                my $description = "Rental";
1470
                my $description = "Rental";
1471
                AddIssuingCharge( $issue, $charge, $description );
1471
                AddIssuingCharge( $issue, $charge, $description );
Lines 1477-1483 sub AddIssue { Link Here
1477
                if ( $accumulate_charge > 0 ) {
1477
                if ( $accumulate_charge > 0 ) {
1478
                    AddIssuingCharge( $issue, $accumulate_charge, 'Daily rental' ) if $accumulate_charge > 0;
1478
                    AddIssuingCharge( $issue, $accumulate_charge, 'Daily rental' ) if $accumulate_charge > 0;
1479
                    $charge += $accumulate_charge;
1479
                    $charge += $accumulate_charge;
1480
                    $item->{charge} = $charge;
1480
                    $item_unblessed->{charge} = $charge;
1481
                }
1481
                }
1482
            }
1482
            }
1483
1483
Lines 1488-1498 sub AddIssue { Link Here
1488
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1488
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1489
                    amount         => $charge,
1489
                    amount         => $charge,
1490
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1490
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1491
                    itemnumber     => $item->itemnumber,
1491
                    itemnumber     => $item_object->itemnumber,
1492
                    itemtype       => $item->effective_itemtype,
1492
                    itemtype       => $item_object->effective_itemtype,
1493
                    location       => $item->location,
1493
                    location       => $item_object->location,
1494
                    borrowernumber => $borrower->{'borrowernumber'},
1494
                    borrowernumber => $borrower->{'borrowernumber'},
1495
                    ccode          => $item->ccode,
1495
                    ccode          => $item_object->ccode,
1496
                }
1496
                }
1497
            );
1497
            );
1498
1498
Lines 1501-1514 sub AddIssue { Link Here
1501
            my %conditions        = (
1501
            my %conditions        = (
1502
                branchcode   => $branch,
1502
                branchcode   => $branch,
1503
                categorycode => $borrower->{categorycode},
1503
                categorycode => $borrower->{categorycode},
1504
                item_type    => $item->effective_itemtype,
1504
                item_type    => $item_object->effective_itemtype,
1505
                notification => 'CHECKOUT',
1505
                notification => 'CHECKOUT',
1506
            );
1506
            );
1507
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
1507
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
1508
                SendCirculationAlert(
1508
                SendCirculationAlert(
1509
                    {
1509
                    {
1510
                        type     => 'CHECKOUT',
1510
                        type     => 'CHECKOUT',
1511
                        item     => $item->unblessed,
1511
                        item     => $item_object->unblessed,
1512
                        borrower => $borrower,
1512
                        borrower => $borrower,
1513
                        branch   => $branch,
1513
                        branch   => $branch,
1514
                    }
1514
                    }
Lines 1517-1523 sub AddIssue { Link Here
1517
            logaction(
1517
            logaction(
1518
                "CIRCULATION", "ISSUE",
1518
                "CIRCULATION", "ISSUE",
1519
                $borrower->{'borrowernumber'},
1519
                $borrower->{'borrowernumber'},
1520
                $item->itemnumber,
1520
                $item_object->itemnumber,
1521
            ) if C4::Context->preference("IssueLog");
1521
            ) if C4::Context->preference("IssueLog");
1522
        }
1522
        }
1523
    }
1523
    }
Lines 2853-2862 sub AddRenewal { Link Here
2853
    my $datedue         = shift;
2853
    my $datedue         = shift;
2854
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2854
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
2855
2855
2856
    my $item   = Koha::Items->find($itemnumber) or return;
2856
    my $item_object   = Koha::Items->find($itemnumber) or return;
2857
    my $biblio = $item->biblio;
2857
    my $biblio = $item_object->biblio;
2858
    my $issue  = $item->checkout;
2858
    my $issue  = $item_object->checkout;
2859
    my $item_unblessed = $item->unblessed;
2859
    my $item_unblessed = $item_object->unblessed;
2860
2860
2861
    my $dbh = C4::Context->dbh;
2861
    my $dbh = C4::Context->dbh;
2862
2862
Lines 2872-2878 sub AddRenewal { Link Here
2872
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
2872
    my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
2873
    my $patron_unblessed = $patron->unblessed;
2873
    my $patron_unblessed = $patron->unblessed;
2874
2874
2875
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item, $patron_unblessed) );
2875
    my $circ_library = Koha::Libraries->find( _GetCircControlBranch($item_unblessed, $patron_unblessed) );
2876
2876
2877
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2877
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2878
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2878
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
Lines 2882-2894 sub AddRenewal { Link Here
2882
    # If the due date wasn't specified, calculate it by adding the
2882
    # If the due date wasn't specified, calculate it by adding the
2883
    # book's loan length to today's date or the current due date
2883
    # book's loan length to today's date or the current due date
2884
    # based on the value of the RenewalPeriodBase syspref.
2884
    # based on the value of the RenewalPeriodBase syspref.
2885
    my $itemtype = $item_object->effective_itemtype;
2885
    unless ($datedue) {
2886
    unless ($datedue) {
2886
2887
2887
        my $itemtype = $item->effective_itemtype;
2888
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2888
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2889
                                        dt_from_string( $issue->date_due, 'sql' ) :
2889
                                        dt_from_string( $issue->date_due, 'sql' ) :
2890
                                        DateTime->now( time_zone => C4::Context->tz());
2890
                                        DateTime->now( time_zone => C4::Context->tz());
2891
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item_unblessed, $patron_unblessed), $patron_unblessed, 'is a renewal');
2891
        $datedue =  CalcDateDue($datedue, $itemtype, $circ_library, $patron_unblessed, 'is a renewal');
2892
    }
2892
    }
2893
2893
2894
    my $fees = Koha::Charges::Fees->new(
2894
    my $fees = Koha::Charges::Fees->new(
Lines 2912-2933 sub AddRenewal { Link Here
2912
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2912
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2913
2913
2914
    # Update the renewal count on the item, and tell zebra to reindex
2914
    # Update the renewal count on the item, and tell zebra to reindex
2915
    $renews = $item->renewals + 1;
2915
    $renews = $item_object->renewals + 1;
2916
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } );
2916
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item_object->biblionumber, $itemnumber, { log_action => 0 } );
2917
2917
2918
    # Charge a new rental fee, if applicable
2918
    # Charge a new rental fee, if applicable
2919
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2919
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2920
    if ( $charge > 0 ) {
2920
    if ( $charge > 0 ) {
2921
        my $description = "Renewal of Rental Item " . $biblio->title . " " .$item->barcode;
2921
        my $description = "Renewal of Rental Item " . $biblio->title . " " .$item_object->barcode;
2922
        AddIssuingCharge($issue, $charge, $description);
2922
        AddIssuingCharge($issue, $charge, $description);
2923
    }
2923
    }
2924
2924
2925
    # Charge a new accumulate rental fee, if applicable
2925
    # Charge a new accumulate rental fee, if applicable
2926
    my $itemtype = Koha::ItemTypes->find( $item_object->effective_itemtype );
2927
    if ( $itemtype ) {
2926
    if ( $itemtype ) {
2928
        my $accumulate_charge = $fees->accumulate_rentalcharge();
2927
        my $accumulate_charge = $fees->accumulate_rentalcharge();
2929
        if ( $accumulate_charge > 0 ) {
2928
        if ( $accumulate_charge > 0 ) {
2930
            my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item->{'barcode'}";
2929
            my $type_desc = "Renewal of Daily Rental Item " . $biblio->title . " $item_unblessed->{'barcode'}";
2931
            AddIssuingCharge( $issue, $accumulate_charge, $type_desc )
2930
            AddIssuingCharge( $issue, $accumulate_charge, $type_desc )
2932
        }
2931
        }
2933
        $charge += $accumulate_charge;
2932
        $charge += $accumulate_charge;
Lines 2939-2945 sub AddRenewal { Link Here
2939
        my %conditions        = (
2938
        my %conditions        = (
2940
            branchcode   => $branch,
2939
            branchcode   => $branch,
2941
            categorycode => $patron->categorycode,
2940
            categorycode => $patron->categorycode,
2942
            item_type    => $item->effective_itemtype,
2941
            item_type    => $itemtype,
2943
            notification => 'CHECKOUT',
2942
            notification => 'CHECKOUT',
2944
        );
2943
        );
2945
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2944
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
Lines 2974-2983 sub AddRenewal { Link Here
2974
            type           => 'renew',
2973
            type           => 'renew',
2975
            amount         => $charge,
2974
            amount         => $charge,
2976
            itemnumber     => $itemnumber,
2975
            itemnumber     => $itemnumber,
2977
            itemtype       => $item->effective_itemtype,
2976
            itemtype       => $itemtype,
2978
            location       => $item->location,
2977
            location       => $item_object->location,
2979
            borrowernumber => $borrowernumber,
2978
            borrowernumber => $borrowernumber,
2980
            ccode          => $item->ccode,
2979
            ccode          => $item_object->ccode,
2981
        }
2980
        }
2982
    );
2981
    );
2983
2982
(-)a/t/db_dependent/Circulation/Returns.t (-2 / +3 lines)
Lines 41-47 use MARC::Field; Link Here
41
my $branch;
41
my $branch;
42
my $context = Test::MockModule->new('C4::Context');
42
my $context = Test::MockModule->new('C4::Context');
43
$context->mock( 'userenv', sub {
43
$context->mock( 'userenv', sub {
44
    return { branch => $branch }
44
    return { branch => $branch, number => 1234, firstname => "Adam", surname => "Smaith" }
45
});
45
});
46
46
47
my $schema = Koha::Database->schema;
47
my $schema = Koha::Database->schema;
Lines 177-182 subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub { Link Here
177
                 [qr/^item-level_itypes set but no itemtype set for item/,
177
                 [qr/^item-level_itypes set but no itemtype set for item/,
178
                 qr/^item-level_itypes set but no itemtype set for item/,
178
                 qr/^item-level_itypes set but no itemtype set for item/,
179
                 qr/^item-level_itypes set but no itemtype set for item/,
179
                 qr/^item-level_itypes set but no itemtype set for item/,
180
                 qr/^item-level_itypes set but no itemtype set for item/,
181
                 qr/^item-level_itypes set but no itemtype set for item/,
180
                 qr/^item-level_itypes set but no itemtype set for item/],
182
                 qr/^item-level_itypes set but no itemtype set for item/],
181
                 'Item without itemtype set raises warning on AddIssue';
183
                 'Item without itemtype set raises warning on AddIssue';
182
    warning_like { AddReturn( $item_without_itemtype->{ barcode }, $branch ) }
184
    warning_like { AddReturn( $item_without_itemtype->{ barcode }, $branch ) }
183
- 

Return to bug 20912