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>.
31 plugin that shows a stats on serials
38 my $templatename = "reports/serials_stats.tt";
39 my $do_it = $input->param("do_it");
40 my $bookseller = $input->param("bookseller");
41 my $branchcode = $input->param("branchcode");
42 my $expired = $input->param("expired");
43 my $order = $input->param("order");
44 my $output = $input->param("output");
45 my $basename = $input->param("basename");
46 our $sep = $input->param("sep") || '';
47 $sep = "\t" if ($sep eq 'tabulation');
49 my ($template, $borrowernumber, $cookie)
50 = get_template_and_user
({template_name
=> $templatename,
53 flagsrequired
=> {reports
=> '*'},
59 my $dbh = C4
::Context
->dbh;
62 my $where = "WHERE 1 ";
64 # if a specific branchcode was selected
65 if( $branchcode ne '' ){
66 $where .= "AND branchcode = ? ";
67 push @args,$branchcode;
70 # if a specific bookseller was selected
71 if($bookseller ne ''){
72 $where .= "AND aqbooksellerid = ? ";
73 push @args,$bookseller;
76 my $sth = $dbh->prepare("SELECT *
78 LEFT JOIN aqbooksellers
79 ON (aqbooksellers.id=subscription.aqbooksellerid)
81 ON (biblio.biblionumber=subscription.biblionumber)
87 ## hash generation of items by branchcode
90 while(my $row = $sth->fetchrow_hashref){
91 $row->{'enddate'} = GetExpirationDate
($row->{'subscriptionid'});
92 $row->{expired
} = HasSubscriptionExpired
($row->{subscriptionid
});
93 push @datas, $row if (
99 and not $row->{closed
}
105 if($output eq 'screen'){
106 $template->param(datas
=> \
@datas,
109 binmode STDOUT
, ':encoding(UTF-8)';
110 print $input->header(-type
=> 'application/vnd.sun.xml.calc',
111 -encoding
=> 'utf-8',
112 -name
=> "$basename.csv",
113 -attachment
=> "$basename.csv");
116 print "Subscription id".$sep;
118 print "Callnumber".$sep;
119 print "Subscription Begin".$sep;
120 print "Subscription End\n";
122 foreach my $item (@datas){
123 print $item->{name
}.$sep;
124 print $item->{title
}.$sep;
125 print $item->{subscriptionid
}.$sep;
126 print $item->{branchcode
}.$sep;
127 print $item->{callnumber
}.$sep;
128 print $item->{startdate
}.$sep;
129 print $item->{enddate
}."\n";
134 ## We generate booksellers list
137 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
139 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
140 ORDER BY aqbooksellers.name ASC
144 while(my $row = $sth->fetchrow_hashref){
145 push(@booksellers,$row)
148 my $CGIextChoice = ( 'CSV' ); # FIXME translation
149 my $CGIsepChoice=GetDelimiterChoices
;
151 CGIextChoice
=> $CGIextChoice,
152 CGIsepChoice
=> $CGIsepChoice,
153 booksellers
=> \
@booksellers,
157 output_html_with_http_headers
$input, $cookie, $template->output;