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>.
32 plugin that shows a stats on serials
39 my $templatename = "reports/serials_stats.tt";
40 my $do_it = $input->param("do_it");
41 my $bookseller = $input->param("bookseller");
42 my $branchcode = $input->param("branchcode");
43 my $expired = $input->param("expired");
44 my $order = $input->param("order");
45 my $output = $input->param("output");
46 my $basename = $input->param("basename");
47 our $sep = $input->param("sep") || '';
48 $sep = "\t" if ($sep eq 'tabulation');
50 my ($template, $borrowernumber, $cookie)
51 = get_template_and_user
({template_name
=> $templatename,
55 flagsrequired
=> {reports
=> '*'},
61 my $dbh = C4
::Context
->dbh;
64 my $where = "WHERE 1 ";
66 # if a specific branchcode was selected
67 if( $branchcode ne '' ){
68 $where .= "AND branchcode = ? ";
69 push @args,$branchcode;
72 # if a specific bookseller was selected
73 if($bookseller ne ''){
74 $where .= "AND aqbooksellerid = ? ";
75 push @args,$bookseller;
78 my $sth = $dbh->prepare("SELECT *
80 LEFT JOIN aqbooksellers
81 ON (aqbooksellers.id=subscription.aqbooksellerid)
83 ON (biblio.biblionumber=subscription.biblionumber)
89 ## hash generation of items by branchcode
92 while(my $row = $sth->fetchrow_hashref){
93 $row->{'enddate'} = GetExpirationDate
($row->{'subscriptionid'});
94 $row->{expired
} = HasSubscriptionExpired
($row->{subscriptionid
});
95 push @datas, $row if (
101 and not $row->{closed
}
107 if($output eq 'screen'){
108 $template->param(datas
=> \
@datas,
111 binmode STDOUT
, ':encoding(UTF-8)';
112 print $input->header(-type
=> 'application/vnd.sun.xml.calc',
113 -encoding
=> 'utf-8',
114 -name
=> "$basename.csv",
115 -attachment
=> "$basename.csv");
118 print "Subscription id".$sep;
120 print "Callnumber".$sep;
121 print "Subscription Begin".$sep;
122 print "Subscription End\n";
124 foreach my $item (@datas){
125 print $item->{name
}.$sep;
126 print $item->{title
}.$sep;
127 print $item->{subscriptionid
}.$sep;
128 print $item->{branchcode
}.$sep;
129 print $item->{callnumber
}.$sep;
130 print $item->{startdate
}.$sep;
131 print $item->{enddate
}."\n";
136 ## We generate booksellers list
139 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
141 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
142 GROUP BY aqbooksellerid");
145 while(my $row = $sth->fetchrow_hashref){
146 push(@booksellers,$row)
149 my $CGIextChoice = ( 'CSV' ); # FIXME translation
150 my $CGIsepChoice=GetDelimiterChoices
;
152 CGIextChoice
=> $CGIextChoice,
153 CGIsepChoice
=> $CGIsepChoice,
154 booksellers
=> \
@booksellers,
158 output_html_with_http_headers
$input, $cookie, $template->output;