Bug 14961: Remove C4::Dates from files reports/*_stats.pl
[koha.git] / reports / serials_stats.pl
blobf6ba4c008c903c750ede93c90b7a4348ae7245f1
1 #!/usr/bin/perl
3 # Copyright 2009 SARL Biblibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use strict;
21 use warnings;
22 use C4::Auth;
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Branch; # GetBranches
26 use C4::Output;
27 use C4::Koha;
28 use C4::Reports;
29 use C4::Serials;
31 =head1 serials_out
33 plugin that shows a stats on serials
35 =head1 DESCRIPTION
37 =cut
39 my $input = new CGI;
40 my $templatename = "reports/serials_stats.tt";
41 my $do_it = $input->param("do_it");
42 my $bookseller = $input->param("bookseller");
43 my $branchcode = $input->param("branchcode");
44 my $expired = $input->param("expired");
45 my $order = $input->param("order");
46 my $output = $input->param("output");
47 my $basename = $input->param("basename");
48 our $sep = $input->param("sep") || '';
49 $sep = "\t" if ($sep eq 'tabulation');
51 my ($template, $borrowernumber, $cookie)
52 = get_template_and_user({template_name => $templatename,
53 query => $input,
54 type => "intranet",
55 authnotrequired => 0,
56 flagsrequired => {reports => '*'},
57 debug => 1,
58 });
62 my $dbh = C4::Context->dbh;
64 if($do_it){
65 my $where = "WHERE 1 ";
66 my @args;
67 # if a specific branchcode was selected
68 if( $branchcode ne '' ){
69 $where .= "AND branchcode = ? ";
70 push @args,$branchcode;
73 # if a specific bookseller was selected
74 if($bookseller ne ''){
75 $where .= "AND aqbooksellerid = ? ";
76 push @args,$bookseller;
79 my $sth = $dbh->prepare("SELECT *
80 FROM subscription
81 LEFT JOIN aqbooksellers
82 ON (aqbooksellers.id=subscription.aqbooksellerid)
83 LEFT JOIN biblio
84 ON (biblio.biblionumber=subscription.biblionumber)
85 $where
86 ");
88 $sth->execute(@args);
90 ## hash generation of items by branchcode
91 my @datas;
93 while(my $row = $sth->fetchrow_hashref){
94 $row->{'enddate'} = GetExpirationDate($row->{'subscriptionid'});
95 $row->{expired} = HasSubscriptionExpired($row->{subscriptionid});
96 push @datas, $row if (
97 $expired
98 or (
99 not $expired
100 and (
101 not $row->{expired}
102 and not $row->{closed}
108 if($output eq 'screen'){
109 $template->param(datas => \@datas,
110 do_it => 1);
111 }else{
112 binmode STDOUT, ':encoding(UTF-8)';
113 print $input->header(-type => 'application/vnd.sun.xml.calc',
114 -encoding => 'utf-8',
115 -name => "$basename.csv",
116 -attachment => "$basename.csv");
117 print "Vendor".$sep;
118 print "Title".$sep;
119 print "Subscription id".$sep;
120 print "Branch".$sep;
121 print "Callnumber".$sep;
122 print "Subscription Begin".$sep;
123 print "Subscription End\n";
125 foreach my $item (@datas){
126 print $item->{name}.$sep;
127 print $item->{title}.$sep;
128 print $item->{subscriptionid}.$sep;
129 print $item->{branchcode}.$sep;
130 print $item->{callnumber}.$sep;
131 print $item->{startdate}.$sep;
132 print $item->{enddate}."\n";
134 exit;
136 }else{
137 ## We generate booksellers list
138 my @booksellers;
140 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
141 FROM subscription
142 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
143 GROUP BY aqbooksellerid");
144 $sth->execute();
146 while(my $row = $sth->fetchrow_hashref){
147 push(@booksellers,$row)
150 my $CGIextChoice = ( 'CSV' ); # FIXME translation
151 my $CGIsepChoice=GetDelimiterChoices;
152 $template->param(
153 CGIextChoice => $CGIextChoice,
154 CGIsepChoice => $CGIsepChoice,
155 booksellers => \@booksellers,
156 branches => GetBranchesLoop(C4::Context->userenv->{'branch'}));
159 output_html_with_http_headers $input, $cookie, $template->output;