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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 use C4::Branch; # GetBranches
26 use C4::Dates qw/format_date/;
34 plugin that shows a stats on serials
43 my $templatename = "reports/serials_stats.tmpl";
44 my $do_it = $input->param("do_it");
45 my $bookseller = $input->param("bookseller");
46 my $branchcode = $input->param("branchcode");
47 my $expired = $input->param("expired");
48 my $order = $input->param("order");
49 my $output = $input->param("output");
50 my $basename = $input->param("basename");
51 my $mime = $input->param("MIME");
52 our $sep = $input->param("sep") || '';
53 $sep = "\t" if ($sep eq 'tabulation');
55 my ($template, $borrowernumber, $cookie)
56 = get_template_and_user({template_name => $templatename,
60 flagsrequired => {reports => 1},
66 my $dbh = C4::Context->dbh;
71 16 => 'Without periodicity'
75 , 1 => 'daily (n/week)'
80 , 6 => '1/2 months (6/year)'
81 , 7 => '1/3 months (1/quarter)'
82 , 8 => '1/quarter (seasonal)'
88 my $where = "WHERE 1 ";
90 # if a specific branchcode was selected
91 if( $branchcode ne '' ){
92 $where .= "AND branchcode = ? ";
93 push @args,$branchcode;
96 # if a specific bookseller was selected
97 if($bookseller ne ''){
98 $where .= "AND aqbooksellerid = ? ";
99 push @args,$bookseller;
102 my $sth = $dbh->prepare("SELECT *
104 LEFT JOIN aqbooksellers
105 ON (aqbooksellers.id=subscription.aqbooksellerid)
107 ON (biblio.biblionumber=subscription.biblionumber)
111 $sth->execute(@args);
113 ## hash generation of items by branchcode
116 while(my $row = $sth->fetchrow_hashref){
117 $row->{'periodicity'} = $periodicities->{$row->{'periodicity'}};
118 $row->{'enddate'} = format_date(GetExpirationDate($row->{'subscriptionid'}));
119 $row->{'startdate'} = format_date($row->{'startdate'});
120 push @datas, $row if ($expired || (not $expired && not HasSubscriptionExpired($row->{subscriptionid})) );
123 if($output eq 'screen'){
124 $template->param(datas => \@datas,
127 binmode STDOUT, ':utf8';
128 print $input->header(-type => 'application/vnd.sun.xml.calc',
129 -encoding => 'utf-8',
130 -name => "$basename.csv",
131 -attachment => "$basename.csv");
134 print "Subscription id".$sep;
136 print "Callnumber".$sep;
137 print "Periodicity".$sep;
138 print "Subscription Begin".$sep;
139 print "Subscription End\n";
141 foreach my $item (@datas){
142 print $item->{name}.$sep;
143 print $item->{title}.$sep;
144 print $item->{subscriptionid}.$sep;
145 print $item->{branchcode}.$sep;
146 print $item->{callnumber}.$sep;
147 print $item->{periodicity}.$sep;
148 print $item->{startdate}.$sep;
149 print $item->{enddate}."\n";
154 ## We generate booksellers list
157 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
159 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
160 GROUP BY aqbooksellerid");
163 while(my $row = $sth->fetchrow_hashref){
164 push(@booksellers,$row)
167 ## We generate branchlist
168 my $branches=GetBranches();
170 foreach (keys %$branches) {
171 my $thisbranch = ''; # FIXME: populate $thisbranch to preselect one
172 my %row = (branchcode => $_,
173 selected => ($thisbranch eq $_ ? 1 : 0),
174 branchname => $branches->{$_}->{'branchname'},
176 push @branchloop, \%row;
179 my @mime = ( C4::Context->preference("MIME") );
180 # warn 'MIME(s): ' . join ' ', @mime;
181 my $CGIextChoice=CGI::scrolling_list(
187 my $CGIsepChoice=GetDelimiterChoices;
189 CGIextChoice => $CGIextChoice,
190 CGIsepChoice => $CGIsepChoice,
191 booksellers => \@booksellers,
192 branches => \@branchloop);
195 output_html_with_http_headers $input, $cookie, $template->output;