Lines 24-29
use Koha::Database;
Link Here
|
24 |
use Koha::Patrons; |
24 |
use Koha::Patrons; |
25 |
use Koha::Acquisition::Invoice::Adjustments; |
25 |
use Koha::Acquisition::Invoice::Adjustments; |
26 |
use C4::Debug; |
26 |
use C4::Debug; |
|
|
27 |
use C4::Acquisition; |
27 |
use vars qw(@ISA @EXPORT); |
28 |
use vars qw(@ISA @EXPORT); |
28 |
|
29 |
|
29 |
BEGIN { |
30 |
BEGIN { |
Lines 210-216
sub GetBudgetsPlanCell {
Link Here
|
210 |
my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period |
211 |
my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period |
211 |
my ($actual, $sth); |
212 |
my ($actual, $sth); |
212 |
my $dbh = C4::Context->dbh; |
213 |
my $dbh = C4::Context->dbh; |
213 |
my $roundsql = _get_rounding_sql(qq|ecost_tax_included|); |
214 |
my $roundsql = C4::Acquisition::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 |
# FIXME we should consider quantity |
217 |
# FIXME we should consider quantity |
Lines 335-341
sub GetBudgetSpent {
Link Here
|
335 |
# unitprice_tax_included should always been set here |
336 |
# unitprice_tax_included should always been set here |
336 |
# we should not need to retrieve ecost_tax_included |
337 |
# we should not need to retrieve ecost_tax_included |
337 |
my $sth = $dbh->prepare(qq| |
338 |
my $sth = $dbh->prepare(qq| |
338 |
SELECT SUM( | . _get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders |
339 |
SELECT SUM( | . C4::Acquisition::get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders |
339 |
WHERE budget_id = ? AND |
340 |
WHERE budget_id = ? AND |
340 |
quantityreceived > 0 AND |
341 |
quantityreceived > 0 AND |
341 |
datecancellationprinted IS NULL |
342 |
datecancellationprinted IS NULL |
Lines 366-372
sub GetBudgetOrdered {
Link Here
|
366 |
my ($budget_id) = @_; |
367 |
my ($budget_id) = @_; |
367 |
my $dbh = C4::Context->dbh; |
368 |
my $dbh = C4::Context->dbh; |
368 |
my $sth = $dbh->prepare(qq| |
369 |
my $sth = $dbh->prepare(qq| |
369 |
SELECT SUM(| . _get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders |
370 |
SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders |
370 |
WHERE budget_id = ? AND |
371 |
WHERE budget_id = ? AND |
371 |
quantityreceived = 0 AND |
372 |
quantityreceived = 0 AND |
372 |
datecancellationprinted IS NULL |
373 |
datecancellationprinted IS NULL |
Lines 560-573
sub GetBudgetHierarchy {
Link Here
|
560 |
# Get all the budgets totals in as few queries as possible |
561 |
# Get all the budgets totals in as few queries as possible |
561 |
my $hr_budget_spent = $dbh->selectall_hashref(q| |
562 |
my $hr_budget_spent = $dbh->selectall_hashref(q| |
562 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
563 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
563 |
SUM( | . _get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent |
564 |
SUM( | . C4::Acquisition::get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent |
564 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
565 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
565 |
WHERE quantityreceived > 0 AND datecancellationprinted IS NULL |
566 |
WHERE quantityreceived > 0 AND datecancellationprinted IS NULL |
566 |
GROUP BY budget_id |
567 |
GROUP BY budget_id |
567 |
|, 'budget_id'); |
568 |
|, 'budget_id'); |
568 |
my $hr_budget_ordered = $dbh->selectall_hashref(q| |
569 |
my $hr_budget_ordered = $dbh->selectall_hashref(q| |
569 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
570 |
SELECT aqorders.budget_id, aqbudgets.budget_parent_id, |
570 |
SUM( | . _get_rounding_sql(qq|ecost_tax_included|) . q| * quantity) AS budget_ordered |
571 |
SUM( | . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . q| * quantity) AS budget_ordered |
571 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
572 |
FROM aqorders JOIN aqbudgets USING (budget_id) |
572 |
WHERE quantityreceived = 0 AND datecancellationprinted IS NULL |
573 |
WHERE quantityreceived = 0 AND datecancellationprinted IS NULL |
573 |
GROUP BY budget_id |
574 |
GROUP BY budget_id |
Lines 1344-1368
sub MoveOrders {
Link Here
|
1344 |
return \@report; |
1345 |
return \@report; |
1345 |
} |
1346 |
} |
1346 |
|
1347 |
|
1347 |
=head1 INTERNAL FUNCTIONS |
|
|
1348 |
|
1349 |
=cut |
1350 |
|
1351 |
=head3 _get_rounding_sql |
1352 |
|
1353 |
$rounding_sql = _get_rounding_sql("mysql_variable_to_round_string"); |
1354 |
|
1355 |
returns the correct SQL routine based on OrderPriceRounding system preference. |
1356 |
|
1357 |
=cut |
1358 |
|
1359 |
sub _get_rounding_sql { |
1360 |
my $to_round = shift; |
1361 |
my $rounding_pref = C4::Context->preference('OrderPriceRounding'); |
1362 |
if ($rounding_pref eq 'nearest_cent') { return "CAST($to_round*100 AS UNSIGNED)/100"; } |
1363 |
else { return "$to_round"; } |
1364 |
} |
1365 |
|
1366 |
END { } # module clean-up code here (global destructor) |
1348 |
END { } # module clean-up code here (global destructor) |
1367 |
|
1349 |
|
1368 |
1; |
1350 |
1; |