* Merge task estimate to effort.

This commit is contained in:
sunguangming
2022-09-02 13:52:56 +08:00
parent 17b58bc39b
commit d5ee1ab4f3
7 changed files with 101 additions and 74 deletions
+49 -39
View File
@@ -486,17 +486,10 @@ class taskModel extends model
$clonedTaskID = $this->dao->lastInsertID();
/* Update the table by judging the beginning of the version number. */
if($this->config->edition == 'open')
{
/* ZenTao Pms update TABLE_TASKESTIMATE. */
$this->dao->update(TABLE_TASKESTIMATE)->set('task')->eq($clonedTaskID)->where('task')->eq($oldParentTask->id)->exec();
}
else
{
/* ZenTao Pro and ZenTao Biz update TABLE_EFFORT. */
$this->dao->update(TABLE_EFFORT)->set('objectID')->eq($clonedTaskID)->where('objectID')->eq($oldParentTask->id)->exec();
}
$this->dao->update(TABLE_EFFORT)->set('objectID')->eq($clonedTaskID)
->where('objectID')->eq($oldParentTask->id)
->andWhere('objectType')->eq('task')
->exec();
}
$this->updateParentStatus($taskID);
@@ -1849,7 +1842,7 @@ class taskModel extends model
$left = $task->left;
$now = helper::now();
$oldStatus = $task->status;
$lastDate = $this->dao->select('*')->from(TABLE_TASKESTIMATE)->where('task')->eq($taskID)->orderBy('date_desc,id_desc')->limit(1)->fetch('date');
$lastDate = $this->dao->select('*')->from(TABLE_EFFORT)->where('objectID')->eq($taskID)->andWhere('objectType')->eq('task')->orderBy('date_desc,id_desc')->limit(1)->fetch('date');
foreach($estimates as $estimate)
{
@@ -1952,12 +1945,12 @@ class taskModel extends model
*/
public function resetEffortLeft($taskID, $members)
{
$table = $this->config->edition == 'open' ? TABLE_TASKESTIMATE : TABLE_EFFORT;
foreach($members as $account)
{
$this->dao->update($table)->set('`left`')->eq(0)->where('account')->eq($account)
->beginIF($this->config->edition == 'open')->andWhere('task')->eq($taskID)->fi()
->beginIF($this->config->edition != 'open')->andWhere('objectID')->eq($taskID)->andWhere('objectType')->eq('task')->fi()
$this->dao->update(TABLE_EFFORT)->set('`left`')->eq(0)
->where('account')->eq($account)
->andWhere('objectID')->eq($taskID)
->andWhere('objectType')->eq('task')
->orderBy('date_desc,id_desc')
->limit('1')
->exec();
@@ -2789,15 +2782,14 @@ class taskModel extends model
/**
* Update estimate order for linear task team.
*
* @param int $estimateID
* @param int $effortID
* @param int $order
* @access public
* @return void
*/
public function updateEstimateOrder($estimateID, $order)
public function updateEstimateOrder($effortID, $order)
{
$table = $this->config->edition == 'open' ? TABLE_TASKESTIMATE : TABLE_EFFORT;
$this->dao->update($table)->set('`order`')->eq((int)$order)->where('id')->eq($estimateID)->exec();
$this->dao->update(TABLE_EFFORT)->set('`order`')->eq((int)$order)->where('id')->eq($effortID)->exec();
}
/**
@@ -2812,15 +2804,6 @@ class taskModel extends model
*/
public function getTaskEstimate($taskID, $account = '', $append = '', $orderBy = 'date,id')
{
if($this->config->edition == 'open')
{
return $this->dao->select('*')->from(TABLE_TASKESTIMATE)
->where('task')->eq($taskID)
->beginIF($account)->andWhere('account')->eq($account)->fi()
->beginIF($append)->orWhere('id')->eq($append)->fi()
->orderBy($orderBy)
->fetchAll();
}
return $this->dao->select('*')->from(TABLE_EFFORT)->where('objectID')->eq($taskID)
->andWhere('objectType')->eq('task')
->andWhere('deleted')->eq('0')
@@ -2833,18 +2816,22 @@ class taskModel extends model
/**
* Get estimate by id.
*
* @param int $estimateID
* @param int $effortID
* @access public
* @return object.
*/
public function getEstimateById($estimateID)
public function getEstimateById($effortID)
{
$estimate = $this->dao->select('*')->from(TABLE_TASKESTIMATE)
->where('id')->eq($estimateID)
$estimate = $this->dao->select('*')->from(TABLE_EFFORT)
->where('id')->eq($effortID)
->fetch();
/* If the estimate is the last of its task, status of task will be checked. */
$lastID = $this->dao->select('id')->from(TABLE_TASKESTIMATE)->where('task')->eq($estimate->task)->orderBy('date_desc,id_desc')->limit(1)->fetch('id');
$lastID = $this->dao->select('id')->from(TABLE_EFFORT)
->where('objectID')->eq($estimate->objectID)
->andWhere('objectType')->eq('task')
->orderBy('date_desc,id_desc')->limit(1)->fetch('id');
$estimate->isLast = $lastID == $estimate->id;
return $estimate;
}
@@ -2898,14 +2885,17 @@ class taskModel extends model
if($estimate->left < 0) return dao::$errors[] = sprintf($this->lang->error->ge, $this->lang->task->left, '0');
$task = $this->getById($oldEstimate->task);
$this->dao->update(TABLE_TASKESTIMATE)->data($estimate)
$this->dao->update(TABLE_EFFORT)->data($estimate)
->autoCheck()
->where('id')->eq((int)$estimateID)
->exec();
$consumed = $task->consumed + $estimate->consumed - $oldEstimate->consumed;
$lastEstimate = $this->dao->select('*')->from(TABLE_TASKESTIMATE)->where('task')->eq($task->id)->orderBy('date_desc,id_desc')->limit(1)->fetch();
$left = ($lastEstimate and $estimateID == $lastEstimate->id) ? $estimate->left : $task->left;
$lastEstimate = $this->dao->select('*')->from(TABLE_EFFORT)
->where('objectID')->eq($task->id)
->andWhere('objectType')->eq('task')
->orderBy('date_desc,id_desc')->limit(1)->fetch();
$now = helper::now();
$data = new stdClass();
@@ -2974,7 +2964,10 @@ class taskModel extends model
$left = $task->left;
if($estimate->isLast)
{
$lastTwoEstimates = $this->dao->select('*')->from(TABLE_TASKESTIMATE)->where('task')->eq($estimate->task)->orderBy('date desc,id desc')->limit(2)->fetchAll();
$lastTwoEstimates = $this->dao->select('*')->from(TABLE_EFFORT)
->where('objectID')->eq($estimate->task)
->andWhere('objectType')->eq('task')
->orderBy('date desc,id desc')->limit(2)->fetchAll();
$lastTwoEstimate = isset($lastTwoEstimates[1]) ? $lastTwoEstimates[1] : '';
if($lastTwoEstimate) $left = $lastTwoEstimate->left;
if(empty($lastTwoEstimate) and $left == 0) $left = $task->estimate;
@@ -3041,7 +3034,7 @@ class taskModel extends model
}
}
$this->dao->delete()->from(TABLE_TASKESTIMATE)->where('id')->eq($estimateID)->exec();
$this->dao->update(TABLE_EFFORT)->set('deleted')->eq('1')->where('id')->eq($estimateID)->exec();
if(!empty($task->team)) $data = $this->computeHours4Multiple($task, $data);
$this->dao->update(TABLE_TASK)->data($data) ->where('id')->eq($estimate->task)->exec();
@@ -3618,7 +3611,24 @@ class taskModel extends model
*/
public function addTaskEstimate($data)
{
$this->dao->insert(TABLE_TASKESTIMATE)->data($data)->autoCheck()->exec();
$oldTask = $this->getById($data->task);
$relation = $this->loadModel('action')->getRelatedFields('task', $data->task);
$effort = new stdclass();
$effort->objectType = 'task';
$effort->objectID = $data->task;
$effort->execution = $oldTask->execution;
$effort->product = $relation['product'];
$effort->project = (int)$relation['project'];
$effort->account = $data->account;
$effort->date = $data->date;
$effort->consumed = $data->consumed;
$effort->left = $data->left;
$effort->work = isset($data->work) ? $data->work : '';
$effort->vision = $this->config->vision;
$this->dao->insert(TABLE_EFFORT)->data($effort)->autoCheck()->exec();
return $this->dao->lastInsertID();
}