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>.
26 this script is to show orders ordered but not yet received
35 use Koha::Acquisition::Invoice::Adjustments;
38 my $dbh = C4::Context->dbh;
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",
48 flagsrequired => { acquisition => '*' },
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 GROUP_CONCAT(DISTINCT itype SEPARATOR '|') AS itypes,
63 JOIN aqbasket USING (basketno)
65 biblio.biblionumber=aqorders.biblionumber
66 LEFT JOIN aqorders_items ON
67 aqorders.ordernumber=aqorders_items.ordernumber
69 items.itemnumber=aqorders_items.itemnumber
70 LEFT JOIN aqbooksellers ON
71 aqbasket.booksellerid = aqbooksellers.id
74 datecancellationprinted IS NULL AND
75 (quantity > quantityreceived OR quantityreceived IS NULL)
76 GROUP BY aqorders.biblionumber, aqorders.basketno, aqorders.ordernumber,
78 ecost_tax_included, budgetdate, entrydate,
79 aqbasket.booksellerid,
84 my $sth = $dbh->prepare($query);
86 $sth->execute($fund_id);
88 die "Error occurred fetching records: " . $sth->errstr;
93 while ( my $data = $sth->fetchrow_hashref ) {
94 $data->{'itemtypes'} = [split('\|', $data->{itypes})];
95 my $left = $data->{'tleft'};
96 if ( !$left || $left eq '' ) {
97 $left = $data->{'quantity'};
99 if ( $left && $left > 0 ) {
100 my $subtotal = $left * get_rounded_price( $data->{'ecost_tax_included'} );
101 $data->{subtotal} = sprintf( "%.2f", $subtotal );
102 $data->{'left'} = $left;
103 push @ordered, $data;
108 my $adjustments = Koha::Acquisition::Invoice::Adjustments->search({budget_id => $fund_id, closedate => undef, encumber_open => 1 }, { prefetch => 'invoiceid' } );
109 while ( my $adj = $adjustments->next ){
110 $total += $adj->adjustment;
113 $total = sprintf( "%.2f", $total );
115 $template->{VARS}->{'fund'} = $fund_id;
116 $template->{VARS}->{'ordered'} = \@ordered;
117 $template->{VARS}->{'total'} = $total;
118 $template->{VARS}->{'fund_code'} = $fund_code;
119 $template->{VARS}->{'adjustments'} = $adjustments;
123 output_html_with_http_headers $input, $cookie, $template->output;