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 my $borrower= GetMember('borrowernumber' => $loggedinuser);
71 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
73 my @results = GetBudgets($homebranch);
74 my $count = scalar @results;
75 my $branchname = GetBranchName($homebranch);
77 #my $count = scalar @results;
85 # ---------------------------------------------------
88 my @rates = GetCurrencies();
89 $count = scalar @rates;
91 my $active_currency = GetCurrency;
94 my $cur_format = C4::Context->preference("CurrencyFormat");
95 if ( $cur_format eq 'FR' ) {
96 $num = new Number::Format(
97 'decimal_fill' => '2',
98 'decimal_point' => ',',
99 'int_curr_symbol' => '',
100 'mon_thousands_sep' => ' ',
101 'thousands_sep' => ' ',
102 'mon_decimal_point' => ','
104 } else { # US by default..
105 $num = new Number::Format(
106 'int_curr_symbol' => '',
107 'mon_thousands_sep' => ',',
108 'mon_decimal_point' => '.'
112 my @loop_currency = ();
113 for ( my $i = 0 ; $i < $count ; $i++ ) {
115 $line{currency} = $rates[$i]->{'currency'} ;
116 $line{currency_symbol} = $rates[$i]->{'symbol'};
117 $line{rate} = sprintf ( '%.2f', $rates[$i]->{'rate'} );
118 push @loop_currency, \%line;
122 my $status = $query->param('status') || "ASKED";
123 my $suggestion = CountSuggestion($status);
124 my $suggestions_loop = &SearchSuggestion( {STATUS=> $status} );
125 # ---------------------------------------------------
127 my $period = GetBudgetPeriod;
128 my $budget_period_id = $period->{budget_period_id};
129 my $budget_branchcode = $period->{budget_branchcode};
130 my $moo = GetBudgetHierarchy('',$homebranch, $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} );
132 my $period_total = 0;
136 foreach my $result (@results) {
137 # only get top-level budgets for display
138 # warn $result->{'budget_branchcode'};
140 $period_total += $result->{'budget_amount'};
142 my $a = $result->{'budget_code_indent'};
143 $a =~ s/\ /\ \;/g;
144 $result->{'budget_code_indent'} = $a;
146 my $r = GetBranchName( $result->{'budget_owner_id'} );
147 $result->{'budget_branchname'} = GetBranchName( $result->{'budget_branchcode'} );
149 my $member = GetMember( $result->{'budget_owner_id'} );
150 my $member_full = $member->{'firstname'} . ' ' . $member->{'surname'} if $member;
152 $result->{'budget_owner'} = $member_full;
153 if ($result->{'budget_spent'}){
154 $result->{'budget_avail'} = $result->{'budget_amount'} - $result->{'budget_spent'};
157 $result->{'budget_avail'} = $result->{'budget_amount'};
159 $result->{'budget_spent'} = GetBudgetSpent( $result->{'budget_id'} );
161 $total += $result->{'budget_amount'};
162 $totspent += $result->{'budget_spent'} if $result->{'budget_spent'};
163 $totavail += $result->{'budget_avail'};
165 $result->{'budget_amount'} = $num->format_price( $result->{'budget_amount'} );
166 $result->{'budget_spent'} = $num->format_price( $result->{'budget_spent'} );
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 );
172 my $borrower = &GetMember( $result->{budget_owner_id} );
173 $result->{budget_owner_name} = $borrower->{'firstname'} . ' ' . $borrower->{'surname'} if $borrower;
175 push( @loop_budget, { %{$result}, toggle => $toggle++ % 2, } );
179 classlist => $classlist,
181 loop_budget => \@loop_budget,
182 loop_currency => \@loop_currency,
183 active_symbol => $active_currency->{'symbol'},
184 branchname => $branchname,
185 budget => $period->{budget_name},
186 total => $num->format_price( $total ),
187 totspent => $num->format_price($totspent ),
188 totcomtd => $num->format_price( $totcomtd ),
189 totavail => $num->format_price( $totavail ),
190 suggestion => $suggestion,
193 output_html_with_http_headers $query, $cookie, $template->output;