Merging Katipo changes.
[koha.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 $dbh = C4::Context->dbh;
25 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
26 $sthtemp->execute($loggedinuser);
27 my ($flags, $homebranch)=$sthtemp->fetchrow;
28
29 my ($count,@results)=bookfunds($homebranch);
30 my $classlist='';
31 my $total=0;
32 my $totspent=0;
33 my $totcomtd=0;
34 my $totavail=0;
35 my @loop_budget = ();
36 for (my $i=0;$i<$count;$i++){
37
38     if ( $toggle eq 0 ) {
39         $toggle = 1;
40     }
41     else {
42         $toggle = 0;
43     }
44         my ($spent,$comtd)=bookfundbreakdown($results[$i]->{'bookfundid'});
45         my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
46         my %line;
47
48         $line{bookfundname} = $results[$i]->{'bookfundname'};
49         $line{budgetamount} = $results[$i]->{'budgetamount'};
50         $line{spent} = sprintf  ("%.2f", $spent);
51         $line{comtd} = sprintf  ("%.2f",$comtd);
52         $line{avail}  = sprintf  ("%.2f",$avail);
53         $line{'toggle'}     = $toggle;
54         push @loop_budget, \%line;
55         $total+=$results[$i]->{'budgetamount'};
56         $totspent+=$spent;
57         $totcomtd+=$comtd;
58         $totavail+=$avail;
59 }
60 #currencies
61 my $rates;
62 ($count,$rates)=getcurrencies();
63 my @loop_currency = ();
64 for (my $i=0;$i<$count;$i++){
65         my %line;
66         $line{currency} = $rates->[$i]->{'currency'};
67         $line{rate} = $rates->[$i]->{'rate'};
68         push @loop_currency, \%line;
69 }
70
71 # suggestions ?
72 my $suggestion = countsuggestion("ASKED");
73 $template->param(classlist => $classlist,
74                                                 type => 'intranet',
75                                                 loop_budget => \@loop_budget,
76                                                 loop_currency => \@loop_currency,
77                                                 total => sprintf("%.2f",$total),
78                                                 suggestion => $suggestion,
79                                                 totspent => sprintf("%.2f",$totspent),
80                                                 totcomtd => sprintf("%.2f",$totcomtd),
81                                                 totavail => sprintf("%.2f",$totavail),
82                                                 nobudget => $#results==-1?1:0);
83
84 output_html_with_http_headers $query, $cookie, $template->output;