3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use C4::Serials qw( GetLateOrMissingIssues updateClaim );
25 use Koha::CsvProfiles;
30 my $supplierid = $query->param('supplierid');
31 my @serialids = $query->multi_param('serialid');
32 my $op = $query->param('op') || q{};
34 my $csv_profile_id = $query->param('csv_profile');
35 my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id );
36 die "There is no valid csv profile given" unless $csv_profile;
38 my $delimiter = $csv_profile->csv_separator;
39 $delimiter = "\t" if $delimiter eq "\\t";
41 my $csv = Text::CSV_XS->new({
44 'sep_char' => $delimiter,
48 my $content = $csv_profile->content;
49 my ( @headers, @fields );
53 ([^\|]*) # fieldname (table.row or row)
57 my $field = ($2 eq '') ? $1 : $2;
59 $header =~ s/^\s+|\s+$//g; # Trim whitespaces
60 push @headers, $header;
62 $field =~ s/[^.]+\.//; # Remove the table name if exists.
63 $field =~ s/^\s+|\s+$//g; # Trim whitespaces
68 for my $serialid ( @serialids ) {
69 my @missingissues = GetLateOrMissingIssues($supplierid, $serialid);
70 my $issue = $missingissues[0];
72 for my $field ( @fields ) {
73 push @row, $issue->{$field};
77 # update claim date to let one know they have looked at this missing item
78 updateClaim($serialid);
82 -type => 'plain/text',
83 -attachment => "serials-claims.csv",
86 print join( $delimiter, @headers ) . "\n";
88 for my $row ( @rows ) {
90 my $string = $csv->string;