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
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 this script is designed to show the spent amount in budgets
38 use Koha
::Acquisition
::Invoice
::Adjustments
;
40 my $dbh = C4
::Context
->dbh;
42 my $bookfund = $input->param('fund');
43 my $fund_code = $input->param('fund_code');
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
47 template_name
=> "acqui/spent.tt",
51 flagsrequired
=> { acquisition
=> '*' },
58 aqorders.biblionumber, aqorders.basketno, aqorders.ordernumber,
59 quantity-quantityreceived AS tleft,
60 budgetdate, entrydate,
61 aqbasket.booksellerid,
62 GROUP_CONCAT(DISTINCT itype SEPARATOR '|') as itypes,
65 aqinvoices.invoicenumber,
67 unitprice_tax_included,
69 aqbooksellers.name as vendorname
70 FROM (aqorders, aqbasket)
72 biblio.biblionumber=aqorders.biblionumber
73 LEFT JOIN aqorders_items ON
74 aqorders.ordernumber = aqorders_items.ordernumber
76 aqorders_items.itemnumber = items.itemnumber
77 LEFT JOIN aqinvoices ON
78 aqorders.invoiceid = aqinvoices.invoiceid
79 LEFT JOIN aqbooksellers ON
80 aqbasket.booksellerid = aqbooksellers.id
82 aqorders.basketno=aqbasket.basketno AND
84 (datecancellationprinted IS NULL OR
85 datecancellationprinted='0000-00-00') AND
86 datereceived IS NOT NULL
87 GROUP BY aqorders.biblionumber, aqorders.basketno, aqorders.ordernumber,
89 budgetdate, entrydate,
90 aqbasket.booksellerid,
93 aqinvoices.invoicenumber,
95 unitprice_tax_included,
100 my $sth = $dbh->prepare($query);
101 $sth->execute($bookfund);
103 die "An error occurred fetching records: " . $sth->errstr;
107 while ( my $data = $sth->fetchrow_hashref ) {
108 my $recv = $data->{'quantityreceived'};
109 $data->{'itemtypes'} = [split('\|', $data->{itypes
})];
111 my $rowtotal = $recv * get_rounded_price
($data->{'unitprice_tax_included'});
112 $data->{'rowtotal'} = sprintf( "%.2f", $rowtotal );
113 $data->{'unitprice_tax_included'} = sprintf( "%.2f", $data->{'unitprice_tax_included'} );
114 $subtotal += $rowtotal;
120 my $total = $subtotal;
122 SELECT invoiceid
, invoicenumber
, shipmentcost
124 WHERE shipmentcost_budgetid
= ?
126 $sth = $dbh->prepare($query);
127 $sth->execute($bookfund);
129 while (my $data = $sth->fetchrow_hashref) {
130 push @shipmentcosts, {
131 shipmentcost
=> sprintf("%.2f", $data->{shipmentcost
}),
132 invoiceid
=> $data->{invoiceid
},
133 invoicenumber
=> $data->{invoicenumber
}
135 $total += $data->{shipmentcost
};
139 my $adjustments = Koha
::Acquisition
::Invoice
::Adjustments
->search({budget_id
=> $bookfund, closedate
=> { '!=' => undef } }, { prefetch
=> 'invoiceid' }, );
140 while ( my $adj = $adjustments->next ){
141 $total += $adj->adjustment;
144 $total = sprintf( "%.2f", $total );
149 subtotal
=> $subtotal,
150 shipmentcosts
=> \
@shipmentcosts,
151 adjustments
=> $adjustments,
153 fund_code
=> $fund_code
156 output_html_with_http_headers
$input, $cookie, $template->output;