Commit 31c29fd3 authored by joubu's avatar joubu Committed by root

Bug 21206: Replace C4::Items::GetItem

Note: This is here for information purpose, feel free to test it if you
wan to play with it.

TODO: C4::Reserves::_get_itype is not longer in use

No more GetItem must be returned by:
git grep GetItem|grep -v GetItemsAvailableToFillHoldRequestsForBib|grep
-v GetItemsForInventory|grep -v GetItemsInfo|grep -v
GetItemsLocationInfo|grep -v GetItemsInCollection|grep -v
GetItemCourseReservesInfo|grep -v GetItemnumbersFromOrder|grep -v
GetItemSearchField|grep -v GetItemTypesCategorized|grep -v
GetItemNumbersFromImportBatch|cut -d':' -f1|sort|uniq
Signed-off-by: Josef Moravec's avatarJosef Moravec <josef.moravec@gmail.com>
Signed-off-by: default avatarTomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: default avatarTomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Wm. Nick Clemens's avatarNick Clemens <nick@bywatersolutions.com>
parent e47fa012
......@@ -2196,10 +2196,9 @@ sub PrepHostMarcField {
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" ) {
......@@ -2222,7 +2221,7 @@ sub PrepHostMarcField {
#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
......@@ -2825,8 +2824,12 @@ sub EmbedItemsInMarcBiblio {
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 =
......
This diff is collapsed.
......@@ -20,7 +20,7 @@ use Modern::Perl;
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);
......@@ -606,14 +606,14 @@ sub _SwapAllFields {
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{};
}
}
......
......@@ -29,6 +29,7 @@ use C4::Circulation;
use C4::Members;
use C4::Biblio;
use Koha::DateUtils;
use Koha::Items;
use Koha::Patrons;
use List::Util qw(shuffle);
......@@ -674,9 +675,9 @@ sub CreatePicklistFromItemMap {
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;
......
......@@ -535,17 +535,17 @@ sub GetServices {
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';
}
......@@ -568,7 +568,7 @@ sub GetServices {
}
# 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 );
......@@ -607,14 +607,17 @@ sub RenewLoan {
# 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;
......@@ -745,11 +748,11 @@ sub HoldItem {
# 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};
......@@ -823,25 +826,25 @@ Returns, for an itemnumber, an array containing availability information.
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 );
......
......@@ -177,10 +177,9 @@ sub CartToShelf {
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);
}
}
......@@ -200,9 +199,7 @@ sub ShelfToCart {
croak "FAILED ShelfToCart() - no itemnumber supplied";
}
my $item = GetItem($itemnumber);
$item->{'location'} = 'CART';
ModItem($item, undef, $itemnumber);
ModItem({ location => 'CART'}, undef, $itemnumber);
}
=head2 AddItemFromMarc
......@@ -555,12 +552,12 @@ sub ModItem {
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' } =
......@@ -1338,13 +1335,12 @@ sub GetMarcItem {
# 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 {
......@@ -1783,31 +1779,21 @@ sub ItemSafeToDelete {
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')
......@@ -2692,7 +2678,6 @@ sub ToggleNewStatus {
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 )
......
......@@ -37,7 +37,7 @@ How to add a new message to the queue:
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',
......
......@@ -320,14 +320,14 @@ sub CanItemBeReserved {
# 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
......@@ -355,7 +355,7 @@ sub CanItemBeReserved {
if ( $controlbranch eq "ItemHomeLibrary" ) {
$branchfield = "items.homebranch";
$branchcode = $item->{homebranch};
$branchcode = $item->homebranch;
}
elsif ( $controlbranch eq "PatronLibrary" ) {
$branchfield = "borrowers.branchcode";
......@@ -363,7 +363,7 @@ sub CanItemBeReserved {
}
# 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};
......@@ -373,7 +373,6 @@ sub CanItemBeReserved {
$ruleitemtype = '*';
}
$item = Koha::Items->find( $itemnumber );
my $holds = Koha::Holds->search(
{
borrowernumber => $borrowernumber,
......@@ -449,7 +448,7 @@ sub CanItemBeReserved {
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' };
......@@ -466,8 +465,7 @@ sub CanItemBeReserved {
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' };
}
}
......@@ -528,8 +526,8 @@ sub GetOtherReserves {
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(
......@@ -540,7 +538,7 @@ sub GetOtherReserves {
#launch the subroutine dotransfer
C4::Items::ModItemTransfer(
$itemnumber,
$iteminfo->{'holdingbranch'},
$item->holdingbranch,
$checkreserves->{'branchcode'}
),
;
......@@ -776,15 +774,15 @@ sub CheckReserves {
}
} 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}
......@@ -798,14 +796,15 @@ sub CheckReserves {
# 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;
......
......@@ -130,10 +130,10 @@ if ($AcqCreateItem eq 'receiving') {
);
} 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} // '';
......@@ -150,8 +150,9 @@ if ($AcqCreateItem eq 'receiving') {
$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;
......
......@@ -29,6 +29,7 @@ use C4::Output;
use Koha::Libraries;
use Koha::AuthorisedValues;
use Koha::Items;
use Koha::ItemTypes;
my $cgi = new CGI;
......@@ -43,39 +44,42 @@ unless ($status eq "ok") {
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';
......@@ -44,7 +44,7 @@ my $confirm=$cgi->param('confirm');
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) {
......
......@@ -74,15 +74,20 @@ sub get_item_from_barcode {
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;
}
}
......@@ -693,12 +698,12 @@ if ($op eq "additem") {
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";
......
......@@ -78,13 +78,14 @@ my $query = "UPDATE statistics SET itemtype = ? WHERE itemnumber = ?";
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 = ?");
......
......@@ -25,7 +25,6 @@ use CGI qw ( -utf8 );
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;
......@@ -89,7 +88,7 @@ elsif ($op eq 'add') {
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
......
......@@ -26,6 +26,7 @@ use C4::Context;
use C4::Items;
use Data::Dumper;
use Getopt::Long;
use Koha::Items;
my $dbh = C4::Context->dbh;
......@@ -73,7 +74,8 @@ if ($issues == 1) {
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'},
......@@ -82,10 +84,10 @@ if ($issues == 1) {
'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++;
}
......@@ -106,7 +108,8 @@ if ($issues == 1) {
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'},
......@@ -115,10 +118,10 @@ if ($issues == 1) {
'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++;
}
......@@ -145,7 +148,8 @@ if ($returns == 1) {
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'},
......@@ -154,10 +158,10 @@ if ($returns == 1) {
'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++;
}
......
......@@ -29,6 +29,7 @@ use C4::Auth;
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;
......@@ -65,14 +66,14 @@ else {
my $renewalbranch = C4::Context->preference('OpacRenewalBranch');
my $branchcode;
if ( $renewalbranch eq 'itemhomebranch' ) {