modify bad field name
[koha.git] / serials / acqui-search.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Output;
7 use C4::Interface::CGI::Output;
8 use C4::Database;
9 use HTML::Template;
10 use C4::Acquisition;
11 my $query = new CGI;
12 my ($template, $loggedinuser, $cookie)
13     = get_template_and_user({template_name => "serials/acqui-search.tmpl",
14                              query => $query,
15                              type => "intranet",
16                              authnotrequired => 0,
17                              flagsrequired => {acquisition => 1},
18                              debug => 1,
19                              });
20
21 #FIXME : Is this page still used ????
22 # looks like no.
23
24 # budget
25 my $dbh = C4::Context->dbh;
26 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
27 $sthtemp->execute($loggedinuser);
28 my ($flags, $homebranch)=$sthtemp->fetchrow;
29 my ($count,@results)=bookfunds($homebranch);
30 my $classlist='';
31 my $total=0;
32 my $totspent=0;
33 my $totcomtd=0;
34 my $totavail=0;
35 my @loop_budget = ();
36 for (my $i=0;$i<$count;$i++){
37         my ($spent,$comtd)=bookfundbreakdown($results[$i]->{'bookfundid'});
38         my $avail=$results[$i]->{'budgetamount'}-($spent+$comtd);
39         my %line;
40         $line{bookfundname} = $results[$i]->{'bookfundname'};
41         $line{budgetamount} = $results[$i]->{'budgetamount'};
42         $line{spent} = sprintf  ("%.2f", $spent);
43         $line{comtd} = sprintf  ("%.2f",$comtd);
44         $line{avail}  = sprintf  ("%.2f",$avail);
45         push @loop_budget, \%line;
46         $total+=$results[$i]->{'budgetamount'};
47         $totspent+=$spent;
48         $totcomtd+=$comtd;
49         $totavail+=$avail;
50 }
51 #currencies
52 my ($count,$rates)=getcurrencies();
53 my @loop_currency = ();
54 for (my $i=0;$i<$count;$i++){
55         my %line;
56         $line{currency} = $rates->[$i]->{'currency'};
57         $line{rate} = $rates->[$i]->{'rate'};
58         push @loop_currency, \%line;
59 }
60 $template->param(classlist => $classlist,
61                                                 type => 'intranet',
62                                                 loop_budget => \@loop_budget,
63                                                 loop_currency => \@loop_currency,
64                                                 total => sprintf("%.2f",$total),
65                                                 totspent => sprintf("%.2f",$totspent),
66                                                 totcomtd => sprintf("%.2f",$totcomtd),
67                                                 totavail => sprintf("%.2f",$totavail));
68
69 output_html_with_http_headers $query, $cookie, $template->output;