Bug 21637: Fixed upercase letter in EasyAnalyticalRecords syspref
[koha.git] / acqui / ordered.pl
blob75291d9f5c5dcb159d7c2dc047159952b0c49e4a
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;
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.biblionumber, aqorders.basketno, aqorders.ordernumber,
56 quantity-quantityreceived AS tleft,
57 ecost_tax_included, budgetdate, entrydate,
58 aqbasket.booksellerid,
59 aqbooksellers.name as vendorname,
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 LEFT JOIN aqbooksellers ON
70 aqbasket.booksellerid = aqbooksellers.id
71 WHERE
72 aqorders.basketno=aqbasket.basketno AND
73 budget_id=? AND
74 (datecancellationprinted IS NULL OR
75 datecancellationprinted='0000-00-00') AND
76 (quantity > quantityreceived OR quantityreceived IS NULL)
77 GROUP BY aqorders.ordernumber
78 EOQ
80 my $sth = $dbh->prepare($query);
82 $sth->execute($fund_id);
83 if ( $sth->err ) {
84 die "Error occurred fetching records: " . $sth->errstr;
86 my @ordered;
88 my $total = 0;
89 while ( my $data = $sth->fetchrow_hashref ) {
90 my $left = $data->{'tleft'};
91 if ( !$left || $left eq '' ) {
92 $left = $data->{'quantity'};
94 if ( $left && $left > 0 ) {
95 my $subtotal = $left * $data->{'ecost_tax_included'};
96 $data->{subtotal} = sprintf( "%.2f", $subtotal );
97 $data->{'left'} = $left;
98 push @ordered, $data;
99 $total += $subtotal;
103 my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { join => 'invoiceid' } );
104 while ( my $adj = $adjustments->next ){
105 $total += $adj->adjustment;
108 $total = sprintf( "%.2f", $total );
110 $template->{VARS}->{'fund'} = $fund_id;
111 $template->{VARS}->{'ordered'} = \@ordered;
112 $template->{VARS}->{'total'} = $total;
113 $template->{VARS}->{'fund_code'} = $fund_code;
114 $template->{VARS}->{'adjustments'} = $adjustments;
116 $sth->finish;
118 output_html_with_http_headers $input, $cookie, $template->output;