bug 5492 update import patrons page title
[koha.git] / serials / lateissues-excel.pl
blobe5cc8498d1eda6e9166fb59fb880561216ef8342
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 use strict;
19 use warnings;
20 use CGI;
21 use C4::Auth;
22 use C4::Serials;
23 use C4::Acquisition;
24 use C4::Output;
25 use C4::Context;
27 # use Date::Manip;
28 use Text::CSV_XS;
31 # &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
34 my $csv = Text::CSV_XS->new(
36 'quote_char' => '"',
37 'escape_char' => '"',
38 'sep_char' => ',',
39 'binary' => 1
44 my $query = new CGI;
45 my $supplierid = $query->param('supplierid');
46 my @serialid = $query->param('serialid');
47 my $op = $query->param('op') || q{};
48 my $serialidcount = @serialid;
50 my @loop1;
51 my @lateissues;
52 if($op ne 'claims'){
53 @lateissues = GetLateIssues($supplierid);
54 for my $issue (@lateissues){
55 push @loop1,
56 [ $issue->{'name'}, $issue->{'title'}, $issue->{'serialseq'}, $issue->{'planneddate'},];
59 my $totalcount2 = 0;
60 my @loop2;
61 my @missingissues;
62 for (my $k=0;$k<@serialid;$k++){
63 @missingissues = GetLateOrMissingIssues($supplierid, $serialid[$k]);
65 for (my $j=0;$j<@missingissues;$j++){
66 my @rows2 = ($missingissues[$j]->{'name'}, # lets build up a row
67 $missingissues[$j]->{'title'},
68 $missingissues[$j]->{'serialseq'},
69 $missingissues[$j]->{'planneddate'},
71 push (@loop2, \@rows2);
73 $totalcount2 += scalar @missingissues;
74 # update claim date to let one know they have looked at this missing item
75 updateClaim($serialid[$k]);
78 my $heading ='';
79 my $filename ='';
80 if($supplierid){
81 if($missingissues[0]->{'name'}){ # if exists display supplier name in heading for neatness
82 # not necessarily needed as the name will appear in supplier column also
83 $heading = "FOR $missingissues[0]->{'name'}";
84 $filename = "_$missingissues[0]->{'name'}";
88 print $query->header(
89 -type => 'application/vnd.ms-excel',
90 -attachment => "claims".$filename.".csv",
93 if($op ne 'claims'){
94 print "LATE ISSUES ".$heading."\n\n";
95 print "SUPPLIER,TITLE,ISSUE NUMBER,LATE SINCE\n";
97 for my $row ( @loop1 ) {
99 $csv->combine(@$row);
100 my $string = $csv->string;
101 print $string, "\n";
104 print ",,,,,,,\n\n";
106 if($serialidcount == 1){
107 print "MISSING ISSUE ".$heading."\n\n";
108 } else {
109 print "MISSING ISSUES ".$heading."\n\n";
111 print "SUPPLIER,TITLE,ISSUE NUMBER,LATE SINCE\n";
113 for my $row ( @loop2 ) {
115 $csv->combine(@$row);
116 my $string = $csv->string;
117 print $string, "\n";
120 print ",,,,,,,\n";
121 print ",,,,,,,\n";
122 if($op ne 'claims'){
123 my $count = scalar @lateissues;
124 print ",,Total Number Late, $count\n";
126 if($serialidcount == 1){
128 } else {
129 print ",,Total Number Missing, $totalcount2\n";