*** empty log message ***
[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
39 =back
40
41 =cut
42
43 use strict;
44 use CGI;
45 use C4::Auth;
46 use C4::Output;
47 use C4::Interface::CGI::Output;
48
49 use C4::Suggestions;
50
51 use C4::Acquisition;
52 use C4::Bookfund;
53 use C4::Members;
54
55 my $query = new CGI;
56 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
57     {
58         template_name   => "acqui/acqui-home.tmpl",
59         query           => $query,
60         type            => "intranet",
61         authnotrequired => 0,
62         flagsrequired   => { acquisition => 1 },
63         debug           => 1,
64     }
65 );
66
67 # budget
68 my ( $flags, $homebranch ) = GetFlagsAndBranchFromBorrower($loggedinuser);
69
70 my @results = GetBookFunds($homebranch);
71 my $count = scalar @results;
72
73 my $classlist   = '';
74 my $total       = 0;
75 my $totspent    = 0;
76 my $totcomtd    = 0;
77 my $totavail    = 0;
78 my @loop_budget = ();
79
80 for (my $i=0; $i<$count; $i++){
81         my ($spent,$comtd)=GetBookFundBreakdown($results[$i]->{'bookfundid'});
82         my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
83         my %line;
84         $line{bookfundname} = $results[$i]->{'bookfundname'};
85         $line{budgetamount} = $results[$i]->{'budgetamount'};
86         $line{spent} = sprintf  ("%.2f", $spent);
87         $line{comtd} = sprintf  ("%.2f",$comtd);
88         $line{avail}  = sprintf  ("%.2f",$avail);
89         push @loop_budget, \%line;
90         $total+=$results[$i]->{'budgetamount'};
91         $totspent+=$spent;
92         $totcomtd+=$comtd;
93         $totavail+=$avail;
94 }
95
96 # currencies
97 my @rates = GetCurrencies();
98 $count = scalar @rates;
99
100 my @loop_currency = ();
101 for ( my $i = 0 ; $i < $count ; $i++ ) {
102     my %line;
103     $line{currency} = $rates[$i]->{'currency'};
104     $line{rate}     = $rates[$i]->{'rate'};
105     push @loop_currency, \%line;
106 }
107
108 # suggestions
109 my $status           = $query->param('status') || "ASKED";
110 my $suggestion       = CountSuggestion($status);
111 my $suggestions_loop = &SearchSuggestion( '', '', '', '', $status, '' );
112
113 $template->param(
114     classlist        => $classlist,
115     type             => 'intranet',
116     loop_budget      => \@loop_budget,
117     loop_currency    => \@loop_currency,
118     total            => sprintf( "%.2f", $total ),
119     suggestion       => $suggestion,
120     suggestions_loop => $suggestions_loop,
121     totspent         => sprintf( "%.2f", $totspent ),
122     totcomtd         => sprintf( "%.2f", $totcomtd ),
123     totavail         => sprintf( "%.2f", $totavail ),
124     nobudget         => $#results == -1 ? 1 : 0
125 );
126
127 output_html_with_http_headers $query, $cookie, $template->output;