Bugfixes & improvements (various and minor) :
[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::Bookfund;
27
28 my $query = new CGI;
29
30 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31     {
32         template_name   => "serials/acqui-search.tmpl",
33         query           => $query,
34         type            => "intranet",
35         authnotrequired => 0,
36         flagsrequired   => { serials => 1 },
37         debug           => 1,
38     }
39 );
40
41 # budget
42 my $dbh     = C4::Context->dbh;
43 my $sthtemp =
44   $dbh->prepare(
45     "Select flags, branchcode from borrowers where borrowernumber = ?");
46 $sthtemp->execute($loggedinuser);
47 my ( $flags, $homebranch ) = $sthtemp->fetchrow;
48 my @results = GetBookFunds($homebranch);
49 my $count   = scalar(@results);
50
51 my $classlist   = '';
52 my $total       = 0;
53 my $totspent    = 0;
54 my $totcomtd    = 0;
55 my $totavail    = 0;
56 my @loop_budget = ();
57 for ( my $i = 0 ; $i < $count ; $i++ ) {
58     my ( $spent, $comtd ) =
59       GetBookFundBreakdown( $results[$i]->{'bookfundid'} );
60     my $avail = $results[$i]->{'budgetamount'} - ( $spent + $comtd );
61     my %line;
62     $line{bookfundname} = $results[$i]->{'bookfundname'};
63     $line{budgetamount} = $results[$i]->{'budgetamount'};
64     $line{spent}        = sprintf( "%.2f", $spent );
65     $line{comtd}        = sprintf( "%.2f", $comtd );
66     $line{avail}        = sprintf( "%.2f", $avail );
67     push @loop_budget, \%line;
68     $total    += $results[$i]->{'budgetamount'};
69     $totspent += $spent;
70     $totcomtd += $comtd;
71     $totavail += $avail;
72 }
73
74 #currencies
75 my @rates = GetCurrencies();
76 my $count = scalar @rates;
77
78 my @loop_currency = ();
79 for ( my $i = 0 ; $i < $count ; $i++ ) {
80     my %line;
81     $line{currency} = $rates[$i]->{'currency'};
82     $line{rate}     = $rates[$i]->{'rate'};
83     push @loop_currency, \%line;
84 }
85 $template->param(
86     classlist     => $classlist,
87     type          => 'intranet',
88     loop_budget   => \@loop_budget,
89     loop_currency => \@loop_currency,
90     total         => sprintf( "%.2f", $total ),
91     totspent      => sprintf( "%.2f", $totspent ),
92     totcomtd      => sprintf( "%.2f", $totcomtd ),
93     totavail      => sprintf( "%.2f", $totavail )
94 );
95
96 output_html_with_http_headers $query, $cookie, $template->output;