Bug 22789: Set non_priority column as boolean in schema
[koha-ffzg.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
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.
10 #
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.
15 #
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>.
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 Modern::Perl;
30
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 Koha::Acquisition::Currencies;
39 use Koha::Patrons;
40 use Koha::Suggestions;
41
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,
50     }
51 );
52
53 my $status           = $query->param('status') || "ASKED";
54 # Get current branch count and total viewable count, if they don't match then pass
55 # both to template
56 if( C4::Context->only_my_library ){
57     my $local_pendingsuggestions_count = Koha::Suggestions->search({ status => "ASKED", branchcode => C4::Context->userenv()->{'branch'} })->count();
58     $template->param( suggestions_count => $local_pendingsuggestions_count );
59 } else {
60     my $pendingsuggestions = Koha::Suggestions->search({ status => "ASKED" });
61     my $local_pendingsuggestions_count = $pendingsuggestions->search({ 'me.branchcode' => C4::Context->userenv()->{'branch'} })->count();
62     my $pendingsuggestions_count = $pendingsuggestions->count();
63     $template->param(
64         all_pendingsuggestions => $pendingsuggestions_count != $local_pendingsuggestions_count ? $pendingsuggestions_count : 0,
65         suggestions_count => $local_pendingsuggestions_count
66     );
67 }
68
69 my $budget_arr = GetBudgetHierarchy;
70
71 my $total      = 0;
72 my $totspent   = 0;
73 my $totordered = 0;
74 my $totcomtd   = 0;
75 my $totavail   = 0;
76
77 my $total_active        = 0;
78 my $totspent_active     = 0;
79 my $totordered_active   = 0;
80 my $totavail_active     = 0;
81
82 my @budget_loop;
83 foreach my $budget ( @{$budget_arr} ) {
84     next unless (CanUserUseBudget($loggedinuser, $budget, $userflags));
85
86     my $patron = Koha::Patrons->find( $budget->{budget_owner_id} );
87     if ( $patron ) {
88         $budget->{budget_owner} = $patron;
89     }
90
91     if ( !defined $budget->{budget_amount} ) {
92         $budget->{budget_amount} = 0;
93     }
94     if ( !defined $budget->{budget_spent} ) {
95         $budget->{budget_spent} = 0;
96     }
97     if ( !defined $budget->{budget_ordered} ) {
98         $budget->{budget_ordered} = 0;
99     }
100     $budget->{'budget_avail'} =
101       $budget->{'budget_amount'} - ( $budget->{'budget_spent'} + $budget->{'budget_ordered'} );
102
103     $total      += $budget->{'budget_amount'};
104     $totspent   += $budget->{'budget_spent'};
105     $totordered += $budget->{'budget_ordered'};
106     $totavail   += $budget->{'budget_avail'};
107
108     if ($budget->{budget_period_active}){
109         $total_active      += $budget->{'budget_amount'};
110         $totspent_active   += $budget->{'budget_spent'};
111         $totordered_active += $budget->{'budget_ordered'};
112         $totavail_active   += $budget->{'budget_avail'};    
113     }
114
115     push @budget_loop, $budget;
116 }
117
118 $template->param(
119     type          => 'intranet',
120     loop_budget   => \@budget_loop,
121     total         => $total,
122     totspent      => $totspent,
123     totordered    => $totordered,
124     totcomtd      => $totcomtd,
125     totavail      => $totavail,
126     total_active  => $total_active,
127     totspent_active     => $totspent_active,
128     totordered_active   => $totordered_active,
129     totavail_active     => $totavail_active,
130 );
131
132 my $cur = Koha::Acquisition::Currencies->get_active;
133 if ( $cur ) {
134     $template->param(
135         currency => $cur->currency,
136     );
137 }
138
139 output_html_with_http_headers $query, $cookie, $template->output;