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 (-144 / +149 lines)
Lines 669-685 sub CanBookBeIssued { Link Here
669
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
669
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
670
    my $override_high_holds = $params->{override_high_holds} || 0;
670
    my $override_high_holds = $params->{override_high_holds} || 0;
671
671
672
    my $item = GetItem(undef, $barcode );
672
    my $item = Koha::Items->find({barcode => $barcode });
673
    # MANDATORY CHECKS - unless item exists, nothing else matters
673
    # MANDATORY CHECKS - unless item exists, nothing else matters
674
    unless ( $item ) {
674
    unless ( $item ) {
675
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
675
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
676
    }
676
    }
677
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
677
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
678
678
679
    my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
679
    my $item_unblessed = $item->unblessed; # Transition...
680
    my $biblio = Koha::Biblios->find( $item->{biblionumber} );
680
    my $issue = $item->checkout;
681
    my $biblio = $item->biblio;
681
    my $biblioitem = $biblio->biblioitem;
682
    my $biblioitem = $biblio->biblioitem;
682
    my $effective_itemtype = $item->{itype}; # GetItem deals with that
683
    my $effective_itemtype = $item->effective_itemtype;
683
    my $dbh             = C4::Context->dbh;
684
    my $dbh             = C4::Context->dbh;
684
    my $patron_unblessed = $patron->unblessed;
685
    my $patron_unblessed = $patron->unblessed;
685
686
Lines 693-699 sub CanBookBeIssued { Link Here
693
    unless ( $duedate ) {
694
    unless ( $duedate ) {
694
        my $issuedate = $now->clone();
695
        my $issuedate = $now->clone();
695
696
696
        my $branch = _GetCircControlBranch($item, $patron_unblessed);
697
        my $branch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
697
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
698
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
698
699
699
        # Offline circ calls AddIssue directly, doesn't run through here
700
        # Offline circ calls AddIssue directly, doesn't run through here
Lines 712-728 sub CanBookBeIssued { Link Here
712
    #
713
    #
713
    # BORROWER STATUS
714
    # BORROWER STATUS
714
    #
715
    #
715
    if ( $patron->category->category_type eq 'X' && (  $item->{barcode}  )) {
716
    if ( $patron->category->category_type eq 'X' && (  $item->barcode  )) {
716
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
717
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
717
        &UpdateStats({
718
        &UpdateStats({
718
                     branch => C4::Context->userenv->{'branch'},
719
                     branch => C4::Context->userenv->{'branch'},
719
                     type => 'localuse',
720
                     type => 'localuse',
720
                     itemnumber => $item->{'itemnumber'},
721
                     itemnumber => $item->itemnumber,
721
                     itemtype => $effective_itemtype,
722
                     itemtype => $effective_itemtype,
722
                     borrowernumber => $patron->borrowernumber,
723
                     borrowernumber => $patron->borrowernumber,
723
                     ccode => $item->{'ccode'}}
724
                     ccode => $item->ccode}
724
                    );
725
                    );
725
        ModDateLastSeen( $item->{'itemnumber'} );
726
        ModDateLastSeen( $item->itemnumber ); # FIXME Move to Koha::Item
726
        return( { STATS => 1 }, {});
727
        return( { STATS => 1 }, {});
727
    }
728
    }
728
729
Lines 833-839 sub CanBookBeIssued { Link Here
833
        } else {
834
        } else {
834
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
835
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
835
                $patron->borrowernumber,
836
                $patron->borrowernumber,
836
                $item->{'itemnumber'},
837
                $item->itemnumber,
837
            );
838
            );
838
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
839
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
839
                if ( $renewerror eq 'onsite_checkout' ) {
840
                if ( $renewerror eq 'onsite_checkout' ) {
Lines 854-860 sub CanBookBeIssued { Link Here
854
855
855
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
856
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
856
857
857
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
858
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
858
859
859
        unless ( $can_be_returned ) {
860
        unless ( $can_be_returned ) {
860
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
861
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
Lines 875-881 sub CanBookBeIssued { Link Here
875
      and $issue
876
      and $issue
876
      and $issue->onsite_checkout
877
      and $issue->onsite_checkout
877
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
878
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
878
    my $toomany = TooMany( $patron_unblessed, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
879
    my $toomany = TooMany( $patron_unblessed, $item->biblionumber, $item_unblessed, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
879
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
880
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
880
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
881
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
881
        if ( $toomany->{max_allowed} == 0 ) {
882
        if ( $toomany->{max_allowed} == 0 ) {
Lines 898-916 sub CanBookBeIssued { Link Here
898
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
899
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
899
    my $wants_check = $patron->wants_check_for_previous_checkout;
900
    my $wants_check = $patron->wants_check_for_previous_checkout;
900
    $needsconfirmation{PREVISSUE} = 1
901
    $needsconfirmation{PREVISSUE} = 1
901
        if ($wants_check and $patron->do_check_for_previous_checkout($item));
902
        if ($wants_check and $patron->do_check_for_previous_checkout($item_unblessed));
902
903
903
    #
904
    #
904
    # ITEM CHECKING
905
    # ITEM CHECKING
905
    #
906
    #
906
    if ( $item->{'notforloan'} )
907
    if ( $item->notforloan )
907
    {
908
    {
908
        if(!C4::Context->preference("AllowNotForLoanOverride")){
909
        if(!C4::Context->preference("AllowNotForLoanOverride")){
909
            $issuingimpossible{NOT_FOR_LOAN} = 1;
910
            $issuingimpossible{NOT_FOR_LOAN} = 1;
910
            $issuingimpossible{item_notforloan} = $item->{'notforloan'};
911
            $issuingimpossible{item_notforloan} = $item->notforloan;
911
        }else{
912
        }else{
912
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
913
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
913
            $needsconfirmation{item_notforloan} = $item->{'notforloan'};
914
            $needsconfirmation{item_notforloan} = $item->notforloan;
914
        }
915
        }
915
    }
916
    }
916
    else {
917
    else {
Lines 943-959 sub CanBookBeIssued { Link Here
943
            }
944
            }
944
        }
945
        }
945
    }
946
    }
946
    if ( $item->{'withdrawn'} && $item->{'withdrawn'} > 0 )
947
    if ( $item->withdrawn && $item->withdrawn > 0 )
947
    {
948
    {
948
        $issuingimpossible{WTHDRAWN} = 1;
949
        $issuingimpossible{WTHDRAWN} = 1;
949
    }
950
    }
950
    if (   $item->{'restricted'}
951
    if (   $item->restricted
951
        && $item->{'restricted'} == 1 )
952
        && $item->restricted == 1 )
952
    {
953
    {
953
        $issuingimpossible{RESTRICTED} = 1;
954
        $issuingimpossible{RESTRICTED} = 1;
954
    }
955
    }
955
    if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
956
    if ( $item->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
956
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} });
957
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->itemlost });
957
        my $code = $av->count ? $av->next->lib : '';
958
        my $code = $av->count ? $av->next->lib : '';
958
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
959
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
959
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
960
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
Lines 961-969 sub CanBookBeIssued { Link Here
961
    if ( C4::Context->preference("IndependentBranches") ) {
962
    if ( C4::Context->preference("IndependentBranches") ) {
962
        my $userenv = C4::Context->userenv;
963
        my $userenv = C4::Context->userenv;
963
        unless ( C4::Context->IsSuperLibrarian() ) {
964
        unless ( C4::Context->IsSuperLibrarian() ) {
964
            if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
965
            my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch");
966
            if ( $item->$HomeOrHoldingBranch ne $userenv->{branch} ){
965
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
967
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
966
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
968
                $issuingimpossible{'itemhomebranch'} = $item->$HomeOrHoldingBranch;
967
            }
969
            }
968
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
970
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
969
              if ( $patron->branchcode ne $userenv->{branch} );
971
              if ( $patron->branchcode ne $userenv->{branch} );
Lines 975-981 sub CanBookBeIssued { Link Here
975
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
977
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
976
978
977
    if ( $rentalConfirmation ){
979
    if ( $rentalConfirmation ){
978
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
980
        my ($rentalCharge) = GetIssuingCharges( $item->itemnumber, $patron->borrowernumber );
979
        if ( $rentalCharge > 0 ){
981
        if ( $rentalCharge > 0 ){
980
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
982
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
981
        }
983
        }
Lines 983-989 sub CanBookBeIssued { Link Here
983
985
984
    unless ( $ignore_reserves ) {
986
    unless ( $ignore_reserves ) {
985
        # See if the item is on reserve.
987
        # See if the item is on reserve.
986
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
988
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->itemnumber );
987
        if ($restype) {
989
        if ($restype) {
988
            my $resbor = $res->{'borrowernumber'};
990
            my $resbor = $res->{'borrowernumber'};
989
            if ( $resbor ne $patron->borrowernumber ) {
991
            if ( $resbor ne $patron->borrowernumber ) {
Lines 1028-1034 sub CanBookBeIssued { Link Here
1028
1030
1029
    ## check for high holds decreasing loan period
1031
    ## check for high holds decreasing loan period
1030
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1032
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1031
        my $check = checkHighHolds( $item, $patron_unblessed );
1033
        my $check = checkHighHolds( $item_unblessed, $patron_unblessed );
1032
1034
1033
        if ( $check->{exceeded} ) {
1035
        if ( $check->{exceeded} ) {
1034
            if ($override_high_holds) {
1036
            if ($override_high_holds) {
Lines 1057-1063 sub CanBookBeIssued { Link Here
1057
    ) {
1059
    ) {
1058
        # Check if borrower has already issued an item from the same biblio
1060
        # Check if borrower has already issued an item from the same biblio
1059
        # Only if it's not a subscription
1061
        # Only if it's not a subscription
1060
        my $biblionumber = $item->{biblionumber};
1062
        my $biblionumber = $item->biblionumber;
1061
        require C4::Serials;
1063
        require C4::Serials;
1062
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1064
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1063
        unless ($is_a_subscription) {
1065
        unless ($is_a_subscription) {
Lines 1090-1096 Check whether the item can be returned to the provided branch Link Here
1090
1092
1091
=over 4
1093
=over 4
1092
1094
1093
=item C<$item> is a hash of item information as returned from GetItem
1095
=item C<$item> is a hash of item information as returned Koha::Items->find->unblessed (Temporary, should be a Koha::Item instead)
1094
1096
1095
=item C<$branch> is the branchcode where the return is taking place
1097
=item C<$branch> is the branchcode where the return is taking place
1096
1098
Lines 1288-1308 sub AddIssue { Link Here
1288
    # Stop here if the patron or barcode doesn't exist
1290
    # Stop here if the patron or barcode doesn't exist
1289
    if ( $borrower && $barcode && $barcodecheck ) {
1291
    if ( $borrower && $barcode && $barcodecheck ) {
1290
        # find which item we issue
1292
        # find which item we issue
1291
        my $item = GetItem( '', $barcode )
1293
        my $item = Koha::Items->find({ barcode => $barcode })
1292
          or return;    # if we don't get an Item, abort.
1294
          or return;    # if we don't get an Item, abort.
1293
        my $item_object = Koha::Items->find( { barcode => $barcode } );
1295
        my $item_unblessed = $item->unblessed;
1294
1296
1295
        my $branch = _GetCircControlBranch( $item, $borrower );
1297
        my $branch = _GetCircControlBranch( $item_unblessed, $borrower );
1296
1298
1297
        # get actual issuing if there is one
1299
        # get actual issuing if there is one
1298
        my $actualissue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
1300
        my $actualissue = $item->checkout;
1299
1301
1300
        # check if we just renew the issue.
1302
        # check if we just renew the issue.
1301
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1303
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1302
                and not $switch_onsite_checkout ) {
1304
                and not $switch_onsite_checkout ) {
1303
            $datedue = AddRenewal(
1305
            $datedue = AddRenewal(
1304
                $borrower->{'borrowernumber'},
1306
                $borrower->{'borrowernumber'},
1305
                $item->{'itemnumber'},
1307
                $item->itemnumber,
1306
                $branch,
1308
                $branch,
1307
                $datedue,
1309
                $datedue,
1308
                $issuedate,    # here interpreted as the renewal date
1310
                $issuedate,    # here interpreted as the renewal date
Lines 1313-1327 sub AddIssue { Link Here
1313
            if ( $actualissue and not $switch_onsite_checkout ) {
1315
            if ( $actualissue and not $switch_onsite_checkout ) {
1314
                # This book is currently on loan, but not to the person
1316
                # This book is currently on loan, but not to the person
1315
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1317
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1316
                my ( $allowed, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
1318
                my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
1317
                return unless $allowed;
1319
                return unless $allowed;
1318
                AddReturn( $item->{'barcode'}, C4::Context->userenv->{'branch'} );
1320
                AddReturn( $item->barcode, C4::Context->userenv->{'branch'} );
1319
            }
1321
            }
1320
1322
1321
            C4::Reserves::MoveReserve( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $cancelreserve );
1323
            C4::Reserves::MoveReserve( $item->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1322
1324
1323
            # Starting process for transfer job (checking transfert and validate it if we have one)
1325
            # Starting process for transfer job (checking transfert and validate it if we have one)
1324
            my ($datesent) = GetTransfers( $item->{'itemnumber'} );
1326
            my ($datesent) = GetTransfers( $item->itemnumber );
1325
            if ($datesent) {
1327
            if ($datesent) {
1326
                # 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
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1327
                my $sth = $dbh->prepare(
1329
                my $sth = $dbh->prepare(
Lines 1332-1345 sub AddIssue { Link Here
1332
                    WHERE itemnumber= ? AND datearrived IS NULL"
1334
                    WHERE itemnumber= ? AND datearrived IS NULL"
1333
                );
1335
                );
1334
                $sth->execute( C4::Context->userenv->{'branch'},
1336
                $sth->execute( C4::Context->userenv->{'branch'},
1335
                    $item->{'itemnumber'} );
1337
                    $item->itemnumber );
1336
            }
1338
            }
1337
1339
1338
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1340
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1339
            unless ($auto_renew) {
1341
            unless ($auto_renew) {
1340
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1342
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1341
                    {   categorycode => $borrower->{categorycode},
1343
                    {   categorycode => $borrower->{categorycode},
1342
                        itemtype     => $item->{itype},
1344
                        itemtype     => $item->effective_itemtype,
1343
                        branchcode   => $branch
1345
                        branchcode   => $branch
1344
                    }
1346
                    }
1345
                );
1347
                );
Lines 1349-1355 sub AddIssue { Link Here
1349
1351
1350
            # Record in the database the fact that the book was issued.
1352
            # Record in the database the fact that the book was issued.
1351
            unless ($datedue) {
1353
            unless ($datedue) {
1352
                my $itype = $item_object->effective_itemtype;
1354
                my $itype = $item->effective_itemtype;
1353
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1355
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1354
1356
1355
            }
1357
            }
Lines 1358-1364 sub AddIssue { Link Here
1358
            $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create(
1360
            $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create(
1359
                {
1361
                {
1360
                    borrowernumber => $borrower->{'borrowernumber'},
1362
                    borrowernumber => $borrower->{'borrowernumber'},
1361
                    itemnumber     => $item->{'itemnumber'},
1363
                    itemnumber     => $item->itemnumber,
1362
                    issuedate      => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1364
                    issuedate      => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1363
                    date_due       => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1365
                    date_due       => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1364
                    branchcode     => C4::Context->userenv->{'branch'},
1366
                    branchcode     => C4::Context->userenv->{'branch'},
Lines 1369-1417 sub AddIssue { Link Here
1369
1371
1370
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1372
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1371
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1373
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1372
                CartToShelf( $item->{'itemnumber'} );
1374
                CartToShelf( $item->itemnumber );
1373
            }
1375
            }
1374
            $item->{'issues'}++;
1376
1375
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1377
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1376
                UpdateTotalIssues( $item->{'biblionumber'}, 1 );
1378
                UpdateTotalIssues( $item->biblionumber, 1 );
1377
            }
1379
            }
1378
1380
1379
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1381
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1380
            if ( $item->{'itemlost'} ) {
1382
            if ( $item->itemlost ) {
1381
                if (
1383
                if (
1382
                    Koha::RefundLostItemFeeRules->should_refund(
1384
                    Koha::RefundLostItemFeeRules->should_refund(
1383
                        {
1385
                        {
1384
                            current_branch      => C4::Context->userenv->{branch},
1386
                            current_branch      => C4::Context->userenv->{branch},
1385
                            item_home_branch    => $item->{homebranch},
1387
                            item_home_branch    => $item->homebranch,
1386
                            item_holding_branch => $item->{holdingbranch}
1388
                            item_holding_branch => $item->holdingbranch,
1387
                        }
1389
                        }
1388
                    )
1390
                    )
1389
                  )
1391
                  )
1390
                {
1392
                {
1391
                    _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef,
1393
                    _FixAccountForLostAndReturned( $item->itemnumber, undef,
1392
                        $item->{'barcode'} );
1394
                        $item->barcode );
1393
                }
1395
                }
1394
            }
1396
            }
1395
1397
1396
            ModItem(
1398
            ModItem(
1397
                {
1399
                {
1398
                    issues        => $item->{'issues'},
1400
                    issues        => $item->issues + 1,
1399
                    holdingbranch => C4::Context->userenv->{'branch'},
1401
                    holdingbranch => C4::Context->userenv->{'branch'},
1400
                    itemlost      => 0,
1402
                    itemlost      => 0,
1401
                    onloan        => $datedue->ymd(),
1403
                    onloan        => $datedue->ymd(),
1402
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1404
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1403
                },
1405
                },
1404
                $item->{'biblionumber'},
1406
                $item->biblionumber,
1405
                $item->{'itemnumber'},
1407
                $item->itemnumber,
1406
                { log_action => 0 }
1408
                { log_action => 0 }
1407
            );
1409
            );
1408
            ModDateLastSeen( $item->{'itemnumber'} );
1410
            ModDateLastSeen( $item->itemnumber );
1409
1411
1410
           # If it costs to borrow this book, charge it to the patron's account.
1412
           # If it costs to borrow this book, charge it to the patron's account.
1411
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1413
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->itemnumber, $borrower->{'borrowernumber'} );
1412
            if ( $charge > 0 ) {
1414
            if ( $charge > 0 ) {
1413
                AddIssuingCharge( $issue, $charge );
1415
                AddIssuingCharge( $issue, $charge );
1414
                $item->{'charge'} = $charge;
1415
            }
1416
            }
1416
1417
1417
            # Record the fact that this book was issued.
1418
            # Record the fact that this book was issued.
Lines 1421-1431 sub AddIssue { Link Here
1421
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1422
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1422
                    amount         => $charge,
1423
                    amount         => $charge,
1423
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1424
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1424
                    itemnumber     => $item->{'itemnumber'},
1425
                    itemnumber     => $item->itemnumber,
1425
                    itemtype       => $item->{'itype'},
1426
                    itemtype       => $item->effective_itemtype,
1426
                    location       => $item->{location},
1427
                    location       => $item->location,
1427
                    borrowernumber => $borrower->{'borrowernumber'},
1428
                    borrowernumber => $borrower->{'borrowernumber'},
1428
                    ccode          => $item->{'ccode'}
1429
                    ccode          => $item->ccode,
1429
                }
1430
                }
1430
            );
1431
            );
1431
1432
Lines 1434-1440 sub AddIssue { Link Here
1434
            my %conditions        = (
1435
            my %conditions        = (
1435
                branchcode   => $branch,
1436
                branchcode   => $branch,
1436
                categorycode => $borrower->{categorycode},
1437
                categorycode => $borrower->{categorycode},
1437
                item_type    => $item->{itype},
1438
                item_type    => $item->effective_itemtype,
1438
                notification => 'CHECKOUT',
1439
                notification => 'CHECKOUT',
1439
            );
1440
            );
1440
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
1441
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
Lines 1450-1456 sub AddIssue { Link Here
1450
            logaction(
1451
            logaction(
1451
                "CIRCULATION", "ISSUE",
1452
                "CIRCULATION", "ISSUE",
1452
                $borrower->{'borrowernumber'},
1453
                $borrower->{'borrowernumber'},
1453
                $item->{'itemnumber'}
1454
                $item->itemnumber,
1454
            ) if C4::Context->preference("IssueLog");
1455
            ) if C4::Context->preference("IssueLog");
1455
        }
1456
        }
1456
    }
1457
    }
Lines 1803-1815 sub AddReturn { Link Here
1803
    my $stat_type = 'return';
1804
    my $stat_type = 'return';
1804
1805
1805
    # get information on item
1806
    # get information on item
1806
    my $item = GetItem( undef, $barcode );
1807
    my $item = Koha::Items->find({ barcode => $barcode });
1807
    unless ($item) {
1808
    unless ($item) {
1808
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1809
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1809
    }
1810
    }
1810
1811
1811
    my $itemnumber = $item->{ itemnumber };
1812
    my $itemnumber = $item->itemnumber;
1812
    my $itemtype = $item->{itype}; # GetItem called effective_itemtype
1813
    my $itemtype = $item->effective_itemtype;
1813
1814
1814
    my $issue  = Koha::Checkouts->find( { itemnumber => $itemnumber } );
1815
    my $issue  = Koha::Checkouts->find( { itemnumber => $itemnumber } );
1815
    if ( $issue ) {
1816
    if ( $issue ) {
Lines 1829-1849 sub AddReturn { Link Here
1829
        }
1830
        }
1830
    }
1831
    }
1831
1832
1832
    if ( $item->{'location'} eq 'PROC' ) {
1833
    my $item_unblessed = $item->unblessed;
1834
    if ( $item->location eq 'PROC' ) {
1833
        if ( C4::Context->preference("InProcessingToShelvingCart") ) {
1835
        if ( C4::Context->preference("InProcessingToShelvingCart") ) {
1834
            $item->{'location'} = 'CART';
1836
            $item_unblessed->{location} = 'CART';
1835
        }
1837
        }
1836
        else {
1838
        else {
1837
            $item->{location} = $item->{permanent_location};
1839
            $item_unblessed->{location} = $item->permanent_location;
1838
        }
1840
        }
1839
1841
1840
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, { log_action => 0 } );
1842
        ModItem( $item_unblessed, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
1841
    }
1843
    }
1842
1844
1843
        # full item data, but no borrowernumber or checkout info (no issue)
1845
        # full item data, but no borrowernumber or checkout info (no issue)
1844
    my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
1846
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
1845
        # get the proper branch to which to return the item
1847
        # get the proper branch to which to return the item
1846
    my $returnbranch = $item->{$hbr} || $branch ;
1848
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
1847
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1849
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1848
1850
1849
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
1851
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
Lines 1859-1866 sub AddReturn { Link Here
1859
        }
1861
        }
1860
        else {
1862
        else {
1861
            foreach my $key ( keys %$rules ) {
1863
            foreach my $key ( keys %$rules ) {
1862
                if ( $item->{notforloan} eq $key ) {
1864
                if ( $item->notforloan eq $key ) {
1863
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1865
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1864
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
1866
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
1865
                    last;
1867
                    last;
1866
                }
1868
                }
Lines 1869-1875 sub AddReturn { Link Here
1869
    }
1871
    }
1870
1872
1871
    # check if the return is allowed at this branch
1873
    # check if the return is allowed at this branch
1872
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
1874
    my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch);
1873
    unless ($returnallowed){
1875
    unless ($returnallowed){
1874
        $messages->{'Wrongbranch'} = {
1876
        $messages->{'Wrongbranch'} = {
1875
            Wrongbranch => $branch,
1877
            Wrongbranch => $branch,
Lines 1879-1890 sub AddReturn { Link Here
1879
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1881
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1880
    }
1882
    }
1881
1883
1882
    if ( $item->{'withdrawn'} ) { # book has been cancelled
1884
    if ( $item->withdrawn ) { # book has been cancelled
1883
        $messages->{'withdrawn'} = 1;
1885
        $messages->{'withdrawn'} = 1;
1884
        $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems");
1886
        $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems");
1885
    }
1887
    }
1886
1888
1887
    if ( $item->{itemlost} and C4::Context->preference("BlockReturnOfLostItems") ) {
1889
    if ( $item->itemlost and C4::Context->preference("BlockReturnOfLostItems") ) {
1888
        $doreturn = 0;
1890
        $doreturn = 0;
1889
    }
1891
    }
1890
1892
Lines 1901-1907 sub AddReturn { Link Here
1901
            # don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
1903
            # don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
1902
            # FIXME: check issuedate > returndate, factoring in holidays
1904
            # FIXME: check issuedate > returndate, factoring in holidays
1903
1905
1904
            $circControlBranch = _GetCircControlBranch($item,$patron_unblessed);
1906
            $circControlBranch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
1905
            $is_overdue = $issue->is_overdue( $dropboxdate );
1907
            $is_overdue = $issue->is_overdue( $dropboxdate );
1906
        } else {
1908
        } else {
1907
            $is_overdue = $issue->is_overdue;
1909
            $is_overdue = $issue->is_overdue;
Lines 1909-1920 sub AddReturn { Link Here
1909
1911
1910
        if ($patron) {
1912
        if ($patron) {
1911
            eval {
1913
            eval {
1912
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1914
                MarkIssueReturned( $borrowernumber, $item->itemnumber,
1913
                    $circControlBranch, $return_date, $patron->privacy );
1915
                    $circControlBranch, $return_date, $patron->privacy );
1914
            };
1916
            };
1915
            unless ( $@ ) {
1917
            unless ( $@ ) {
1916
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1918
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1917
                    _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } );
1919
                    _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } );
1918
                }
1920
                }
1919
            } else {
1921
            } else {
1920
                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 );
1922
                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 1927-1984 sub AddReturn { Link Here
1927
1929
1928
        }
1930
        }
1929
1931
1930
        ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, { log_action => 0 } );
1932
        ModItem( { onloan => undef }, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
1931
    }
1933
    }
1932
1934
1933
    # the holdingbranch is updated if the document is returned to another location.
1935
    # the holdingbranch is updated if the document is returned to another location.
1934
    # this is always done regardless of whether the item was on loan or not
1936
    # this is always done regardless of whether the item was on loan or not
1935
    my $item_holding_branch = $item->{ holdingbranch };
1937
    my $item_holding_branch = $item->holdingbranch;
1936
    if ($item->{'holdingbranch'} ne $branch) {
1938
    if ($item->holdingbranch ne $branch) {
1937
        UpdateHoldingbranch($branch, $item->{'itemnumber'});
1939
        UpdateHoldingbranch($branch, $item->itemnumber);
1938
        $item->{'holdingbranch'} = $branch; # update item data holdingbranch too
1940
        $item_unblessed->{'holdingbranch'} = $branch; # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later
1939
    }
1941
    }
1940
1942
1941
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
1943
    my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
1942
    ModDateLastSeen( $item->{itemnumber}, $leave_item_lost );
1944
    ModDateLastSeen( $item->itemnumber, $leave_item_lost );
1943
1945
1944
    # check if we have a transfer for this document
1946
    # check if we have a transfer for this document
1945
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->{'itemnumber'} );
1947
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber );
1946
1948
1947
    # if we have a transfer to do, we update the line of transfers with the datearrived
1949
    # if we have a transfer to do, we update the line of transfers with the datearrived
1948
    my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->{'itemnumber'} );
1950
    my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber );
1949
    if ($datesent) {
1951
    if ($datesent) {
1950
        if ( $tobranch eq $branch ) {
1952
        if ( $tobranch eq $branch ) {
1951
            my $sth = C4::Context->dbh->prepare(
1953
            my $sth = C4::Context->dbh->prepare(
1952
                "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
1954
                "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
1953
            );
1955
            );
1954
            $sth->execute( $item->{'itemnumber'} );
1956
            $sth->execute( $item->itemnumber );
1955
            # if we have a reservation with valid transfer, we can set it's status to 'W'
1957
            # if we have a reservation with valid transfer, we can set it's status to 'W'
1956
            ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
1958
            ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
1957
            C4::Reserves::ModReserveStatus($item->{'itemnumber'}, 'W');
1959
            C4::Reserves::ModReserveStatus($item->itemnumber, 'W');
1958
        } else {
1960
        } else {
1959
            $messages->{'WrongTransfer'}     = $tobranch;
1961
            $messages->{'WrongTransfer'}     = $tobranch;
1960
            $messages->{'WrongTransferItem'} = $item->{'itemnumber'};
1962
            $messages->{'WrongTransferItem'} = $item->itemnumber;
1961
        }
1963
        }
1962
        $validTransfert = 1;
1964
        $validTransfert = 1;
1963
    } else {
1965
    } else {
1964
        ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
1966
        ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
1965
    }
1967
    }
1966
1968
1967
    # fix up the accounts.....
1969
    # fix up the accounts.....
1968
    if ( $item->{'itemlost'} ) {
1970
    if ( $item->itemlost ) {
1969
        $messages->{'WasLost'} = 1;
1971
        $messages->{'WasLost'} = 1;
1970
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1972
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1971
            if (
1973
            if (
1972
                Koha::RefundLostItemFeeRules->should_refund(
1974
                Koha::RefundLostItemFeeRules->should_refund(
1973
                    {
1975
                    {
1974
                        current_branch      => C4::Context->userenv->{branch},
1976
                        current_branch      => C4::Context->userenv->{branch},
1975
                        item_home_branch    => $item->{homebranch},
1977
                        item_home_branch    => $item->homebranch,
1976
                        item_holding_branch => $item_holding_branch
1978
                        item_holding_branch => $item_holding_branch
1977
                    }
1979
                    }
1978
                )
1980
                )
1979
              )
1981
              )
1980
            {
1982
            {
1981
                _FixAccountForLostAndReturned( $item->{'itemnumber'},
1983
                _FixAccountForLostAndReturned( $item->itemnumber,
1982
                    $borrowernumber, $barcode );
1984
                    $borrowernumber, $barcode );
1983
                $messages->{'LostItemFeeRefunded'} = 1;
1985
                $messages->{'LostItemFeeRefunded'} = 1;
1984
            }
1986
            }
Lines 1987-2000 sub AddReturn { Link Here
1987
1989
1988
    # fix up the overdues in accounts...
1990
    # fix up the overdues in accounts...
1989
    if ($borrowernumber) {
1991
    if ($borrowernumber) {
1990
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
1992
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->itemnumber, $exemptfine, $dropbox);
1991
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
1993
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->itemnumber...) failed!";  # zero is OK, check defined
1992
1994
1993
        if ( $issue and $issue->is_overdue ) {
1995
        if ( $issue and $issue->is_overdue ) {
1994
        # fix fine days
1996
        # fix fine days
1995
            $today = dt_from_string($return_date) if $return_date;
1997
            $today = dt_from_string($return_date) if $return_date;
1996
            $today = $dropboxdate if $dropbox;
1998
            $today = $dropboxdate if $dropbox;
1997
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today );
1999
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item_unblessed, dt_from_string($issue->date_due), $today );
1998
            if ($reminder){
2000
            if ($reminder){
1999
                $messages->{'PrevDebarred'} = $debardate;
2001
                $messages->{'PrevDebarred'} = $debardate;
2000
            } else {
2002
            } else {
Lines 2019-2025 sub AddReturn { Link Here
2019
    # if we don't have a reserve with the status W, we launch the Checkreserves routine
2021
    # if we don't have a reserve with the status W, we launch the Checkreserves routine
2020
    my ($resfound, $resrec);
2022
    my ($resfound, $resrec);
2021
    my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
2023
    my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
2022
    ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'}, undef, $lookahead ) unless ( $item->{'withdrawn'} );
2024
    ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->itemnumber, undef, $lookahead ) unless ( $item->withdrawn );
2023
    if ($resfound) {
2025
    if ($resfound) {
2024
          $resrec->{'ResFound'} = $resfound;
2026
          $resrec->{'ResFound'} = $resfound;
2025
        $messages->{'ResFound'} = $resrec;
2027
        $messages->{'ResFound'} = $resrec;
Lines 2032-2038 sub AddReturn { Link Here
2032
        itemnumber     => $itemnumber,
2034
        itemnumber     => $itemnumber,
2033
        itemtype       => $itemtype,
2035
        itemtype       => $itemtype,
2034
        borrowernumber => $borrowernumber,
2036
        borrowernumber => $borrowernumber,
2035
        ccode          => $item->{ ccode }
2037
        ccode          => $item->ccode,
2036
    });
2038
    });
2037
2039
2038
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
2040
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
Lines 2041-2059 sub AddReturn { Link Here
2041
        my %conditions = (
2043
        my %conditions = (
2042
            branchcode   => $branch,
2044
            branchcode   => $branch,
2043
            categorycode => $patron->categorycode,
2045
            categorycode => $patron->categorycode,
2044
            item_type    => $item->{itype},
2046
            item_type    => $itemtype,
2045
            notification => 'CHECKIN',
2047
            notification => 'CHECKIN',
2046
        );
2048
        );
2047
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2049
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2048
            SendCirculationAlert({
2050
            SendCirculationAlert({
2049
                type     => 'CHECKIN',
2051
                type     => 'CHECKIN',
2050
                item     => $item,
2052
                item     => $item_unblessed,
2051
                borrower => $patron->unblessed,
2053
                borrower => $patron->unblessed,
2052
                branch   => $branch,
2054
                branch   => $branch,
2053
            });
2055
            });
2054
        }
2056
        }
2055
2057
2056
        logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
2058
        logaction("CIRCULATION", "RETURN", $borrowernumber, $item->itemnumber)
2057
            if C4::Context->preference("ReturnLog");
2059
            if C4::Context->preference("ReturnLog");
2058
        }
2060
        }
2059
2061
Lines 2069-2081 sub AddReturn { Link Here
2069
2071
2070
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
2072
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
2071
    if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
2073
    if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
2074
        my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType");
2072
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
2075
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
2073
            (C4::Context->preference("UseBranchTransferLimits") and
2076
            (C4::Context->preference("UseBranchTransferLimits") and
2074
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->{C4::Context->preference("BranchTransferLimitsType")} )
2077
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2075
           )) {
2078
           )) {
2076
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $returnbranch;
2079
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch;
2077
            $debug and warn "item: " . Dumper($item);
2080
            $debug and warn "item: " . Dumper($item_unblessed);
2078
            ModItemTransfer($item->{'itemnumber'}, $branch, $returnbranch);
2081
            ModItemTransfer($item->itemnumber, $branch, $returnbranch);
2079
            $messages->{'WasTransfered'} = 1;
2082
            $messages->{'WasTransfered'} = 1;
2080
        } else {
2083
        } else {
2081
            $messages->{'NeedsTransfer'} = $returnbranch;
2084
            $messages->{'NeedsTransfer'} = $returnbranch;
Lines 2612-2618 sub CanBookBeRenewed { Link Here
2612
    my $dbh    = C4::Context->dbh;
2615
    my $dbh    = C4::Context->dbh;
2613
    my $renews = 1;
2616
    my $renews = 1;
2614
2617
2615
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2618
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2616
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2619
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2617
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2620
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2618
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
2621
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
Lines 2670-2676 sub CanBookBeRenewed { Link Here
2670
            my @reservable;
2673
            my @reservable;
2671
            my %borrowers;
2674
            my %borrowers;
2672
            ITEM: foreach my $i (@itemnumbers) {
2675
            ITEM: foreach my $i (@itemnumbers) {
2673
                my $item = GetItem($i);
2676
                my $item = Koha::Items->find($i)->unblessed;
2674
                next if IsItemOnHoldAndFound($i);
2677
                next if IsItemOnHoldAndFound($i);
2675
                for my $b (@borrowernumbers) {
2678
                for my $b (@borrowernumbers) {
2676
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
2679
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
Lines 2691-2700 sub CanBookBeRenewed { Link Here
2691
2694
2692
    return ( 1, undef ) if $override_limit;
2695
    return ( 1, undef ) if $override_limit;
2693
2696
2694
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
2697
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2695
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2698
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2696
        {   categorycode => $patron->categorycode,
2699
        {   categorycode => $patron->categorycode,
2697
            itemtype     => $item->{itype},
2700
            itemtype     => $item->effective_itemtype,
2698
            branchcode   => $branchcode
2701
            branchcode   => $branchcode
2699
        }
2702
        }
2700
    );
2703
    );
Lines 2818-2832 sub AddRenewal { Link Here
2818
    my $datedue         = shift;
2821
    my $datedue         = shift;
2819
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2822
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2820
2823
2821
    my $item   = GetItem($itemnumber) or return;
2824
    my $item   = Koha::Items->find($itemnumber) or return;
2822
    my $item_object = Koha::Items->find( $itemnumber ); # Should replace $item
2825
    my $biblio = $item->biblio;
2823
    my $biblio = $item_object->biblio;
2826
    my $issue  = $item->checkout;
2827
    my $item_unblessed = $item->unblessed;
2824
2828
2825
    my $dbh = C4::Context->dbh;
2829
    my $dbh = C4::Context->dbh;
2826
2830
2827
    # Find the issues record for this book
2828
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
2829
2830
    return unless $issue;
2831
    return unless $issue;
2831
2832
2832
    $borrowernumber ||= $issue->borrowernumber;
2833
    $borrowernumber ||= $issue->borrowernumber;
Lines 2840-2846 sub AddRenewal { Link Here
2840
    my $patron_unblessed = $patron->unblessed;
2841
    my $patron_unblessed = $patron->unblessed;
2841
2842
2842
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2843
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2843
        _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
2844
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2844
    }
2845
    }
2845
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2846
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2846
2847
Lines 2849-2859 sub AddRenewal { Link Here
2849
    # based on the value of the RenewalPeriodBase syspref.
2850
    # based on the value of the RenewalPeriodBase syspref.
2850
    unless ($datedue) {
2851
    unless ($datedue) {
2851
2852
2852
        my $itemtype = $item_object->effective_itemtype;
2853
        my $itemtype = $item->effective_itemtype;
2853
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2854
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2854
                                        dt_from_string( $issue->date_due, 'sql' ) :
2855
                                        dt_from_string( $issue->date_due, 'sql' ) :
2855
                                        DateTime->now( time_zone => C4::Context->tz());
2856
                                        DateTime->now( time_zone => C4::Context->tz());
2856
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2857
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item_unblessed, $patron_unblessed), $patron_unblessed, 'is a renewal');
2857
    }
2858
    }
2858
2859
2859
    # Update the issues record to have the new due date, and a new count
2860
    # Update the issues record to have the new due date, and a new count
Lines 2867-2874 sub AddRenewal { Link Here
2867
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2868
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2868
2869
2869
    # Update the renewal count on the item, and tell zebra to reindex
2870
    # Update the renewal count on the item, and tell zebra to reindex
2870
    $renews = $item->{renewals} + 1;
2871
    $renews = $item->renewals + 1;
2871
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2872
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } );
2872
2873
2873
    # Charge a new rental fee, if applicable?
2874
    # Charge a new rental fee, if applicable?
2874
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2875
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
Lines 2883-2889 sub AddRenewal { Link Here
2883
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2884
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2884
        );
2885
        );
2885
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2886
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2886
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2887
            "Renewal of Rental Item " . $biblio->title . " " . $item->barcode,
2887
            'Rent', $charge, $itemnumber );
2888
            'Rent', $charge, $itemnumber );
2888
    }
2889
    }
2889
2890
Lines 2893-2906 sub AddRenewal { Link Here
2893
        my %conditions        = (
2894
        my %conditions        = (
2894
            branchcode   => $branch,
2895
            branchcode   => $branch,
2895
            categorycode => $patron->categorycode,
2896
            categorycode => $patron->categorycode,
2896
            item_type    => $item->{itype},
2897
            item_type    => $item->effective_itemtype,
2897
            notification => 'CHECKOUT',
2898
            notification => 'CHECKOUT',
2898
        );
2899
        );
2899
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2900
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2900
            SendCirculationAlert(
2901
            SendCirculationAlert(
2901
                {
2902
                {
2902
                    type     => 'RENEWAL',
2903
                    type     => 'RENEWAL',
2903
                    item     => $item,
2904
                    item     => $item_unblessed,
2904
                    borrower => $patron->unblessed,
2905
                    borrower => $patron->unblessed,
2905
                    branch   => $branch,
2906
                    branch   => $branch,
2906
                }
2907
                }
Lines 2928-2937 sub AddRenewal { Link Here
2928
            type           => 'renew',
2929
            type           => 'renew',
2929
            amount         => $charge,
2930
            amount         => $charge,
2930
            itemnumber     => $itemnumber,
2931
            itemnumber     => $itemnumber,
2931
            itemtype       => $item->{itype},
2932
            itemtype       => $item->effective_itemtype,
2932
            location       => $item->{location},
2933
            location       => $item->location,
2933
            borrowernumber => $borrowernumber,
2934
            borrowernumber => $borrowernumber,
2934
            ccode          => $item->{'ccode'}
2935
            ccode          => $item->ccode,
2935
        }
2936
        }
2936
    );
2937
    );
2937
2938
Lines 2949-2955 sub GetRenewCount { Link Here
2949
    my $renewsleft    = 0;
2950
    my $renewsleft    = 0;
2950
2951
2951
    my $patron = Koha::Patrons->find( $bornum );
2952
    my $patron = Koha::Patrons->find( $bornum );
2952
    my $item     = GetItem($itemno);
2953
    my $item   = Koha::Items->find($itemno);
2953
2954
2954
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2955
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2955
2956
Lines 2966-2976 sub GetRenewCount { Link Here
2966
    my $data = $sth->fetchrow_hashref;
2967
    my $data = $sth->fetchrow_hashref;
2967
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2968
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2968
    # $item and $borrower should be calculated
2969
    # $item and $borrower should be calculated
2969
    my $branchcode = _GetCircControlBranch($item, $patron->unblessed);
2970
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
2970
2971
2971
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2972
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2972
        {   categorycode => $patron->categorycode,
2973
        {   categorycode => $patron->categorycode,
2973
            itemtype     => $item->{itype},
2974
            itemtype     => $item->effective_itemtype,
2974
            branchcode   => $branchcode
2975
            branchcode   => $branchcode
2975
        }
2976
        }
2976
    );
2977
    );
Lines 3005-3021 sub GetSoonestRenewDate { Link Here
3005
3006
3006
    my $dbh = C4::Context->dbh;
3007
    my $dbh = C4::Context->dbh;
3007
3008
3008
    my $item      = GetItem($itemnumber)      or return;
3009
    my $item      = Koha::Items->find($itemnumber)      or return;
3009
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3010
    my $itemissue = $item->checkout or return;
3010
3011
3011
    $borrowernumber ||= $itemissue->borrowernumber;
3012
    $borrowernumber ||= $itemissue->borrowernumber;
3012
    my $patron = Koha::Patrons->find( $borrowernumber )
3013
    my $patron = Koha::Patrons->find( $borrowernumber )
3013
      or return;
3014
      or return;
3014
3015
3015
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3016
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3016
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3017
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3017
        {   categorycode => $patron->categorycode,
3018
        {   categorycode => $patron->categorycode,
3018
            itemtype     => $item->{itype},
3019
            itemtype     => $item->effective_itemtype,
3019
            branchcode   => $branchcode
3020
            branchcode   => $branchcode
3020
        }
3021
        }
3021
    );
3022
    );
Lines 3064-3080 sub GetLatestAutoRenewDate { Link Here
3064
3065
3065
    my $dbh = C4::Context->dbh;
3066
    my $dbh = C4::Context->dbh;
3066
3067
3067
    my $item      = GetItem($itemnumber)      or return;
3068
    my $item      = Koha::Items->find($itemnumber)  or return;
3068
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3069
    my $itemissue = $item->checkout                 or return;
3069
3070
3070
    $borrowernumber ||= $itemissue->borrowernumber;
3071
    $borrowernumber ||= $itemissue->borrowernumber;
3071
    my $patron = Koha::Patrons->find( $borrowernumber )
3072
    my $patron = Koha::Patrons->find( $borrowernumber )
3072
      or return;
3073
      or return;
3073
3074
3074
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3075
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3075
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3076
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3076
        {   categorycode => $patron->categorycode,
3077
        {   categorycode => $patron->categorycode,
3077
            itemtype     => $item->{itype},
3078
            itemtype     => $item->effective_itemtype,
3078
            branchcode   => $branchcode
3079
            branchcode   => $branchcode
3079
        }
3080
        }
3080
    );
3081
    );
Lines 3651-3658 sub ReturnLostItem{ Link Here
3651
3652
3652
    MarkIssueReturned( $borrowernumber, $itemnum );
3653
    MarkIssueReturned( $borrowernumber, $itemnum );
3653
    my $patron = Koha::Patrons->find( $borrowernumber );
3654
    my $patron = Koha::Patrons->find( $borrowernumber );
3654
    my $item = C4::Items::GetItem( $itemnum );
3655
    my $item = Koha::Items->find($itemnum);
3655
    my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{};
3656
    my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{};
3656
    my @datearr = localtime(time);
3657
    my @datearr = localtime(time);
3657
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3658
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3658
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
3659
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
Lines 3839-3846 sub ProcessOfflinePayment { Link Here
3839
sub TransferSlip {
3840
sub TransferSlip {
3840
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3841
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3841
3842
3842
    my $item =  GetItem( $itemnumber, $barcode )
3843
    my $item =
3843
      or return;
3844
      $itemnumber
3845
      ? Koha::Items->find($itemnumber)
3846
      : Koha::Items->find( { barcode => $barcode } );
3847
3848
    $item or return;
3844
3849
3845
    return C4::Letters::GetPreparedLetter (
3850
    return C4::Letters::GetPreparedLetter (
3846
        module => 'circulation',
3851
        module => 'circulation',
Lines 3848-3855 sub TransferSlip { Link Here
3848
        branchcode => $branch,
3853
        branchcode => $branch,
3849
        tables => {
3854
        tables => {
3850
            'branches'    => $to_branch,
3855
            'branches'    => $to_branch,
3851
            'biblio'      => $item->{biblionumber},
3856
            'biblio'      => $item->biblionumber,
3852
            'items'       => $item,
3857
            'items'       => $item->unblessed,
3853
        },
3858
        },
3854
    );
3859
    );
3855
}
3860
}
(-)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 318-331 sub CanItemBeReserved { Link Here
318
318
319
    # we retrieve borrowers and items informations #
319
    # we retrieve borrowers and items informations #
320
    # item->{itype} will come for biblioitems if necessery
320
    # item->{itype} will come for biblioitems if necessery
321
    my $item       = C4::Items::GetItem($itemnumber);
321
    my $item       = Koha::Items->find($itemnumber);
322
    my $biblio     = Koha::Biblios->find( $item->{biblionumber} );
322
    my $biblio     = $item->biblio;
323
    my $patron = Koha::Patrons->find( $borrowernumber );
323
    my $patron = Koha::Patrons->find( $borrowernumber );
324
    my $borrower = $patron->unblessed;
324
    my $borrower = $patron->unblessed;
325
325
326
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
326
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
327
    return { status =>'damaged' }
327
    return { status =>'damaged' }
328
      if ( $item->{damaged}
328
      if ( $item->damaged
329
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
329
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
330
330
331
    # Check for the age restriction
331
    # Check for the age restriction
Lines 353-359 sub CanItemBeReserved { Link Here
353
353
354
    if ( $controlbranch eq "ItemHomeLibrary" ) {
354
    if ( $controlbranch eq "ItemHomeLibrary" ) {
355
        $branchfield = "items.homebranch";
355
        $branchfield = "items.homebranch";
356
        $branchcode  = $item->{homebranch};
356
        $branchcode  = $item->homebranch;
357
    }
357
    }
358
    elsif ( $controlbranch eq "PatronLibrary" ) {
358
    elsif ( $controlbranch eq "PatronLibrary" ) {
359
        $branchfield = "borrowers.branchcode";
359
        $branchfield = "borrowers.branchcode";
Lines 361-367 sub CanItemBeReserved { Link Here
361
    }
361
    }
362
362
363
    # we retrieve rights
363
    # we retrieve rights
364
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) {
364
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
365
        $ruleitemtype     = $rights->{itemtype};
365
        $ruleitemtype     = $rights->{itemtype};
366
        $allowedreserves  = $rights->{reservesallowed};
366
        $allowedreserves  = $rights->{reservesallowed};
367
        $holds_per_record = $rights->{holds_per_record};
367
        $holds_per_record = $rights->{holds_per_record};
Lines 371-377 sub CanItemBeReserved { Link Here
371
        $ruleitemtype = '*';
371
        $ruleitemtype = '*';
372
    }
372
    }
373
373
374
    $item = Koha::Items->find( $itemnumber );
375
    my $holds = Koha::Holds->search(
374
    my $holds = Koha::Holds->search(
376
        {
375
        {
377
            borrowernumber => $borrowernumber,
376
            borrowernumber => $borrowernumber,
Lines 447-453 sub CanItemBeReserved { Link Here
447
    my $circ_control_branch =
446
    my $circ_control_branch =
448
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
447
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
449
    my $branchitemrule =
448
    my $branchitemrule =
450
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype );
449
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype ); # FIXME Should not be item->effective_itemtype?
451
450
452
    if ( $branchitemrule->{holdallowed} == 0 ) {
451
    if ( $branchitemrule->{holdallowed} == 0 ) {
453
        return { status => 'notReservable' };
452
        return { status => 'notReservable' };
Lines 464-471 sub CanItemBeReserved { Link Here
464
    if ( C4::Context->preference('IndependentBranches')
463
    if ( C4::Context->preference('IndependentBranches')
465
        and !C4::Context->preference('canreservefromotherbranches') )
464
        and !C4::Context->preference('canreservefromotherbranches') )
466
    {
465
    {
467
        my $itembranch = $item->homebranch;
466
        if ( $item->homebranch ne $borrower->{branchcode} ) {
468
        if ( $itembranch ne $borrower->{branchcode} ) {
469
            return { status => 'cannotReserveFromOtherBranches' };
467
            return { status => 'cannotReserveFromOtherBranches' };
470
        }
468
        }
471
    }
469
    }
Lines 522-529 sub GetOtherReserves { Link Here
522
    my $nextreservinfo;
520
    my $nextreservinfo;
523
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
521
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
524
    if ($checkreserves) {
522
    if ($checkreserves) {
525
        my $iteminfo = GetItem($itemnumber);
523
        my $item = Koha::Items->find($itemnumber);
526
        if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
524
        if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) {
527
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
525
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
528
            #minus priorities of others reservs
526
            #minus priorities of others reservs
529
            ModReserveMinusPriority(
527
            ModReserveMinusPriority(
Lines 534-540 sub GetOtherReserves { Link Here
534
            #launch the subroutine dotransfer
532
            #launch the subroutine dotransfer
535
            C4::Items::ModItemTransfer(
533
            C4::Items::ModItemTransfer(
536
                $itemnumber,
534
                $itemnumber,
537
                $iteminfo->{'holdingbranch'},
535
                $item->holdingbranch,
538
                $checkreserves->{'branchcode'}
536
                $checkreserves->{'branchcode'}
539
              ),
537
              ),
540
              ;
538
              ;
Lines 759-773 sub CheckReserves { Link Here
759
                }
757
                }
760
            } else {
758
            } else {
761
                my $patron;
759
                my $patron;
762
                my $iteminfo;
760
                my $item;
763
                my $local_hold_match;
761
                my $local_hold_match;
764
762
765
                if ($LocalHoldsPriority) {
763
                if ($LocalHoldsPriority) {
766
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
764
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
767
                    $iteminfo = C4::Items::GetItem($itemnumber);
765
                    $item = Koha::Items->find($itemnumber);
768
766
769
                    my $local_holds_priority_item_branchcode =
767
                    my $local_holds_priority_item_branchcode =
770
                      $iteminfo->{$LocalHoldsPriorityItemControl};
768
                      $item->$LocalHoldsPriorityItemControl;
771
                    my $local_holds_priority_patron_branchcode =
769
                    my $local_holds_priority_patron_branchcode =
772
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
770
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
773
                      ? $res->{branchcode}
771
                      ? $res->{branchcode}
Lines 781-794 sub CheckReserves { Link Here
781
779
782
                # See if this item is more important than what we've got so far
780
                # See if this item is more important than what we've got so far
783
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
781
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
784
                    $iteminfo ||= C4::Items::GetItem($itemnumber);
782
                    $item ||= Koha::Items->find($itemnumber);
785
                    next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
783
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
786
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
784
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
787
                    my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
785
                    my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
788
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
786
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
789
                    next if ($branchitemrule->{'holdallowed'} == 0);
787
                    next if ($branchitemrule->{'holdallowed'} == 0);
790
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
788
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
791
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
789
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
790
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
792
                    $priority = $res->{'priority'};
791
                    $priority = $res->{'priority'};
793
                    $highest  = $res;
792
                    $highest  = $res;
794
                    last if $local_hold_match;
793
                    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 695-706 if ($op eq "additem") { Link Here
695
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
700
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
696
        push @errors,"barcode_not_unique";
701
        push @errors,"barcode_not_unique";
697
    } else {
702
    } else {
698
        my $item = GetItem( $itemnumber );
703
        my $item = Koha::Items->find($itemnumber );
699
        my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber);
704
        my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber);
700
        $itemnumber = q{};
705
        $itemnumber = q{};
701
        my $olditemlost = $item->{itemlost};
706
        my $olditemlost = $item->itemlost;
702
        my $newitemlost = $newitem->{itemlost};
707
        my $newitemlost = $newitem->{itemlost};
703
        LostItem( $item->{itemnumber}, 'additem' )
708
        LostItem( $item->itemnumber, 'additem' )
704
            if $newitemlost && $newitemlost ge '1' && !$olditemlost;
709
            if $newitemlost && $newitemlost ge '1' && !$olditemlost;
705
    }
710
    }
706
    $nextop="additem";
711
    $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 / +5 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 104-110 my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed) = ( Link Here
104
105
105
my $issuenoconfirm = 1; #don't need to confirm on issue.
106
my $issuenoconfirm = 1; #don't need to confirm on issue.
106
my $issuer   = Koha::Patrons->find( $issuerid )->unblessed;
107
my $issuer   = Koha::Patrons->find( $issuerid )->unblessed;
107
my $item     = GetItem(undef,$barcode);
108
my $item     = Koha::Items->find({ barcode => $barcode });
108
if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) {
109
if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) {
109
    my $dbh = C4::Context->dbh;
110
    my $dbh = C4::Context->dbh;
110
    my $resval;
111
    my $resval;
Lines 157-163 elsif ( $patron and $op eq "checkout" ) { Link Here
157
        $template->param(
158
        $template->param(
158
            impossible                => $issue_error,
159
            impossible                => $issue_error,
159
            "circ_error_$issue_error" => 1,
160
            "circ_error_$issue_error" => 1,
160
            title                     => $item->{title},
161
            title                     => $item->biblio->title, # FIXME Need to be backport! GetItem did not return the biblio's title
161
            hide_main                 => 1,
162
            hide_main                 => 1,
162
        );
163
        );
163
        if ($issue_error eq 'DEBT') {
164
        if ($issue_error eq 'DEBT') {
Lines 174-180 elsif ( $patron and $op eq "checkout" ) { Link Here
174
    } elsif ( $needconfirm->{RENEW_ISSUE} ) {
175
    } elsif ( $needconfirm->{RENEW_ISSUE} ) {
175
        if ($confirmed) {
176
        if ($confirmed) {
176
            #warn "renewing";
177
            #warn "renewing";
177
            AddRenewal( $borrower->{borrowernumber}, $item->{itemnumber} );
178
            AddRenewal( $borrower->{borrowernumber}, $item->itemnumber );
178
        } else {
179
        } else {
179
            #warn "renew confirmation";
180
            #warn "renew confirmation";
180
            $template->param(
181
            $template->param(
Lines 235-241 elsif ( $patron and $op eq "checkout" ) { Link Here
235
            $confirm_required = 1;
236
            $confirm_required = 1;
236
            #warn "issue confirmation";
237
            #warn "issue confirmation";
237
            $template->param(
238
            $template->param(
238
                confirm    => "Issuing title: " . $item->{title},
239
                confirm    => "Issuing title: " . $item->biblio->title,
239
                barcode    => $barcode,
240
                barcode    => $barcode,
240
                hide_main  => 1,
241
                hide_main  => 1,
241
                inputfocus => 'confirm',
242
                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 35-40 use C4::Overdues qw(UpdateFine CalcFine); Link Here
35
use Koha::DateUtils;
35
use Koha::DateUtils;
36
use Koha::Database;
36
use Koha::Database;
37
use Koha::IssuingRules;
37
use Koha::IssuingRules;
38
use Koha::Items;
38
use Koha::Checkouts;
39
use Koha::Checkouts;
39
use Koha::Patrons;
40
use Koha::Patrons;
40
use Koha::Subscriptions;
41
use Koha::Subscriptions;
Lines 484-490 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
484
    my $passeddatedue1 = AddIssue($renewing_borrower, $barcode7, $five_weeks_ago);
485
    my $passeddatedue1 = AddIssue($renewing_borrower, $barcode7, $five_weeks_ago);
485
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
486
    is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
486
487
487
    my ( $fine ) = CalcFine( GetItem(undef, $barcode7), $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
488
    my $item = Koha::Items->find({barcode => $barcode7});
489
    my ( $fine ) = CalcFine( $item->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
488
    C4::Overdues::UpdateFine(
490
    C4::Overdues::UpdateFine(
489
        {
491
        {
490
            issue_id       => $passeddatedue1->id(),
492
            issue_id       => $passeddatedue1->id(),
Lines 857-863 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
857
    $line = Koha::Account::Lines->find($line->id);
859
    $line = Koha::Account::Lines->find($line->id);
858
    is( $line->accounttype, 'F', 'Account type correctly changed from FU to F' );
860
    is( $line->accounttype, 'F', 'Account type correctly changed from FU to F' );
859
861
860
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
862
    $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
861
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
863
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
862
    my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
864
    my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
863
    is( $checkout, undef, 'LostItem called with forced return has checked in the item' );
865
    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 68-79 my ( undef, undef, $itemnumber ) = AddItem( Link Here
68
    $biblionumber
69
    $biblionumber
69
);
70
);
70
71
71
my $item = GetItem( $itemnumber );
72
my $item = Koha::Items->find( $itemnumber );
72
73
73
is ( IsItemIssued( $item->{itemnumber} ), 0, "item is not on loan at first" );
74
is ( IsItemIssued( $item->itemnumber ), 0, "item is not on loan at first" );
74
75
75
AddIssue($borrower, 'i_dont_exist');
76
AddIssue($borrower, 'i_dont_exist');
76
is ( IsItemIssued( $item->{itemnumber} ), 1, "item is now on loan" );
77
is ( IsItemIssued( $item->itemnumber ), 1, "item is now on loan" );
77
78
78
is(
79
is(
79
    DelItemCheck( $biblionumber, $itemnumber),
80
    DelItemCheck( $biblionumber, $itemnumber),
Lines 82-88 is( Link Here
82
);
83
);
83
84
84
AddReturn('i_dont_exist', $library->{branchcode});
85
AddReturn('i_dont_exist', $library->{branchcode});
85
is ( IsItemIssued( $item->{itemnumber} ), 0, "item has been returned" );
86
is ( IsItemIssued( $item->itemnumber ), 0, "item has been returned" );
86
87
87
is(
88
is(
88
    DelItemCheck( $biblionumber, $itemnumber),
89
    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 358-374 my $itemnumber; Link Here
358
359
359
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
360
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
360
AddReturn( 'barcode_3', $branchcode_1 );
361
AddReturn( 'barcode_3', $branchcode_1 );
361
my $item = GetItem( $itemnumber );
362
my $item = Koha::Items->find( $itemnumber );
362
ok( $item->{notforloan} eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' );
363
ok( $item->notforloan eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' );
363
364
364
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', '1: 9' );
365
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', '1: 9' );
365
AddReturn( 'barcode_3', $branchcode_1 );
366
AddReturn( 'barcode_3', $branchcode_1 );
366
$item = GetItem( $itemnumber );
367
$item = Koha::Items->find( $itemnumber );
367
ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} );
368
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} );
368
369
369
AddReturn( 'barcode_3', $branchcode_1 );
370
AddReturn( 'barcode_3', $branchcode_1 );
370
$item = GetItem( $itemnumber );
371
$item = Koha::Items->find( $itemnumber );
371
ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
372
ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
372
373
373
# Bug 14640 - Cancel the hold on checking out if asked
374
# Bug 14640 - Cancel the hold on checking out if asked
374
my $reserve_id = AddReserve($branchcode_1, $borrower_id1, $biblionumber,
375
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 79-85 my $itemnumber1 = Link Here
79
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
80
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
80
  or BAIL_OUT("Cannot find newly created item");
81
  or BAIL_OUT("Cannot find newly created item");
81
82
82
my $item1 = GetItem( $itemnumber1 );
83
my $item1 = Koha::Items->find( $itemnumber1 )->unblessed;
83
84
84
$dbh->do("
85
$dbh->do("
85
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
86
    INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
Lines 90-96 my $itemnumber2 = Link Here
90
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC")
91
  $dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC")
91
  or BAIL_OUT("Cannot find newly created item");
92
  or BAIL_OUT("Cannot find newly created item");
92
93
93
my $item2 = GetItem( $itemnumber2 );
94
my $item2 = Koha::Items->find( $itemnumber2 )->unblessed;
94
95
95
$dbh->do("DELETE FROM issuingrules");
96
$dbh->do("DELETE FROM issuingrules");
96
my $rule = Koha::IssuingRule->new(
97
my $rule = Koha::IssuingRule->new(
Lines 134-141 AddReturn( $item1->{barcode} ); Link Here
134
        subtest 'Item is available at a different library' => sub {
135
        subtest 'Item is available at a different library' => sub {
135
            plan tests => 4;
136
            plan tests => 4;
136
137
137
            Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_B, holdingbranch => $library_B })->store;
138
            $item1 = Koha::Items->find( $item1->{itemnumber} );
138
            $item1 = GetItem( $itemnumber1 );
139
            $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store;
140
            $item1 = $item1->unblessed;
139
            #Scenario is:
141
            #Scenario is:
140
            #One shelf holds is 'If all unavailable'/2
142
            #One shelf holds is 'If all unavailable'/2
141
            #Item 1 homebranch library B is available
143
            #Item 1 homebranch library B is available
Lines 174-181 AddReturn( $item1->{barcode} ); Link Here
174
        subtest 'Item is available at the same library' => sub {
176
        subtest 'Item is available at the same library' => sub {
175
            plan tests => 4;
177
            plan tests => 4;
176
178
177
            Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_A, holdingbranch => $library_A })->store;
179
            $item1 = Koha::Items->find( $item1->{itemnumber} );
178
            $item1 = GetItem( $itemnumber1 );
180
            $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store;
181
            $item1 = $item1->unblessed;
179
            #Scenario is:
182
            #Scenario is:
180
            #One shelf holds is 'If all unavailable'/2
183
            #One shelf holds is 'If all unavailable'/2
181
            #Item 1 homebranch library A is available
184
            #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 539-545 is( C4::Reserves::CanBookBeReserved($borrowernumber, $biblionumber)->{status} , Link Here
539
####### EO Bug 13113 <<<
540
####### EO Bug 13113 <<<
540
       ####
541
       ####
541
542
542
$item = GetItem($itemnumber);
543
$item = Koha::Items->find($itemnumber)->unblessed;
543
544
544
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
545
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
545
546
(-)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 531-537 sub BuildItemsData{ Link Here
531
		my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
533
		my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
532
		my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
534
		my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
533
		foreach my $itemnumber (@itemnumbers){
535
		foreach my $itemnumber (@itemnumbers){
534
			my $itemdata=GetItem($itemnumber);
536
            my $itemdata = Koha::Items->find($itemnumber);
537
            next unless $itemdata; # Should have been tested earlier, but just in case...
538
            $itemdata = $itemdata->unblessed;
535
			my $itemmarc=Item2Marc($itemdata);
539
			my $itemmarc=Item2Marc($itemdata);
536
			my %this_row;
540
			my %this_row;
537
			foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
541
			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