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/
34 C<$status> is the status a suggestion could has. Default value is 'ASKED'.
35 thus, it can be REJECTED, ACCEPTED, ORDERED, ASKED, AVAIBLE
56 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
58 template_name => "acqui/acqui-home.tmpl",
62 flagsrequired => { acquisition => "*" },
68 my $borrower= GetMember('borrowernumber' => $loggedinuser);
69 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
71 my @results = GetBudgets($homebranch);
72 my $count = scalar @results;
73 my $branchname = GetBranchName($homebranch);
83 # ---------------------------------------------------
87 my $active_currency = GetCurrency;
90 my $cur_format = C4::Context->preference("CurrencyFormat");
91 if ( $cur_format eq 'FR' ) {
92 $num = new Number::Format(
93 'decimal_fill' => '2',
94 'decimal_point' => ',',
95 'int_curr_symbol' => '',
96 'mon_thousands_sep' => ' ',
97 'thousands_sep' => ' ',
98 'mon_decimal_point' => ','
100 } else { # US by default..
101 $num = new Number::Format(
102 'int_curr_symbol' => '',
103 'mon_thousands_sep' => ',',
104 'mon_decimal_point' => '.'
109 my $status = $query->param('status') || "ASKED";
110 my $suggestion = CountSuggestion($status);
111 my $suggestions_loop = &SearchSuggestion( {STATUS=> $status} );
112 # ---------------------------------------------------
114 my $period = GetBudgetPeriod;
115 my $budget_period_id = $period->{budget_period_id};
116 my $budget_branchcode = $period->{budget_branchcode};
117 my $moo = GetBudgetHierarchy('',$homebranch, $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} );
119 my $period_total = 0;
123 foreach my $result (@results) {
124 # only get top-level budgets for display
125 # warn $result->{'budget_branchcode'};
127 $period_total += $result->{'budget_amount'};
129 my $a = $result->{'budget_code_indent'};
130 $a =~ s/\ /\ \;/g;
131 $result->{'budget_code_indent'} = $a;
133 my $r = GetBranchName( $result->{'budget_owner_id'} );
134 $result->{'budget_branchname'} = GetBranchName( $result->{'budget_branchcode'} );
136 my $member = GetMember( borrowernumber => $result->{budget_owner_id} );
137 my $member_full = $member->{'firstname'} . ' ' . $member->{'surname'} if $member;
138 # as we are going to treat these as numbers let's ensure they are not NULL
139 if (!defined $result->{budget_amount} ) {
140 $result->{budget_amount} = 0;
142 if (!defined $result->{budget_spent} ) {
143 $result->{budget_spent} = 0;
145 if (!defined $result->{budget_ordered} ) {
146 $result->{budget_ordered} = 0;
149 $result->{'budget_owner'} = $member_full;
150 $result->{'budget_ordered'} = GetBudgetOrdered( $result->{'budget_id'} );
151 $result->{'budget_spent'} = GetBudgetSpent( $result->{'budget_id'} );
152 $result->{'budget_avail'} = $result->{'budget_amount'} - $result->{'budget_spent'} - $result->{'budget_ordered'};
154 $total += $result->{'budget_amount'};
155 $totspent += $result->{'budget_spent'};
156 $totordered += $result->{'budget_ordered'};
157 $totavail += $result->{'budget_avail'};
159 $result->{'budget_amount'} = $num->format_price( $result->{'budget_amount'} );
160 $result->{'budget_spent'} = $num->format_price( $result->{'budget_spent'} );
161 $result->{'budget_ordered'} = $num->format_price( $result->{'budget_ordered'} );
162 $result->{'budget_avail'} = $num->format_price( $result->{'budget_avail'} );
164 # my $spent_percent = ( $result->{'budget_spent'} / $result->{'budget_amount'} ) * 100;
165 # $result->{'budget_spent_percent'} = sprintf( "%00d", $spent_percent );
168 $result->{budget_owner_name} = $member->{'firstname'} . ' ' . $member->{'surname'};
171 push( @loop_budget, { %{$result}, toggle => $toggle++ % 2, } );
175 classlist => $classlist,
177 loop_budget => \@loop_budget,
178 active_symbol => $active_currency->{'symbol'},
179 branchname => $branchname,
180 budget => $period->{budget_name},
181 total => $num->format_price( $total ),
182 totspent => $num->format_price( $totspent ),
183 totordered => $num->format_price( $totordered ),
184 totcomtd => $num->format_price( $totcomtd ),
185 totavail => $num->format_price( $totavail ),
186 suggestion => $suggestion,
189 output_html_with_http_headers $query, $cookie, $template->output;