this file has been changed by parcel.pl
[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         my ($spent,$comtd)=bookfundbreakdown($results[$i]->{'bookfundid'});
42         my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
43         my %line;
44         $line{bookfundname} = $results[$i]->{'bookfundname'};
45         $line{budgetamount} = $results[$i]->{'budgetamount'};
46         $line{spent} = sprintf  ("%.2f", $spent);
47         $line{comtd} = sprintf  ("%.2f",$comtd);
48         $line{avail}  = sprintf  ("%.2f",$avail);
49         push @loop_budget, \%line;
50         $total+=$results[$i]->{'budgetamount'};
51         $totspent+=$spent;
52         $totcomtd+=$comtd;
53         $totavail+=$avail;
54 }
55
56 #currencies
57 my $rates;
58 ( $count, $rates ) = getcurrencies();
59 my @loop_currency = ();
60 for ( my $i = 0 ; $i < $count ; $i++ ) {
61     my %line;
62     $line{currency} = $rates->[$i]->{'currency'};
63     $line{rate}     = $rates->[$i]->{'rate'};
64     push @loop_currency, \%line;
65 }
66
67 # suggestions ?
68 my $status           = $query->param('status') || "ASKED";
69 my $suggestion       = CountSuggestion($status);
70 my $suggestions_loop = &SearchSuggestion( '', '', '', '', $status, '' );
71
72 $template->param(
73     classlist        => $classlist,
74     type             => 'intranet',
75     loop_budget      => \@loop_budget,
76     loop_currency    => \@loop_currency,
77     total            => sprintf( "%.2f", $total ),
78     suggestion       => $suggestion,
79     suggestions_loop => $suggestions_loop,
80     totspent         => sprintf( "%.2f", $totspent ),
81     totcomtd         => sprintf( "%.2f", $totcomtd ),
82     totavail         => sprintf( "%.2f", $totavail ),
83     nobudget         => $#results == -1 ? 1 : 0
84 );
85
86 output_html_with_http_headers $query, $cookie, $template->output;