Lines 211-221
sub GetBudgetsPlanCell {
Link Here
|
211 |
my ( $cell, $period, $budget ) = @_; |
211 |
my ( $cell, $period, $budget ) = @_; |
212 |
my ($actual, $sth); |
212 |
my ($actual, $sth); |
213 |
my $dbh = C4::Context->dbh; |
213 |
my $dbh = C4::Context->dbh; |
|
|
214 |
my $roundsql = _get_rounding_sql(qq|ecost_tax_included|); |
214 |
if ( $cell->{'authcat'} eq 'MONTHS' ) { |
215 |
if ( $cell->{'authcat'} eq 'MONTHS' ) { |
215 |
# get the actual amount |
216 |
# get the actual amount |
216 |
$sth = $dbh->prepare( qq| |
217 |
$sth = $dbh->prepare( qq| |
217 |
|
218 |
|
218 |
SELECT SUM(ecost_tax_included) AS actual FROM aqorders |
219 |
SELECT SUM(| . $roundsql . qq|) AS actual FROM aqorders |
219 |
WHERE budget_id = ? AND |
220 |
WHERE budget_id = ? AND |
220 |
entrydate like "$cell->{'authvalue'}%" | |
221 |
entrydate like "$cell->{'authvalue'}%" | |
221 |
); |
222 |
); |
Lines 224-230
sub GetBudgetsPlanCell {
Link Here
|
224 |
# get the actual amount |
225 |
# get the actual amount |
225 |
$sth = $dbh->prepare( qq| |
226 |
$sth = $dbh->prepare( qq| |
226 |
|
227 |
|
227 |
SELECT SUM(ecost_tax_included) FROM aqorders |
228 |
SELECT SUM(| . $roundsql . qq|) FROM aqorders |
228 |
LEFT JOIN aqorders_items |
229 |
LEFT JOIN aqorders_items |
229 |
ON (aqorders.ordernumber = aqorders_items.ordernumber) |
230 |
ON (aqorders.ordernumber = aqorders_items.ordernumber) |
230 |
LEFT JOIN items |
231 |
LEFT JOIN items |
Lines 236-242
sub GetBudgetsPlanCell {
Link Here
|
236 |
# get the actual amount |
237 |
# get the actual amount |
237 |
$sth = $dbh->prepare( qq| |
238 |
$sth = $dbh->prepare( qq| |
238 |
|
239 |
|
239 |
SELECT SUM( ecost_tax_included * quantity) AS actual |
240 |
SELECT SUM( | . $roundsql . qq| * quantity) AS actual |
240 |
FROM aqorders JOIN biblioitems |
241 |
FROM aqorders JOIN biblioitems |
241 |
ON (biblioitems.biblionumber = aqorders.biblionumber ) |
242 |
ON (biblioitems.biblionumber = aqorders.biblionumber ) |
242 |
WHERE aqorders.budget_id = ? and itemtype = ? | |
243 |
WHERE aqorders.budget_id = ? and itemtype = ? | |
Lines 249-255
sub GetBudgetsPlanCell {
Link Here
|
249 |
# get the actual amount |
250 |
# get the actual amount |
250 |
$sth = $dbh->prepare( qq| |
251 |
$sth = $dbh->prepare( qq| |
251 |
|
252 |
|
252 |
SELECT SUM(ecost_tax_included * quantity) AS actual |
253 |
SELECT SUM(| . $roundsql . qq| * quantity) AS actual |
253 |
FROM aqorders |
254 |
FROM aqorders |
254 |
JOIN aqbudgets ON (aqbudgets.budget_id = aqorders.budget_id ) |
255 |
JOIN aqbudgets ON (aqbudgets.budget_id = aqorders.budget_id ) |
255 |
WHERE aqorders.budget_id = ? AND |
256 |
WHERE aqorders.budget_id = ? AND |
Lines 333-339
sub GetBudgetSpent {
Link Here
|
333 |
# unitprice_tax_included should always been set here |
334 |
# unitprice_tax_included should always been set here |
334 |
# we should not need to retrieve ecost_tax_included |
335 |
# we should not need to retrieve ecost_tax_included |
335 |
my $sth = $dbh->prepare(qq| |
336 |
my $sth = $dbh->prepare(qq| |
336 |
SELECT SUM( COALESCE(unitprice_tax_included, ecost_tax_included) * quantity ) AS sum FROM aqorders |
337 |
SELECT SUM( | . _get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders |
337 |
WHERE budget_id = ? AND |
338 |
WHERE budget_id = ? AND |
338 |
quantityreceived > 0 AND |
339 |
quantityreceived > 0 AND |
339 |
datecancellationprinted IS NULL |
340 |
datecancellationprinted IS NULL |
Lines 364-370
sub GetBudgetOrdered {
Link Here
|
364 |
my ($budget_id) = @_; |
365 |
my ($budget_id) = @_; |
365 |
my $dbh = C4::Context->dbh; |
366 |
my $dbh = C4::Context->dbh; |
366 |
my $sth = $dbh->prepare(qq| |
367 |
my $sth = $dbh->prepare(qq| |
367 |
SELECT SUM(ecost_tax_included * quantity) AS sum FROM aqorders |
368 |
SELECT SUM(| . _get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders |
368 |
WHERE budget_id = ? AND |
369 |
WHERE budget_id = ? AND |
369 |
quantityreceived = 0 AND |
370 |
quantityreceived = 0 AND |
370 |
datecancellationprinted IS NULL |
371 |
datecancellationprinted IS NULL |
Lines 1346-1351
sub MoveOrders {
Link Here
|
1346 |
return \@report; |
1347 |
return \@report; |
1347 |
} |
1348 |
} |
1348 |
|
1349 |
|
|
|
1350 |
=head1 INTERNAL FUNCTIONS |
1351 |
|
1352 |
=cut |
1353 |
|
1354 |
=head3 _get_rounding_sql |
1355 |
|
1356 |
$rounding_sql = _get_rounding_sql("mysql_variable_to_round_string"); |
1357 |
|
1358 |
returns the correct SQL routine based on OrderPriceRounding system preference. |
1359 |
|
1360 |
=cut |
1361 |
|
1362 |
sub _get_rounding_sql { |
1363 |
my $to_round = shift; |
1364 |
my $rounding_pref = C4::Context->preference('OrderPriceRounding'); |
1365 |
if ($rounding_pref eq 'nearest_cent') { return "CAST($to_round*100 AS INTEGER)/100"; } |
1366 |
else { return "$to_round"; } |
1367 |
} |
1368 |
|
1349 |
END { } # module clean-up code here (global destructor) |
1369 |
END { } # module clean-up code here (global destructor) |
1350 |
|
1370 |
|
1351 |
1; |
1371 |
1; |