&FillWithDefaultValues
&get_rounded_price
+ &get_rounding_sql
);
}
$dbh->do(q|
UPDATE aqorders
SET
- tax_value_on_ordering = quantity * | . _get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
- tax_value_on_receiving = quantity * | . _get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
+ tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
+ tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
WHERE ordernumber = ?
|, undef, $order->{ordernumber});
$dbh->do(q|
UPDATE aqorders
SET
- tax_value_on_ordering = quantity * | . _get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
- tax_value_on_receiving = quantity * | . _get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
+ tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
+ tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
WHERE ordernumber = ?
|, undef, $parent_ordernumber);
return $newordernumber;
}
-=head3 _get_rounding_sql
+=head3 get_rounding_sql
- $rounding_sql = _get_rounding_sql("mysql_variable_to_round_string");
+ $rounding_sql = get_rounding_sql("mysql_variable_to_round_string");
returns the correct SQL routine based on OrderPriceRounding system preference.
=cut
-sub _get_rounding_sql {
+sub get_rounding_sql {
my ( $round_string ) = @_;
my $rounding_pref = C4::Context->preference('OrderPriceRounding');
if ( $rounding_pref eq "nearest_cent" ) { return ("CAST($round_string*100 AS UNSIGNED)/100"); }
use Koha::Patrons;
use Koha::Acquisition::Invoice::Adjustments;
use C4::Debug;
+use C4::Acquisition;
use vars qw(@ISA @EXPORT);
BEGIN {
my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period
my ($actual, $sth);
my $dbh = C4::Context->dbh;
- my $roundsql = _get_rounding_sql(qq|ecost_tax_included|);
+ my $roundsql = C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|);
if ( $cell->{'authcat'} eq 'MONTHS' ) {
# get the actual amount
# FIXME we should consider quantity
# unitprice_tax_included should always been set here
# we should not need to retrieve ecost_tax_included
my $sth = $dbh->prepare(qq|
- SELECT SUM( | . _get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders
+ SELECT SUM( | . C4::Acquisition::get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders
WHERE budget_id = ? AND
quantityreceived > 0 AND
datecancellationprinted IS NULL
my ($budget_id) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(qq|
- SELECT SUM(| . _get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders
+ SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| * quantity) AS sum FROM aqorders
WHERE budget_id = ? AND
quantityreceived = 0 AND
datecancellationprinted IS NULL
# Get all the budgets totals in as few queries as possible
my $hr_budget_spent = $dbh->selectall_hashref(q|
SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
- SUM( | . _get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent
+ SUM( | . C4::Acquisition::get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent
FROM aqorders JOIN aqbudgets USING (budget_id)
WHERE quantityreceived > 0 AND datecancellationprinted IS NULL
GROUP BY budget_id, budget_parent_id
|, 'budget_id');
my $hr_budget_ordered = $dbh->selectall_hashref(q|
SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
- SUM( | . _get_rounding_sql(qq|ecost_tax_included|) . q| * quantity) AS budget_ordered
+ SUM( | . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . q| * quantity) AS budget_ordered
FROM aqorders JOIN aqbudgets USING (budget_id)
WHERE quantityreceived = 0 AND datecancellationprinted IS NULL
GROUP BY budget_id, budget_parent_id
return \@report;
}
-=head1 INTERNAL FUNCTIONS
-
-=cut
-
-=head3 _get_rounding_sql
-
- $rounding_sql = _get_rounding_sql("mysql_variable_to_round_string");
-
-returns the correct SQL routine based on OrderPriceRounding system preference.
-
-=cut
-
-sub _get_rounding_sql {
- my $to_round = shift;
- my $rounding_pref = C4::Context->preference('OrderPriceRounding');
- if ($rounding_pref eq 'nearest_cent') { return "CAST($to_round*100 AS UNSIGNED)/100"; }
- else { return "$to_round"; }
-}
-
END { } # module clean-up code here (global destructor)
1;
use_ok( 'C4::Acquisition' );
-subtest 'Tests for _get_rounding_sql' => sub {
+subtest 'Tests for get_rounding_sql' => sub {
plan tests => 2;
my $value = '3.141592';
t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} );
- my $no_rounding_result = C4::Acquisition::_get_rounding_sql($value);
+ my $no_rounding_result = C4::Acquisition::get_rounding_sql($value);
t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} );
- my $rounding_result = C4::Acquisition::_get_rounding_sql($value);
+ my $rounding_result = C4::Acquisition::get_rounding_sql($value);
ok( $no_rounding_result eq $value, "Value ($value) not to be rounded" );
ok( $rounding_result =~ /CAST/, "Value ($value) will be rounded" );