From c907c0fad536e0ec6fec4cd52dc8ac95fe6e719f Mon Sep 17 00:00:00 2001 From: qiyu-xie Date: Mon, 18 Jan 2021 13:02:49 +0800 Subject: [PATCH] * Finish task#8962. --- module/program/control.php | 8 +++++- module/program/lang/de.php | 2 +- module/program/lang/en.php | 2 +- module/program/lang/fr.php | 2 +- module/program/lang/vi.php | 2 +- module/program/lang/zh-cn.php | 2 +- module/program/lang/zh-tw.php | 2 +- module/program/model.php | 39 ++++++++++++++++---------- module/program/view/pgmcreate.html.php | 10 +++++-- module/program/view/pgmedit.html.php | 9 ++++-- 10 files changed, 50 insertions(+), 28 deletions(-) diff --git a/module/program/control.php b/module/program/control.php index 2bd7ebde20..7e9e31f8c0 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -146,6 +146,8 @@ class program extends control { $this->lang->navGroup->program = 'program'; + $parentProgram = $parentProgramID ? $this->program->getPGMByID($parentProgramID) : ''; + if($_POST) { $projectID = $this->program->PGMCreate(); @@ -161,10 +163,11 @@ class program extends control $this->view->pmUsers = $this->loadModel('user')->getPairs('noclosed|nodeleted|pmfirst'); $this->view->poUsers = $this->user->getPairs('noclosed|nodeleted|pofirst'); $this->view->users = $this->user->getPairs('noclosed|nodeleted'); - $this->view->parentProgram = $parentProgramID ? $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($parentProgramID)->fetch() : 0; + $this->view->parentProgram = $parentProgram; $this->view->parents = $this->program->getParentPairs(); $this->view->PGMList = $this->program->getPGMList(); $this->view->budgetUnitList = $this->program->getBudgetUnitList(); + $this->view->remainBudget = $this->program->getParentRemainBudget($parentProgram); $this->display(); } @@ -181,6 +184,7 @@ class program extends control $this->lang->navGroup->program = 'program'; $program = $this->program->getPGMByID($programID); + $parentProgram = $program->parent ? $this->program->getPGMByID($program->parent) : ''; if($_POST) { @@ -208,6 +212,8 @@ class program extends control $this->view->parents = $parents; $this->view->PGMList = $this->program->getPGMList(); $this->view->budgetUnitList = $this->program->getBudgetUnitList(); + $this->view->parentProgram = $parentProgram; + $this->view->remainBudget = $this->program->getParentRemainBudget($parentProgram); $this->display(); } diff --git a/module/program/lang/de.php b/module/program/lang/de.php index dcbbdc61db..d66de6fd8f 100644 --- a/module/program/lang/de.php +++ b/module/program/lang/de.php @@ -215,7 +215,7 @@ $lang->program->stakeholderType = 'Stakeholder type'; $lang->program->isStakeholderKey = 'Key stakeholder'; $lang->program->importStakeholder = 'Import program'; $lang->program->PGMManageMembers = 'Program Team'; -$lang->program->PGMParentBudget = "Parent program budget:"; +$lang->program->PGMParentBudget = 'Parent program remain budget:'; $lang->program->beyondParentBudget = 'The remaining budget of the owned program has been exceeded.'; $lang->program->PGMBeginLetterParent = "Parent begin date: %s, begin date should be >= parent begin date."; $lang->program->PGMEndGreaterParent = "Parent end date: %s, end date should be <= parent end date."; diff --git a/module/program/lang/en.php b/module/program/lang/en.php index de350b9f4d..67072cfd48 100644 --- a/module/program/lang/en.php +++ b/module/program/lang/en.php @@ -215,7 +215,7 @@ $lang->program->stakeholderType = 'Stakeholder type'; $lang->program->isStakeholderKey = 'Key stakeholder'; $lang->program->importStakeholder = 'Import program'; $lang->program->PGMManageMembers = 'Program Team'; -$lang->program->PGMParentBudget = "Parent program budget:"; +$lang->program->PGMParentBudget = 'Parent program remain budget:'; $lang->program->beyondParentBudget = 'The remaining budget of the owned program has been exceeded.'; $lang->program->PGMBeginLetterParent = "Parent begin date: %s, begin date should be >= parent begin date."; $lang->program->PGMEndGreaterParent = "Parent end date: %s, end date should be <= parent end date."; diff --git a/module/program/lang/fr.php b/module/program/lang/fr.php index 3917f94989..45d02f9bb8 100644 --- a/module/program/lang/fr.php +++ b/module/program/lang/fr.php @@ -215,7 +215,7 @@ $lang->program->stakeholderType = 'Stakeholder type'; $lang->program->isStakeholderKey = 'Key stakeholder'; $lang->program->importStakeholder = 'Import program'; $lang->program->PGMManageMembers = 'Program Team'; -$lang->program->PGMParentBudget = "Parent program budget:"; +$lang->program->PGMParentBudget = 'Parent program remain budget:'; $lang->program->beyondParentBudget = 'The remaining budget of the owned program has been exceeded.'; $lang->program->PGMBeginLetterParent = "Parent begin date: %s, begin date should be >= parent begin date."; $lang->program->PGMEndGreaterParent = "Parent end date: %s, end date should be <= parent end date."; diff --git a/module/program/lang/vi.php b/module/program/lang/vi.php index 3917f94989..45d02f9bb8 100644 --- a/module/program/lang/vi.php +++ b/module/program/lang/vi.php @@ -215,7 +215,7 @@ $lang->program->stakeholderType = 'Stakeholder type'; $lang->program->isStakeholderKey = 'Key stakeholder'; $lang->program->importStakeholder = 'Import program'; $lang->program->PGMManageMembers = 'Program Team'; -$lang->program->PGMParentBudget = "Parent program budget:"; +$lang->program->PGMParentBudget = 'Parent program remain budget:'; $lang->program->beyondParentBudget = 'The remaining budget of the owned program has been exceeded.'; $lang->program->PGMBeginLetterParent = "Parent begin date: %s, begin date should be >= parent begin date."; $lang->program->PGMEndGreaterParent = "Parent end date: %s, end date should be <= parent end date."; diff --git a/module/program/lang/zh-cn.php b/module/program/lang/zh-cn.php index b8c7f86e22..c1ae6fa4fa 100644 --- a/module/program/lang/zh-cn.php +++ b/module/program/lang/zh-cn.php @@ -215,7 +215,7 @@ $lang->program->stakeholderType = '干系人类型'; $lang->program->isStakeholderKey = '关键干系人'; $lang->program->importStakeholder = '从父项目集导入'; $lang->program->PGMManageMembers = '项目集团队'; -$lang->program->PGMParentBudget = "父项目集预算:"; +$lang->program->PGMParentBudget = '所属项目集剩余预算:'; $lang->program->beyondParentBudget = '已超出所属项目集的剩余预算'; $lang->program->PGMBeginLetterParent = "父项目集的开始日期:%s,开始日期不能小于父项目集的开始日期"; $lang->program->PGMEndGreaterParent = "父项目集的完成日期:%s,完成日期不能大于父项目集的完成日期"; diff --git a/module/program/lang/zh-tw.php b/module/program/lang/zh-tw.php index 26f9276ac7..540df6c2e3 100644 --- a/module/program/lang/zh-tw.php +++ b/module/program/lang/zh-tw.php @@ -213,7 +213,7 @@ $lang->program->stakeholderType = '干係人類型'; $lang->program->isStakeholderKey = '關鍵干係人'; $lang->program->importStakeholder = '從父項目集導入'; $lang->program->PGMManageMembers = '項目集團隊'; -$lang->program->PGMParentBudget = "父項目集預算:"; +$lang->program->PGMParentBudget = '所屬項目集剩餘預算:'; $lang->program->beyondParentBudget = '已超出所屬項目集的剩餘預算'; $lang->program->PGMBeginLetterParent = "父項目集的開始日期:%s,開始日期不能小於父項目集的開始日期"; $lang->program->PGMEndGreaterParent = "父項目集的完成日期:%s,完成日期不能大於父項目集的完成日期"; diff --git a/module/program/model.php b/module/program/model.php index 100bc51359..1c35f65580 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -178,13 +178,8 @@ class programModel extends model /* The budget of a child program cannot beyond the remaining budget of the parent program. */ if(isset($program->budget) and $parentProgram->budget != 0) { - $childGrade = $parentProgram->grade + 1; - $childSumBudget = $this->dao->select("sum(budget) as sumBudget")->from(TABLE_PROJECT) - ->where('path')->like("%{$program->parent}%") - ->andWhere('grade')->eq($childGrade) - ->fetch('sumBudget'); - - if($program->budget > $parentProgram->budget - $childSumBudget) dao::$errors['budget'] = $this->lang->program->beyondParentBudget; + $parentRemainBudget = $this->getParentRemainBudget($parentProgram); + if($program->budget > $parentRemainBudget) dao::$errors['budget'] = $this->lang->program->beyondParentBudget; } if(dao::isError()) return false; @@ -297,14 +292,8 @@ class programModel extends model /* The budget of a child program cannot beyond the remaining budget of the parent program. */ if($program->budget != 0 and $parentProgram->budget != 0) { - $childGrade = $parentProgram->grade + 1; - $childSumBudget = $this->dao->select("sum(budget) as sumBudget")->from(TABLE_PROJECT) - ->where('path')->like("%{$program->parent}%") - ->andWhere('grade')->eq($childGrade) - ->andWhere('id')->ne($programID) - ->fetch('sumBudget'); - - if($program->budget > $parentProgram->budget - $childSumBudget) dao::$errors['budget'] = $this->lang->program->beyondParentBudget; + $parentRemainBudget = $this->getParentRemainBudget($parentProgram); + if($program->budget > $parentRemainBudget + $program->budget) dao::$errors['budget'] = $this->lang->program->beyondParentBudget; } } if(dao::isError()) return false; @@ -677,6 +666,26 @@ class programModel extends model return $budgetUnitList; } + /** + * Get parent remain budget. + * + * @param object $parentProgram + * @access public + * @return int + */ + public function getParentRemainBudget($parentProgram) + { + if(empty($parentProgram)) return; + + $childGrade = $parentProgram->grade + 1; + $childSumBudget = $this->dao->select("sum(budget) as sumBudget")->from(TABLE_PROJECT) + ->where('path')->like("%{$parentProgram->id}%") + ->andWhere('grade')->eq($childGrade) + ->fetch('sumBudget'); + + return $parentProgram->budget - $childSumBudget; + } + /** * Get program parent pairs * diff --git a/module/program/view/pgmcreate.html.php b/module/program/view/pgmcreate.html.php index 8e8b5bb21a..933eab4da1 100644 --- a/module/program/view/pgmcreate.html.php +++ b/module/program/view/pgmcreate.html.php @@ -66,10 +66,14 @@ program->PGMBudget;?>
- program->PGMParentBudget . ($parentProgram->budget != 0 ? $parentProgram->budget . zget($lang->program->unitList, $parentProgram->budgetUnit, '') : $lang->program->future);?> - + budget != 0 ? 'placeholder=' . $lang->program->PGMParentBudget . $remainBudget : '';?> + + + budgetUnit);?> + - budgetUnit) ? $config->program->mainCurrency : $parentProgram->budgetUnit, "class='form-control'");?> + program->mainCurrency, "class='form-control'");?> +
diff --git a/module/program/view/pgmedit.html.php b/module/program/view/pgmedit.html.php index c97fd14e4e..20bdfa7b67 100644 --- a/module/program/view/pgmedit.html.php +++ b/module/program/view/pgmedit.html.php @@ -44,11 +44,14 @@ program->PGMBudget;?>
- parent, '');?> - program->PGMParentBudget . ($parentProgram->budget != 0 ? $parentProgram->budget . zget($lang->program->unitList, $parentProgram->budgetUnit, '') : $lang->program->future);?> - budget != 0 ? $program->budget : '', "class='form-control' " . (strpos($requiredFields, 'budget') !== false ? 'required ' : '') . ($program->budget == 0 ? 'disabled ' : '') . ($parentProgram ? "placeholder=$parentProgramNote " : ''));?> + budget != 0 ? 'placeholder=' . $lang->program->PGMParentBudget . $remainBudget : '';?> + budget != 0 ? $program->budget : '', "class='form-control' " . (strpos($requiredFields, 'budget') !== false ? 'required ' : '') . ($program->budget == 0 ? 'disabled ' : '') . $placeholder);?> + + budgetUnit);?> + budgetUnit, "class='form-control'");?> +