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>.
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.tt";
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 our $sep = $input->param("sep") || '';
52 $sep = "\t" if ($sep eq 'tabulation');
54 my ($template, $borrowernumber, $cookie)
55 = get_template_and_user
({template_name
=> $templatename,
59 flagsrequired
=> {reports
=> '*'},
65 my $dbh = C4
::Context
->dbh;
68 my $where = "WHERE 1 ";
70 # if a specific branchcode was selected
71 if( $branchcode ne '' ){
72 $where .= "AND branchcode = ? ";
73 push @args,$branchcode;
76 # if a specific bookseller was selected
77 if($bookseller ne ''){
78 $where .= "AND aqbooksellerid = ? ";
79 push @args,$bookseller;
82 my $sth = $dbh->prepare("SELECT *
84 LEFT JOIN aqbooksellers
85 ON (aqbooksellers.id=subscription.aqbooksellerid)
87 ON (biblio.biblionumber=subscription.biblionumber)
93 ## hash generation of items by branchcode
96 while(my $row = $sth->fetchrow_hashref){
97 $row->{'enddate'} = GetExpirationDate
($row->{'subscriptionid'});
98 $row->{expired
} = HasSubscriptionExpired
($row->{subscriptionid
});
99 push @datas, $row if (
105 and not $row->{closed
}
111 if($output eq 'screen'){
112 $template->param(datas
=> \
@datas,
115 binmode STDOUT
, ':encoding(UTF-8)';
116 print $input->header(-type
=> 'application/vnd.sun.xml.calc',
117 -encoding
=> 'utf-8',
118 -name
=> "$basename.csv",
119 -attachment
=> "$basename.csv");
122 print "Subscription id".$sep;
124 print "Callnumber".$sep;
125 print "Subscription Begin".$sep;
126 print "Subscription End\n";
128 foreach my $item (@datas){
129 print $item->{name
}.$sep;
130 print $item->{title
}.$sep;
131 print $item->{subscriptionid
}.$sep;
132 print $item->{branchcode
}.$sep;
133 print $item->{callnumber
}.$sep;
134 print $item->{startdate
}.$sep;
135 print $item->{enddate
}."\n";
140 ## We generate booksellers list
143 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
145 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
146 GROUP BY aqbooksellerid");
149 while(my $row = $sth->fetchrow_hashref){
150 push(@booksellers,$row)
153 my $CGIextChoice = ( 'CSV' ); # FIXME translation
154 my $CGIsepChoice=GetDelimiterChoices
;
156 CGIextChoice
=> $CGIextChoice,
157 CGIsepChoice
=> $CGIsepChoice,
158 booksellers
=> \
@booksellers,
159 branches
=> GetBranchesLoop
(C4
::Context
->userenv->{'branch'}));
162 output_html_with_http_headers
$input, $cookie, $template->output;