3 # Copyright 2008 - 2009 BibLibre SARL
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
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.
36 C<$status> is the status a suggestion could has. Default value is 'ASKED'.
37 thus, it can be REJECTED, ACCEPTED, ORDERED, ASKED, AVAIBLE
58 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60 template_name => "acqui/acqui-home.tmpl",
64 flagsrequired => { acquisition => "*" },
70 warn("LOGGED=$loggedinuser");
71 my $borrower= GetMember('borrowernumber' => $loggedinuser);
72 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
74 my @results = GetBudgets($homebranch);
75 my $count = scalar @results;
76 my $branchname = GetBranchName($homebranch);
78 #my $count = scalar @results;
87 # ---------------------------------------------------
90 my @rates = GetCurrencies();
91 $count = scalar @rates;
93 my $active_currency = GetCurrency;
96 my $cur_format = C4::Context->preference("CurrencyFormat");
97 if ( $cur_format eq 'FR' ) {
98 $num = new Number::Format(
99 'decimal_fill' => '2',
100 'decimal_point' => ',',
101 'int_curr_symbol' => '',
102 'mon_thousands_sep' => ' ',
103 'thousands_sep' => ' ',
104 'mon_decimal_point' => ','
106 } else { # US by default..
107 $num = new Number::Format(
108 'int_curr_symbol' => '',
109 'mon_thousands_sep' => ',',
110 'mon_decimal_point' => '.'
114 my @loop_currency = ();
115 for ( my $i = 0 ; $i < $count ; $i++ ) {
117 $line{currency} = $rates[$i]->{'currency'} ;
118 $line{currency_symbol} = $rates[$i]->{'symbol'};
119 $line{rate} = sprintf ( '%.2f', $rates[$i]->{'rate'} );
120 push @loop_currency, \%line;
124 my $status = $query->param('status') || "ASKED";
125 my $suggestion = CountSuggestion($status);
126 my $suggestions_loop = &SearchSuggestion( {STATUS=> $status} );
127 # ---------------------------------------------------
129 my $period = GetBudgetPeriod;
130 my $budget_period_id = $period->{budget_period_id};
131 my $budget_branchcode = $period->{budget_branchcode};
132 my $moo = GetBudgetHierarchy('',$homebranch, $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} );
134 my $period_total = 0;
138 foreach my $result (@results) {
139 # only get top-level budgets for display
140 # warn $result->{'budget_branchcode'};
142 $period_total += $result->{'budget_amount'};
144 my $a = $result->{'budget_code_indent'};
145 $a =~ s/\ /\ \;/g;
146 $result->{'budget_code_indent'} = $a;
148 my $r = GetBranchName( $result->{'budget_owner_id'} );
149 $result->{'budget_branchname'} = GetBranchName( $result->{'budget_branchcode'} );
151 my $member = GetMember( borrowernumber => $result->{budget_owner_id} );
152 my $member_full = $member->{'firstname'} . ' ' . $member->{'surname'} if $member;
154 $result->{'budget_owner'} = $member_full;
155 $result->{'budget_ordered'} = GetBudgetOrdered( $result->{'budget_id'} );
156 $result->{'budget_spent'} = GetBudgetSpent( $result->{'budget_id'} );
157 $result->{'budget_avail'} = $result->{'budget_amount'} - $result->{'budget_spent'} - $result->{'budget_ordered'};
159 $total += $result->{'budget_amount'};
160 $totspent += $result->{'budget_spent'};
161 $totordered += $result->{'budget_ordered'};
162 $totavail += $result->{'budget_avail'};
164 $result->{'budget_amount'} = $num->format_price( $result->{'budget_amount'} );
165 $result->{'budget_spent'} = $num->format_price( $result->{'budget_spent'} );
166 $result->{'budget_ordered'} = $num->format_price( $result->{'budget_ordered'} );
167 $result->{'budget_avail'} = $num->format_price( $result->{'budget_avail'} );
169 # my $spent_percent = ( $result->{'budget_spent'} / $result->{'budget_amount'} ) * 100;
170 # $result->{'budget_spent_percent'} = sprintf( "%00d", $spent_percent );
173 $result->{budget_owner_name} = $member->{'firstname'} . ' ' . $member->{'surname'};
176 push( @loop_budget, { %{$result}, toggle => $toggle++ % 2, } );
180 classlist => $classlist,
182 loop_budget => \@loop_budget,
183 loop_currency => \@loop_currency,
184 active_symbol => $active_currency->{'symbol'},
185 branchname => $branchname,
186 budget => $period->{budget_name},
187 total => $num->format_price( $total ),
188 totspent => $num->format_price( $totspent ),
189 totordered => $num->format_price( $totordered ),
190 totcomtd => $num->format_price( $totcomtd ),
191 totavail => $num->format_price( $totavail ),
192 suggestion => $suggestion,
195 output_html_with_http_headers $query, $cookie, $template->output;