Bug 14898: Add button at manual invoice to redirect to pay tab
[koha.git] / acqui / acqui-home.pl
blob9c70773f8f9774d5442b01c0626756c95c15f284
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
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 =head1 NAME
21 acqui-home.pl
23 =head1 DESCRIPTION
25 this script is the main page for acqui
27 =cut
29 use Modern::Perl;
31 use CGI qw ( -utf8 );
32 use C4::Auth;
33 use C4::Output;
34 use C4::Acquisition;
35 use C4::Budgets;
36 use C4::Members;
37 use C4::Debug;
38 use C4::Suggestions;
39 use Koha::Acquisition::Currencies;
40 use Koha::Patrons;
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 $status = $query->param('status') || "ASKED";
54 my $suggestions_count = CountSuggestion($status);
56 my $budget_arr = GetBudgetHierarchy;
58 my $total = 0;
59 my $totspent = 0;
60 my $totordered = 0;
61 my $totcomtd = 0;
62 my $totavail = 0;
64 my $total_active = 0;
65 my $totspent_active = 0;
66 my $totordered_active = 0;
67 my $totavail_active = 0;
69 my @budget_loop;
70 foreach my $budget ( @{$budget_arr} ) {
71 next unless (CanUserUseBudget($loggedinuser, $budget, $userflags));
73 my $patron = Koha::Patrons->find( $budget->{budget_owner_id} );
74 if ( $patron ) {
75 $budget->{budget_owner} = $patron;
78 if ( !defined $budget->{budget_amount} ) {
79 $budget->{budget_amount} = 0;
81 if ( !defined $budget->{budget_spent} ) {
82 $budget->{budget_spent} = 0;
84 if ( !defined $budget->{budget_ordered} ) {
85 $budget->{budget_ordered} = 0;
87 $budget->{'budget_avail'} =
88 $budget->{'budget_amount'} - ( $budget->{'budget_spent'} + $budget->{'budget_ordered'} );
90 $total += $budget->{'budget_amount'};
91 $totspent += $budget->{'budget_spent'};
92 $totordered += $budget->{'budget_ordered'};
93 $totavail += $budget->{'budget_avail'};
95 if ($budget->{budget_period_active}){
96 $total_active += $budget->{'budget_amount'};
97 $totspent_active += $budget->{'budget_spent'};
98 $totordered_active += $budget->{'budget_ordered'};
99 $totavail_active += $budget->{'budget_avail'};
102 push @budget_loop, $budget;
105 $template->param(
106 type => 'intranet',
107 loop_budget => \@budget_loop,
108 total => $total,
109 totspent => $totspent,
110 totordered => $totordered,
111 totcomtd => $totcomtd,
112 totavail => $totavail,
113 total_active => $total_active,
114 totspent_active => $totspent_active,
115 totordered_active => $totordered_active,
116 totavail_active => $totavail_active,
117 suggestions_count => $suggestions_count,
120 my $cur = Koha::Acquisition::Currencies->get_active;
121 if ( $cur ) {
122 $template->param(
123 currency => $cur->currency,
127 output_html_with_http_headers $query, $cookie, $template->output;