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 1474-1481 sub ModReceiveOrder { Link Here
1474
        $dbh->do(q|
1475
        $dbh->do(q|
1475
            UPDATE aqorders
1476
            UPDATE aqorders
1476
            SET
1477
            SET
1477
                tax_value_on_ordering = quantity * | . _get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1478
                tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1478
                tax_value_on_receiving = quantity * | . _get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1479
                tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1479
            WHERE ordernumber = ?
1480
            WHERE ordernumber = ?
1480
        |, undef, $order->{ordernumber});
1481
        |, undef, $order->{ordernumber});
1481
1482
Lines 1658-1665 sub CancelReceipt { Link Here
1658
        $dbh->do(q|
1659
        $dbh->do(q|
1659
            UPDATE aqorders
1660
            UPDATE aqorders
1660
            SET
1661
            SET
1661
                tax_value_on_ordering = quantity * | . _get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1662
                tax_value_on_ordering = quantity * | . get_rounding_sql(q|ecost_tax_excluded|) . q| * tax_rate_on_ordering,
1662
                tax_value_on_receiving = quantity * | . _get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1663
                tax_value_on_receiving = quantity * | . get_rounding_sql(q|unitprice_tax_excluded|) . q| * tax_rate_on_receiving
1663
            WHERE ordernumber = ?
1664
            WHERE ordernumber = ?
1664
        |, undef, $parent_ordernumber);
1665
        |, undef, $parent_ordernumber);
1665
1666
Lines 2010-2024 sub TransferOrder { Link Here
2010
    return $newordernumber;
2011
    return $newordernumber;
2011
}
2012
}
2012
2013
2013
=head3 _get_rounding_sql
2014
=head3 get_rounding_sql
2014
2015
2015
    $rounding_sql = _get_rounding_sql("mysql_variable_to_round_string");
2016
    $rounding_sql = get_rounding_sql("mysql_variable_to_round_string");
2016
2017
2017
returns the correct SQL routine based on OrderPriceRounding system preference.
2018
returns the correct SQL routine based on OrderPriceRounding system preference.
2018
2019
2019
=cut
2020
=cut
2020
2021
2021
sub _get_rounding_sql {
2022
sub get_rounding_sql {
2022
    my ( $round_string ) = @_;
2023
    my ( $round_string ) = @_;
2023
    my $rounding_pref = C4::Context->preference('OrderPriceRounding');
2024
    my $rounding_pref = C4::Context->preference('OrderPriceRounding');
2024
    if ( $rounding_pref eq "nearest_cent"  ) { return ("CAST($round_string*100 AS UNSIGNED)/100"); }
2025
    if ( $rounding_pref eq "nearest_cent"  ) { return ("CAST($round_string*100 AS UNSIGNED)/100"); }
(-)a/C4/Budgets.pm (-25 / +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 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;
1369
- 

Return to bug 18736