3 # script to show a breakdown of committed and spent budgets
5 # needs to be templated at some point
13 my $dbh = C4::Context->dbh;
15 my $bookfund = $input->param('bookfund');
16 my $start = $input->param('start');
17 my $end = $input->param('end');
19 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
21 template_name => "acqui/spent.tmpl",
25 flagsrequired => { acquisition => 1 },
30 #James Winter 3/4/2009: Original query does not select spent rows
31 # correctly due to missing joins between tables
34 "SELECT quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived
35 as qrev,subscription,title,aqorders.biblionumber,aqorders.booksellerinvoicenumber,
36 quantity-quantityreceived as tleft,
38 as ordnum,entrydate,budgetdate,aqbasket.booksellerid,aqbasket.basketno
40 LEFT JOIN aqorderbreakdown USING (ordernumber)
41 LEFT JOIN aqbasket USING (basketno)
42 LEFT JOIN aqbudget USING (bookfundid)
44 AND (datecancellationprinted IS NULL OR datecancellationprinted = '0000-00-00')
45 AND closedate BETWEEN startdate AND enddate
46 AND creationdate > startdate
49 my $sth = $dbh->prepare($query);
50 $sth->execute( $bookfund);
55 while ( my $data = $sth->fetchrow_hashref ) {
56 my $recv = $data->{'qrev'};
58 my $subtotal = $recv * $data->{'unitprice'};
59 $data->{'subtotal'} = $subtotal;
60 $data->{'unitprice'} += 0;
68 $data->{'toggle'} = $toggle;
69 push @spent_loop, $data;
75 SPENTLOOP => \@spent_loop,
81 output_html_with_http_headers $input, $cookie, $template->output;