diff --git a/module/program/model.php b/module/program/model.php index f1ca0d0cd3..0ba7e0cfd4 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1273,11 +1273,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 9e683e7098..ec9bd9d130 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'); @@ -283,26 +284,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'); @@ -379,21 +374,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')