diff --git a/module/product/control.php b/module/product/control.php index 0d4a8e9e9d..4045f5c654 100755 --- a/module/product/control.php +++ b/module/product/control.php @@ -1056,7 +1056,7 @@ class product extends control $param = strtolower($param); if(strpos($param, 'forstory') === false) { - $plans = $this->loadModel('productplan')->getPairs($productID, $branch, $expired, strpos($param, 'skipparent') !== false); + $plans = $this->loadModel('productplan')->getPairs($productID, empty($branch) ? 'all' : $branch, $expired, strpos($param, 'skipparent') !== false); } else { diff --git a/module/productplan/model.php b/module/productplan/model.php index e182796538..dbb8372e66 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -467,11 +467,25 @@ class productplanModel extends model */ public function getBranchPlanPairs($productID, $branches = '', $param = '', $skipParent = false) { + $branchQuery = ''; + if($branches !== '' and $branches !== 'all') + { + $branchQuery .= '('; + if(!is_array($branches)) $branches = explode(',', $branches); + foreach($branches as $branchID) + { + $branchQuery .= "CONCAT(',', branch, ',') LIKE '%,$branchID,%'"; + if($branchID != end($branches)) $branchQuery .= ' OR '; + } + $branchQuery .= ')'; + } + $date = date('Y-m-d'); $param = strtolower($param); $plans = $this->dao->select('parent,branch,id,title,begin,end')->from(TABLE_PRODUCTPLAN) ->where('product')->eq($productID) ->andWhere('deleted')->eq(0) + ->beginIF(!empty($branchQuery))->andWhere($branchQuery)->fi() ->beginIF($branches != '')->andWhere('branch')->in($branches)->fi() ->beginIF(strpos($param, 'unexpired') !== false)->andWhere('end')->ge($date)->fi() ->orderBy('begin desc') @@ -486,6 +500,7 @@ class productplanModel extends model if($plan->parent > 0 and isset($plans[$plan->parent])) $plan->title = $plans[$plan->parent]->title . ' /' . $plan->title; $planPairs[$branch][$planID] = $plan->title . ' [' . $plan->begin . '~' . $plan->end . ']'; + if($branch !== BRANCH_MAIN) $planPairs[BRANCH_MAIN][$planID] = $plan->title . ' [' . $plan->begin . '~' . $plan->end . ']'; } } return $planPairs;