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

(-)a/C4/Biblio.pm (-6 / +9 lines)
Lines 2196-2205 sub PrepHostMarcField { Link Here
2196
    my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
2196
    my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
2197
    $marcflavour ||="MARC21";
2197
    $marcflavour ||="MARC21";
2198
    
2198
    
2199
    require C4::Items;
2200
    my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
2199
    my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
2201
	my $item = C4::Items::GetItem($hostitemnumber);
2200
    my $item = Koha::Items->find($hostitemnumber);
2202
	
2201
2203
	my $hostmarcfield;
2202
	my $hostmarcfield;
2204
    if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
2203
    if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
2205
	
2204
	
Lines 2222-2228 sub PrepHostMarcField { Link Here
2222
2221
2223
    	#other fields
2222
    	#other fields
2224
        my $ed = $hostrecord->subfield('250','a');
2223
        my $ed = $hostrecord->subfield('250','a');
2225
        my $barcode = $item->{'barcode'};
2224
        my $barcode = $item->barcode;
2226
        my $title = $hostrecord->subfield('245','a');
2225
        my $title = $hostrecord->subfield('245','a');
2227
2226
2228
        # record control number, 001 with 003 and prefix
2227
        # record control number, 001 with 003 and prefix
Lines 2825-2832 sub EmbedItemsInMarcBiblio { Link Here
2825
    require C4::Items;
2824
    require C4::Items;
2826
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2825
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2827
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2826
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2828
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2827
        my $item;
2829
        push @items, { itemnumber => $itemnumber, item => $i };
2828
        if ( $opachiddenitems ) {
2829
            $item = Koha::Items->find($itemnumber);
2830
            $item = $item ? $item->unblessed : undef;
2831
        }
2832
        push @items, { itemnumber => $itemnumber, item => $item };
2830
    }
2833
    }
2831
    my @items2pass = map { $_->{item} } @items;
2834
    my @items2pass = map { $_->{item} } @items;
2832
    my @hiddenitems =
2835
    my @hiddenitems =
(-)a/C4/Circulation.pm (-145 / +150 lines)
Lines 670-686 sub CanBookBeIssued { Link Here
670
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
670
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
671
    my $override_high_holds = $params->{override_high_holds} || 0;
671
    my $override_high_holds = $params->{override_high_holds} || 0;
672
672
673
    my $item = GetItem(undef, $barcode );
673
    my $item = Koha::Items->find({barcode => $barcode });
674
    # MANDATORY CHECKS - unless item exists, nothing else matters
674
    # MANDATORY CHECKS - unless item exists, nothing else matters
675
    unless ( $item ) {
675
    unless ( $item ) {
676
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
676
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
677
    }
677
    }
678
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
678
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
679
679
680
    my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
680
    my $item_unblessed = $item->unblessed; # Transition...
681
    my $biblio = Koha::Biblios->find( $item->{biblionumber} );
681
    my $issue = $item->checkout;
682
    my $biblio = $item->biblio;
682
    my $biblioitem = $biblio->biblioitem;
683
    my $biblioitem = $biblio->biblioitem;
683
    my $effective_itemtype = $item->{itype}; # GetItem deals with that
684
    my $effective_itemtype = $item->effective_itemtype;
684
    my $dbh             = C4::Context->dbh;
685
    my $dbh             = C4::Context->dbh;
685
    my $patron_unblessed = $patron->unblessed;
686
    my $patron_unblessed = $patron->unblessed;
686
687
Lines 694-700 sub CanBookBeIssued { Link Here
694
    unless ( $duedate ) {
695
    unless ( $duedate ) {
695
        my $issuedate = $now->clone();
696
        my $issuedate = $now->clone();
696
697
697
        my $branch = _GetCircControlBranch($item, $patron_unblessed);
698
        my $branch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
698
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
699
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
699
700
700
        # Offline circ calls AddIssue directly, doesn't run through here
701
        # Offline circ calls AddIssue directly, doesn't run through here
Lines 713-729 sub CanBookBeIssued { Link Here
713
    #
714
    #
714
    # BORROWER STATUS
715
    # BORROWER STATUS
715
    #
716
    #
716
    if ( $patron->category->category_type eq 'X' && (  $item->{barcode}  )) {
717
    if ( $patron->category->category_type eq 'X' && (  $item->barcode  )) {
717
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
718
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
718
        &UpdateStats({
719
        &UpdateStats({
719
                     branch => C4::Context->userenv->{'branch'},
720
                     branch => C4::Context->userenv->{'branch'},
720
                     type => 'localuse',
721
                     type => 'localuse',
721
                     itemnumber => $item->{'itemnumber'},
722
                     itemnumber => $item->itemnumber,
722
                     itemtype => $effective_itemtype,
723
                     itemtype => $effective_itemtype,
723
                     borrowernumber => $patron->borrowernumber,
724
                     borrowernumber => $patron->borrowernumber,
724
                     ccode => $item->{'ccode'}}
725
                     ccode => $item->ccode}
725
                    );
726
                    );
726
        ModDateLastSeen( $item->{'itemnumber'} );
727
        ModDateLastSeen( $item->itemnumber ); # FIXME Move to Koha::Item
727
        return( { STATS => 1 }, {});
728
        return( { STATS => 1 }, {});
728
    }
729
    }
729
730
Lines 834-840 sub CanBookBeIssued { Link Here
834
        } else {
835
        } else {
835
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
836
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
836
                $patron->borrowernumber,
837
                $patron->borrowernumber,
837
                $item->{'itemnumber'},
838
                $item->itemnumber,
838
            );
839
            );
839
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
840
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
840
                if ( $renewerror eq 'onsite_checkout' ) {
841
                if ( $renewerror eq 'onsite_checkout' ) {
Lines 855-861 sub CanBookBeIssued { Link Here
855
856
856
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
857
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
857
858
858
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
859
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
859
860
860
        unless ( $can_be_returned ) {
861
        unless ( $can_be_returned ) {
861
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
862
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
Lines 876-882 sub CanBookBeIssued { Link Here
876
      and $issue
877
      and $issue
877
      and $issue->onsite_checkout
878
      and $issue->onsite_checkout
878
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
879
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
879
    my $toomany = TooMany( $patron_unblessed, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
880
    my $toomany = TooMany( $patron_unblessed, $item->biblionumber, $item_unblessed, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
880
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
881
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
881
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
882
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
882
        if ( $toomany->{max_allowed} == 0 ) {
883
        if ( $toomany->{max_allowed} == 0 ) {
Lines 899-917 sub CanBookBeIssued { Link Here
899
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
900
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
900
    my $wants_check = $patron->wants_check_for_previous_checkout;
901
    my $wants_check = $patron->wants_check_for_previous_checkout;
901
    $needsconfirmation{PREVISSUE} = 1
902
    $needsconfirmation{PREVISSUE} = 1
902
        if ($wants_check and $patron->do_check_for_previous_checkout($item));
903
        if ($wants_check and $patron->do_check_for_previous_checkout($item_unblessed));
903
904
904
    #
905
    #
905
    # ITEM CHECKING
906
    # ITEM CHECKING
906
    #
907
    #
907
    if ( $item->{'notforloan'} )
908
    if ( $item->notforloan )
908
    {
909
    {
909
        if(!C4::Context->preference("AllowNotForLoanOverride")){
910
        if(!C4::Context->preference("AllowNotForLoanOverride")){
910
            $issuingimpossible{NOT_FOR_LOAN} = 1;
911
            $issuingimpossible{NOT_FOR_LOAN} = 1;
911
            $issuingimpossible{item_notforloan} = $item->{'notforloan'};
912
            $issuingimpossible{item_notforloan} = $item->notforloan;
912
        }else{
913
        }else{
913
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
914
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
914
            $needsconfirmation{item_notforloan} = $item->{'notforloan'};
915
            $needsconfirmation{item_notforloan} = $item->notforloan;
915
        }
916
        }
916
    }
917
    }
917
    else {
918
    else {
Lines 944-960 sub CanBookBeIssued { Link Here
944
            }
945
            }
945
        }
946
        }
946
    }
947
    }
947
    if ( $item->{'withdrawn'} && $item->{'withdrawn'} > 0 )
948
    if ( $item->withdrawn && $item->withdrawn > 0 )
948
    {
949
    {
949
        $issuingimpossible{WTHDRAWN} = 1;
950
        $issuingimpossible{WTHDRAWN} = 1;
950
    }
951
    }
951
    if (   $item->{'restricted'}
952
    if (   $item->restricted
952
        && $item->{'restricted'} == 1 )
953
        && $item->restricted == 1 )
953
    {
954
    {
954
        $issuingimpossible{RESTRICTED} = 1;
955
        $issuingimpossible{RESTRICTED} = 1;
955
    }
956
    }
956
    if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
957
    if ( $item->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
957
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} });
958
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->itemlost });
958
        my $code = $av->count ? $av->next->lib : '';
959
        my $code = $av->count ? $av->next->lib : '';
959
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
960
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
960
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
961
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
Lines 962-970 sub CanBookBeIssued { Link Here
962
    if ( C4::Context->preference("IndependentBranches") ) {
963
    if ( C4::Context->preference("IndependentBranches") ) {
963
        my $userenv = C4::Context->userenv;
964
        my $userenv = C4::Context->userenv;
964
        unless ( C4::Context->IsSuperLibrarian() ) {
965
        unless ( C4::Context->IsSuperLibrarian() ) {
965
            if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
966
            my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch");
967
            if ( $item->$HomeOrHoldingBranch ne $userenv->{branch} ){
966
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
968
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
967
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
969
                $issuingimpossible{'itemhomebranch'} = $item->$HomeOrHoldingBranch;
968
            }
970
            }
969
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
971
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
970
              if ( $patron->branchcode ne $userenv->{branch} );
972
              if ( $patron->branchcode ne $userenv->{branch} );
Lines 976-982 sub CanBookBeIssued { Link Here
976
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
978
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
977
979
978
    if ( $rentalConfirmation ){
980
    if ( $rentalConfirmation ){
979
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
981
        my ($rentalCharge) = GetIssuingCharges( $item->itemnumber, $patron->borrowernumber );
980
        if ( $rentalCharge > 0 ){
982
        if ( $rentalCharge > 0 ){
981
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
983
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
982
        }
984
        }
Lines 984-990 sub CanBookBeIssued { Link Here
984
986
985
    unless ( $ignore_reserves ) {
987
    unless ( $ignore_reserves ) {
986
        # See if the item is on reserve.
988
        # See if the item is on reserve.
987
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
989
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->itemnumber );
988
        if ($restype) {
990
        if ($restype) {
989
            my $resbor = $res->{'borrowernumber'};
991
            my $resbor = $res->{'borrowernumber'};
990
            if ( $resbor ne $patron->borrowernumber ) {
992
            if ( $resbor ne $patron->borrowernumber ) {
Lines 1029-1035 sub CanBookBeIssued { Link Here
1029
1031
1030
    ## check for high holds decreasing loan period
1032
    ## check for high holds decreasing loan period
1031
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1033
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1032
        my $check = checkHighHolds( $item, $patron_unblessed );
1034
        my $check = checkHighHolds( $item_unblessed, $patron_unblessed );
1033
1035
1034
        if ( $check->{exceeded} ) {
1036
        if ( $check->{exceeded} ) {
1035
            if ($override_high_holds) {
1037
            if ($override_high_holds) {
Lines 1058-1064 sub CanBookBeIssued { Link Here
1058
    ) {
1060
    ) {
1059
        # Check if borrower has already issued an item from the same biblio
1061
        # Check if borrower has already issued an item from the same biblio
1060
        # Only if it's not a subscription
1062
        # Only if it's not a subscription
1061
        my $biblionumber = $item->{biblionumber};
1063
        my $biblionumber = $item->biblionumber;
1062
        require C4::Serials;
1064
        require C4::Serials;
1063
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1065
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1064
        unless ($is_a_subscription) {
1066
        unless ($is_a_subscription) {
Lines 1091-1097 Check whether the item can be returned to the provided branch Link Here
1091
1093
1092
=over 4
1094
=over 4
1093
1095
1094
=item C<$item> is a hash of item information as returned from GetItem
1096
=item C<$item> is a hash of item information as returned Koha::Items->find->unblessed (Temporary, should be a Koha::Item instead)
1095
1097
1096
=item C<$branch> is the branchcode where the return is taking place
1098
=item C<$branch> is the branchcode where the return is taking place
1097
1099
Lines 1289-1309 sub AddIssue { Link Here
1289
    # Stop here if the patron or barcode doesn't exist
1291
    # Stop here if the patron or barcode doesn't exist
1290
    if ( $borrower && $barcode && $barcodecheck ) {
1292
    if ( $borrower && $barcode && $barcodecheck ) {
1291
        # find which item we issue
1293
        # find which item we issue
1292
        my $item = GetItem( '', $barcode )
1294
        my $item = Koha::Items->find({ barcode => $barcode })
1293
          or return;    # if we don't get an Item, abort.
1295
          or return;    # if we don't get an Item, abort.
1294
        my $item_object = Koha::Items->find( { barcode => $barcode } );
1296
        my $item_unblessed = $item->unblessed;
1295
1297
1296
        my $branch = _GetCircControlBranch( $item, $borrower );
1298
        my $branch = _GetCircControlBranch( $item_unblessed, $borrower );
1297
1299
1298
        # get actual issuing if there is one
1300
        # get actual issuing if there is one
1299
        my $actualissue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
1301
        my $actualissue = $item->checkout;
1300
1302
1301
        # check if we just renew the issue.
1303
        # check if we just renew the issue.
1302
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1304
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1303
                and not $switch_onsite_checkout ) {
1305
                and not $switch_onsite_checkout ) {
1304
            $datedue = AddRenewal(
1306
            $datedue = AddRenewal(
1305
                $borrower->{'borrowernumber'},
1307
                $borrower->{'borrowernumber'},
1306
                $item->{'itemnumber'},
1308
                $item->itemnumber,
1307
                $branch,
1309
                $branch,
1308
                $datedue,
1310
                $datedue,
1309
                $issuedate,    # here interpreted as the renewal date
1311
                $issuedate,    # here interpreted as the renewal date
Lines 1314-1328 sub AddIssue { Link Here
1314
            if ( $actualissue and not $switch_onsite_checkout ) {
1316
            if ( $actualissue and not $switch_onsite_checkout ) {
1315
                # This book is currently on loan, but not to the person
1317
                # This book is currently on loan, but not to the person
1316
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1318
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1317
                my ( $allowed, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
1319
                my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
1318
                return unless $allowed;
1320
                return unless $allowed;
1319
                AddReturn( $item->{'barcode'}, C4::Context->userenv->{'branch'} );
1321
                AddReturn( $item->barcode, C4::Context->userenv->{'branch'} );
1320
            }
1322
            }
1321
1323
1322
            C4::Reserves::MoveReserve( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $cancelreserve );
1324
            C4::Reserves::MoveReserve( $item->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1323
1325
1324
            # Starting process for transfer job (checking transfert and validate it if we have one)
1326
            # Starting process for transfer job (checking transfert and validate it if we have one)
1325
            my ($datesent) = GetTransfers( $item->{'itemnumber'} );
1327
            my ($datesent) = GetTransfers( $item->itemnumber );
1326
            if ($datesent) {
1328
            if ($datesent) {
1327
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1329
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1328
                my $sth = $dbh->prepare(
1330
                my $sth = $dbh->prepare(
Lines 1333-1346 sub AddIssue { Link Here
1333
                    WHERE itemnumber= ? AND datearrived IS NULL"
1335
                    WHERE itemnumber= ? AND datearrived IS NULL"
1334
                );
1336
                );
1335
                $sth->execute( C4::Context->userenv->{'branch'},
1337
                $sth->execute( C4::Context->userenv->{'branch'},
1336
                    $item->{'itemnumber'} );
1338
                    $item->itemnumber );
1337
            }
1339
            }
1338
1340
1339
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1341
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1340
            unless ($auto_renew) {
1342
            unless ($auto_renew) {
1341
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1343
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1342
                    {   categorycode => $borrower->{categorycode},
1344
                    {   categorycode => $borrower->{categorycode},
1343
                        itemtype     => $item->{itype},
1345
                        itemtype     => $item->effective_itemtype,
1344
                        branchcode   => $branch
1346
                        branchcode   => $branch
1345
                    }
1347
                    }
1346
                );
1348
                );
Lines 1350-1356 sub AddIssue { Link Here
1350
1352
1351
            # Record in the database the fact that the book was issued.
1353
            # Record in the database the fact that the book was issued.
1352
            unless ($datedue) {
1354
            unless ($datedue) {
1353
                my $itype = $item_object->effective_itemtype;
1355
                my $itype = $item->effective_itemtype;
1354
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1356
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1355
1357
1356
            }
1358
            }
Lines 1372-1378 sub AddIssue { Link Here
1372
            else {
1374
            else {
1373
                $issue = Koha::Checkout->new(
1375
                $issue = Koha::Checkout->new(
1374
                    {
1376
                    {
1375
                        itemnumber => $item->{itemnumber},
1377
                        itemnumber => $item->itemnumber,
1376
                        %$issue_attributes,
1378
                        %$issue_attributes,
1377
                    }
1379
                    }
1378
                )->store;
1380
                )->store;
Lines 1380-1428 sub AddIssue { Link Here
1380
1382
1381
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1383
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1382
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1384
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1383
                CartToShelf( $item->{'itemnumber'} );
1385
                CartToShelf( $item->itemnumber );
1384
            }
1386
            }
1385
            $item->{'issues'}++;
1387
1386
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1388
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1387
                UpdateTotalIssues( $item->{'biblionumber'}, 1 );
1389
                UpdateTotalIssues( $item->biblionumber, 1 );
1388
            }
1390
            }
1389
1391
1390
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1392
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1391
            if ( $item->{'itemlost'} ) {
1393
            if ( $item->itemlost ) {
1392
                if (
1394
                if (
1393
                    Koha::RefundLostItemFeeRules->should_refund(
1395
                    Koha::RefundLostItemFeeRules->should_refund(
1394
                        {
1396
                        {
1395
                            current_branch      => C4::Context->userenv->{branch},
1397
                            current_branch      => C4::Context->userenv->{branch},
1396
                            item_home_branch    => $item->{homebranch},
1398
                            item_home_branch    => $item->homebranch,
1397
                            item_holding_branch => $item->{holdingbranch}
1399
                            item_holding_branch => $item->holdingbranch,
1398
                        }
1400
                        }
1399
                    )
1401
                    )
1400
                  )
1402
                  )
1401
                {
1403
                {
1402
                    _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef,
1404
                    _FixAccountForLostAndReturned( $item->itemnumber, undef,
1403
                        $item->{'barcode'} );
1405
                        $item->barcode );
1404
                }
1406
                }
1405
            }
1407
            }
1406
1408
1407
            ModItem(
1409
            ModItem(
1408
                {
1410
                {
1409
                    issues        => $item->{'issues'},
1411
                    issues        => $item->issues + 1,
1410
                    holdingbranch => C4::Context->userenv->{'branch'},
1412
                    holdingbranch => C4::Context->userenv->{'branch'},
1411
                    itemlost      => 0,
1413
                    itemlost      => 0,
1412
                    onloan        => $datedue->ymd(),
1414
                    onloan        => $datedue->ymd(),
1413
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1415
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1414
                },
1416
                },
1415
                $item->{'biblionumber'},
1417
                $item->biblionumber,
1416
                $item->{'itemnumber'},
1418
                $item->itemnumber,
1417
                { log_action => 0 }
1419
                { log_action => 0 }
1418
            );
1420
            );
1419
            ModDateLastSeen( $item->{'itemnumber'} );
1421
            ModDateLastSeen( $item->itemnumber );
1420
1422
1421
           # If it costs to borrow this book, charge it to the patron's account.
1423
           # If it costs to borrow this book, charge it to the patron's account.
1422
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1424
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->itemnumber, $borrower->{'borrowernumber'} );
1423
            if ( $charge > 0 ) {
1425
            if ( $charge > 0 ) {
1424
                AddIssuingCharge( $issue, $charge );
1426
                AddIssuingCharge( $issue, $charge );
1425
                $item->{'charge'} = $charge;
1426
            }
1427
            }
1427
1428
1428
            # Record the fact that this book was issued.
1429
            # Record the fact that this book was issued.
Lines 1432-1442 sub AddIssue { Link Here
1432
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1433
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1433
                    amount         => $charge,
1434
                    amount         => $charge,
1434
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1435
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1435
                    itemnumber     => $item->{'itemnumber'},
1436
                    itemnumber     => $item->itemnumber,
1436
                    itemtype       => $item->{'itype'},
1437
                    itemtype       => $item->effective_itemtype,
1437
                    location       => $item->{location},
1438
                    location       => $item->location,
1438
                    borrowernumber => $borrower->{'borrowernumber'},
1439
                    borrowernumber => $borrower->{'borrowernumber'},
1439
                    ccode          => $item->{'ccode'}
1440
                    ccode          => $item->ccode,
1440
                }
1441
                }
1441
            );
1442
            );
1442
1443
Lines 1445-1451 sub AddIssue { Link Here
1445
            my %conditions        = (
1446
            my %conditions        = (
1446
                branchcode   => $branch,
1447
                branchcode   => $branch,
1447
                categorycode => $borrower->{categorycode},
1448
                categorycode => $borrower->{categorycode},
1448
                item_type    => $item->{itype},
1449
                item_type    => $item->effective_itemtype,
1449
                notification => 'CHECKOUT',
1450
                notification => 'CHECKOUT',
1450
            );
1451
            );
1451
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
1452
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
Lines 1461-1467 sub AddIssue { Link Here
1461
            logaction(
1462
            logaction(
1462
                "CIRCULATION", "ISSUE",
1463
                "CIRCULATION", "ISSUE",
1463
                $borrower->{'borrowernumber'},
1464
                $borrower->{'borrowernumber'},
1464
                $item->{'itemnumber'}
1465
                $item->itemnumber,
1465
            ) if C4::Context->preference("IssueLog");
1466
            ) if C4::Context->preference("IssueLog");
1466
        }
1467
        }
1467
    }
1468
    }
Lines 1814-1826 sub AddReturn { Link Here
1814
    my $stat_type = 'return';
1815
    my $stat_type = 'return';
1815
1816
1816
    # get information on item
1817
    # get information on item
1817
    my $item = GetItem( undef, $barcode );
1818
    my $item = Koha::Items->find({ barcode => $barcode });
1818
    unless ($item) {
1819
    unless ($item) {
1819
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1820
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1820
    }
1821
    }
1821
1822
1822
    my $itemnumber = $item->{ itemnumber };
1823
    my $itemnumber = $item->itemnumber;
1823
    my $itemtype = $item->{itype}; # GetItem called effective_itemtype
1824
    my $itemtype = $item->effective_itemtype;
1824
1825
1825
    my $issue  = Koha::Checkouts->find( { itemnumber => $itemnumber } );
1826
    my $issue  = Koha::Checkouts->find( { itemnumber => $itemnumber } );
1826
    if ( $issue ) {
1827
    if ( $issue ) {
Lines 1840-1860 sub AddReturn { Link Here
1840
        }
1841
        }
1841
    }
1842
    }
1842
1843
1843
    if ( $item->{'location'} eq 'PROC' ) {
1844
    my $item_unblessed = $item->unblessed;
1845
    if ( $item->location eq 'PROC' ) {
1844
        if ( C4::Context->preference("InProcessingToShelvingCart") ) {
1846
        if ( C4::Context->preference("InProcessingToShelvingCart") ) {
1845
            $item->{'location'} = 'CART';
1847
            $item_unblessed->{location} = 'CART';
1846
        }
1848
        }
1847
        else {
1849
        else {
1848
            $item->{location} = $item->{permanent_location};
1850
            $item_unblessed->{location} = $item->permanent_location;
1849
        }
1851
        }
1850
1852
1851
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, { log_action => 0 } );
1853
        ModItem( $item_unblessed, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
1852
    }
1854
    }
1853
1855
1854
        # full item data, but no borrowernumber or checkout info (no issue)
1856
        # full item data, but no borrowernumber or checkout info (no issue)
1855
    my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
1857
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
1856
        # get the proper branch to which to return the item
1858
        # get the proper branch to which to return the item
1857
    my $returnbranch = $item->{$hbr} || $branch ;
1859
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
1858
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1860
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1859
1861
1860
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
1862
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
Lines 1870-1877 sub AddReturn { Link Here
1870
        }
1872
        }
1871
        else {
1873
        else {
1872
            foreach my $key ( keys %$rules ) {
1874
            foreach my $key ( keys %$rules ) {
1873
                if ( $item->{notforloan} eq $key ) {
1875
                if ( $item->notforloan eq $key ) {
1874
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1876
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1875
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
1877
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
1876
                    last;
1878
                    last;
1877
                }
1879
                }
Lines 1880-1886 sub AddReturn { Link Here
1880
    }
1882
    }
1881
1883
1882
    # check if the return is allowed at this branch
1884
    # check if the return is allowed at this branch
1883
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
1885
    my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch);
1884
    unless ($returnallowed){
1886
    unless ($returnallowed){
1885
        $messages->{'Wrongbranch'} = {
1887
        $messages->{'Wrongbranch'} = {
1886
            Wrongbranch => $branch,
1888
            Wrongbranch => $branch,
Lines 1890-1901 sub AddReturn { Link Here
1890
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1892
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1891
    }
1893
    }
1892
1894
1893
    if ( $item->{'withdrawn'} ) { # book has been cancelled
1895
    if ( $item->withdrawn ) { # book has been cancelled
1894
        $messages->{'withdrawn'} = 1;
1896
        $messages->{'withdrawn'} = 1;
1895
        $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems");
1897
        $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems");
1896
    }
1898
    }
1897
1899
1898
    if ( $item->{itemlost} and C4::Context->preference("BlockReturnOfLostItems") ) {
1900
    if ( $item->itemlost and C4::Context->preference("BlockReturnOfLostItems") ) {
1899
        $doreturn = 0;
1901
        $doreturn = 0;
1900
    }
1902
    }
1901
1903
Lines 1915-1931 sub AddReturn { Link Here
1915
        if ($patron) {
1917
        if ($patron) {
1916
            eval {
1918
            eval {
1917
                if ( $dropbox ) {
1919
                if ( $dropbox ) {
1918
                    MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1920
                    MarkIssueReturned( $borrowernumber, $item->itemnumber,
1919
                        $dropboxdate, $patron->privacy );
1921
                        $dropboxdate, $patron->privacy );
1920
                }
1922
                }
1921
                else {
1923
                else {
1922
                    MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1924
                    MarkIssueReturned( $borrowernumber, $item->itemnumber,
1923
                        $return_date, $patron->privacy );
1925
                        $return_date, $patron->privacy );
1924
                }
1926
                }
1925
            };
1927
            };
1926
            unless ( $@ ) {
1928
            unless ( $@ ) {
1927
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1929
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1928
                    _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } );
1930
                    _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } );
1929
                }
1931
                }
1930
            } else {
1932
            } else {
1931
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
1933
                carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue->unblessed );
Lines 1938-1995 sub AddReturn { Link Here
1938
1940
1939
        }
1941
        }
1940
1942
1941
        ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, { log_action => 0 } );
1943
        ModItem( { onloan => undef }, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
1942
    }
1944
    }
1943
1945
1944
    # the holdingbranch is updated if the document is returned to another location.
1946
    # the holdingbranch is updated if the document is returned to another location.
1945
    # this is always done regardless of whether the item was on loan or not
1947
    # this is always done regardless of whether the item was on loan or not
1946
    my $item_holding_branch = $item->{ holdingbranch };
1948
    my $item_holding_branch = $item->holdingbranch;
1947
    if ($item->{'holdingbranch'} ne $branch) {
1949
    if ($item->holdingbranch ne $branch) {
1948
        UpdateHoldingbranch($branch, $item->{'itemnumber'});
1950
        UpdateHoldingbranch($branch, $item->itemnumber);
1949
        $item->{'holdingbranch'} = $branch; # update item data holdingbranch too
1951
        $item_unblessed->{'holdingbranch'} = $branch; # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later
1950
    }
1952
    }
1951
1953
1952
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
1954
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
1953
    ModDateLastSeen( $item->{itemnumber}, $leave_item_lost );
1955
    ModDateLastSeen( $item->itemnumber, $leave_item_lost );
1954
1956
1955
    # check if we have a transfer for this document
1957
    # check if we have a transfer for this document
1956
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->{'itemnumber'} );
1958
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber );
1957
1959
1958
    # if we have a transfer to do, we update the line of transfers with the datearrived
1960
    # if we have a transfer to do, we update the line of transfers with the datearrived
1959
    my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->{'itemnumber'} );
1961
    my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber );
1960
    if ($datesent) {
1962
    if ($datesent) {
1961
        if ( $tobranch eq $branch ) {
1963
        if ( $tobranch eq $branch ) {
1962
            my $sth = C4::Context->dbh->prepare(
1964
            my $sth = C4::Context->dbh->prepare(
1963
                "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
1965
                "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
1964
            );
1966
            );
1965
            $sth->execute( $item->{'itemnumber'} );
1967
            $sth->execute( $item->itemnumber );
1966
            # if we have a reservation with valid transfer, we can set it's status to 'W'
1968
            # if we have a reservation with valid transfer, we can set it's status to 'W'
1967
            ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
1969
            ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
1968
            C4::Reserves::ModReserveStatus($item->{'itemnumber'}, 'W');
1970
            C4::Reserves::ModReserveStatus($item->itemnumber, 'W');
1969
        } else {
1971
        } else {
1970
            $messages->{'WrongTransfer'}     = $tobranch;
1972
            $messages->{'WrongTransfer'}     = $tobranch;
1971
            $messages->{'WrongTransferItem'} = $item->{'itemnumber'};
1973
            $messages->{'WrongTransferItem'} = $item->itemnumber;
1972
        }
1974
        }
1973
        $validTransfert = 1;
1975
        $validTransfert = 1;
1974
    } else {
1976
    } else {
1975
        ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
1977
        ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
1976
    }
1978
    }
1977
1979
1978
    # fix up the accounts.....
1980
    # fix up the accounts.....
1979
    if ( $item->{'itemlost'} ) {
1981
    if ( $item->itemlost ) {
1980
        $messages->{'WasLost'} = 1;
1982
        $messages->{'WasLost'} = 1;
1981
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1983
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1982
            if (
1984
            if (
1983
                Koha::RefundLostItemFeeRules->should_refund(
1985
                Koha::RefundLostItemFeeRules->should_refund(
1984
                    {
1986
                    {
1985
                        current_branch      => C4::Context->userenv->{branch},
1987
                        current_branch      => C4::Context->userenv->{branch},
1986
                        item_home_branch    => $item->{homebranch},
1988
                        item_home_branch    => $item->homebranch,
1987
                        item_holding_branch => $item_holding_branch
1989
                        item_holding_branch => $item_holding_branch
1988
                    }
1990
                    }
1989
                )
1991
                )
1990
              )
1992
              )
1991
            {
1993
            {
1992
                _FixAccountForLostAndReturned( $item->{'itemnumber'},
1994
                _FixAccountForLostAndReturned( $item->itemnumber,
1993
                    $borrowernumber, $barcode );
1995
                    $borrowernumber, $barcode );
1994
                $messages->{'LostItemFeeRefunded'} = 1;
1996
                $messages->{'LostItemFeeRefunded'} = 1;
1995
            }
1997
            }
Lines 1998-2011 sub AddReturn { Link Here
1998
2000
1999
    # fix up the overdues in accounts...
2001
    # fix up the overdues in accounts...
2000
    if ($borrowernumber) {
2002
    if ($borrowernumber) {
2001
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
2003
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->itemnumber, $exemptfine, $dropbox);
2002
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
2004
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->itemnumber...) failed!";  # zero is OK, check defined
2003
2005
2004
        if ( $issue and $issue->is_overdue ) {
2006
        if ( $issue and $issue->is_overdue ) {
2005
        # fix fine days
2007
        # fix fine days
2006
            $today = dt_from_string($return_date) if $return_date;
2008
            $today = dt_from_string($return_date) if $return_date;
2007
            $today = $dropboxdate if $dropbox;
2009
            $today = $dropboxdate if $dropbox;
2008
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today );
2010
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item_unblessed, dt_from_string($issue->date_due), $today );
2009
            if ($reminder){
2011
            if ($reminder){
2010
                $messages->{'PrevDebarred'} = $debardate;
2012
                $messages->{'PrevDebarred'} = $debardate;
2011
            } else {
2013
            } else {
Lines 2030-2036 sub AddReturn { Link Here
2030
    # if we don't have a reserve with the status W, we launch the Checkreserves routine
2032
    # if we don't have a reserve with the status W, we launch the Checkreserves routine
2031
    my ($resfound, $resrec);
2033
    my ($resfound, $resrec);
2032
    my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
2034
    my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
2033
    ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'}, undef, $lookahead ) unless ( $item->{'withdrawn'} );
2035
    ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->itemnumber, undef, $lookahead ) unless ( $item->withdrawn );
2034
    if ($resfound) {
2036
    if ($resfound) {
2035
          $resrec->{'ResFound'} = $resfound;
2037
          $resrec->{'ResFound'} = $resfound;
2036
        $messages->{'ResFound'} = $resrec;
2038
        $messages->{'ResFound'} = $resrec;
Lines 2043-2049 sub AddReturn { Link Here
2043
        itemnumber     => $itemnumber,
2045
        itemnumber     => $itemnumber,
2044
        itemtype       => $itemtype,
2046
        itemtype       => $itemtype,
2045
        borrowernumber => $borrowernumber,
2047
        borrowernumber => $borrowernumber,
2046
        ccode          => $item->{ ccode }
2048
        ccode          => $item->ccode,
2047
    });
2049
    });
2048
2050
2049
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
2051
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
Lines 2052-2070 sub AddReturn { Link Here
2052
        my %conditions = (
2054
        my %conditions = (
2053
            branchcode   => $branch,
2055
            branchcode   => $branch,
2054
            categorycode => $patron->categorycode,
2056
            categorycode => $patron->categorycode,
2055
            item_type    => $item->{itype},
2057
            item_type    => $itemtype,
2056
            notification => 'CHECKIN',
2058
            notification => 'CHECKIN',
2057
        );
2059
        );
2058
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2060
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2059
            SendCirculationAlert({
2061
            SendCirculationAlert({
2060
                type     => 'CHECKIN',
2062
                type     => 'CHECKIN',
2061
                item     => $item,
2063
                item     => $item_unblessed,
2062
                borrower => $patron->unblessed,
2064
                borrower => $patron->unblessed,
2063
                branch   => $branch,
2065
                branch   => $branch,
2064
            });
2066
            });
2065
        }
2067
        }
2066
2068
2067
        logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
2069
        logaction("CIRCULATION", "RETURN", $borrowernumber, $item->itemnumber)
2068
            if C4::Context->preference("ReturnLog");
2070
            if C4::Context->preference("ReturnLog");
2069
        }
2071
        }
2070
2072
Lines 2080-2092 sub AddReturn { Link Here
2080
2082
2081
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
2083
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
2082
    if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
2084
    if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
2085
        my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType");
2083
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
2086
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
2084
            (C4::Context->preference("UseBranchTransferLimits") and
2087
            (C4::Context->preference("UseBranchTransferLimits") and
2085
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->{C4::Context->preference("BranchTransferLimitsType")} )
2088
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2086
           )) {
2089
           )) {
2087
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $returnbranch;
2090
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch;
2088
            $debug and warn "item: " . Dumper($item);
2091
            $debug and warn "item: " . Dumper($item_unblessed);
2089
            ModItemTransfer($item->{'itemnumber'}, $branch, $returnbranch);
2092
            ModItemTransfer($item->itemnumber, $branch, $returnbranch);
2090
            $messages->{'WasTransfered'} = 1;
2093
            $messages->{'WasTransfered'} = 1;
2091
        } else {
2094
        } else {
2092
            $messages->{'NeedsTransfer'} = $returnbranch;
2095
            $messages->{'NeedsTransfer'} = $returnbranch;
Lines 2612-2618 sub CanBookBeRenewed { Link Here
2612
    my $dbh    = C4::Context->dbh;
2615
    my $dbh    = C4::Context->dbh;
2613
    my $renews = 1;
2616
    my $renews = 1;
2614
2617
2615
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2618
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2616
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2619
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2617
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2620
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2618
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
2621
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
Lines 2670-2676 sub CanBookBeRenewed { Link Here
2670
            my @reservable;
2673
            my @reservable;
2671
            my %borrowers;
2674
            my %borrowers;
2672
            ITEM: foreach my $i (@itemnumbers) {
2675
            ITEM: foreach my $i (@itemnumbers) {
2673
                my $item = GetItem($i);
2676
                my $item = Koha::Items->find($i)->unblessed;
2674
                next if IsItemOnHoldAndFound($i);
2677
                next if IsItemOnHoldAndFound($i);
2675
                for my $b (@borrowernumbers) {
2678
                for my $b (@borrowernumbers) {
2676
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
2679
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
Lines 2691-2700 sub CanBookBeRenewed { Link Here
2691
2694
2692
    return ( 1, undef ) if $override_limit;
2695
    return ( 1, undef ) if $override_limit;
2693
2696
2694
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
2697
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2695
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2698
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2696
        {   categorycode => $patron->categorycode,
2699
        {   categorycode => $patron->categorycode,
2697
            itemtype     => $item->{itype},
2700
            itemtype     => $item->effective_itemtype,
2698
            branchcode   => $branchcode
2701
            branchcode   => $branchcode
2699
        }
2702
        }
2700
    );
2703
    );
Lines 2818-2832 sub AddRenewal { Link Here
2818
    my $datedue         = shift;
2821
    my $datedue         = shift;
2819
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2822
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2820
2823
2821
    my $item   = GetItem($itemnumber) or return;
2824
    my $item   = Koha::Items->find($itemnumber) or return;
2822
    my $item_object = Koha::Items->find( $itemnumber ); # Should replace $item
2825
    my $biblio = $item->biblio;
2823
    my $biblio = $item_object->biblio;
2826
    my $issue  = $item->checkout;
2827
    my $item_unblessed = $item->unblessed;
2824
2828
2825
    my $dbh = C4::Context->dbh;
2829
    my $dbh = C4::Context->dbh;
2826
2830
2827
    # Find the issues record for this book
2828
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
2829
2830
    return unless $issue;
2831
    return unless $issue;
2831
2832
2832
    $borrowernumber ||= $issue->borrowernumber;
2833
    $borrowernumber ||= $issue->borrowernumber;
Lines 2840-2846 sub AddRenewal { Link Here
2840
    my $patron_unblessed = $patron->unblessed;
2841
    my $patron_unblessed = $patron->unblessed;
2841
2842
2842
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2843
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2843
        _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
2844
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2844
    }
2845
    }
2845
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2846
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2846
2847
Lines 2849-2859 sub AddRenewal { Link Here
2849
    # based on the value of the RenewalPeriodBase syspref.
2850
    # based on the value of the RenewalPeriodBase syspref.
2850
    unless ($datedue) {
2851
    unless ($datedue) {
2851
2852
2852
        my $itemtype = $item_object->effective_itemtype;
2853
        my $itemtype = $item->effective_itemtype;
2853
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2854
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2854
                                        dt_from_string( $issue->date_due, 'sql' ) :
2855
                                        dt_from_string( $issue->date_due, 'sql' ) :
2855
                                        DateTime->now( time_zone => C4::Context->tz());
2856
                                        DateTime->now( time_zone => C4::Context->tz());
2856
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2857
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item_unblessed, $patron_unblessed), $patron_unblessed, 'is a renewal');
2857
    }
2858
    }
2858
2859
2859
    # Update the issues record to have the new due date, and a new count
2860
    # Update the issues record to have the new due date, and a new count
Lines 2867-2881 sub AddRenewal { Link Here
2867
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2868
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2868
2869
2869
    # Update the renewal count on the item, and tell zebra to reindex
2870
    # Update the renewal count on the item, and tell zebra to reindex
2870
    $renews = $item->{renewals} + 1;
2871
    $renews = $item->renewals + 1;
2871
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2872
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } );
2872
2873
2873
    # Charge a new rental fee, if applicable?
2874
    # Charge a new rental fee, if applicable?
2874
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2875
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2875
    if ( $charge > 0 ) {
2876
    if ( $charge > 0 ) {
2876
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2877
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2877
        my $manager_id = 0;
2878
        my $manager_id = 0;
2878
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2879
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
2879
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2880
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2880
        Koha::Account::Line->new(
2881
        Koha::Account::Line->new(
2881
            {
2882
            {
Lines 2890-2896 sub AddRenewal { Link Here
2890
                branchcode        => $branchcode,
2891
                branchcode        => $branchcode,
2891
                description       => 'Renewal of Rental Item '
2892
                description       => 'Renewal of Rental Item '
2892
                  . $biblio->title
2893
                  . $biblio->title
2893
                  . " $item->{'barcode'}",
2894
                  . " $item->barcode",
2894
            }
2895
            }
2895
        )->store();
2896
        )->store();
2896
    }
2897
    }
Lines 2901-2914 sub AddRenewal { Link Here
2901
        my %conditions        = (
2902
        my %conditions        = (
2902
            branchcode   => $branch,
2903
            branchcode   => $branch,
2903
            categorycode => $patron->categorycode,
2904
            categorycode => $patron->categorycode,
2904
            item_type    => $item->{itype},
2905
            item_type    => $item->effective_itemtype,
2905
            notification => 'CHECKOUT',
2906
            notification => 'CHECKOUT',
2906
        );
2907
        );
2907
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2908
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2908
            SendCirculationAlert(
2909
            SendCirculationAlert(
2909
                {
2910
                {
2910
                    type     => 'RENEWAL',
2911
                    type     => 'RENEWAL',
2911
                    item     => $item,
2912
                    item     => $item_unblessed,
2912
                    borrower => $patron->unblessed,
2913
                    borrower => $patron->unblessed,
2913
                    branch   => $branch,
2914
                    branch   => $branch,
2914
                }
2915
                }
Lines 2936-2945 sub AddRenewal { Link Here
2936
            type           => 'renew',
2937
            type           => 'renew',
2937
            amount         => $charge,
2938
            amount         => $charge,
2938
            itemnumber     => $itemnumber,
2939
            itemnumber     => $itemnumber,
2939
            itemtype       => $item->{itype},
2940
            itemtype       => $item->effective_itemtype,
2940
            location       => $item->{location},
2941
            location       => $item->location,
2941
            borrowernumber => $borrowernumber,
2942
            borrowernumber => $borrowernumber,
2942
            ccode          => $item->{'ccode'}
2943
            ccode          => $item->ccode,
2943
        }
2944
        }
2944
    );
2945
    );
2945
2946
Lines 2957-2963 sub GetRenewCount { Link Here
2957
    my $renewsleft    = 0;
2958
    my $renewsleft    = 0;
2958
2959
2959
    my $patron = Koha::Patrons->find( $bornum );
2960
    my $patron = Koha::Patrons->find( $bornum );
2960
    my $item     = GetItem($itemno);
2961
    my $item   = Koha::Items->find($itemno);
2961
2962
2962
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2963
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2963
2964
Lines 2974-2984 sub GetRenewCount { Link Here
2974
    my $data = $sth->fetchrow_hashref;
2975
    my $data = $sth->fetchrow_hashref;
2975
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2976
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2976
    # $item and $borrower should be calculated
2977
    # $item and $borrower should be calculated
2977
    my $branchcode = _GetCircControlBranch($item, $patron->unblessed);
2978
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
2978
2979
2979
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2980
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2980
        {   categorycode => $patron->categorycode,
2981
        {   categorycode => $patron->categorycode,
2981
            itemtype     => $item->{itype},
2982
            itemtype     => $item->effective_itemtype,
2982
            branchcode   => $branchcode
2983
            branchcode   => $branchcode
2983
        }
2984
        }
2984
    );
2985
    );
Lines 3013-3029 sub GetSoonestRenewDate { Link Here
3013
3014
3014
    my $dbh = C4::Context->dbh;
3015
    my $dbh = C4::Context->dbh;
3015
3016
3016
    my $item      = GetItem($itemnumber)      or return;
3017
    my $item      = Koha::Items->find($itemnumber)      or return;
3017
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3018
    my $itemissue = $item->checkout or return;
3018
3019
3019
    $borrowernumber ||= $itemissue->borrowernumber;
3020
    $borrowernumber ||= $itemissue->borrowernumber;
3020
    my $patron = Koha::Patrons->find( $borrowernumber )
3021
    my $patron = Koha::Patrons->find( $borrowernumber )
3021
      or return;
3022
      or return;
3022
3023
3023
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3024
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3024
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3025
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3025
        {   categorycode => $patron->categorycode,
3026
        {   categorycode => $patron->categorycode,
3026
            itemtype     => $item->{itype},
3027
            itemtype     => $item->effective_itemtype,
3027
            branchcode   => $branchcode
3028
            branchcode   => $branchcode
3028
        }
3029
        }
3029
    );
3030
    );
Lines 3072-3088 sub GetLatestAutoRenewDate { Link Here
3072
3073
3073
    my $dbh = C4::Context->dbh;
3074
    my $dbh = C4::Context->dbh;
3074
3075
3075
    my $item      = GetItem($itemnumber)      or return;
3076
    my $item      = Koha::Items->find($itemnumber)  or return;
3076
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3077
    my $itemissue = $item->checkout                 or return;
3077
3078
3078
    $borrowernumber ||= $itemissue->borrowernumber;
3079
    $borrowernumber ||= $itemissue->borrowernumber;
3079
    my $patron = Koha::Patrons->find( $borrowernumber )
3080
    my $patron = Koha::Patrons->find( $borrowernumber )
3080
      or return;
3081
      or return;
3081
3082
3082
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3083
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3083
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3084
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3084
        {   categorycode => $patron->categorycode,
3085
        {   categorycode => $patron->categorycode,
3085
            itemtype     => $item->{itype},
3086
            itemtype     => $item->effective_itemtype,
3086
            branchcode   => $branchcode
3087
            branchcode   => $branchcode
3087
        }
3088
        }
3088
    );
3089
    );
Lines 3662-3669 sub ReturnLostItem{ Link Here
3662
3663
3663
    MarkIssueReturned( $borrowernumber, $itemnum );
3664
    MarkIssueReturned( $borrowernumber, $itemnum );
3664
    my $patron = Koha::Patrons->find( $borrowernumber );
3665
    my $patron = Koha::Patrons->find( $borrowernumber );
3665
    my $item = C4::Items::GetItem( $itemnum );
3666
    my $item = Koha::Items->find($itemnum);
3666
    my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{};
3667
    my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{};
3667
    my @datearr = localtime(time);
3668
    my @datearr = localtime(time);
3668
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3669
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3669
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
3670
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
Lines 3852-3859 sub ProcessOfflinePayment { Link Here
3852
sub TransferSlip {
3853
sub TransferSlip {
3853
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3854
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3854
3855
3855
    my $item =  GetItem( $itemnumber, $barcode )
3856
    my $item =
3856
      or return;
3857
      $itemnumber
3858
      ? Koha::Items->find($itemnumber)
3859
      : Koha::Items->find( { barcode => $barcode } );
3860
3861
    $item or return;
3857
3862
3858
    return C4::Letters::GetPreparedLetter (
3863
    return C4::Letters::GetPreparedLetter (
3859
        module => 'circulation',
3864
        module => 'circulation',
Lines 3861-3868 sub TransferSlip { Link Here
3861
        branchcode => $branch,
3866
        branchcode => $branch,
3862
        tables => {
3867
        tables => {
3863
            'branches'    => $to_branch,
3868
            'branches'    => $to_branch,
3864
            'biblio'      => $item->{biblionumber},
3869
            'biblio'      => $item->biblionumber,
3865
            'items'       => $item,
3870
            'items'       => $item->unblessed,
3866
        },
3871
        },
3867
    );
3872
    );
3868
}
3873
}
(-)a/C4/CourseReserves.pm (-3 / +3 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use List::MoreUtils qw(any);
20
use List::MoreUtils qw(any);
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Items qw(GetItem ModItem);
23
use C4::Items qw(ModItem);
24
use C4::Circulation qw(GetOpenIssue);
24
use C4::Circulation qw(GetOpenIssue);
25
25
26
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
26
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
Lines 606-619 sub _SwapAllFields { Link Here
606
    warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG;
606
    warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG;
607
607
608
    my $course_item = GetCourseItem( ci_id => $ci_id );
608
    my $course_item = GetCourseItem( ci_id => $ci_id );
609
    my $item = GetItem( $course_item->{'itemnumber'} );
609
    my $item = Koha::Items->find($course_item->{'itemnumber'});
610
610
611
    my %course_item_fields;
611
    my %course_item_fields;
612
    my %item_fields;
612
    my %item_fields;
613
    foreach (@FIELDS) {
613
    foreach (@FIELDS) {
614
        if ( defined( $course_item->{$_} ) ) {
614
        if ( defined( $course_item->{$_} ) ) {
615
            $course_item_fields{$_} = $course_item->{$_};
615
            $course_item_fields{$_} = $course_item->{$_};
616
            $item_fields{$_}        = $item->{$_} || q{};
616
            $item_fields{$_}        = $item->$_ || q{};
617
        }
617
        }
618
    }
618
    }
619
619
(-)a/C4/HoldsQueue.pm (-3 / +4 lines)
Lines 29-34 use C4::Circulation; Link Here
29
use C4::Members;
29
use C4::Members;
30
use C4::Biblio;
30
use C4::Biblio;
31
use Koha::DateUtils;
31
use Koha::DateUtils;
32
use Koha::Items;
32
use Koha::Patrons;
33
use Koha::Patrons;
33
34
34
use List::Util qw(shuffle);
35
use List::Util qw(shuffle);
Lines 674-682 sub CreatePicklistFromItemMap { Link Here
674
        my $reservenotes = $mapped_item->{reservenotes};
675
        my $reservenotes = $mapped_item->{reservenotes};
675
        my $item_level = $mapped_item->{item_level};
676
        my $item_level = $mapped_item->{item_level};
676
677
677
        my $item = GetItem($itemnumber);
678
        my $item = Koha::Items->find($itemnumber);
678
        my $barcode = $item->{barcode};
679
        my $barcode = $item->barcode;
679
        my $itemcallnumber = $item->{itemcallnumber};
680
        my $itemcallnumber = $item->itemcallnumber;
680
681
681
        my $patron = Koha::Patrons->find( $borrowernumber );
682
        my $patron = Koha::Patrons->find( $borrowernumber );
682
        my $cardnumber = $patron->cardnumber;
683
        my $cardnumber = $patron->cardnumber;
(-)a/C4/ILSDI/Services.pm (-20 / +23 lines)
Lines 535-551 sub GetServices { Link Here
535
    my $borrower = $patron->unblessed;
535
    my $borrower = $patron->unblessed;
536
    # Get the item, or return an error code if not found
536
    # Get the item, or return an error code if not found
537
    my $itemnumber = $cgi->param('item_id');
537
    my $itemnumber = $cgi->param('item_id');
538
    my $item = GetItem( $itemnumber );
538
    my $item = Koha::Items->find($itemnumber);
539
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
539
    return { code => 'RecordNotFound' } unless $item;
540
540
541
    my @availablefor;
541
    my @availablefor;
542
542
543
    # Reserve level management
543
    # Reserve level management
544
    my $biblionumber = $item->{'biblionumber'};
544
    my $biblionumber = $item->biblionumber;
545
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
545
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
546
    if ($canbookbereserved->{status} eq 'OK') {
546
    if ($canbookbereserved->{status} eq 'OK') {
547
        push @availablefor, 'title level hold';
547
        push @availablefor, 'title level hold';
548
        my $canitembereserved = IsAvailableForItemLevelRequest($item, $borrower);
548
        my $canitembereserved = IsAvailableForItemLevelRequest($item->unblessed, $borrower);
549
        if ($canitembereserved) {
549
        if ($canitembereserved) {
550
            push @availablefor, 'item level hold';
550
            push @availablefor, 'item level hold';
551
        }
551
        }
Lines 568-574 sub GetServices { Link Here
568
    }
568
    }
569
569
570
    # Issuing management
570
    # Issuing management
571
    my $barcode = $item->{'barcode'} || '';
571
    my $barcode = $item->barcode || '';
572
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
572
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
573
    if ($barcode) {
573
    if ($barcode) {
574
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
574
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
Lines 607-620 sub RenewLoan { Link Here
607
607
608
    # Get the item, or return an error code
608
    # Get the item, or return an error code
609
    my $itemnumber = $cgi->param('item_id');
609
    my $itemnumber = $cgi->param('item_id');
610
    my $item = GetItem( $itemnumber );
610
    my $item = Koha::Items->find($itemnumber);
611
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
611
    return { code => 'RecordNotFound' } unless $item;
612
612
613
    # Add renewal if possible
613
    # Add renewal if possible
614
    my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
614
    my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
615
    if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); }
615
    if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); }
616
616
617
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; # FIXME should be handled
617
    return unless $item; # FIXME should be handled
618
619
    my $issue = $item->checkout;
620
    return $issue; # FIXME should be handled
618
621
619
    # Hashref building
622
    # Hashref building
620
    my $out;
623
    my $out;
Lines 745-755 sub HoldItem { Link Here
745
748
746
    # Get the item or return an error code
749
    # Get the item or return an error code
747
    my $itemnumber = $cgi->param('item_id');
750
    my $itemnumber = $cgi->param('item_id');
748
    my $item = GetItem( $itemnumber );
751
    my $item = Koha::Items->find($itemnumber);
749
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
752
    return { code => 'RecordNotFound' } unless $item;
750
753
751
    # If the biblio does not match the item, return an error code
754
    # If the biblio does not match the item, return an error code
752
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
755
    return { code => 'RecordNotFound' } if $item->biblionumber ne $biblio->biblionumber;
753
756
754
    # Check for item disponibility
757
    # Check for item disponibility
755
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber )->{status};
758
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber )->{status};
Lines 823-847 Returns, for an itemnumber, an array containing availability information. Link Here
823
826
824
sub _availability {
827
sub _availability {
825
    my ($itemnumber) = @_;
828
    my ($itemnumber) = @_;
826
    my $item = GetItem( $itemnumber, undef, undef );
829
    my $item = Koha::Items->find($itemnumber);
827
830
828
    if ( not $item->{'itemnumber'} ) {
831
    unless ( $item ) {
829
        return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
832
        return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
830
    }
833
    }
831
834
832
    my $biblionumber = $item->{'biblioitemnumber'};
835
    my $biblionumber = $item->biblioitemnumber;
833
    my $library = Koha::Libraries->find( $item->{holdingbranch} );
836
    my $library = Koha::Libraries->find( $item->holdingbranch );
834
    my $location = $library ? $library->branchname : '';
837
    my $location = $library ? $library->branchname : '';
835
838
836
    if ( $item->{'notforloan'} ) {
839
    if ( $item->notforloan ) {
837
        return ( $biblionumber, 'not available', 'Not for loan', $location );
840
        return ( $biblionumber, 'not available', 'Not for loan', $location );
838
    } elsif ( $item->{'onloan'} ) {
841
    } elsif ( $item->onloan ) {
839
        return ( $biblionumber, 'not available', 'Checked out', $location );
842
        return ( $biblionumber, 'not available', 'Checked out', $location );
840
    } elsif ( $item->{'itemlost'} ) {
843
    } elsif ( $item->itemlost ) {
841
        return ( $biblionumber, 'not available', 'Item lost', $location );
844
        return ( $biblionumber, 'not available', 'Item lost', $location );
842
    } elsif ( $item->{'withdrawn'} ) {
845
    } elsif ( $item->withdrawn ) {
843
        return ( $biblionumber, 'not available', 'Item withdrawn', $location );
846
        return ( $biblionumber, 'not available', 'Item withdrawn', $location );
844
    } elsif ( $item->{'damaged'} ) {
847
    } elsif ( $item->damaged ) {
845
        return ( $biblionumber, 'not available', 'Item damaged', $location );
848
        return ( $biblionumber, 'not available', 'Item damaged', $location );
846
    } else {
849
    } else {
847
        return ( $biblionumber, 'available', undef, $location );
850
        return ( $biblionumber, 'available', undef, $location );
(-)a/C4/Items.pm (-28 / +13 lines)
Lines 177-186 sub CartToShelf { Link Here
177
        croak "FAILED CartToShelf() - no itemnumber supplied";
177
        croak "FAILED CartToShelf() - no itemnumber supplied";
178
    }
178
    }
179
179
180
    my $item = GetItem($itemnumber);
180
    my $item = Koha::Items->find($itemnumber);
181
    if ( $item->{location} eq 'CART' ) {
181
    if ( $item->location eq 'CART' ) {
182
        $item->{location} = $item->{permanent_location};
182
        ModItem({ location => $item->permanent_location}, undef, $itemnumber);
183
        ModItem($item, undef, $itemnumber);
184
    }
183
    }
185
}
184
}
186
185
Lines 200-208 sub ShelfToCart { Link Here
200
        croak "FAILED ShelfToCart() - no itemnumber supplied";
199
        croak "FAILED ShelfToCart() - no itemnumber supplied";
201
    }
200
    }
202
201
203
    my $item = GetItem($itemnumber);
202
    ModItem({ location => 'CART'}, undef, $itemnumber);
204
    $item->{'location'} = 'CART';
205
    ModItem($item, undef, $itemnumber);
206
}
203
}
207
204
208
=head2 AddItemFromMarc
205
=head2 AddItemFromMarc
Lines 555-566 sub ModItem { Link Here
555
552
556
    my @fields = qw( itemlost withdrawn damaged );
553
    my @fields = qw( itemlost withdrawn damaged );
557
554
558
    # Only call GetItem if we need to set an "on" date field
555
    # Only retrieve the item if we need to set an "on" date field
559
    if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) {
556
    if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) {
560
        my $pre_mod_item = GetItem( $item->{'itemnumber'} );
557
        my $pre_mod_item = Koha::Items->find( $item->{'itemnumber'} );
561
        for my $field (@fields) {
558
        for my $field (@fields) {
562
            if (    defined( $item->{$field} )
559
            if (    defined( $item->{$field} )
563
                and not $pre_mod_item->{$field}
560
                and not $pre_mod_item->$field
564
                and $item->{$field} )
561
                and $item->{$field} )
565
            {
562
            {
566
                $item->{ $field . '_on' } =
563
                $item->{ $field . '_on' } =
Lines 1334-1346 sub GetMarcItem { Link Here
1334
    # while the other treats the MARC representation as authoritative
1331
    # while the other treats the MARC representation as authoritative
1335
    # under certain circumstances.
1332
    # under certain circumstances.
1336
1333
1337
    my $itemrecord = GetItem($itemnumber);
1334
    my $item = Koha::Items->find($itemnumber) or return;
1338
1335
1339
    # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work.
1336
    # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work.
1340
    # Also, don't emit a subfield if the underlying field is blank.
1337
    # Also, don't emit a subfield if the underlying field is blank.
1341
1338
1342
    
1339
    return Item2Marc($item->unblessed, $biblionumber);
1343
    return Item2Marc($itemrecord,$biblionumber);
1344
1340
1345
}
1341
}
1346
sub Item2Marc {
1342
sub Item2Marc {
Lines 1779-1809 sub ItemSafeToDelete { Link Here
1779
1775
1780
    my $countanalytics = GetAnalyticsCount($itemnumber);
1776
    my $countanalytics = GetAnalyticsCount($itemnumber);
1781
1777
1782
    # check that there is no issue on this item before deletion.
1778
    my $item = Koha::Items->find($itemnumber) or return;
1783
    my $sth = $dbh->prepare(
1784
        q{
1785
        SELECT COUNT(*) FROM issues
1786
        WHERE itemnumber = ?
1787
    }
1788
    );
1789
    $sth->execute($itemnumber);
1790
    my ($onloan) = $sth->fetchrow;
1791
1792
    my $item = GetItem($itemnumber);
1793
1779
1794
    if ($onloan) {
1780
    if ($item->checkout) {
1795
        $status = "book_on_loan";
1781
        $status = "book_on_loan";
1796
    }
1782
    }
1797
    elsif ( defined C4::Context->userenv
1783
    elsif ( defined C4::Context->userenv
1798
        and !C4::Context->IsSuperLibrarian()
1784
        and !C4::Context->IsSuperLibrarian()
1799
        and C4::Context->preference("IndependentBranches")
1785
        and C4::Context->preference("IndependentBranches")
1800
        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
1786
        and ( C4::Context->userenv->{branch} ne $item->homebranch ) )
1801
    {
1787
    {
1802
        $status = "not_same_branch";
1788
        $status = "not_same_branch";
1803
    }
1789
    }
1804
    else {
1790
    else {
1805
        # check it doesn't have a waiting reserve
1791
        # check it doesn't have a waiting reserve
1806
        $sth = $dbh->prepare(
1792
        my $sth = $dbh->prepare(
1807
            q{
1793
            q{
1808
            SELECT COUNT(*) FROM reserves
1794
            SELECT COUNT(*) FROM reserves
1809
            WHERE (found = 'W' OR found = 'T')
1795
            WHERE (found = 'W' OR found = 'T')
Lines 2688-2694 sub ToggleNewStatus { Link Here
2688
        while ( my $values = $sth->fetchrow_hashref ) {
2674
        while ( my $values = $sth->fetchrow_hashref ) {
2689
            my $biblionumber = $values->{biblionumber};
2675
            my $biblionumber = $values->{biblionumber};
2690
            my $itemnumber = $values->{itemnumber};
2676
            my $itemnumber = $values->{itemnumber};
2691
            my $item = C4::Items::GetItem( $itemnumber );
2692
            for my $substitution ( @$substitutions ) {
2677
            for my $substitution ( @$substitutions ) {
2693
                next unless $substitution->{field};
2678
                next unless $substitution->{field};
2694
                C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
2679
                C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
(-)a/C4/Message.pm (-1 / +1 lines)
Lines 37-43 How to add a new message to the queue: Link Here
37
  use C4::Message;
37
  use C4::Message;
38
  use C4::Items;
38
  use C4::Items;
39
  my $borrower = { borrowernumber => 1 };
39
  my $borrower = { borrowernumber => 1 };
40
  my $item     = C4::Items::GetItem(1);
40
  my $item     = Koha::Items->find($itemnumber)->unblessed;
41
  my $letter =  C4::Letters::GetPreparedLetter (
41
  my $letter =  C4::Letters::GetPreparedLetter (
42
      module => 'circulation',
42
      module => 'circulation',
43
      letter_code => 'CHECKOUT',
43
      letter_code => 'CHECKOUT',
(-)a/C4/Reserves.pm (-20 / +19 lines)
Lines 320-333 sub CanItemBeReserved { Link Here
320
320
321
    # we retrieve borrowers and items informations #
321
    # we retrieve borrowers and items informations #
322
    # item->{itype} will come for biblioitems if necessery
322
    # item->{itype} will come for biblioitems if necessery
323
    my $item       = C4::Items::GetItem($itemnumber);
323
    my $item       = Koha::Items->find($itemnumber);
324
    my $biblio     = Koha::Biblios->find( $item->{biblionumber} );
324
    my $biblio     = $item->biblio;
325
    my $patron = Koha::Patrons->find( $borrowernumber );
325
    my $patron = Koha::Patrons->find( $borrowernumber );
326
    my $borrower = $patron->unblessed;
326
    my $borrower = $patron->unblessed;
327
327
328
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
328
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
329
    return { status =>'damaged' }
329
    return { status =>'damaged' }
330
      if ( $item->{damaged}
330
      if ( $item->damaged
331
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
331
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
332
332
333
    # Check for the age restriction
333
    # Check for the age restriction
Lines 355-361 sub CanItemBeReserved { Link Here
355
355
356
    if ( $controlbranch eq "ItemHomeLibrary" ) {
356
    if ( $controlbranch eq "ItemHomeLibrary" ) {
357
        $branchfield = "items.homebranch";
357
        $branchfield = "items.homebranch";
358
        $branchcode  = $item->{homebranch};
358
        $branchcode  = $item->homebranch;
359
    }
359
    }
360
    elsif ( $controlbranch eq "PatronLibrary" ) {
360
    elsif ( $controlbranch eq "PatronLibrary" ) {
361
        $branchfield = "borrowers.branchcode";
361
        $branchfield = "borrowers.branchcode";
Lines 363-369 sub CanItemBeReserved { Link Here
363
    }
363
    }
364
364
365
    # we retrieve rights
365
    # we retrieve rights
366
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) {
366
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
367
        $ruleitemtype     = $rights->{itemtype};
367
        $ruleitemtype     = $rights->{itemtype};
368
        $allowedreserves  = $rights->{reservesallowed};
368
        $allowedreserves  = $rights->{reservesallowed};
369
        $holds_per_record = $rights->{holds_per_record};
369
        $holds_per_record = $rights->{holds_per_record};
Lines 373-379 sub CanItemBeReserved { Link Here
373
        $ruleitemtype = '*';
373
        $ruleitemtype = '*';
374
    }
374
    }
375
375
376
    $item = Koha::Items->find( $itemnumber );
377
    my $holds = Koha::Holds->search(
376
    my $holds = Koha::Holds->search(
378
        {
377
        {
379
            borrowernumber => $borrowernumber,
378
            borrowernumber => $borrowernumber,
Lines 449-455 sub CanItemBeReserved { Link Here
449
    my $circ_control_branch =
448
    my $circ_control_branch =
450
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
449
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
451
    my $branchitemrule =
450
    my $branchitemrule =
452
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype );
451
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype ); # FIXME Should not be item->effective_itemtype?
453
452
454
    if ( $branchitemrule->{holdallowed} == 0 ) {
453
    if ( $branchitemrule->{holdallowed} == 0 ) {
455
        return { status => 'notReservable' };
454
        return { status => 'notReservable' };
Lines 466-473 sub CanItemBeReserved { Link Here
466
    if ( C4::Context->preference('IndependentBranches')
465
    if ( C4::Context->preference('IndependentBranches')
467
        and !C4::Context->preference('canreservefromotherbranches') )
466
        and !C4::Context->preference('canreservefromotherbranches') )
468
    {
467
    {
469
        my $itembranch = $item->homebranch;
468
        if ( $item->homebranch ne $borrower->{branchcode} ) {
470
        if ( $itembranch ne $borrower->{branchcode} ) {
471
            return { status => 'cannotReserveFromOtherBranches' };
469
            return { status => 'cannotReserveFromOtherBranches' };
472
        }
470
        }
473
    }
471
    }
Lines 528-535 sub GetOtherReserves { Link Here
528
    my $nextreservinfo;
526
    my $nextreservinfo;
529
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
527
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
530
    if ($checkreserves) {
528
    if ($checkreserves) {
531
        my $iteminfo = GetItem($itemnumber);
529
        my $item = Koha::Items->find($itemnumber);
532
        if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
530
        if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) {
533
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
531
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
534
            #minus priorities of others reservs
532
            #minus priorities of others reservs
535
            ModReserveMinusPriority(
533
            ModReserveMinusPriority(
Lines 540-546 sub GetOtherReserves { Link Here
540
            #launch the subroutine dotransfer
538
            #launch the subroutine dotransfer
541
            C4::Items::ModItemTransfer(
539
            C4::Items::ModItemTransfer(
542
                $itemnumber,
540
                $itemnumber,
543
                $iteminfo->{'holdingbranch'},
541
                $item->holdingbranch,
544
                $checkreserves->{'branchcode'}
542
                $checkreserves->{'branchcode'}
545
              ),
543
              ),
546
              ;
544
              ;
Lines 776-790 sub CheckReserves { Link Here
776
                }
774
                }
777
            } else {
775
            } else {
778
                my $patron;
776
                my $patron;
779
                my $iteminfo;
777
                my $item;
780
                my $local_hold_match;
778
                my $local_hold_match;
781
779
782
                if ($LocalHoldsPriority) {
780
                if ($LocalHoldsPriority) {
783
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
781
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
784
                    $iteminfo = C4::Items::GetItem($itemnumber);
782
                    $item = Koha::Items->find($itemnumber);
785
783
786
                    my $local_holds_priority_item_branchcode =
784
                    my $local_holds_priority_item_branchcode =
787
                      $iteminfo->{$LocalHoldsPriorityItemControl};
785
                      $item->$LocalHoldsPriorityItemControl;
788
                    my $local_holds_priority_patron_branchcode =
786
                    my $local_holds_priority_patron_branchcode =
789
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
787
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
790
                      ? $res->{branchcode}
788
                      ? $res->{branchcode}
Lines 798-811 sub CheckReserves { Link Here
798
796
799
                # See if this item is more important than what we've got so far
797
                # See if this item is more important than what we've got so far
800
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
798
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
801
                    $iteminfo ||= C4::Items::GetItem($itemnumber);
799
                    $item ||= Koha::Items->find($itemnumber);
802
                    next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
800
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
803
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
801
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
804
                    my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
802
                    my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
805
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
803
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
806
                    next if ($branchitemrule->{'holdallowed'} == 0);
804
                    next if ($branchitemrule->{'holdallowed'} == 0);
807
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
805
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
808
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
806
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
807
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
809
                    $priority = $res->{'priority'};
808
                    $priority = $res->{'priority'};
810
                    $highest  = $res;
809
                    $highest  = $res;
811
                    last if $local_hold_match;
810
                    last if $local_hold_match;
(-)a/acqui/orderreceive.pl (-4 / +5 lines)
Lines 130-139 if ($AcqCreateItem eq 'receiving') { Link Here
130
    );
130
    );
131
} elsif ($AcqCreateItem eq 'ordering') {
131
} elsif ($AcqCreateItem eq 'ordering') {
132
    my $fw = ($acq_fw) ? 'ACQ' : '';
132
    my $fw = ($acq_fw) ? 'ACQ' : '';
133
    my @itemnumbers = $order_object->items->get_column('itemnumber');
133
    my $items = $order_object->items;
134
    my @items;
134
    my @items;
135
    foreach (@itemnumbers) {
135
    while ( my $i = $items->next ) {
136
        my $item = GetItem($_); # FIXME We do not need this call, we already have the Koha::Items
136
        my $item = $i->unblessed;
137
        my $descriptions;
137
        my $descriptions;
138
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
138
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
139
        $item->{notforloan} = $descriptions->{lib} // '';
139
        $item->{notforloan} = $descriptions->{lib} // '';
Lines 150-157 if ($AcqCreateItem eq 'receiving') { Link Here
150
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
150
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
151
        $item->{materials} = $descriptions->{lib} // '';
151
        $item->{materials} = $descriptions->{lib} // '';
152
152
153
        my $itemtype = Koha::ItemTypes->find( $item->{itype} );
153
        my $itemtype = Koha::ItemTypes->find($i->effective_itemtype);
154
        if (defined $itemtype) {
154
        if (defined $itemtype) {
155
            # We should not do that here, but call ->itemtype->description when needed instead
155
            $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
156
            $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
156
        }
157
        }
157
        push @items, $item;
158
        push @items, $item;
(-)a/catalogue/getitem-ajax.pl (-18 / +22 lines)
Lines 29-34 use C4::Output; Link Here
29
use Koha::Libraries;
29
use Koha::Libraries;
30
30
31
use Koha::AuthorisedValues;
31
use Koha::AuthorisedValues;
32
use Koha::Items;
32
use Koha::ItemTypes;
33
use Koha::ItemTypes;
33
34
34
my $cgi = new CGI;
35
my $cgi = new CGI;
Lines 43-81 unless ($status eq "ok") { Link Here
43
my $item = {};
44
my $item = {};
44
my $itemnumber = $cgi->param('itemnumber');
45
my $itemnumber = $cgi->param('itemnumber');
45
46
47
my $item_unblessed = {};
46
if($itemnumber) {
48
if($itemnumber) {
47
    my $acq_fw = GetMarcStructure(1, 'ACQ');
49
    my $acq_fw = GetMarcStructure(1, 'ACQ');
48
    my $fw = ($acq_fw) ? 'ACQ' : '';
50
    my $fw = ($acq_fw) ? 'ACQ' : '';
49
    $item = GetItem($itemnumber);
51
    $item = Koha::Items->find($itemnumber);
52
    $item_unblessed = $item->unblessed; # FIXME Not needed, call home_branch and holding_branch in the templates instead
50
53
51
    if($item->{homebranch}) {
54
    if($item->homebranch) { # This test should not be needed, homebranch and holdingbranch are mandatory
52
        $item->{homebranchname} = Koha::Libraries->find($item->{homebranch})->branchname;
55
        $item_unblessed->{homebranchname} = $item->home_branch->branchname;
53
    }
56
    }
54
57
55
    if($item->{holdingbranch}) {
58
    if($item->holdingbranch) {
56
        $item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname;
59
        $item_unblessed->{holdingbranchname} = $item->holding_branch->branchname;
57
    }
60
    }
58
61
59
    my $descriptions;
62
    my $descriptions;
60
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
63
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->notforloan });
61
    $item->{notforloan} = $descriptions->{lib} // '';
64
    $item_unblessed->{notforloan} = $descriptions->{lib} // '';
62
65
63
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
66
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->restricted });
64
    $item->{restricted} = $descriptions->{lib} // '';
67
    $item_unblessed->{restricted} = $descriptions->{lib} // '';
65
68
66
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
69
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->location });
67
    $item->{location} = $descriptions->{lib} // '';
70
    $item_unblessed->{location} = $descriptions->{lib} // '';
68
71
69
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
72
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->collection });
70
    $item->{collection} = $descriptions->{lib} // '';
73
    $item_unblessed->{collection} = $descriptions->{lib} // '';
71
74
72
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
75
    $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->materials });
73
    $item->{materials} = $descriptions->{lib} // '';
76
    $item_unblessed->{materials} = $descriptions->{lib} // '';
74
77
75
    my $itemtype = Koha::ItemTypes->find( $item->{itype} );
78
    my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
76
    $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
79
    # We should not do that here, but call ->itemtype->description when needed instea
80
    $item_unblessed->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
77
}
81
}
78
82
79
my $json_text = to_json( $item, { utf8 => 1 } );
83
my $json_text = to_json( $item_unblessed, { utf8 => 1 } );
80
84
81
output_with_http_headers $cgi, undef, $json_text, 'json';
85
output_with_http_headers $cgi, undef, $json_text, 'json';
(-)a/catalogue/updateitem.pl (-1 / +1 lines)
Lines 44-50 my $confirm=$cgi->param('confirm'); Link Here
44
my $dbh = C4::Context->dbh;
44
my $dbh = C4::Context->dbh;
45
45
46
# get the rest of this item's information
46
# get the rest of this item's information
47
my $item_data_hashref = GetItem($itemnumber, undef);
47
my $item_data_hashref = Koha::Items->find($itemnumber)->unblessed;
48
48
49
# make sure item statuses are set to 0 if empty or NULL
49
# make sure item statuses are set to 0 if empty or NULL
50
for ($damaged,$itemlost,$withdrawn) {
50
for ($damaged,$itemlost,$withdrawn) {
(-)a/cataloguing/additem.pl (-9 / +14 lines)
Lines 74-88 sub get_item_from_barcode { Link Here
74
74
75
sub set_item_default_location {
75
sub set_item_default_location {
76
    my $itemnumber = shift;
76
    my $itemnumber = shift;
77
    my $item = GetItem( $itemnumber );
77
    my $item       = Koha::Items->find($itemnumber);
78
    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
78
    if ( C4::Context->preference('NewItemsDefaultLocation') ) {
79
        $item->{'permanent_location'} = $item->{'location'};
79
        ModItem(
80
        $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation');
80
            {
81
        ModItem( $item, undef, $itemnumber);
81
                permanent_location => $item->location,
82
                location => C4::Context->preference('NewItemsDefaultLocation')
83
            },
84
            undef,
85
            $itemnumber
86
        );
82
    }
87
    }
83
    else {
88
    else {
84
      $item->{'permanent_location'} = $item->{'location'} if !defined($item->{'permanent_location'});
89
        ModItem( { permanent_location => $item->location }, undef, $itemnumber )
85
      ModItem( $item, undef, $itemnumber);
90
          unless defined $item->permanent_location;
86
    }
91
    }
87
}
92
}
88
93
Lines 693-704 if ($op eq "additem") { Link Here
693
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
698
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
694
        push @errors,"barcode_not_unique";
699
        push @errors,"barcode_not_unique";
695
    } else {
700
    } else {
696
        my $item = GetItem( $itemnumber );
701
        my $item = Koha::Items->find($itemnumber );
697
        my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber);
702
        my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber);
698
        $itemnumber = q{};
703
        $itemnumber = q{};
699
        my $olditemlost = $item->{itemlost};
704
        my $olditemlost = $item->itemlost;
700
        my $newitemlost = $newitem->{itemlost};
705
        my $newitemlost = $newitem->{itemlost};
701
        LostItem( $item->{itemnumber}, 'additem' )
706
        LostItem( $item->itemnumber, 'additem' )
702
            if $newitemlost && $newitemlost ge '1' && !$olditemlost;
707
            if $newitemlost && $newitemlost ge '1' && !$olditemlost;
703
    }
708
    }
704
    $nextop="additem";
709
    $nextop="additem";
(-)a/installer/data/mysql/backfill_statistics.pl (-4 / +5 lines)
Lines 78-90 my $query = "UPDATE statistics SET itemtype = ? WHERE itemnumber = ?"; Link Here
78
my $update = $dbh->prepare($query);
78
my $update = $dbh->prepare($query);
79
# $debug and print "Update Query: $query\n";
79
# $debug and print "Update Query: $query\n";
80
foreach (@itemnumbers) {
80
foreach (@itemnumbers) {
81
	my $item = GetItem($_);
81
    my $item = Koha::Items->find($_);
82
	unless ($item) {
82
    unless ($item) {
83
		print STDERR "\tNo item found for itemnumber $_\n"; 
83
		print STDERR "\tNo item found for itemnumber $_\n"; 
84
		next;
84
		next;
85
	}
85
	}
86
	$update->execute($item->{itype},$_) or warn "Error in UPDATE execution";
86
    my $itemtype = $item->effective_itemtype;
87
	printf "\titemnumber %5d : %7s  (%s rows)\n", $_, $item->{itype}, $update->rows;
87
    $update->execute($itemtype,$_) or warn "Error in UPDATE execution";
88
    printf "\titemnumber %5d : %7s  (%s rows)\n", $_, $itemtype, $update->rows;
88
}
89
}
89
90
90
my $old_issues = $dbh->prepare("SELECT * FROM old_issues WHERE timestamp = ? AND itemnumber = ?");
91
my $old_issues = $dbh->prepare("SELECT * FROM old_issues WHERE timestamp = ? AND itemnumber = ?");
(-)a/labels/label-edit-batch.pl (-2 / +1 lines)
Lines 25-31 use CGI qw ( -utf8 ); Link Here
25
25
26
use C4::Auth qw(get_template_and_user);
26
use C4::Auth qw(get_template_and_user);
27
use C4::Output qw(output_html_with_http_headers);
27
use C4::Output qw(output_html_with_http_headers);
28
use C4::Items qw(GetItem);
29
use C4::Creators;
28
use C4::Creators;
30
use C4::Labels;
29
use C4::Labels;
31
30
Lines 89-95 elsif ($op eq 'add') { Link Here
89
        my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a <cr> separated list
88
        my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a <cr> separated list
90
        foreach my $number (@numbers_list) {
89
        foreach my $number (@numbers_list) {
91
            $number =~ s/\r$//; # strip any naughty return chars
90
            $number =~ s/\r$//; # strip any naughty return chars
92
            if( $number_type eq "itemnumber" && GetItem($number) ) {
91
            if( $number_type eq "itemnumber" && Koha::Items->find($number) ) {
93
                push @item_numbers, $number;
92
                push @item_numbers, $number;
94
            }
93
            }
95
            elsif ($number_type eq "barcode" ) {  # we must test in case an invalid barcode is passed in; we effectively disgard them atm
94
            elsif ($number_type eq "barcode" ) {  # we must test in case an invalid barcode is passed in; we effectively disgard them atm
(-)a/misc/recreateIssueStatistics.pl (-9 / +13 lines)
Lines 26-31 use C4::Context; Link Here
26
use C4::Items;
26
use C4::Items;
27
use Data::Dumper;
27
use Data::Dumper;
28
use Getopt::Long;
28
use Getopt::Long;
29
use Koha::Items;
29
30
30
my $dbh = C4::Context->dbh;
31
my $dbh = C4::Context->dbh;
31
32
Lines 73-79 if ($issues == 1) { Link Here
73
		    my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
74
		    my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
74
					 VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
75
					 VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
75
		    $substh = $dbh->prepare($insert);
76
		    $substh = $dbh->prepare($insert);
76
		    my $item = GetItem($hashref->{'itemnumber'});
77
            my $item = Koha::Items->find($hashref->{'itemnumber'});
78
            my $itemtype = $item->effective_itemtype;
77
79
78
		    $substh->execute(
80
		    $substh->execute(
79
			$hashref->{'issuedate'},
81
			$hashref->{'issuedate'},
Lines 82-91 if ($issues == 1) { Link Here
82
			'issue',
84
			'issue',
83
			'',
85
			'',
84
			$hashref->{'itemnumber'},
86
			$hashref->{'itemnumber'},
85
			$item->{'itype'},
87
            $itemtype,
86
			$hashref->{'borrowernumber'}
88
			$hashref->{'borrowernumber'}
87
		    );
89
		    );
88
		    print "date: $hashref->{'issuedate'} branchcode: $hashref->{'branchcode'} type: issue itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n";
90
            print "date: $hashref->{'issuedate'} branchcode: $hashref->{'branchcode'} type: issue itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n";
89
		    $count_issues++;
91
		    $count_issues++;
90
		}
92
		}
91
93
Lines 106-112 if ($issues == 1) { Link Here
106
			my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
108
			my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
107
					 VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
109
					 VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
108
			$substh = $dbh->prepare($insert);
110
			$substh = $dbh->prepare($insert);
109
			my $item = GetItem($hashref->{'itemnumber'});
111
            my $item = Koha::Items->find($hashref->{'itemnumber'});
112
            my $itemtype = $item->effective_itemtype;
110
113
111
			$substh->execute(
114
			$substh->execute(
112
			    $hashref->{'lastreneweddate'},
115
			    $hashref->{'lastreneweddate'},
Lines 115-124 if ($issues == 1) { Link Here
115
			    'renew',
118
			    'renew',
116
			    '',
119
			    '',
117
			    $hashref->{'itemnumber'},
120
			    $hashref->{'itemnumber'},
118
			    $item->{'itype'},
121
                $itemtype,
119
			    $hashref->{'borrowernumber'}
122
			    $hashref->{'borrowernumber'}
120
			    );
123
			    );
121
			print "date: $hashref->{'lastreneweddate'} branchcode: $hashref->{'branchcode'} type: renew itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n";
124
            print "date: $hashref->{'lastreneweddate'} branchcode: $hashref->{'branchcode'} type: renew itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n";
122
			$count_renewals++;
125
			$count_renewals++;
123
126
124
		    }
127
		    }
Lines 145-151 if ($returns == 1) { Link Here
145
		my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
148
		my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
146
				     VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
149
				     VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
147
		$substh = $dbh->prepare($insert);
150
		$substh = $dbh->prepare($insert);
148
		my $item = GetItem($hashref->{'itemnumber'});
151
        my $item = Koha::Items->find($hashref->{'itemnumber'});
152
        my $itemtype = $item->effective_itemtype;
149
153
150
		$substh->execute(
154
		$substh->execute(
151
		    $hashref->{'returndate'},
155
		    $hashref->{'returndate'},
Lines 154-163 if ($returns == 1) { Link Here
154
		    'return',
158
		    'return',
155
		    '',
159
		    '',
156
		    $hashref->{'itemnumber'},
160
		    $hashref->{'itemnumber'},
157
		    $item->{'itype'},
161
            $itemtype,
158
		    $hashref->{'borrowernumber'}
162
		    $hashref->{'borrowernumber'}
159
		);
163
		);
160
		print "date: $hashref->{'returndate'} branchcode: $hashref->{'branchcode'} type: return itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n";
164
        print "date: $hashref->{'returndate'} branchcode: $hashref->{'branchcode'} type: return itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n";
161
		$count_returns++;
165
		$count_returns++;
162
	    }
166
	    }
163
167
(-)a/opac/opac-renew.pl (-3 / +4 lines)
Lines 29-34 use C4::Auth; Link Here
29
use C4::Context;
29
use C4::Context;
30
use C4::Items;
30
use C4::Items;
31
use C4::Members;
31
use C4::Members;
32
use Koha::Items;
32
use Koha::Patrons;
33
use Koha::Patrons;
33
use Date::Calc qw( Today Date_to_Days );
34
use Date::Calc qw( Today Date_to_Days );
34
my $query = new CGI;
35
my $query = new CGI;
Lines 65-78 else { Link Here
65
            my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
66
            my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
66
            my $branchcode;
67
            my $branchcode;
67
            if ( $renewalbranch eq 'itemhomebranch' ) {
68
            if ( $renewalbranch eq 'itemhomebranch' ) {
68
                my $item = GetItem($itemnumber);
69
                my $item = Koha::Items->find($itemnumber);
69
                $branchcode = $item->{'homebranch'};
70
                $branchcode = $item->homebranch;
70
            }
71
            }
71
            elsif ( $renewalbranch eq 'patronhomebranch' ) {
72
            elsif ( $renewalbranch eq 'patronhomebranch' ) {
72
                $branchcode = Koha::Patrons->find( $borrowernumber )->branchcode;
73
                $branchcode = Koha::Patrons->find( $borrowernumber )->branchcode;
73
            }
74
            }
74
            elsif ( $renewalbranch eq 'checkoutbranch' ) {
75
            elsif ( $renewalbranch eq 'checkoutbranch' ) {
75
                my $issue = GetOpenIssue($itemnumber);
76
                my $issue = GetOpenIssue($itemnumber); # FIXME Should not be $item->checkout?
76
                $branchcode = $issue->{'branchcode'};
77
                $branchcode = $issue->{'branchcode'};
77
            }
78
            }
78
            elsif ( $renewalbranch eq 'NULL' ) {
79
            elsif ( $renewalbranch eq 'NULL' ) {
(-)a/opac/opac-shelves.pl (-3 / +3 lines)
Lines 176-185 if ( $op eq 'add_form' ) { Link Here
176
    $shelf = Koha::Virtualshelves->find($shelfnumber);
176
    $shelf = Koha::Virtualshelves->find($shelfnumber);
177
    if ($shelf) {
177
    if ($shelf) {
178
        if( my $barcode = $query->param('barcode') ) {
178
        if( my $barcode = $query->param('barcode') ) {
179
            my $item = GetItem( 0, $barcode);
179
            my $item = Koha::Items->find({ barcode => $barcode });
180
            if (defined $item && $item->{itemnumber}) {
180
            if ( $item ) {
181
                if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
181
                if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
182
                    my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); };
182
                    my $added = eval { $shelf->add_biblio( $item->biblionumber, $loggedinuser ); };
183
                    if ($@) {
183
                    if ($@) {
184
                        push @messages, { type => 'error', code => ref($@), msg => $@ };
184
                        push @messages, { type => 'error', code => ref($@), msg => $@ };
185
                    } elsif ( $added ) {
185
                    } elsif ( $added ) {
(-)a/opac/sco/sco-main.pl (-4 / +6 lines)
Lines 45-50 use C4::Biblio; Link Here
45
use C4::Items;
45
use C4::Items;
46
use Koha::DateUtils qw( dt_from_string );
46
use Koha::DateUtils qw( dt_from_string );
47
use Koha::Acquisition::Currencies;
47
use Koha::Acquisition::Currencies;
48
use Koha::Items;
48
use Koha::Patrons;
49
use Koha::Patrons;
49
use Koha::Patron::Images;
50
use Koha::Patron::Images;
50
use Koha::Patron::Messages;
51
use Koha::Patron::Messages;
Lines 102-111 my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed, $newissues) = Link Here
102
    $query->param("confirmed")  || '',
103
    $query->param("confirmed")  || '',
103
    $query->param("newissues")  || '',
104
    $query->param("newissues")  || '',
104
);
105
);
106
105
my @newissueslist = split /,/, $newissues;
107
my @newissueslist = split /,/, $newissues;
106
my $issuenoconfirm = 1; #don't need to confirm on issue.
108
my $issuenoconfirm = 1; #don't need to confirm on issue.
107
my $issuer   = Koha::Patrons->find( $issuerid )->unblessed;
109
my $issuer   = Koha::Patrons->find( $issuerid )->unblessed;
108
my $item     = GetItem(undef,$barcode);
110
my $item     = Koha::Items->find({ barcode => $barcode });
109
if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) {
111
if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) {
110
    my $dbh = C4::Context->dbh;
112
    my $dbh = C4::Context->dbh;
111
    my $resval;
113
    my $resval;
Lines 158-164 elsif ( $patron and $op eq "checkout" ) { Link Here
158
        $template->param(
160
        $template->param(
159
            impossible                => $issue_error,
161
            impossible                => $issue_error,
160
            "circ_error_$issue_error" => 1,
162
            "circ_error_$issue_error" => 1,
161
            title                     => $item->{title},
163
            title                     => $item->biblio->title, # FIXME Need to be backport! GetItem did not return the biblio's title
162
            hide_main                 => 1,
164
            hide_main                 => 1,
163
        );
165
        );
164
        if ($issue_error eq 'DEBT') {
166
        if ($issue_error eq 'DEBT') {
Lines 175-181 elsif ( $patron and $op eq "checkout" ) { Link Here
175
    } elsif ( $needconfirm->{RENEW_ISSUE} ) {
177
    } elsif ( $needconfirm->{RENEW_ISSUE} ) {
176
        if ($confirmed) {
178
        if ($confirmed) {
177
            #warn "renewing";
179
            #warn "renewing";
178
            AddRenewal( $borrower->{borrowernumber}, $item->{itemnumber} );
180
            AddRenewal( $borrower->{borrowernumber}, $item->itemnumber );
179
            push @newissueslist, $barcode;
181
            push @newissueslist, $barcode;
180
        } else {
182
        } else {
181
            #warn "renew confirmation";
183
            #warn "renew confirmation";
Lines 239-245 elsif ( $patron and $op eq "checkout" ) { Link Here
239
            $confirm_required = 1;
241
            $confirm_required = 1;
240
            #warn "issue confirmation";
242
            #warn "issue confirmation";
241
            $template->param(
243
            $template->param(
242
                confirm    => "Issuing title: " . $item->{title},
244
                confirm    => "Issuing title: " . $item->biblio->title,
243
                barcode    => $barcode,
245
                barcode    => $barcode,
244
                hide_main  => 1,
246
                hide_main  => 1,
245
                inputfocus => 'confirm',
247
                inputfocus => 'confirm',
(-)a/reserve/placerequest.pl (-3 / +5 lines)
Lines 31-36 use C4::Reserves; Link Here
31
use C4::Circulation;
31
use C4::Circulation;
32
use C4::Members;
32
use C4::Members;
33
use C4::Auth qw/checkauth/;
33
use C4::Auth qw/checkauth/;
34
35
use Koha::Items;
34
use Koha::Patrons;
36
use Koha::Patrons;
35
37
36
my $input = CGI->new();
38
my $input = CGI->new();
Lines 87-95 if ( $type eq 'str8' && $borrower ) { Link Here
87
        }
89
        }
88
90
89
        if ( defined $checkitem && $checkitem ne '' ) {
91
        if ( defined $checkitem && $checkitem ne '' ) {
90
            my $item = GetItem($checkitem);
92
            my $item = Koha::Items->find($checkitem);
91
            if ( $item->{'biblionumber'} ne $biblionumber ) {
93
            if ( $item->biblionumber ne $biblionumber ) {
92
                $biblionumber = $item->{'biblionumber'};
94
                $biblionumber = $item->biblionumber;
93
            }
95
            }
94
        }
96
        }
95
97
(-)a/svc/checkin (-8 / +6 lines)
Lines 24-30 use CGI; Link Here
24
use JSON qw(to_json);
24
use JSON qw(to_json);
25
25
26
use C4::Circulation;
26
use C4::Circulation;
27
use C4::Items qw(GetItem ModItem);
27
use C4::Items qw(ModItem);
28
use C4::Context;
28
use C4::Context;
29
use C4::Auth qw(check_cookie_auth);
29
use C4::Auth qw(check_cookie_auth);
30
use Koha::Checkouts;
30
use Koha::Checkouts;
Lines 64-80 $data->{borrowernumber} = $borrowernumber; Link Here
64
$data->{branchcode}     = $branchcode;
64
$data->{branchcode}     = $branchcode;
65
65
66
if ( C4::Context->preference("InProcessingToShelvingCart") ) {
66
if ( C4::Context->preference("InProcessingToShelvingCart") ) {
67
    my $item = GetItem($itemnumber);
67
    my $item = Koha::Items->find($itemnumber);
68
    if ( $item->{'location'} eq 'PROC' ) {
68
    if ( $item->location eq 'PROC' ) {
69
        $item->{'location'} = 'CART';
69
        ModItem( { location => 'CART' }, $item->biblionumber, $item->itemnumber );
70
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
71
    }
70
    }
72
}
71
}
73
72
74
if ( C4::Context->preference("ReturnToShelvingCart") ) {
73
if ( C4::Context->preference("ReturnToShelvingCart") ) {
75
    my $item = GetItem($itemnumber);
74
    my $item = Koha::Items->find($itemnumber);
76
    $item->{'location'} = 'CART';
75
    ModItem( { location => 'CART' }, $item->biblionumber, $item->itemnumber );
77
    ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
78
}
76
}
79
77
80
my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
78
my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
(-)a/t/db_dependent/Acquisition/CancelReceipt.t (-4 / +5 lines)
Lines 31-36 use Koha::Database; Link Here
31
use Koha::DateUtils;
31
use Koha::DateUtils;
32
use Koha::Acquisition::Booksellers;
32
use Koha::Acquisition::Booksellers;
33
use Koha::Acquisition::Orders;
33
use Koha::Acquisition::Orders;
34
use Koha::Items;
34
use MARC::Record;
35
use MARC::Record;
35
36
36
my $schema = Koha::Database->new()->schema();
37
my $schema = Koha::Database->new()->schema();
Lines 162-171 is( Link Here
162
    "Create items on ordering: items are not deleted after cancelling a receipt"
163
    "Create items on ordering: items are not deleted after cancelling a receipt"
163
);
164
);
164
165
165
my $item1 = C4::Items::GetItem( $itemnumber1 );
166
my $item1 = Koha::Items->find( $itemnumber1 );
166
is( $item1->{notforloan}, 9, "The notforloan value has been updated with '9'" );
167
is( $item1->notforloan, 9, "The notforloan value has been updated with '9'" );
167
168
168
my $item2 = C4::Items::GetItem( $itemnumber2 );
169
my $item2 = Koha::Items->find( $itemnumber2 );
169
is( $item2->{notforloan}, 0, "The notforloan value has been updated with '9'" );
170
is( $item2->notforloan, 0, "The notforloan value has been updated with '9'" );
170
171
171
$schema->storage->txn_rollback();
172
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Circulation.t (-1 / +2 lines)
Lines 38-43 use C4::Overdues qw(UpdateFine CalcFine); Link Here
38
use Koha::DateUtils;
38
use Koha::DateUtils;
39
use Koha::Database;
39
use Koha::Database;
40
use Koha::IssuingRules;
40
use Koha::IssuingRules;
41
use Koha::Items;
41
use Koha::Checkouts;
42
use Koha::Checkouts;
42
use Koha::Patrons;
43
use Koha::Patrons;
43
use Koha::Subscriptions;
44
use Koha::Subscriptions;
Lines 454-460 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
454
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
455
    my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
455
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
456
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
456
457
457
    my ( $fine ) = CalcFine( GetItem(undef, $item_7->barcode), $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
458
    my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
458
    C4::Overdues::UpdateFine(
459
    C4::Overdues::UpdateFine(
459
        {
460
        {
460
            issue_id       => $passeddatedue1->id(),
461
            issue_id       => $passeddatedue1->id(),
(-)a/t/db_dependent/Circulation/IsItemIssued.t (+1 lines)
Lines 25-30 use C4::Items; Link Here
25
use C4::Biblio;
25
use C4::Biblio;
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::DateUtils;
27
use Koha::DateUtils;
28
use Koha::Items;
28
use Koha::Patrons;
29
use Koha::Patrons;
29
30
30
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
(-)a/t/db_dependent/Circulation/Returns.t (-6 / +5 lines)
Lines 87-103 subtest "InProcessingToShelvingCart tests" => sub { Link Here
87
87
88
    t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 1 );
88
    t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 1 );
89
    AddReturn( $barcode, $branch );
89
    AddReturn( $barcode, $branch );
90
    $item = GetItem( $itemnumber );
90
    $item = Koha::Items->find( $itemnumber );
91
    is( $item->{location}, 'CART',
91
    is( $item->location, 'CART',
92
        "InProcessingToShelvingCart functions as intended" );
92
        "InProcessingToShelvingCart functions as intended" );
93
93
94
    $item->{location} = $location;
94
    ModItem( {location => $location}, undef, $itemnumber );
95
    ModItem( $item, undef, $itemnumber );
96
95
97
    t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 0 );
96
    t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 0 );
98
    AddReturn( $barcode, $branch );
97
    AddReturn( $barcode, $branch );
99
    $item = GetItem( $itemnumber );
98
    $item = Koha::Items->find( $itemnumber );
100
    is( $item->{location}, $permanent_location,
99
    is( $item->location, $permanent_location,
101
        "InProcessingToShelvingCart functions as intended" );
100
        "InProcessingToShelvingCart functions as intended" );
102
};
101
};
103
102
(-)a/t/db_dependent/Circulation/issue.t (-6 / +7 lines)
Lines 32-37 use Koha::Checkouts; Link Here
32
use Koha::Database;
32
use Koha::Database;
33
use Koha::DateUtils;
33
use Koha::DateUtils;
34
use Koha::Holds;
34
use Koha::Holds;
35
use Koha::Items;
35
use Koha::Library;
36
use Koha::Library;
36
use Koha::Patrons;
37
use Koha::Patrons;
37
38
Lines 349-365 my $itemnumber; Link Here
349
350
350
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
351
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
351
AddReturn( 'barcode_3', $branchcode_1 );
352
AddReturn( 'barcode_3', $branchcode_1 );
352
my $item = GetItem( $itemnumber );
353
my $item = Koha::Items->find( $itemnumber );
353
ok( $item->{notforloan} eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' );
354
ok( $item->notforloan eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' );
354
355
355
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', '1: 9' );
356
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', '1: 9' );
356
AddReturn( 'barcode_3', $branchcode_1 );
357
AddReturn( 'barcode_3', $branchcode_1 );
357
$item = GetItem( $itemnumber );
358
$item = Koha::Items->find( $itemnumber );
358
ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} );
359
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} );
359
360
360
AddReturn( 'barcode_3', $branchcode_1 );
361
AddReturn( 'barcode_3', $branchcode_1 );
361
$item = GetItem( $itemnumber );
362
$item = Koha::Items->find( $itemnumber );
362
ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
363
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
363
364
364
# Bug 14640 - Cancel the hold on checking out if asked
365
# Bug 14640 - Cancel the hold on checking out if asked
365
my $reserve_id = AddReserve($branchcode_1, $borrower_id1, $biblionumber,
366
my $reserve_id = AddReserve($branchcode_1, $borrower_id1, $biblionumber,
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-6 / +9 lines)
Lines 6-11 use C4::Context; Link Here
6
use C4::Circulation;
6
use C4::Circulation;
7
use C4::Items;
7
use C4::Items;
8
use Koha::IssuingRule;
8
use Koha::IssuingRule;
9
use Koha::Items;
9
10
10
use Test::More tests => 6;
11
use Test::More tests => 6;
11
12
Lines 77-83 my $itemnumber1 = Link Here
77
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
78
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
78
  or BAIL_OUT("Cannot find newly created item");
79
  or BAIL_OUT("Cannot find newly created item");
79
80
80
my $item1 = GetItem( $itemnumber1 );
81
my $item1 = Koha::Items->find( $itemnumber1 )->unblessed;
81
82
82
$dbh->do("
83
$dbh->do("
83
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
84
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
Lines 88-94 my $itemnumber2 = Link Here
88
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC")
89
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC")
89
  or BAIL_OUT("Cannot find newly created item");
90
  or BAIL_OUT("Cannot find newly created item");
90
91
91
my $item2 = GetItem( $itemnumber2 );
92
my $item2 = Koha::Items->find( $itemnumber2 )->unblessed;
92
93
93
$dbh->do("DELETE FROM issuingrules");
94
$dbh->do("DELETE FROM issuingrules");
94
my $rule = Koha::IssuingRule->new(
95
my $rule = Koha::IssuingRule->new(
Lines 132-139 AddReturn( $item1->{barcode} ); Link Here
132
        subtest 'Item is available at a different library' => sub {
133
        subtest 'Item is available at a different library' => sub {
133
            plan tests => 4;
134
            plan tests => 4;
134
135
135
            Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_B, holdingbranch => $library_B })->store;
136
            $item1 = Koha::Items->find( $item1->{itemnumber} );
136
            $item1 = GetItem( $itemnumber1 );
137
            $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store;
138
            $item1 = $item1->unblessed;
137
            #Scenario is:
139
            #Scenario is:
138
            #One shelf holds is 'If all unavailable'/2
140
            #One shelf holds is 'If all unavailable'/2
139
            #Item 1 homebranch library B is available
141
            #Item 1 homebranch library B is available
Lines 172-179 AddReturn( $item1->{barcode} ); Link Here
172
        subtest 'Item is available at the same library' => sub {
174
        subtest 'Item is available at the same library' => sub {
173
            plan tests => 4;
175
            plan tests => 4;
174
176
175
            Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_A, holdingbranch => $library_A })->store;
177
            $item1 = Koha::Items->find( $item1->{itemnumber} );
176
            $item1 = GetItem( $itemnumber1 );
178
            $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store;
179
            $item1 = $item1->unblessed;
177
            #Scenario is:
180
            #Scenario is:
178
            #One shelf holds is 'If all unavailable'/2
181
            #One shelf holds is 'If all unavailable'/2
179
            #Item 1 homebranch library A is available
182
            #Item 1 homebranch library A is available
(-)a/t/db_dependent/Items.t (-34 / +34 lines)
Lines 64-74 subtest 'General Add, Get and Del tests' => sub { Link Here
64
    cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
64
    cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
65
65
66
    # Get item.
66
    # Get item.
67
    my $getitem = GetItem($itemnumber);
67
    my $getitem = Koha::Items->find($itemnumber);
68
    cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber.");
68
    cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber.");
69
    cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber.");
69
    cmp_ok($getitem->biblioitemnumber, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber.");
70
    is( $getitem->{location}, $location, "The location should not have been modified" );
70
    is( $getitem->location, $location, "The location should not have been modified" );
71
    is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to the location value" );
71
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" );
72
72
73
73
74
    # Do not modify anything, and do not explode!
74
    # Do not modify anything, and do not explode!
Lines 78-112 subtest 'General Add, Get and Del tests' => sub { Link Here
78
78
79
    # Modify item; setting barcode.
79
    # Modify item; setting barcode.
80
    ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber);
80
    ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber);
81
    my $moditem = GetItem($itemnumber);
81
    my $moditem = Koha::Items->find($itemnumber);
82
    cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
82
    cmp_ok($moditem->barcode, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->barcode . '.');
83
83
84
    # Delete item.
84
    # Delete item.
85
    DelItem({ biblionumber => $biblio->biblionumber, itemnumber => $itemnumber });
85
    DelItem({ biblionumber => $biblio->biblionumber, itemnumber => $itemnumber });
86
    my $getdeleted = GetItem($itemnumber);
86
    my $getdeleted = Koha::Items->find($itemnumber);
87
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
87
    is($getdeleted, undef, "Item deleted as expected.");
88
88
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
90
    $getitem = GetItem($itemnumber);
90
    $getitem = Koha::Items->find($itemnumber);
91
    is( $getitem->{location}, $location, "The location should not have been modified" );
91
    is( $getitem->location, $location, "The location should not have been modified" );
92
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
92
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
93
93
94
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
94
    ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
95
    $getitem = GetItem($itemnumber);
95
    $getitem = Koha::Items->find($itemnumber);
96
    is( $getitem->{location}, $location, "The location should have been set to correct location" );
96
    is( $getitem->location, $location, "The location should have been set to correct location" );
97
    is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
97
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to location" );
98
98
99
    ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber);
99
    ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber);
100
    $getitem = GetItem($itemnumber);
100
    $getitem = Koha::Items->find($itemnumber);
101
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
101
    is( $getitem->location, 'CART', "The location should have been set to CART" );
102
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
102
    is( $getitem->permanent_location, $location, "The permanent_location should not have been set to CART" );
103
103
104
    t::lib::Mocks::mock_preference('item-level_itypes', '1');
104
    t::lib::Mocks::mock_preference('item-level_itypes', '1');
105
    $getitem = GetItem($itemnumber);
105
    $getitem = Koha::Items->find($itemnumber);
106
    is( $getitem->{itype}, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" );
106
    is( $getitem->effective_itemtype, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" );
107
    t::lib::Mocks::mock_preference('item-level_itypes', '0');
107
    t::lib::Mocks::mock_preference('item-level_itypes', '0');
108
    $getitem = GetItem($itemnumber);
108
    $getitem = Koha::Items->find($itemnumber);
109
    is( $getitem->{itype}, $biblio->biblioitem->itemtype, "Itemtype set correctly when not using item-level_itypes" );
109
    is( $getitem->effective_itemtype, $biblio->biblioitem->itemtype, "Itemtype set correctly when not using item-level_itypes" );
110
110
111
    $schema->storage->txn_rollback;
111
    $schema->storage->txn_rollback;
112
};
112
};
Lines 194-201 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
194
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
194
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
195
    my @hidden;
195
    my @hidden;
196
    my @items;
196
    my @items;
197
    push @items, GetItem( $item1_itemnumber );
197
    push @items, Koha::Items->find( $item1_itemnumber )->unblessed;
198
    push @items, GetItem( $item2_itemnumber );
198
    push @items, Koha::Items->find( $item2_itemnumber )->unblessed;
199
199
200
    # Empty OpacHiddenItems
200
    # Empty OpacHiddenItems
201
    t::lib::Mocks::mock_preference('OpacHiddenItems','');
201
    t::lib::Mocks::mock_preference('OpacHiddenItems','');
Lines 502-509 subtest 'SearchItems test' => sub { Link Here
502
    ModItemFromMarc($item3_record, $biblio->biblionumber, $item3_itemnumber);
502
    ModItemFromMarc($item3_record, $biblio->biblionumber, $item3_itemnumber);
503
503
504
    # Make sure the link is used
504
    # Make sure the link is used
505
    my $item3 = GetItem($item3_itemnumber);
505
    my $item3 = Koha::Items->find($item3_itemnumber);
506
    ok($item3->{itemnotes} eq 'foobar', 'itemnotes eq "foobar"');
506
    ok($item3->itemnotes eq 'foobar', 'itemnotes eq "foobar"');
507
507
508
    # Do the same search again.
508
    # Do the same search again.
509
    # This time it will search in items.itemnotes
509
    # This time it will search in items.itemnotes
Lines 719-739 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
719
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblio->biblionumber);
719
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblio->biblionumber);
720
720
721
    # Make sure everything has been set up
721
    # Make sure everything has been set up
722
    my $item = GetItem($item_itemnumber);
722
    my $item = Koha::Items->find($item_itemnumber);
723
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
723
    is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
724
724
725
    # Delete the barcode field and save the record
725
    # Delete the barcode field and save the record
726
    $item_record->delete_fields( $barcode_field );
726
    $item_record->delete_fields( $barcode_field );
727
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
727
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
728
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
728
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
729
    $item = GetItem($item_itemnumber);
729
    $item = Koha::Items->find($item_itemnumber);
730
    is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
730
    is( $item->barcode, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
731
731
732
    # Re-add the barcode field and save the record
732
    # Re-add the barcode field and save the record
733
    $item_record->append_fields( $barcode_field );
733
    $item_record->append_fields( $barcode_field );
734
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
734
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
735
    $item = GetItem($item_itemnumber);
735
    $item = Koha::Items->find($item_itemnumber);
736
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
736
    is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
737
737
738
    # Remove the mapping for barcode
738
    # Remove the mapping for barcode
739
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
739
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
Lines 753-760 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
753
    $item_record->append_fields( $another_barcode_field );
753
    $item_record->append_fields( $another_barcode_field );
754
    # The DB value should not have been updated
754
    # The DB value should not have been updated
755
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
755
    ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
756
    $item = GetItem($item_itemnumber);
756
    $item = Koha::Items->find($item_itemnumber);
757
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
757
    is ( $item->barcode, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
758
758
759
    $cache->clear_from_cache("default_value_for_mod_marc-");
759
    $cache->clear_from_cache("default_value_for_mod_marc-");
760
    $cache->clear_from_cache( "MarcSubfieldStructure-" );
760
    $cache->clear_from_cache( "MarcSubfieldStructure-" );
(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-26 / +25 lines)
Lines 11-16 use C4::Items; Link Here
11
use C4::Biblio;
11
use C4::Biblio;
12
use C4::Context;
12
use C4::Context;
13
use Koha::DateUtils;
13
use Koha::DateUtils;
14
use Koha::Items;
14
use t::lib::TestBuilder;
15
use t::lib::TestBuilder;
15
16
16
my $schema = Koha::Database->new->schema;
17
my $schema = Koha::Database->new->schema;
Lines 61-68 my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem( Link Here
61
    $biblionumber
62
    $biblionumber
62
);
63
);
63
64
64
my $item = C4::Items::GetItem( $itemnumber );
65
my $item = Koha::Items->find( $itemnumber );
65
is ( $item->{new_status}, 'new_value', q|AddItem insert the 'new_status' field| );
66
is ( $item->new_status, 'new_value', q|AddItem insert the 'new_status' field| );
66
67
67
my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', $frameworkcode);
68
my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', $frameworkcode);
68
my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
69
my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
Lines 89-96 my @rules = ( Link Here
89
90
90
C4::Items::ToggleNewStatus( { rules => \@rules } );
91
C4::Items::ToggleNewStatus( { rules => \@rules } );
91
92
92
my $modified_item = C4::Items::GetItem( $itemnumber );
93
my $modified_item = Koha::Items->find( $itemnumber );
93
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is updated|);
94
is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: The new_status value is updated|);
94
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
95
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
95
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is updated| );
96
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is updated| );
96
97
Lines 115-132 is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew Link Here
115
116
116
C4::Items::ToggleNewStatus( { rules => \@rules } );
117
C4::Items::ToggleNewStatus( { rules => \@rules } );
117
118
118
$modified_item = C4::Items::GetItem( $itemnumber );
119
$modified_item = Koha::Items->find( $itemnumber );
119
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|);
120
is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|);
120
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
121
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
121
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is not updated| );
122
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is not updated| );
122
123
123
# Play with age
124
# Play with age
124
$item = C4::Items::GetItem( $itemnumber );
125
my $dt_today = dt_from_string;
125
my $dt_today = dt_from_string;
126
my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) );
126
my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) );
127
127
128
C4::Items::ModItem( { dateaccessioned => $days5ago }, $biblionumber, $itemnumber );
128
C4::Items::ModItem( { dateaccessioned => $days5ago }, $biblionumber, $itemnumber );
129
$item = C4::Items::GetItem( $itemnumber );
130
129
131
@rules = (
130
@rules = (
132
    {
131
    {
Lines 146-171 $item = C4::Items::GetItem( $itemnumber ); Link Here
146
    },
145
    },
147
);
146
);
148
C4::Items::ToggleNewStatus( { rules => \@rules } );
147
C4::Items::ToggleNewStatus( { rules => \@rules } );
149
$modified_item = C4::Items::GetItem( $itemnumber );
148
$modified_item = Koha::Items->find( $itemnumber );
150
is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|);
149
is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|);
151
150
152
$rules[0]->{age} = 5;
151
$rules[0]->{age} = 5;
153
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5';
152
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5';
154
C4::Items::ToggleNewStatus( { rules => \@rules } );
153
C4::Items::ToggleNewStatus( { rules => \@rules } );
155
$modified_item = C4::Items::GetItem( $itemnumber );
154
$modified_item = Koha::Items->find( $itemnumber );
156
is( $modified_item->{new_status}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|);
155
is( $modified_item->new_status, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|);
157
156
158
$rules[0]->{age} = '';
157
$rules[0]->{age} = '';
159
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string';
158
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string';
160
C4::Items::ToggleNewStatus( { rules => \@rules } );
159
C4::Items::ToggleNewStatus( { rules => \@rules } );
161
$modified_item = C4::Items::GetItem( $itemnumber );
160
$modified_item = Koha::Items->find( $itemnumber );
162
is( $modified_item->{new_status}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|);
161
is( $modified_item->new_status, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|);
163
162
164
$rules[0]->{age} = undef;
163
$rules[0]->{age} = undef;
165
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef';
164
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef';
166
C4::Items::ToggleNewStatus( { rules => \@rules } );
165
C4::Items::ToggleNewStatus( { rules => \@rules } );
167
$modified_item = C4::Items::GetItem( $itemnumber );
166
$modified_item = Koha::Items->find( $itemnumber );
168
is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|);
167
is( $modified_item->new_status, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|);
169
168
170
# Field deletion
169
# Field deletion
171
@rules = (
170
@rules = (
Lines 188-195 is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: Link Here
188
187
189
C4::Items::ToggleNewStatus( { rules => \@rules } );
188
C4::Items::ToggleNewStatus( { rules => \@rules } );
190
189
191
$modified_item = C4::Items::GetItem( $itemnumber );
190
$modified_item = Koha::Items->find( $itemnumber );
192
is( $modified_item->{new_status}, '', q|ToggleNewStatus: The new_status value is empty|);
191
is( $modified_item->new_status, '', q|ToggleNewStatus: The new_status value is empty|);
193
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
192
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
194
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new_status field is removed from the item marc| );
193
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new_status field is removed from the item marc| );
195
194
Lines 218-225 is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th Link Here
218
217
219
C4::Items::ToggleNewStatus( { rules => \@rules } );
218
C4::Items::ToggleNewStatus( { rules => \@rules } );
220
219
221
$modified_item = C4::Items::GetItem( $itemnumber );
220
$modified_item = Koha::Items->find( $itemnumber );
222
is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|);
221
is( $modified_item->new_status, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|);
223
222
224
@rules = (
223
@rules = (
225
    {
224
    {
Lines 245-252 is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions mul Link Here
245
244
246
C4::Items::ToggleNewStatus( { rules => \@rules } );
245
C4::Items::ToggleNewStatus( { rules => \@rules } );
247
246
248
$modified_item = C4::Items::GetItem( $itemnumber );
247
$modified_item = Koha::Items->find( $itemnumber );
249
is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new_status value is not updated|);
248
is( $modified_item->new_status, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new_status value is not updated|);
250
249
251
@rules = (
250
@rules = (
252
    {
251
    {
Lines 272-279 is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions mul Link Here
272
271
273
C4::Items::ToggleNewStatus( { rules => \@rules } );
272
C4::Items::ToggleNewStatus( { rules => \@rules } );
274
273
275
$modified_item = C4::Items::GetItem( $itemnumber );
274
$modified_item = Koha::Items->find( $itemnumber );
276
is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|);
275
is( $modified_item->new_status, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|);
277
276
278
@rules = (
277
@rules = (
279
    {
278
    {
Lines 295-302 is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: condit Link Here
295
294
296
C4::Items::ToggleNewStatus( { rules => \@rules } );
295
C4::Items::ToggleNewStatus( { rules => \@rules } );
297
296
298
$modified_item = C4::Items::GetItem( $itemnumber );
297
$modified_item = Koha::Items->find( $itemnumber );
299
is( $modified_item->{new_status}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
298
is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
300
299
301
# Clear cache
300
# Clear cache
302
$cache = Koha::Caches->get_instance();
301
$cache = Koha::Caches->get_instance();
(-)a/t/db_dependent/Items/DelItem.t (-4 / +6 lines)
Lines 4-9 use MARC::Record; Link Here
4
use C4::Items;
4
use C4::Items;
5
use C4::Biblio;
5
use C4::Biblio;
6
6
7
use Koha::Items;
8
7
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
8
10
9
use Test::More tests => 6;
11
use Test::More tests => 6;
Lines 24-38 my ( $item_bibnum, $item_bibitemnum, $itemnumber ); Link Here
24
26
25
my $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
27
my $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
26
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
28
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
27
my $deleted_item = GetItem($itemnumber);
29
my $deleted_item = Koha::Items->find($itemnumber);
28
is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." );
30
is( $deleted_item, undef, "DelItem with biblionumber parameter - the item should be deleted." );
29
31
30
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
32
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
31
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber );
33
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber );
32
$deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
34
$deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
33
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
35
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
34
$deleted_item = GetItem($itemnumber);
36
$deleted_item = Koha::Items->find($itemnumber);
35
is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." );
37
is( $deleted_item, undef, "DelItem without biblionumber parameter - the item should be deleted." );
36
38
37
$deleted = DelItem( { itemnumber => $itemnumber + 1} );
39
$deleted = DelItem( { itemnumber => $itemnumber + 1} );
38
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
40
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
(-)a/t/db_dependent/Items/MoveItemFromBiblio.t (-6 / +7 lines)
Lines 22-27 use C4::Items; Link Here
22
use C4::Reserves;
22
use C4::Reserves;
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::Holds;
24
use Koha::Holds;
25
use Koha::Items;
25
26
26
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
27
use Data::Dumper qw|Dumper|;
28
use Data::Dumper qw|Dumper|;
Lines 79-90 $to_biblionumber_after_moved = C4::Items::MoveItemFromBiblio( $item2->{itemnumbe Link Here
79
80
80
is( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' );
81
is( $to_biblionumber_after_moved, undef, 'MoveItemFromBiblio should return undef if the move has failed. If called twice, the item is not attached to the first biblio anymore' );
81
82
82
my $get_item1 = C4::Items::GetItem( $item1->{itemnumber} );
83
my $get_item1 = Koha::Items->find( $item1->{itemnumber} );
83
is( $get_item1->{biblionumber}, $from_biblio->{biblionumber}, 'The item1 should not have been moved' );
84
is( $get_item1->biblionumber, $from_biblio->{biblionumber}, 'The item1 should not have been moved' );
84
my $get_item2 = C4::Items::GetItem( $item2->{itemnumber} );
85
my $get_item2 = Koha::Items->find( $item2->{itemnumber} );
85
is( $get_item2->{biblionumber}, $to_biblio->{biblionumber}, 'The item2 should have been moved' );
86
is( $get_item2->biblionumber, $to_biblio->{biblionumber}, 'The item2 should have been moved' );
86
my $get_item3 = C4::Items::GetItem( $item3->{itemnumber} );
87
my $get_item3 = Koha::Items->find( $item3->{itemnumber} );
87
is( $get_item3->{biblionumber}, $to_biblio->{biblionumber}, 'The item3 should not have been moved' );
88
is( $get_item3->biblionumber, $to_biblio->{biblionumber}, 'The item3 should not have been moved' );
88
89
89
my $get_bib_level_hold    = Koha::Holds->find( $bib_level_hold_not_to_move->{reserve_id} );
90
my $get_bib_level_hold    = Koha::Holds->find( $bib_level_hold_not_to_move->{reserve_id} );
90
my $get_item_level_hold_1 = Koha::Holds->find( $item_level_hold_not_to_move->{reserve_id} );
91
my $get_item_level_hold_1 = Koha::Holds->find( $item_level_hold_not_to_move->{reserve_id} );
(-)a/t/db_dependent/Items_DelItemCheck.t (-2 / +3 lines)
Lines 19-24 use Modern::Perl; Link Here
19
19
20
use C4::Circulation;
20
use C4::Circulation;
21
use Koha::Database;
21
use Koha::Database;
22
use Koha::Items;
22
23
23
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 159-167 is( Link Here
159
160
160
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} );
161
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} );
161
162
162
my $test_item = GetItem( $item->{itemnumber} );
163
my $test_item = Koha::Items->find( $item->{itemnumber} );
163
164
164
is( $test_item->{itemnumber}, undef,
165
is( $test_item, undef,
165
    "DelItemCheck should delete item if ItemSafeToDelete returns true"
166
    "DelItemCheck should delete item if ItemSafeToDelete returns true"
166
);
167
);
167
168
(-)a/t/db_dependent/Reserves.t (-1 / +2 lines)
Lines 35-40 use C4::Reserves; Link Here
35
use Koha::Caches;
35
use Koha::Caches;
36
use Koha::DateUtils;
36
use Koha::DateUtils;
37
use Koha::Holds;
37
use Koha::Holds;
38
use Koha::Items;
38
use Koha::Libraries;
39
use Koha::Libraries;
39
use Koha::Notice::Templates;
40
use Koha::Notice::Templates;
40
use Koha::Patrons;
41
use Koha::Patrons;
Lines 521-527 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblio_with_no_item->{bibl Link Here
521
####### EO Bug 13113 <<<
522
####### EO Bug 13113 <<<
522
       ####
523
       ####
523
524
524
$item = GetItem($itemnumber);
525
$item = Koha::Items->find($itemnumber)->unblessed;
525
526
526
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
527
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
527
528
(-)a/tools/batchMod.pl (-2 / +6 lines)
Lines 176-182 if ($op eq "action") { Link Here
176
	foreach my $itemnumber(@itemnumbers){
176
	foreach my $itemnumber(@itemnumbers){
177
177
178
		$job->progress($i) if $runinbackground;
178
		$job->progress($i) if $runinbackground;
179
		my $itemdata = GetItem($itemnumber);
179
        my $itemdata = Koha::Items->find($itemnumber);
180
        next unless $itemdata; # Should have been tested earlier, but just in case...
181
        $itemdata = $itemdata->unblessed;
180
        if ( $del ){
182
        if ( $del ){
181
            my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
183
            my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
182
			if ($return == 1) {
184
			if ($return == 1) {
Lines 530-536 sub BuildItemsData{ Link Here
530
		my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
532
		my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
531
		my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
533
		my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
532
		foreach my $itemnumber (@itemnumbers){
534
		foreach my $itemnumber (@itemnumbers){
533
			my $itemdata=GetItem($itemnumber);
535
            my $itemdata = Koha::Items->find($itemnumber);
536
            next unless $itemdata; # Should have been tested earlier, but just in case...
537
            $itemdata = $itemdata->unblessed;
534
			my $itemmarc=Item2Marc($itemdata);
538
			my $itemmarc=Item2Marc($itemdata);
535
			my %this_row;
539
			my %this_row;
536
			foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
540
			foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
(-)a/tools/inventory.pl (-2 / +4 lines)
Lines 40-45 use Koha::DateUtils; Link Here
40
use Koha::AuthorisedValues;
40
use Koha::AuthorisedValues;
41
use Koha::BiblioFrameworks;
41
use Koha::BiblioFrameworks;
42
use Koha::ClassSources;
42
use Koha::ClassSources;
43
use Koha::Items;
43
use List::MoreUtils qw( none );
44
use List::MoreUtils qw( none );
44
45
45
my $minlocation=$input->param('minlocation') || '';
46
my $minlocation=$input->param('minlocation') || '';
Lines 195-202 if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { Link Here
195
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
196
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
196
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
197
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
197
        } else {
198
        } else {
198
            my $item = GetItem( '', $barcode );
199
            my $item = Koha::Items->find({barcode => $barcode});
199
            if ( defined $item && $item->{'itemnumber'} ) {
200
            if ( $item ) {
201
                $item = $item->unblessed;
200
                # Modify date last seen for scanned items, remove lost status
202
                # Modify date last seen for scanned items, remove lost status
201
                ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
203
                ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
202
                $moddatecount++;
204
                $moddatecount++;
(-)a/tools/viewlog.pl (-4 / +6 lines)
Lines 31-36 use C4::Items; Link Here
31
use C4::Serials;
31
use C4::Serials;
32
use C4::Debug;
32
use C4::Debug;
33
use C4::Search;    # enabled_staff_search_views
33
use C4::Search;    # enabled_staff_search_views
34
35
use Koha::Items;
34
use Koha::Patrons;
36
use Koha::Patrons;
35
37
36
use vars qw($debug $cgi_debug);
38
use vars qw($debug $cgi_debug);
Lines 120-130 if ($do_it) { Link Here
120
            # get item information so we can create a working link
122
            # get item information so we can create a working link
121
            my $itemnumber = $result->{'object'};
123
            my $itemnumber = $result->{'object'};
122
            $itemnumber = $result->{'info'} if ( $result->{module} eq "CIRCULATION" );
124
            $itemnumber = $result->{'info'} if ( $result->{module} eq "CIRCULATION" );
123
            my $item = GetItem($itemnumber);
125
            my $item = Koha::Items->find($itemnumber);
124
            if ($item) {
126
            if ($item) {
125
                $result->{'biblionumber'}     = $item->{'biblionumber'};
127
                $result->{'biblionumber'}     = $item->biblionumber;
126
                $result->{'biblioitemnumber'} = $item->{'biblionumber'};
128
                $result->{'biblioitemnumber'} = $item->biblionumber;
127
                $result->{'barcode'}          = $item->{'barcode'};
129
                $result->{'barcode'}          = $item->barcode;
128
            }
130
            }
129
        }
131
        }
130
132
(-)a/virtualshelves/shelves.pl (-4 / +4 lines)
Lines 29-34 use C4::XSLT; Link Here
29
29
30
use Koha::Biblios;
30
use Koha::Biblios;
31
use Koha::Biblioitems;
31
use Koha::Biblioitems;
32
use Koha::Items;
32
use Koha::ItemTypes;
33
use Koha::ItemTypes;
33
use Koha::CsvProfiles;
34
use Koha::CsvProfiles;
34
use Koha::Patrons;
35
use Koha::Patrons;
Lines 151-159 if ( $op eq 'add_form' ) { Link Here
151
                foreach my $barcode (@barcodes){
152
                foreach my $barcode (@barcodes){
152
                    $barcode =~ s/\r$//; # strip any naughty return chars
153
                    $barcode =~ s/\r$//; # strip any naughty return chars
153
                    next if $barcode eq '';
154
                    next if $barcode eq '';
154
                    my $item = GetItem( 0, $barcode);
155
                    my $item = Koha::Items->find({barcode => $barcode});
155
                    if (defined $item && $item->{itemnumber}) {
156
                    if ( $item ) {
156
                        my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); };
157
                        my $added = eval { $shelf->add_biblio( $item->biblionumber, $loggedinuser ); };
157
                        if ($@) {
158
                        if ($@) {
158
                            push @messages, { item_barcode => $barcode, type => 'alert', code => ref($@), msg => $@ };
159
                            push @messages, { item_barcode => $barcode, type => 'alert', code => ref($@), msg => $@ };
159
                        } elsif ( $added ) {
160
                        } elsif ( $added ) {
160
- 

Return to bug 21206