Koha/t/db_dependent/Items/GetItemsForInventory.t
Marc Véron e8b2f04638 Bug 14870: (followup) Remove stray C4::Dates
(See comment #23)

This patch removes stray C4::Dates (date_fromat...) from
C4/Items.pm
C4/Log.pm
C4/Serials.pm
serials/acqui-search-result.pl
t/DateUtils.t
t/db_dependent/Items/GetItemsForInventory.t
tools/koha-news.pl

Some of them were inside comments etc.

To test:
- git grep 'C4::Dates' should give no result
- git grep 'format_d' should give no result
  Exception: in one cron job there exists an own sub format_date, and occurences not
             related to C4::Dates
- Search for regressions

http://bugs.koha-community.org/show_bug.cgi?id=14870
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
serials/acqui-search-results.pl looks like it should be revisited,
containing code that might not be needed. Searching a vendor
in serials still works witout a problem.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2015-11-19 13:05:06 -03:00

156 lines
4.8 KiB
Perl
Executable file

#!/usr/bin/perl
#
# This file is part of Koha.
#
# Copyright (c) 2015 Mark Tompsett
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 6;
$| = 1;
BEGIN {
use_ok('C4::Context');
use_ok('C4::Items');
use_ok('C4::Biblio');
use_ok('C4::Koha');
}
can_ok('C4::Items','GetItemsForInventory');
my $dbh = C4::Context->dbh;
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
diag("This could take a while for large datasets...");
my ($oldResults, $oldCount) = OldWay($dbh);
my ($newResults, $newCount) = GetItemsForInventory( { interface => 'staff' } );
is_deeply($newResults,$oldResults,"Inventory results unchanged.");
$dbh->rollback;
sub OldWay {
my ($tdbh) = @_;
my $ldbh = $tdbh;
my $minlocation = '';
my $maxlocation = '';
my $location = '';
my $itemtype = '';
my $ignoreissued = '';
my $datelastseen = '';
my $branchcode = '';
my $branch = '';
my $offset = '';
my $size = '';
my $statushash = '';
my $interface = '';
my ( @bind_params, @where_strings );
my $select_columns = q{
SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, withdrawn, stocknumber
};
my $select_count = q{SELECT COUNT(*)};
my $query = q{
FROM items
LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
};
if ($statushash){
for my $authvfield (keys %$statushash){
if ( scalar @{$statushash->{$authvfield}} > 0 ){
my $joinedvals = join ',', @{$statushash->{$authvfield}};
push @where_strings, "$authvfield in (" . $joinedvals . ")";
}
}
}
if ($minlocation) {
push @where_strings, 'itemcallnumber >= ?';
push @bind_params, $minlocation;
}
if ($maxlocation) {
push @where_strings, 'itemcallnumber <= ?';
push @bind_params, $maxlocation;
}
if ($datelastseen) {
$datelastseen = output_pref({ str => $datelastseen, dateformat => 'iso', dateonly => 1 });
push @where_strings, '(datelastseen < ? OR datelastseen IS NULL)';
push @bind_params, $datelastseen;
}
if ( $location ) {
push @where_strings, 'items.location = ?';
push @bind_params, $location;
}
if ( $branchcode ) {
if($branch eq "homebranch"){
push @where_strings, 'items.homebranch = ?';
}else{
push @where_strings, 'items.holdingbranch = ?';
}
push @bind_params, $branchcode;
}
if ( $itemtype ) {
push @where_strings, 'biblioitems.itemtype = ?';
push @bind_params, $itemtype;
}
if ( $ignoreissued) {
$query .= "LEFT JOIN issues ON items.itemnumber = issues.itemnumber ";
push @where_strings, 'issues.date_due IS NULL';
}
if ( @where_strings ) {
$query .= 'WHERE ';
$query .= join ' AND ', @where_strings;
}
$query .= ' ORDER BY items.cn_sort, itemcallnumber, title';
my $count_query = $select_count . $query;
$query .= " LIMIT $offset, $size" if ($offset and $size);
$query = $select_columns . $query;
my $sth = $ldbh->prepare($query);
$sth->execute( @bind_params );
my @results = ();
my $tmpresults = $sth->fetchall_arrayref({});
$sth = $ldbh->prepare( $count_query );
$sth->execute( @bind_params );
my ($iTotalRecords) = $sth->fetchrow_array();
foreach my $row (@$tmpresults) {
# Auth values
foreach my $field (sort keys %$row) {
# If the koha field is mapped to a marc field
my ($f, $sf) = C4::Biblio::GetMarcFromKohaField("items.$field", $row->{'frameworkcode'});
if (defined($f) and defined($sf)) {
# We replace the code with it's description
my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $row->{'frameworkcode'});
$row->{$field} = $authvals->{$row->{$field}} if defined $authvals && defined $row->{$field} && defined $authvals->{$row->{$field}};
}
}
push @results, $row;
}
return (\@results, $iTotalRecords);
}