ShuanghongS vor 1 Monat
Ursprung
Commit
7314e9c44a
6 geänderte Dateien mit 415 neuen und 115 gelöschten Zeilen
  1. 4 1
      main_new_version.php
  2. 17 21
      service/ajax.class.php
  3. 17 6
      service/column.class.php
  4. 4 4
      service/ocean_order.class.php
  5. 285 83
      service/report.class.php
  6. 88 0
      utils/common.class.php

+ 4 - 1
main_new_version.php

@@ -834,7 +834,10 @@ switch ($action) {
         break;
     case 'report_config':
         report::getInstance()->report_config();
-        break;                                     
+        break;
+    case 'shipment_status_report':
+        report::getInstance()->shipment_status_report();
+        break;                                         
     case 'user_guide':
         $rootPath = realpath(dirname(__FILE__)) . DS;
         //common::download_file($rootPath."images\ACE-M1_ISF_ACI_User_Guide\ACE-M1_ISF_ACI_User_Guide.pdf", "ACE-M1_ISF_ACI_User_Guide_V2.0.pdf");

+ 17 - 21
service/ajax.class.php

@@ -260,25 +260,25 @@ class ajax {
                     $_curr_schemas = "public";
                 }
             }
-            $sql = "SELECT company_name as id, contacts_id as code from $_curr_schemas.contacts_group where company_name ilike '" . common::check_input($term) . "%'";
+            $sql = "SELECT company_name as code, contacts_id as id from $_curr_schemas.contacts_group where company_name ilike '" . common::check_input($term) . "%'";
             if (!empty($input))
                 $sql .= " and lower(company_name) " . utils::getInSql($input, TRUE);
             $sql .= " order by company_name limit 20";
         }
 
-        if (strtolower($type) == "contact_group_user") {
-            $_curr_schemas = $_POST['model'];
-            if (empty($_curr_schemas)) {
-                $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
-                if (empty($_curr_schemas)) {
-                    $_curr_schemas = "public";
-                }
-            }
-            $sql = "SELECT contacts_id as id, company_name as code from $_curr_schemas.contacts_group where contacts_id ilike '%" . common::check_input($term) . "%'";
-            if (!empty($input))
-                $sql .= " and lower(contacts_id) " . utils::getInSql($input, TRUE);
-            $sql .= " order by company_name limit 20";
-        }
+        // if (strtolower($type) == "contact_group_user") {
+        //     $_curr_schemas = $_POST['model'];
+        //     if (empty($_curr_schemas)) {
+        //         $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
+        //         if (empty($_curr_schemas)) {
+        //             $_curr_schemas = "public";
+        //         }
+        //     }
+        //     $sql = "SELECT contacts_id as id, company_name as code from $_curr_schemas.contacts_group where contacts_id ilike '%" . common::check_input($term) . "%'";
+        //     if (!empty($input))
+        //         $sql .= " and lower(contacts_id) " . utils::getInSql($input, TRUE);
+        //     $sql .= " order by company_name limit 20";
+        // }
 
         if (strtolower($type) == "apex") {
             $_curr_schemas = $_POST['model'];
@@ -288,14 +288,10 @@ class ajax {
                     $_curr_schemas = "public";
                 }
             }
-            if ($_curr_schemas == "public") {
-                $sql = "select contact_id as id, company as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
-                        . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
-                        . "and active=true and coalesce(hblcode, '')<>'' and  (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
+            if ($_curr_schemas == "public") {//apex ocean和air 分开
+                $sql = "SELECT contact_id as code, company as id from ocean.contacts where contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%'";
             } else {
-                $sql = "select contact_id as id, company as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
-                        . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
-                        . "and active=true and coalesce(hblcode, '')<>'' and  (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
+                $sql = "SELECT contact_id as code, company as id from $_curr_schemas.contacts where contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%'";
             }
             if (!empty($input))
                 $sql .= " and lower(contact_id) " . utils::getInSql($input, TRUE);

+ 17 - 6
service/column.class.php

@@ -36,9 +36,21 @@ class column {
             $rightSqlwhere = " and item_level_default = true order by item_level_default_order";
             $leftSqlwhere = " and coalesce(item_level_default,false) = false";
         }
-
-        $kln_report_field_str = " id as ids, code as label ,code as field, level as field_level,'System' as field_type,data_type,level as field_level,group_name ";
-        $kln_report_field_config = " field_id as ids, field_display_name as label,field_db as field,field_type,data_type,field_level ";
+ 
+        $kln_report_field_str = " id as ids,
+            code as field, 
+            code as label,
+            level as \"fieldLevel\",
+            'System' as \"fieldType\",
+            data_type as \"dataType\",
+            group_name as \"groupName\" ";
+        $kln_report_field_config = " field_id as ids,
+            field_db as field,
+            field_display_name as label,
+            field_level as \"fieldLevel\",
+            field_type as \"fieldType\",
+            data_type as \"dataType\",
+            field_group_name as \"groupName\" ";
 
         $allData = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." order by id");
         if(empty($serial_no) || $defualt == 'true'){
@@ -47,10 +59,9 @@ class column {
                 $dataLeft = common::excuteListSql("select   ".$kln_report_field_str." from public.kln_report_field where  ".$levelSQlWhere."  ".$leftSqlwhere." order by id");
         }else{
                 $groupSetting = common::excuteListSql("select ".$kln_report_field_config." from public.kln_report_field_config 
-                    where template_serial_no = '$serial_no' 
-                        order by id");
+                    where template_serial_no = '$serial_no' and field_type = 'System' order by id");
                 $dataLeft = common::excuteListSql("select ".$kln_report_field_str."from public.kln_report_field 
-                    where level = '$level' and id != ALL(select field_ids from public.kln_report_template where serial_no = '$serial_no') 
+                    where level = '$level' and id != ALL(select field_ids from public.kln_report_template where serial_no = '$serial_no' and field_type = 'System') 
                         order by id");
         }
 

+ 4 - 4
service/ocean_order.class.php

@@ -2474,12 +2474,12 @@ class ocean_order {
             //未发生前
             if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
                 //如果milestone有值,或者与milestone不等,以milestone的优先度最高
-                $ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
+                //$ocean['f_etd'] = $ocean_milestone_status_code['IFFDEP']['est_date'];
             } 
         } else{
             if(!empty($ocean_milestone_status_code['IFFDEP']['act_date'])){
                 //如果milestone有值,或者与milestone不等,以milestone的优先度最高
-                $ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
+                //$ocean['atd'] = $ocean_milestone_status_code['IFFDEP']['act_date'];
             }
         }    
         //先处理一下 ATD 和 ATA,在进行后面的取值
@@ -2660,13 +2660,13 @@ class ocean_order {
             //未发生前
             if(!empty($ocean_milestone_status_code['IFFONB']['est_date'])){
                 //如果milestone有值,或者与milestone不等,以milestone的优先度最高
-                $ocean['etd'] = $ocean_milestone_status_code['IFFONB']['est_date'];
+                //$ocean['etd'] = $ocean_milestone_status_code['IFFONB']['est_date'];
             } 
         } else{
             if(!empty($ocean_milestone_status_code['IFFONB']['act_date'])){
                 //如果milestone有值,或者与milestone不等,以milestone的优先度最高
                 //ATD 取值为IFFONB milestone实际发生的时间
-                $ocean['atd'] = $ocean_milestone_status_code['IFFONB']['act_date'];
+                //$ocean['atd'] = $ocean_milestone_status_code['IFFONB']['act_date'];
             }
         }
 

+ 285 - 83
service/report.class.php

@@ -57,7 +57,7 @@ class report {
             }
 
             $rc = $_POST ['rc'];
-            if ($rc == - 1) {
+            if ($rc == -1) {
                 $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
                 $rc = common::excuteOneSql($sql);
             }
@@ -81,7 +81,7 @@ class report {
         }
 
         if ($operate == "add"){
-            $serial_no = common::deCode($_REQUEST['serial_no'], 'D');
+            $serial_no = $_REQUEST['serial_no'];
             if(!empty($serial_no)){
                 //代表编辑
                 $reportMain = common::excuteObjectSql("select *,
@@ -90,13 +90,22 @@ class report {
                     from kln_report_template where serial_no = '$serial_no'");
                 
                 $reportFields = array();    
-                $reportField = common::excuteListSql("select field_id,field_level,field_type,field_db,field_display_name,
-                        field_display_name_user,data_type,custom_value_type,
-                        custom_fixed_value,is_filter_enabled,is_sort_enabled 
-                    from kln_report_field_config  where template_serial_no = '$serial_no' order by order_index");
+                $reportField = common::excuteListSql("select 
+                        field_id as ids,
+                        field_level as \"fieldLevel\",
+                        field_type as \"fieldType\",
+                        field_group_name as \"groupName\",
+                        field_db as field,
+                        field_display_name as title,
+                        field_display_name_user as \"displayName\",
+                        data_type as \"dataType\",
+                        custom_fixed_value as value,
+                        is_filter_enabled as \"isFilter\",
+                        is_sort_enabled as  \"isSort\"
+                    from kln_report_field_config  where template_serial_no = '$serial_no' order by id");
                 foreach($reportField as  $_reportField){
-                    $_reportField['is_filter_enabled'] = $_reportField['is_filter_enabled'] == 't' ? true : false;
-                    $_reportField['is_sort_enabled'] = $_reportField['is_sort_enabled'] == 't' ? true : false;
+                    $_reportField['isFilter'] = $_reportField['isFilter'] == 't' ? true : false;
+                    $_reportField['isSort'] = $_reportField['isSort'] == 't' ? true : false;
                     $reportFields[] = $_reportField;
                 }
 
@@ -117,7 +126,7 @@ class report {
         }
 
         if ($operate == "save"){
-            $serial_no = common::deCode($_POST['serial_no'], 'D');
+            $serial_no = $_POST['serial_no'];
             $name = common::check_input($_POST['report_name']);
             $description = common::check_input($_POST['report_description']);
             $level = common::check_input($_POST['report_level']);
@@ -125,23 +134,21 @@ class report {
             $party_ids = $_POST['party_ids'];
             $group_names = $_POST['group_names'];
 
-            //字段配置信息
-            $field_ids = $_POST['field_id'];
-            $field_level = $_POST['field_level'];
-            $field_type = $_POST['field_type'];
-            $field_db = $_POST['field_db'];
-            $field_code = $_POST['field_code'];
-            $display_name = $_POST['display_name'];
-            $data_type = $_POST['data_type'];
-            $value_type = $_POST['value_type'];
-            $fixed_value = $_POST['fixed_value'];
-            $is_filter_enabled = $_POST['is_filter_enabled'];
-            $is_sort_enabled = $_POST['is_sort_enabled'];
-
-            $report_sql = common::excuteOneSql("select sql from public.kln_report_sql_manage where level = '$level'");
+            //单独处理字段id
+            $fieldsList = $_POST['fieldsList'];
+            $field_ids = array();
+            foreach($fieldsList as $_fieldsList){
+                if (!empty($_fieldsList['ids'])){
+                    $field_ids[] = $_fieldsList['ids'];
+                }
+            }
+
+            $report_sql_data = common::excuteObjectSql("select sql,count_sql from public.kln_report_sql_manage where level = '$level'");
             $sql = "";
             if (!empty($serial_no)){
-                $updateSqlSet = " report_sql = '$report_sql', modify_by = '"._getLoginName()."',update_time = now()";
+                $updateSqlSet = " report_sql = '".common::check_input($report_sql_data['sql'])."', 
+                                  count_sql = '".common::check_input($report_sql_data['count_sql'])."', 
+                                  modify_by = '"._getLoginName()."',update_time = now()";
                 if (!empty($name)) {
                     $updateSqlSet.= ", name = '$name' ";
                 }
@@ -155,84 +162,79 @@ class report {
                     $updateSqlSet.= ", access_type = '$access_type' ";
                 }
                 if (!empty($party_ids)) {
-                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $party_ids)) . '"';
-                    $updateSqlSet.= ", party_ids = '{".$pgsql_array."}'::text[]";
+                    $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
+                    $updateSqlSet.= ", party_ids = $party_ids_filed";
                 }
                 if (!empty($group_names)) {
-                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
-                    $updateSqlSet.= ", group_names = '{".$pgsql_array."}'::text[]";
+                    $group_names_filed = common::toPgTextArrayLiteral($group_names);
+                    $updateSqlSet.= ", group_names = $group_names_filed";
                 }
                 if (!empty($field_ids)) {
-                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
-                    $updateSqlSet.= ", field_ids = '{".$pgsql_array."}'::INTEGER[]";
+                    $ids_filed =  common::toPgTextArrayLiteral($field_ids);
+                    $updateSqlSet.= ", field_ids = $ids_filed";
                 }
                 //代表update 
                 $sql .= "update public.kln_report_template set ".$updateSqlSet."
                     where serial_no = '$serial_no';";
             } else {
-                $party_ids_filed = null;
+                $party_ids_filed = "NULL";
                 if (!empty($party_ids)) {
-                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $party_ids)) . '"';
-                    $party_ids_filed= "'{".$pgsql_array."}'::text[]";
+                    $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
                 }
 
-                $group_names_filed = null;
+                $group_names_filed = "NULL";
                 if (!empty($group_names)) {
-                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
-                    $group_names_filed = "'{".$pgsql_array."}'::text[]";
+                    $group_names_filed = common::toPgTextArrayLiteral($group_names);
                 }
 
-                $ids_filed = null;
+                $ids_filed = "NULL";
                 if (!empty($field_ids)) {
-                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
-                    $ids_filed = "'{".$pgsql_array."}'::INTEGER[]";
+                    $ids_filed =  common::toPgTextArrayLiteral($field_ids);
                 }
 
                 $serial_no = common::uuid();
                 $sql .= "INSERT INTO public.kln_report_template(
-                                serial_no,name, description, level, field_ids, access_type, report_sql,
+                                serial_no,name, description, level, field_ids, access_type, report_sql,count_sql,
                                 party_ids, group_names, create_by, created_time, modify_by, update_time )
-                        VALUES ('$serial_no','$name', '$description', '$level', $ids_filed, '$access_type', '$report_sql'
-                                $party_ids_filed, $group_names_filed , '"._getLoginName()."', now(), '"._getLoginName()."', now());";
+                        VALUES ('$serial_no','$name', '$description', '$level', $ids_filed, '$access_type',
+                                '".common::check_input($report_sql_data['sql'])."','".common::check_input($report_sql_data['count_sql'])."',
+                                $party_ids_filed, $group_names_filed , '"._getLoginName()."', now(), '"._getLoginName()."', now());";              
             }
-
-            $errmsg = "";
-            //柜子是先删除,后添加
+            //先删除,后添加
             $sql .= "delete from  public.kln_report_field_config where template_serial_no = '$serial_no';";
-            foreach($field_ids as $key =>$_field_id){
-                $_field_level = $field_level[$key];
-                $_ield_type = $field_type[$key];
-                $_field_db = $field_db[$key];
-                $_field_code = $field_code[$key];
-                $_display_name = $display_name[$key];
-                $_data_type = $data_type[$key];
-                $_value_type = $value_type[$key];
-                $_fixed_value = $fixed_value[$key];
-                $_is_filter_enabled = $is_filter_enabled[$key];
-                $_is_sort_enabled = $is_sort_enabled[$key];
+            foreach($fieldsList as $key =>$_tempFieldsList){
+                $_field_id = empty($_tempFieldsList['ids'])? "NULL": $_tempFieldsList['ids'];
+                $_field_level = common::check_input($_tempFieldsList['fieldLevel']);
+                $_field_type = common::check_input($_tempFieldsList['fieldType']);
+                $_field_group_name = common::check_input($_tempFieldsList['groupName']);
+                $_field_db = common::check_input($_tempFieldsList['field']);
+                $_field_code = common::check_input($_tempFieldsList['title']);
+                $_display_name = common::check_input($_tempFieldsList['displayName']);
+                $_data_type = common::check_input($_tempFieldsList['dataType']);
+                $_value_type =  $_field_type == "System" ? "" : (empty($_tempFieldsList['value']) ? "Blank" :"Fixed Value");
+                $_fixed_value = common::check_input($_tempFieldsList['value']);
+                $_is_filter_enabled = $_tempFieldsList['isFilter'];
+                $_is_sort_enabled = $_tempFieldsList['isSort'];
                 $sql .=  "INSERT INTO public.kln_report_field_config(
-                            template_serial_no, field_id, field_level, field_type, field_db, 
+                            template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
                             field_display_name, field_display_name_user, data_type, custom_value_type, 
                             custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
-                    VALUES ('$serial_no', '$_field_id', '$_field_level', '$_ield_type', '$_field_db', 
+                    VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name', 
                             '$_field_code', '$_display_name', '$_data_type', '$_value_type', 
                             '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
-
             }
-            if (empty($errmsg) && !empty($sql)){
+            if (!empty($sql)){
                 common::excuteUpdateSql($sql);
                 $data = array("msg" =>"success");
-            } else {
-                $data = array("msg" =>$errmsg);
-            }  
+            }
             common::echo_json_encode(200,$data);                
             exit(); 
         }
 
-        if ($operate == "delete"){
-            $serial_no = common::deCode($_POST['a'], 'D');
-            $sql = "delete from public.kln_report_template where serial_no = '$serial_no';";
-            $sql .= "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
+        if ($operate == "active"){
+            $serial_no =$_POST['serial_no'];
+            $is_active = $_POST['is_active'];
+            $sql = "update public.kln_report_template set is_active = '$is_active'  where serial_no = '$serial_no';";
             common::excuteUpdateSql($sql);
             $data = array("msg" =>"success");
             common::echo_json_encode(200,$data);                
@@ -288,36 +290,236 @@ class report {
 
         if ($operate == "report_detail") {
             $serial_no = common::check_input($_POST ['serial_no']); 
+            $dataReturn = array();
+            $tableColumns = array();
+            $filtersList = array();
+            $sortByOptions = array();
+            $reportFiled = common::excuteListSql("select * from public.kln_report_field_config where template_serial_no = '".$serial_no."' 
+                and field_type = 'System' and is_enabled = true order by id ");
+            foreach($reportFiled as $filed){
+                if($filed['is_filter_enabled'] == 't'){
+                    $type = $filed['data_type'] == "string" ? "input" : ($filed['data_type'] == "date" ? "date" : "input");
+                    $filtersList[] = array(
+                        "label"=>$filed['field_display_name_user'],
+                        "field"=>$filed['field_display_name'],
+                        "type"=>$type,
+                        "data_type"=>$filed['data_type'],
+                        "value"=>[],"options"=>[]);
+                }
+                if($filed['is_sort_enabled'] == 't'){
+                    $sortByOptions[] = $filed['field_db'];
+                }
+
+                $temp = array();
+                $temp['field'] = $filed['field_display_name'];
+                $temp['title'] = $filed['field_display_name_user'];
+                $temp['type'] = $filed['field_db'] == "Status" ? "status" : "normal";
+                $temp['formatter'] = "";
+                $tableColumns[] = $temp;
+            }
+            $dataReturn['tableColumns'] =  $tableColumns;
+            $dataReturn['filtersList'] =  $filtersList;
+            if(!empty($sortByOptions)){
+                $dataReturn['sortBy'] =  array("field"=>$sortByOptions[0],"options"=>$sortByOptions,"order"=>"asc");
+            }else{
+                $dataReturn['sortBy'] =  array("field"=>"","options"=>[],"order"=>"asc");
+            }
             
-            common::excuteListSql("select * from kln_report_field_config where template_serial_no = '".$serial_no."' and field_type = 'System' order by id ");
-           
+            $reportFiled = common::excuteObjectSql("select report_sql,count_sql from public.kln_report_template where serial_no = '".$serial_no."'");
+            $report_sql = $reportFiled["report_sql"];
+            $count_sql = $reportFiled["count_sql"];
 
-            //第一次进来,把查询放到一起了
-            $cp = 10;
-            $ps = 1;
-            $rc = $_POST ['rc'];
-            if ($rc == - 1) {
-                $sql = "select count(*) from public.kln_report_template where " ;
-                $rc = common::excuteOneSql($sql);
+            $filterSQLArr = $this->returnFilterSql($filtersList);
+            //return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
+            $report_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $report_sql);
+            $report_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $report_sql);
+            $report_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $report_sql);
+            
+
+            //查询data
+            $cp = common::check_input($_POST ['cp']); //current_page
+            $ps = common::check_input($_POST ['ps']); //ps
+            if (empty($ps))
+                $ps = 10;
+            if (empty($cp))
+                $cp = 1;
+           
+            if (true) {
+                $count_sql = str_replace('<{orderby}>', "", $count_sql);
+                error_log($count_sql);
+                $rc = common::excuteOneSql($count_sql);
             }
             $tp = ceil($rc / $ps);
             if ($rc > 0) {
-                $sql = "select name,description from public.kln_report_template where " ;
-                $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
-                $rs = common::excuteListSql($sql);
+                $report_sql = str_replace('<{orderby}>', $this->returnSortBySql(), $report_sql);
+                $tmp_search_without_limit = $report_sql;
+                $report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
+                error_log($report_sql);
+
+                $rs = common::excuteListSql($report_sql);
                 $arrTmp = array('searchData' => $rs, 
                         'rc' => intval($rc),
                         'ps' => intval($ps),
                         'cp' => intval($cp),
                         'tp' => intval($tp));
-                common::echo_json_encode(200,$arrTmp);
-                exit();
             }else{
                 $arrTmp = array('searchData' => array());
-                common::echo_json_encode(200, $arrTmp);
-                exit();
             }
+            $dataReturn['tableData'] =  $arrTmp;
+            $dataReturn['tmp_search'] =  common::deCode($tmp_search_without_limit, 'E');
+            common::echo_json_encode(200, $dataReturn);
+            exit();
+        }
+
+        /*
+         * export excel
+        */
+        if ($operate == "excel") {
+            $sql = common::deCode($_POST['tmp_search'], 'D');
+            if(!empty($sql)){
+                $rs = common::excuteListSql($sql);
+            }
+            //去除null
+            foreach($rs as $index => $val) {
+                foreach($val as $index_2 => $_val) {
+                    if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
+                        $rs[$index][$index_2] = "";
+                    }
+                }
+            }
+            common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
+            exit;
+        }
+
+        if ($operate == "manage_fileds") {
+            $serial_no = common::check_input($_POST ['serial_no']); 
+            $reportFiled = common::excuteListSql("select * from public.kln_report_field_config 
+                where template_serial_no = '".$serial_no."' 
+                    and field_type = 'System' order by id ");
+            $showData = array();
+            $hideData = array();    
+            foreach($reportFiled as $_reportFiled){
+                $_reportFiled['is_filter_enabled'] = $_reportFiled['is_filter_enabled'] == 't' ? true : false;
+                $_reportFiled['is_sort_enabled'] = $_reportFiled['is_sort_enabled'] == 't' ? true : false;
+                if($_reportFiled['is_enabled'] == 't'){
+                    $showData[] = $_reportFiled;
+                }else{
+                    $hideData[] = $_reportFiled;
+                }
+            }    
+            common::echo_json_encode(200,array("msg"=>"success","showData" => $showData,"hideData" => $hideData));
+            exit;
+        }
+        if ($operate == "manage_fileds_save") {
+            $serial_no = common::check_input($_POST['serial_no']); 
+            $fieldsList = $_POST['fieldsList'];
+            //先删除,后添加  因为不涉及系统配置字段,全部用kln_report_field_config 字段name
+            $sql = "delete from  public.kln_report_field_config where template_serial_no = '$serial_no';";
+            foreach($fieldsList as $key =>$_tempFieldsList){
+                $_field_id = empty($_tempFieldsList['field_id'])? "NULL": $_tempFieldsList['field_id'];
+                $_field_level = common::check_input($_tempFieldsList['field_level']);
+                $_field_type = common::check_input($_tempFieldsList['field_type']);
+                $_field_group_name = common::check_input($_tempFieldsList['field_group_name']);
+                $_field_db = common::check_input($_tempFieldsList['field_db']);
+                $_field_code = common::check_input($_tempFieldsList['field_display_name']);
+                $_display_name = common::check_input($_tempFieldsList['field_display_name_user']);
+                $_data_type = common::check_input($_tempFieldsList['data_type']);
+                $_value_type = common::check_input($_tempFieldsList['custom_value_type']);
+                $_fixed_value = common::check_input($_tempFieldsList['custom_fixed_value']);
+                $_is_filter_enabled = $_tempFieldsList['is_filter_enabled'];
+                $_is_sort_enabled = $_tempFieldsList['is_sort_enabled'];
+                $sql .=  "INSERT INTO public.kln_report_field_config(
+                            template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
+                            field_display_name, field_display_name_user, data_type, custom_value_type, 
+                            custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
+                    VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name', 
+                            '$_field_code', '$_display_name', '$_data_type', '$_value_type', 
+                            '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
+            }
+            if (!empty($sql)){
+                common::excuteUpdateSql($sql);
+                $data = array("msg" =>"success");
+            }
+
+            common::echo_json_encode(200,array("msg"=>"success","Data" => ''));
+            exit;
+        }
+    }
+
+    /**
+     * 根据提交的参数动态的拼接filter sql
+     */
+    public function returnFilterSql($filtersList){
+        $klnOceanDb = common::getReportRealDBFiled("klnOceanDb");
+        $ocItemDb = common::getReportRealDBFiled("ocItemDb");
+
+        $vvSearchKLN = " where 1=1 ";
+        $klnOceanSearchKLN = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
+        $ocItemSearchKLN = " where 1=1 ";
+
+        foreach($filtersList as $fiter){
+            if(!empty($_POST[$fiter['field']])){
+                $key = array_search($fiter['field'], $klnOceanDb);
+                $ockey = array_search($fiter['field'], $ocItemDb);
+                if($key !== false){
+                    //找到给key
+                    if ($fiter['data_type'] == "string"){
+                        $klnOceanSearchKLN .= " and ".$key." = '". common::check_input($_POST[$fiter['field']])."'"; 
+                    } elseif ($fiter['data_type'] == "number"){
+                        $klnOceanSearchKLN .= " and ".$key." >= '". common::check_input($_POST[$fiter['field']."_from"])."'"; 
+                        $klnOceanSearchKLN .= " and ".$key." <= '". common::check_input($_POST[$fiter['field']."_to"])."'"; 
+                    } elseif ($fiter['data_type'] == "date"){
+                        $date_from = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_from"]) . ' 00:00:00');
+                        $date_to = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_to"]) . ' 23:59:59');
+                        $klnOceanSearchKLN .= " and ".$key." >= '". $date_from."'"; 
+                        $klnOceanSearchKLN .= " and ".$key." <= '". $date_to."'"; 
+                    }
+                } elseif ($ockey !== false){
+                    //找到给key
+                    if ($fiter['data_type'] == "string"){
+                        $ocItemSearchKLN .= " and ".$ockey." = '". common::check_input($_POST[$fiter['field']])."'"; 
+                    } elseif ($fiter['data_type'] == "number"){
+                        $ocItemSearchKLN .= " and ".$ockey." >= '". common::check_input($_POST[$fiter['field']."_from"])."'"; 
+                        $ocItemSearchKLN .= " and ".$ockey." <= '". common::check_input($_POST[$fiter['field']."_to"])."'"; 
+                    } elseif ($fiter['data_type'] == "date"){
+                        $date_from = common::check_input(common::usDate2sqlDate($_POST[$fiter['field']."_from"]) . ' 00:00:00');
+                        $date_to = common::check_input(common::usDate2sqlDate($_POST[$fiter['field']."_to"]) . ' 23:59:59');
+                        $ocItemSearchKLN .= " and ".$ockey." >= '". $date_from."'"; 
+                        $ocItemSearchKLN .= " and ".$ockey." <= '". $date_to."'"; 
+                    }
+                } else {
+                    if ($fiter['data_type'] == "string"){
+                        $vvSearchKLN .= " and \"".$fiter['field']."\" ilike '%". common::check_input($_POST [$fiter['field']])."%'"; 
+                    } elseif ($fiter['data_type'] == "number"){
+                        $vvSearchKLN .= " and \"".$fiter['field']."\" >= '". common::check_input($_POST [$fiter['field']."_from"])."'"; 
+                        $vvSearchKLN .= " and \"".$fiter['field']."\" <= '". common::check_input($_POST [$fiter['field']."_to"])."'"; 
+                    } elseif ($fiter['data_type'] == "date"){
+                        $date_from = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_from"]) . ' 00:00:00');
+                        $date_to = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_to"]) . ' 23:59:59');
+                        //先判断日期字符串是否为空,这里则有做 是因为sql 整合了柜子315时间,和 milestone的时间, 只能text转date
+                        $vvSearchKLN .= " and COALESCE(\"".$fiter['field']."\",''::text)<> ''::text ";  
+                        $vvSearchKLN .= " and to_timestamp(\"".$fiter['field']."\", 'MM/DD/YYYY HH24:MI:SS') >= '". $date_from."'"; 
+                        $vvSearchKLN .= " and to_timestamp(\"".$fiter['field']."\", 'MM/DD/YYYY HH24:MI:SS') <= '". $date_to."'"; 
+                    }
+                }
+            }
+        }
+        
+        return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
+    }
+
+    /**
+     * 根据提交的参数动态的拼接sort by sql
+     */
+    public function returnSortBySql(){
+        $sortByField = $_POST['sortByField'];
+        $sortByOrder = $_POST['sortByOrder'];
+
+        $sort_sql_temp = " ";
+        if(!empty($sortByField) && !empty($sortByOrder)){
+            $sort_sql_temp = " order by \"".$sortByField."\" ". $sortByOrder;
         }
+        return  $sort_sql_temp;
     }
 }
 

+ 88 - 0
utils/common.class.php

@@ -4411,5 +4411,93 @@ class common {
         }
         return $columns;
     }
+
+    public static function getReportRealDBFiled($type){
+        $kln_ocean = [
+            "oo.tracking_no"=>"Tracking No.",
+            "oo.m_bol"=>"MBOL/MAWB No.",
+            "oo.h_bol"=>"HBOL/HAWB No.",
+            "oo.invoice_no"=>"Invoice No.",
+            "oo.booking_no"=>"Booking No.",
+            //"oo.po_no"=>"Shipment PO No.",
+            "oo.quote_no"=>"Quote No.",
+            "oo.carrier_booking"=>"Carrier Booking No.",
+            "oo.contract"=>"Contract No.",
+            "oo.manifest_hbol"=>"Manifest HBOL",
+            "oo.transport_mode"=>"Transportation Mode",
+            "oo.service"=>"Service Type",
+            //"oe.manifest_type"=>"Shipment Type",
+            "oo.ex_im"=>"EX/IM",
+            "oo.incoterms"=>"Incoterms",
+            //"oe.loadterm"=>"Load Terms",
+            "oo.status"=>"Status",
+            "oo.carbon_emission"=>"CO2 Emission",
+            "oo.qty"=>"Shipment Qty",
+            "oo.piece_count"=>"Shipment Gross Weight",
+            "oo.weight"=>"Chargeable Weight",
+            //"oe.volume"=>"Shipment Volume",
+            "oo.shipper"=>"Shipper", 
+            "oo.shipper_id"=>"Shipper ID",
+            "oo.consignee"=>"Consignee",
+            "oo.consignee_id"=>"Consignee ID",
+            "oo.notify_party"=>"Notify party",
+            "oo.notify_party_id"=>"Notify party ID",
+            "oo.billto"=>"Bill to",
+            "oo.group_name"=>"Group Name",
+            "oo.origin"=>"Origin Agent",
+            "oo.agent"=>"Destination Agent",
+            "oo.dest_op"=>"Destination Operator",
+            "oo.sales_rep"=>"Sales",
+            "oo.etd"=>"ETD",
+            "oo.eta"=>"ETA",
+            "oo.created_time"=>"Creation Time",
+            "oo.atd"=>"ATD",
+            "oo.ata"=>"ATA",
+            "oo.shipper_city"=>"Shipper City",
+            "oo.consignee_city"=>"Consignee City",
+            "oo.place_of_receipt_exp"=>"Place of Receipt",
+            "oo.port_of_loading"=>"Port of Loading",
+            "oo.port_of_discharge"=>"Port of Discharge",
+            "oo.place_of_delivery_exp"=>"Place of delivery",
+            "oo.port_of_transshipment_name"=>"Port of Transhipment",
+            "oo.carrier"=>"Carrier",
+            //"oo.voyage"=>"Voyage/Flight",
+            //"oo.vessel"=>"Vessel/Airline",
+            "oo.ams_status"=>"ACE-M1 Status",
+            "oo.isisf"=>"Is ISF",
+            "oo.obl_set"=>"OBL_SET"];
+
+        $other = [
+            "oc.ctnr"=>"Container No.",
+            "oc.size"=>"Container Size",
+            "oc.qty"=>"Container Qty",
+            "oc.unit"=>"Container Unit",
+            "oc.grs_kgs"=>"Container Weight",
+            "oc.cbm"=>"Container Volume",
+            "oc.po_no"=>"Container PO No.",
+            "oc.item_no"=>"Item No.",
+            "oc.invoice_no"=>"Invoice No.",
+            "oi.po_no"=>"Item PO No.",
+            "oi.sku_no"=>"SKU NO.",
+            "oi.quantity"=>"Item Qty",
+            "oi.unit"=>"Item Unit",
+            "oi.grs_kgs"=>"Item Weight",
+            "oi.vol_cbm"=>"Item Volume",
+            "oi.description"=>"Description",
+            "oi.inner_pcs"=>"Inner PCS"]; 
+            
+        if($type == "klnOceanDb") 
+            return  $kln_ocean; 
+        else 
+            return  $other; 
+    }
+
+    public static function toPgTextArrayLiteral(array $arr): string {
+        if (empty($arr)) {
+            return "'{}'";
+        }
+        $quoted = array_map(fn($v) => '"' . addcslashes((string)$v, '"\\') . '"', $arr);
+        return "'{" . implode(',', $quoted) . "}'";
+    }
 }
 ?>