Bug 10878: Correct Display856uAsImage pref description
[koha.git] / acqui / acqui-home.pl
blob8741aa485782b37f2af4789b05aaea46968284d6
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;
32 use CGI;
33 use C4::Auth;
34 use C4::Output;
35 use C4::Acquisition;
36 use C4::Budgets;
37 use C4::Members;
38 use C4::Branch;
39 use C4::Debug;
40 use C4::Suggestions;
42 my $query = CGI->new;
43 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
44 { template_name => 'acqui/acqui-home.tt',
45 query => $query,
46 type => 'intranet',
47 authnotrequired => 0,
48 flagsrequired => { acquisition => '*' },
49 debug => 1,
53 my $user = GetMember( 'borrowernumber' => $loggedinuser );
54 my $branchname = GetBranchName($user->{branchcode});
56 my $status = $query->param('status') || "ASKED";
57 my $suggestions_count = CountSuggestion($status);
59 my $budget_arr = GetBudgetHierarchy;
61 my $total = 0;
62 my $totspent = 0;
63 my $totordered = 0;
64 my $totcomtd = 0;
65 my $totavail = 0;
67 my $total_active = 0;
68 my $totspent_active = 0;
69 my $totordered_active = 0;
70 my $totavail_active = 0;
72 my @budget_loop;
73 foreach my $budget ( @{$budget_arr} ) {
74 next unless (CanUserUseBudget($loggedinuser, $budget, $userflags));
76 $budget->{'budget_branchname'} =
77 GetBranchName( $budget->{'budget_branchcode'} );
79 my $member = GetMember( borrowernumber => $budget->{budget_owner_id} );
80 if ($member) {
81 $budget->{budget_owner_firstname} = $member->{'firstname'};
82 $budget->{budget_owner_surname} = $member->{'surname'};
83 $budget->{budget_owner_borrowernumber} = $member->{'borrowernumber'};
86 if ( !defined $budget->{budget_amount} ) {
87 $budget->{budget_amount} = 0;
90 $budget->{'budget_ordered'} = GetBudgetOrdered( $budget->{'budget_id'} );
91 $budget->{'budget_spent'} = GetBudgetSpent( $budget->{'budget_id'} );
92 if ( !defined $budget->{budget_spent} ) {
93 $budget->{budget_spent} = 0;
95 if ( !defined $budget->{budget_ordered} ) {
96 $budget->{budget_ordered} = 0;
98 $budget->{'budget_avail'} =
99 $budget->{'budget_amount'} - ( $budget->{'budget_spent'} + $budget->{'budget_ordered'} );
101 $total += $budget->{'budget_amount'};
102 $totspent += $budget->{'budget_spent'};
103 $totordered += $budget->{'budget_ordered'};
104 $totavail += $budget->{'budget_avail'};
106 if ($budget->{budget_period_active}){
107 $total_active += $budget->{'budget_amount'};
108 $totspent_active += $budget->{'budget_spent'};
109 $totordered_active += $budget->{'budget_ordered'};
110 $totavail_active += $budget->{'budget_avail'};
113 push @budget_loop, $budget;
116 $template->param(
117 type => 'intranet',
118 loop_budget => \@budget_loop,
119 branchname => $branchname,
120 total => $total,
121 totspent => $totspent,
122 totordered => $totordered,
123 totcomtd => $totcomtd,
124 totavail => $totavail,
125 total_active => $total_active,
126 totspent_active => $totspent_active,
127 totordered_active => $totordered_active,
128 totavail_active => $totavail_active,
129 suggestions_count => $suggestions_count,
132 output_html_with_http_headers $query, $cookie, $template->output;