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

(-)a/C4/Biblio.pm (-6 / +9 lines)
Lines 2194-2203 sub PrepHostMarcField { Link Here
2194
    my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
2194
    my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
2195
    $marcflavour ||="MARC21";
2195
    $marcflavour ||="MARC21";
2196
    
2196
    
2197
    require C4::Items;
2198
    my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
2197
    my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
2199
	my $item = C4::Items::GetItem($hostitemnumber);
2198
    my $item = Koha::Items->find($hostitemnumber);
2200
	
2199
2201
	my $hostmarcfield;
2200
	my $hostmarcfield;
2202
    if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
2201
    if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
2203
	
2202
	
Lines 2220-2226 sub PrepHostMarcField { Link Here
2220
2219
2221
    	#other fields
2220
    	#other fields
2222
        my $ed = $hostrecord->subfield('250','a');
2221
        my $ed = $hostrecord->subfield('250','a');
2223
        my $barcode = $item->{'barcode'};
2222
        my $barcode = $item->barcode;
2224
        my $title = $hostrecord->subfield('245','a');
2223
        my $title = $hostrecord->subfield('245','a');
2225
2224
2226
        # record control number, 001 with 003 and prefix
2225
        # record control number, 001 with 003 and prefix
Lines 2823-2830 sub EmbedItemsInMarcBiblio { Link Here
2823
    require C4::Items;
2822
    require C4::Items;
2824
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2823
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2825
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2824
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2826
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2825
        my $item;
2827
        push @items, { itemnumber => $itemnumber, item => $i };
2826
        if ( $opachiddenitems ) {
2827
            $item = Koha::Items->find($itemnumber);
2828
            $item = $item ? $item->unblessed : undef;
2829
        }
2830
        push @items, { itemnumber => $itemnumber, item => $item };
2828
    }
2831
    }
2829
    my @items2pass = map { $_->{item} } @items;
2832
    my @items2pass = map { $_->{item} } @items;
2830
    my @hiddenitems =
2833
    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 1912-1918 sub AddReturn { Link Here
1912
            # don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
1914
            # don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
1913
            # FIXME: check issuedate > returndate, factoring in holidays
1915
            # FIXME: check issuedate > returndate, factoring in holidays
1914
1916
1915
            $circControlBranch = _GetCircControlBranch($item,$patron_unblessed);
1917
            $circControlBranch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
1916
            $is_overdue = $issue->is_overdue( $dropboxdate );
1918
            $is_overdue = $issue->is_overdue( $dropboxdate );
1917
        } else {
1919
        } else {
1918
            $is_overdue = $issue->is_overdue;
1920
            $is_overdue = $issue->is_overdue;
Lines 1920-1931 sub AddReturn { Link Here
1920
1922
1921
        if ($patron) {
1923
        if ($patron) {
1922
            eval {
1924
            eval {
1923
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1925
                MarkIssueReturned( $borrowernumber, $item->itemnumber,
1924
                    $circControlBranch, $return_date, $patron->privacy );
1926
                    $circControlBranch, $return_date, $patron->privacy );
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 2631-2637 sub CanBookBeRenewed { Link Here
2631
    my $dbh    = C4::Context->dbh;
2634
    my $dbh    = C4::Context->dbh;
2632
    my $renews = 1;
2635
    my $renews = 1;
2633
2636
2634
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2637
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2635
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2638
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2636
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2639
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2637
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
2640
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
Lines 2689-2695 sub CanBookBeRenewed { Link Here
2689
            my @reservable;
2692
            my @reservable;
2690
            my %borrowers;
2693
            my %borrowers;
2691
            ITEM: foreach my $i (@itemnumbers) {
2694
            ITEM: foreach my $i (@itemnumbers) {
2692
                my $item = GetItem($i);
2695
                my $item = Koha::Items->find($i)->unblessed;
2693
                next if IsItemOnHoldAndFound($i);
2696
                next if IsItemOnHoldAndFound($i);
2694
                for my $b (@borrowernumbers) {
2697
                for my $b (@borrowernumbers) {
2695
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
2698
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
Lines 2710-2719 sub CanBookBeRenewed { Link Here
2710
2713
2711
    return ( 1, undef ) if $override_limit;
2714
    return ( 1, undef ) if $override_limit;
2712
2715
2713
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
2716
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2714
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2717
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2715
        {   categorycode => $patron->categorycode,
2718
        {   categorycode => $patron->categorycode,
2716
            itemtype     => $item->{itype},
2719
            itemtype     => $item->effective_itemtype,
2717
            branchcode   => $branchcode
2720
            branchcode   => $branchcode
2718
        }
2721
        }
2719
    );
2722
    );
Lines 2837-2851 sub AddRenewal { Link Here
2837
    my $datedue         = shift;
2840
    my $datedue         = shift;
2838
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2841
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2839
2842
2840
    my $item   = GetItem($itemnumber) or return;
2843
    my $item   = Koha::Items->find($itemnumber) or return;
2841
    my $item_object = Koha::Items->find( $itemnumber ); # Should replace $item
2844
    my $biblio = $item->biblio;
2842
    my $biblio = $item_object->biblio;
2845
    my $issue  = $item->checkout;
2846
    my $item_unblessed = $item->unblessed;
2843
2847
2844
    my $dbh = C4::Context->dbh;
2848
    my $dbh = C4::Context->dbh;
2845
2849
2846
    # Find the issues record for this book
2847
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
2848
2849
    return unless $issue;
2850
    return unless $issue;
2850
2851
2851
    $borrowernumber ||= $issue->borrowernumber;
2852
    $borrowernumber ||= $issue->borrowernumber;
Lines 2859-2865 sub AddRenewal { Link Here
2859
    my $patron_unblessed = $patron->unblessed;
2860
    my $patron_unblessed = $patron->unblessed;
2860
2861
2861
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2862
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2862
        _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
2863
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2863
    }
2864
    }
2864
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2865
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2865
2866
Lines 2868-2878 sub AddRenewal { Link Here
2868
    # based on the value of the RenewalPeriodBase syspref.
2869
    # based on the value of the RenewalPeriodBase syspref.
2869
    unless ($datedue) {
2870
    unless ($datedue) {
2870
2871
2871
        my $itemtype = $item_object->effective_itemtype;
2872
        my $itemtype = $item->effective_itemtype;
2872
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2873
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2873
                                        dt_from_string( $issue->date_due, 'sql' ) :
2874
                                        dt_from_string( $issue->date_due, 'sql' ) :
2874
                                        DateTime->now( time_zone => C4::Context->tz());
2875
                                        DateTime->now( time_zone => C4::Context->tz());
2875
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2876
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item_unblessed, $patron_unblessed), $patron_unblessed, 'is a renewal');
2876
    }
2877
    }
2877
2878
2878
    # Update the issues record to have the new due date, and a new count
2879
    # Update the issues record to have the new due date, and a new count
Lines 2886-2900 sub AddRenewal { Link Here
2886
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2887
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2887
2888
2888
    # Update the renewal count on the item, and tell zebra to reindex
2889
    # Update the renewal count on the item, and tell zebra to reindex
2889
    $renews = $item->{renewals} + 1;
2890
    $renews = $item->renewals + 1;
2890
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2891
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } );
2891
2892
2892
    # Charge a new rental fee, if applicable?
2893
    # Charge a new rental fee, if applicable?
2893
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2894
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2894
    if ( $charge > 0 ) {
2895
    if ( $charge > 0 ) {
2895
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2896
        my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
2896
        my $manager_id = 0;
2897
        my $manager_id = 0;
2897
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; 
2898
        $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
2898
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2899
        my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
2899
        Koha::Account::Line->new(
2900
        Koha::Account::Line->new(
2900
            {
2901
            {
Lines 2909-2915 sub AddRenewal { Link Here
2909
                branchcode        => $branchcode,
2910
                branchcode        => $branchcode,
2910
                description       => 'Renewal of Rental Item '
2911
                description       => 'Renewal of Rental Item '
2911
                  . $biblio->title
2912
                  . $biblio->title
2912
                  . " $item->{'barcode'}",
2913
                  . " $item->barcode",
2913
            }
2914
            }
2914
        )->store();
2915
        )->store();
2915
    }
2916
    }
Lines 2920-2933 sub AddRenewal { Link Here
2920
        my %conditions        = (
2921
        my %conditions        = (
2921
            branchcode   => $branch,
2922
            branchcode   => $branch,
2922
            categorycode => $patron->categorycode,
2923
            categorycode => $patron->categorycode,
2923
            item_type    => $item->{itype},
2924
            item_type    => $item->effective_itemtype,
2924
            notification => 'CHECKOUT',
2925
            notification => 'CHECKOUT',
2925
        );
2926
        );
2926
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2927
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2927
            SendCirculationAlert(
2928
            SendCirculationAlert(
2928
                {
2929
                {
2929
                    type     => 'RENEWAL',
2930
                    type     => 'RENEWAL',
2930
                    item     => $item,
2931
                    item     => $item_unblessed,
2931
                    borrower => $patron->unblessed,
2932
                    borrower => $patron->unblessed,
2932
                    branch   => $branch,
2933
                    branch   => $branch,
2933
                }
2934
                }
Lines 2955-2964 sub AddRenewal { Link Here
2955
            type           => 'renew',
2956
            type           => 'renew',
2956
            amount         => $charge,
2957
            amount         => $charge,
2957
            itemnumber     => $itemnumber,
2958
            itemnumber     => $itemnumber,
2958
            itemtype       => $item->{itype},
2959
            itemtype       => $item->effective_itemtype,
2959
            location       => $item->{location},
2960
            location       => $item->location,
2960
            borrowernumber => $borrowernumber,
2961
            borrowernumber => $borrowernumber,
2961
            ccode          => $item->{'ccode'}
2962
            ccode          => $item->ccode,
2962
        }
2963
        }
2963
    );
2964
    );
2964
2965
Lines 2976-2982 sub GetRenewCount { Link Here
2976
    my $renewsleft    = 0;
2977
    my $renewsleft    = 0;
2977
2978
2978
    my $patron = Koha::Patrons->find( $bornum );
2979
    my $patron = Koha::Patrons->find( $bornum );
2979
    my $item     = GetItem($itemno);
2980
    my $item   = Koha::Items->find($itemno);
2980
2981
2981
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2982
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2982
2983
Lines 2993-3003 sub GetRenewCount { Link Here
2993
    my $data = $sth->fetchrow_hashref;
2994
    my $data = $sth->fetchrow_hashref;
2994
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2995
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2995
    # $item and $borrower should be calculated
2996
    # $item and $borrower should be calculated
2996
    my $branchcode = _GetCircControlBranch($item, $patron->unblessed);
2997
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
2997
2998
2998
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2999
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2999
        {   categorycode => $patron->categorycode,
3000
        {   categorycode => $patron->categorycode,
3000
            itemtype     => $item->{itype},
3001
            itemtype     => $item->effective_itemtype,
3001
            branchcode   => $branchcode
3002
            branchcode   => $branchcode
3002
        }
3003
        }
3003
    );
3004
    );
Lines 3032-3048 sub GetSoonestRenewDate { Link Here
3032
3033
3033
    my $dbh = C4::Context->dbh;
3034
    my $dbh = C4::Context->dbh;
3034
3035
3035
    my $item      = GetItem($itemnumber)      or return;
3036
    my $item      = Koha::Items->find($itemnumber)      or return;
3036
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3037
    my $itemissue = $item->checkout or return;
3037
3038
3038
    $borrowernumber ||= $itemissue->borrowernumber;
3039
    $borrowernumber ||= $itemissue->borrowernumber;
3039
    my $patron = Koha::Patrons->find( $borrowernumber )
3040
    my $patron = Koha::Patrons->find( $borrowernumber )
3040
      or return;
3041
      or return;
3041
3042
3042
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3043
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3043
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3044
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3044
        {   categorycode => $patron->categorycode,
3045
        {   categorycode => $patron->categorycode,
3045
            itemtype     => $item->{itype},
3046
            itemtype     => $item->effective_itemtype,
3046
            branchcode   => $branchcode
3047
            branchcode   => $branchcode
3047
        }
3048
        }
3048
    );
3049
    );
Lines 3091-3107 sub GetLatestAutoRenewDate { Link Here
3091
3092
3092
    my $dbh = C4::Context->dbh;
3093
    my $dbh = C4::Context->dbh;
3093
3094
3094
    my $item      = GetItem($itemnumber)      or return;
3095
    my $item      = Koha::Items->find($itemnumber)  or return;
3095
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3096
    my $itemissue = $item->checkout                 or return;
3096
3097
3097
    $borrowernumber ||= $itemissue->borrowernumber;
3098
    $borrowernumber ||= $itemissue->borrowernumber;
3098
    my $patron = Koha::Patrons->find( $borrowernumber )
3099
    my $patron = Koha::Patrons->find( $borrowernumber )
3099
      or return;
3100
      or return;
3100
3101
3101
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3102
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3102
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3103
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3103
        {   categorycode => $patron->categorycode,
3104
        {   categorycode => $patron->categorycode,
3104
            itemtype     => $item->{itype},
3105
            itemtype     => $item->effective_itemtype,
3105
            branchcode   => $branchcode
3106
            branchcode   => $branchcode
3106
        }
3107
        }
3107
    );
3108
    );
Lines 3681-3688 sub ReturnLostItem{ Link Here
3681
3682
3682
    MarkIssueReturned( $borrowernumber, $itemnum );
3683
    MarkIssueReturned( $borrowernumber, $itemnum );
3683
    my $patron = Koha::Patrons->find( $borrowernumber );
3684
    my $patron = Koha::Patrons->find( $borrowernumber );
3684
    my $item = C4::Items::GetItem( $itemnum );
3685
    my $item = Koha::Items->find($itemnum);
3685
    my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{};
3686
    my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{};
3686
    my @datearr = localtime(time);
3687
    my @datearr = localtime(time);
3687
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3688
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3688
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
3689
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
Lines 3873-3880 sub ProcessOfflinePayment { Link Here
3873
sub TransferSlip {
3874
sub TransferSlip {
3874
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3875
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3875
3876
3876
    my $item =  GetItem( $itemnumber, $barcode )
3877
    my $item =
3877
      or return;
3878
      $itemnumber
3879
      ? Koha::Items->find($itemnumber)
3880
      : Koha::Items->find( { barcode => $barcode } );
3881
3882
    $item or return;
3878
3883
3879
    return C4::Letters::GetPreparedLetter (
3884
    return C4::Letters::GetPreparedLetter (
3880
        module => 'circulation',
3885
        module => 'circulation',
Lines 3882-3889 sub TransferSlip { Link Here
3882
        branchcode => $branch,
3887
        branchcode => $branch,
3883
        tables => {
3888
        tables => {
3884
            'branches'    => $to_branch,
3889
            'branches'    => $to_branch,
3885
            'biblio'      => $item->{biblionumber},
3890
            'biblio'      => $item->biblionumber,
3886
            'items'       => $item,
3891
            'items'       => $item->unblessed,
3887
        },
3892
        },
3888
    );
3893
    );
3889
}
3894
}
(-)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 732-742 sub HoldItem { Link Here
732
735
733
    # Get the item or return an error code
736
    # Get the item or return an error code
734
    my $itemnumber = $cgi->param('item_id');
737
    my $itemnumber = $cgi->param('item_id');
735
    my $item = GetItem( $itemnumber );
738
    my $item = Koha::Items->find($itemnumber);
736
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
739
    return { code => 'RecordNotFound' } unless $item;
737
740
738
    # If the biblio does not match the item, return an error code
741
    # If the biblio does not match the item, return an error code
739
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
742
    return { code => 'RecordNotFound' } if $item->biblionumber ne $biblio->biblionumber;
740
743
741
    # Check for item disponibility
744
    # Check for item disponibility
742
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
745
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
Lines 811-835 Returns, for an itemnumber, an array containing availability information. Link Here
811
814
812
sub _availability {
815
sub _availability {
813
    my ($itemnumber) = @_;
816
    my ($itemnumber) = @_;
814
    my $item = GetItem( $itemnumber, undef, undef );
817
    my $item = Koha::Items->find($itemnumber);
815
818
816
    if ( not $item->{'itemnumber'} ) {
819
    unless ( $item ) {
817
        return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
820
        return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
818
    }
821
    }
819
822
820
    my $biblionumber = $item->{'biblioitemnumber'};
823
    my $biblionumber = $item->biblioitemnumber;
821
    my $library = Koha::Libraries->find( $item->{holdingbranch} );
824
    my $library = Koha::Libraries->find( $item->holdingbranch );
822
    my $location = $library ? $library->branchname : '';
825
    my $location = $library ? $library->branchname : '';
823
826
824
    if ( $item->{'notforloan'} ) {
827
    if ( $item->notforloan ) {
825
        return ( $biblionumber, 'not available', 'Not for loan', $location );
828
        return ( $biblionumber, 'not available', 'Not for loan', $location );
826
    } elsif ( $item->{'onloan'} ) {
829
    } elsif ( $item->onloan ) {
827
        return ( $biblionumber, 'not available', 'Checked out', $location );
830
        return ( $biblionumber, 'not available', 'Checked out', $location );
828
    } elsif ( $item->{'itemlost'} ) {
831
    } elsif ( $item->itemlost ) {
829
        return ( $biblionumber, 'not available', 'Item lost', $location );
832
        return ( $biblionumber, 'not available', 'Item lost', $location );
830
    } elsif ( $item->{'withdrawn'} ) {
833
    } elsif ( $item->withdrawn ) {
831
        return ( $biblionumber, 'not available', 'Item withdrawn', $location );
834
        return ( $biblionumber, 'not available', 'Item withdrawn', $location );
832
    } elsif ( $item->{'damaged'} ) {
835
    } elsif ( $item->damaged ) {
833
        return ( $biblionumber, 'not available', 'Item damaged', $location );
836
        return ( $biblionumber, 'not available', 'Item damaged', $location );
834
    } else {
837
    } else {
835
        return ( $biblionumber, 'available', undef, $location );
838
        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 556-567 sub ModItem { Link Here
556
553
557
    my @fields = qw( itemlost withdrawn damaged );
554
    my @fields = qw( itemlost withdrawn damaged );
558
555
559
    # Only call GetItem if we need to set an "on" date field
556
    # Only retrieve the item if we need to set an "on" date field
560
    if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) {
557
    if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) {
561
        my $pre_mod_item = GetItem( $item->{'itemnumber'} );
558
        my $pre_mod_item = Koha::Items->find( $item->{'itemnumber'} );
562
        for my $field (@fields) {
559
        for my $field (@fields) {
563
            if (    defined( $item->{$field} )
560
            if (    defined( $item->{$field} )
564
                and not $pre_mod_item->{$field}
561
                and not $pre_mod_item->$field
565
                and $item->{$field} )
562
                and $item->{$field} )
566
            {
563
            {
567
                $item->{ $field . '_on' } =
564
                $item->{ $field . '_on' } =
Lines 1331-1343 sub GetMarcItem { Link Here
1331
    # while the other treats the MARC representation as authoritative
1328
    # while the other treats the MARC representation as authoritative
1332
    # under certain circumstances.
1329
    # under certain circumstances.
1333
1330
1334
    my $itemrecord = GetItem($itemnumber);
1331
    my $item = Koha::Items->find($itemnumber) or return;
1335
1332
1336
    # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work.
1333
    # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work.
1337
    # Also, don't emit a subfield if the underlying field is blank.
1334
    # Also, don't emit a subfield if the underlying field is blank.
1338
1335
1339
    
1336
    return Item2Marc($item->unblessed, $biblionumber);
1340
    return Item2Marc($itemrecord,$biblionumber);
1341
1337
1342
}
1338
}
1343
sub Item2Marc {
1339
sub Item2Marc {
Lines 1776-1806 sub ItemSafeToDelete { Link Here
1776
1772
1777
    my $countanalytics = GetAnalyticsCount($itemnumber);
1773
    my $countanalytics = GetAnalyticsCount($itemnumber);
1778
1774
1779
    # check that there is no issue on this item before deletion.
1775
    my $item = Koha::Items->find($itemnumber) or return;
1780
    my $sth = $dbh->prepare(
1781
        q{
1782
        SELECT COUNT(*) FROM issues
1783
        WHERE itemnumber = ?
1784
    }
1785
    );
1786
    $sth->execute($itemnumber);
1787
    my ($onloan) = $sth->fetchrow;
1788
1789
    my $item = GetItem($itemnumber);
1790
1776
1791
    if ($onloan) {
1777
    if ($item->checkout) {
1792
        $status = "book_on_loan";
1778
        $status = "book_on_loan";
1793
    }
1779
    }
1794
    elsif ( defined C4::Context->userenv
1780
    elsif ( defined C4::Context->userenv
1795
        and !C4::Context->IsSuperLibrarian()
1781
        and !C4::Context->IsSuperLibrarian()
1796
        and C4::Context->preference("IndependentBranches")
1782
        and C4::Context->preference("IndependentBranches")
1797
        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
1783
        and ( C4::Context->userenv->{branch} ne $item->homebranch ) )
1798
    {
1784
    {
1799
        $status = "not_same_branch";
1785
        $status = "not_same_branch";
1800
    }
1786
    }
1801
    else {
1787
    else {
1802
        # check it doesn't have a waiting reserve
1788
        # check it doesn't have a waiting reserve
1803
        $sth = $dbh->prepare(
1789
        my $sth = $dbh->prepare(
1804
            q{
1790
            q{
1805
            SELECT COUNT(*) FROM reserves
1791
            SELECT COUNT(*) FROM reserves
1806
            WHERE (found = 'W' OR found = 'T')
1792
            WHERE (found = 'W' OR found = 'T')
Lines 2685-2691 sub ToggleNewStatus { Link Here
2685
        while ( my $values = $sth->fetchrow_hashref ) {
2671
        while ( my $values = $sth->fetchrow_hashref ) {
2686
            my $biblionumber = $values->{biblionumber};
2672
            my $biblionumber = $values->{biblionumber};
2687
            my $itemnumber = $values->{itemnumber};
2673
            my $itemnumber = $values->{itemnumber};
2688
            my $item = C4::Items::GetItem( $itemnumber );
2689
            for my $substitution ( @$substitutions ) {
2674
            for my $substitution ( @$substitutions ) {
2690
                next unless $substitution->{field};
2675
                next unless $substitution->{field};
2691
                C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
2676
                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 319-332 sub CanItemBeReserved { Link Here
319
319
320
    # we retrieve borrowers and items informations #
320
    # we retrieve borrowers and items informations #
321
    # item->{itype} will come for biblioitems if necessery
321
    # item->{itype} will come for biblioitems if necessery
322
    my $item       = C4::Items::GetItem($itemnumber);
322
    my $item       = Koha::Items->find($itemnumber);
323
    my $biblio     = Koha::Biblios->find( $item->{biblionumber} );
323
    my $biblio     = $item->biblio;
324
    my $patron = Koha::Patrons->find( $borrowernumber );
324
    my $patron = Koha::Patrons->find( $borrowernumber );
325
    my $borrower = $patron->unblessed;
325
    my $borrower = $patron->unblessed;
326
326
327
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
327
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
328
    return { status =>'damaged' }
328
    return { status =>'damaged' }
329
      if ( $item->{damaged}
329
      if ( $item->damaged
330
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
330
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
331
331
332
    # Check for the age restriction
332
    # Check for the age restriction
Lines 354-360 sub CanItemBeReserved { Link Here
354
354
355
    if ( $controlbranch eq "ItemHomeLibrary" ) {
355
    if ( $controlbranch eq "ItemHomeLibrary" ) {
356
        $branchfield = "items.homebranch";
356
        $branchfield = "items.homebranch";
357
        $branchcode  = $item->{homebranch};
357
        $branchcode  = $item->homebranch;
358
    }
358
    }
359
    elsif ( $controlbranch eq "PatronLibrary" ) {
359
    elsif ( $controlbranch eq "PatronLibrary" ) {
360
        $branchfield = "borrowers.branchcode";
360
        $branchfield = "borrowers.branchcode";
Lines 362-368 sub CanItemBeReserved { Link Here
362
    }
362
    }
363
363
364
    # we retrieve rights
364
    # we retrieve rights
365
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) {
365
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
366
        $ruleitemtype     = $rights->{itemtype};
366
        $ruleitemtype     = $rights->{itemtype};
367
        $allowedreserves  = $rights->{reservesallowed};
367
        $allowedreserves  = $rights->{reservesallowed};
368
        $holds_per_record = $rights->{holds_per_record};
368
        $holds_per_record = $rights->{holds_per_record};
Lines 372-378 sub CanItemBeReserved { Link Here
372
        $ruleitemtype = '*';
372
        $ruleitemtype = '*';
373
    }
373
    }
374
374
375
    $item = Koha::Items->find( $itemnumber );
376
    my $holds = Koha::Holds->search(
375
    my $holds = Koha::Holds->search(
377
        {
376
        {
378
            borrowernumber => $borrowernumber,
377
            borrowernumber => $borrowernumber,
Lines 448-454 sub CanItemBeReserved { Link Here
448
    my $circ_control_branch =
447
    my $circ_control_branch =
449
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
448
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
450
    my $branchitemrule =
449
    my $branchitemrule =
451
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype );
450
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype ); # FIXME Should not be item->effective_itemtype?
452
451
453
    if ( $branchitemrule->{holdallowed} == 0 ) {
452
    if ( $branchitemrule->{holdallowed} == 0 ) {
454
        return { status => 'notReservable' };
453
        return { status => 'notReservable' };
Lines 465-472 sub CanItemBeReserved { Link Here
465
    if ( C4::Context->preference('IndependentBranches')
464
    if ( C4::Context->preference('IndependentBranches')
466
        and !C4::Context->preference('canreservefromotherbranches') )
465
        and !C4::Context->preference('canreservefromotherbranches') )
467
    {
466
    {
468
        my $itembranch = $item->homebranch;
467
        if ( $item->homebranch ne $borrower->{branchcode} ) {
469
        if ( $itembranch ne $borrower->{branchcode} ) {
470
            return { status => 'cannotReserveFromOtherBranches' };
468
            return { status => 'cannotReserveFromOtherBranches' };
471
        }
469
        }
472
    }
470
    }
Lines 523-530 sub GetOtherReserves { Link Here
523
    my $nextreservinfo;
521
    my $nextreservinfo;
524
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
522
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
525
    if ($checkreserves) {
523
    if ($checkreserves) {
526
        my $iteminfo = GetItem($itemnumber);
524
        my $item = Koha::Items->find($itemnumber);
527
        if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
525
        if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) {
528
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
526
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
529
            #minus priorities of others reservs
527
            #minus priorities of others reservs
530
            ModReserveMinusPriority(
528
            ModReserveMinusPriority(
Lines 535-541 sub GetOtherReserves { Link Here
535
            #launch the subroutine dotransfer
533
            #launch the subroutine dotransfer
536
            C4::Items::ModItemTransfer(
534
            C4::Items::ModItemTransfer(
537
                $itemnumber,
535
                $itemnumber,
538
                $iteminfo->{'holdingbranch'},
536
                $item->holdingbranch,
539
                $checkreserves->{'branchcode'}
537
                $checkreserves->{'branchcode'}
540
              ),
538
              ),
541
              ;
539
              ;
Lines 771-785 sub CheckReserves { Link Here
771
                }
769
                }
772
            } else {
770
            } else {
773
                my $patron;
771
                my $patron;
774
                my $iteminfo;
772
                my $item;
775
                my $local_hold_match;
773
                my $local_hold_match;
776
774
777
                if ($LocalHoldsPriority) {
775
                if ($LocalHoldsPriority) {
778
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
776
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
779
                    $iteminfo = C4::Items::GetItem($itemnumber);
777
                    $item = Koha::Items->find($itemnumber);
780
778
781
                    my $local_holds_priority_item_branchcode =
779
                    my $local_holds_priority_item_branchcode =
782
                      $iteminfo->{$LocalHoldsPriorityItemControl};
780
                      $item->$LocalHoldsPriorityItemControl;
783
                    my $local_holds_priority_patron_branchcode =
781
                    my $local_holds_priority_patron_branchcode =
784
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
782
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
785
                      ? $res->{branchcode}
783
                      ? $res->{branchcode}
Lines 793-806 sub CheckReserves { Link Here
793
791
794
                # See if this item is more important than what we've got so far
792
                # See if this item is more important than what we've got so far
795
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
793
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
796
                    $iteminfo ||= C4::Items::GetItem($itemnumber);
794
                    $item ||= Koha::Items->find($itemnumber);
797
                    next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
795
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
798
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
796
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
799
                    my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
797
                    my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
800
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
798
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
801
                    next if ($branchitemrule->{'holdallowed'} == 0);
799
                    next if ($branchitemrule->{'holdallowed'} == 0);
802
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
800
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
803
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
801
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
802
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
804
                    $priority = $res->{'priority'};
803
                    $priority = $res->{'priority'};
805
                    $highest  = $res;
804
                    $highest  = $res;
806
                    last if $local_hold_match;
805
                    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 79-91 my $query = "UPDATE statistics SET itemtype = ? WHERE itemnumber = ?"; Link Here
79
my $update = $dbh->prepare($query);
79
my $update = $dbh->prepare($query);
80
# $debug and print "Update Query: $query\n";
80
# $debug and print "Update Query: $query\n";
81
foreach (@itemnumbers) {
81
foreach (@itemnumbers) {
82
	my $item = GetItem($_);
82
    my $item = Koha::Items->find($_);
83
	unless ($item) {
83
    unless ($item) {
84
		print STDERR "\tNo item found for itemnumber $_\n"; 
84
		print STDERR "\tNo item found for itemnumber $_\n"; 
85
		next;
85
		next;
86
	}
86
	}
87
	$update->execute($item->{itype},$_) or warn "Error in UPDATE execution";
87
    my $itemtype = $item->effective_itemtype;
88
	printf "\titemnumber %5d : %7s  (%s rows)\n", $_, $item->{itype}, $update->rows;
88
    $update->execute($itemtype,$_) or warn "Error in UPDATE execution";
89
    printf "\titemnumber %5d : %7s  (%s rows)\n", $_, $itemtype, $update->rows;
89
}
90
}
90
91
91
my $old_issues = $dbh->prepare("SELECT * FROM old_issues WHERE timestamp = ? AND itemnumber = ?");
92
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 (-2 / +4 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 469-475 $dbh->do( Link Here
469
    my $passeddatedue1 = AddIssue($renewing_borrower, $barcode7, $five_weeks_ago);
470
    my $passeddatedue1 = AddIssue($renewing_borrower, $barcode7, $five_weeks_ago);
470
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
471
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
471
472
472
    my ( $fine ) = CalcFine( GetItem(undef, $barcode7), $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
473
    my $item = Koha::Items->find({barcode => $barcode7});
474
    my ( $fine ) = CalcFine( $item->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
473
    C4::Overdues::UpdateFine(
475
    C4::Overdues::UpdateFine(
474
        {
476
        {
475
            issue_id       => $passeddatedue1->id(),
477
            issue_id       => $passeddatedue1->id(),
Lines 841-847 $dbh->do( Link Here
841
    $line = Koha::Account::Lines->find($line->id);
843
    $line = Koha::Account::Lines->find($line->id);
842
    is( $line->accounttype, 'F', 'Account type correctly changed from FU to F' );
844
    is( $line->accounttype, 'F', 'Account type correctly changed from FU to F' );
843
845
844
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
846
    $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
845
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
847
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
846
    my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
848
    my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
847
    is( $checkout, undef, 'LostItem called with forced return has checked in the item' );
849
    is( $checkout, undef, 'LostItem called with forced return has checked in the item' );
(-)a/t/db_dependent/Circulation/IsItemIssued.t (-4 / +5 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;
Lines 62-73 my ( undef, undef, $itemnumber ) = AddItem( Link Here
62
    $biblionumber
63
    $biblionumber
63
);
64
);
64
65
65
my $item = GetItem( $itemnumber );
66
my $item = Koha::Items->find( $itemnumber );
66
67
67
is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
68
is ( IsItemIssued( $item->itemnumber ), 0, "item is not on loan at first" );
68
69
69
AddIssue($borrower, 'i_dont_exist');
70
AddIssue($borrower, 'i_dont_exist');
70
is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
71
is ( IsItemIssued( $item->itemnumber ), 1, "item is now on loan" );
71
72
72
is(
73
is(
73
    DelItemCheck( $biblionumber, $itemnumber),
74
    DelItemCheck( $biblionumber, $itemnumber),
Lines 76-82 is( Link Here
76
);
77
);
77
78
78
AddReturn('i_dont_exist', $library->{branchcode});
79
AddReturn('i_dont_exist', $library->{branchcode});
79
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
80
is ( IsItemIssued( $item->itemnumber ), 0, "item has been returned" );
80
81
81
is(
82
is(
82
    DelItemCheck( $biblionumber, $itemnumber),
83
    DelItemCheck( $biblionumber, $itemnumber),
(-)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, '==', $bibitemnum, "New item is linked to correct biblioitemnumber.");
64
    cmp_ok($item_bibitemnum, '==', $bibitemnum, "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' }, $bibnum, $itemnumber);
80
    ModItem({ barcode => '987654321' }, $bibnum, $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 => $bibnum, itemnumber => $itemnumber });
85
    DelItem({ biblionumber => $bibnum, 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} } , $bibnum);
89
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum);
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 }, $bibnum, $itemnumber);
94
    ModItem({ location => $location }, $bibnum, $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' }, $bibnum, $itemnumber);
99
    ModItem({ location => 'CART' }, $bibnum, $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}, undef, "Itemtype set correctly when not using item-level_itypes" );
109
    is( $getitem->effective_itemtype, undef, "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 501-508 subtest 'SearchItems test' => sub { Link Here
501
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
501
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
502
502
503
    # Make sure the link is used
503
    # Make sure the link is used
504
    my $item3 = GetItem($item3_itemnumber);
504
    my $item3 = Koha::Items->find($item3_itemnumber);
505
    ok($item3->{itemnotes} eq 'foobar', 'itemnotes eq "foobar"');
505
    ok($item3->itemnotes eq 'foobar', 'itemnotes eq "foobar"');
506
506
507
    # Do the same search again.
507
    # Do the same search again.
508
    # This time it will search in items.itemnotes
508
    # This time it will search in items.itemnotes
Lines 718-738 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
718
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
718
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
719
719
720
    # Make sure everything has been set up
720
    # Make sure everything has been set up
721
    my $item = GetItem($item_itemnumber);
721
    my $item = Koha::Items->find($item_itemnumber);
722
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
722
    is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
723
723
724
    # Delete the barcode field and save the record
724
    # Delete the barcode field and save the record
725
    $item_record->delete_fields( $barcode_field );
725
    $item_record->delete_fields( $barcode_field );
726
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
726
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
727
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
727
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
728
    $item = GetItem($item_itemnumber);
728
    $item = Koha::Items->find($item_itemnumber);
729
    is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
729
    is( $item->barcode, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
730
730
731
    # Re-add the barcode field and save the record
731
    # Re-add the barcode field and save the record
732
    $item_record->append_fields( $barcode_field );
732
    $item_record->append_fields( $barcode_field );
733
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
733
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
734
    $item = GetItem($item_itemnumber);
734
    $item = Koha::Items->find($item_itemnumber);
735
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
735
    is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
736
736
737
    # Remove the mapping for barcode
737
    # Remove the mapping for barcode
738
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
738
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
Lines 752-759 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
752
    $item_record->append_fields( $another_barcode_field );
752
    $item_record->append_fields( $another_barcode_field );
753
    # The DB value should not have been updated
753
    # The DB value should not have been updated
754
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
754
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
755
    $item = GetItem($item_itemnumber);
755
    $item = Koha::Items->find($item_itemnumber);
756
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
756
    is ( $item->barcode, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
757
757
758
    $cache->clear_from_cache("default_value_for_mod_marc-");
758
    $cache->clear_from_cache("default_value_for_mod_marc-");
759
    $cache->clear_from_cache( "MarcSubfieldStructure-" );
759
    $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 => $biblionumber, itemnumber => $itemnumber } );
27
my $deleted = DelItem( { biblionumber => $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} }, $biblionumber );
33
  AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblionumber );
32
$deleted = DelItem( { biblionumber => $biblionumber, itemnumber => $itemnumber } );
34
$deleted = DelItem( { biblionumber => $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 537-543 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , Link Here
537
####### EO Bug 13113 <<<
538
####### EO Bug 13113 <<<
538
       ####
539
       ####
539
540
540
$item = GetItem($itemnumber);
541
$item = Koha::Items->find($itemnumber)->unblessed;
541
542
542
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
543
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
543
544
(-)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 39-44 use Koha::Biblios; Link Here
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
use Koha::AuthorisedValues;
40
use Koha::AuthorisedValues;
41
use Koha::BiblioFrameworks;
41
use Koha::BiblioFrameworks;
42
use Koha::Items;
42
use List::MoreUtils qw( none );
43
use List::MoreUtils qw( none );
43
44
44
my $minlocation=$input->param('minlocation') || '';
45
my $minlocation=$input->param('minlocation') || '';
Lines 187-194 if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { Link Here
187
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
188
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
188
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
189
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
189
        } else {
190
        } else {
190
            my $item = GetItem( '', $barcode );
191
            my $item = Koha::Items->find({barcode => $barcode});
191
            if ( defined $item && $item->{'itemnumber'} ) {
192
            if ( $item ) {
193
                $item = $item->unblessed;
192
                # Modify date last seen for scanned items, remove lost status
194
                # Modify date last seen for scanned items, remove lost status
193
                ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
195
                ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
194
                $moddatecount++;
196
                $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