Bug 929 : Followup fixing date formatting
[koha.git] / acqui / spent.pl
bloba50b7aef44c5255a66fb7c1b8114b64dde59f161
1 #!/usr/bin/perl
3 # script to show a breakdown of committed and spent budgets
5 # Copyright 2002-2009 Katipo Communications Limited
6 # Copyright 2010,2011 Catalyst IT Limited
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 =head1 NAME
24 spent.pl
26 =head1 DESCRIPTION
28 this script is designed to show the spent amount in budges
30 =cut
32 use C4::Context;
33 use C4::Auth;
34 use C4::Output;
35 use C4::Dates;
36 use strict;
37 use warnings;
38 use CGI;
40 my $dbh = C4::Context->dbh;
41 my $input = new CGI;
42 my $bookfund = $input->param('fund');
43 my $start = $input->param('start');
44 my $end = $input->param('end');
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
48 template_name => "acqui/spent.tt",
49 query => $input,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => { acquisition => 1 },
53 debug => 1,
57 my $query = <<EOQ;
58 SELECT
59 aqorders.basketno, aqorders.ordernumber,
60 quantity-quantityreceived AS tleft,
61 ecost, budgetdate, entrydate,
62 aqbasket.booksellerid,
63 itype,
64 title,
65 aqorders.booksellerinvoicenumber,
66 quantityreceived,
67 unitprice,
68 freight,
69 datereceived,
70 aqorders.biblionumber
71 FROM (aqorders, aqbasket)
72 LEFT JOIN items ON
73 items.biblioitemnumber=aqorders.biblioitemnumber
74 LEFT JOIN biblio ON
75 biblio.biblionumber=aqorders.biblionumber
76 LEFT JOIN aqorders_items ON
77 aqorders.ordernumber=aqorders_items.ordernumber
78 WHERE
79 aqorders.basketno=aqbasket.basketno AND
80 budget_id=? AND
81 (datecancellationprinted IS NULL OR
82 datecancellationprinted='0000-00-00')
83 GROUP BY aqorders.ordernumber
84 EOQ
85 my $sth = $dbh->prepare($query);
86 $sth->execute($bookfund);
87 if ( $sth->err ) {
88 die "An error occurred fetching records: " . $sth->errstr;
90 my $total = 0;
91 my $toggle;
92 my @spent;
93 while ( my $data = $sth->fetchrow_hashref ) {
94 my $recv = $data->{'quantityreceived'};
95 if ( $recv > 0 ) {
96 my $subtotal = $recv * ( $data->{'unitprice'} + $data->{'freight'} );
97 $data->{'subtotal'} = sprintf( "%.2f", $subtotal );
98 $data->{'freight'} = sprintf( "%.2f", $data->{'freight'} );
99 $data->{'unitprice'} = sprintf( "%.2f", $data->{'unitprice'} );
100 $total += $subtotal;
101 push @spent, $data;
105 $total = sprintf( "%.2f", $total );
107 $template->{VARS}->{'fund'} = $bookfund;
108 $template->{VARS}->{'spent'} = \@spent;
109 $template->{VARS}->{'total'} = $total;
110 $sth->finish;
112 output_html_with_http_headers $input, $cookie, $template->output;