Call to Bookfund Added.
[koha.git] / acqui / acqui-home.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 # $Id$
19
20
21 =head1 NAME
22
23 acqui-home.pl
24
25 =head1 DESCRIPTION
26
27 this script is the main page for acqui/
28 It presents the budget's dashboard, another table about differents currency with 
29 their rates and the pending suggestions.
30
31 =head1 CGI PARAMETERS
32
33 =over 4
34
35 =item $status
36 C<$status> is the status a suggestion could has. Default value is 'ASKED'.
37 thus, it can be REJECTED, ACCEPTED, ORDERED, ASKED, AVAIBLE
38 =back
39
40 =cut
41
42 use strict;
43 use CGI;
44 use C4::Auth;
45 use C4::Output;
46 use C4::Interface::CGI::Output;
47 use C4::Database;
48 use C4::Suggestions;
49 use HTML::Template;
50 use C4::Acquisition;
51 use C4::Bookfund;
52 use C4::Members;
53
54 my $query = new CGI;
55 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
56     {
57         template_name   => "acqui/acqui-home.tmpl",
58         query           => $query,
59         type            => "intranet",
60         authnotrequired => 0,
61         flagsrequired   => { acquisition => 1 },
62         debug           => 1,
63     }
64 );
65
66 # budget
67 my ( $flags, $homebranch ) = GetFlagsAndBranchFromBorrower($loggedinuser);
68
69 my @results = GetBookFunds($homebranch);
70 my $count = scalar @results;
71
72 my $classlist   = '';
73 my $total       = 0;
74 my $totspent    = 0;
75 my $totcomtd    = 0;
76 my $totavail    = 0;
77 my @loop_budget = ();
78
79 for (my $i=0; $i<$count; $i++){
80         my ($spent,$comtd)=GetBookFundBreakdown($results[$i]->{'bookfundid'});
81         my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
82         my %line;
83         $line{bookfundname} = $results[$i]->{'bookfundname'};
84         $line{budgetamount} = $results[$i]->{'budgetamount'};
85         $line{spent} = sprintf  ("%.2f", $spent);
86         $line{comtd} = sprintf  ("%.2f",$comtd);
87         $line{avail}  = sprintf  ("%.2f",$avail);
88         push @loop_budget, \%line;
89         $total+=$results[$i]->{'budgetamount'};
90         $totspent+=$spent;
91         $totcomtd+=$comtd;
92         $totavail+=$avail;
93 }
94
95 # currencies
96 my @rates = GetCurrencies();
97 my $count = scalar @rates;
98
99 my @loop_currency = ();
100 for ( my $i = 0 ; $i < $count ; $i++ ) {
101     my %line;
102     $line{currency} = @rates[$i]->{'currency'};
103     $line{rate}     = @rates[$i]->{'rate'};
104     push @loop_currency, \%line;
105 }
106
107 # suggestions
108 my $status           = $query->param('status') || "ASKED";
109 my $suggestion       = CountSuggestion($status);
110 my $suggestions_loop = &SearchSuggestion( '', '', '', '', $status, '' );
111
112 $template->param(
113     classlist        => $classlist,
114     type             => 'intranet',
115     loop_budget      => \@loop_budget,
116     loop_currency    => \@loop_currency,
117     total            => sprintf( "%.2f", $total ),
118     suggestion       => $suggestion,
119     suggestions_loop => $suggestions_loop,
120     totspent         => sprintf( "%.2f", $totspent ),
121     totcomtd         => sprintf( "%.2f", $totcomtd ),
122     totavail         => sprintf( "%.2f", $totavail ),
123     nobudget         => $#results == -1 ? 1 : 0
124 );
125
126 output_html_with_http_headers $query, $cookie, $template->output;