# -------------------------------------------------------------------
sub GetBudgetsPlanCell {
- my ( $cell, $period, $budget ) = @_;
+ 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|);
if ( $cell->{'authcat'} eq 'MONTHS' ) {
# get the actual amount
+ # FIXME we should consider quantity
$sth = $dbh->prepare( qq|
SELECT SUM(| . $roundsql . qq|) AS actual FROM aqorders
$sth->execute( $cell->{'budget_id'} );
} elsif ( $cell->{'authcat'} eq 'BRANCHES' ) {
# get the actual amount
+ # FIXME we should consider quantity
$sth = $dbh->prepare( qq|
SELECT SUM(| . $roundsql . qq|) FROM aqorders
# 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( COALESCE(unitprice_tax_included, ecost_tax_included) * quantity ) AS budget_spent
+ SUM( | . _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(ecost_tax_included * quantity) AS budget_ordered
+ SUM( | . _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