From 83ed1f242396ed4fba37962c41e4ed733f4f409c Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Mon, 7 Dec 2020 17:55:45 +0800 Subject: [PATCH] * Adjust code. --- module/durationestimation/control.php | 94 +++++++++++-------- module/durationestimation/js/create.js | 4 +- module/durationestimation/model.php | 44 ++++++--- .../durationestimation/view/create.html.php | 2 +- module/durationestimation/view/index.html.php | 11 +-- module/workestimation/control.php | 14 +-- module/workestimation/lang/de.php | 4 +- module/workestimation/lang/en.php | 4 +- module/workestimation/lang/fr.php | 4 +- module/workestimation/lang/vi.php | 4 +- module/workestimation/lang/zh-cn.php | 4 +- module/workestimation/lang/zh-tw.php | 4 +- module/workestimation/model.php | 41 ++++---- module/workestimation/view/index.html.php | 4 +- 14 files changed, 131 insertions(+), 107 deletions(-) diff --git a/module/durationestimation/control.php b/module/durationestimation/control.php index 13a7d81a50..ba42d300cf 100644 --- a/module/durationestimation/control.php +++ b/module/durationestimation/control.php @@ -11,41 +11,55 @@ */ class durationestimation extends control { - public function index($programID) + /** + * Project duration estimation. + * + * @param int $projectID + * @access public + * @return void + */ + public function index($projectID) { - $workestimation = $this->loadModel('workestimation')->getBudget($programID); - if(!$workestimation) + $workestimation = $this->loadModel('workestimation')->getBudget($projectID); + if(empty($workestimation)) { echo js::alert($this->lang->durationestimation->setWorkestimation); - die(js::locate($this->createLink('workestimation', 'index', "currentProgram=$programID"))); + die(js::locate($this->createLink('workestimation', 'index', "projectID=$projectID"))); } - $this->loadModel('programplan'); - $program = $this->loadModel('project')->getById($programID); + $this->app->loadLang('programplan'); + $project = $this->loadModel('program')->getPRJByID($projectID); $stages = $this->loadModel('stage')->getStages(); - $title = $this->lang->durationestimation->common . $this->lang->colon . $program->name; - $this->view->estimationList = $this->durationestimation->getListByProgram($programID); - if(empty($this->view->estimationList)) $this->locate(inlink('create', "currentProgram=$programID")); + $estimationList = $this->durationestimation->getListByProject($projectID); + if(empty($estimationList)) $this->locate(inlink('create', "projectID=$projectID")); + + $this->view->title = $this->lang->durationestimation->common . $this->lang->colon . $project->name; + $this->view->position[] = $this->lang->durationestimation->common; $this->view->workestimation = $workestimation; - - $this->view->title = $title; - $this->view->program = $program; - $this->view->stages = $stages; - + $this->view->estimationList = $estimationList; + $this->view->project = $project; + $this->view->stages = $stages; $this->display(); } - public function create($programID = 0) + /** + * Save the project duration estimate. + * + * @param int $projectID + * @access public + * @return void + */ + public function create($projectID = 0) { - $workestimation = $this->loadModel('workestimation')->getBudget($programID); - if(!$workestimation) + $workestimation = $this->loadModel('workestimation')->getBudget($projectID); + if(empty($workestimation)) { echo js::alert($this->lang->durationestimation->setWorkestimation); - die(js::locate($this->createLink('workestimation', 'index', "currentProgram=$programID"))); + die(js::locate($this->createLink('workestimation', 'index', "projectID=$projectID"))); } - $this->loadModel('programplan'); + $this->app->loadLang('programplan'); if(!empty($_POST)) { $total = 0; @@ -54,49 +68,51 @@ class durationestimation extends control $workloadTotal = $this->config->durationestimation->workloadTotal; if($total != $workloadTotal) $this->send(array('result' => 'fail', 'message' => $this->lang->durationestimation->workloadError)); - $this->durationestimation->save($programID); + $this->durationestimation->save($projectID); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('index', "currentProgram={$programID}"))); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('index', "projectID={$projectID}"))); } - $this->view->estimationList = $this->durationestimation->getListByProgram($programID); + $project = $this->loadModel('program')->getPRJByID($projectID); + + $this->view->title = $this->lang->durationestimation->common . $this->lang->colon . $project->name; + $this->view->position[] = $this->lang->durationestimation->common; + $this->view->project = $project; + $this->view->stages = $this->loadModel('stage')->getStages(); + $this->view->estimationList = $this->durationestimation->getListByProject($projectID); $this->view->workestimation = $workestimation; - $program = $this->loadModel('project')->getById($programID); - $title = $this->lang->durationestimation->common . $this->lang->colon . $program->name; - - $this->view->title = $title; - $this->view->program = $program; - $this->view->stages = $this->loadModel('stage')->getStages(); - $this->display(); } /** - * ajaxGetDuration - * - * @param int $program - * @param int $workload - * @param int $worktimeRate - * @param int $people + * Calculate the end time of the duration. + * + * @param int $projectID + * @param int $stage + * @param int $workload + * @param int $worktimeRate + * @param int $people + * @param string $startDate * @access public * @return void */ - public function ajaxGetDuration($program, $stage, $workload, $worktimeRate, $people, $startDate) + public function ajaxGetDuration($projectID, $stage, $workload, $worktimeRate, $people, $startDate) { $startDate = str_replace('_', '-', $startDate); if($startDate == '0000-00-00') $this->send(array('result' => 'success', 'endDate' => '0000-00-00')); - $estimation = $this->loadModel('workestimation')->getBudget($program); + $estimation = $this->loadModel('workestimation')->getBudget($projectID); $duration = $estimation->duration * $workload / 100; $divisor = ($people == 0 || $estimation->dayHour == 0) ? 0 : $worktimeRate / 100 * $people * $estimation->dayHour; $duration = $divisor == 0 ? 0 : $duration / $divisor; if(!$divisor) $this->send(array('result' => 'fail')); - $holidays = array(); - $workDays = array(); + $holidays = array(); + $workDays = array(); $i = 0; + $this->loadModel('project'); $startedTime = strtotime($startDate); diff --git a/module/durationestimation/js/create.js b/module/durationestimation/js/create.js index 46374d3915..3951f85f7a 100644 --- a/module/durationestimation/js/create.js +++ b/module/durationestimation/js/create.js @@ -30,7 +30,7 @@ $().ready(function() $(':input').change(function() { var that = $(this); - programID = program.id; + projectID = project.id; stage = $(this).parents('tr').find('[name*=stage]').val(); workload = $(this).parents('tr').find('[name*=workload]').val(); worktimeRate = $(this).parents('tr').find('[name*=worktimeRate]').val(); @@ -39,7 +39,7 @@ $().ready(function() if(startDate) startDate = startDate.replace(/-/g, '_'); if(isNaN(workload) || isNaN(worktimeRate) || isNaN(people) || startDate == '') return false; - url = createLink('durationestimation', 'ajaxGetDuration', 'program=' + programID + '&stage=' + stage + '&workload=' + workload + '&worktimeRate=' + worktimeRate + '&people=' + people + '&startDate=' + startDate), + url = createLink('durationestimation', 'ajaxGetDuration', 'projectID=' + projectID + '&stage=' + stage + '&workload=' + workload + '&worktimeRate=' + worktimeRate + '&people=' + people + '&startDate=' + startDate), $.getJSON( url, function(response) diff --git a/module/durationestimation/model.php b/module/durationestimation/model.php index c43322f495..afb5abe32e 100644 --- a/module/durationestimation/model.php +++ b/module/durationestimation/model.php @@ -1,35 +1,49 @@ * @package durationestimation * @version $Id$ - * @link http://www.chanzhi.org + * @link http://www.zentao.net */ class durationestimationModel extends model { - public function getListByProgram($program) + /** + * Get the project duration estimate. + * + * @param int $projectID + * @access public + * @return void + */ + public function getListByProject($projectID) { - return $this->dao->select('*')->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($program)->fetchAll('stage'); + return $this->dao->select('*')->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($projectID)->fetchAll('stage'); } - public function save($program) + /** + * Save the project duration estimate. + * + * @param int $projectID + * @access public + * @return void + */ + public function save($projectID) { - $this->dao->delete()->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($program); + $this->dao->delete()->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($projectID); foreach($this->post->stage as $i => $stage) { - $estimation = new stdclass; - $estimation->PRJ = $program; - $estimation->stage = $stage; - $estimation->workload = $this->post->workload[$i]; - $estimation->worktimeRate = $this->post->worktimeRate[$i]; - $estimation->people = $this->post->people[$i]; - $estimation->startDate = $this->post->startDate[$i]; - $estimation->endDate = $this->post->endDate[$i]; - $this->dao->insert(TABLE_DURATIONESTIMATION)->data($estimation)->exec(); + $data = new stdclass; + $data->PRJ = $projectID; + $data->stage = $stage; + $data->workload = $this->post->workload[$i]; + $data->worktimeRate = $this->post->worktimeRate[$i]; + $data->people = $this->post->people[$i]; + $data->startDate = $this->post->startDate[$i]; + $data->endDate = $this->post->endDate[$i]; + $this->dao->insert(TABLE_DURATIONESTIMATION)->data($data)->exec(); } return !dao::isError(); diff --git a/module/durationestimation/view/create.html.php b/module/durationestimation/view/create.html.php index 0fd12e4eb0..b27f3abfb6 100644 --- a/module/durationestimation/view/create.html.php +++ b/module/durationestimation/view/create.html.php @@ -1,5 +1,5 @@ - +
diff --git a/module/durationestimation/view/index.html.php b/module/durationestimation/view/index.html.php index 15e94d80fa..46cae13537 100644 --- a/module/durationestimation/view/index.html.php +++ b/module/durationestimation/view/index.html.php @@ -1,6 +1,4 @@ - -
@@ -23,8 +21,8 @@ name;?> id);?> - - + + @@ -35,14 +33,11 @@
% % % %
- id}"), $lang->durationestimation->setting, '', "class='btn btn-primary'");?> + id}"), $lang->durationestimation->setting, '', "class='btn btn-primary'");?>
- - -
diff --git a/module/workestimation/control.php b/module/workestimation/control.php index aa165226b2..a4b4ba01ca 100644 --- a/module/workestimation/control.php +++ b/module/workestimation/control.php @@ -1,12 +1,12 @@ + * @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com) + * @license ZPL (http://zpl.pub/page/zplv12.html) + * @author Chunsheng Wang * @package workestimation - * @version $Id$ + * @version $Id * @link http://www.zentao.net */ class workestimation extends control @@ -28,7 +28,7 @@ class workestimation extends control $this->send(array('result' => 'fail', 'message' => dao::getError())); } - $scale = $this->workestimation->getProgramScale($projectID); + $scale = $this->workestimation->getProjectScale($projectID); $budget = $this->workestimation->getBudget($projectID); if(!isset($this->config->project)) $this->config->project = new stdclass(); if(empty($budget)) @@ -44,7 +44,7 @@ class workestimation extends control $this->view->title = $this->lang->workestimation->common; $this->view->position[] = $this->lang->workestimation->common; $this->view->hourPoint = $this->config->custom->hourPoint; - $this->view->programScale = $scale; + $this->view->scale = $scale; $this->view->budget = $budget; $this->display(); } diff --git a/module/workestimation/lang/de.php b/module/workestimation/lang/de.php index fbf958d3e4..c0052c7212 100644 --- a/module/workestimation/lang/de.php +++ b/module/workestimation/lang/de.php @@ -11,8 +11,8 @@ $lang->workestimation->dayHour = 'Daily Man-hours'; $lang->workestimation->hour = 'Man-hour'; $lang->workestimation->consumed = 'Cost Man-hours'; -$lang->workestimation->programScaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; -$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; +$lang->workestimation->scaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; +$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; $lang->workestimation->placeholder = new stdclass(); $lang->workestimation->placeholder->scale = ''; diff --git a/module/workestimation/lang/en.php b/module/workestimation/lang/en.php index fbf958d3e4..c0052c7212 100644 --- a/module/workestimation/lang/en.php +++ b/module/workestimation/lang/en.php @@ -11,8 +11,8 @@ $lang->workestimation->dayHour = 'Daily Man-hours'; $lang->workestimation->hour = 'Man-hour'; $lang->workestimation->consumed = 'Cost Man-hours'; -$lang->workestimation->programScaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; -$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; +$lang->workestimation->scaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; +$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; $lang->workestimation->placeholder = new stdclass(); $lang->workestimation->placeholder->scale = ''; diff --git a/module/workestimation/lang/fr.php b/module/workestimation/lang/fr.php index fbf958d3e4..c0052c7212 100644 --- a/module/workestimation/lang/fr.php +++ b/module/workestimation/lang/fr.php @@ -11,8 +11,8 @@ $lang->workestimation->dayHour = 'Daily Man-hours'; $lang->workestimation->hour = 'Man-hour'; $lang->workestimation->consumed = 'Cost Man-hours'; -$lang->workestimation->programScaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; -$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; +$lang->workestimation->scaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; +$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; $lang->workestimation->placeholder = new stdclass(); $lang->workestimation->placeholder->scale = ''; diff --git a/module/workestimation/lang/vi.php b/module/workestimation/lang/vi.php index fbf958d3e4..c0052c7212 100644 --- a/module/workestimation/lang/vi.php +++ b/module/workestimation/lang/vi.php @@ -11,8 +11,8 @@ $lang->workestimation->dayHour = 'Daily Man-hours'; $lang->workestimation->hour = 'Man-hour'; $lang->workestimation->consumed = 'Cost Man-hours'; -$lang->workestimation->programScaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; -$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; +$lang->workestimation->scaleTip = "Actual scale of current project: %s{$lang->hourCommon} uses "; +$lang->workestimation->tips = 'Estimate the duration of the project only after the estimate of the workload has been completed'; $lang->workestimation->placeholder = new stdclass(); $lang->workestimation->placeholder->scale = ''; diff --git a/module/workestimation/lang/zh-cn.php b/module/workestimation/lang/zh-cn.php index 7977fd68cd..e235b66a4a 100644 --- a/module/workestimation/lang/zh-cn.php +++ b/module/workestimation/lang/zh-cn.php @@ -11,8 +11,8 @@ $lang->workestimation->dayHour = '每日工时'; $lang->workestimation->hour = '工时'; $lang->workestimation->consumed = '已消耗工时'; -$lang->workestimation->programScaleTip = "当前项目实际规模:%s{$lang->hourCommon} 使用"; -$lang->workestimation->tips = '完成工作量估算后,才能进行工期估算'; +$lang->workestimation->scaleTip = "当前项目实际规模:%s{$lang->hourCommon} 使用"; +$lang->workestimation->tips = '完成工作量估算后,才能进行工期估算'; $lang->workestimation->placeholder = new stdclass(); $lang->workestimation->placeholder->scale = ''; diff --git a/module/workestimation/lang/zh-tw.php b/module/workestimation/lang/zh-tw.php index 8d58fd63ae..4fcf51f672 100644 --- a/module/workestimation/lang/zh-tw.php +++ b/module/workestimation/lang/zh-tw.php @@ -11,8 +11,8 @@ $lang->workestimation->dayHour = '每日工時'; $lang->workestimation->hour = '工時'; $lang->workestimation->consumed = '已消耗工時'; -$lang->workestimation->programScaleTip = "當前項目實際規模:%s{$lang->hourCommon} 使用"; -$lang->workestimation->tips = '完成工作量估算後,才能進行工期估算'; +$lang->workestimation->scaleTip = "當前項目實際規模:%s{$lang->hourCommon} 使用"; +$lang->workestimation->tips = '完成工作量估算後,才能進行工期估算'; $lang->workestimation->placeholder = new stdclass(); $lang->workestimation->placeholder->scale = ''; diff --git a/module/workestimation/model.php b/module/workestimation/model.php index 3c0b570583..6bcce1c500 100644 --- a/module/workestimation/model.php +++ b/module/workestimation/model.php @@ -1,12 +1,12 @@ + * @copyright Copyright 2009-2015 青岛易软天创网络科技有限公司(QingDao Nature Easy Soft Network Technology Co,LTD, www.cnezsoft.com) + * @license ZPL (http://zpl.pub/page/zplv12.html) + * @author Chunsheng Wang * @package workestimation - * @version $Id$ + * @version $Id * @link http://www.zentao.net */ class workestimationModel extends model @@ -14,45 +14,44 @@ class workestimationModel extends model /** * Get a budget. * - * @param int $program + * @param int $projectID * @access public * @return array */ - public function getBudget($program) + public function getBudget($projectID) { - return $this->dao->select('*')->from(TABLE_WORKESTIMATION)->where('PRJ')->eq($program)->fetch(); + return $this->dao->select('*')->from(TABLE_WORKESTIMATION)->where('PRJ')->eq($projectID)->fetch(); } /** - * Get program scale. + * Get project scale. * - * @param int $program + * @param int $projectID * @access public * @return int */ - public function getProgramScale($program) + public function getProjectScale($projectID) { - $products = $this->loadModel('product')->getPairs('', $program); + $products = $this->loadModel('product')->getProductPairsByProject($projectID); $productIdList = array_keys($products); - return $this->dao->select('cast(sum(estimate) as decimal(10,2)) as scale')->from(TABLE_STORY)->where('product')->in($productIdList)->andWhere('type')->eq('requirement')->fetch('scale'); + return $this->dao->select('cast(sum(estimate) as decimal(10,2)) as scale')->from(TABLE_STORY)->where('product')->in($productIdList)->andWhere('type')->eq('requirement')->andWhere('deleted')->eq(0)->fetch('scale'); } - /** + /* * Save a budget. * - * @param int $program + * @param int $projectID * @access public * @return bool */ - public function save($program) + public function save($projectID) { - $postBudget = fixer::input('post')->get(); - $postBudget->PRJ = $program; + $data = fixer::input('post')->setDefault('PRJ', $projectID)->get(); - $budget = $this->getBudget($program); - if(!empty($budget)) $postBudget->id = $budget->id; + $budget = $this->getBudget($projectID); + if(!empty($budget)) $data->id = $budget->id; - $this->dao->replace(TABLE_WORKESTIMATION)->data($postBudget) + $this->dao->replace(TABLE_WORKESTIMATION)->data($data) ->batchCheck($this->config->workestimation->index->requiredFields, 'notempty') ->exec(); diff --git a/module/workestimation/view/index.html.php b/module/workestimation/view/index.html.php index 5654d5ee4b..d1512ecf67 100644 --- a/module/workestimation/view/index.html.php +++ b/module/workestimation/view/index.html.php @@ -28,7 +28,7 @@ hourCommon;?>
- duration) and $budget->duration) printf($lang->workestimation->programScaleTip, $programScale);?> + duration) and $budget->duration) printf($lang->workestimation->scaleTip, $scale);?> @@ -95,7 +95,7 @@ $(function() { $('#useScale').click(function() { - $('#scale').val('').keyup(); + $('#scale').val('').keyup(); }); $(':input').keyup(function()