my ($hostbiblionumber,$hostitemnumber, $marcflavour) = @_;
$marcflavour ||="MARC21";
- require C4::Items;
my $hostrecord = GetMarcBiblio({ biblionumber => $hostbiblionumber });
- my $item = C4::Items::GetItem($hostitemnumber);
-
+ my $item = Koha::Items->find($hostitemnumber);
+
my $hostmarcfield;
if ( $marcflavour eq "MARC21" || $marcflavour eq "NORMARC" ) {
#other fields
my $ed = $hostrecord->subfield('250','a');
- my $barcode = $item->{'barcode'};
+ my $barcode = $item->barcode;
my $title = $hostrecord->subfield('245','a');
# record control number, 001 with 003 and prefix
require C4::Items;
while ( my ($itemnumber) = $sth->fetchrow_array ) {
next if @$itemnumbers and not grep { $_ == $itemnumber } @$itemnumbers;
- my $i = $opachiddenitems ? C4::Items::GetItem($itemnumber) : undef;
- push @items, { itemnumber => $itemnumber, item => $i };
+ my $item;
+ if ( $opachiddenitems ) {
+ $item = Koha::Items->find($itemnumber);
+ $item = $item ? $item->unblessed : undef;
+ }
+ push @items, { itemnumber => $itemnumber, item => $item };
}
my @items2pass = map { $_->{item} } @items;
my @hiddenitems =
my $onsite_checkout = $params->{onsite_checkout} || 0;
my $override_high_holds = $params->{override_high_holds} || 0;
- my $item = GetItem(undef, $barcode );
+ my $item = Koha::Items->find({barcode => $barcode });
# MANDATORY CHECKS - unless item exists, nothing else matters
unless ( $item ) {
$issuingimpossible{UNKNOWN_BARCODE} = 1;
}
return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
- my $issue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
- my $biblio = Koha::Biblios->find( $item->{biblionumber} );
+ my $item_unblessed = $item->unblessed; # Transition...
+ my $issue = $item->checkout;
+ my $biblio = $item->biblio;
my $biblioitem = $biblio->biblioitem;
- my $effective_itemtype = $item->{itype}; # GetItem deals with that
+ my $effective_itemtype = $item->effective_itemtype;
my $dbh = C4::Context->dbh;
my $patron_unblessed = $patron->unblessed;
unless ( $duedate ) {
my $issuedate = $now->clone();
- my $branch = _GetCircControlBranch($item, $patron_unblessed);
+ my $branch = _GetCircControlBranch($item_unblessed, $patron_unblessed);
$duedate = CalcDateDue( $issuedate, $effective_itemtype, $branch, $patron_unblessed );
# Offline circ calls AddIssue directly, doesn't run through here
#
# BORROWER STATUS
#
- if ( $patron->category->category_type eq 'X' && ( $item->{barcode} )) {
+ if ( $patron->category->category_type eq 'X' && ( $item->barcode )) {
# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1 .
&UpdateStats({
branch => C4::Context->userenv->{'branch'},
type => 'localuse',
- itemnumber => $item->{'itemnumber'},
+ itemnumber => $item->itemnumber,
itemtype => $effective_itemtype,
borrowernumber => $patron->borrowernumber,
- ccode => $item->{'ccode'}}
+ ccode => $item->ccode}
);
- ModDateLastSeen( $item->{'itemnumber'} );
+ ModDateLastSeen( $item->itemnumber ); # FIXME Move to Koha::Item
return( { STATS => 1 }, {});
}
} else {
my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
$patron->borrowernumber,
- $item->{'itemnumber'},
+ $item->itemnumber,
);
if ( $CanBookBeRenewed == 0 ) { # no more renewals allowed
if ( $renewerror eq 'onsite_checkout' ) {
my $patron = Koha::Patrons->find( $issue->borrowernumber );
- my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
+ my ( $can_be_returned, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
unless ( $can_be_returned ) {
$issuingimpossible{RETURN_IMPOSSIBLE} = 1;
and $issue
and $issue->onsite_checkout
and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
- my $toomany = TooMany( $patron_unblessed, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
+ my $toomany = TooMany( $patron_unblessed, $item->biblionumber, $item_unblessed, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
# if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
if ( $toomany->{max_allowed} == 0 ) {
$patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
my $wants_check = $patron->wants_check_for_previous_checkout;
$needsconfirmation{PREVISSUE} = 1
- if ($wants_check and $patron->do_check_for_previous_checkout($item));
+ if ($wants_check and $patron->do_check_for_previous_checkout($item_unblessed));
#
# ITEM CHECKING
#
- if ( $item->{'notforloan'} )
+ if ( $item->notforloan )
{
if(!C4::Context->preference("AllowNotForLoanOverride")){
$issuingimpossible{NOT_FOR_LOAN} = 1;
- $issuingimpossible{item_notforloan} = $item->{'notforloan'};
+ $issuingimpossible{item_notforloan} = $item->notforloan;
}else{
$needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
- $needsconfirmation{item_notforloan} = $item->{'notforloan'};
+ $needsconfirmation{item_notforloan} = $item->notforloan;
}
}
else {
}
}
}
- if ( $item->{'withdrawn'} && $item->{'withdrawn'} > 0 )
+ if ( $item->withdrawn && $item->withdrawn > 0 )
{
$issuingimpossible{WTHDRAWN} = 1;
}
- if ( $item->{'restricted'}
- && $item->{'restricted'} == 1 )
+ if ( $item->restricted
+ && $item->restricted == 1 )
{
$issuingimpossible{RESTRICTED} = 1;
}
- if ( $item->{'itemlost'} && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
- my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->{itemlost} });
+ if ( $item->itemlost && C4::Context->preference("IssueLostItem") ne 'nothing' ) {
+ my $av = Koha::AuthorisedValues->search({ category => 'LOST', authorised_value => $item->itemlost });
my $code = $av->count ? $av->next->lib : '';
$needsconfirmation{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'confirm' );
$alerts{ITEM_LOST} = $code if ( C4::Context->preference("IssueLostItem") eq 'alert' );
if ( C4::Context->preference("IndependentBranches") ) {
my $userenv = C4::Context->userenv;
unless ( C4::Context->IsSuperLibrarian() ) {
- if ( $item->{C4::Context->preference("HomeOrHoldingBranch")} ne $userenv->{branch} ){
+ my $HomeOrHoldingBranch = C4::Context->preference("HomeOrHoldingBranch");
+ if ( $item->$HomeOrHoldingBranch ne $userenv->{branch} ){
$issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
- $issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
+ $issuingimpossible{'itemhomebranch'} = $item->$HomeOrHoldingBranch;
}
$needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
if ( $patron->branchcode ne $userenv->{branch} );
my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
if ( $rentalConfirmation ){
- my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
+ my ($rentalCharge) = GetIssuingCharges( $item->itemnumber, $patron->borrowernumber );
if ( $rentalCharge > 0 ){
$needsconfirmation{RENTALCHARGE} = $rentalCharge;
}
unless ( $ignore_reserves ) {
# See if the item is on reserve.
- my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
+ my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->itemnumber );
if ($restype) {
my $resbor = $res->{'borrowernumber'};
if ( $resbor ne $patron->borrowernumber ) {
## check for high holds decreasing loan period
if ( C4::Context->preference('decreaseLoanHighHolds') ) {
- my $check = checkHighHolds( $item, $patron_unblessed );
+ my $check = checkHighHolds( $item_unblessed, $patron_unblessed );
if ( $check->{exceeded} ) {
if ($override_high_holds) {
) {
# Check if borrower has already issued an item from the same biblio
# Only if it's not a subscription
- my $biblionumber = $item->{biblionumber};
+ my $biblionumber = $item->biblionumber;
require C4::Serials;
my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
unless ($is_a_subscription) {
=over 4
-=item C<$item> is a hash of item information as returned from GetItem
+=item C<$item> is a hash of item information as returned Koha::Items->find->unblessed (Temporary, should be a Koha::Item instead)
=item C<$branch> is the branchcode where the return is taking place
# Stop here if the patron or barcode doesn't exist
if ( $borrower && $barcode && $barcodecheck ) {
# find which item we issue
- my $item = GetItem( '', $barcode )
+ my $item = Koha::Items->find({ barcode => $barcode })
or return; # if we don't get an Item, abort.
- my $item_object = Koha::Items->find( { barcode => $barcode } );
+ my $item_unblessed = $item->unblessed;
- my $branch = _GetCircControlBranch( $item, $borrower );
+ my $branch = _GetCircControlBranch( $item_unblessed, $borrower );
# get actual issuing if there is one
- my $actualissue = Koha::Checkouts->find( { itemnumber => $item->{itemnumber} } );
+ my $actualissue = $item->checkout;
# check if we just renew the issue.
if ( $actualissue and $actualissue->borrowernumber eq $borrower->{'borrowernumber'}
and not $switch_onsite_checkout ) {
$datedue = AddRenewal(
$borrower->{'borrowernumber'},
- $item->{'itemnumber'},
+ $item->itemnumber,
$branch,
$datedue,
$issuedate, # here interpreted as the renewal date
if ( $actualissue and not $switch_onsite_checkout ) {
# This book is currently on loan, but not to the person
# who wants to borrow it now. mark it returned before issuing to the new borrower
- my ( $allowed, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
+ my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} );
return unless $allowed;
- AddReturn( $item->{'barcode'}, C4::Context->userenv->{'branch'} );
+ AddReturn( $item->barcode, C4::Context->userenv->{'branch'} );
}
- C4::Reserves::MoveReserve( $item->{'itemnumber'}, $borrower->{'borrowernumber'}, $cancelreserve );
+ C4::Reserves::MoveReserve( $item->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve );
# Starting process for transfer job (checking transfert and validate it if we have one)
- my ($datesent) = GetTransfers( $item->{'itemnumber'} );
+ my ($datesent) = GetTransfers( $item->itemnumber );
if ($datesent) {
# updating line of branchtranfert to finish it, and changing the to branch value, implement a comment for visibility of this case (maybe for stats ....)
my $sth = $dbh->prepare(
WHERE itemnumber= ? AND datearrived IS NULL"
);
$sth->execute( C4::Context->userenv->{'branch'},
- $item->{'itemnumber'} );
+ $item->itemnumber );
}
# If automatic renewal wasn't selected while issuing, set the value according to the issuing rule.
unless ($auto_renew) {
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $borrower->{categorycode},
- itemtype => $item->{itype},
+ itemtype => $item->effective_itemtype,
branchcode => $branch
}
);
# Record in the database the fact that the book was issued.
unless ($datedue) {
- my $itype = $item_object->effective_itemtype;
+ my $itype = $item->effective_itemtype;
$datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
}
else {
$issue = Koha::Checkout->new(
{
- itemnumber => $item->{itemnumber},
+ itemnumber => $item->itemnumber,
%$issue_attributes,
}
)->store;
if ( C4::Context->preference('ReturnToShelvingCart') ) {
# ReturnToShelvingCart is on, anything issued should be taken off the cart.
- CartToShelf( $item->{'itemnumber'} );
+ CartToShelf( $item->itemnumber );
}
- $item->{'issues'}++;
+
if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) {
- UpdateTotalIssues( $item->{'biblionumber'}, 1 );
+ UpdateTotalIssues( $item->biblionumber, 1 );
}
## If item was lost, it has now been found, reverse any list item charges if necessary.
- if ( $item->{'itemlost'} ) {
+ if ( $item->itemlost ) {
if (
Koha::RefundLostItemFeeRules->should_refund(
{
current_branch => C4::Context->userenv->{branch},
- item_home_branch => $item->{homebranch},
- item_holding_branch => $item->{holdingbranch}
+ item_home_branch => $item->homebranch,
+ item_holding_branch => $item->holdingbranch,
}
)
)
{
- _FixAccountForLostAndReturned( $item->{'itemnumber'}, undef,
- $item->{'barcode'} );
+ _FixAccountForLostAndReturned( $item->itemnumber, undef,
+ $item->barcode );
}
}
ModItem(
{
- issues => $item->{'issues'},
+ issues => $item->issues + 1,
holdingbranch => C4::Context->userenv->{'branch'},
itemlost => 0,
onloan => $datedue->ymd(),
datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(),
},
- $item->{'biblionumber'},
- $item->{'itemnumber'},
+ $item->biblionumber,
+ $item->itemnumber,
{ log_action => 0 }
);
- ModDateLastSeen( $item->{'itemnumber'} );
+ ModDateLastSeen( $item->itemnumber );
# If it costs to borrow this book, charge it to the patron's account.
- my ( $charge, $itemtype ) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
+ my ( $charge, $itemtype ) = GetIssuingCharges( $item->itemnumber, $borrower->{'borrowernumber'} );
if ( $charge > 0 ) {
AddIssuingCharge( $issue, $charge );
- $item->{'charge'} = $charge;
}
# Record the fact that this book was issued.
type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
amount => $charge,
other => ( $sipmode ? "SIP-$sipmode" : '' ),
- itemnumber => $item->{'itemnumber'},
- itemtype => $item->{'itype'},
- location => $item->{location},
+ itemnumber => $item->itemnumber,
+ itemtype => $item->effective_itemtype,
+ location => $item->location,
borrowernumber => $borrower->{'borrowernumber'},
- ccode => $item->{'ccode'}
+ ccode => $item->ccode,
}
);
my %conditions = (
branchcode => $branch,
categorycode => $borrower->{categorycode},
- item_type => $item->{itype},
+ item_type => $item->effective_itemtype,
notification => 'CHECKOUT',
);
if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
logaction(
"CIRCULATION", "ISSUE",
$borrower->{'borrowernumber'},
- $item->{'itemnumber'}
+ $item->itemnumber,
) if C4::Context->preference("IssueLog");
}
}
my $stat_type = 'return';
# get information on item
- my $item = GetItem( undef, $barcode );
+ my $item = Koha::Items->find({ barcode => $barcode });
unless ($item) {
return ( 0, { BadBarcode => $barcode } ); # no barcode means no item or borrower. bail out.
}
- my $itemnumber = $item->{ itemnumber };
- my $itemtype = $item->{itype}; # GetItem called effective_itemtype
+ my $itemnumber = $item->itemnumber;
+ my $itemtype = $item->effective_itemtype;
my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
if ( $issue ) {
}
}
- if ( $item->{'location'} eq 'PROC' ) {
+ my $item_unblessed = $item->unblessed;
+ if ( $item->location eq 'PROC' ) {
if ( C4::Context->preference("InProcessingToShelvingCart") ) {
- $item->{'location'} = 'CART';
+ $item_unblessed->{location} = 'CART';
}
else {
- $item->{location} = $item->{permanent_location};
+ $item_unblessed->{location} = $item->permanent_location;
}
- ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'}, { log_action => 0 } );
+ ModItem( $item_unblessed, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
}
# full item data, but no borrowernumber or checkout info (no issue)
- my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
+ my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
# get the proper branch to which to return the item
- my $returnbranch = $item->{$hbr} || $branch ;
+ my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
# if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not
}
else {
foreach my $key ( keys %$rules ) {
- if ( $item->{notforloan} eq $key ) {
- $messages->{'NotForLoanStatusUpdated'} = { from => $item->{notforloan}, to => $rules->{$key} };
+ if ( $item->notforloan eq $key ) {
+ $messages->{'NotForLoanStatusUpdated'} = { from => $item->notforloan, to => $rules->{$key} };
ModItem( { notforloan => $rules->{$key} }, undef, $itemnumber, { log_action => 0 } );
last;
}
}
# check if the return is allowed at this branch
- my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
+ my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch);
unless ($returnallowed){
$messages->{'Wrongbranch'} = {
Wrongbranch => $branch,
return ( $doreturn, $messages, $issue, $patron_unblessed);
}
- if ( $item->{'withdrawn'} ) { # book has been cancelled
+ if ( $item->withdrawn ) { # book has been cancelled
$messages->{'withdrawn'} = 1;
$doreturn = 0 if C4::Context->preference("BlockReturnOfWithdrawnItems");
}
- if ( $item->{itemlost} and C4::Context->preference("BlockReturnOfLostItems") ) {
+ if ( $item->itemlost and C4::Context->preference("BlockReturnOfLostItems") ) {
$doreturn = 0;
}
if ($patron) {
eval {
if ( $dropbox ) {
- MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
+ MarkIssueReturned( $borrowernumber, $item->itemnumber,
$dropboxdate, $patron->privacy );
}
else {
- MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
+ MarkIssueReturned( $borrowernumber, $item->itemnumber,
$return_date, $patron->privacy );
}
};
unless ( $@ ) {
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
- _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } );
+ _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed, return_date => $return_date } );
}
} else {
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 );
}
- ModItem( { onloan => undef }, $item->{biblionumber}, $item->{itemnumber}, { log_action => 0 } );
+ ModItem( { onloan => undef }, $item->biblionumber, $item->itemnumber, { log_action => 0 } );
}
# the holdingbranch is updated if the document is returned to another location.
# this is always done regardless of whether the item was on loan or not
- my $item_holding_branch = $item->{ holdingbranch };
- if ($item->{'holdingbranch'} ne $branch) {
- UpdateHoldingbranch($branch, $item->{'itemnumber'});
- $item->{'holdingbranch'} = $branch; # update item data holdingbranch too
+ my $item_holding_branch = $item->holdingbranch;
+ if ($item->holdingbranch ne $branch) {
+ UpdateHoldingbranch($branch, $item->itemnumber);
+ $item_unblessed->{'holdingbranch'} = $branch; # update item data holdingbranch too # FIXME I guess this is for the _debar_user_on_return call later
}
my $leave_item_lost = C4::Context->preference("BlockReturnOfLostItems") ? 1 : 0;
- ModDateLastSeen( $item->{itemnumber}, $leave_item_lost );
+ ModDateLastSeen( $item->itemnumber, $leave_item_lost );
# check if we have a transfer for this document
- my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->{'itemnumber'} );
+ my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->itemnumber );
# if we have a transfer to do, we update the line of transfers with the datearrived
- my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->{'itemnumber'} );
+ my $is_in_rotating_collection = C4::RotatingCollections::isItemInAnyCollection( $item->itemnumber );
if ($datesent) {
if ( $tobranch eq $branch ) {
my $sth = C4::Context->dbh->prepare(
"UPDATE branchtransfers SET datearrived = now() WHERE itemnumber= ? AND datearrived IS NULL"
);
- $sth->execute( $item->{'itemnumber'} );
+ $sth->execute( $item->itemnumber );
# if we have a reservation with valid transfer, we can set it's status to 'W'
- ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
- C4::Reserves::ModReserveStatus($item->{'itemnumber'}, 'W');
+ ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
+ C4::Reserves::ModReserveStatus($item->itemnumber, 'W');
} else {
$messages->{'WrongTransfer'} = $tobranch;
- $messages->{'WrongTransferItem'} = $item->{'itemnumber'};
+ $messages->{'WrongTransferItem'} = $item->itemnumber;
}
$validTransfert = 1;
} else {
- ShelfToCart( $item->{'itemnumber'} ) if ( C4::Context->preference("ReturnToShelvingCart") );
+ ShelfToCart( $item->itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") );
}
# fix up the accounts.....
- if ( $item->{'itemlost'} ) {
+ if ( $item->itemlost ) {
$messages->{'WasLost'} = 1;
unless ( C4::Context->preference("BlockReturnOfLostItems") ) {
if (
Koha::RefundLostItemFeeRules->should_refund(
{
current_branch => C4::Context->userenv->{branch},
- item_home_branch => $item->{homebranch},
+ item_home_branch => $item->homebranch,
item_holding_branch => $item_holding_branch
}
)
)
{
- _FixAccountForLostAndReturned( $item->{'itemnumber'},
+ _FixAccountForLostAndReturned( $item->itemnumber,
$borrowernumber, $barcode );
$messages->{'LostItemFeeRefunded'} = 1;
}
# fix up the overdues in accounts...
if ($borrowernumber) {
- my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
- defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined
+ my $fix = _FixOverduesOnReturn($borrowernumber, $item->itemnumber, $exemptfine, $dropbox);
+ defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->itemnumber...) failed!"; # zero is OK, check defined
if ( $issue and $issue->is_overdue ) {
# fix fine days
$today = dt_from_string($return_date) if $return_date;
$today = $dropboxdate if $dropbox;
- my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today );
+ my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item_unblessed, dt_from_string($issue->date_due), $today );
if ($reminder){
$messages->{'PrevDebarred'} = $debardate;
} else {
# if we don't have a reserve with the status W, we launch the Checkreserves routine
my ($resfound, $resrec);
my $lookahead= C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
- ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->{'itemnumber'}, undef, $lookahead ) unless ( $item->{'withdrawn'} );
+ ($resfound, $resrec, undef) = C4::Reserves::CheckReserves( $item->itemnumber, undef, $lookahead ) unless ( $item->withdrawn );
if ($resfound) {
$resrec->{'ResFound'} = $resfound;
$messages->{'ResFound'} = $resrec;
itemnumber => $itemnumber,
itemtype => $itemtype,
borrowernumber => $borrowernumber,
- ccode => $item->{ ccode }
+ ccode => $item->ccode,
});
# Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
my %conditions = (
branchcode => $branch,
categorycode => $patron->categorycode,
- item_type => $item->{itype},
+ item_type => $itemtype,
notification => 'CHECKIN',
);
if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
SendCirculationAlert({
type => 'CHECKIN',
- item => $item,
+ item => $item_unblessed,
borrower => $patron->unblessed,
branch => $branch,
});
}
- logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
+ logaction("CIRCULATION", "RETURN", $borrowernumber, $item->itemnumber)
if C4::Context->preference("ReturnLog");
}
# Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
+ my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType");
if (C4::Context->preference("AutomaticItemReturn" ) or
(C4::Context->preference("UseBranchTransferLimits") and
- ! IsBranchTransferAllowed($branch, $returnbranch, $item->{C4::Context->preference("BranchTransferLimitsType")} )
+ ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
)) {
- $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $returnbranch;
- $debug and warn "item: " . Dumper($item);
- ModItemTransfer($item->{'itemnumber'}, $branch, $returnbranch);
+ $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->itemnumber,$branch, $returnbranch;
+ $debug and warn "item: " . Dumper($item_unblessed);
+ ModItemTransfer($item->itemnumber, $branch, $returnbranch);
$messages->{'WasTransfered'} = 1;
} else {
$messages->{'NeedsTransfer'} = $returnbranch;
my $dbh = C4::Context->dbh;
my $renews = 1;
- my $item = GetItem($itemnumber) or return ( 0, 'no_item' );
+ my $item = Koha::Items->find($itemnumber) or return ( 0, 'no_item' );
my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
my @reservable;
my %borrowers;
ITEM: foreach my $i (@itemnumbers) {
- my $item = GetItem($i);
+ my $item = Koha::Items->find($i)->unblessed;
next if IsItemOnHoldAndFound($i);
for my $b (@borrowernumbers) {
my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
return ( 1, undef ) if $override_limit;
- my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
+ my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $patron->categorycode,
- itemtype => $item->{itype},
+ itemtype => $item->effective_itemtype,
branchcode => $branchcode
}
);
my $datedue = shift;
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz);
- my $item = GetItem($itemnumber) or return;
- my $item_object = Koha::Items->find( $itemnumber ); # Should replace $item
- my $biblio = $item_object->biblio;
+ my $item = Koha::Items->find($itemnumber) or return;
+ my $biblio = $item->biblio;
+ my $issue = $item->checkout;
+ my $item_unblessed = $item->unblessed;
my $dbh = C4::Context->dbh;
- # Find the issues record for this book
- my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
-
return unless $issue;
$borrowernumber ||= $issue->borrowernumber;
my $patron_unblessed = $patron->unblessed;
if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
- _CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
+ _CalculateAndUpdateFine( { issue => $issue, item => $item_unblessed, borrower => $patron_unblessed } );
}
_FixOverduesOnReturn( $borrowernumber, $itemnumber );
# based on the value of the RenewalPeriodBase syspref.
unless ($datedue) {
- my $itemtype = $item_object->effective_itemtype;
+ my $itemtype = $item->effective_itemtype;
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
dt_from_string( $issue->date_due, 'sql' ) :
DateTime->now( time_zone => C4::Context->tz());
- $datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
+ $datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item_unblessed, $patron_unblessed), $patron_unblessed, 'is a renewal');
}
# Update the issues record to have the new due date, and a new count
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber );
# Update the renewal count on the item, and tell zebra to reindex
- $renews = $item->{renewals} + 1;
- ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->{biblionumber}, $itemnumber, { log_action => 0 } );
+ $renews = $item->renewals + 1;
+ ModItem( { renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $item->biblionumber, $itemnumber, { log_action => 0 } );
# Charge a new rental fee, if applicable?
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
if ( $charge > 0 ) {
my $accountno = C4::Accounts::getnextacctno( $borrowernumber );
my $manager_id = 0;
- $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
+ $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
Koha::Account::Line->new(
{
branchcode => $branchcode,
description => 'Renewal of Rental Item '
. $biblio->title
- . " $item->{'barcode'}",
+ . " $item->barcode",
}
)->store();
}
my %conditions = (
branchcode => $branch,
categorycode => $patron->categorycode,
- item_type => $item->{itype},
+ item_type => $item->effective_itemtype,
notification => 'CHECKOUT',
);
if ( $circulation_alert->is_enabled_for( \%conditions ) ) {
SendCirculationAlert(
{
type => 'RENEWAL',
- item => $item,
+ item => $item_unblessed,
borrower => $patron->unblessed,
branch => $branch,
}
type => 'renew',
amount => $charge,
itemnumber => $itemnumber,
- itemtype => $item->{itype},
- location => $item->{location},
+ itemtype => $item->effective_itemtype,
+ location => $item->location,
borrowernumber => $borrowernumber,
- ccode => $item->{'ccode'}
+ ccode => $item->ccode,
}
);
my $renewsleft = 0;
my $patron = Koha::Patrons->find( $bornum );
- my $item = GetItem($itemno);
+ my $item = Koha::Items->find($itemno);
return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
my $data = $sth->fetchrow_hashref;
$renewcount = $data->{'renewals'} if $data->{'renewals'};
# $item and $borrower should be calculated
- my $branchcode = _GetCircControlBranch($item, $patron->unblessed);
+ my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $patron->categorycode,
- itemtype => $item->{itype},
+ itemtype => $item->effective_itemtype,
branchcode => $branchcode
}
);
my $dbh = C4::Context->dbh;
- my $item = GetItem($itemnumber) or return;
- my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
+ my $item = Koha::Items->find($itemnumber) or return;
+ my $itemissue = $item->checkout or return;
$borrowernumber ||= $itemissue->borrowernumber;
my $patron = Koha::Patrons->find( $borrowernumber )
or return;
- my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
+ my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $patron->categorycode,
- itemtype => $item->{itype},
+ itemtype => $item->effective_itemtype,
branchcode => $branchcode
}
);
my $dbh = C4::Context->dbh;
- my $item = GetItem($itemnumber) or return;
- my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
+ my $item = Koha::Items->find($itemnumber) or return;
+ my $itemissue = $item->checkout or return;
$borrowernumber ||= $itemissue->borrowernumber;
my $patron = Koha::Patrons->find( $borrowernumber )
or return;
- my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
+ my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $patron->categorycode,
- itemtype => $item->{itype},
+ itemtype => $item->effective_itemtype,
branchcode => $branchcode
}
);
MarkIssueReturned( $borrowernumber, $itemnum );
my $patron = Koha::Patrons->find( $borrowernumber );
- my $item = C4::Items::GetItem( $itemnum );
- my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{};
+ my $item = Koha::Items->find($itemnum);
+ my $old_note = ($item->paidfor && ($item->paidfor ne q{})) ? $item->paidfor.' / ' : q{};
my @datearr = localtime(time);
my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
sub TransferSlip {
my ($branch, $itemnumber, $barcode, $to_branch) = @_;
- my $item = GetItem( $itemnumber, $barcode )
- or return;
+ my $item =
+ $itemnumber
+ ? Koha::Items->find($itemnumber)
+ : Koha::Items->find( { barcode => $barcode } );
+
+ $item or return;
return C4::Letters::GetPreparedLetter (
module => 'circulation',
branchcode => $branch,
tables => {
'branches' => $to_branch,
- 'biblio' => $item->{biblionumber},
- 'items' => $item,
+ 'biblio' => $item->biblionumber,
+ 'items' => $item->unblessed,
},
);
}
use List::MoreUtils qw(any);
use C4::Context;
-use C4::Items qw(GetItem ModItem);
+use C4::Items qw(ModItem);
use C4::Circulation qw(GetOpenIssue);
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG @FIELDS);
warn "C4::CourseReserves::_SwapFields( $ci_id )" if $DEBUG;
my $course_item = GetCourseItem( ci_id => $ci_id );
- my $item = GetItem( $course_item->{'itemnumber'} );
+ my $item = Koha::Items->find($course_item->{'itemnumber'});
my %course_item_fields;
my %item_fields;
foreach (@FIELDS) {
if ( defined( $course_item->{$_} ) ) {
$course_item_fields{$_} = $course_item->{$_};
- $item_fields{$_} = $item->{$_} || q{};
+ $item_fields{$_} = $item->$_ || q{};
}
}
use C4::Members;
use C4::Biblio;
use Koha::DateUtils;
+use Koha::Items;
use Koha::Patrons;
use List::Util qw(shuffle);
my $reservenotes = $mapped_item->{reservenotes};
my $item_level = $mapped_item->{item_level};
- my $item = GetItem($itemnumber);
- my $barcode = $item->{barcode};
- my $itemcallnumber = $item->{itemcallnumber};
+ my $item = Koha::Items->find($itemnumber);
+ my $barcode = $item->barcode;
+ my $itemcallnumber = $item->itemcallnumber;
my $patron = Koha::Patrons->find( $borrowernumber );
my $cardnumber = $patron->cardnumber;
my $borrower = $patron->unblessed;
# Get the item, or return an error code if not found
my $itemnumber = $cgi->param('item_id');
- my $item = GetItem( $itemnumber );
- return { code => 'RecordNotFound' } unless $$item{itemnumber};
+ my $item = Koha::Items->find($itemnumber);
+ return { code => 'RecordNotFound' } unless $item;
my @availablefor;
# Reserve level management
- my $biblionumber = $item->{'biblionumber'};
+ my $biblionumber = $item->biblionumber;
my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
if ($canbookbereserved->{status} eq 'OK') {
push @availablefor, 'title level hold';
- my $canitembereserved = IsAvailableForItemLevelRequest($item, $borrower);
+ my $canitembereserved = IsAvailableForItemLevelRequest($item->unblessed, $borrower);
if ($canitembereserved) {
push @availablefor, 'item level hold';
}
}
# Issuing management
- my $barcode = $item->{'barcode'} || '';
+ my $barcode = $item->barcode || '';
$barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
if ($barcode) {
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
# Get the item, or return an error code
my $itemnumber = $cgi->param('item_id');
- my $item = GetItem( $itemnumber );
- return { code => 'RecordNotFound' } unless $$item{itemnumber};
+ my $item = Koha::Items->find($itemnumber);
+ return { code => 'RecordNotFound' } unless $item;
# Add renewal if possible
my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); }
- my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return; # FIXME should be handled
+ return unless $item; # FIXME should be handled
+
+ my $issue = $item->checkout;
+ return $issue; # FIXME should be handled
# Hashref building
my $out;
# Get the item or return an error code
my $itemnumber = $cgi->param('item_id');
- my $item = GetItem( $itemnumber );
- return { code => 'RecordNotFound' } unless $$item{itemnumber};
+ my $item = Koha::Items->find($itemnumber);
+ return { code => 'RecordNotFound' } unless $item;
# If the biblio does not match the item, return an error code
- return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
+ return { code => 'RecordNotFound' } if $item->biblionumber ne $biblio->biblionumber;
# Check for item disponibility
my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber )->{status};
sub _availability {
my ($itemnumber) = @_;
- my $item = GetItem( $itemnumber, undef, undef );
+ my $item = Koha::Items->find($itemnumber);
- if ( not $item->{'itemnumber'} ) {
+ unless ( $item ) {
return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
}
- my $biblionumber = $item->{'biblioitemnumber'};
- my $library = Koha::Libraries->find( $item->{holdingbranch} );
+ my $biblionumber = $item->biblioitemnumber;
+ my $library = Koha::Libraries->find( $item->holdingbranch );
my $location = $library ? $library->branchname : '';
- if ( $item->{'notforloan'} ) {
+ if ( $item->notforloan ) {
return ( $biblionumber, 'not available', 'Not for loan', $location );
- } elsif ( $item->{'onloan'} ) {
+ } elsif ( $item->onloan ) {
return ( $biblionumber, 'not available', 'Checked out', $location );
- } elsif ( $item->{'itemlost'} ) {
+ } elsif ( $item->itemlost ) {
return ( $biblionumber, 'not available', 'Item lost', $location );
- } elsif ( $item->{'withdrawn'} ) {
+ } elsif ( $item->withdrawn ) {
return ( $biblionumber, 'not available', 'Item withdrawn', $location );
- } elsif ( $item->{'damaged'} ) {
+ } elsif ( $item->damaged ) {
return ( $biblionumber, 'not available', 'Item damaged', $location );
} else {
return ( $biblionumber, 'available', undef, $location );
croak "FAILED CartToShelf() - no itemnumber supplied";
}
- my $item = GetItem($itemnumber);
- if ( $item->{location} eq 'CART' ) {
- $item->{location} = $item->{permanent_location};
- ModItem($item, undef, $itemnumber);
+ my $item = Koha::Items->find($itemnumber);
+ if ( $item->location eq 'CART' ) {
+ ModItem({ location => $item->permanent_location}, undef, $itemnumber);
}
}
croak "FAILED ShelfToCart() - no itemnumber supplied";
}
- my $item = GetItem($itemnumber);
- $item->{'location'} = 'CART';
- ModItem($item, undef, $itemnumber);
+ ModItem({ location => 'CART'}, undef, $itemnumber);
}
=head2 AddItemFromMarc
my @fields = qw( itemlost withdrawn damaged );
- # Only call GetItem if we need to set an "on" date field
+ # Only retrieve the item if we need to set an "on" date field
if ( $item->{itemlost} || $item->{withdrawn} || $item->{damaged} ) {
- my $pre_mod_item = GetItem( $item->{'itemnumber'} );
+ my $pre_mod_item = Koha::Items->find( $item->{'itemnumber'} );
for my $field (@fields) {
if ( defined( $item->{$field} )
- and not $pre_mod_item->{$field}
+ and not $pre_mod_item->$field
and $item->{$field} )
{
$item->{ $field . '_on' } =
# while the other treats the MARC representation as authoritative
# under certain circumstances.
- my $itemrecord = GetItem($itemnumber);
+ my $item = Koha::Items->find($itemnumber) or return;
# Tack on 'items.' prefix to column names so that C4::Biblio::TransformKohaToMarc will work.
# Also, don't emit a subfield if the underlying field is blank.
-
- return Item2Marc($itemrecord,$biblionumber);
+ return Item2Marc($item->unblessed, $biblionumber);
}
sub Item2Marc {
my $countanalytics = GetAnalyticsCount($itemnumber);
- # check that there is no issue on this item before deletion.
- my $sth = $dbh->prepare(
- q{
- SELECT COUNT(*) FROM issues
- WHERE itemnumber = ?
- }
- );
- $sth->execute($itemnumber);
- my ($onloan) = $sth->fetchrow;
-
- my $item = GetItem($itemnumber);
+ my $item = Koha::Items->find($itemnumber) or return;
- if ($onloan) {
+ if ($item->checkout) {
$status = "book_on_loan";
}
elsif ( defined C4::Context->userenv
and !C4::Context->IsSuperLibrarian()
and C4::Context->preference("IndependentBranches")
- and ( C4::Context->userenv->{branch} ne $item->{'homebranch'} ) )
+ and ( C4::Context->userenv->{branch} ne $item->homebranch ) )
{
$status = "not_same_branch";
}
else {
# check it doesn't have a waiting reserve
- $sth = $dbh->prepare(
+ my $sth = $dbh->prepare(
q{
SELECT COUNT(*) FROM reserves
WHERE (found = 'W' OR found = 'T')
while ( my $values = $sth->fetchrow_hashref ) {
my $biblionumber = $values->{biblionumber};
my $itemnumber = $values->{itemnumber};
- my $item = C4::Items::GetItem( $itemnumber );
for my $substitution ( @$substitutions ) {
next unless $substitution->{field};
C4::Items::ModItem( {$substitution->{field} => $substitution->{value}}, $biblionumber, $itemnumber )
use C4::Message;
use C4::Items;
my $borrower = { borrowernumber => 1 };
- my $item = C4::Items::GetItem(1);
+ my $item = Koha::Items->find($itemnumber)->unblessed;
my $letter = C4::Letters::GetPreparedLetter (
module => 'circulation',
letter_code => 'CHECKOUT',
# we retrieve borrowers and items informations #
# item->{itype} will come for biblioitems if necessery
- my $item = C4::Items::GetItem($itemnumber);
- my $biblio = Koha::Biblios->find( $item->{biblionumber} );
+ my $item = Koha::Items->find($itemnumber);
+ my $biblio = $item->biblio;
my $patron = Koha::Patrons->find( $borrowernumber );
my $borrower = $patron->unblessed;
# If an item is damaged and we don't allow holds on damaged items, we can stop right here
return { status =>'damaged' }
- if ( $item->{damaged}
+ if ( $item->damaged
&& !C4::Context->preference('AllowHoldsOnDamagedItems') );
# Check for the age restriction
if ( $controlbranch eq "ItemHomeLibrary" ) {
$branchfield = "items.homebranch";
- $branchcode = $item->{homebranch};
+ $branchcode = $item->homebranch;
}
elsif ( $controlbranch eq "PatronLibrary" ) {
$branchfield = "borrowers.branchcode";
}
# we retrieve rights
- if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->{'itype'}, $branchcode ) ) {
+ if ( my $rights = GetHoldRule( $borrower->{'categorycode'}, $item->effective_itemtype, $branchcode ) ) {
$ruleitemtype = $rights->{itemtype};
$allowedreserves = $rights->{reservesallowed};
$holds_per_record = $rights->{holds_per_record};
$ruleitemtype = '*';
}
- $item = Koha::Items->find( $itemnumber );
my $holds = Koha::Holds->search(
{
borrowernumber => $borrowernumber,
my $circ_control_branch =
C4::Circulation::_GetCircControlBranch( $item->unblessed(), $borrower );
my $branchitemrule =
- C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype );
+ C4::Circulation::GetBranchItemRule( $circ_control_branch, $item->itype ); # FIXME Should not be item->effective_itemtype?
if ( $branchitemrule->{holdallowed} == 0 ) {
return { status => 'notReservable' };
if ( C4::Context->preference('IndependentBranches')
and !C4::Context->preference('canreservefromotherbranches') )
{
- my $itembranch = $item->homebranch;
- if ( $itembranch ne $borrower->{branchcode} ) {
+ if ( $item->homebranch ne $borrower->{branchcode} ) {
return { status => 'cannotReserveFromOtherBranches' };
}
}
my $nextreservinfo;
my ( undef, $checkreserves, undef ) = CheckReserves($itemnumber);
if ($checkreserves) {
- my $iteminfo = GetItem($itemnumber);
- if ( $iteminfo->{'holdingbranch'} ne $checkreserves->{'branchcode'} ) {
+ my $item = Koha::Items->find($itemnumber);
+ if ( $item->holdingbranch ne $checkreserves->{'branchcode'} ) {
$messages->{'transfert'} = $checkreserves->{'branchcode'};
#minus priorities of others reservs
ModReserveMinusPriority(
#launch the subroutine dotransfer
C4::Items::ModItemTransfer(
$itemnumber,
- $iteminfo->{'holdingbranch'},
+ $item->holdingbranch,
$checkreserves->{'branchcode'}
),
;
}
} else {
my $patron;
- my $iteminfo;
+ my $item;
my $local_hold_match;
if ($LocalHoldsPriority) {
$patron = Koha::Patrons->find( $res->{borrowernumber} );
- $iteminfo = C4::Items::GetItem($itemnumber);
+ $item = Koha::Items->find($itemnumber);
my $local_holds_priority_item_branchcode =
- $iteminfo->{$LocalHoldsPriorityItemControl};
+ $item->$LocalHoldsPriorityItemControl;
my $local_holds_priority_patron_branchcode =
( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
? $res->{branchcode}
# See if this item is more important than what we've got so far
if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
- $iteminfo ||= C4::Items::GetItem($itemnumber);
- next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
+ $item ||= Koha::Items->find($itemnumber);
+ next if $res->{itemtype} && $res->{itemtype} ne $item->effective_itemtype;
$patron ||= Koha::Patrons->find( $res->{borrowernumber} );
- my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
- my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
+ my $branch = GetReservesControlBranch( $item->unblessed, $patron->unblessed );
+ my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$item->effective_itemtype);
next if ($branchitemrule->{'holdallowed'} == 0);
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
- next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
+ my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
+ next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
$priority = $res->{'priority'};
$highest = $res;
last if $local_hold_match;
);
} elsif ($AcqCreateItem eq 'ordering') {
my $fw = ($acq_fw) ? 'ACQ' : '';
- my @itemnumbers = $order_object->items->get_column('itemnumber');
+ my $items = $order_object->items;
my @items;
- foreach (@itemnumbers) {
- my $item = GetItem($_); # FIXME We do not need this call, we already have the Koha::Items
+ while ( my $i = $items->next ) {
+ my $item = $i->unblessed;
my $descriptions;
$descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
$item->{notforloan} = $descriptions->{lib} // '';
$descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
$item->{materials} = $descriptions->{lib} // '';
- my $itemtype = Koha::ItemTypes->find( $item->{itype} );
+ my $itemtype = Koha::ItemTypes->find($i->effective_itemtype);
if (defined $itemtype) {
+ # We should not do that here, but call ->itemtype->description when needed instead
$item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
}
push @items, $item;
use Koha::Libraries;
use Koha::AuthorisedValues;
+use Koha::Items;
use Koha::ItemTypes;
my $cgi = new CGI;
my $item = {};
my $itemnumber = $cgi->param('itemnumber');
+my $item_unblessed = {};
if($itemnumber) {
my $acq_fw = GetMarcStructure(1, 'ACQ');
my $fw = ($acq_fw) ? 'ACQ' : '';
- $item = GetItem($itemnumber);
+ $item = Koha::Items->find($itemnumber);
+ $item_unblessed = $item->unblessed; # FIXME Not needed, call home_branch and holding_branch in the templates instead
- if($item->{homebranch}) {
- $item->{homebranchname} = Koha::Libraries->find($item->{homebranch})->branchname;
+ if($item->homebranch) { # This test should not be needed, homebranch and holdingbranch are mandatory
+ $item_unblessed->{homebranchname} = $item->home_branch->branchname;
}
- if($item->{holdingbranch}) {
- $item->{holdingbranchname} = Koha::Libraries->find($item->{holdingbranch})->branchname;
+ if($item->holdingbranch) {
+ $item_unblessed->{holdingbranchname} = $item->holding_branch->branchname;
}
my $descriptions;
- $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->{notforloan} });
- $item->{notforloan} = $descriptions->{lib} // '';
+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.notforloan', authorised_value => $item->notforloan });
+ $item_unblessed->{notforloan} = $descriptions->{lib} // '';
- $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->{restricted} });
- $item->{restricted} = $descriptions->{lib} // '';
+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.restricted', authorised_value => $item->restricted });
+ $item_unblessed->{restricted} = $descriptions->{lib} // '';
- $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->{location} });
- $item->{location} = $descriptions->{lib} // '';
+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.location', authorised_value => $item->location });
+ $item_unblessed->{location} = $descriptions->{lib} // '';
- $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->{collection} });
- $item->{collection} = $descriptions->{lib} // '';
+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.collection', authorised_value => $item->collection });
+ $item_unblessed->{collection} = $descriptions->{lib} // '';
- $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->{materials} });
- $item->{materials} = $descriptions->{lib} // '';
+ $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => $item->materials });
+ $item_unblessed->{materials} = $descriptions->{lib} // '';
- my $itemtype = Koha::ItemTypes->find( $item->{itype} );
- $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
+ my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype );
+ # We should not do that here, but call ->itemtype->description when needed instea
+ $item_unblessed->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description?
}
-my $json_text = to_json( $item, { utf8 => 1 } );
+my $json_text = to_json( $item_unblessed, { utf8 => 1 } );
output_with_http_headers $cgi, undef, $json_text, 'json';
my $dbh = C4::Context->dbh;
# get the rest of this item's information
-my $item_data_hashref = GetItem($itemnumber, undef);
+my $item_data_hashref = Koha::Items->find($itemnumber)->unblessed;
# make sure item statuses are set to 0 if empty or NULL
for ($damaged,$itemlost,$withdrawn) {
sub set_item_default_location {
my $itemnumber = shift;
- my $item = GetItem( $itemnumber );
+ my $item = Koha::Items->find($itemnumber);
if ( C4::Context->preference('NewItemsDefaultLocation') ) {
- $item->{'permanent_location'} = $item->{'location'};
- $item->{'location'} = C4::Context->preference('NewItemsDefaultLocation');
- ModItem( $item, undef, $itemnumber);
+ ModItem(
+ {
+ permanent_location => $item->location,
+ location => C4::Context->preference('NewItemsDefaultLocation')
+ },
+ undef,
+ $itemnumber
+ );
}
else {
- $item->{'permanent_location'} = $item->{'location'} if !defined($item->{'permanent_location'});
- ModItem( $item, undef, $itemnumber);
+ ModItem( { permanent_location => $item->location }, undef, $itemnumber )
+ unless defined $item->permanent_location;
}
}
if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
push @errors,"barcode_not_unique";
} else {
- my $item = GetItem( $itemnumber );
+ my $item = Koha::Items->find($itemnumber );
my $newitem = ModItemFromMarc($itemtosave, $biblionumber, $itemnumber);
$itemnumber = q{};
- my $olditemlost = $item->{itemlost};
+ my $olditemlost = $item->itemlost;
my $newitemlost = $newitem->{itemlost};
- LostItem( $item->{itemnumber}, 'additem' )
+ LostItem( $item->itemnumber, 'additem' )
if $newitemlost && $newitemlost ge '1' && !$olditemlost;
}
$nextop="additem";
my $update = $dbh->prepare($query);
# $debug and print "Update Query: $query\n";
foreach (@itemnumbers) {
- my $item = GetItem($_);
- unless ($item) {
+ my $item = Koha::Items->find($_);
+ unless ($item) {
print STDERR "\tNo item found for itemnumber $_\n";
next;
}
- $update->execute($item->{itype},$_) or warn "Error in UPDATE execution";
- printf "\titemnumber %5d : %7s (%s rows)\n", $_, $item->{itype}, $update->rows;
+ my $itemtype = $item->effective_itemtype;
+ $update->execute($itemtype,$_) or warn "Error in UPDATE execution";
+ printf "\titemnumber %5d : %7s (%s rows)\n", $_, $itemtype, $update->rows;
}
my $old_issues = $dbh->prepare("SELECT * FROM old_issues WHERE timestamp = ? AND itemnumber = ?");
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
-use C4::Items qw(GetItem);
use C4::Creators;
use C4::Labels;
my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a <cr> separated list
foreach my $number (@numbers_list) {
$number =~ s/\r$//; # strip any naughty return chars
- if( $number_type eq "itemnumber" && GetItem($number) ) {
+ if( $number_type eq "itemnumber" && Koha::Items->find($number) ) {
push @item_numbers, $number;
}
elsif ($number_type eq "barcode" ) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm
use C4::Items;
use Data::Dumper;
use Getopt::Long;
+use Koha::Items;
my $dbh = C4::Context->dbh;
my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
$substh = $dbh->prepare($insert);
- my $item = GetItem($hashref->{'itemnumber'});
+ my $item = Koha::Items->find($hashref->{'itemnumber'});
+ my $itemtype = $item->effective_itemtype;
$substh->execute(
$hashref->{'issuedate'},
'issue',
'',
$hashref->{'itemnumber'},
- $item->{'itype'},
+ $itemtype,
$hashref->{'borrowernumber'}
);
- print "date: $hashref->{'issuedate'} branchcode: $hashref->{'branchcode'} type: issue itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n";
+ print "date: $hashref->{'issuedate'} branchcode: $hashref->{'branchcode'} type: issue itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n";
$count_issues++;
}
my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
$substh = $dbh->prepare($insert);
- my $item = GetItem($hashref->{'itemnumber'});
+ my $item = Koha::Items->find($hashref->{'itemnumber'});
+ my $itemtype = $item->effective_itemtype;
$substh->execute(
$hashref->{'lastreneweddate'},
'renew',
'',
$hashref->{'itemnumber'},
- $item->{'itype'},
+ $itemtype,
$hashref->{'borrowernumber'}
);
- print "date: $hashref->{'lastreneweddate'} branchcode: $hashref->{'branchcode'} type: renew itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n";
+ print "date: $hashref->{'lastreneweddate'} branchcode: $hashref->{'branchcode'} type: renew itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n";
$count_renewals++;
}
my $insert = "INSERT INTO statistics (datetime, branch, value, type, other, itemnumber, itemtype, borrowernumber)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
$substh = $dbh->prepare($insert);
- my $item = GetItem($hashref->{'itemnumber'});
+ my $item = Koha::Items->find($hashref->{'itemnumber'});
+ my $itemtype = $item->effective_itemtype;
$substh->execute(
$hashref->{'returndate'},
'return',
'',
$hashref->{'itemnumber'},
- $item->{'itype'},
+ $itemtype,
$hashref->{'borrowernumber'}
);
- print "date: $hashref->{'returndate'} branchcode: $hashref->{'branchcode'} type: return itemnumber: $hashref->{'itemnumber'} itype: $item->{'itype'} borrowernumber: $hashref->{'borrowernumber'}\n";
+ print "date: $hashref->{'returndate'} branchcode: $hashref->{'branchcode'} type: return itemnumber: $hashref->{'itemnumber'} itype: $itemtype borrowernumber: $hashref->{'borrowernumber'}\n";
$count_returns++;
}
use C4::Context;
use C4::Items;
use C4::Members;
+use Koha::Items;
use Koha::Patrons;
use Date::Calc qw( Today Date_to_Days );
my $query = new CGI;
my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
my $branchcode;
if ( $renewalbranch eq 'itemhomebranch' ) {
- my $item = GetItem($itemnumber);
- $branchcode = $item->{'homebranch'};
+ my $item = Koha::Items->find($itemnumber);
+ $branchcode = $item->homebranch;
}
elsif ( $renewalbranch eq 'patronhomebranch' ) {
$branchcode = Koha::Patrons->find( $borrowernumber )->branchcode;
}
elsif ( $renewalbranch eq 'checkoutbranch' ) {
- my $issue = GetOpenIssue($itemnumber);
+ my $issue = GetOpenIssue($itemnumber); # FIXME Should not be $item->checkout?
$branchcode = $issue->{'branchcode'};
}
elsif ( $renewalbranch eq 'NULL' ) {
$shelf = Koha::Virtualshelves->find($shelfnumber);
if ($shelf) {
if( my $barcode = $query->param('barcode') ) {
- my $item = GetItem( 0, $barcode);
- if (defined $item && $item->{itemnumber}) {
+ my $item = Koha::Items->find({ barcode => $barcode });
+ if ( $item ) {
if ( $shelf->can_biblios_be_added( $loggedinuser ) ) {
- my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); };
+ my $added = eval { $shelf->add_biblio( $item->biblionumber, $loggedinuser ); };
if ($@) {
push @messages, { type => 'error', code => ref($@), msg => $@ };
} elsif ( $added ) {
use C4::Items;
use Koha::DateUtils qw( dt_from_string );
use Koha::Acquisition::Currencies;
+use Koha::Items;
use Koha::Patrons;
use Koha::Patron::Images;
use Koha::Patron::Messages;
$query->param("confirmed") || '',
$query->param("newissues") || '',
);
+
my @newissueslist = split /,/, $newissues;
my $issuenoconfirm = 1; #don't need to confirm on issue.
my $issuer = Koha::Patrons->find( $issuerid )->unblessed;
-my $item = GetItem(undef,$barcode);
+my $item = Koha::Items->find({ barcode => $barcode });
if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) {
my $dbh = C4::Context->dbh;
my $resval;
$template->param(
impossible => $issue_error,
"circ_error_$issue_error" => 1,
- title => $item->{title},
+ title => $item->biblio->title, # FIXME Need to be backport! GetItem did not return the biblio's title
hide_main => 1,
);
if ($issue_error eq 'DEBT') {
} elsif ( $needconfirm->{RENEW_ISSUE} || $op eq 'renew' ) {
if ($confirmed) {
#warn "renewing";
- AddRenewal( $borrower->{borrowernumber}, $item->{itemnumber} );
+ AddRenewal( $borrower->{borrowernumber}, $item->itemnumber );
push @newissueslist, $barcode;
$template->param( renewed => 1 );
} else {
$confirm_required = 1;
#warn "issue confirmation";
$template->param(
- confirm => "Issuing title: " . $item->{title},
+ confirm => "Issuing title: " . $item->biblio->title,
barcode => $barcode,
hide_main => 1,
inputfocus => 'confirm',
use C4::Circulation;
use C4::Members;
use C4::Auth qw/checkauth/;
+
+use Koha::Items;
use Koha::Patrons;
my $input = CGI->new();
}
if ( defined $checkitem && $checkitem ne '' ) {
- my $item = GetItem($checkitem);
- if ( $item->{'biblionumber'} ne $biblionumber ) {
- $biblionumber = $item->{'biblionumber'};
+ my $item = Koha::Items->find($checkitem);
+ if ( $item->biblionumber ne $biblionumber ) {
+ $biblionumber = $item->biblionumber;
}
}
use JSON qw(to_json);
use C4::Circulation;
-use C4::Items qw(GetItem ModItem);
+use C4::Items qw(ModItem);
use C4::Context;
use C4::Auth qw(check_cookie_auth);
use Koha::Checkouts;
$data->{branchcode} = $branchcode;
if ( C4::Context->preference("InProcessingToShelvingCart") ) {
- my $item = GetItem($itemnumber);
- if ( $item->{'location'} eq 'PROC' ) {
- $item->{'location'} = 'CART';
- ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
+ my $item = Koha::Items->find($itemnumber);
+ if ( $item->location eq 'PROC' ) {
+ ModItem( { location => 'CART' }, $item->biblionumber, $item->itemnumber );
}
}
if ( C4::Context->preference("ReturnToShelvingCart") ) {
- my $item = GetItem($itemnumber);
- $item->{'location'} = 'CART';
- ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
+ my $item = Koha::Items->find($itemnumber);
+ ModItem( { location => 'CART' }, $item->biblionumber, $item->itemnumber );
}
my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
use Koha::DateUtils;
use Koha::Acquisition::Booksellers;
use Koha::Acquisition::Orders;
+use Koha::Items;
use MARC::Record;
my $schema = Koha::Database->new()->schema();
"Create items on ordering: items are not deleted after cancelling a receipt"
);
-my $item1 = C4::Items::GetItem( $itemnumber1 );
-is( $item1->{notforloan}, 9, "The notforloan value has been updated with '9'" );
+my $item1 = Koha::Items->find( $itemnumber1 );
+is( $item1->notforloan, 9, "The notforloan value has been updated with '9'" );
-my $item2 = C4::Items::GetItem( $itemnumber2 );
-is( $item2->{notforloan}, 0, "The notforloan value has been updated with '9'" );
+my $item2 = Koha::Items->find( $itemnumber2 );
+is( $item2->notforloan, 0, "The notforloan value has been updated with '9'" );
$schema->storage->txn_rollback();
use Koha::DateUtils;
use Koha::Database;
use Koha::IssuingRules;
+use Koha::Items;
use Koha::Checkouts;
use Koha::Patrons;
use Koha::Subscriptions;
my $passeddatedue1 = AddIssue($renewing_borrower, $item_7->barcode, $five_weeks_ago);
is (defined $passeddatedue1, 1, "Item with passed date due checked out, due date: " . $passeddatedue1->date_due);
- my ( $fine ) = CalcFine( GetItem(undef, $item_7->barcode), $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
+ my ( $fine ) = CalcFine( $item_7->unblessed, $renewing_borrower->{categorycode}, $branch, $five_weeks_ago, $now );
C4::Overdues::UpdateFine(
{
issue_id => $passeddatedue1->id(),
use C4::Biblio;
use Koha::Database;
use Koha::DateUtils;
+use Koha::Items;
use Koha::Patrons;
use t::lib::TestBuilder;
t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 1 );
AddReturn( $barcode, $branch );
- $item = GetItem( $itemnumber );
- is( $item->{location}, 'CART',
+ $item = Koha::Items->find( $itemnumber );
+ is( $item->location, 'CART',
"InProcessingToShelvingCart functions as intended" );
- $item->{location} = $location;
- ModItem( $item, undef, $itemnumber );
+ ModItem( {location => $location}, undef, $itemnumber );
t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 0 );
AddReturn( $barcode, $branch );
- $item = GetItem( $itemnumber );
- is( $item->{location}, $permanent_location,
+ $item = Koha::Items->find( $itemnumber );
+ is( $item->location, $permanent_location,
"InProcessingToShelvingCart functions as intended" );
};
use Koha::Database;
use Koha::DateUtils;
use Koha::Holds;
+use Koha::Items;
use Koha::Library;
use Koha::Patrons;
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', q{} );
AddReturn( 'barcode_3', $branchcode_1 );
-my $item = GetItem( $itemnumber );
-ok( $item->{notforloan} eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' );
+my $item = Koha::Items->find( $itemnumber );
+ok( $item->notforloan eq 1, 'UpdateNotForLoanStatusOnCheckin does not modify value when not enabled' );
t::lib::Mocks::mock_preference( 'UpdateNotForLoanStatusOnCheckin', '1: 9' );
AddReturn( 'barcode_3', $branchcode_1 );
-$item = GetItem( $itemnumber );
-ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} );
+$item = Koha::Items->find( $itemnumber );
+ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin updates notforloan value from 1 to 9 with setting "1: 9"} );
AddReturn( 'barcode_3', $branchcode_1 );
-$item = GetItem( $itemnumber );
-ok( $item->{notforloan} eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
+$item = Koha::Items->find( $itemnumber );
+ok( $item->notforloan eq 9, q{UpdateNotForLoanStatusOnCheckin does not update notforloan value from 9 with setting "1: 9"} );
# Bug 14640 - Cancel the hold on checking out if asked
my $reserve_id = AddReserve($branchcode_1, $borrower_id1, $biblionumber,
use C4::Circulation;
use C4::Items;
use Koha::IssuingRule;
+use Koha::Items;
use Test::More tests => 6;
$dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber")
or BAIL_OUT("Cannot find newly created item");
-my $item1 = GetItem( $itemnumber1 );
+my $item1 = Koha::Items->find( $itemnumber1 )->unblessed;
$dbh->do("
INSERT INTO items (barcode, biblionumber, biblioitemnumber, homebranch, holdingbranch, notforloan, damaged, itemlost, withdrawn, onloan, itype)
$dbh->selectrow_array("SELECT itemnumber FROM items WHERE biblionumber = $biblionumber ORDER BY itemnumber DESC")
or BAIL_OUT("Cannot find newly created item");
-my $item2 = GetItem( $itemnumber2 );
+my $item2 = Koha::Items->find( $itemnumber2 )->unblessed;
$dbh->do("DELETE FROM issuingrules");
my $rule = Koha::IssuingRule->new(
subtest 'Item is available at a different library' => sub {
plan tests => 4;
- Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_B, holdingbranch => $library_B })->store;
- $item1 = GetItem( $itemnumber1 );
+ $item1 = Koha::Items->find( $item1->{itemnumber} );
+ $item1->set({homebranch => $library_B, holdingbranch => $library_B })->store;
+ $item1 = $item1->unblessed;
#Scenario is:
#One shelf holds is 'If all unavailable'/2
#Item 1 homebranch library B is available
subtest 'Item is available at the same library' => sub {
plan tests => 4;
- Koha::Items->find( $item1->{itemnumber} )->set({homebranch => $library_A, holdingbranch => $library_A })->store;
- $item1 = GetItem( $itemnumber1 );
+ $item1 = Koha::Items->find( $item1->{itemnumber} );
+ $item1->set({homebranch => $library_A, holdingbranch => $library_A })->store;
+ $item1 = $item1->unblessed;
#Scenario is:
#One shelf holds is 'If all unavailable'/2
#Item 1 homebranch library A is available
cmp_ok($item_bibitemnum, '==', $biblio->biblioitem->biblioitemnumber, "New item is linked to correct biblioitemnumber.");
# Get item.
- my $getitem = GetItem($itemnumber);
- cmp_ok($getitem->{'itemnumber'}, '==', $itemnumber, "Retrieved item has correct itemnumber.");
- cmp_ok($getitem->{'biblioitemnumber'}, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber.");
- is( $getitem->{location}, $location, "The location should not have been modified" );
- is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to the location value" );
+ my $getitem = Koha::Items->find($itemnumber);
+ cmp_ok($getitem->itemnumber, '==', $itemnumber, "Retrieved item has correct itemnumber.");
+ cmp_ok($getitem->biblioitemnumber, '==', $item_bibitemnum, "Retrieved item has correct biblioitemnumber.");
+ is( $getitem->location, $location, "The location should not have been modified" );
+ is( $getitem->permanent_location, $location, "The permanent_location should have been set to the location value" );
# Do not modify anything, and do not explode!
# Modify item; setting barcode.
ModItem({ barcode => '987654321' }, $biblio->biblionumber, $itemnumber);
- my $moditem = GetItem($itemnumber);
- cmp_ok($moditem->{'barcode'}, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->{'barcode'} . '.');
+ my $moditem = Koha::Items->find($itemnumber);
+ cmp_ok($moditem->barcode, '==', '987654321', 'Modified item barcode successfully to: '.$moditem->barcode . '.');
# Delete item.
DelItem({ biblionumber => $biblio->biblionumber, itemnumber => $itemnumber });
- my $getdeleted = GetItem($itemnumber);
- is($getdeleted->{'itemnumber'}, undef, "Item deleted as expected.");
+ my $getdeleted = Koha::Items->find($itemnumber);
+ is($getdeleted, undef, "Item deleted as expected.");
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $biblio->biblionumber);
- $getitem = GetItem($itemnumber);
- is( $getitem->{location}, $location, "The location should not have been modified" );
- is( $getitem->{permanent_location}, 'my permanent location', "The permanent_location should not have modified" );
+ $getitem = Koha::Items->find($itemnumber);
+ is( $getitem->location, $location, "The location should not have been modified" );
+ is( $getitem->permanent_location, 'my permanent location', "The permanent_location should not have modified" );
ModItem({ location => $location }, $biblio->biblionumber, $itemnumber);
- $getitem = GetItem($itemnumber);
- is( $getitem->{location}, $location, "The location should have been set to correct location" );
- is( $getitem->{permanent_location}, $location, "The permanent_location should have been set to location" );
+ $getitem = Koha::Items->find($itemnumber);
+ is( $getitem->location, $location, "The location should have been set to correct location" );
+ is( $getitem->permanent_location, $location, "The permanent_location should have been set to location" );
ModItem({ location => 'CART' }, $biblio->biblionumber, $itemnumber);
- $getitem = GetItem($itemnumber);
- is( $getitem->{location}, 'CART', "The location should have been set to CART" );
- is( $getitem->{permanent_location}, $location, "The permanent_location should not have been set to CART" );
+ $getitem = Koha::Items->find($itemnumber);
+ is( $getitem->location, 'CART', "The location should have been set to CART" );
+ is( $getitem->permanent_location, $location, "The permanent_location should not have been set to CART" );
t::lib::Mocks::mock_preference('item-level_itypes', '1');
- $getitem = GetItem($itemnumber);
- is( $getitem->{itype}, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" );
+ $getitem = Koha::Items->find($itemnumber);
+ is( $getitem->effective_itemtype, $itemtype->{itemtype}, "Itemtype set correctly when using item-level_itypes" );
t::lib::Mocks::mock_preference('item-level_itypes', '0');
- $getitem = GetItem($itemnumber);
- is( $getitem->{itype}, $biblio->biblioitem->itemtype, "Itemtype set correctly when not using item-level_itypes" );
+ $getitem = Koha::Items->find($itemnumber);
+ is( $getitem->effective_itemtype, $biblio->biblioitem->itemtype, "Itemtype set correctly when not using item-level_itypes" );
$schema->storage->txn_rollback;
};
my @itemnumbers = ($item1_itemnumber,$item2_itemnumber);
my @hidden;
my @items;
- push @items, GetItem( $item1_itemnumber );
- push @items, GetItem( $item2_itemnumber );
+ push @items, Koha::Items->find( $item1_itemnumber )->unblessed;
+ push @items, Koha::Items->find( $item2_itemnumber )->unblessed;
# Empty OpacHiddenItems
t::lib::Mocks::mock_preference('OpacHiddenItems','');
ModItemFromMarc($item3_record, $biblio->biblionumber, $item3_itemnumber);
# Make sure the link is used
- my $item3 = GetItem($item3_itemnumber);
- ok($item3->{itemnotes} eq 'foobar', 'itemnotes eq "foobar"');
+ my $item3 = Koha::Items->find($item3_itemnumber);
+ ok($item3->itemnotes eq 'foobar', 'itemnotes eq "foobar"');
# Do the same search again.
# This time it will search in items.itemnotes
my (undef, undef, $item_itemnumber) = AddItemFromMarc($item_record, $biblio->biblionumber);
# Make sure everything has been set up
- my $item = GetItem($item_itemnumber);
- is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
+ my $item = Koha::Items->find($item_itemnumber);
+ is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
# Delete the barcode field and save the record
$item_record->delete_fields( $barcode_field );
$item_record->append_fields( $itemtype_field ); # itemtype is mandatory
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
- $item = GetItem($item_itemnumber);
- is( $item->{barcode}, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
+ $item = Koha::Items->find($item_itemnumber);
+ is( $item->barcode, undef, 'The default value should have been set to the barcode, the field is mapped to a kohafield' );
# Re-add the barcode field and save the record
$item_record->append_fields( $barcode_field );
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
- $item = GetItem($item_itemnumber);
- is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
+ $item = Koha::Items->find($item_itemnumber);
+ is( $item->barcode, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
# Remove the mapping for barcode
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
$item_record->append_fields( $another_barcode_field );
# The DB value should not have been updated
ModItemFromMarc($item_record, $biblio->biblionumber, $item_itemnumber);
- $item = GetItem($item_itemnumber);
- is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
+ $item = Koha::Items->find($item_itemnumber);
+ is ( $item->barcode, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
$cache->clear_from_cache("default_value_for_mod_marc-");
$cache->clear_from_cache( "MarcSubfieldStructure-" );
use C4::Biblio;
use C4::Context;
use Koha::DateUtils;
+use Koha::Items;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
$biblionumber
);
-my $item = C4::Items::GetItem( $itemnumber );
-is ( $item->{new_status}, 'new_value', q|AddItem insert the 'new_status' field| );
+my $item = Koha::Items->find( $itemnumber );
+is ( $item->new_status, 'new_value', q|AddItem insert the 'new_status' field| );
my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', $frameworkcode);
my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
C4::Items::ToggleNewStatus( { rules => \@rules } );
-my $modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is updated|);
+my $modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: The new_status value is updated|);
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is updated| );
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|);
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is not updated| );
# Play with age
-$item = C4::Items::GetItem( $itemnumber );
my $dt_today = dt_from_string;
my $days5ago = $dt_today->add_duration( DateTime::Duration->new( days => -5 ) );
C4::Items::ModItem( { dateaccessioned => $days5ago }, $biblionumber, $itemnumber );
-$item = C4::Items::GetItem( $itemnumber );
@rules = (
{
},
);
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|);
$rules[0]->{age} = 5;
$rules[0]->{substitutions}[0]{value} = 'new_updated_value5';
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|);
$rules[0]->{age} = '';
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string';
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|);
$rules[0]->{age} = undef;
$rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef';
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|);
# Field deletion
@rules = (
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, '', q|ToggleNewStatus: The new_status value is empty|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, '', q|ToggleNewStatus: The new_status value is empty|);
$marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber );
is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new_status field is removed from the item marc| );
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|);
@rules = (
{
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-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|);
+$modified_item = Koha::Items->find( $itemnumber );
+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|);
@rules = (
{
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|);
@rules = (
{
C4::Items::ToggleNewStatus( { rules => \@rules } );
-$modified_item = C4::Items::GetItem( $itemnumber );
-is( $modified_item->{new_status}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
+$modified_item = Koha::Items->find( $itemnumber );
+is( $modified_item->new_status, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|);
# Clear cache
$cache = Koha::Caches->get_instance();
use C4::Items;
use C4::Biblio;
+use Koha::Items;
+
use t::lib::TestBuilder;
use Test::More tests => 6;
my $deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
-my $deleted_item = GetItem($itemnumber);
-is( $deleted_item->{itemnumber}, undef, "DelItem with biblionumber parameter - the item should be deleted." );
+my $deleted_item = Koha::Items->find($itemnumber);
+is( $deleted_item, undef, "DelItem with biblionumber parameter - the item should be deleted." );
( $item_bibnum, $item_bibitemnum, $itemnumber ) =
AddItem( { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode} }, $biblio->biblionumber );
$deleted = DelItem( { biblionumber => $biblio->biblionumber, itemnumber => $itemnumber } );
is( $deleted, 1, "DelItem should return 1 if the item has been deleted" );
-$deleted_item = GetItem($itemnumber);
-is( $deleted_item->{itemnumber}, undef, "DelItem without biblionumber parameter - the item should be deleted." );
+$deleted_item = Koha::Items->find($itemnumber);
+is( $deleted_item, undef, "DelItem without biblionumber parameter - the item should be deleted." );
$deleted = DelItem( { itemnumber => $itemnumber + 1} );
is ( $deleted, 0, "DelItem should return 0 if no item has been deleted" );
use C4::Reserves;
use Koha::Database;
use Koha::Holds;
+use Koha::Items;
use t::lib::TestBuilder;
use Data::Dumper qw|Dumper|;
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' );
-my $get_item1 = C4::Items::GetItem( $item1->{itemnumber} );
-is( $get_item1->{biblionumber}, $from_biblio->{biblionumber}, 'The item1 should not have been moved' );
-my $get_item2 = C4::Items::GetItem( $item2->{itemnumber} );
-is( $get_item2->{biblionumber}, $to_biblio->{biblionumber}, 'The item2 should have been moved' );
-my $get_item3 = C4::Items::GetItem( $item3->{itemnumber} );
-is( $get_item3->{biblionumber}, $to_biblio->{biblionumber}, 'The item3 should not have been moved' );
+my $get_item1 = Koha::Items->find( $item1->{itemnumber} );
+is( $get_item1->biblionumber, $from_biblio->{biblionumber}, 'The item1 should not have been moved' );
+my $get_item2 = Koha::Items->find( $item2->{itemnumber} );
+is( $get_item2->biblionumber, $to_biblio->{biblionumber}, 'The item2 should have been moved' );
+my $get_item3 = Koha::Items->find( $item3->{itemnumber} );
+is( $get_item3->biblionumber, $to_biblio->{biblionumber}, 'The item3 should not have been moved' );
my $get_bib_level_hold = Koha::Holds->find( $bib_level_hold_not_to_move->{reserve_id} );
my $get_item_level_hold_1 = Koha::Holds->find( $item_level_hold_not_to_move->{reserve_id} );
use C4::Circulation;
use Koha::Database;
+use Koha::Items;
use t::lib::TestBuilder;
use t::lib::Mocks;
DelItemCheck( $biblio->{biblionumber}, $item->{itemnumber} );
-my $test_item = GetItem( $item->{itemnumber} );
+my $test_item = Koha::Items->find( $item->{itemnumber} );
-is( $test_item->{itemnumber}, undef,
+is( $test_item, undef,
"DelItemCheck should delete item if ItemSafeToDelete returns true"
);
use Koha::Caches;
use Koha::DateUtils;
use Koha::Holds;
+use Koha::Items;
use Koha::Libraries;
use Koha::Notice::Templates;
use Koha::Patrons;
####### EO Bug 13113 <<<
####
-$item = GetItem($itemnumber);
+$item = Koha::Items->find($itemnumber)->unblessed;
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
foreach my $itemnumber(@itemnumbers){
$job->progress($i) if $runinbackground;
- my $itemdata = GetItem($itemnumber);
+ my $itemdata = Koha::Items->find($itemnumber);
+ next unless $itemdata; # Should have been tested earlier, but just in case...
+ $itemdata = $itemdata->unblessed;
if ( $del ){
my $return = DelItemCheck( $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
if ($return == 1) {
my ( $itemtagfield, $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
my ($branchtagfield, $branchtagsubfield) = &GetMarcFromKohaField("items.homebranch", "");
foreach my $itemnumber (@itemnumbers){
- my $itemdata=GetItem($itemnumber);
+ my $itemdata = Koha::Items->find($itemnumber);
+ next unless $itemdata; # Should have been tested earlier, but just in case...
+ $itemdata = $itemdata->unblessed;
my $itemmarc=Item2Marc($itemdata);
my %this_row;
foreach my $field (grep {$_->tag() eq $itemtagfield} $itemmarc->fields()) {
use Koha::AuthorisedValues;
use Koha::BiblioFrameworks;
use Koha::ClassSources;
+use Koha::Items;
use List::MoreUtils qw( none );
my $minlocation=$input->param('minlocation') || '';
if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
} else {
- my $item = GetItem( '', $barcode );
- if ( defined $item && $item->{'itemnumber'} ) {
+ my $item = Koha::Items->find({barcode => $barcode});
+ if ( $item ) {
+ $item = $item->unblessed;
# Modify date last seen for scanned items, remove lost status
ModItem( { itemlost => 0, datelastseen => $date }, undef, $item->{'itemnumber'} );
$moddatecount++;
use C4::Serials;
use C4::Debug;
use C4::Search; # enabled_staff_search_views
+
+use Koha::Items;
use Koha::Patrons;
use vars qw($debug $cgi_debug);
# get item information so we can create a working link
my $itemnumber = $result->{'object'};
$itemnumber = $result->{'info'} if ( $result->{module} eq "CIRCULATION" );
- my $item = GetItem($itemnumber);
+ my $item = Koha::Items->find($itemnumber);
if ($item) {
- $result->{'biblionumber'} = $item->{'biblionumber'};
- $result->{'biblioitemnumber'} = $item->{'biblionumber'};
- $result->{'barcode'} = $item->{'barcode'};
+ $result->{'biblionumber'} = $item->biblionumber;
+ $result->{'biblioitemnumber'} = $item->biblionumber;
+ $result->{'barcode'} = $item->barcode;
}
}
use Koha::Biblios;
use Koha::Biblioitems;
+use Koha::Items;
use Koha::ItemTypes;
use Koha::CsvProfiles;
use Koha::Patrons;
foreach my $barcode (@barcodes){
$barcode =~ s/\r$//; # strip any naughty return chars
next if $barcode eq '';
- my $item = GetItem( 0, $barcode);
- if (defined $item && $item->{itemnumber}) {
- my $added = eval { $shelf->add_biblio( $item->{biblionumber}, $loggedinuser ); };
+ my $item = Koha::Items->find({barcode => $barcode});
+ if ( $item ) {
+ my $added = eval { $shelf->add_biblio( $item->biblionumber, $loggedinuser ); };
if ($@) {
push @messages, { item_barcode => $barcode, type => 'alert', code => ref($@), msg => $@ };
} elsif ( $added ) {