use C4::Context;
use C4::Koha;
use C4::Biblio;
-use C4::Dates qw/format_date format_date_in_iso/;
+use Koha::DateUtils;
use MARC::Record;
use C4::ClassSource;
use C4::Log;
This function uses the hash %default_values_for_mod_from_marc,
which contains default values for item fields to
-apply when modifying an item. This is needed beccause
+apply when modifying an item. This is needed because
if an item field's value is cleared, TransformMarcToKoha
does not include the column in the
hash that's passed to ModItem, which without
sub ModDateLastSeen {
my ($itemnumber) = @_;
- my $today = C4::Dates->new();
- ModItem({ itemlost => 0, datelastseen => $today->output("iso") }, undef, $itemnumber);
+ my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
+ ModItem({ itemlost => 0, datelastseen => $today }, undef, $itemnumber);
}
=head2 DelItem
NOTE: does B<not> return an individual item's
status.
-Can be MARC dependant.
+Can be MARC dependent.
fwkcode is optional.
But basically could be can be loan or not
Create a status selector with the following code
=head2 GetItemsForInventory
-($itemlist, $iTotalRecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $offset, $size, $statushash);
+($itemlist, $iTotalRecords) = GetItemsForInventory( {
+ minlocation => $minlocation,
+ maxlocation => $maxlocation,
+ location => $location,
+ itemtype => $itemtype,
+ ignoreissued => $ignoreissued,
+ datelastseen => $datelastseen,
+ branchcode => $branchcode,
+ branch => $branch,
+ offset => $offset,
+ size => $size,
+ statushash => $statushash,
+ interface => $interface,
+} );
Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
=cut
sub GetItemsForInventory {
- my ( $minlocation, $maxlocation,$location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $size, $statushash ) = @_;
+ my ( $parameters ) = @_;
+ my $minlocation = $parameters->{'minlocation'} // '';
+ my $maxlocation = $parameters->{'maxlocation'} // '';
+ my $location = $parameters->{'location'} // '';
+ my $itemtype = $parameters->{'itemtype'} // '';
+ my $ignoreissued = $parameters->{'ignoreissued'} // '';
+ my $datelastseen = $parameters->{'datelastseen'} // '';
+ my $branchcode = $parameters->{'branchcode'} // '';
+ my $branch = $parameters->{'branch'} // '';
+ my $offset = $parameters->{'offset'} // '';
+ my $size = $parameters->{'size'} // '';
+ my $statushash = $parameters->{'statushash'} // '';
+ my $interface = $parameters->{'interface'} // '';
+
my $dbh = C4::Context->dbh;
my ( @bind_params, @where_strings );
$sth->execute( @bind_params );
my ($iTotalRecords) = $sth->fetchrow_array();
+ my $avmapping = C4::Koha::GetKohaAuthorisedValuesMapping( {
+ interface => $interface
+ } );
foreach my $row (@$tmpresults) {
# Auth values
foreach (keys %$row) {
- # If the koha field is mapped to a marc field
- my ($f, $sf) = GetMarcFromKohaField("items.$_", $row->{'frameworkcode'});
- if ($f and $sf) {
- # We replace the code with it's description
- my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $row->{'frameworkcode'});
- $row->{$_} = $authvals->{$row->{$_}} if defined $authvals->{$row->{$_}};
+ if (defined($avmapping->{"items.$_,".$row->{'frameworkcode'}.",".$row->{$_}})) {
+ $row->{$_} = $avmapping->{"items.$_,".$row->{'frameworkcode'}.",".$row->{$_}};
}
}
push @results, $row;
my ( $biblionumber ) = @_;
my $dbh = C4::Context->dbh;
# note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance.
+ require C4::Languages;
+ my $language = C4::Languages::getlanguage();
my $query = "
SELECT items.*,
biblio.*,
serial.serialseq,
serial.publisheddate,
itemtypes.description,
+ COALESCE( localization.translation, itemtypes.description ) AS translated_description,
itemtypes.notforloan as notforloan_per_itemtype,
holding.branchurl,
holding.branchname,
LEFT JOIN serial USING (serialid)
LEFT JOIN itemtypes ON itemtypes.itemtype = "
. (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype');
+ $query .= q|
+ LEFT JOIN localization ON itemtypes.itemtype = localization.code
+ AND localization.entity = 'itemtypes'
+ AND localization.lang = ?
+ |;
+
$query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ;
my $sth = $dbh->prepare($query);
- $sth->execute($biblionumber);
+ $sth->execute($language, $biblionumber);
my $i = 0;
my @results;
my $serial;
(not defined $item->{'withdrawn'} or $item->{'withdrawn'} eq '')) {
$item->{'withdrawn'} = 0;
}
- if (exists $item->{'location'} && !$item->{'permanent_location'}) {
+ if (exists $item->{location}
+ and $item->{location} ne 'CART'
+ and $item->{location} ne 'PROC'
+ and not $item->{permanent_location}
+ ) {
$item->{'permanent_location'} = $item->{'location'};
}
if (exists $item->{'timestamp'}) {
sub _set_defaults_for_add {
my $item = shift;
- $item->{dateaccessioned} ||= C4::Dates->new->output('iso');
+ $item->{dateaccessioned} ||= output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
$item->{$_} ||= 0 for (qw( notforloan damaged itemlost withdrawn));
}
my ( $item, $barcode ) = @_;
my $dbh=C4::Context->dbh;
my $error;
+ $item->{permanent_location} //= $item->{location};
my $query =
"INSERT INTO items SET
biblionumber = ?,
notforloan = ?,
damaged = ?,
itemlost = ?,
- withdrawn = ?,
+ withdrawn = ?,
itemcallnumber = ?,
coded_location_qualifier = ?,
restricted = ?,
holdingbranch = ?,
paidfor = ?,
location = ?,
- permanent_location = ?,
+ permanent_location = ?,
onloan = ?,
issues = ?,
renewals = ?,
ccode = ?,
itype = ?,
materials = ?,
- uri = ?,
+ uri = ?,
enumchron = ?,
more_subfields_xml = ?,
copynumber = ?,
stocknumber = ?
";
my $sth = $dbh->prepare($query);
- my $today = C4::Dates->today('iso');
+ my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
$sth->execute(
$item->{'biblionumber'},
$item->{'biblioitemnumber'},
sub MoveItemFromBiblio {
my ($itemnumber, $frombiblio, $tobiblio) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber = ?");
- $sth->execute( $tobiblio );
- my ( $tobiblioitem ) = $sth->fetchrow();
- $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
- my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
+ my ( $tobiblioitem ) = $dbh->selectrow_array(q|
+ SELECT biblioitemnumber
+ FROM biblioitems
+ WHERE biblionumber = ?
+ |, undef, $tobiblio );
+ my $return = $dbh->do(q|
+ UPDATE items
+ SET biblioitemnumber = ?,
+ biblionumber = ?
+ WHERE itemnumber = ?
+ AND biblionumber = ?
+ |, undef, $tobiblioitem, $tobiblio, $itemnumber, $frombiblio );
if ($return == 1) {
ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
$order->{'biblionumber'} = $tobiblio;
C4::Acquisition::ModOrder($order);
}
+
+ # Update reserves, hold_fill_targets, tmp_holdsqueue and linktracker tables
+ for my $table_name ( qw( reserves hold_fill_targets tmp_holdsqueue linktracker ) ) {
+ $dbh->do( qq|
+ UPDATE $table_name
+ SET biblionumber = ?
+ WHERE itemnumber = ?
+ |, undef, $tobiblio, $itemnumber );
+ }
return $tobiblio;
}
return;
$error = "not_same_branch";
}
else{
- # check it doesnt have a waiting reserve
+ # check it doesn't have a waiting reserve
$sth = $dbh->prepare(q{
SELECT COUNT(*) FROM reserves
WHERE (found = 'W' OR found = 'T')
sub SearchItemsByField {
my ($field, $value) = @_;
- my $filters = [ {
- field => $field,
- query => $value,
- } ];
+ my $filters = {
+ field => $field,
+ query => $value,
+ };
my ($results) = SearchItems($filters);
return $results;
#----- itemtypes
} elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
- my $sth = $dbh->prepare( "SELECT itemtype,description FROM itemtypes ORDER BY description" );
- $sth->execute;
+ my $itemtypes = GetItemTypes( style => 'array' );
push @authorised_values, ""
unless ( $tagslib->{$tag}->{$subfield}->{mandatory} );
- while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
- push @authorised_values, $itemtype;
- $authorised_lib{$itemtype} = $description;
+ for my $itemtype ( @$itemtypes ) {
+ push @authorised_values, $itemtype->{itemtype};
+ $authorised_lib{$itemtype->{itemtype}} = $itemtype->{translated_description};
}
#---- class_sources
} elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) {