reordering code & debugging
[koha.git] / bull / acqui-search.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Output;
7 use C4::Interface::CGI::Output;
8 use C4::Database;
9 use HTML::Template;
10 use C4::Acquisition;
11 my $query = new CGI;
12 my ($template, $loggedinuser, $cookie)
13     = get_template_and_user({template_name => "bull/search-supply.tmpl",
14                              query => $query,
15                              type => "intranet",
16                              authnotrequired => 0,
17                              flagsrequired => {acquisition => 1},
18                              debug => 1,
19                              });
20
21 # budget
22 my ($count,@results)=&bookfunds;
23 my $classlist='';
24 my $total=0;
25 my $totspent=0;
26 my $totcomtd=0;
27 my $totavail=0;
28 my @loop_budget = ();
29 for (my $i=0;$i<$count;$i++){
30         my ($spent,$comtd)=bookfundbreakdown($results[$i]->{'bookfundid'});
31         my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
32         my %line;
33         $line{bookfundname} = $results[$i]->{'bookfundname'};
34         $line{budgetamount} = $results[$i]->{'budgetamount'};
35         $line{spent} = sprintf  ("%.2f", $spent);
36         $line{comtd} = sprintf  ("%.2f",$comtd);
37         $line{avail}  = sprintf  ("%.2f",$avail);
38         push @loop_budget, \%line;
39         $total+=$results[$i]->{'budgetamount'};
40         $totspent+=$spent;
41         $totcomtd+=$comtd;
42         $totavail+=$avail;
43 }
44 #currencies
45 my ($count,$rates)=getcurrencies();
46 my @loop_currency = ();
47 for (my $i=0;$i<$count;$i++){
48         my %line;
49         $line{currency} = $rates->[$i]->{'currency'};
50         $line{rate} = $rates->[$i]->{'rate'};
51         push @loop_currency, \%line;
52 }
53 $template->param(classlist => $classlist,
54                                                 type => 'intranet',
55                                                 loop_budget => \@loop_budget,
56                                                 loop_currency => \@loop_currency,
57                                                 total => sprintf("%.2f",$total),
58                                                 totspent => sprintf("%.2f",$totspent),
59                                                 totcomtd => sprintf("%.2f",$totcomtd),
60                                                 totavail => sprintf("%.2f",$totavail));
61
62 output_html_with_http_headers $query, $cookie, $template->output;