bug 2848 [1/2]: Send notifications to patrons when hold is received
[koha.git] / acqui / acqui-home.pl
blobb8e6162f0a25495d46daf85c2de3408d4a24e46c
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
20 =head1 NAME
22 acqui-home.pl
24 =head1 DESCRIPTION
26 this script is the main page for acqui/
27 It presents the budget's dashboard, another table about differents currency with
28 their rates and the pending suggestions.
30 =head1 CGI PARAMETERS
32 =over 4
34 =item $status
35 C<$status> is the status a suggestion could has. Default value is 'ASKED'.
36 thus, it can be REJECTED, ACCEPTED, ORDERED, ASKED, AVAIBLE
38 =back
40 =cut
42 use strict;
43 use CGI;
44 use C4::Auth;
45 use C4::Output;
47 use C4::Suggestions;
49 use C4::Acquisition;
50 use C4::Bookfund;
51 use C4::Members;
53 my $query = new CGI;
54 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
56 template_name => "acqui/acqui-home.tmpl",
57 query => $query,
58 type => "intranet",
59 authnotrequired => 0,
60 flagsrequired => { acquisition => 1 },
61 debug => 1,
65 # budget
66 my $borrower= GetMember($loggedinuser);
67 my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
69 my @results = GetBookFunds($homebranch);
70 my $count = scalar @results;
72 my $classlist = '';
73 my $total = 0;
74 my $totspent = 0;
75 my $totcomtd = 0;
76 my $totavail = 0;
77 my @loop_budget = ();
79 for (my $i=0; $i<$count; $i++){
80 my ($spent,$comtd)=GetBookFundBreakdown($results[$i]->{'bookfundid'},$results[$i]->{'startdate'},$results[$i]->{'enddate'});
81 my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
82 my %line;
83 $line{bookfundname} = $results[$i]->{'bookfundname'};
84 $line{budgetamount} = $results[$i]->{'budgetamount'};
85 $line{aqbudgetid} = $results[$i]->{'aqbudgetid'};
86 $line{bookfundid} = $results[$i]->{'bookfundid'};
87 $line{sdate} = $results[$i]->{'startdate'};
88 $line{edate} = $results[$i]->{'enddate'};
89 $line{spent} = sprintf ("%.2f", $spent);
90 $line{comtd} = sprintf ("%.2f",$comtd);
91 $line{avail} = sprintf ("%.2f",$avail);
92 push @loop_budget, \%line;
93 $total+=$results[$i]->{'budgetamount'};
94 $totspent+=$spent;
95 $totcomtd+=$comtd;
96 $totavail+=$avail;
99 # currencies
100 my @rates = GetCurrencies();
101 $count = scalar @rates;
103 my @loop_currency = ();
104 for ( my $i = 0 ; $i < $count ; $i++ ) {
105 my %line;
106 $line{currency} = $rates[$i]->{'currency'};
107 $line{rate} = $rates[$i]->{'rate'};
108 push @loop_currency, \%line;
111 # suggestions
112 my $status = $query->param('status') || "ASKED";
113 my $suggestion = CountSuggestion($status);
114 my $suggestions_loop = &SearchSuggestion( '', '', '', '', $status, '' );
116 $template->param(
117 classlist => $classlist,
118 type => 'intranet',
119 loop_budget => \@loop_budget,
120 loop_currency => \@loop_currency,
121 total => sprintf( "%.2f", $total ),
122 suggestion => $suggestion,
123 suggestions_loop => $suggestions_loop,
124 totspent => sprintf( "%.2f", $totspent ),
125 totcomtd => sprintf( "%.2f", $totcomtd ),
126 totavail => sprintf( "%.2f", $totavail ),
127 nobudget => $#results == -1 ? 1 : 0
130 output_html_with_http_headers $query, $cookie, $template->output;