rel_3_0 moved to HEAD
[koha.git] / serials / acqui-search.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 # $Id$
21
22 use strict;
23 use CGI;
24 use C4::Auth;
25 use C4::Output;
26 use C4::Interface::CGI::Output;
27 use C4::Bookfund;
28
29 my $query = new CGI;
30
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
32     {
33         template_name   => "serials/acqui-search.tmpl",
34         query           => $query,
35         type            => "intranet",
36         authnotrequired => 0,
37         flagsrequired   => { serials => 1 },
38         debug           => 1,
39     }
40 );
41
42 # budget
43 my $dbh     = C4::Context->dbh;
44 my $sthtemp =
45   $dbh->prepare(
46     "Select flags, branchcode from borrowers where borrowernumber = ?");
47 $sthtemp->execute($loggedinuser);
48 my ( $flags, $homebranch ) = $sthtemp->fetchrow;
49 my @results = GetBookFunds($homebranch);
50 my $count   = scalar(@results);
51
52 my $classlist   = '';
53 my $total       = 0;
54 my $totspent    = 0;
55 my $totcomtd    = 0;
56 my $totavail    = 0;
57 my @loop_budget = ();
58 for ( my $i = 0 ; $i < $count ; $i++ ) {
59     my ( $spent, $comtd ) =
60       GetBookFundBreakdown( $results[$i]->{'bookfundid'} );
61     my $avail = $results[$i]->{'budgetamount'} - ( $spent + $comtd );
62     my %line;
63     $line{bookfundname} = $results[$i]->{'bookfundname'};
64     $line{budgetamount} = $results[$i]->{'budgetamount'};
65     $line{spent}        = sprintf( "%.2f", $spent );
66     $line{comtd}        = sprintf( "%.2f", $comtd );
67     $line{avail}        = sprintf( "%.2f", $avail );
68     push @loop_budget, \%line;
69     $total    += $results[$i]->{'budgetamount'};
70     $totspent += $spent;
71     $totcomtd += $comtd;
72     $totavail += $avail;
73 }
74
75 #currencies
76 my @rates = GetCurrencies();
77 my $count = scalar @rates;
78
79 my @loop_currency = ();
80 for ( my $i = 0 ; $i < $count ; $i++ ) {
81     my %line;
82     $line{currency} = $rates[$i]->{'currency'};
83     $line{rate}     = $rates[$i]->{'rate'};
84     push @loop_currency, \%line;
85 }
86 $template->param(
87     classlist     => $classlist,
88     type          => 'intranet',
89     loop_budget   => \@loop_budget,
90     loop_currency => \@loop_currency,
91     total         => sprintf( "%.2f", $total ),
92     totspent      => sprintf( "%.2f", $totspent ),
93     totcomtd      => sprintf( "%.2f", $totcomtd ),
94     totavail      => sprintf( "%.2f", $totavail )
95 );
96
97 output_html_with_http_headers $query, $cookie, $template->output;