Bug 7476 Remove executable bit from files that probably should not be executed
[koha.git] / acqui / ordered.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008 - 2009 BibLibre SARL
4 # Copyright 2010,2011 Catalyst IT Limited
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 =head1 NAME
21
22 ordered.pl
23
24 =head1 DESCRIPTION
25
26 this script is to show orders ordered but not yet received
27
28 =cut
29
30 use C4::Context;
31 use strict;
32 use warnings;
33 use CGI;
34 use C4::Auth;
35 use C4::Output;
36 use C4::Dates;
37
38 my $dbh     = C4::Context->dbh;
39 my $input   = new CGI;
40 my $fund_id = $input->param('fund');
41 my $fund_code = $input->param('fund_code');
42
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44     {
45         template_name   => "acqui/ordered.tt",
46         query           => $input,
47         type            => "intranet",
48         authnotrequired => 0,
49         flagsrequired   => { acquisition => 1 },
50         debug           => 1,
51     }
52 );
53
54 my $query = <<EOQ;
55 SELECT
56     aqorders.basketno, aqorders.ordernumber,
57     quantity-quantityreceived AS tleft,
58     ecost, budgetdate, entrydate,
59     aqbasket.booksellerid,
60     itype,
61     title
62 FROM (aqorders, aqbasket)
63 LEFT JOIN biblio ON
64     biblio.biblionumber=aqorders.biblionumber
65 LEFT JOIN aqorders_items ON
66     aqorders.ordernumber=aqorders_items.ordernumber
67 LEFT JOIN items ON
68     items.itemnumber=aqorders_items.itemnumber
69 WHERE
70     aqorders.basketno=aqbasket.basketno AND
71     budget_id=? AND
72     (datecancellationprinted IS NULL OR
73         datecancellationprinted='0000-00-00') AND
74     (quantity > quantityreceived OR quantityreceived IS NULL)
75     GROUP BY aqorders.ordernumber
76 EOQ
77
78 my $sth = $dbh->prepare($query);
79
80 $sth->execute($fund_id);
81 if ( $sth->err ) {
82     die "Error occurred fetching records: " . $sth->errstr;
83 }
84 my @ordered;
85
86 my $total = 0;
87 while ( my $data = $sth->fetchrow_hashref ) {
88     my $left = $data->{'tleft'};
89     if ( !$left || $left eq '' ) {
90         $left = $data->{'quantity'};
91     }
92     if ( $left && $left > 0 ) {
93         my $subtotal = $left * $data->{'ecost'};
94         $data->{subtotal} = sprintf( "%.2f", $subtotal );
95         $data->{'left'} = $left;
96         push @ordered, $data;
97         $total += $subtotal;
98     }
99 }
100 $total = sprintf( "%.2f", $total );
101
102 $template->{VARS}->{'fund'}    = $fund_id;
103 $template->{VARS}->{'ordered'} = \@ordered;
104 $template->{VARS}->{'total'}   = $total;
105 $template->{VARS}->{'fund_code'} = $fund_code;
106
107 $sth->finish;
108
109 output_html_with_http_headers $input, $cookie, $template->output;