Bug 23403: Fix whitespace
[koha.git] / acqui / ordered.pl
blob8f095302dd31f4ad145c39f55e2820522133a775
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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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 Modern::Perl;
32 use CGI qw ( -utf8 );
33 use C4::Auth;
34 use C4::Output;
35 use Koha::Acquisition::Invoice::Adjustments;
36 use C4::Acquisition;
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');
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45 template_name => "acqui/ordered.tt",
46 query => $input,
47 type => "intranet",
48 authnotrequired => 0,
49 flagsrequired => { acquisition => '*' },
50 debug => 1,
54 my $query = <<EOQ;
55 SELECT
56 aqorders.biblionumber, aqorders.basketno, aqorders.ordernumber,
57 quantity-quantityreceived AS tleft,
58 ecost_tax_included, budgetdate, entrydate,
59 aqbasket.booksellerid,
60 aqbooksellers.name as vendorname,
61 GROUP_CONCAT(DISTINCT itype SEPARATOR '|') AS itypes,
62 title
63 FROM aqorders
64 JOIN aqbasket USING (basketno)
65 LEFT JOIN biblio ON
66 biblio.biblionumber=aqorders.biblionumber
67 LEFT JOIN aqorders_items ON
68 aqorders.ordernumber=aqorders_items.ordernumber
69 LEFT JOIN items ON
70 items.itemnumber=aqorders_items.itemnumber
71 LEFT JOIN aqbooksellers ON
72 aqbasket.booksellerid = aqbooksellers.id
73 WHERE
74 budget_id=? AND
75 (datecancellationprinted IS NULL OR
76 datecancellationprinted='0000-00-00') AND
77 (quantity > quantityreceived OR quantityreceived IS NULL)
78 GROUP BY aqorders.biblionumber, aqorders.basketno, aqorders.ordernumber,
79 tleft,
80 ecost_tax_included, budgetdate, entrydate,
81 aqbasket.booksellerid,
82 aqbooksellers.name,
83 title
84 EOQ
86 my $sth = $dbh->prepare($query);
88 $sth->execute($fund_id);
89 if ( $sth->err ) {
90 die "Error occurred fetching records: " . $sth->errstr;
92 my @ordered;
94 my $total = 0;
95 while ( my $data = $sth->fetchrow_hashref ) {
96 $data->{'itemtypes'} = [split('\|', $data->{itypes})];
97 my $left = $data->{'tleft'};
98 if ( !$left || $left eq '' ) {
99 $left = $data->{'quantity'};
101 if ( $left && $left > 0 ) {
102 my $subtotal = $left * get_rounded_price( $data->{'ecost_tax_included'} );
103 $data->{subtotal} = sprintf( "%.2f", $subtotal );
104 $data->{'left'} = $left;
105 push @ordered, $data;
106 $total += $subtotal;
110 my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { prefetch => 'invoiceid' } );
111 while ( my $adj = $adjustments->next ){
112 $total += $adj->adjustment;
115 $total = sprintf( "%.2f", $total );
117 $template->{VARS}->{'fund'} = $fund_id;
118 $template->{VARS}->{'ordered'} = \@ordered;
119 $template->{VARS}->{'total'} = $total;
120 $template->{VARS}->{'fund_code'} = $fund_code;
121 $template->{VARS}->{'adjustments'} = $adjustments;
123 $sth->finish;
125 output_html_with_http_headers $input, $cookie, $template->output;