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