@@ -, +, @@ --- C4/Items.pm | 40 ++++++++++++++++++++++++++++++++-------- C4/Koha.pm | 44 ++++++++++++++++++++++++++++++++++++++++++++ tools/inventory.pl | 30 ++++++++++++++++++++++++++++-- 3 files changed, 104 insertions(+), 10 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -1024,7 +1024,20 @@ sub GetLostItems { =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, + stautshash => $statushash + interface => $interface, +} ); Retrieve a list of title/authors/barcode/callnumber, for biblio inventory. @@ -1042,7 +1055,19 @@ $iTotalRecords is the number of rows that would have been returned without the $ =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 $dbh = C4::Context->dbh; my ( @bind_params, @where_strings ); @@ -1121,16 +1146,15 @@ sub GetItemsForInventory { $sth->execute( @bind_params ); my ($iTotalRecords) = $sth->fetchrow_array(); + my $avmapping = C4::Koha::GetKohaAuthorisedValuesMapping( { + interface => 'unknown' + } ); 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; --- a/C4/Koha.pm +++ a/C4/Koha.pm @@ -1327,6 +1327,50 @@ sub GetKohaAuthorisedValuesFromField { } } +=head2 GetKohaAuthorisedValuesMapping + +Takes a hash as a parameter. The interface key indicates the +description to use in the mapping. + +Returns hashref of: + "{kohafield},{frameworkcode},{authorised_value}" => "{description}" +for all the kohafields, frameworkcodes, and authorised values. + +Returns undef if nothing is found. + +=cut + +sub GetKohaAuthorisedValuesMapping { + my ($parameter) = @_; + my $interface = $parameter->{'interface'} // ''; + + my $query_mapping = q{ +SELECT TA.kohafield,TA.authorised_value AS category, + TA.frameworkcode,TB.authorised_value, + IF(TB.lib_opac>'',TB.lib_opac,TB.lib) AS OPAC, + TB.lib AS Intranet,TB.lib_opac +FROM marc_subfield_structure AS TA JOIN + authorised_values as TB ON + TA.authorised_value=TB.category +WHERE TA.kohafield>'' AND TA.authorised_value>''; + }; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query_mapping); + $sth->execute(); + my $avmapping; + if ($interface eq 'opac') { + while (my $row = $sth->fetchrow_hashref) { + $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{OPAC}; + } + } + else { + while (my $row = $sth->fetchrow_hashref) { + $avmapping->{$row->{kohafield}.",".$row->{frameworkcode}.",".$row->{authorised_value}} = $row->{Intranet}; + } + } + return $avmapping; +} + =head2 xml_escape my $escaped_string = C4::Koha::xml_escape($string); --- a/tools/inventory.pl +++ a/tools/inventory.pl @@ -234,10 +234,36 @@ if ( $markseen or $op ) { # We use datelastseen only when comparing the results to the barcode file. my $paramdatelastseen = ($compareinv2barcd) ? $datelastseen : ''; - ($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $paramdatelastseen, $branchcode, $branch, 0, undef, $staton); + ($inventorylist, $totalrecords) = GetItemsForInventory( { + minlocation => $minlocation, + maxlocation => $maxlocation, + location => $location, + itemtype => $itemtype, + ignoreissued => $ignoreissued, + datelastseen => $paramdatelastseen, + branchcode => $branchcode, + branch => $branch, + offset => 0, + size => undef, + statushash => $staton, + interface => 'staff', + } ); # For the items that may be marked as "wrong place", we only check the location (callnumbers, location and branch) - ($wrongplacelist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, undef, undef, undef, $branchcode, $branch, 0, undef, undef); + ($wrongplacelist, $totalrecords) = GetItemsForInventory( { + minlocation => $minlocation, + maxlocation => $maxlocation, + location => $location, + itemtype => undef, + ignoreissued => undef, + datelastseen => undef, + branchcode => $branchcode, + branch => $branch, + offset => 0, + size => undef, + statushash => undef, + interface => 'staff', + } ); } --