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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
=> '*'},
66 my $dbh = C4
::Context
->dbh;
69 my $where = "WHERE 1 ";
71 # if a specific branchcode was selected
72 if( $branchcode ne '' ){
73 $where .= "AND branchcode = ? ";
74 push @args,$branchcode;
77 # if a specific bookseller was selected
78 if($bookseller ne ''){
79 $where .= "AND aqbooksellerid = ? ";
80 push @args,$bookseller;
83 my $sth = $dbh->prepare("SELECT *
85 LEFT JOIN aqbooksellers
86 ON (aqbooksellers.id=subscription.aqbooksellerid)
88 ON (biblio.biblionumber=subscription.biblionumber)
94 ## hash generation of items by branchcode
97 while(my $row = $sth->fetchrow_hashref){
98 $row->{'enddate'} = format_date
(GetExpirationDate
($row->{'subscriptionid'}));
99 $row->{'startdate'} = format_date
($row->{'startdate'});
100 push @datas, $row if ($expired || (not $expired && not HasSubscriptionExpired
($row->{subscriptionid
})) );
103 if($output eq 'screen'){
104 $template->param(datas
=> \
@datas,
107 binmode STDOUT
, ':utf8';
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 GROUP BY aqbooksellerid");
141 while(my $row = $sth->fetchrow_hashref){
142 push(@booksellers,$row)
145 ## We generate branchlist
146 my $branches=GetBranches
();
148 foreach (sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} keys %$branches) {
149 my $thisbranch = ''; # FIXME: populate $thisbranch to preselect one
150 my %row = (branchcode
=> $_,
151 selected
=> ($thisbranch eq $_ ?
1 : 0),
152 branchname
=> $branches->{$_}->{'branchname'},
154 push @branchloop, \
%row;
157 my @mime = ( C4
::Context
->preference("MIME") );
158 # warn 'MIME(s): ' . join ' ', @mime;
159 my $CGIextChoice=CGI
::scrolling_list
(
165 my $CGIsepChoice=GetDelimiterChoices
;
167 CGIextChoice
=> $CGIextChoice,
168 CGIsepChoice
=> $CGIsepChoice,
169 booksellers
=> \
@booksellers,
170 branches
=> \
@branchloop);
173 output_html_with_http_headers
$input, $cookie, $template->output;