Bug 7143 : Adding Stacey Walker to the history
[koha.git] / acqui / ordered.pl
blobcdf2cd75c300ecaad1ea4fffd0e70e74f51ea94c
1 #!/usr/bin/perl
3 # Copyright 2008 - 2009 BibLibre SARL
4 # Copyright 2010,2011 Catalyst IT Limited
5 # This file is part of Koha.
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.
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.
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.
20 =head1 NAME
22 ordered.pl
24 =head1 DESCRIPTION
26 this script is to show orders ordered but not yet received
28 =cut
30 use C4::Context;
31 use strict;
32 use warnings;
33 use CGI;
34 use C4::Auth;
35 use C4::Output;
37 my $dbh = C4::Context->dbh;
38 my $input = new CGI;
39 my $fund_id = $input->param('fund');
40 my $fund_code = $input->param('fund_code');
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44 template_name => "acqui/ordered.tt",
45 query => $input,
46 type => "intranet",
47 authnotrequired => 0,
48 flagsrequired => { acquisition => '*' },
49 debug => 1,
53 my $query = <<EOQ;
54 SELECT
55 aqorders.basketno, aqorders.ordernumber,
56 quantity-quantityreceived AS tleft,
57 ecost, budgetdate, entrydate,
58 aqbasket.booksellerid,
59 itype,
60 title
61 FROM (aqorders, aqbasket)
62 LEFT JOIN biblio ON
63 biblio.biblionumber=aqorders.biblionumber
64 LEFT JOIN aqorders_items ON
65 aqorders.ordernumber=aqorders_items.ordernumber
66 LEFT JOIN items ON
67 items.itemnumber=aqorders_items.itemnumber
68 WHERE
69 aqorders.basketno=aqbasket.basketno AND
70 budget_id=? AND
71 (datecancellationprinted IS NULL OR
72 datecancellationprinted='0000-00-00') AND
73 (quantity > quantityreceived OR quantityreceived IS NULL)
74 GROUP BY aqorders.ordernumber
75 EOQ
77 my $sth = $dbh->prepare($query);
79 $sth->execute($fund_id);
80 if ( $sth->err ) {
81 die "Error occurred fetching records: " . $sth->errstr;
83 my @ordered;
85 my $total = 0;
86 while ( my $data = $sth->fetchrow_hashref ) {
87 my $left = $data->{'tleft'};
88 if ( !$left || $left eq '' ) {
89 $left = $data->{'quantity'};
91 if ( $left && $left > 0 ) {
92 my $subtotal = $left * $data->{'ecost'};
93 $data->{subtotal} = sprintf( "%.2f", $subtotal );
94 $data->{'left'} = $left;
95 push @ordered, $data;
96 $total += $subtotal;
99 $total = sprintf( "%.2f", $total );
101 $template->{VARS}->{'fund'} = $fund_id;
102 $template->{VARS}->{'ordered'} = \@ordered;
103 $template->{VARS}->{'total'} = $total;
104 $template->{VARS}->{'fund_code'} = $fund_code;
106 $sth->finish;
108 output_html_with_http_headers $input, $cookie, $template->output;