Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 174 lines (149 sloc) 5.554 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
#!/usr/bin/env 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 Koha;
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 @booksellers= split(/,/, $input->param("bookseller"));
my @branches = split(/,/, $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( @branches ){
        $where .= "AND branchcode IN (" . join( ',', ('?') x scalar(@branches) ) . ")";
        push @args,@branches;
    }
    
    # if a specific bookseller was selected
    if(@booksellers){
        $where .= "AND aqbooksellerid IN (" . join( ',', ('?') x scalar(@booksellers) ) . ")";
        push @args,@booksellers;
    }

    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;
    }
}else{
    ## We generate booksellers list
    my @bookseller_choices;
    
    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(@bookseller_choices,$row)
    }
   
    ## We generate branchlist
    my $branches=GetBranches();
my @branchloop;
foreach (sort {$branches->{$a}->{'branchname'} cmp $branches->{$b}->{'branchname'}} 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 => \@bookseller_choices,
        branches => \@branchloop);
}

output_html_with_http_headers $input, $cookie, $template->output;
Something went wrong with that request. Please try again.