From 5697ba482a99bcfce479ecfd578b88a38c4d9009 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Fri, 15 Oct 2021 14:13:41 +0800 Subject: [PATCH 1/3] * Fix bug#15543. --- module/program/model.php | 10 +++++----- module/project/model.php | 30 ++++++++++++------------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/module/program/model.php b/module/program/model.php index a32ecae0b3..7891fb1015 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1271,11 +1271,11 @@ class programModel extends model /* Get the number of left tasks. */ if($this->cookie->projectType and $this->cookie->projectType == 'bycard') { - $leftTasks = $this->dao->select('project,count(*) as tasks')->from(TABLE_TASK) - ->where('project')->in($projectKeys) - ->andWhere('status')->notIn('cancel,closed') - ->andWhere('execution')->in(array_keys($executions)) - ->groupBy('project') + $leftTasks = $this->dao->select('t2.parent as project, count(*) as tasks')->from(TABLE_TASK)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution = t2.id') + ->where('t1.execution')->in(array_keys($executions)) + ->andWhere('t1.status')->notIn('cancel,closed') + ->groupBy('t2.parent') ->fetchAll('project'); } diff --git a/module/project/model.php b/module/project/model.php index 4a7198daf3..5bdb59b827 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -283,26 +283,20 @@ class projectModel extends model ->andWhere('type')->eq('project') ->groupBy('root')->fetchPairs(); - $executionIdList = $this->dao->select('id')->from(TABLE_PROJECT) - ->where('parent')->in($projectIdList) - ->andWhere('deleted')->eq(0) - ->fetchPairs(); - - $hours = $this->dao->select('project, - sum(consumed) as consumed, - sum(estimate) as estimate') - ->from(TABLE_TASK) - ->where('execution')->in($executionIdList) - ->andWhere('deleted')->eq(0) - ->andWhere('parent')->lt(1) - ->groupBy('project') + $hours = $this->dao->select('t2.parent as project, sum(t1.consumed) as consumed, sum(t1.estimate) as estimate')->from(TABLE_TASK)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution = t2.id') + ->where('t2.parent')->in($projectIdList) + ->andWhere('t1.deleted')->eq(0) + ->andWhere('t1.parent')->lt(1) + ->groupBy('t2.parent') ->fetchAll('project'); - $leftTasks = $this->dao->select('project, count(*) as tasks')->from(TABLE_TASK) - ->where('execution')->in($executionIdList) - ->andWhere('deleted')->eq(0) - ->andWhere('status')->in('wait,doing,pause') - ->groupBy('project') + $leftTasks = $this->dao->select('t2.parent as project, count(*) as tasks')->from(TABLE_TASK)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution = t2.id') + ->where('t2.parent')->in($projectIdList) + ->andWhere('t1.deleted')->eq(0) + ->andWhere('t1.status')->in('wait,doing,pause') + ->groupBy('t2.parent') ->fetchPairs(); $this->loadModel('product'); From 5cd2f5d2dbfe9dd5db370619e2ab3d115805bc82 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Fri, 15 Oct 2021 14:45:01 +0800 Subject: [PATCH 2/3] * Code for bug#15543. --- module/project/model.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/module/project/model.php b/module/project/model.php index 5bdb59b827..239fea49e1 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -373,21 +373,18 @@ class projectModel extends model ROUND(SUM(`left`), 2) AS totalLeft') ->from(TABLE_TASK) ->where('execution')->in(array_keys($executions)) - ->andWhere('project')->eq($projectID) ->andWhere('deleted')->eq(0) ->andWhere('parent')->lt(1) ->fetch(); $totalConsumed = $this->dao->select('ROUND(SUM(consumed), 1) AS totalConsumed')->from(TABLE_TASK) ->where('execution')->in(array_keys($executions)) - ->andWhere('project')->eq($projectID) ->andWhere('deleted')->eq(0) ->andWhere('parent')->lt(1) ->fetch('totalConsumed'); $closedTotalLeft = $this->dao->select('ROUND(SUM(`left`), 2) AS totalLeft')->from(TABLE_TASK) ->where('execution')->in(array_keys($executions)) - ->andWhere('project')->eq($projectID) ->andWhere('deleted')->eq(0) ->andWhere('parent')->lt(1) ->andWhere('status')->in('closed,cancel') From 21ad4ecf0a6b17f41786af10a22dfd0c1434d570 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Sat, 16 Oct 2021 08:27:28 +0800 Subject: [PATCH 3/3] * Code for bug#15543.Modify the consumed hours of the project in the block. --- module/project/model.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/module/project/model.php b/module/project/model.php index 239fea49e1..5f1049d0b2 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -213,10 +213,11 @@ class projectModel extends model ->groupBy('root') ->fetchAll('root'); - $estimates = $this->dao->select('project, sum(estimate) as estimate')->from(TABLE_TASK) - ->where('project')->in($projectIdList) - ->andWhere('deleted')->eq(0) - ->andWhere('parent')->lt(1) + $estimates = $this->dao->select('t2.parent as project, sum(estimate) as estimate')->from(TABLE_TASK)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution = t2.id') + ->where('t2.parent')->in($projectIdList) + ->andWhere('t1.deleted')->eq(0) + ->andWhere('t1.parent')->lt(1) ->groupBy('project') ->fetchAll('project');