From cd8247954caa6105aeb9b1899d0667e0c8cbcfde Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Wed, 27 Jul 2022 13:31:48 +0800 Subject: [PATCH 1/3] * Fix bug#25004. --- module/product/model.php | 5 ++-- module/program/model.php | 5 ++-- module/project/model.php | 41 +++++++++++++++++++++++++++++++ module/project/view/view.html.php | 2 +- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/module/product/model.php b/module/product/model.php index 2f8350ac1d..083154e73f 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -1271,13 +1271,14 @@ class productModel extends model } /* Compute totalReal and progress. */ - foreach($hours as $hour) + $this->loadModel('project'); + foreach($hours as $projectID => $hour) { $hour->totalEstimate = round($hour->totalEstimate, 1) ; $hour->totalConsumed = round($hour->totalConsumed, 1); $hour->totalLeft = round($hour->totalLeft, 1); $hour->totalReal = $hour->totalConsumed + $hour->totalLeft; - $hour->progress = $hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0; + $hour->progress = $projects[$projectID]->model == 'waterfall' ? $this->project->getWaterfallProgress($projectID) : ($hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0); } /* Get the number of project teams. */ diff --git a/module/program/model.php b/module/program/model.php index 47b702d040..a9f376915e 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1434,13 +1434,14 @@ class programModel extends model } /* Compute totalReal and progress. */ - foreach($hours as $hour) + $this->loadModel('project'); + foreach($hours as $projectID => $hour) { $hour->totalEstimate = round($hour->totalEstimate, 1) ; $hour->totalConsumed = round($hour->totalConsumed, 1); $hour->totalLeft = round($hour->totalLeft, 1); $hour->totalReal = $hour->totalConsumed + $hour->totalLeft; - $hour->progress = $hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0; + $hour->progress = $projects[$projectID]->model == 'waterfall' ? $this->project->getWaterfallProgress($projectID) : ($hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0); } /* Get the number of left tasks. */ diff --git a/module/project/model.php b/module/project/model.php index 3e815f6808..9b52db5478 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -393,6 +393,47 @@ class projectModel extends model ->fetchAll('project'); } + /** + * Get waterfall project progress. + * + * @param int $projectID + * @access public + * @return int + */ + public function getWaterfallProgress($projectID) + { + $executions = $this->loadModel('execution')->getByProject($projectID); + + $totalHour = $this->dao->select('execution, ROUND(SUM(`left`), 2) AS totalLeft, ROUND(SUM(consumed), 1) AS totalConsumed')->from(TABLE_TASK) + ->where('execution')->in(array_keys($executions)) + ->andWhere('deleted')->eq(0) + ->andWhere('parent')->lt(1) + ->groupBy('execution') + ->fetchAll('execution'); + + $closedTotalLeft = $this->dao->select('execution, ROUND(SUM(`left`), 2) AS totalLeft')->from(TABLE_TASK) + ->where('execution')->in(array_keys($executions)) + ->andWhere('deleted')->eq(0) + ->andWhere('parent')->lt(1) + ->andWhere('status')->in('closed,cancel') + ->groupBy('execution') + ->fetchPairs('execution'); + + $progress = 0; + foreach($executions as $executionID => $execution) + { + $executionClosedLeft = isset($closedTotalLeft[$executionID]) ? $closedTotalLeft[$executionID] : 0; + $executionTotalConsumed = isset($totalHour[$executionID]) ? $totalHour[$executionID]->totalConsumed : 0; + $executionTotalLeft = isset($totalHour[$executionID]) ? round($totalHour[$executionID]->totalLeft - $executionClosedLeft, 1) : 0; + + $executionProgress = ($executionTotalConsumed + $executionTotalLeft) ? floor($executionTotalConsumed / ($executionTotalConsumed + $executionTotalLeft) * 1000) / 1000 * 100 : 0; + + $progress += $executionProgress * ($execution->percent / 100); + } + + return $progress; + } + /** * Get project workhour info. * diff --git a/module/project/view/view.html.php b/module/project/view/view.html.php index 28b98330fa..2ae7484bee 100644 --- a/module/project/view/view.html.php +++ b/module/project/view/view.html.php @@ -195,7 +195,7 @@ - totalConsumed + $workhour->totalLeft) ? floor($workhour->totalConsumed / ($workhour->totalConsumed + $workhour->totalLeft) * 1000) / 1000 * 100 : 0;?> + model == 'waterfall' ? $this->project->getWaterfallProgress($project->id) : (($workhour->totalConsumed + $workhour->totalLeft) ? floor($workhour->totalConsumed / ($workhour->totalConsumed + $workhour->totalLeft) * 1000) / 1000 * 100 : 0);?> project->progress;?> percent;?>  
From 0ec68feb10f5877634e169266f10bd7061b38da2 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Wed, 27 Jul 2022 21:38:28 +0800 Subject: [PATCH 2/3] * Fix bug#25004. --- module/product/model.php | 4 +- module/product/view/project.html.php | 4 +- module/program/model.php | 4 +- module/project/model.php | 56 +++++++++++++++------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/module/product/model.php b/module/product/model.php index 083154e73f..43e1d0f115 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -1271,14 +1271,14 @@ class productModel extends model } /* Compute totalReal and progress. */ - $this->loadModel('project'); + $progressList = $this->loadModel('project')->getWaterfallProgress(array_keys($hours)); foreach($hours as $projectID => $hour) { $hour->totalEstimate = round($hour->totalEstimate, 1) ; $hour->totalConsumed = round($hour->totalConsumed, 1); $hour->totalLeft = round($hour->totalLeft, 1); $hour->totalReal = $hour->totalConsumed + $hour->totalLeft; - $hour->progress = $projects[$projectID]->model == 'waterfall' ? $this->project->getWaterfallProgress($projectID) : ($hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0); + $hour->progress = $projects[$projectID]->model == 'waterfall' ? $progressList[$projectID] : ($hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0); } /* Get the number of project teams. */ diff --git a/module/product/view/project.html.php b/module/product/view/project.html.php index 32cb6a14d9..2037c8943c 100644 --- a/module/product/view/project.html.php +++ b/module/product/view/project.html.php @@ -96,8 +96,8 @@ hours->totalEstimate . $lang->execution->workHourUnit;?> hours->totalConsumed . $lang->execution->workHourUnit;?> -
-
hours->progress;?>
+
+
hours->progress);?>
diff --git a/module/program/model.php b/module/program/model.php index a9f376915e..64cce62d4a 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1434,14 +1434,14 @@ class programModel extends model } /* Compute totalReal and progress. */ - $this->loadModel('project'); + $progressList = $this->loadModel('project')->getWaterfallProgress(array_keys($hours)); foreach($hours as $projectID => $hour) { $hour->totalEstimate = round($hour->totalEstimate, 1) ; $hour->totalConsumed = round($hour->totalConsumed, 1); $hour->totalLeft = round($hour->totalLeft, 1); $hour->totalReal = $hour->totalConsumed + $hour->totalLeft; - $hour->progress = $projects[$projectID]->model == 'waterfall' ? $this->project->getWaterfallProgress($projectID) : ($hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0); + $hour->progress = $projects[$projectID]->model == 'waterfall' ? $progressList[$projectID] : ($hour->totalReal ? round($hour->totalConsumed / $hour->totalReal, 2) * 100 : 0); } /* Get the number of left tasks. */ diff --git a/module/project/model.php b/module/project/model.php index 9b52db5478..9505afc7f1 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -396,42 +396,48 @@ class projectModel extends model /** * Get waterfall project progress. * - * @param int $projectID + * @param array $projectIDList * @access public * @return int */ - public function getWaterfallProgress($projectID) + public function getWaterfallProgress($projectIDList) { - $executions = $this->loadModel('execution')->getByProject($projectID); + $projectList = $this->dao->select('t1.*')->from(TABLE_EXECUTION)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id') + ->where('t1.type')->in('stage') + ->andWhere('t1.deleted')->eq('0') + ->andWhere('t1.vision')->eq($this->config->vision) + ->andWhere('t1.project')->in($projectIDList) + ->andWhere('t2.model')->eq('waterfall') + ->fetchGroup('project', 'id'); - $totalHour = $this->dao->select('execution, ROUND(SUM(`left`), 2) AS totalLeft, ROUND(SUM(consumed), 1) AS totalConsumed')->from(TABLE_TASK) - ->where('execution')->in(array_keys($executions)) - ->andWhere('deleted')->eq(0) - ->andWhere('parent')->lt(1) - ->groupBy('execution') - ->fetchAll('execution'); + $totalHour = $this->dao->select('t1.project, t1.execution, ROUND(SUM(if(t1.status !="closed" && t1.status !="cancel", `left`, 0)), 2) AS totalLeft, ROUND(SUM(consumed), 1) AS totalConsumed')->from(TABLE_TASK)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution = t2.id') + ->where('t2.project')->in(array_keys($projectList)) + ->andWhere('t1.deleted')->eq(0) + ->andWhere('t1.parent')->lt(1) + ->groupBy('t1.execution') + ->fetchGroup('project', 'execution'); - $closedTotalLeft = $this->dao->select('execution, ROUND(SUM(`left`), 2) AS totalLeft')->from(TABLE_TASK) - ->where('execution')->in(array_keys($executions)) - ->andWhere('deleted')->eq(0) - ->andWhere('parent')->lt(1) - ->andWhere('status')->in('closed,cancel') - ->groupBy('execution') - ->fetchPairs('execution'); - - $progress = 0; - foreach($executions as $executionID => $execution) + $progressList = array(); + foreach($projectList as $projectID => $stageList) { - $executionClosedLeft = isset($closedTotalLeft[$executionID]) ? $closedTotalLeft[$executionID] : 0; - $executionTotalConsumed = isset($totalHour[$executionID]) ? $totalHour[$executionID]->totalConsumed : 0; - $executionTotalLeft = isset($totalHour[$executionID]) ? round($totalHour[$executionID]->totalLeft - $executionClosedLeft, 1) : 0; + $progress = 0; + foreach($stageList as $stageID => $stage) + { + if($stage->project != $projectID) continue; - $executionProgress = ($executionTotalConsumed + $executionTotalLeft) ? floor($executionTotalConsumed / ($executionTotalConsumed + $executionTotalLeft) * 1000) / 1000 * 100 : 0; + $stageTotalConsumed = isset($totalHour[$projectID][$stageID]) ? $totalHour[$projectID][$stageID]->totalConsumed : 0; + $stageTotalLeft = isset($totalHour[$projectID][$stageID]) ? round($totalHour[$projectID][$stageID]->totalLeft, 1) : 0; - $progress += $executionProgress * ($execution->percent / 100); + $stageProgress = ($stageTotalConsumed + $stageTotalLeft) ? floor($stageTotalConsumed / ($stageTotalConsumed + $stageTotalLeft) * 1000) / 1000 * 100 : 0; + + $progress += $stageProgress * ($stage->percent / 100); + } + $progressList[$projectID] = $progress; } - return $progress; + return is_numeric($projectIDList) ? $progressList[$projectIDList] : $progressList; } /** From e92779664118169b3cf11da1cac7855ec3f51d19 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Thu, 28 Jul 2022 08:16:07 +0800 Subject: [PATCH 3/3] * Fix bug#25004. --- module/program/view/browsebylist.html.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/program/view/browsebylist.html.php b/module/program/view/browsebylist.html.php index faefdc1c04..44da6a7f16 100644 --- a/module/program/view/browsebylist.html.php +++ b/module/program/view/browsebylist.html.php @@ -85,8 +85,8 @@ end == LONG_TIME ? $lang->program->longTime : $program->end;?> id])):?> -
-
id];?>
+
+
id]);?>