View | Details | Raw Unified | Return to bug 18736
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-7 / +8 lines)
Lines 95-100 BEGIN { Link Here
95
        &FillWithDefaultValues
95
        &FillWithDefaultValues
96
96
97
        &get_rounded_price
97
        &get_rounded_price
98
        &get_rounding_sql
98
    );
99
    );
99
}
100
}
100
101
Lines 1463-1470 sub ModReceiveOrder { Link Here
1463
        $dbh->do(q|
1464
        $dbh->do(q|
1464
            UPDATE aqorders
1465
            UPDATE aqorders
1465
            SET
1466
            SET
1466
                tax_value_on_ordering = quantity * | . _get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1467
                tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1467
                tax_value_on_receiving = quantity * | . _get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1468
                tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1468
            WHERE ordernumber = ?
1469
            WHERE ordernumber = ?
1469
        |, undef, $order->{ordernumber});
1470
        |, undef, $order->{ordernumber});
1470
1471
Lines 1647-1654 sub CancelReceipt { Link Here
1647
        $dbh->do(q|
1648
        $dbh->do(q|
1648
            UPDATE aqorders
1649
            UPDATE aqorders
1649
            SET
1650
            SET
1650
                tax_value_on_ordering = quantity * | . _get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1651
                tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1651
                tax_value_on_receiving = quantity * | . _get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1652
                tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1652
            WHERE ordernumber = ?
1653
            WHERE ordernumber = ?
1653
        |, undef, $parent_ordernumber);
1654
        |, undef, $parent_ordernumber);
1654
1655
Lines 2000-2014 sub TransferOrder { Link Here
2000
    return $newordernumber;
2001
    return $newordernumber;
2001
}
2002
}
2002
2003
2003
=head3 _get_rounding_sql
2004
=head3 get_rounding_sql
2004
2005
2005
    $rounding_sql = _get_rounding_sql("mysql_variable_to_round_string");
2006
    $rounding_sql = get_rounding_sql("mysql_variable_to_round_string");
2006
2007
2007
returns the correct SQL routine based on OrderPriceRounding system preference.
2008
returns the correct SQL routine based on OrderPriceRounding system preference.
2008
2009
2009
=cut
2010
=cut
2010
2011
2011
sub _get_rounding_sql {
2012
sub get_rounding_sql {
2012
    my ( $round_string ) = @_;
2013
    my ( $round_string ) = @_;
2013
    my $rounding_pref = C4::Context->preference('OrderPriceRounding');
2014
    my $rounding_pref = C4::Context->preference('OrderPriceRounding');
2014
    if ( $rounding_pref eq "nearest_cent"  ) { return ("CAST($round_string*100 AS UNSIGNED)/100"); }
2015
    if ( $rounding_pref eq "nearest_cent"  ) { return ("CAST($round_string*100 AS UNSIGNED)/100"); }
(-)a/C4/Budgets.pm (-24 / +6 lines)
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 211-217 sub GetBudgetsPlanCell { Link Here
211
    my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period
212
    my ( $cell, $period, $budget ) = @_; #FIXME we don't use $period
212
    my ($actual, $sth);
213
    my ($actual, $sth);
213
    my $dbh = C4::Context->dbh;
214
    my $dbh = C4::Context->dbh;
214
    my $roundsql = _get_rounding_sql(qq|ecost_tax_included|);
215
    my $roundsql = C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|);
215
    if ( $cell->{'authcat'} eq 'MONTHS' ) {
216
    if ( $cell->{'authcat'} eq 'MONTHS' ) {
216
        # get the actual amount
217
        # get the actual amount
217
        # FIXME we should consider quantity
218
        # FIXME we should consider quantity
Lines 336-342 sub GetBudgetSpent { Link Here
336
    # unitprice_tax_included should always been set here
337
    # unitprice_tax_included should always been set here
337
    # we should not need to retrieve ecost_tax_included
338
    # we should not need to retrieve ecost_tax_included
338
    my $sth = $dbh->prepare(qq|
339
    my $sth = $dbh->prepare(qq|
339
        SELECT SUM( | . _get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders
340
        SELECT SUM( | . C4::Acquisition::get_rounding_sql("COALESCE(unitprice_tax_included, ecost_tax_included)") . qq| * quantity ) AS sum FROM aqorders
340
            WHERE budget_id = ? AND
341
            WHERE budget_id = ? AND
341
            quantityreceived > 0 AND
342
            quantityreceived > 0 AND
342
            datecancellationprinted IS NULL
343
            datecancellationprinted IS NULL
Lines 367-373 sub GetBudgetOrdered { Link Here
367
	my ($budget_id) = @_;
368
	my ($budget_id) = @_;
368
	my $dbh = C4::Context->dbh;
369
	my $dbh = C4::Context->dbh;
369
	my $sth = $dbh->prepare(qq|
370
	my $sth = $dbh->prepare(qq|
370
        SELECT SUM(| . _get_rounding_sql(qq|ecost_tax_included|) . qq| *  quantity) AS sum FROM aqorders
371
        SELECT SUM(| . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . qq| *  quantity) AS sum FROM aqorders
371
            WHERE budget_id = ? AND
372
            WHERE budget_id = ? AND
372
            quantityreceived = 0 AND
373
            quantityreceived = 0 AND
373
            datecancellationprinted IS NULL
374
            datecancellationprinted IS NULL
Lines 561-574 sub GetBudgetHierarchy { Link Here
561
    # Get all the budgets totals in as few queries as possible
562
    # Get all the budgets totals in as few queries as possible
562
    my $hr_budget_spent = $dbh->selectall_hashref(q|
563
    my $hr_budget_spent = $dbh->selectall_hashref(q|
563
        SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
564
        SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
564
               SUM( | . _get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent
565
               SUM( | . C4::Acquisition::get_rounding_sql(qq|COALESCE(unitprice_tax_included, ecost_tax_included)|) . q| * quantity ) AS budget_spent
565
        FROM aqorders JOIN aqbudgets USING (budget_id)
566
        FROM aqorders JOIN aqbudgets USING (budget_id)
566
        WHERE quantityreceived > 0 AND datecancellationprinted IS NULL
567
        WHERE quantityreceived > 0 AND datecancellationprinted IS NULL
567
        GROUP BY budget_id, budget_parent_id
568
        GROUP BY budget_id, budget_parent_id
568
        |, 'budget_id');
569
        |, 'budget_id');
569
    my $hr_budget_ordered = $dbh->selectall_hashref(q|
570
    my $hr_budget_ordered = $dbh->selectall_hashref(q|
570
        SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
571
        SELECT aqorders.budget_id, aqbudgets.budget_parent_id,
571
               SUM( | . _get_rounding_sql(qq|ecost_tax_included|) . q| *  quantity) AS budget_ordered
572
               SUM( | . C4::Acquisition::get_rounding_sql(qq|ecost_tax_included|) . q| *  quantity) AS budget_ordered
572
        FROM aqorders JOIN aqbudgets USING (budget_id)
573
        FROM aqorders JOIN aqbudgets USING (budget_id)
573
        WHERE quantityreceived = 0 AND datecancellationprinted IS NULL
574
        WHERE quantityreceived = 0 AND datecancellationprinted IS NULL
574
        GROUP BY budget_id, budget_parent_id
575
        GROUP BY budget_id, budget_parent_id
Lines 1349-1373 sub MoveOrders { Link Here
1349
    return \@report;
1350
    return \@report;
1350
}
1351
}
1351
1352
1352
=head1 INTERNAL FUNCTIONS
1353
1354
=cut
1355
1356
=head3 _get_rounding_sql
1357
1358
    $rounding_sql = _get_rounding_sql("mysql_variable_to_round_string");
1359
1360
returns the correct SQL routine based on OrderPriceRounding system preference.
1361
1362
=cut
1363
1364
sub _get_rounding_sql {
1365
    my $to_round = shift;
1366
    my $rounding_pref = C4::Context->preference('OrderPriceRounding');
1367
    if   ($rounding_pref eq 'nearest_cent') { return "CAST($to_round*100 AS UNSIGNED)/100"; }
1368
    else { return "$to_round"; }
1369
}
1370
1371
END { }    # module clean-up code here (global destructor)
1353
END { }    # module clean-up code here (global destructor)
1372
1354
1373
1;
1355
1;
(-)a/t/Acquisition.t (-4 / +3 lines)
Lines 23-38 use t::lib::Mocks; Link Here
23
23
24
use_ok( 'C4::Acquisition' );
24
use_ok( 'C4::Acquisition' );
25
25
26
subtest 'Tests for _get_rounding_sql' => sub {
26
subtest 'Tests for get_rounding_sql' => sub {
27
27
28
    plan tests => 2;
28
    plan tests => 2;
29
29
30
    my $value = '3.141592';
30
    my $value = '3.141592';
31
31
32
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} );
32
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{} );
33
    my $no_rounding_result = C4::Acquisition::_get_rounding_sql($value);
33
    my $no_rounding_result = C4::Acquisition::get_rounding_sql($value);
34
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} );
34
    t::lib::Mocks::mock_preference( 'OrderPriceRounding', q{nearest_cent} );
35
    my $rounding_result = C4::Acquisition::_get_rounding_sql($value);
35
    my $rounding_result = C4::Acquisition::get_rounding_sql($value);
36
36
37
    ok( $no_rounding_result eq $value, "Value ($value) not to be rounded" );
37
    ok( $no_rounding_result eq $value, "Value ($value) not to be rounded" );
38
    ok( $rounding_result =~ /CAST/,    "Value ($value) will be rounded" );
38
    ok( $rounding_result =~ /CAST/,    "Value ($value) will be rounded" );
39
- 

Return to bug 18736