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');