BZ4104: Removes tagging in staff client
[koha.git] / serials / lateissues-excel.pl
blobea0f5033118dc74662b591f5a8b63d3b563c1913
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use CGI;
6 use C4::Auth;
7 use C4::Serials;
8 use C4::Acquisition;
9 use C4::Output;
10 use C4::Context;
12 # use Date::Manip;
13 use Text::CSV_XS;
16 # &Date_Init("DateFormat=non-US"); # set non-USA date, eg:19/08/2005
19 my $csv = Text::CSV_XS->new(
21 'quote_char' => '"',
22 'escape_char' => '"',
23 'sep_char' => ',',
24 'binary' => 1
29 my $query = new CGI;
30 my $supplierid = $query->param('supplierid');
31 my @serialid = $query->param('serialid');
32 my $op = $query->param('op') || q{};
33 my $serialidcount = @serialid;
35 my %supplierlist = GetSuppliersWithLateIssues;
37 my @loop1;
38 my ($count, @lateissues);
39 if($op ne 'claims'){
40 ($count, @lateissues) = GetLateIssues($supplierid);
41 for my $issue (@lateissues){
42 push @loop1,
43 [ $issue->{'name'}, $issue->{'title'}, $issue->{'serialseq'}, $issue->{'planneddate'},];
46 my $totalcount2 = 0;
47 my @loop2;
48 my ($count2, @missingissues);
49 for (my $k=0;$k<@serialid;$k++){
50 ($count2, @missingissues) = GetLateOrMissingIssues($supplierid, $serialid[$k]);
52 for (my $j=0;$j<@missingissues;$j++){
53 my @rows2 = ($missingissues[$j]->{'name'}, # lets build up a row
54 $missingissues[$j]->{'title'},
55 $missingissues[$j]->{'serialseq'},
56 $missingissues[$j]->{'planneddate'},
58 push (@loop2, \@rows2);
60 $totalcount2 = $totalcount2 + $count2;
61 # update claim date to let one know they have looked at this missing item
62 updateClaim($serialid[$k]);
65 my $heading ='';
66 my $filename ='';
67 if($supplierid){
68 if($missingissues[0]->{'name'}){ # if exists display supplier name in heading for neatness
69 # not necessarily needed as the name will appear in supplier column also
70 $heading = "FOR $missingissues[0]->{'name'}";
71 $filename = "_$missingissues[0]->{'name'}";
75 print $query->header(
76 -type => 'application/vnd.ms-excel',
77 -attachment => "claims".$filename.".csv",
80 if($op ne 'claims'){
81 print "LATE ISSUES ".$heading."\n\n";
82 print "SUPPLIER,TITLE,ISSUE NUMBER,LATE SINCE\n";
84 for my $row ( @loop1 ) {
86 $csv->combine(@$row);
87 my $string = $csv->string;
88 print $string, "\n";
91 print ",,,,,,,\n\n";
93 if($serialidcount == 1){
94 print "MISSING ISSUE ".$heading."\n\n";
95 } else {
96 print "MISSING ISSUES ".$heading."\n\n";
98 print "SUPPLIER,TITLE,ISSUE NUMBER,LATE SINCE\n";
100 for my $row ( @loop2 ) {
102 $csv->combine(@$row);
103 my $string = $csv->string;
104 print $string, "\n";
107 print ",,,,,,,\n";
108 print ",,,,,,,\n";
109 if($op ne 'claims'){
110 print ",,Total Number Late, $count\n";
112 if($serialidcount == 1){
114 } else {
115 print ",,Total Number Missing, $totalcount2\n";