--- /dev/null
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Reports › serials subscriptions stats</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<style type="text/css">
+ .sql {display: none;}
+</style>
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/JavaScript" language="JavaScript">
+ //<![CDATA[
+ $(document).ready(function() {
+ $("#resulttable").tablesorter({
+ widgets : ['zebra']
+ });
+ });
+ //]]>
+</script>
+</head>
+<body>
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a> › Items with no checkouts</div>
+
+<div id="doc3" class="yui-t2">
+ <div id="bd">
+ <div id="yui-main">
+ <div class="yui-b">
+
+ <h1>Serials subscriptions</h1>
+<!-- TMPL_IF NAME="do_it" -->
+ <table id="resulttable">
+ <thead>
+ <tr>
+ <th>Bookseller</th>
+ <th>Title</th>
+ <th>Subscription id</th>
+ <th>Branch</th>
+ <th>Callnumber</th>
+ <th>Subscription Begin</th>
+ <th>Subscription End</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <!-- TMPL_LOOP NAME="datas" -->
+ <td><!-- TMPL_VAR NAME="name" --></td>
+ <td><!-- TMPL_VAR NAME="title" --></td>
+ <td><!-- TMPL_VAR NAME="subscriptionid" --></td>
+ <td><!-- TMPL_VAR NAME="branchcode" --></td>
+ <td><!-- TMPL_VAR NAME="callnumber" --></td>
+ <td><!-- TMPL_VAR NAME="startdate" --></td>
+ <td><!-- TMPL_VAR NAME="enddate" --></td>
+ </tr>
+ <!-- /TMPL_LOOP -->
+ </tr>
+ </tbody>
+ </table>
+
+<!-- TMPL_ELSE -->
+ <form method="post" action="/cgi-bin/koha/reports/serials_stats.pl">
+
+ <fieldset class="rows">
+ <ol>
+ <li>
+
+ <label for="bookseller">
+ Vendor:
+ </label>
+ <select name="bookseller" id="bookseller">
+ <option value="">Any Vendor</option>
+ <!--TMPL_LOOP Name="booksellers"-->
+ <option value="<!--TMPL_VAR Name="aqbooksellerid"-->"><!--TMPL_VAR Name="name"--></option>
+ <!--/TMPL_LOOP -->
+ </select>
+ </li><li>
+ <label for="branch">
+ Branch:
+ </label>
+ <select name="branchcode" id="branchcode">
+ <option value="">Any Branch</option>
+ <!--TMPL_LOOP Name="branches"-->
+ <option value="<!--TMPL_VAR Name="branchcode"-->"><!--TMPL_VAR Name="branchname"--></option>
+ <!--/TMPL_LOOP -->
+ </select>
+
+ </li>
+ <li>
+ <label for="expired">Include expired subscriptions: </label>
+ <input type="checkbox" name="expired" />
+ </li>
+ </ol>
+ </fieldset>
+
+
+ <fieldset class="rows">
+ <legend>Output</legend>
+<ol><li><label for="outputscreen">To screen into the browser: </label><input type="radio" checked="checked" name="output" id="outputscreen" value="screen" /> </li>
+<li><label for="outputfile">To a file:</label> <input type="radio" name="output" value="file" id="outputfile" /> <label class="inline" for="basename">Named: </label><input type="text" name="basename" id="basename" value="Export" />
+ <label class="inline" for="MIME">Into an application</label><!-- TMPL_VAR NAME="CGIextChoice" -->
+ <!-- TMPL_VAR NAME="CGIsepChoice" --></li></ol>
+ </fieldset>
+
+ <fieldset class="action">
+ <input type="submit" value="Submit" />
+ <input type="hidden" name="report_name" value="<!--TMPL_VAR NAME="report_name" -->" />
+ <input type="hidden" name="do_it" value="1" />
+ </fieldset>
+ </form>
+<!-- /TMPL_IF -->
+</div>
+</div>
+<div class="yui-b">
+<!-- TMPL_INCLUDE NAME="reports-menu.inc" -->
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
--- /dev/null
+#!/usr/bin/perl
+
+# Copyright 2009 SARL Biblibre
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use warnings;
+use C4::Auth;
+use CGI;
+use C4::Context;
+use C4::Branch; # GetBranches
+use C4::Dates qw/format_date/;
+use C4::Output;
+use C4::Koha;
+use C4::Reports;
+use C4::Serials;
+
+=head1 serials_out
+
+plugin that shows a stats on serials
+
+=head1 DESCRIPTION
+
+=over 2
+
+=cut
+
+my $input = new CGI;
+my $templatename = "reports/serials_stats.tmpl";
+my $do_it = $input->param("do_it");
+my $bookseller = $input->param("bookseller");
+my $branchcode = $input->param("branchcode");
+my $expired = $input->param("expired");
+my $order = $input->param("order");
+my $output = $input->param("output");
+my $basename = $input->param("basename");
+my $mime = $input->param("MIME");
+our $sep = $input->param("sep");
+$sep = "\t" if ($sep eq 'tabulation');
+
+my ($template, $borrowernumber, $cookie)
+ = get_template_and_user({template_name => $templatename,
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => {reports => 1},
+ debug => 1,
+ });
+
+
+
+my $dbh = C4::Context->dbh;
+
+if($do_it){
+ my $where = "WHERE 1 ";
+ my @args;
+ # if a specific branchcode was selected
+ if( $branchcode ne '' ){
+ $where .= "AND branchcode = ? ";
+ push @args,$branchcode;
+ }
+
+ # if a specific bookseller was selected
+ if($bookseller ne ''){
+ $where .= "AND aqbooksellerid = ? ";
+ push @args,$bookseller;
+ }
+
+ my $sth = $dbh->prepare("SELECT *
+ FROM subscription
+ LEFT JOIN aqbooksellers
+ ON (aqbooksellers.id=subscription.aqbooksellerid)
+ LEFT JOIN biblio
+ ON (biblio.biblionumber=subscription.biblionumber)
+ $where
+ ");
+
+ $sth->execute(@args);
+
+ ## hash generation of items by branchcode
+ my @datas;
+
+ while(my $row = $sth->fetchrow_hashref){
+ $row->{'enddate'} = format_date(GetExpirationDate($row->{'subscriptionid'}));
+ $row->{'startdate'} = format_date($row->{'startdate'});
+ push @datas, $row if ($expired || (not $expired && not HasSubscriptionExpired($row->{subscriptionid})) );
+ }
+
+ if($output eq 'screen'){
+ $template->param(datas => \@datas,
+ do_it => 1);
+ }else{
+ binmode STDOUT, ':utf8';
+ print $input->header(-type => 'application/vnd.sun.xml.calc',
+ -encoding => 'utf-8',
+ -name => "$basename.csv",
+ -attachment => "$basename.csv");
+ print "Vendor".$sep;
+ print "Title".$sep;
+ print "Subscription id".$sep;
+ print "Branch".$sep;
+ print "Callnumber".$sep;
+ print "Subscription Begin".$sep;
+ print "Subscription End\n";
+
+ foreach my $item (@datas){
+ print $item->{name}.$sep;
+ print $item->{title}.$sep;
+ print $item->{subscriptionid}.$sep;
+ print $item->{branchcode}.$sep;
+ print $item->{callnumber}.$sep;
+ print $item->{startdate}.$sep;
+ print $item->{enddate}."\n";
+ }
+ exit(1);
+ }
+}else{
+ ## We generate booksellers list
+ my @booksellers;
+
+ my $sth = $dbh->prepare("SELECT aqbooksellerid, aqbooksellers.name
+ FROM subscription
+ LEFT JOIN aqbooksellers ON (subscription.aqbooksellerid=aqbooksellers.id )
+ GROUP BY aqbooksellerid");
+ $sth->execute();
+
+ while(my $row = $sth->fetchrow_hashref){
+ push(@booksellers,$row)
+ }
+
+ ## We generate branchlist
+ my $branches=GetBranches();
+ my @branchloop;
+ foreach (keys %$branches) {
+ my $thisbranch = ''; # FIXME: populate $thisbranch to preselect one
+ my %row = (branchcode => $_,
+ selected => ($thisbranch eq $_ ? 1 : 0),
+ branchname => $branches->{$_}->{'branchname'},
+ );
+ push @branchloop, \%row;
+ }
+
+ my @mime = ( C4::Context->preference("MIME") );
+ # warn 'MIME(s): ' . join ' ', @mime;
+ my $CGIextChoice=CGI::scrolling_list(
+ -name => 'MIME',
+ -id => 'MIME',
+ -values => \@mime,
+ -size => 1,
+ -multiple => 0 );
+ my $CGIsepChoice=GetDelimiterChoices;
+ $template->param(
+ CGIextChoice => $CGIextChoice,
+ CGIsepChoice => $CGIsepChoice,
+ booksellers => \@booksellers,
+ branches => \@branchloop);
+}
+
+output_html_with_http_headers $input, $cookie, $template->output;
\ No newline at end of file