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>.
25 this script is the main page for acqui
32 use C4::Auth qw( get_template_and_user );
33 use C4::Output qw( output_html_with_http_headers );
34 use C4::Budgets qw( GetBudgetHierarchy GetBudget CanUserUseBudget );
36 use Koha::Acquisition::Currencies;
38 use Koha::Suggestions;
41 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
42 { template_name => 'acqui/acqui-home.tt',
45 flagsrequired => { acquisition => '*' },
49 my $status = $query->param('status') || "ASKED";
50 # Get current branch count and total viewable count, if they don't match then pass
52 if( C4::Context->only_my_library ){
53 my $local_pendingsuggestions_count = Koha::Suggestions->search({ status => "ASKED", branchcode => C4::Context->userenv()->{'branch'} })->count();
54 $template->param( suggestions_count => $local_pendingsuggestions_count );
56 my $pendingsuggestions = Koha::Suggestions->search({ status => "ASKED" });
57 my $local_pendingsuggestions_count = $pendingsuggestions->search({ 'me.branchcode' => C4::Context->userenv()->{'branch'} })->count();
58 my $pendingsuggestions_count = $pendingsuggestions->count();
60 all_pendingsuggestions => $pendingsuggestions_count != $local_pendingsuggestions_count ? $pendingsuggestions_count : 0,
61 suggestions_count => $local_pendingsuggestions_count
65 my $budget_arr = GetBudgetHierarchy;
74 my $totspent_active = 0;
75 my $totordered_active = 0;
76 my $totavail_active = 0;
79 my %patrons = ( $loggedinuser => Koha::Patrons->find($loggedinuser) );
80 my $loggedinpatron = $patrons{$loggedinuser}->unblessed;
81 foreach my $budget ( @{$budget_arr} ) {
82 next unless (CanUserUseBudget($loggedinpatron, $budget, $userflags));
84 if ( my $borrowernumber = $budget->{budget_owner_id} ) {
85 unless ( exists $patrons{$borrowernumber} ) {
86 $patrons{$borrowernumber} = Koha::Patrons->find($borrowernumber);
88 $budget->{budget_owner} = $patrons{$borrowernumber};
91 if ( !defined $budget->{budget_amount} ) {
92 $budget->{budget_amount} = 0;
94 if ( !defined $budget->{budget_spent} ) {
95 $budget->{budget_spent} = 0;
97 if ( !defined $budget->{budget_ordered} ) {
98 $budget->{budget_ordered} = 0;
100 $budget->{'budget_avail'} =
101 $budget->{'budget_amount'} - ( $budget->{'budget_spent'} + $budget->{'budget_ordered'} );
102 $budget->{'total_avail'} =
103 $budget->{'budget_amount'} - ( $budget->{'total_spent'} + $budget->{'total_ordered'} );
105 $total += $budget->{'budget_amount'};
106 $totspent += $budget->{'budget_spent'};
107 $totordered += $budget->{'budget_ordered'};
108 $totavail += $budget->{'budget_avail'};
110 if ($budget->{budget_period_active}){
111 $total_active += $budget->{'budget_amount'};
112 $totspent_active += $budget->{'budget_spent'};
113 $totordered_active += $budget->{'budget_ordered'};
114 $totavail_active += $budget->{'budget_avail'};
117 push @budget_loop, $budget;
122 loop_budget => \@budget_loop,
124 totspent => $totspent,
125 totordered => $totordered,
126 totcomtd => $totcomtd,
127 totavail => $totavail,
128 total_active => $total_active,
129 totspent_active => $totspent_active,
130 totordered_active => $totordered_active,
131 totavail_active => $totavail_active,
134 my $cur = Koha::Acquisition::Currencies->get_active;
137 currency => $cur->currency,
141 output_html_with_http_headers $query, $cookie, $template->output;