Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#102 Calculate %done in Projects

closed-accepted
nobody
None
5
2005-09-27
2005-08-09
Oscar
No

Hi All,

In the Projects module, the %done was not properly
calculated. A project is even never started as long as
no tasks are finished.

The function below is a replacement of
percentcomplete() in projects_func.inc.php.
It uses the actual hours spent on tasks, even if it's
more than planned, and tasks don't need to be closed
for the calculation.

You can also copy the attached file over the existing one.

Hope this helps others as well,
Oscar

function percentcomplete($id) {
global $conn;
// This function takes a project id and and
compares the todo hours
// to the finished hours to make a percent done

$Qopenpl = 'SELECT SUM(hours) as openpl '
. 'FROM mgw_projects_tasks '
. 'WHERE project_id=' . (int)$id . ' '
. 'AND status=1 '
. 'AND usedhours <= hours';
$Qopenot = 'SELECT SUM(usedhours) as openot '
. 'FROM mgw_projects_tasks '
. 'WHERE project_id=' . (int)$id . ' '
. 'AND status=1 '
. 'AND usedhours > hours';
$Qopendn = 'SELECT SUM(usedhours) as opendn '
. 'FROM mgw_projects_tasks '
. 'WHERE project_id=' . (int)$id . ' '
. 'AND status=1 ';
$Qclospl = 'SELECT SUM(hours) as clospl '
. 'FROM mgw_projects_tasks '
. 'WHERE project_id=' . (int)$id . ' '
. 'AND status=0';

// Open tasks
$Qopen_planned = $conn->GetOne($Qopenpl); // On
schedule
$Qopen_overtime = $conn->GetOne($Qopenot); //
Used more than planned so far
$Qopen_done = $conn->GetOne($Qopendn); //
Time spent
// Closed tasks
$Qclosed_planned = $conn->GetOne($Qclospl); // On
schedule
$Qclosed_done = $Qclosed_planned; //
Ignore overtime

$todo = $Qopen_planned + $Qopen_overtime +
$Qclosed_planned;
$done = $Qopen_done + $Qclosed_done;

if (($Qopen_planned + $Qopen_overtime) == 0) {
return 100; // No open tasks; done!
}
elseif ($done > 0) {
$PercDone = (($done / $todo) * 100);
if ($PercDone >= 100) {
return 95; // Used more than planned but not yet done
}
else {
return sprintf("%2d", $PercDone);
}
}
else {
return 0;
}
}

Discussion

  • Oscar
    Oscar
    2005-08-09

    Updated projects_func.inc.php

     
    Attachments
  • Logged In: YES
    user_id=109671

    Your patch has been accepted and added to CVS.

    Check out CVS or fetch a CVS snapshot to see the new code.

    --
    more.groupware developer team

     
    • status: open --> closed-accepted