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 = C4::Context->csv_delimiter(scalar $input->param("sep"));
47 my ($template, $borrowernumber, $cookie)
48 = get_template_and_user({template_name => $templatename,
51 flagsrequired => {reports => '*'},
56 my $dbh = C4::Context->dbh;
59 my $where = "WHERE 1 ";
61 # if a specific branchcode was selected
62 if( $branchcode ne '' ){
63 $where .= "AND branchcode = ? ";
64 push @args,$branchcode;
67 # if a specific bookseller was selected
68 if($bookseller ne ''){
69 $where .= "AND aqbooksellerid = ? ";
70 push @args,$bookseller;
73 my $sth = $dbh->prepare("SELECT *
75 LEFT JOIN aqbooksellers
76 ON (aqbooksellers.id=subscription.aqbooksellerid)
78 ON (biblio.biblionumber=subscription.biblionumber)
84 ## hash generation of items by branchcode
87 while(my $row = $sth->fetchrow_hashref){
88 $row->{'enddate'} = GetExpirationDate($row->{'subscriptionid'});
89 $row->{expired} = HasSubscriptionExpired($row->{subscriptionid});
90 push @datas, $row if (
96 and not $row->{closed}
102 if($output eq 'screen'){
103 $template->param(datas => \@datas,
106 binmode STDOUT, ':encoding(UTF-8)';
107 print $input->header(-type => 'application/vnd.sun.xml.calc',
108 -encoding => 'utf-8',
109 -name => "$basename.csv",
110 -attachment => "$basename.csv");
113 print "Subscription id".$sep;
115 print "Callnumber".$sep;
116 print "Subscription Begin".$sep;
117 print "Subscription End\n";
119 foreach my $item (@datas){
120 print $item->{name}.$sep;
121 print $item->{title}.$sep;
122 print $item->{subscriptionid}.$sep;
123 print $item->{branchcode}.$sep;
124 print $item->{callnumber}.$sep;
125 print $item->{startdate}.$sep;
126 print $item->{enddate}."\n";
131 ## We generate booksellers list
134 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
136 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
137 GROUP BY aqbooksellerid, aqbooksellers.name
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;