ShuanghongS 5 months ago
parent
commit
e04fc18e37
1 changed files with 14 additions and 73 deletions
  1. 14 73
      utils/common.class.php

+ 14 - 73
utils/common.class.php

@@ -1000,10 +1000,16 @@ class common {
             $Management = common::getdefaultManagement();
         }else{
             $Management = json_decode($user_management,true);
-            $Management = common::insertRevenueSpent($Management,_isRevenueDisplay());
             foreach($Management as $key =>$val){
                 $Management[$key]['id'] = ($key +1);
                 $Management[$key]['switchValue'] = $val['switchValue'] == "true" ? true : false;
+
+                if ($val['title'] == "Revenue Spent"){
+                    $Management[$key]['isRevenueDisplay'] = _isRevenueDisplay();
+                    if(!_isRevenueDisplay()){
+                        $Management[$key]['switchValue'] = false;
+                    }
+                }
             }
             
         }
@@ -1078,72 +1084,6 @@ class common {
         return  array("Management" => $Management,"dashboard_filter" =>$dashboard_filter);
     }
 
-    public static  function insertRevenueSpent($array, $isRevenueDisplay) {
-        if (!$isRevenueDisplay){
-            // 移除 Revenue Spent(如果存在)
-            foreach ($array as $index => $item) {
-                if (isset($item['title']) && $item['title'] === "Revenue Spent") {
-                    unset($array[$index]);
-                    // 重置索引
-                    $array = array_values($array);
-                    break;
-                }
-            }
-            return $array;
-        }
-        
-        // 检查是否已经存在 Revenue Spent
-        foreach ($array as $item) {
-            if (isset($item['title']) && $item['title'] === 'Revenue Spent') {
-                return; // 已存在,不插入
-            }
-        }
-        
-        // 查找插入位置
-        $insertAfterTitles = ["Container Count", "ETD to ETA (Days)", "Pending", "KPI"];
-        $insertIndex = null;
-        // 遍历数组,记录每个优先级字段的位置
-        $positions = [];
-
-        foreach ($array as $index => $item) {
-            if (isset($item['title'])) {
-                $key = array_search($item['title'], $insertAfterTitles);
-                if ($key !== false) {
-                    $positions[$key] = $index;
-                }
-            }
-        }
-
-        // 找出最早出现的那个标题
-        ksort($positions); // 按优先级排序
-        foreach ($positions as $pos) {
-            $insertIndex = $pos + 1;
-            break;
-        }
-
-        // 如果都没有匹配项,插到开头
-        if ($insertIndex === null) {
-            $newItem = [
-                "id" => 0, // 可选:生成唯一 ID
-                "title" => "Revenue Spent",
-                "switchValue" => "true",
-                "text" => "Description for Revenue Spent"
-            ];
-            array_unshift($array, $newItem);
-        } else {
-            // 要插入的新元素
-            $newItem = [
-                "id" => 0, // 可选:重新排序后,最后都要循环,重新赋值id
-                "title" => "Revenue Spent",
-                "switchValue" => "true",
-                "text" => "Description for Revenue Spent"
-            ];
-            array_splice($array, $insertIndex, 0, [$newItem]);
-        }
-        
-        return array_values($array);
-    }
-
     public static function getItemStyle($type,$code){
         if($type == 'r1'){
             $data =  array("0-20 Days" =>"#ffc594",
@@ -1785,12 +1725,13 @@ class common {
             "title"=>"Container Count",
             "switchValue"=>true,
             "text"=>"Pie chart showing figures of shipments which are soon to depart/arrive (Calculated from ETD/ETA).");
-        if(_isRevenueDisplay()){    
-            $Management[] = array("id"=>5 ,
-                "title"=>"Revenue Spent",
-                "switchValue"=>true,
-                "text"=>"Revenue data for the past 12 months."); 
-        }   
+        //if(_isRevenueDisplay()){    
+        $Management[] = array("id"=>5 ,
+            "title"=>"Revenue Spent",
+            "switchValue"=>_isRevenueDisplay(),
+            "text"=>"Revenue data for the past 12 months.",
+            "isRevenueDisplay"=>_isRevenueDisplay()); 
+        //}   
         $Management[] = array("id"=>6 ,
             "title"=>"Top 10 Origin/Destination",
             "switchValue"=>true,