Merge remote-tracking branch 'tamil/3.8.4-translate' into 3.8.x
[koha.git] / acqui / acqui-home.pl
blob69482a819e985bac78cabfe4c35905bd3d87582d
1 #!/usr/bin/perl
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
9 # version.
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
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 =head1 NAME
21 acqui-home.pl
23 =head1 DESCRIPTION
25 this script is the main page for acqui
27 =cut
29 use strict;
30 use warnings;
31 use Number::Format;
33 use CGI;
34 use C4::Auth;
35 use C4::Output;
36 use C4::Acquisition;
37 use C4::Budgets;
38 use C4::Members;
39 use C4::Branch;
40 use C4::Debug;
41 use C4::Suggestions;
43 my $query = CGI->new;
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45 { template_name => 'acqui/acqui-home.tmpl',
46 query => $query,
47 type => 'intranet',
48 authnotrequired => 0,
49 flagsrequired => { acquisition => '*' },
50 debug => 1,
54 my $user = GetMember( 'borrowernumber' => $loggedinuser );
55 my $branchname = GetBranchName($user->{branchcode});
58 my $num_formatter;
60 my $cur_format = C4::Context->preference("CurrencyFormat");
61 if ( $cur_format eq 'FR' ) {
62 $num_formatter = Number::Format->new(
63 'decimal_fill' => '2',
64 'decimal_point' => ',',
65 'int_curr_symbol' => '',
66 'mon_thousands_sep' => ' ',
67 'thousands_sep' => ' ',
68 'mon_decimal_point' => ','
70 } else { # US by default..
71 $num_formatter = Number::Format->new(
72 'int_curr_symbol' => '',
73 'mon_thousands_sep' => ',',
74 'mon_decimal_point' => '.'
78 my $status = $query->param('status') || "ASKED";
79 my $suggestions_count = CountSuggestion($status);
81 my $budget_arr =
82 GetBudgetHierarchy( '', $user->{branchcode},
83 $template->{VARS}->{'USER_INFO'}[0]->{'borrowernumber'} );
85 my $total = 0;
86 my $totspent = 0;
87 my $totordered = 0;
88 my $totcomtd = 0;
89 my $totavail = 0;
91 my $total_active = 0;
92 my $totspent_active = 0;
93 my $totordered_active = 0;
94 my $totavail_active = 0;
96 foreach my $budget ( @{$budget_arr} ) {
98 $budget->{budget_code_indent} =~ s/\ /\&nbsp\;/g;
100 $budget->{'budget_branchname'} =
101 GetBranchName( $budget->{'budget_branchcode'} );
103 my $member = GetMember( borrowernumber => $budget->{budget_owner_id} );
104 if ($member) {
105 $budget->{budget_owner} =
106 $member->{'firstname'} . ' ' . $member->{'surname'};
109 if ( !defined $budget->{budget_amount} ) {
110 $budget->{budget_amount} = 0;
113 $budget->{'budget_ordered'} = GetBudgetOrdered( $budget->{'budget_id'} );
114 $budget->{'budget_spent'} = GetBudgetSpent( $budget->{'budget_id'} );
115 if ( !defined $budget->{budget_spent} ) {
116 $budget->{budget_spent} = 0;
118 if ( !defined $budget->{budget_ordered} ) {
119 $budget->{budget_ordered} = 0;
121 $budget->{'budget_avail'} =
122 $budget->{'budget_amount'} - ( $budget->{'budget_spent'} + $budget->{'budget_ordered'} );
124 $total += $budget->{'budget_amount'};
125 $totspent += $budget->{'budget_spent'};
126 $totordered += $budget->{'budget_ordered'};
127 $totavail += $budget->{'budget_avail'};
129 if ($budget->{budget_period_active}){
130 $total_active += $budget->{'budget_amount'};
131 $totspent_active += $budget->{'budget_spent'};
132 $totordered_active += $budget->{'budget_ordered'};
133 $totavail_active += $budget->{'budget_avail'};
136 for my $field (qw( budget_amount budget_spent budget_ordered budget_avail ) ) {
137 $budget->{$field} = $num_formatter->format_price( $budget->{$field} );
141 $template->param(
142 type => 'intranet',
143 loop_budget => $budget_arr,
144 branchname => $branchname,
145 total => $num_formatter->format_price($total),
146 totspent => $num_formatter->format_price($totspent),
147 totordered => $num_formatter->format_price($totordered),
148 totcomtd => $num_formatter->format_price($totcomtd),
149 totavail => $num_formatter->format_price($totavail),
150 total_active => $num_formatter->format_price($total_active),
151 totspent_active => $num_formatter->format_price($totspent_active),
152 totordered_active => $num_formatter->format_price($totordered_active),
153 totavail_active => $num_formatter->format_price($totavail_active),
154 suggestions_count => $suggestions_count,
157 output_html_with_http_headers $query, $cookie, $template->output;