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,
54 flagsrequired
=> {reports
=> '*'},
60 my $dbh = C4
::Context
->dbh;
63 my $where = "WHERE 1 ";
65 # if a specific branchcode was selected
66 if( $branchcode ne '' ){
67 $where .= "AND branchcode = ? ";
68 push @args,$branchcode;
71 # if a specific bookseller was selected
72 if($bookseller ne ''){
73 $where .= "AND aqbooksellerid = ? ";
74 push @args,$bookseller;
77 my $sth = $dbh->prepare("SELECT *
79 LEFT JOIN aqbooksellers
80 ON (aqbooksellers.id=subscription.aqbooksellerid)
82 ON (biblio.biblionumber=subscription.biblionumber)
88 ## hash generation of items by branchcode
91 while(my $row = $sth->fetchrow_hashref){
92 $row->{'enddate'} = GetExpirationDate
($row->{'subscriptionid'});
93 $row->{expired
} = HasSubscriptionExpired
($row->{subscriptionid
});
94 push @datas, $row if (
100 and not $row->{closed
}
106 if($output eq 'screen'){
107 $template->param(datas
=> \
@datas,
110 binmode STDOUT
, ':encoding(UTF-8)';
111 print $input->header(-type
=> 'application/vnd.sun.xml.calc',
112 -encoding
=> 'utf-8',
113 -name
=> "$basename.csv",
114 -attachment
=> "$basename.csv");
117 print "Subscription id".$sep;
119 print "Callnumber".$sep;
120 print "Subscription Begin".$sep;
121 print "Subscription End\n";
123 foreach my $item (@datas){
124 print $item->{name
}.$sep;
125 print $item->{title
}.$sep;
126 print $item->{subscriptionid
}.$sep;
127 print $item->{branchcode
}.$sep;
128 print $item->{callnumber
}.$sep;
129 print $item->{startdate
}.$sep;
130 print $item->{enddate
}."\n";
135 ## We generate booksellers list
138 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
140 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
141 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;