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