perltidy before next commit.
[koha.git] / acqui / bookfund.pl
1 #!/usr/bin/perl -w
2
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.                                                                  
11 #                                                                           
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. 
15 #                                                                             
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 
19
20 use C4::Context;
21 use strict;
22 use CGI;
23 use C4::Auth;
24 use C4::Interface::CGI::Output;
25
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');
31
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33     {
34         template_name   => "acqui/bookfund.tmpl",
35         query           => $input,
36         type            => "intranet",
37         authnotrequired => 0,
38         flagsrequired   => { acquisition => 1 },
39         debug           => 1,
40     }
41 );
42
43 my $query =
44 "Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived                                      
45 as qrev,subscription,title,itemtype,aqorders.biblionumber,aqorders.booksellerinvoicenumber,                                 
46 quantity-quantityreceived as tleft,aqorders.ordernumber                                                                                                        
47 as ordnum,entrydate,budgetdate,booksellerid,aqbasket.basketno                                                               
48 from aqorders,aqorderbreakdown,aqbasket                                                                                     
49 left join biblioitems on  biblioitems.biblioitemnumber=aqorders.biblioitemnumber
50 where bookfundid=? and aqorders.ordernumber=aqorderbreakdown.ordernumber and
51 aqorders.basketno=aqbasket.basketno and (budgetdate >= ? and budgetdate < ?)
52 and (datecancellationprinted is NULL or datecancellationprinted='0000-00-00')
53 ";
54 warn $query;
55 my $sth = $dbh->prepare($query);
56 $sth->execute( $bookfund, $start, $end );
57 my @commited_loop;
58
59 my $total = 0;
60 while ( my $data = $sth->fetchrow_hashref ) {
61     my $left = $data->{'tleft'};
62     if ( !$left || $left eq '' ) {
63         $left = $data->{'quantity'};
64     }
65     if ( $left && $left > 0 ) {
66         my $subtotal = $left * $data->{'ecost'};
67         $data->{subtotal} = $subtotal;
68         $data->{'left'} = $left;
69         push @commited_loop, $data;
70         $total += $subtotal;
71     }
72 }
73
74 $template->param(
75     COMMITEDLOOP => \@commited_loop,
76     total        => $total
77 );
78 $sth->finish;
79 $dbh->disconnect;
80
81 output_html_with_http_headers $input, $cookie, $template->output;