Skip to content

Commit

Permalink
Fixed bug #13
Browse files Browse the repository at this point in the history
The estimate total now use the accounted value if its absolute value is
larger than the estimate's absolute value, using the math bellow:

```
fixed_estimate = (ABS(accounted) > ABS(estimated)
                    AND accounted > 0 == estimated > 0)?
                 accounted: estimated;
```

It gives more robustness for the evaluation, as the estimate accumulated
over the mounths becoming quickly useless.
  • Loading branch information
talesm committed Feb 9, 2015
1 parent 6a4abdf commit 0c57d3b
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions OrcamentoMainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,19 +321,31 @@ void OrcamentoMainFrame::RefreshStatusBar()
return;
}
try{
auto query= "SELECT "
" budget.name,"
" SUM(estimate.amount)/100.0,"
" SUM(execution_estimate.amount)/100.0,"
" (SUM(execution_estimate.amount) - SUM(estimate.amount))/100.0"
" FROM budget"
" JOIN estimate USING(budget_id)"
" LEFT JOIN (SELECT "
" IFNULL(SUM(execution.amount), 0) AS amount,"
" estimate_id"
" FROM execution GROUP BY estimate_id"
" ) execution_estimate USING(estimate_id)"
" WHERE budget_id = ?1"
auto query = R"==(
SELECT
budget.name,
SUM(fixed_estimate.estimated)/100.0,
SUM(fixed_estimate.accounted)/100.0,
(SUM(fixed_estimate.accounted) - SUM(fixed_estimate.estimated))/100.0
FROM budget
JOIN (
SELECT
CASE WHEN ABS(execution_estimate.amount) > ABS(estimate.amount)
THEN
execution_estimate.amount
ELSE
estimate.amount
END AS estimated,
execution_estimate.amount AS accounted, budget_id
FROM estimate
LEFT JOIN (
SELECT
IFNULL(SUM(execution.amount), 0) AS amount, estimate_id
FROM execution GROUP BY estimate_id
) AS execution_estimate USING(estimate_id)
) AS fixed_estimate USING(budget_id)
WHERE budget_id = ?1
)=="
;
SQLite::Statement stm(*_database, query);
stm.bind(1, budget_id);
Expand Down

0 comments on commit 0c57d3b

Please sign in to comment.