added 440* and 490* 'series' indexes
[koha.git] / acqui / bookfund.pl
blob76e14fe7b75de1f7b4d1449ebcd34b3e729189d0
1 #!/usr/bin/perl
3 # Copyright 2006 Katipo Communications
4 #
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.
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 use C4::Context;
21 use strict;
22 use CGI;
23 use C4::Auth;
24 use C4::Output;
26 my $dbh = C4::Context->dbh;
27 my $input = new CGI;
28 my $bookfund = $input->param('bookfund');
29 my $start = $input->param('start');
30 my $end = $input->param('end');
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 template_name => "acqui/bookfund.tmpl",
35 query => $input,
36 type => "intranet",
37 authnotrequired => 0,
38 flagsrequired => { acquisition => 1 },
39 debug => 1,
43 my $query = '
44 SELECT quantity,
45 datereceived,
46 freight,
47 unitprice,
48 listprice,
49 ecost,
50 quantityreceived AS qrev,
51 subscription,
52 title,
53 itemtype,
54 aqorders.biblionumber,
55 aqorders.booksellerinvoicenumber,
56 quantity-quantityreceived AS tleft,
57 aqorders.ordernumber AS ordnum,
58 entrydate,
59 budgetdate,
60 booksellerid,
61 aqbasket.basketno
62 FROM aqorders
63 INNER JOIN aqorderbreakdown
64 ON aqorderbreakdown.ordernumber = aqorders.ordernumber
65 INNER JOIN aqbasket
66 ON aqbasket.basketno = aqorders.basketno
67 LEFT JOIN biblioitems
68 ON biblioitems.biblioitemnumber = aqorders.biblioitemnumber
69 WHERE bookfundid = ?
70 AND budgetdate >= ?
71 AND budgetdate < ?
72 AND (datecancellationprinted IS NULL
73 OR datecancellationprinted = \'0000-00-00\')
75 my $sth = $dbh->prepare($query);
76 $sth->execute( $bookfund, $start, $end );
77 my @commited_loop;
79 my $total = 0;
80 while ( my $data = $sth->fetchrow_hashref ) {
81 my $left = $data->{'tleft'};
82 if ( !$left || $left eq '' ) {
83 $left = $data->{'quantity'};
85 if ( $left && $left > 0 ) {
86 my $subtotal = $left * $data->{'ecost'};
87 $data->{subtotal} = $subtotal;
88 $data->{'left'} = $left;
89 push @commited_loop, $data;
90 $total += $subtotal;
94 $template->param(
95 COMMITEDLOOP => \@commited_loop,
96 total => $total
98 $sth->finish;
99 $dbh->disconnect;
101 output_html_with_http_headers $input, $cookie, $template->output;