*** empty log message ***
[wip/koha-chris_n.git] / acqui / acqui-home.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::Catalogue;
11
12 my $query = new CGI;
13 my ($template, $loggedinuser, $cookie)
14     = get_template_and_user({template_name => "acqui/acqui-home.tmpl",
15                              query => $query,
16                              type => "intranet",
17                              authnotrequired => 0,
18                              flagsrequired => {acquisition => 1},
19                              debug => 1,
20                              });
21
22 # budget
23 my ($count,@results)=bookfunds;
24 my $classlist='';
25 my $total=0;
26 my $totspent=0;
27 my $totcomtd=0;
28 my $totavail=0;
29 my @loop_budget = ();
30 for (my $i=0;$i<$count;$i++){
31         my ($spent,$comtd)=bookfundbreakdown($results[$i]->{'bookfundid'});
32         my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
33         my %line;
34         $line{bookfundname} = $results[$i]->{'bookfundname'};
35         $line{budgetamount} = $results[$i]->{'budgetamount'};
36         $line{spent} = sprintf  ("%.2f", $spent);
37         $line{comtd} = sprintf  ("%.2f",$comtd);
38         $line{avail}  = sprintf  ("%.2f",$avail);
39         push @loop_budget, \%line;
40         $total+=$results[$i]->{'budgetamount'};
41         $totspent+=$spent;
42         $totcomtd+=$comtd;
43         $totavail+=$avail;
44 }
45 #currencies
46 my ($count,$rates)=getcurrencies();
47 my @loop_currency = ();
48 for (my $i=0;$i<$count;$i++){
49         my %line;
50         $line{currency} = $rates->[$i]->{'currency'};
51         $line{rate} = $rates->[$i]->{'rate'};
52         push @loop_currency, \%line;
53 }
54 $template->param(classlist => $classlist,
55                                                 type => 'intranet',
56                                                 loop_budget => \@loop_budget,
57                                                 loop_currency => \@loop_currency,
58                                                 total => sprintf("%.2f",$total),
59                                                 totspent => sprintf("%.2f",$totspent),
60                                                 totcomtd => sprintf("%.2f",$totcomtd),
61                                                 totavail => sprintf("%.2f",$totavail));
62
63 output_html_with_http_headers $query, $cookie, $template->output;