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