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>.
21 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Reports qw( GetDelimiterChoices );
26 use C4::Serials qw( GetExpirationDate HasSubscriptionExpired );
30 plugin that shows a stats on serials
37 my $templatename = "reports/serials_stats.tt";
38 my $do_it = $input->param("do_it");
39 my $bookseller = $input->param("bookseller");
40 my $branchcode = $input->param("branchcode");
41 my $expired = $input->param("expired");
42 my $order = $input->param("order");
43 my $output = $input->param("output");
44 my $basename = $input->param("basename");
45 our $sep = $input->param("sep") || '';
46 $sep = "\t" if ($sep eq 'tabulation');
48 my ($template, $borrowernumber, $cookie)
49 = get_template_and_user({template_name => $templatename,
52 flagsrequired => {reports => '*'},
57 my $dbh = C4::Context->dbh;
60 my $where = "WHERE 1 ";
62 # if a specific branchcode was selected
63 if( $branchcode ne '' ){
64 $where .= "AND branchcode = ? ";
65 push @args,$branchcode;
68 # if a specific bookseller was selected
69 if($bookseller ne ''){
70 $where .= "AND aqbooksellerid = ? ";
71 push @args,$bookseller;
74 my $sth = $dbh->prepare("SELECT *
76 LEFT JOIN aqbooksellers
77 ON (aqbooksellers.id=subscription.aqbooksellerid)
79 ON (biblio.biblionumber=subscription.biblionumber)
85 ## hash generation of items by branchcode
88 while(my $row = $sth->fetchrow_hashref){
89 $row->{'enddate'} = GetExpirationDate($row->{'subscriptionid'});
90 $row->{expired} = HasSubscriptionExpired($row->{subscriptionid});
91 push @datas, $row if (
97 and not $row->{closed}
103 if($output eq 'screen'){
104 $template->param(datas => \@datas,
107 binmode STDOUT, ':encoding(UTF-8)';
108 print $input->header(-type => 'application/vnd.sun.xml.calc',
109 -encoding => 'utf-8',
110 -name => "$basename.csv",
111 -attachment => "$basename.csv");
114 print "Subscription id".$sep;
116 print "Callnumber".$sep;
117 print "Subscription Begin".$sep;
118 print "Subscription End\n";
120 foreach my $item (@datas){
121 print $item->{name}.$sep;
122 print $item->{title}.$sep;
123 print $item->{subscriptionid}.$sep;
124 print $item->{branchcode}.$sep;
125 print $item->{callnumber}.$sep;
126 print $item->{startdate}.$sep;
127 print $item->{enddate}."\n";
132 ## We generate booksellers list
135 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
137 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
138 ORDER BY aqbooksellers.name ASC
142 while(my $row = $sth->fetchrow_hashref){
143 push(@booksellers,$row)
146 my $CGIextChoice = ( 'CSV' ); # FIXME translation
147 my $CGIsepChoice=GetDelimiterChoices;
149 CGIextChoice => $CGIextChoice,
150 CGIsepChoice => $CGIsepChoice,
151 booksellers => \@booksellers,
155 output_html_with_http_headers $input, $cookie, $template->output;