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
33 plugin that shows a stats on serials
40 my $templatename = "reports/serials_stats.tt";
41 my $do_it = $input->param("do_it");
42 my $bookseller = $input->param("bookseller");
43 my $branchcode = $input->param("branchcode");
44 my $expired = $input->param("expired");
45 my $order = $input->param("order");
46 my $output = $input->param("output");
47 my $basename = $input->param("basename");
48 our $sep = $input->param("sep") || '';
49 $sep = "\t" if ($sep eq 'tabulation');
51 my ($template, $borrowernumber, $cookie)
52 = get_template_and_user
({template_name
=> $templatename,
56 flagsrequired
=> {reports
=> '*'},
62 my $dbh = C4
::Context
->dbh;
65 my $where = "WHERE 1 ";
67 # if a specific branchcode was selected
68 if( $branchcode ne '' ){
69 $where .= "AND branchcode = ? ";
70 push @args,$branchcode;
73 # if a specific bookseller was selected
74 if($bookseller ne ''){
75 $where .= "AND aqbooksellerid = ? ";
76 push @args,$bookseller;
79 my $sth = $dbh->prepare("SELECT *
81 LEFT JOIN aqbooksellers
82 ON (aqbooksellers.id=subscription.aqbooksellerid)
84 ON (biblio.biblionumber=subscription.biblionumber)
90 ## hash generation of items by branchcode
93 while(my $row = $sth->fetchrow_hashref){
94 $row->{'enddate'} = GetExpirationDate
($row->{'subscriptionid'});
95 $row->{expired
} = HasSubscriptionExpired
($row->{subscriptionid
});
96 push @datas, $row if (
102 and not $row->{closed
}
108 if($output eq 'screen'){
109 $template->param(datas
=> \
@datas,
112 binmode STDOUT
, ':encoding(UTF-8)';
113 print $input->header(-type
=> 'application/vnd.sun.xml.calc',
114 -encoding
=> 'utf-8',
115 -name
=> "$basename.csv",
116 -attachment
=> "$basename.csv");
119 print "Subscription id".$sep;
121 print "Callnumber".$sep;
122 print "Subscription Begin".$sep;
123 print "Subscription End\n";
125 foreach my $item (@datas){
126 print $item->{name
}.$sep;
127 print $item->{title
}.$sep;
128 print $item->{subscriptionid
}.$sep;
129 print $item->{branchcode
}.$sep;
130 print $item->{callnumber
}.$sep;
131 print $item->{startdate
}.$sep;
132 print $item->{enddate
}."\n";
137 ## We generate booksellers list
140 my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
142 LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
143 GROUP BY aqbooksellerid");
146 while(my $row = $sth->fetchrow_hashref){
147 push(@booksellers,$row)
150 my $CGIextChoice = ( 'CSV' ); # FIXME translation
151 my $CGIsepChoice=GetDelimiterChoices
;
153 CGIextChoice
=> $CGIextChoice,
154 CGIsepChoice
=> $CGIsepChoice,
155 booksellers
=> \
@booksellers,
156 branches
=> GetBranchesLoop
(C4
::Context
->userenv->{'branch'}));
159 output_html_with_http_headers
$input, $cookie, $template->output;