Bug 4805: Fixes multiple subscriptionid's being passed to serials-collection.
[koha.git] / acqui / acqui-home.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008 - 2009 BibLibre SARL
4 # This file is part of Koha.
5 #
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.
10 #
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.
14 #
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.
18
19 =head1 NAME
20
21 acqui-home.pl
22
23 =head1 DESCRIPTION
24
25 this script is the main page for acqui
26
27 =cut
28
29 use strict;
30 use warnings;
31 use Number::Format;
32
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
42 my $query = CGI->new;
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44     {   template_name   => 'acqui/acqui-home.tmpl',
45         query           => $query,
46         type            => 'intranet',
47         authnotrequired => 0,
48         flagsrequired   => { acquisition => '*' },
49         debug           => 1,
50     }
51 );
52
53 my $user = GetMember( 'borrowernumber' => $loggedinuser );
54 my $branchname = GetBranchName($user->{branchcode});
55
56
57 my $num_formatter;
58
59 my $cur_format = C4::Context->preference("CurrencyFormat");
60 if ( $cur_format eq 'FR' ) {
61     $num_formatter = Number::Format->new(
62         'decimal_fill'      => '2',
63         'decimal_point'     => ',',
64         'int_curr_symbol'   => '',
65         'mon_thousands_sep' => ' ',
66         'thousands_sep'     => ' ',
67         'mon_decimal_point' => ','
68     );
69 } else {    # US by default..
70     $num_formatter = Number::Format->new(
71         'int_curr_symbol'   => '',
72         'mon_thousands_sep' => ',',
73         'mon_decimal_point' => '.'
74     );
75 }
76
77 my $budget_arr =
78   GetBudgetHierarchy( '', $user->{branchcode},
79     $template->{param_map}->{'USER_INFO'}[0]->{'borrowernumber'} );
80
81 my $total      = 0;
82 my $totspent   = 0;
83 my $totordered = 0;
84 my $totcomtd   = 0;
85 my $totavail   = 0;
86
87 foreach my $budget ( @{$budget_arr} ) {
88
89     $budget->{budget_code_indent} =~ s/\ /\&nbsp\;/g;
90
91     $budget->{'budget_branchname'} =
92       GetBranchName( $budget->{'budget_branchcode'} );
93
94     my $member = GetMember( borrowernumber => $budget->{budget_owner_id} );
95     if ($member) {
96         $budget->{budget_owner} =
97           $member->{'firstname'} . ' ' . $member->{'surname'};
98     }
99
100     if ( !defined $budget->{budget_amount} ) {
101         $budget->{budget_amount} = 0;
102     }
103
104     $budget->{'budget_ordered'} = GetBudgetOrdered( $budget->{'budget_id'} );
105     $budget->{'budget_spent'}   = GetBudgetSpent( $budget->{'budget_id'} );
106     if ( !defined $budget->{budget_spent} ) {
107         $budget->{budget_spent} = 0;
108     }
109     if ( !defined $budget->{budget_ordered} ) {
110         $budget->{budget_ordered} = 0;
111     }
112     $budget->{'budget_avail'} =
113       $budget->{'budget_amount'} - ( $budget->{'budget_spent'} + $budget->{'budget_ordered'} );
114
115     $total      += $budget->{'budget_amount'};
116     $totspent   += $budget->{'budget_spent'};
117     $totordered += $budget->{'budget_ordered'};
118     $totavail   += $budget->{'budget_avail'};
119
120     for my $field (qw( budget_amount budget_spent budget_ordered budget_avail ) ) {
121         $budget->{$field} = $num_formatter->format_price( $budget->{$field} );
122     }
123 }
124
125 $template->param(
126
127     type          => 'intranet',
128     loop_budget   => $budget_arr,
129     branchname    => $branchname,
130     total         => $num_formatter->format_price($total),
131     totspent      => $num_formatter->format_price($totspent),
132     totordered    => $num_formatter->format_price($totordered),
133     totcomtd      => $num_formatter->format_price($totcomtd),
134     totavail      => $num_formatter->format_price($totavail),
135 );
136
137 output_html_with_http_headers $query, $cookie, $template->output;