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

(-)a/C4/Biblio.pm (-6 / +9 lines)
Lines 2196-2205 sub PrepHostMarcField { Link Here
2196
    my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
2196
    my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
2197
    $marcflavour ||="MARC21";
2197
    $marcflavour ||="MARC21";
2198
    
2198
    
2199
    require C4::Items;
2200
    my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
2199
    my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
2201
	my $item = C4::Items::GetItem($hostitemnumber);
2200
    my $item = Koha::Items->find($hostitemnumber);
2202
	
2201
2203
	my $hostmarcfield;
2202
	my $hostmarcfield;
2204
    if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
2203
    if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
2205
	
2204
	
Lines 2222-2228 sub PrepHostMarcField { Link Here
2222
2221
2223
    	#other fields
2222
    	#other fields
2224
        my $ed = $hostrecord->subfield('250','a');
2223
        my $ed = $hostrecord->subfield('250','a');
2225
        my $barcode = $item->{'barcode'};
2224
        my $barcode = $item->barcode;
2226
        my $title = $hostrecord->subfield('245','a');
2225
        my $title = $hostrecord->subfield('245','a');
2227
2226
2228
        # record control number, 001 with 003 and prefix
2227
        # record control number, 001 with 003 and prefix
Lines 2807-2814 sub EmbedItemsInMarcBiblio { Link Here
2807
    require C4::Items;
2806
    require C4::Items;
2808
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2807
    while ( my ($itemnumber) = $sth->fetchrow_array ) {
2809
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2808
        next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
2810
        my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
2809
        my $item;
2811
        push @items, { itemnumber => $itemnumber, item => $i };
2810
        if ( $opachiddenitems ) {
2811
            $item = Koha::Items->find($itemnumber);
2812
            $item = $item ? $item->unblessed : undef;
2813
        }
2814
        push @items, { itemnumber => $itemnumber, item => $item };
2812
    }
2815
    }
2813
    my @hiddenitems =
2816
    my @hiddenitems =
2814
      $opachiddenitems
2817
      $opachiddenitems
(-)a/C4/Circulation.pm (-144 / +149 lines)
Lines 668-684 sub CanBookBeIssued { Link Here
668
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
668
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
669
    my $override_high_holds = $params->{override_high_holds} || 0;
669
    my $override_high_holds = $params->{override_high_holds} || 0;
670
670
671
    my $item = GetItem(undef, $barcode );
671
    my $item = Koha::Items->find({barcode => $barcode });
672
    # MANDATORY CHECKS - unless item exists, nothing else matters
672
    # MANDATORY CHECKS - unless item exists, nothing else matters
673
    unless ( $item ) {
673
    unless ( $item ) {
674
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
674
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
675
    }
675
    }
676
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
676
    return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
677
677
678
    my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
678
    my $item_unblessed = $item->unblessed; # Transition...
679
    my $biblio = Koha::Biblios->find( $item->{biblionumber} );
679
    my $issue = $item->checkout;
680
    my $biblio = $item->biblio;
680
    my $biblioitem = $biblio->biblioitem;
681
    my $biblioitem = $biblio->biblioitem;
681
    my $effective_itemtype = $item->{itype}; # GetItem deals with that
682
    my $effective_itemtype = $item->effective_itemtype;
682
    my $dbh             = C4::Context->dbh;
683
    my $dbh             = C4::Context->dbh;
683
    my $patron_unblessed = $patron->unblessed;
684
    my $patron_unblessed = $patron->unblessed;
684
685
Lines 692-698 sub CanBookBeIssued { Link Here
692
    unless ( $duedate ) {
693
    unless ( $duedate ) {
693
        my $issuedate = $now->clone();
694
        my $issuedate = $now->clone();
694
695
695
        my $branch = _GetCircControlBranch($item, $patron_unblessed);
696
        my $branch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
696
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
697
        $duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
697
698
698
        # Offline circ calls AddIssue directly, doesn't run through here
699
        # Offline circ calls AddIssue directly, doesn't run through here
Lines 711-727 sub CanBookBeIssued { Link Here
711
    #
712
    #
712
    # BORROWER STATUS
713
    # BORROWER STATUS
713
    #
714
    #
714
    if ( $patron->category->category_type eq 'X' && (  $item->{barcode}  )) {
715
    if ( $patron->category->category_type eq 'X' && (  $item->barcode  )) {
715
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
716
    	# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1  .
716
        &UpdateStats({
717
        &UpdateStats({
717
                     branch => C4::Context->userenv->{'branch'},
718
                     branch => C4::Context->userenv->{'branch'},
718
                     type => 'localuse',
719
                     type => 'localuse',
719
                     itemnumber => $item->{'itemnumber'},
720
                     itemnumber => $item->itemnumber,
720
                     itemtype => $effective_itemtype,
721
                     itemtype => $effective_itemtype,
721
                     borrowernumber => $patron->borrowernumber,
722
                     borrowernumber => $patron->borrowernumber,
722
                     ccode => $item->{'ccode'}}
723
                     ccode => $item->ccode}
723
                    );
724
                    );
724
        ModDateLastSeen( $item->{'itemnumber'} );
725
        ModDateLastSeen( $item->itemnumber ); # FIXME Move to Koha::Item
725
        return( { STATS => 1 }, {});
726
        return( { STATS => 1 }, {});
726
    }
727
    }
727
728
Lines 832-838 sub CanBookBeIssued { Link Here
832
        } else {
833
        } else {
833
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
834
            my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
834
                $patron->borrowernumber,
835
                $patron->borrowernumber,
835
                $item->{'itemnumber'},
836
                $item->itemnumber,
836
            );
837
            );
837
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
838
            if ( $CanBookBeRenewed == 0 ) {    # no more renewals allowed
838
                if ( $renewerror eq 'onsite_checkout' ) {
839
                if ( $renewerror eq 'onsite_checkout' ) {
Lines 853-859 sub CanBookBeIssued { Link Here
853
854
854
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
855
        my $patron = Koha::Patrons->find( $issue->borrowernumber );
855
856
856
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
857
        my ( $can_be_returned, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
857
858
858
        unless ( $can_be_returned ) {
859
        unless ( $can_be_returned ) {
859
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
860
            $issuingimpossible{RETURN_IMPOSSIBLE} = 1;
Lines 874-880 sub CanBookBeIssued { Link Here
874
      and $issue
875
      and $issue
875
      and $issue->onsite_checkout
876
      and $issue->onsite_checkout
876
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
877
      and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
877
    my $toomany = TooMany( $patron_unblessed, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
878
    my $toomany = TooMany( $patron_unblessed, $item->biblionumber, $item_unblessed, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
878
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
879
    # if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
879
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
880
    if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
880
        if ( $toomany->{max_allowed} == 0 ) {
881
        if ( $toomany->{max_allowed} == 0 ) {
Lines 897-915 sub CanBookBeIssued { Link Here
897
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
898
    $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
898
    my $wants_check = $patron->wants_check_for_previous_checkout;
899
    my $wants_check = $patron->wants_check_for_previous_checkout;
899
    $needsconfirmation{PREVISSUE} = 1
900
    $needsconfirmation{PREVISSUE} = 1
900
        if ($wants_check and $patron->do_check_for_previous_checkout($item));
901
        if ($wants_check and $patron->do_check_for_previous_checkout($item_unblessed));
901
902
902
    #
903
    #
903
    # ITEM CHECKING
904
    # ITEM CHECKING
904
    #
905
    #
905
    if ( $item->{'notforloan'} )
906
    if ( $item->notforloan )
906
    {
907
    {
907
        if(!C4::Context->preference("AllowNotForLoanOverride")){
908
        if(!C4::Context->preference("AllowNotForLoanOverride")){
908
            $issuingimpossible{NOT_FOR_LOAN} = 1;
909
            $issuingimpossible{NOT_FOR_LOAN} = 1;
909
            $issuingimpossible{item_notforloan} = $item->{'notforloan'};
910
            $issuingimpossible{item_notforloan} = $item->notforloan;
910
        }else{
911
        }else{
911
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
912
            $needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
912
            $needsconfirmation{item_notforloan} = $item->{'notforloan'};
913
            $needsconfirmation{item_notforloan} = $item->notforloan;
913
        }
914
        }
914
    }
915
    }
915
    else {
916
    else {
Lines 942-958 sub CanBookBeIssued { Link Here
942
            }
943
            }
943
        }
944
        }
944
    }
945
    }
945
    if ( $item->{'withdrawn'} && $item->{'withdrawn'} > 0 )
946
    if ( $item->withdrawn && $item->withdrawn > 0 )
946
    {
947
    {
947
        $issuingimpossible{WTHDRAWN} = 1;
948
        $issuingimpossible{WTHDRAWN} = 1;
948
    }
949
    }
949
    if (   $item->{'restricted'}
950
    if (   $item->restricted
950
        && $item->{'restricted'} == 1 )
951
        && $item->restricted == 1 )
951
    {
952
    {
952
        $issuingimpossible{RESTRICTED} = 1;
953
        $issuingimpossible{RESTRICTED} = 1;
953
    }
954
    }
954
    if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
955
    if ( $item->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
955
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} });
956
        my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->itemlost });
956
        my $code = $av->count ? $av->next->lib : '';
957
        my $code = $av->count ? $av->next->lib : '';
957
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
958
        $needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
958
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
959
        $alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
Lines 960-968 sub CanBookBeIssued { Link Here
960
    if ( C4::Context->preference("IndependentBranches") ) {
961
    if ( C4::Context->preference("IndependentBranches") ) {
961
        my $userenv = C4::Context->userenv;
962
        my $userenv = C4::Context->userenv;
962
        unless ( C4::Context->IsSuperLibrarian() ) {
963
        unless ( C4::Context->IsSuperLibrarian() ) {
963
            if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
964
            my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch");
965
            if ( $item->$HomeOrHoldingBranch ne $userenv->{branch} ){
964
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
966
                $issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
965
                $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
967
                $issuingimpossible{'itemhomebranch'} = $item->$HomeOrHoldingBranch;
966
            }
968
            }
967
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
969
            $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
968
              if ( $patron->branchcode ne $userenv->{branch} );
970
              if ( $patron->branchcode ne $userenv->{branch} );
Lines 974-980 sub CanBookBeIssued { Link Here
974
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
976
    my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
975
977
976
    if ( $rentalConfirmation ){
978
    if ( $rentalConfirmation ){
977
        my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
979
        my ($rentalCharge) = GetIssuingCharges( $item->itemnumber, $patron->borrowernumber );
978
        if ( $rentalCharge > 0 ){
980
        if ( $rentalCharge > 0 ){
979
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
981
            $needsconfirmation{RENTALCHARGE} = $rentalCharge;
980
        }
982
        }
Lines 982-988 sub CanBookBeIssued { Link Here
982
984
983
    unless ( $ignore_reserves ) {
985
    unless ( $ignore_reserves ) {
984
        # See if the item is on reserve.
986
        # See if the item is on reserve.
985
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
987
        my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->itemnumber );
986
        if ($restype) {
988
        if ($restype) {
987
            my $resbor = $res->{'borrowernumber'};
989
            my $resbor = $res->{'borrowernumber'};
988
            if ( $resbor ne $patron->borrowernumber ) {
990
            if ( $resbor ne $patron->borrowernumber ) {
Lines 1027-1033 sub CanBookBeIssued { Link Here
1027
1029
1028
    ## check for high holds decreasing loan period
1030
    ## check for high holds decreasing loan period
1029
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1031
    if ( C4::Context->preference('decreaseLoanHighHolds') ) {
1030
        my $check = checkHighHolds( $item, $patron_unblessed );
1032
        my $check = checkHighHolds( $item_unblessed, $patron_unblessed );
1031
1033
1032
        if ( $check->{exceeded} ) {
1034
        if ( $check->{exceeded} ) {
1033
            if ($override_high_holds) {
1035
            if ($override_high_holds) {
Lines 1056-1062 sub CanBookBeIssued { Link Here
1056
    ) {
1058
    ) {
1057
        # Check if borrower has already issued an item from the same biblio
1059
        # Check if borrower has already issued an item from the same biblio
1058
        # Only if it's not a subscription
1060
        # Only if it's not a subscription
1059
        my $biblionumber = $item->{biblionumber};
1061
        my $biblionumber = $item->biblionumber;
1060
        require C4::Serials;
1062
        require C4::Serials;
1061
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1063
        my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
1062
        unless ($is_a_subscription) {
1064
        unless ($is_a_subscription) {
Lines 1089-1095 Check whether the item can be returned to the provided branch Link Here
1089
1091
1090
=over 4
1092
=over 4
1091
1093
1092
=item C<$item> is a hash of item information as returned from GetItem
1094
=item C<$item> is a hash of item information as returned Koha::Items->find->unblessed (Temporary, should be a Koha::Item instead)
1093
1095
1094
=item C<$branch> is the branchcode where the return is taking place
1096
=item C<$branch> is the branchcode where the return is taking place
1095
1097
Lines 1287-1307 sub AddIssue { Link Here
1287
    # Stop here if the patron or barcode doesn't exist
1289
    # Stop here if the patron or barcode doesn't exist
1288
    if ( $borrower && $barcode && $barcodecheck ) {
1290
    if ( $borrower && $barcode && $barcodecheck ) {
1289
        # find which item we issue
1291
        # find which item we issue
1290
        my $item = GetItem( '', $barcode )
1292
        my $item = Koha::Items->find({ barcode => $barcode })
1291
          or return;    # if we don't get an Item, abort.
1293
          or return;    # if we don't get an Item, abort.
1292
        my $item_object = Koha::Items->find( { barcode => $barcode } );
1294
        my $item_unblessed = $item->unblessed;
1293
1295
1294
        my $branch = _GetCircControlBranch( $item, $borrower );
1296
        my $branch = _GetCircControlBranch( $item_unblessed, $borrower );
1295
1297
1296
        # get actual issuing if there is one
1298
        # get actual issuing if there is one
1297
        my $actualissue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
1299
        my $actualissue = $item->checkout;
1298
1300
1299
        # check if we just renew the issue.
1301
        # check if we just renew the issue.
1300
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1302
        if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
1301
                and not $switch_onsite_checkout ) {
1303
                and not $switch_onsite_checkout ) {
1302
            $datedue = AddRenewal(
1304
            $datedue = AddRenewal(
1303
                $borrower->{'borrowernumber'},
1305
                $borrower->{'borrowernumber'},
1304
                $item->{'itemnumber'},
1306
                $item->itemnumber,
1305
                $branch,
1307
                $branch,
1306
                $datedue,
1308
                $datedue,
1307
                $issuedate,    # here interpreted as the renewal date
1309
                $issuedate,    # here interpreted as the renewal date
Lines 1312-1326 sub AddIssue { Link Here
1312
            if ( $actualissue and not $switch_onsite_checkout ) {
1314
            if ( $actualissue and not $switch_onsite_checkout ) {
1313
                # This book is currently on loan, but not to the person
1315
                # This book is currently on loan, but not to the person
1314
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1316
                # who wants to borrow it now. mark it returned before issuing to the new borrower
1315
                my ( $allowed, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
1317
                my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
1316
                return unless $allowed;
1318
                return unless $allowed;
1317
                AddReturn( $item->{'barcode'}, C4::Context->userenv->{'branch'} );
1319
                AddReturn( $item->barcode, C4::Context->userenv->{'branch'} );
1318
            }
1320
            }
1319
1321
1320
            C4::Reserves::MoveReserve( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $cancelreserve );
1322
            C4::Reserves::MoveReserve( $item->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
1321
1323
1322
            # Starting process for transfer job (checking transfert and validate it if we have one)
1324
            # Starting process for transfer job (checking transfert and validate it if we have one)
1323
            my ($datesent) = GetTransfers( $item->{'itemnumber'} );
1325
            my ($datesent) = GetTransfers( $item->itemnumber );
1324
            if ($datesent) {
1326
            if ($datesent) {
1325
                # 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
                # updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
1326
                my $sth = $dbh->prepare(
1328
                my $sth = $dbh->prepare(
Lines 1331-1344 sub AddIssue { Link Here
1331
                    WHERE itemnumber= ? AND datearrived IS NULL"
1333
                    WHERE itemnumber= ? AND datearrived IS NULL"
1332
                );
1334
                );
1333
                $sth->execute( C4::Context->userenv->{'branch'},
1335
                $sth->execute( C4::Context->userenv->{'branch'},
1334
                    $item->{'itemnumber'} );
1336
                    $item->itemnumber );
1335
            }
1337
            }
1336
1338
1337
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1339
            # If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
1338
            unless ($auto_renew) {
1340
            unless ($auto_renew) {
1339
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1341
                my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
1340
                    {   categorycode => $borrower->{categorycode},
1342
                    {   categorycode => $borrower->{categorycode},
1341
                        itemtype     => $item->{itype},
1343
                        itemtype     => $item->effective_itemtype,
1342
                        branchcode   => $branch
1344
                        branchcode   => $branch
1343
                    }
1345
                    }
1344
                );
1346
                );
Lines 1348-1354 sub AddIssue { Link Here
1348
1350
1349
            # Record in the database the fact that the book was issued.
1351
            # Record in the database the fact that the book was issued.
1350
            unless ($datedue) {
1352
            unless ($datedue) {
1351
                my $itype = $item_object->effective_itemtype;
1353
                my $itype = $item->effective_itemtype;
1352
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1354
                $datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
1353
1355
1354
            }
1356
            }
Lines 1357-1363 sub AddIssue { Link Here
1357
            $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create(
1359
            $issue = Koha::Database->new()->schema()->resultset('Issue')->update_or_create(
1358
                {
1360
                {
1359
                    borrowernumber => $borrower->{'borrowernumber'},
1361
                    borrowernumber => $borrower->{'borrowernumber'},
1360
                    itemnumber     => $item->{'itemnumber'},
1362
                    itemnumber     => $item->itemnumber,
1361
                    issuedate      => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1363
                    issuedate      => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1362
                    date_due       => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1364
                    date_due       => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1363
                    branchcode     => C4::Context->userenv->{'branch'},
1365
                    branchcode     => C4::Context->userenv->{'branch'},
Lines 1368-1416 sub AddIssue { Link Here
1368
1370
1369
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1371
            if ( C4::Context->preference('ReturnToShelvingCart') ) {
1370
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1372
                # ReturnToShelvingCart is on, anything issued should be taken off the cart.
1371
                CartToShelf( $item->{'itemnumber'} );
1373
                CartToShelf( $item->itemnumber );
1372
            }
1374
            }
1373
            $item->{'issues'}++;
1375
1374
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1376
            if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
1375
                UpdateTotalIssues( $item->{'biblionumber'}, 1 );
1377
                UpdateTotalIssues( $item->biblionumber, 1 );
1376
            }
1378
            }
1377
1379
1378
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1380
            ## If item was lost, it has now been found, reverse any list item charges if necessary.
1379
            if ( $item->{'itemlost'} ) {
1381
            if ( $item->itemlost ) {
1380
                if (
1382
                if (
1381
                    Koha::RefundLostItemFeeRules->should_refund(
1383
                    Koha::RefundLostItemFeeRules->should_refund(
1382
                        {
1384
                        {
1383
                            current_branch      => C4::Context->userenv->{branch},
1385
                            current_branch      => C4::Context->userenv->{branch},
1384
                            item_home_branch    => $item->{homebranch},
1386
                            item_home_branch    => $item->homebranch,
1385
                            item_holding_branch => $item->{holdingbranch}
1387
                            item_holding_branch => $item->holdingbranch,
1386
                        }
1388
                        }
1387
                    )
1389
                    )
1388
                  )
1390
                  )
1389
                {
1391
                {
1390
                    _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef,
1392
                    _FixAccountForLostAndReturned( $item->itemnumber, undef,
1391
                        $item->{'barcode'} );
1393
                        $item->barcode );
1392
                }
1394
                }
1393
            }
1395
            }
1394
1396
1395
            ModItem(
1397
            ModItem(
1396
                {
1398
                {
1397
                    issues        => $item->{'issues'},
1399
                    issues        => $item->issues + 1,
1398
                    holdingbranch => C4::Context->userenv->{'branch'},
1400
                    holdingbranch => C4::Context->userenv->{'branch'},
1399
                    itemlost      => 0,
1401
                    itemlost      => 0,
1400
                    onloan        => $datedue->ymd(),
1402
                    onloan        => $datedue->ymd(),
1401
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1403
                    datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
1402
                },
1404
                },
1403
                $item->{'biblionumber'},
1405
                $item->biblionumber,
1404
                $item->{'itemnumber'},
1406
                $item->itemnumber,
1405
                { log_action => 0 }
1407
                { log_action => 0 }
1406
            );
1408
            );
1407
            ModDateLastSeen( $item->{'itemnumber'} );
1409
            ModDateLastSeen( $item->itemnumber );
1408
1410
1409
           # If it costs to borrow this book, charge it to the patron's account.
1411
           # If it costs to borrow this book, charge it to the patron's account.
1410
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
1412
            my ( $charge, $itemtype ) = GetIssuingCharges( $item->itemnumber, $borrower->{'borrowernumber'} );
1411
            if ( $charge > 0 ) {
1413
            if ( $charge > 0 ) {
1412
                AddIssuingCharge( $issue, $charge );
1414
                AddIssuingCharge( $issue, $charge );
1413
                $item->{'charge'} = $charge;
1414
            }
1415
            }
1415
1416
1416
            # Record the fact that this book was issued.
1417
            # Record the fact that this book was issued.
Lines 1420-1430 sub AddIssue { Link Here
1420
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1421
                    type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1421
                    amount         => $charge,
1422
                    amount         => $charge,
1422
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1423
                    other          => ( $sipmode ? "SIP-$sipmode" : '' ),
1423
                    itemnumber     => $item->{'itemnumber'},
1424
                    itemnumber     => $item->itemnumber,
1424
                    itemtype       => $item->{'itype'},
1425
                    itemtype       => $item->effective_itemtype,
1425
                    location       => $item->{location},
1426
                    location       => $item->location,
1426
                    borrowernumber => $borrower->{'borrowernumber'},
1427
                    borrowernumber => $borrower->{'borrowernumber'},
1427
                    ccode          => $item->{'ccode'}
1428
                    ccode          => $item->ccode,
1428
                }
1429
                }
1429
            );
1430
            );
1430
1431
Lines 1433-1439 sub AddIssue { Link Here
1433
            my %conditions        = (
1434
            my %conditions        = (
1434
                branchcode   => $branch,
1435
                branchcode   => $branch,
1435
                categorycode => $borrower->{categorycode},
1436
                categorycode => $borrower->{categorycode},
1436
                item_type    => $item->{itype},
1437
                item_type    => $item->effective_itemtype,
1437
                notification => 'CHECKOUT',
1438
                notification => 'CHECKOUT',
1438
            );
1439
            );
1439
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
1440
            if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
Lines 1449-1455 sub AddIssue { Link Here
1449
            logaction(
1450
            logaction(
1450
                "CIRCULATION", "ISSUE",
1451
                "CIRCULATION", "ISSUE",
1451
                $borrower->{'borrowernumber'},
1452
                $borrower->{'borrowernumber'},
1452
                $item->{'itemnumber'}
1453
                $item->itemnumber,
1453
            ) if C4::Context->preference("IssueLog");
1454
            ) if C4::Context->preference("IssueLog");
1454
        }
1455
        }
1455
    }
1456
    }
Lines 1802-1814 sub AddReturn { Link Here
1802
    my $stat_type = 'return';
1803
    my $stat_type = 'return';
1803
1804
1804
    # get information on item
1805
    # get information on item
1805
    my $item = GetItem( undef, $barcode );
1806
    my $item = Koha::Items->find({ barcode => $barcode });
1806
    unless ($item) {
1807
    unless ($item) {
1807
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1808
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1808
    }
1809
    }
1809
1810
1810
    my $itemnumber = $item->{ itemnumber };
1811
    my $itemnumber = $item->itemnumber;
1811
    my $itemtype = $item->{itype}; # GetItem called effective_itemtype
1812
    my $itemtype = $item->effective_itemtype;
1812
1813
1813
    my $issue  = Koha::Checkouts->find( { itemnumber => $itemnumber } );
1814
    my $issue  = Koha::Checkouts->find( { itemnumber => $itemnumber } );
1814
    if ( $issue ) {
1815
    if ( $issue ) {
Lines 1828-1848 sub AddReturn { Link Here
1828
        }
1829
        }
1829
    }
1830
    }
1830
1831
1831
    if ( $item->{'location'} eq 'PROC' ) {
1832
    my $item_unblessed = $item->unblessed;
1833
    if ( $item->location eq 'PROC' ) {
1832
        if ( C4::Context->preference("InProcessingToShelvingCart") ) {
1834
        if ( C4::Context->preference("InProcessingToShelvingCart") ) {
1833
            $item->{'location'} = 'CART';
1835
            $item_unblessed->{location} = 'CART';
1834
        }
1836
        }
1835
        else {
1837
        else {
1836
            $item->{location} = $item->{permanent_location};
1838
            $item_unblessed->{location} = $item->permanent_location;
1837
        }
1839
        }
1838
1840
1839
        ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, { log_action => 0 } );
1841
        ModItem( $item_unblessed, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
1840
    }
1842
    }
1841
1843
1842
        # full item data, but no borrowernumber or checkout info (no issue)
1844
        # full item data, but no borrowernumber or checkout info (no issue)
1843
    my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
1845
    my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
1844
        # get the proper branch to which to return the item
1846
        # get the proper branch to which to return the item
1845
    my $returnbranch = $item->{$hbr} || $branch ;
1847
    my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
1846
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1848
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1847
1849
1848
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
1850
    my $borrowernumber = $patron ? $patron->borrowernumber : undef;    # we don't know if we had a borrower or not
Lines 1858-1865 sub AddReturn { Link Here
1858
        }
1860
        }
1859
        else {
1861
        else {
1860
            foreach my $key ( keys %$rules ) {
1862
            foreach my $key ( keys %$rules ) {
1861
                if ( $item->{notforloan} eq $key ) {
1863
                if ( $item->notforloan eq $key ) {
1862
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
1864
                    $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
1863
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
1865
                    ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
1864
                    last;
1866
                    last;
1865
                }
1867
                }
Lines 1868-1874 sub AddReturn { Link Here
1868
    }
1870
    }
1869
1871
1870
    # check if the return is allowed at this branch
1872
    # check if the return is allowed at this branch
1871
    my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
1873
    my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch);
1872
    unless ($returnallowed){
1874
    unless ($returnallowed){
1873
        $messages->{'Wrongbranch'} = {
1875
        $messages->{'Wrongbranch'} = {
1874
            Wrongbranch => $branch,
1876
            Wrongbranch => $branch,
Lines 1878-1889 sub AddReturn { Link Here
1878
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1880
        return ( $doreturn, $messages, $issue, $patron_unblessed);
1879
    }
1881
    }
1880
1882
1881
    if ( $item->{'withdrawn'} ) { # book has been cancelled
1883
    if ( $item->withdrawn ) { # book has been cancelled
1882
        $messages->{'withdrawn'} = 1;
1884
        $messages->{'withdrawn'} = 1;
1883
        $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems");
1885
        $doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems");
1884
    }
1886
    }
1885
1887
1886
    if ( $item->{itemlost} and C4::Context->preference("BlockReturnOfLostItems") ) {
1888
    if ( $item->itemlost and C4::Context->preference("BlockReturnOfLostItems") ) {
1887
        $doreturn = 0;
1889
        $doreturn = 0;
1888
    }
1890
    }
1889
1891
Lines 1900-1906 sub AddReturn { Link Here
1900
            # don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
1902
            # don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
1901
            # FIXME: check issuedate > returndate, factoring in holidays
1903
            # FIXME: check issuedate > returndate, factoring in holidays
1902
1904
1903
            $circControlBranch = _GetCircControlBranch($item,$patron_unblessed);
1905
            $circControlBranch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
1904
            $is_overdue = $issue->is_overdue( $dropboxdate );
1906
            $is_overdue = $issue->is_overdue( $dropboxdate );
1905
        } else {
1907
        } else {
1906
            $is_overdue = $issue->is_overdue;
1908
            $is_overdue = $issue->is_overdue;
Lines 1908-1919 sub AddReturn { Link Here
1908
1910
1909
        if ($patron) {
1911
        if ($patron) {
1910
            eval {
1912
            eval {
1911
                MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
1913
                MarkIssueReturned( $borrowernumber, $item->itemnumber,
1912
                    $circControlBranch, $return_date, $patron->privacy );
1914
                    $circControlBranch, $return_date, $patron->privacy );
1913
            };
1915
            };
1914
            unless ( $@ ) {
1916
            unless ( $@ ) {
1915
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1917
                if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
1916
                    _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } );
1918
                    _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } );
1917
                }
1919
                }
1918
            } else {
1920
            } else {
1919
                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 );
1921
                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 1926-1981 sub AddReturn { Link Here
1926
1928
1927
        }
1929
        }
1928
1930
1929
        ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, { log_action => 0 } );
1931
        ModItem( { onloan => undef }, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
1930
    }
1932
    }
1931
1933
1932
    # the holdingbranch is updated if the document is returned to another location.
1934
    # the holdingbranch is updated if the document is returned to another location.
1933
    # this is always done regardless of whether the item was on loan or not
1935
    # this is always done regardless of whether the item was on loan or not
1934
    my $item_holding_branch = $item->{ holdingbranch };
1936
    my $item_holding_branch = $item->holdingbranch;
1935
    if ($item->{'holdingbranch'} ne $branch) {
1937
    if ($item->holdingbranch ne $branch) {
1936
        UpdateHoldingbranch($branch, $item->{'itemnumber'});
1938
        UpdateHoldingbranch($branch, $item->itemnumber);
1937
        $item->{'holdingbranch'} = $branch; # update item data holdingbranch too
1939
        $item_unblessed->{'holdingbranch'} = $branch; # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later
1938
    }
1940
    }
1939
    ModDateLastSeen( $item->{'itemnumber'} );
1941
    ModDateLastSeen( $item->itemnumber );
1940
1942
1941
    # check if we have a transfer for this document
1943
    # check if we have a transfer for this document
1942
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->{'itemnumber'} );
1944
    my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber );
1943
1945
1944
    # if we have a transfer to do, we update the line of transfers with the datearrived
1946
    # if we have a transfer to do, we update the line of transfers with the datearrived
1945
    my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->{'itemnumber'} );
1947
    my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber );
1946
    if ($datesent) {
1948
    if ($datesent) {
1947
        if ( $tobranch eq $branch ) {
1949
        if ( $tobranch eq $branch ) {
1948
            my $sth = C4::Context->dbh->prepare(
1950
            my $sth = C4::Context->dbh->prepare(
1949
                "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
1951
                "UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
1950
            );
1952
            );
1951
            $sth->execute( $item->{'itemnumber'} );
1953
            $sth->execute( $item->itemnumber );
1952
            # if we have a reservation with valid transfer, we can set it's status to 'W'
1954
            # if we have a reservation with valid transfer, we can set it's status to 'W'
1953
            ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
1955
            ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
1954
            C4::Reserves::ModReserveStatus($item->{'itemnumber'}, 'W');
1956
            C4::Reserves::ModReserveStatus($item->itemnumber, 'W');
1955
        } else {
1957
        } else {
1956
            $messages->{'WrongTransfer'}     = $tobranch;
1958
            $messages->{'WrongTransfer'}     = $tobranch;
1957
            $messages->{'WrongTransferItem'} = $item->{'itemnumber'};
1959
            $messages->{'WrongTransferItem'} = $item->itemnumber;
1958
        }
1960
        }
1959
        $validTransfert = 1;
1961
        $validTransfert = 1;
1960
    } else {
1962
    } else {
1961
        ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
1963
        ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
1962
    }
1964
    }
1963
1965
1964
    # fix up the accounts.....
1966
    # fix up the accounts.....
1965
    if ( $item->{'itemlost'} ) {
1967
    if ( $item->itemlost ) {
1966
        $messages->{'WasLost'} = 1;
1968
        $messages->{'WasLost'} = 1;
1967
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1969
        unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
1968
            if (
1970
            if (
1969
                Koha::RefundLostItemFeeRules->should_refund(
1971
                Koha::RefundLostItemFeeRules->should_refund(
1970
                    {
1972
                    {
1971
                        current_branch      => C4::Context->userenv->{branch},
1973
                        current_branch      => C4::Context->userenv->{branch},
1972
                        item_home_branch    => $item->{homebranch},
1974
                        item_home_branch    => $item->homebranch,
1973
                        item_holding_branch => $item_holding_branch
1975
                        item_holding_branch => $item_holding_branch
1974
                    }
1976
                    }
1975
                )
1977
                )
1976
              )
1978
              )
1977
            {
1979
            {
1978
                _FixAccountForLostAndReturned( $item->{'itemnumber'},
1980
                _FixAccountForLostAndReturned( $item->itemnumber,
1979
                    $borrowernumber, $barcode );
1981
                    $borrowernumber, $barcode );
1980
                $messages->{'LostItemFeeRefunded'} = 1;
1982
                $messages->{'LostItemFeeRefunded'} = 1;
1981
            }
1983
            }
Lines 1984-1997 sub AddReturn { Link Here
1984
1986
1985
    # fix up the overdues in accounts...
1987
    # fix up the overdues in accounts...
1986
    if ($borrowernumber) {
1988
    if ($borrowernumber) {
1987
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
1989
        my $fix = _FixOverduesOnReturn($borrowernumber, $item->itemnumber, $exemptfine, $dropbox);
1988
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
1990
        defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->itemnumber...) failed!";  # zero is OK, check defined
1989
1991
1990
        if ( $issue and $issue->is_overdue ) {
1992
        if ( $issue and $issue->is_overdue ) {
1991
        # fix fine days
1993
        # fix fine days
1992
            $today = dt_from_string($return_date) if $return_date;
1994
            $today = dt_from_string($return_date) if $return_date;
1993
            $today = $dropboxdate if $dropbox;
1995
            $today = $dropboxdate if $dropbox;
1994
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today );
1996
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item_unblessed, dt_from_string($issue->date_due), $today );
1995
            if ($reminder){
1997
            if ($reminder){
1996
                $messages->{'PrevDebarred'} = $debardate;
1998
                $messages->{'PrevDebarred'} = $debardate;
1997
            } else {
1999
            } else {
Lines 2016-2022 sub AddReturn { Link Here
2016
    # if we don't have a reserve with the status W, we launch the Checkreserves routine
2018
    # if we don't have a reserve with the status W, we launch the Checkreserves routine
2017
    my ($resfound, $resrec);
2019
    my ($resfound, $resrec);
2018
    my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
2020
    my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
2019
    ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'}, undef, $lookahead ) unless ( $item->{'withdrawn'} );
2021
    ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->itemnumber, undef, $lookahead ) unless ( $item->withdrawn );
2020
    if ($resfound) {
2022
    if ($resfound) {
2021
          $resrec->{'ResFound'} = $resfound;
2023
          $resrec->{'ResFound'} = $resfound;
2022
        $messages->{'ResFound'} = $resrec;
2024
        $messages->{'ResFound'} = $resrec;
Lines 2029-2035 sub AddReturn { Link Here
2029
        itemnumber     => $itemnumber,
2031
        itemnumber     => $itemnumber,
2030
        itemtype       => $itemtype,
2032
        itemtype       => $itemtype,
2031
        borrowernumber => $borrowernumber,
2033
        borrowernumber => $borrowernumber,
2032
        ccode          => $item->{ ccode }
2034
        ccode          => $item->ccode,
2033
    });
2035
    });
2034
2036
2035
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
2037
    # Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
Lines 2038-2056 sub AddReturn { Link Here
2038
        my %conditions = (
2040
        my %conditions = (
2039
            branchcode   => $branch,
2041
            branchcode   => $branch,
2040
            categorycode => $patron->categorycode,
2042
            categorycode => $patron->categorycode,
2041
            item_type    => $item->{itype},
2043
            item_type    => $itemtype,
2042
            notification => 'CHECKIN',
2044
            notification => 'CHECKIN',
2043
        );
2045
        );
2044
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2046
        if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
2045
            SendCirculationAlert({
2047
            SendCirculationAlert({
2046
                type     => 'CHECKIN',
2048
                type     => 'CHECKIN',
2047
                item     => $item,
2049
                item     => $item_unblessed,
2048
                borrower => $patron->unblessed,
2050
                borrower => $patron->unblessed,
2049
                branch   => $branch,
2051
                branch   => $branch,
2050
            });
2052
            });
2051
        }
2053
        }
2052
2054
2053
        logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
2055
        logaction("CIRCULATION", "RETURN", $borrowernumber, $item->itemnumber)
2054
            if C4::Context->preference("ReturnLog");
2056
            if C4::Context->preference("ReturnLog");
2055
        }
2057
        }
2056
2058
Lines 2066-2078 sub AddReturn { Link Here
2066
2068
2067
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
2069
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
2068
    if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
2070
    if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
2071
        my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType");
2069
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
2072
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
2070
            (C4::Context->preference("UseBranchTransferLimits") and
2073
            (C4::Context->preference("UseBranchTransferLimits") and
2071
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->{C4::Context->preference("BranchTransferLimitsType")} )
2074
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2072
           )) {
2075
           )) {
2073
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $returnbranch;
2076
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch;
2074
            $debug and warn "item: " . Dumper($item);
2077
            $debug and warn "item: " . Dumper($item_unblessed);
2075
            ModItemTransfer($item->{'itemnumber'}, $branch, $returnbranch);
2078
            ModItemTransfer($item->itemnumber, $branch, $returnbranch);
2076
            $messages->{'WasTransfered'} = 1;
2079
            $messages->{'WasTransfered'} = 1;
2077
        } else {
2080
        } else {
2078
            $messages->{'NeedsTransfer'} = $returnbranch;
2081
            $messages->{'NeedsTransfer'} = $returnbranch;
Lines 2590-2596 sub CanBookBeRenewed { Link Here
2590
    my $dbh    = C4::Context->dbh;
2593
    my $dbh    = C4::Context->dbh;
2591
    my $renews = 1;
2594
    my $renews = 1;
2592
2595
2593
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2596
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2594
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2597
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2595
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2598
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2596
2599
Lines 2646-2652 sub CanBookBeRenewed { Link Here
2646
            my @reservable;
2649
            my @reservable;
2647
            my %borrowers;
2650
            my %borrowers;
2648
            ITEM: foreach my $i (@itemnumbers) {
2651
            ITEM: foreach my $i (@itemnumbers) {
2649
                my $item = GetItem($i);
2652
                my $item = Koha::Items->find($i)->unblessed;
2650
                next if IsItemOnHoldAndFound($i);
2653
                next if IsItemOnHoldAndFound($i);
2651
                for my $b (@borrowernumbers) {
2654
                for my $b (@borrowernumbers) {
2652
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
2655
                    my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
Lines 2667-2676 sub CanBookBeRenewed { Link Here
2667
2670
2668
    return ( 1, undef ) if $override_limit;
2671
    return ( 1, undef ) if $override_limit;
2669
2672
2670
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
2673
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2671
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2674
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2672
        {   categorycode => $patron->categorycode,
2675
        {   categorycode => $patron->categorycode,
2673
            itemtype     => $item->{itype},
2676
            itemtype     => $item->effective_itemtype,
2674
            branchcode   => $branchcode
2677
            branchcode   => $branchcode
2675
        }
2678
        }
2676
    );
2679
    );
Lines 2794-2808 sub AddRenewal { Link Here
2794
    my $datedue         = shift;
2797
    my $datedue         = shift;
2795
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2798
    my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz)->ymd();
2796
2799
2797
    my $item   = GetItem($itemnumber) or return;
2800
    my $item   = Koha::Items->find($itemnumber) or return;
2798
    my $item_object = Koha::Items->find( $itemnumber ); # Should replace $item
2801
    my $biblio = $item->biblio;
2799
    my $biblio = $item_object->biblio;
2802
    my $issue  = $item->checkout;
2803
    my $item_unblessed = $item->unblessed;
2800
2804
2801
    my $dbh = C4::Context->dbh;
2805
    my $dbh = C4::Context->dbh;
2802
2806
2803
    # Find the issues record for this book
2804
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
2805
2806
    return unless $issue;
2807
    return unless $issue;
2807
2808
2808
    $borrowernumber ||= $issue->borrowernumber;
2809
    $borrowernumber ||= $issue->borrowernumber;
Lines 2816-2822 sub AddRenewal { Link Here
2816
    my $patron_unblessed = $patron->unblessed;
2817
    my $patron_unblessed = $patron->unblessed;
2817
2818
2818
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2819
    if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
2819
        _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
2820
        _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
2820
    }
2821
    }
2821
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2822
    _FixOverduesOnReturn( $borrowernumber, $itemnumber );
2822
2823
Lines 2825-2835 sub AddRenewal { Link Here
2825
    # based on the value of the RenewalPeriodBase syspref.
2826
    # based on the value of the RenewalPeriodBase syspref.
2826
    unless ($datedue) {
2827
    unless ($datedue) {
2827
2828
2828
        my $itemtype = $item_object->effective_itemtype;
2829
        my $itemtype = $item->effective_itemtype;
2829
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2830
        $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2830
                                        dt_from_string( $issue->date_due, 'sql' ) :
2831
                                        dt_from_string( $issue->date_due, 'sql' ) :
2831
                                        DateTime->now( time_zone => C4::Context->tz());
2832
                                        DateTime->now( time_zone => C4::Context->tz());
2832
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2833
        $datedue =  CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item_unblessed, $patron_unblessed), $patron_unblessed, 'is a renewal');
2833
    }
2834
    }
2834
2835
2835
    # Update the issues record to have the new due date, and a new count
2836
    # Update the issues record to have the new due date, and a new count
Lines 2843-2850 sub AddRenewal { Link Here
2843
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2844
    $sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
2844
2845
2845
    # Update the renewal count on the item, and tell zebra to reindex
2846
    # Update the renewal count on the item, and tell zebra to reindex
2846
    $renews = $item->{renewals} + 1;
2847
    $renews = $item->renewals + 1;
2847
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
2848
    ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } );
2848
2849
2849
    # Charge a new rental fee, if applicable?
2850
    # Charge a new rental fee, if applicable?
2850
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
2851
    my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
Lines 2859-2865 sub AddRenewal { Link Here
2859
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2860
                    VALUES (now(),?,?,?,?,?,?,?,?)"
2860
        );
2861
        );
2861
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2862
        $sth->execute( $borrowernumber, $accountno, $charge, $manager_id,
2862
            "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}",
2863
            "Renewal of Rental Item " . $biblio->title . " " . $item->barcode,
2863
            'Rent', $charge, $itemnumber );
2864
            'Rent', $charge, $itemnumber );
2864
    }
2865
    }
2865
2866
Lines 2869-2882 sub AddRenewal { Link Here
2869
        my %conditions        = (
2870
        my %conditions        = (
2870
            branchcode   => $branch,
2871
            branchcode   => $branch,
2871
            categorycode => $patron->categorycode,
2872
            categorycode => $patron->categorycode,
2872
            item_type    => $item->{itype},
2873
            item_type    => $item->effective_itemtype,
2873
            notification => 'CHECKOUT',
2874
            notification => 'CHECKOUT',
2874
        );
2875
        );
2875
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2876
        if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
2876
            SendCirculationAlert(
2877
            SendCirculationAlert(
2877
                {
2878
                {
2878
                    type     => 'RENEWAL',
2879
                    type     => 'RENEWAL',
2879
                    item     => $item,
2880
                    item     => $item_unblessed,
2880
                    borrower => $patron->unblessed,
2881
                    borrower => $patron->unblessed,
2881
                    branch   => $branch,
2882
                    branch   => $branch,
2882
                }
2883
                }
Lines 2904-2913 sub AddRenewal { Link Here
2904
            type           => 'renew',
2905
            type           => 'renew',
2905
            amount         => $charge,
2906
            amount         => $charge,
2906
            itemnumber     => $itemnumber,
2907
            itemnumber     => $itemnumber,
2907
            itemtype       => $item->{itype},
2908
            itemtype       => $item->effective_itemtype,
2908
            location       => $item->{location},
2909
            location       => $item->location,
2909
            borrowernumber => $borrowernumber,
2910
            borrowernumber => $borrowernumber,
2910
            ccode          => $item->{'ccode'}
2911
            ccode          => $item->ccode,
2911
        }
2912
        }
2912
    );
2913
    );
2913
2914
Lines 2925-2931 sub GetRenewCount { Link Here
2925
    my $renewsleft    = 0;
2926
    my $renewsleft    = 0;
2926
2927
2927
    my $patron = Koha::Patrons->find( $bornum );
2928
    my $patron = Koha::Patrons->find( $bornum );
2928
    my $item     = GetItem($itemno);
2929
    my $item   = Koha::Items->find($itemno);
2929
2930
2930
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2931
    return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
2931
2932
Lines 2942-2952 sub GetRenewCount { Link Here
2942
    my $data = $sth->fetchrow_hashref;
2943
    my $data = $sth->fetchrow_hashref;
2943
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2944
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
2944
    # $item and $borrower should be calculated
2945
    # $item and $borrower should be calculated
2945
    my $branchcode = _GetCircControlBranch($item, $patron->unblessed);
2946
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
2946
2947
2947
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2948
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2948
        {   categorycode => $patron->categorycode,
2949
        {   categorycode => $patron->categorycode,
2949
            itemtype     => $item->{itype},
2950
            itemtype     => $item->effective_itemtype,
2950
            branchcode   => $branchcode
2951
            branchcode   => $branchcode
2951
        }
2952
        }
2952
    );
2953
    );
Lines 2981-2997 sub GetSoonestRenewDate { Link Here
2981
2982
2982
    my $dbh = C4::Context->dbh;
2983
    my $dbh = C4::Context->dbh;
2983
2984
2984
    my $item      = GetItem($itemnumber)      or return;
2985
    my $item      = Koha::Items->find($itemnumber)      or return;
2985
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2986
    my $itemissue = $item->checkout or return;
2986
2987
2987
    $borrowernumber ||= $itemissue->borrowernumber;
2988
    $borrowernumber ||= $itemissue->borrowernumber;
2988
    my $patron = Koha::Patrons->find( $borrowernumber )
2989
    my $patron = Koha::Patrons->find( $borrowernumber )
2989
      or return;
2990
      or return;
2990
2991
2991
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
2992
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2992
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2993
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
2993
        {   categorycode => $patron->categorycode,
2994
        {   categorycode => $patron->categorycode,
2994
            itemtype     => $item->{itype},
2995
            itemtype     => $item->effective_itemtype,
2995
            branchcode   => $branchcode
2996
            branchcode   => $branchcode
2996
        }
2997
        }
2997
    );
2998
    );
Lines 3040-3056 sub GetLatestAutoRenewDate { Link Here
3040
3041
3041
    my $dbh = C4::Context->dbh;
3042
    my $dbh = C4::Context->dbh;
3042
3043
3043
    my $item      = GetItem($itemnumber)      or return;
3044
    my $item      = Koha::Items->find($itemnumber)  or return;
3044
    my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
3045
    my $itemissue = $item->checkout                 or return;
3045
3046
3046
    $borrowernumber ||= $itemissue->borrowernumber;
3047
    $borrowernumber ||= $itemissue->borrowernumber;
3047
    my $patron = Koha::Patrons->find( $borrowernumber )
3048
    my $patron = Koha::Patrons->find( $borrowernumber )
3048
      or return;
3049
      or return;
3049
3050
3050
    my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
3051
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3051
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3052
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
3052
        {   categorycode => $patron->categorycode,
3053
        {   categorycode => $patron->categorycode,
3053
            itemtype     => $item->{itype},
3054
            itemtype     => $item->effective_itemtype,
3054
            branchcode   => $branchcode
3055
            branchcode   => $branchcode
3055
        }
3056
        }
3056
    );
3057
    );
Lines 3627-3634 sub ReturnLostItem{ Link Here
3627
3628
3628
    MarkIssueReturned( $borrowernumber, $itemnum );
3629
    MarkIssueReturned( $borrowernumber, $itemnum );
3629
    my $patron = Koha::Patrons->find( $borrowernumber );
3630
    my $patron = Koha::Patrons->find( $borrowernumber );
3630
    my $item = C4::Items::GetItem( $itemnum );
3631
    my $item = Koha::Items->find($itemnum);
3631
    my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{};
3632
    my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{};
3632
    my @datearr = localtime(time);
3633
    my @datearr = localtime(time);
3633
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3634
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
3634
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
3635
    my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
Lines 3816-3823 sub ProcessOfflinePayment { Link Here
3816
sub TransferSlip {
3817
sub TransferSlip {
3817
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3818
    my ($branch, $itemnumber, $barcode, $to_branch) = @_;
3818
3819
3819
    my $item =  GetItem( $itemnumber, $barcode )
3820
    my $item =
3820
      or return;
3821
      $itemnumber
3822
      ? Koha::Items->find($itemnumber)
3823
      : Koha::Items->find( { barcode => $barcode } );
3824
3825
    $item or return;
3821
3826
3822
    return C4::Letters::GetPreparedLetter (
3827
    return C4::Letters::GetPreparedLetter (
3823
        module => 'circulation',
3828
        module => 'circulation',
Lines 3825-3832 sub TransferSlip { Link Here
3825
        branchcode => $branch,
3830
        branchcode => $branch,
3826
        tables => {
3831
        tables => {
3827
            'branches'    => $to_branch,
3832
            'branches'    => $to_branch,
3828
            'biblio'      => $item->{biblionumber},
3833
            'biblio'      => $item->biblionumber,
3829
            'items'       => $item,
3834
            'items'       => $item->unblessed,
3830
        },
3835
        },
3831
    );
3836
    );
3832
}
3837
}
(-)a/C4/CourseReserves.pm (-5 / +5 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 572-584 sub _UpdateCourseItem { Link Here
572
    ## Update fields that didn't have an original value, but now do
572
    ## Update fields that didn't have an original value, but now do
573
    ## We must save the original value in course_items, and also
573
    ## We must save the original value in course_items, and also
574
    ## update the item fields to the new value
574
    ## update the item fields to the new value
575
    my $item = GetItem( $course_item->{'itemnumber'} );
575
    my $item = Koha::Items->find($course_item->{'itemnumber'});
576
    my %mod_params_new;
576
    my %mod_params_new;
577
    my %mod_params_old;
577
    my %mod_params_old;
578
    foreach (@FIELDS) {
578
    foreach (@FIELDS) {
579
        if ( $params{$_} && !$course_item->{$_} ) {
579
        if ( $params{$_} && !$course_item->{$_} ) {
580
            $mod_params_new{$_} = $params{$_};
580
            $mod_params_new{$_} = $params{$_};
581
            $mod_params_old{$_} = $item->{$_};
581
            $mod_params_old{$_} = $item->$_;
582
        }
582
        }
583
    }
583
    }
584
    _ModStoredFields( 'ci_id' => $params{'ci_id'}, %mod_params_old );
584
    _ModStoredFields( 'ci_id' => $params{'ci_id'}, %mod_params_old );
Lines 665-678 sub _SwapAllFields { Link Here
665
    warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG;
665
    warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG;
666
666
667
    my $course_item = GetCourseItem( ci_id => $ci_id );
667
    my $course_item = GetCourseItem( ci_id => $ci_id );
668
    my $item = GetItem( $course_item->{'itemnumber'} );
668
    my $item = Koha::Items->find($course_item->{'itemnumber'});
669
669
670
    my %course_item_fields;
670
    my %course_item_fields;
671
    my %item_fields;
671
    my %item_fields;
672
    foreach (@FIELDS) {
672
    foreach (@FIELDS) {
673
        if ( $course_item->{$_} ) {
673
        if ( $course_item->{$_} ) {
674
            $course_item_fields{$_} = $course_item->{$_};
674
            $course_item_fields{$_} = $course_item->{$_};
675
            $item_fields{$_}        = $item->{$_};
675
            $item_fields{$_}        = $item->$_;
676
        }
676
        }
677
    }
677
    }
678
678
(-)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 534-550 sub GetServices { Link Here
534
    my $borrower = $patron->unblessed;
534
    my $borrower = $patron->unblessed;
535
    # Get the item, or return an error code if not found
535
    # Get the item, or return an error code if not found
536
    my $itemnumber = $cgi->param('item_id');
536
    my $itemnumber = $cgi->param('item_id');
537
    my $item = GetItem( $itemnumber );
537
    my $item = Koha::Items->find($itemnumber);
538
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
538
    return { code => 'RecordNotFound' } unless $item;
539
539
540
    my @availablefor;
540
    my @availablefor;
541
541
542
    # Reserve level management
542
    # Reserve level management
543
    my $biblionumber = $item->{'biblionumber'};
543
    my $biblionumber = $item->biblionumber;
544
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
544
    my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
545
    if ($canbookbereserved->{status} eq 'OK') {
545
    if ($canbookbereserved->{status} eq 'OK') {
546
        push @availablefor, 'title level hold';
546
        push @availablefor, 'title level hold';
547
        my $canitembereserved = IsAvailableForItemLevelRequest($item, $borrower);
547
        my $canitembereserved = IsAvailableForItemLevelRequest($item->unblessed, $borrower);
548
        if ($canitembereserved) {
548
        if ($canitembereserved) {
549
            push @availablefor, 'item level hold';
549
            push @availablefor, 'item level hold';
550
        }
550
        }
Lines 567-573 sub GetServices { Link Here
567
    }
567
    }
568
568
569
    # Issuing management
569
    # Issuing management
570
    my $barcode = $item->{'barcode'} || '';
570
    my $barcode = $item->barcode || '';
571
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
571
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
572
    if ($barcode) {
572
    if ($barcode) {
573
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
573
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
Lines 606-619 sub RenewLoan { Link Here
606
606
607
    # Get the item, or return an error code
607
    # Get the item, or return an error code
608
    my $itemnumber = $cgi->param('item_id');
608
    my $itemnumber = $cgi->param('item_id');
609
    my $item = GetItem( $itemnumber );
609
    my $item = Koha::Items->find($itemnumber);
610
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
610
    return { code => 'RecordNotFound' } unless $item;
611
611
612
    # Add renewal if possible
612
    # Add renewal if possible
613
    my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
613
    my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
614
    if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); }
614
    if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); }
615
615
616
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; # FIXME should be handled
616
    return unless $item; # FIXME should be handled
617
618
    my $issue = $item->checkout;
619
    return $issue; # FIXME should be handled
617
620
618
    # Hashref building
621
    # Hashref building
619
    my $out;
622
    my $out;
Lines 731-741 sub HoldItem { Link Here
731
734
732
    # Get the item or return an error code
735
    # Get the item or return an error code
733
    my $itemnumber = $cgi->param('item_id');
736
    my $itemnumber = $cgi->param('item_id');
734
    my $item = GetItem( $itemnumber );
737
    my $item = Koha::Items->find($itemnumber);
735
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
738
    return { code => 'RecordNotFound' } unless $item;
736
739
737
    # If the biblio does not match the item, return an error code
740
    # If the biblio does not match the item, return an error code
738
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
741
    return { code => 'RecordNotFound' } if $item->biblionumber ne $biblio->biblionumber;
739
742
740
    # Check for item disponibility
743
    # Check for item disponibility
741
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
744
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber );
Lines 810-834 Returns, for an itemnumber, an array containing availability information. Link Here
810
813
811
sub _availability {
814
sub _availability {
812
    my ($itemnumber) = @_;
815
    my ($itemnumber) = @_;
813
    my $item = GetItem( $itemnumber, undef, undef );
816
    my $item = Koha::Items->find($itemnumber);
814
817
815
    if ( not $item->{'itemnumber'} ) {
818
    unless ( $item ) {
816
        return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
819
        return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
817
    }
820
    }
818
821
819
    my $biblionumber = $item->{'biblioitemnumber'};
822
    my $biblionumber = $item->biblioitemnumber;
820
    my $library = Koha::Libraries->find( $item->{holdingbranch} );
823
    my $library = Koha::Libraries->find( $item->holdingbranch );
821
    my $location = $library ? $library->branchname : '';
824
    my $location = $library ? $library->branchname : '';
822
825
823
    if ( $item->{'notforloan'} ) {
826
    if ( $item->notforloan ) {
824
        return ( $biblionumber, 'not available', 'Not for loan', $location );
827
        return ( $biblionumber, 'not available', 'Not for loan', $location );
825
    } elsif ( $item->{'onloan'} ) {
828
    } elsif ( $item->onloan ) {
826
        return ( $biblionumber, 'not available', 'Checked out', $location );
829
        return ( $biblionumber, 'not available', 'Checked out', $location );
827
    } elsif ( $item->{'itemlost'} ) {
830
    } elsif ( $item->itemlost ) {
828
        return ( $biblionumber, 'not available', 'Item lost', $location );
831
        return ( $biblionumber, 'not available', 'Item lost', $location );
829
    } elsif ( $item->{'withdrawn'} ) {
832
    } elsif ( $item->withdrawn ) {
830
        return ( $biblionumber, 'not available', 'Item withdrawn', $location );
833
        return ( $biblionumber, 'not available', 'Item withdrawn', $location );
831
    } elsif ( $item->{'damaged'} ) {
834
    } elsif ( $item->damaged ) {
832
        return ( $biblionumber, 'not available', 'Item damaged', $location );
835
        return ( $biblionumber, 'not available', 'Item damaged', $location );
833
    } else {
836
    } else {
834
        return ( $biblionumber, 'available', undef, $location );
837
        return ( $biblionumber, 'available', undef, $location );
(-)a/C4/Items.pm (-28 / +13 lines)
Lines 189-198 sub CartToShelf { Link Here
189
        croak "FAILED CartToShelf() - no itemnumber supplied";
189
        croak "FAILED CartToShelf() - no itemnumber supplied";
190
    }
190
    }
191
191
192
    my $item = GetItem($itemnumber);
192
    my $item = Koha::Items->find($itemnumber);
193
    if ( $item->{location} eq 'CART' ) {
193
    if ( $item->location eq 'CART' ) {
194
        $item->{location} = $item->{permanent_location};
194
        ModItem({ location => $item->permanent_location}, undef, $itemnumber);
195
        ModItem($item, undef, $itemnumber);
196
    }
195
    }
197
}
196
}
198
197
Lines 212-220 sub ShelfToCart { Link Here
212
        croak "FAILED ShelfToCart() - no itemnumber supplied";
211
        croak "FAILED ShelfToCart() - no itemnumber supplied";
213
    }
212
    }
214
213
215
    my $item = GetItem($itemnumber);
214
    ModItem({ location => 'CART'}, undef, $itemnumber);
216
    $item->{'location'} = 'CART';
217
    ModItem($item, undef, $itemnumber);
218
}
215
}
219
216
220
=head2 AddItemFromMarc
217
=head2 AddItemFromMarc
Lines 567-578 sub ModItem { Link Here
567
564
568
    my @fields = qw( itemlost withdrawn damaged );
565
    my @fields = qw( itemlost withdrawn damaged );
569
566
570
    # Only call GetItem if we need to set an "on" date field
567
    # Only retrieve the item if we need to set an "on" date field
571
    if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) {
568
    if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) {
572
        my $pre_mod_item = GetItem( $item->{'itemnumber'} );
569
        my $pre_mod_item = Koha::Items->find( $item->{'itemnumber'} );
573
        for my $field (@fields) {
570
        for my $field (@fields) {
574
            if (    defined( $item->{$field} )
571
            if (    defined( $item->{$field} )
575
                and not $pre_mod_item->{$field}
572
                and not $pre_mod_item->$field
576
                and $item->{$field} )
573
                and $item->{$field} )
577
            {
574
            {
578
                $item->{ $field . '_on' } =
575
                $item->{ $field . '_on' } =
Lines 1392-1404 sub GetMarcItem { Link Here
1392
    # while the other treats the MARC representation as authoritative
1389
    # while the other treats the MARC representation as authoritative
1393
    # under certain circumstances.
1390
    # under certain circumstances.
1394
1391
1395
    my $itemrecord = GetItem($itemnumber);
1392
    my $item = Koha::Items->find($itemnumber) or return;
1396
1393
1397
    # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work.
1394
    # Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work.
1398
    # Also, don't emit a subfield if the underlying field is blank.
1395
    # Also, don't emit a subfield if the underlying field is blank.
1399
1396
1400
    
1397
    return Item2Marc($item->unblessed, $biblionumber);
1401
    return Item2Marc($itemrecord,$biblionumber);
1402
1398
1403
}
1399
}
1404
sub Item2Marc {
1400
sub Item2Marc {
Lines 1839-1869 sub ItemSafeToDelete { Link Here
1839
1835
1840
    my $countanalytics = GetAnalyticsCount($itemnumber);
1836
    my $countanalytics = GetAnalyticsCount($itemnumber);
1841
1837
1842
    # check that there is no issue on this item before deletion.
1838
    my $item = Koha::Items->find($itemnumber) or return;
1843
    my $sth = $dbh->prepare(
1844
        q{
1845
        SELECT COUNT(*) FROM issues
1846
        WHERE itemnumber = ?
1847
    }
1848
    );
1849
    $sth->execute($itemnumber);
1850
    my ($onloan) = $sth->fetchrow;
1851
1852
    my $item = GetItem($itemnumber);
1853
1839
1854
    if ($onloan) {
1840
    if ($item->checkout) {
1855
        $status = "book_on_loan";
1841
        $status = "book_on_loan";
1856
    }
1842
    }
1857
    elsif ( defined C4::Context->userenv
1843
    elsif ( defined C4::Context->userenv
1858
        and !C4::Context->IsSuperLibrarian()
1844
        and !C4::Context->IsSuperLibrarian()
1859
        and C4::Context->preference("IndependentBranches")
1845
        and C4::Context->preference("IndependentBranches")
1860
        and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
1846
        and ( C4::Context->userenv->{branch} ne $item->homebranch ) )
1861
    {
1847
    {
1862
        $status = "not_same_branch";
1848
        $status = "not_same_branch";
1863
    }
1849
    }
1864
    else {
1850
    else {
1865
        # check it doesn't have a waiting reserve
1851
        # check it doesn't have a waiting reserve
1866
        $sth = $dbh->prepare(
1852
        my $sth = $dbh->prepare(
1867
            q{
1853
            q{
1868
            SELECT COUNT(*) FROM reserves
1854
            SELECT COUNT(*) FROM reserves
1869
            WHERE (found = 'W' OR found = 'T')
1855
            WHERE (found = 'W' OR found = 'T')
Lines 2748-2754 sub ToggleNewStatus { Link Here
2748
        while ( my $values = $sth->fetchrow_hashref ) {
2734
        while ( my $values = $sth->fetchrow_hashref ) {
2749
            my $biblionumber = $values->{biblionumber};
2735
            my $biblionumber = $values->{biblionumber};
2750
            my $itemnumber = $values->{itemnumber};
2736
            my $itemnumber = $values->{itemnumber};
2751
            my $item = C4::Items::GetItem( $itemnumber );
2752
            for my $substitution ( @$substitutions ) {
2737
            for my $substitution ( @$substitutions ) {
2753
                next unless $substitution->{field};
2738
                next unless $substitution->{field};
2754
                C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
2739
                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 314-327 sub CanItemBeReserved { Link Here
314
314
315
    # we retrieve borrowers and items informations #
315
    # we retrieve borrowers and items informations #
316
    # item->{itype} will come for biblioitems if necessery
316
    # item->{itype} will come for biblioitems if necessery
317
    my $item       = GetItem($itemnumber);
317
    my $item       = Koha::Items->find($itemnumber);
318
    my $biblio     = Koha::Biblios->find( $item->{biblionumber} );
318
    my $biblio     = $item->biblio;
319
    my $patron = Koha::Patrons->find( $borrowernumber );
319
    my $patron = Koha::Patrons->find( $borrowernumber );
320
    my $borrower = $patron->unblessed;
320
    my $borrower = $patron->unblessed;
321
321
322
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
322
    # If an item is damaged and we don't allow holds on damaged items, we can stop right here
323
    return { status =>'damaged' }
323
    return { status =>'damaged' }
324
      if ( $item->{damaged}
324
      if ( $item->damaged
325
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
325
        && !C4::Context->preference('AllowHoldsOnDamagedItems') );
326
326
327
    # Check for the age restriction
327
    # Check for the age restriction
Lines 349-355 sub CanItemBeReserved { Link Here
349
349
350
    if ( $controlbranch eq "ItemHomeLibrary" ) {
350
    if ( $controlbranch eq "ItemHomeLibrary" ) {
351
        $branchfield = "items.homebranch";
351
        $branchfield = "items.homebranch";
352
        $branchcode  = $item->{homebranch};
352
        $branchcode  = $item->homebranch;
353
    }
353
    }
354
    elsif ( $controlbranch eq "PatronLibrary" ) {
354
    elsif ( $controlbranch eq "PatronLibrary" ) {
355
        $branchfield = "borrowers.branchcode";
355
        $branchfield = "borrowers.branchcode";
Lines 357-363 sub CanItemBeReserved { Link Here
357
    }
357
    }
358
358
359
    # we retrieve rights
359
    # we retrieve rights
360
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) {
360
    if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
361
        $ruleitemtype     = $rights->{itemtype};
361
        $ruleitemtype     = $rights->{itemtype};
362
        $allowedreserves  = $rights->{reservesallowed};
362
        $allowedreserves  = $rights->{reservesallowed};
363
        $holds_per_record = $rights->{holds_per_record};
363
        $holds_per_record = $rights->{holds_per_record};
Lines 366-372 sub CanItemBeReserved { Link Here
366
        $ruleitemtype = '*';
366
        $ruleitemtype = '*';
367
    }
367
    }
368
368
369
    $item = Koha::Items->find( $itemnumber );
370
    my $holds = Koha::Holds->search(
369
    my $holds = Koha::Holds->search(
371
        {
370
        {
372
            borrowernumber => $borrowernumber,
371
            borrowernumber => $borrowernumber,
Lines 435-441 sub CanItemBeReserved { Link Here
435
    my $circ_control_branch =
434
    my $circ_control_branch =
436
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
435
      C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
437
    my $branchitemrule =
436
    my $branchitemrule =
438
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype );
437
      C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype ); # FIXME Should not be item->effective_itemtype?
439
438
440
    if ( $branchitemrule->{holdallowed} == 0 ) {
439
    if ( $branchitemrule->{holdallowed} == 0 ) {
441
        return { status => 'notReservable' };
440
        return { status => 'notReservable' };
Lines 452-459 sub CanItemBeReserved { Link Here
452
    if ( C4::Context->preference('IndependentBranches')
451
    if ( C4::Context->preference('IndependentBranches')
453
        and !C4::Context->preference('canreservefromotherbranches') )
452
        and !C4::Context->preference('canreservefromotherbranches') )
454
    {
453
    {
455
        my $itembranch = $item->homebranch;
454
        if ( $item->homebranch ne $borrower->{branchcode} ) {
456
        if ( $itembranch ne $borrower->{branchcode} ) {
457
            return { status => 'cannotReserveFromOtherBranches' };
455
            return { status => 'cannotReserveFromOtherBranches' };
458
        }
456
        }
459
    }
457
    }
Lines 498-505 sub GetOtherReserves { Link Here
498
    my $nextreservinfo;
496
    my $nextreservinfo;
499
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
497
    my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
500
    if ($checkreserves) {
498
    if ($checkreserves) {
501
        my $iteminfo = GetItem($itemnumber);
499
        my $item = Koha::Items->find($itemnumber);
502
        if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
500
        if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) {
503
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
501
            $messages->{'transfert'} = $checkreserves->{'branchcode'};
504
            #minus priorities of others reservs
502
            #minus priorities of others reservs
505
            ModReserveMinusPriority(
503
            ModReserveMinusPriority(
Lines 510-516 sub GetOtherReserves { Link Here
510
            #launch the subroutine dotransfer
508
            #launch the subroutine dotransfer
511
            C4::Items::ModItemTransfer(
509
            C4::Items::ModItemTransfer(
512
                $itemnumber,
510
                $itemnumber,
513
                $iteminfo->{'holdingbranch'},
511
                $item->holdingbranch,
514
                $checkreserves->{'branchcode'}
512
                $checkreserves->{'branchcode'}
515
              ),
513
              ),
516
              ;
514
              ;
Lines 735-749 sub CheckReserves { Link Here
735
                }
733
                }
736
            } else {
734
            } else {
737
                my $patron;
735
                my $patron;
738
                my $iteminfo;
736
                my $item;
739
                my $local_hold_match;
737
                my $local_hold_match;
740
738
741
                if ($LocalHoldsPriority) {
739
                if ($LocalHoldsPriority) {
742
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
740
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
743
                    $iteminfo = C4::Items::GetItem($itemnumber);
741
                    $item = Koha::Items->find($itemnumber);
744
742
745
                    my $local_holds_priority_item_branchcode =
743
                    my $local_holds_priority_item_branchcode =
746
                      $iteminfo->{$LocalHoldsPriorityItemControl};
744
                      $item->$LocalHoldsPriorityItemControl;
747
                    my $local_holds_priority_patron_branchcode =
745
                    my $local_holds_priority_patron_branchcode =
748
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
746
                      ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
749
                      ? $res->{branchcode}
747
                      ? $res->{branchcode}
Lines 757-770 sub CheckReserves { Link Here
757
755
758
                # See if this item is more important than what we've got so far
756
                # See if this item is more important than what we've got so far
759
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
757
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
760
                    $iteminfo ||= C4::Items::GetItem($itemnumber);
758
                    $item ||= Koha::Items->find($itemnumber);
761
                    next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
759
                    next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
762
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
760
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
763
                    my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
761
                    my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
764
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
762
                    my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
765
                    next if ($branchitemrule->{'holdallowed'} == 0);
763
                    next if ($branchitemrule->{'holdallowed'} == 0);
766
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
764
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
767
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
765
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
766
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
768
                    $priority = $res->{'priority'};
767
                    $priority = $res->{'priority'};
769
                    $highest  = $res;
768
                    $highest  = $res;
770
                    last if $local_hold_match;
769
                    last if $local_hold_match;
(-)a/acqui/orderreceive.pl (-4 / +5 lines)
Lines 128-137 if ($AcqCreateItem eq 'receiving') { Link Here
128
    );
128
    );
129
} elsif ($AcqCreateItem eq 'ordering') {
129
} elsif ($AcqCreateItem eq 'ordering') {
130
    my $fw = ($acq_fw) ? 'ACQ' : '';
130
    my $fw = ($acq_fw) ? 'ACQ' : '';
131
    my @itemnumbers = $order_object->items->get_column('itemnumber');
131
    my $items = $order_object->items;
132
    my @items;
132
    my @items;
133
    foreach (@itemnumbers) {
133
    while ( my $i = $items->next ) {
134
        my $item = GetItem($_); # FIXME We do not need this call, we already have the Koha::Items
134
        my $item = $i->unblessed;
135
        my $descriptions;
135
        my $descriptions;
136
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
136
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
137
        $item->{notforloan} = $descriptions->{lib} // '';
137
        $item->{notforloan} = $descriptions->{lib} // '';
Lines 148-155 if ($AcqCreateItem eq 'receiving') { Link Here
148
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
148
        $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
149
        $item->{materials} = $descriptions->{lib} // '';
149
        $item->{materials} = $descriptions->{lib} // '';
150
150
151
        my $itemtype = Koha::ItemTypes->find( $item->{itype} );
151
        my $itemtype = Koha::ItemTypes->find($i->effective_itemtype);
152
        if (defined $itemtype) {
152
        if (defined $itemtype) {
153
            # We should not do that here, but call ->itemtype->description when needed instead
153
            $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
154
            $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
154
        }
155
        }
155
        push @items, $item;
156
        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 88-94 elsif ($op eq 'add') { Link Here
88
        my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a <cr> separated list
87
        my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a <cr> separated list
89
        foreach my $number (@numbers_list) {
88
        foreach my $number (@numbers_list) {
90
            $number =~ s/\r$//; # strip any naughty return chars
89
            $number =~ s/\r$//; # strip any naughty return chars
91
            if( $number_type eq "itemnumber" && GetItem($number) ) {
90
            if( $number_type eq "itemnumber" && Koha::Items->find($number) ) {
92
                push @item_numbers, $number;
91
                push @item_numbers, $number;
93
            }
92
            }
94
            elsif ($number_type eq "barcode" ) {  # we must test in case an invalid barcode is passed in; we effectively disgard them atm
93
            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 30-35 use C4::Auth; Link Here
30
use C4::Context;
30
use C4::Context;
31
use C4::Items;
31
use C4::Items;
32
use C4::Members;
32
use C4::Members;
33
use Koha::Items;
33
use Koha::Patrons;
34
use Koha::Patrons;
34
use Date::Calc qw( Today Date_to_Days );
35
use Date::Calc qw( Today Date_to_Days );
35
my $query = new CGI;
36
my $query = new CGI;
Lines 66-79 else { Link Here
66
            my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
67
            my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
67
            my $branchcode;
68
            my $branchcode;
68
            if ( $renewalbranch eq 'itemhomebranch' ) {
69
            if ( $renewalbranch eq 'itemhomebranch' ) {
69
                my $item = GetItem($itemnumber);
70
                my $item = Koha::Items->find($itemnumber);
70
                $branchcode = $item->{'homebranch'};
71
                $branchcode = $item->homebranch;
71
            }
72
            }
72
            elsif ( $renewalbranch eq 'patronhomebranch' ) {
73
            elsif ( $renewalbranch eq 'patronhomebranch' ) {
73
                $branchcode = Koha::Patrons->find( $borrowernumber )->branchcode;
74
                $branchcode = Koha::Patrons->find( $borrowernumber )->branchcode;
74
            }
75
            }
75
            elsif ( $renewalbranch eq 'checkoutbranch' ) {
76
            elsif ( $renewalbranch eq 'checkoutbranch' ) {
76
                my $issue = GetOpenIssue($itemnumber);
77
                my $issue = GetOpenIssue($itemnumber); # FIXME Should not be $item->checkout?
77
                $branchcode = $issue->{'branchcode'};
78
                $branchcode = $issue->{'branchcode'};
78
            }
79
            }
79
            elsif ( $renewalbranch eq 'NULL' ) {
80
            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 854-860 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
854
856
855
    LostItem( $itemnumber, 'test', 1 );
857
    LostItem( $itemnumber, 'test', 1 );
856
858
857
    my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
859
    $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
858
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
860
    ok( !$item->onloan(), "Lost item marked as returned has false onloan value" );
859
    my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
861
    my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
860
    is( $checkout, undef, 'LostItem called with forced return has checked in the item' );
862
    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-106 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
    # Modify item; setting barcode.
73
    # Modify item; setting barcode.
74
    ModItem({ barcode => '987654321' }, $bibnum, $itemnumber);
74
    ModItem({ barcode => '987654321' }, $bibnum, $itemnumber);
75
    my $moditem = GetItem($itemnumber);
75
    my $moditem = Koha::Items->find($itemnumber);
76
    cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
76
    cmp_ok($moditem->barcode, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->barcode . '.');
77
77
78
    # Delete item.
78
    # Delete item.
79
    DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber });
79
    DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber });
80
    my $getdeleted = GetItem($itemnumber);
80
    my $getdeleted = Koha::Items->find($itemnumber);
81
    is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
81
    is($getdeleted, undef, "Item deleted as expected.");
82
82
83
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum);
83
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum);
84
    $getitem = GetItem($itemnumber);
84
    $getitem = Koha::Items->find($itemnumber);
85
    is( $getitem->{location}, $location, "The location should not have been modified" );
85
    is( $getitem->location, $location, "The location should not have been modified" );
86
    is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
86
    is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
87
87
88
    ModItem({ location => $location }, $bibnum, $itemnumber);
88
    ModItem({ location => $location }, $bibnum, $itemnumber);
89
    $getitem = GetItem($itemnumber);
89
    $getitem = Koha::Items->find($itemnumber);
90
    is( $getitem->{location}, $location, "The location should have been set to correct location" );
90
    is( $getitem->location, $location, "The location should have been set to correct location" );
91
    is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
91
    is( $getitem->permanent_location, $location, "The permanent_location should have been set to location" );
92
92
93
    ModItem({ location => 'CART' }, $bibnum, $itemnumber);
93
    ModItem({ location => 'CART' }, $bibnum, $itemnumber);
94
    $getitem = GetItem($itemnumber);
94
    $getitem = Koha::Items->find($itemnumber);
95
    is( $getitem->{location}, 'CART', "The location should have been set to CART" );
95
    is( $getitem->location, 'CART', "The location should have been set to CART" );
96
    is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
96
    is( $getitem->permanent_location, $location, "The permanent_location should not have been set to CART" );
97
97
98
    t::lib::Mocks::mock_preference('item-level_itypes', '1');
98
    t::lib::Mocks::mock_preference('item-level_itypes', '1');
99
    $getitem = GetItem($itemnumber);
99
    $getitem = Koha::Items->find($itemnumber);
100
    is( $getitem->{itype}, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" );
100
    is( $getitem->effective_itemtype, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" );
101
    t::lib::Mocks::mock_preference('item-level_itypes', '0');
101
    t::lib::Mocks::mock_preference('item-level_itypes', '0');
102
    $getitem = GetItem($itemnumber);
102
    $getitem = Koha::Items->find($itemnumber);
103
    is( $getitem->{itype}, undef, "Itemtype set correctly when not using item-level_itypes" );
103
    is( $getitem->effective_itemtype, undef, "Itemtype set correctly when not using item-level_itypes" );
104
104
105
    $schema->storage->txn_rollback;
105
    $schema->storage->txn_rollback;
106
};
106
};
Lines 188-195 subtest 'GetHiddenItemnumbers tests' => sub { Link Here
188
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
188
    my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
189
    my @hidden;
189
    my @hidden;
190
    my @items;
190
    my @items;
191
    push @items, GetItem( $item1_itemnumber );
191
    push @items, Koha::Items->find( $item1_itemnumber )->unblessed;
192
    push @items, GetItem( $item2_itemnumber );
192
    push @items, Koha::Items->find( $item2_itemnumber )->unblessed;
193
193
194
    # Empty OpacHiddenItems
194
    # Empty OpacHiddenItems
195
    t::lib::Mocks::mock_preference('OpacHiddenItems','');
195
    t::lib::Mocks::mock_preference('OpacHiddenItems','');
Lines 488-495 subtest 'SearchItems test' => sub { Link Here
488
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
488
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
489
489
490
    # Make sure the link is used
490
    # Make sure the link is used
491
    my $item3 = GetItem($item3_itemnumber);
491
    my $item3 = Koha::Items->find($item3_itemnumber);
492
    ok($item3->{itemnotes} eq 'foobar', 'itemnotes eq "foobar"');
492
    ok($item3->itemnotes eq 'foobar', 'itemnotes eq "foobar"');
493
493
494
    # Do the same search again.
494
    # Do the same search again.
495
    # This time it will search in items.itemnotes
495
    # This time it will search in items.itemnotes
Lines 685-705 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
685
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
685
    my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblionumber);
686
686
687
    # Make sure everything has been set up
687
    # Make sure everything has been set up
688
    my $item = GetItem($item_itemnumber);
688
    my $item = Koha::Items->find($item_itemnumber);
689
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
689
    is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
690
690
691
    # Delete the barcode field and save the record
691
    # Delete the barcode field and save the record
692
    $item_record->delete_fields( $barcode_field );
692
    $item_record->delete_fields( $barcode_field );
693
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
693
    $item_record->append_fields( $itemtype_field ); # itemtype is mandatory
694
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
694
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
695
    $item = GetItem($item_itemnumber);
695
    $item = Koha::Items->find($item_itemnumber);
696
    is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
696
    is( $item->barcode, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
697
697
698
    # Re-add the barcode field and save the record
698
    # Re-add the barcode field and save the record
699
    $item_record->append_fields( $barcode_field );
699
    $item_record->append_fields( $barcode_field );
700
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
700
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
701
    $item = GetItem($item_itemnumber);
701
    $item = Koha::Items->find($item_itemnumber);
702
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
702
    is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
703
703
704
    # Remove the mapping for barcode
704
    # Remove the mapping for barcode
705
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
705
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
Lines 719-726 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
719
    $item_record->append_fields( $another_barcode_field );
719
    $item_record->append_fields( $another_barcode_field );
720
    # The DB value should not have been updated
720
    # The DB value should not have been updated
721
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
721
    ModItemFromMarc($item_record, $biblionumber, $item_itemnumber);
722
    $item = GetItem($item_itemnumber);
722
    $item = Koha::Items->find($item_itemnumber);
723
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
723
    is ( $item->barcode, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
724
724
725
    $cache->clear_from_cache("default_value_for_mod_marc-");
725
    $cache->clear_from_cache("default_value_for_mod_marc-");
726
    $cache->clear_from_cache( "MarcSubfieldStructure-" );
726
    $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 175-181 if ($op eq "action") { Link Here
175
	foreach my $itemnumber(@itemnumbers){
175
	foreach my $itemnumber(@itemnumbers){
176
176
177
		$job->progress($i) if $runinbackground;
177
		$job->progress($i) if $runinbackground;
178
		my $itemdata = GetItem($itemnumber);
178
        my $itemdata = Koha::Items->find($itemnumber);
179
        next unless $itemdata; # Should have been tested earlier, but just in case...
180
        $itemdata = $itemdata->unblessed;
179
        if ( $del ){
181
        if ( $del ){
180
            my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
182
            my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
181
			if ($return == 1) {
183
			if ($return == 1) {
Lines 535-541 sub BuildItemsData{ Link Here
535
		my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
537
		my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
536
		my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
538
		my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
537
		foreach my $itemnumber (@itemnumbers){
539
		foreach my $itemnumber (@itemnumbers){
538
			my $itemdata=GetItem($itemnumber);
540
            my $itemdata = Koha::Items->find($itemnumber);
541
            next unless $itemdata; # Should have been tested earlier, but just in case...
542
            $itemdata = $itemdata->unblessed;
539
			my $itemmarc=Item2Marc($itemdata);
543
			my $itemmarc=Item2Marc($itemdata);
540
			my %this_row;
544
			my %this_row;
541
			foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
545
			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 184-191 if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { Link Here
184
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
185
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
185
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
186
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
186
        } else {
187
        } else {
187
            my $item = GetItem( '', $barcode );
188
            my $item = Koha::Items->find({barcode => $barcode});
188
            if ( defined $item && $item->{'itemnumber'} ) {
189
            if ( $item ) {
190
                $item = $item->unblessed;
189
                # Modify date last seen for scanned items, remove lost status
191
                # Modify date last seen for scanned items, remove lost status
190
                ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
192
                ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
191
                $moddatecount++;
193
                $moddatecount++;
(-)a/tools/viewlog.pl (-4 / +6 lines)
Lines 30-35 use C4::Log; Link Here
30
use C4::Items;
30
use C4::Items;
31
use C4::Debug;
31
use C4::Debug;
32
use C4::Search;    # enabled_staff_search_views
32
use C4::Search;    # enabled_staff_search_views
33
34
use Koha::Items;
33
use Koha::Patrons;
35
use Koha::Patrons;
34
36
35
use vars qw($debug $cgi_debug);
37
use vars qw($debug $cgi_debug);
Lines 118-128 if ($do_it) { Link Here
118
            # get item information so we can create a working link
120
            # get item information so we can create a working link
119
            my $itemnumber = $result->{'object'};
121
            my $itemnumber = $result->{'object'};
120
            $itemnumber = $result->{'info'} if ( $result->{module} eq "CIRCULATION" );
122
            $itemnumber = $result->{'info'} if ( $result->{module} eq "CIRCULATION" );
121
            my $item = GetItem($itemnumber);
123
            my $item = Koha::Items->find($itemnumber);
122
            if ($item) {
124
            if ($item) {
123
                $result->{'biblionumber'}     = $item->{'biblionumber'};
125
                $result->{'biblionumber'}     = $item->biblionumber;
124
                $result->{'biblioitemnumber'} = $item->{'biblionumber'};
126
                $result->{'biblioitemnumber'} = $item->biblionumber;
125
                $result->{'barcode'}          = $item->{'barcode'};
127
                $result->{'barcode'}          = $item->barcode;
126
            }
128
            }
127
        }
129
        }
128
130
(-)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