383b2a75de
Test plan: - Create a CSV profile (or use the default one) with a type 'sql'. - Go to serials/claims.pl, select the wanted CSV profile and click on the "Export selected items data". - Verify the CSV file is correctly generated. Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Work as described. No koha-qa errors On top of 10853 (solving merge conflict) Need to do homework to test. Add subscription and serial claim notice. 1) Create a new CSV profile, type SQL, copy sample fields 2) Go to claims, select vendor 3) Go to Export selected items with created profile 4) CSV (in my case I use | as separator) download successfully 5) All fields present, file correct Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> Passes all tests and QA script. Works as advertised, keeps existing format by porting it to a SQL profile. Signed-off-by: Galen Charlton <gmc@esilibrary.com>
84 lines
2.3 KiB
Perl
Executable file
84 lines
2.3 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# This file is part of Koha.
|
|
#
|
|
# 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 2 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, write to the Free Software Foundation, Inc.,
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
use Modern::Perl;
|
|
use CGI;
|
|
use C4::Auth;
|
|
use C4::Serials;
|
|
use C4::Acquisition;
|
|
use C4::Output;
|
|
use C4::Context;
|
|
use C4::Csv qw( GetCsvProfile );
|
|
|
|
use Text::CSV_XS;
|
|
|
|
my $query = new CGI;
|
|
my $supplierid = $query->param('supplierid');
|
|
my @serialids = $query->param('serialid');
|
|
my $op = $query->param('op') || q{};
|
|
|
|
my $csv_profile_id = $query->param('csv_profile');
|
|
my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
|
|
die "There is no valid csv profile given" unless $csv_profile;
|
|
|
|
my $csv = Text::CSV_XS->new({
|
|
'quote_char' => '"',
|
|
'escape_char' => '"',
|
|
'sep_char' => $csv_profile->{csv_separator},
|
|
'binary' => 1
|
|
});
|
|
|
|
my $content = $csv_profile->{content};
|
|
my ( @headers, @fields );
|
|
while ( $content =~ /
|
|
([^=]+) # header
|
|
=
|
|
([^\|]+) # fieldname (table.row or row)
|
|
\|? /gxms
|
|
) {
|
|
push @headers, $1;
|
|
my $field = $2;
|
|
$field =~ s/[^\.]*\.?//; # Remove the table name if exists.
|
|
push @fields, $field;
|
|
}
|
|
|
|
my @rows;
|
|
for my $serialid ( @serialids ) {
|
|
my @missingissues = GetLateOrMissingIssues($supplierid, $serialid);
|
|
my $issue = $missingissues[0];
|
|
my @row;
|
|
for my $field ( @fields ) {
|
|
push @row, $issue->{$field};
|
|
}
|
|
push @rows, \@row;
|
|
|
|
# update claim date to let one know they have looked at this missing item
|
|
updateClaim($serialid);
|
|
}
|
|
|
|
print $query->header(
|
|
-type => 'plain/text',
|
|
-attachment => "serials-claims.csv",
|
|
);
|
|
|
|
print join( $csv_profile->{csv_separator}, @headers ) . "\n";
|
|
|
|
for my $row ( @rows ) {
|
|
$csv->combine(@$row);
|
|
my $string = $csv->string;
|
|
print $string, "\n";
|
|
}
|