ShuanghongS 1 月之前
父節點
當前提交
18d1520020
共有 5 個文件被更改,包括 354 次插入73 次删除
  1. 5 1
      main_new_version.php
  2. 77 0
      service/ajax.class.php
  3. 89 0
      service/column.class.php
  4. 5 5
      service/ocean_order.class.php
  5. 178 67
      service/report.class.php

+ 5 - 1
main_new_version.php

@@ -21,6 +21,7 @@ include 'service/tools.class.php';
 include 'service/robot.class.php';
 include 'service/AIClientFactory.php';
 include 'service/destination_delivery.class.php';
+include 'service/report.class.php';
 
 //为了调用,临时做一个登录动作  如果是正式版 要注释掉菜单System Settings
  //$_POST['uname'] = "ra.admin";
@@ -830,7 +831,10 @@ switch ($action) {
         break; 
     case 'destination_delivery_booking':
         destination_delivery::getInstance()->destination_delivery_booking();
-        break;                            
+        break;
+    case 'report_config':
+        report::getInstance()->report_config();
+        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");

+ 77 - 0
service/ajax.class.php

@@ -39,6 +39,9 @@ class ajax {
                 break;
             case 'autoport':
                 return json_encode($this->autoPort());
+                break;
+            case 'autody_extend':
+                return json_encode($this->autody_extend());
                 break;        
             default :
                 break;
@@ -239,6 +242,80 @@ class ajax {
         }
     }
 
+    public function autody_extend(){
+        $term = $_POST['term'];
+        $type = $_POST['type'];
+        $append = $_POST['append'];
+        if (utils::checkExist($term, ";") && $append != 'f') {
+            $input = substr($term, 0, strripos($term, ";"));
+            $term = substr($term, strripos($term, ";") + 1);
+        }
+        $term = trim($term);
+    
+        if (strtolower($type) == "contact_group") {
+            $_curr_schemas = $_POST['model'];
+            if (empty($_curr_schemas)) {
+                $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
+                if (empty($_curr_schemas)) {
+                    $_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) . "%'";
+            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) == "apex") {
+            $_curr_schemas = $_POST['model'];
+            if (empty($_curr_schemas)) {
+                $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
+                if (empty($_curr_schemas)) {
+                    $_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) . "%')";
+            } 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) . "%')";
+            }
+            if (!empty($input))
+                $sql .= " and lower(contact_id) " . utils::getInSql($input, TRUE);
+            $sql .= " order by contact_id limit 20";
+        }
+
+
+        $rs = common::excuteListSql($sql);
+
+        foreach ($rs as $value) {
+            $array[] = array(
+                'label' => $value['code'],
+                'id' => $value['id'],
+                'code' => $value['code']
+            );
+        }
+        common::echo_json_encode(200,$array);
+        exit();
+    }
+
     public function autoPort_old() {
         $cp = common::check_input($_POST ['cp']); //current_page
         $ps = common::check_input($_POST ['ps']); //ps

+ 89 - 0
service/column.class.php

@@ -16,6 +16,70 @@ class column {
         return self::$_column;
     }
 
+    public function settingDisplayForVIPReport() {
+        $data = array();
+        //判断是否重置
+        $level = common::check_input($_POST['level']);
+        $serial_no = common::check_input($_POST['serial_no']);
+        $defualt = common::check_input($_POST['defualt']);
+
+        if($level == "Shipment level"){
+            $levelSQlWhere = "level = 'Shipment level'";
+            $rightSqlwhere = " and shipment_level_default = true order by shipment_level_default_order";
+            $leftSqlwhere = " and coalesce(shipment_level_default,false) = false";
+        }elseif($level == "Container Level"){
+            $levelSQlWhere = "level in ('Shipment level','Container Level')";
+            $rightSqlwhere = " and ctnr_level_default = true order by ctnr_level_default_order";
+            $leftSqlwhere = " and coalesce(ctnr_level_default,false) = false";
+        }else {
+            $levelSQlWhere = " 1=1 ";
+            $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 ";
+
+        $allData = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." order by id");
+        if(empty($serial_no) || $defualt == 'true'){
+                //代表第一次添加或者用户恢复默认顺序
+                $groupSetting = common::excuteListSql("select  ".$kln_report_field_str." from public.kln_report_field where  ".$levelSQlWhere."  ".$rightSqlwhere);
+                $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");
+                $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') 
+                        order by id");
+        }
+
+        $children['All'] = array();
+        $children['Reference No.'] = array();
+        $children['General'] = array();
+        $children['Parties'] = array();
+        $children['Packing'] = array();
+        $children['Time'] = array();
+        $children['Places'] = array();
+        $children['Transportation'] = array();
+        $children['Milestone'] = array();
+        $children['Container info'] = array();
+        $children['Container Status'] = array();
+        $children['Item info'] = array();
+        $children['Others'] = array();
+
+        $groupColumns_all = $this->allGroupVipReprotColumns($allData,$children);
+        //总分组的检索要去掉右边的已经选中的部分
+        $groupColumns_left = $this->allGroupVipReprotColumns($dataLeft,$children);
+            
+        $data['GroupColumnsAll'] = $groupColumns_all;
+        $data['GroupColumnsLeft'] = $groupColumns_left;
+        $data['GroupColumnsRight'] = $groupSetting;
+
+        common::echo_json_encode(200,$data);
+        exit;
+    }
+
     public function settingDisplay($model_name, $url, $type = null) {
         $data = array();
         //判断是否重置
@@ -364,6 +428,31 @@ class column {
         }
         return $groupColumns;
     }
+
+    /**
+     * 通用返回setting vip_reprot 分组数据
+     */
+    public function allGroupVipReprotColumns($allData,$children){
+        foreach ($allData as $key => $data) {
+            //固定ALl的分组
+            if (array_key_exists("All", $children)) {
+                $temp = $children['All'];
+                $temp[] = $data;
+                $children['All'] = $temp;
+            } 
+            if (array_key_exists($data['group_name'], $children)) {
+                $temp = $children[$data['group_name']];
+                $temp[] = $data;
+                $children[$data['group_name']] = $temp;
+            } 
+        }
+
+        $groupColumns  = array();
+        foreach ($children as $k => $ch) {
+            $groupColumns[] = array("name"=>$k,"children" =>$ch);
+        }
+        return $groupColumns;
+    }
 }
 
 ?>

File diff suppressed because it is too large
+ 5 - 5
service/ocean_order.class.php


+ 178 - 67
service/report.class.php

@@ -39,14 +39,31 @@ class report {
             if (empty($cp))
                 $cp = 1;
 
+            $sqlWhere = "1=1";
+            $text_search = $_POST['text_search'];
+            if (!empty($text_search)){
+                $sqlWhere .= " and (lower(name) like '%".strtolower($text_search)."%')";
+            }
+            if(!empty($_POST['application_scope'])){
+                $pplication_scope =  $_POST['application_scope'] =='all' ? "All Users" : "Specific Users";
+                $sqlWhere .= " and access_type ='". common::check_input($pplication_scope)."'";
+            }
+            if(!empty($_POST['is_active'])){
+                if($_POST['is_active'] == 't'){
+                    $sqlWhere .= " and is_active = true";
+                }else{
+                    $sqlWhere .= " and is_active = false";
+                }
+            }
+
             $rc = $_POST ['rc'];
             if ($rc == - 1) {
-                $sql = "select count(*) from public.kln_report_template";
+                $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
                 $rc = common::excuteOneSql($sql);
             }
             $tp = ceil($rc / $ps);
             if ($rc > 0) {
-                $sql = "select * from public.kln_report_template";
+                $sql = "select * from public.kln_report_template where " .$sqlWhere;
                 $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
                 $rs = common::excuteListSql($sql);
                 $arrTmp = array('searchData' => $rs, 
@@ -64,45 +81,67 @@ class report {
         }
 
         if ($operate == "add"){
-            $id = common::deCode($_REQUEST['id'], 'D');
-            if(!empty($id)){
+            $serial_no = common::deCode($_REQUEST['serial_no'], 'D');
+            if(!empty($serial_no)){
                 //代表编辑
-                $reportMain = common::excuteObjectSql("select * from kln_report_template where id = $id");
-                $reportField = common::excuteListSql("select * from kln_report_field_config  where template_id = $id order by order_index");
-                $data = array("reportMain" => $reportMain,"reportField" =>$reportField);
+                $reportMain = common::excuteObjectSql("select *,
+                        array_to_json(party_ids) as party_ids_json,
+                        array_to_json(group_names) as group_names_json
+                    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");
+                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;
+                    $reportFields[] = $_reportField;
+                }
+
+                $reportAccess = array("type"=>$reportMain['access_type'],
+                    "partyId"=>json_decode($reportMain['party_ids_json'],true),
+                    "groupName"=>json_decode($reportMain['group_names_json'],true));
+                $data = array("reportName"=>$reportMain['name'],"reportLevel"=>$reportMain['level'],"reportDescription"=>$reportMain['description'],
+                    "reportFields"=>$reportFields,"reportAccess"=>$reportAccess);
             }else{
-                $data = array("reportMain" =>array(),"reportField" =>array());
+                $data = array();
             }
             common::echo_json_encode(200,$data);                
             exit(); 
         }
        
         if ($operate == "report_field_load"){
-            $level = common::check_input($_POST['level']);
-            $template_id = common::check_input($_POST['template_id']);
-
-            $all_field = common::excuteListSql("select * from public.kln_report_field where level = '$level' order by id");
-
-            $right_field = common::excuteListSql("select * from public.kln_report_field_config where template_id = '$template_id' order by id");
-
-            $left_field = common::excuteListSql("select * from public.kln_report_field where level = '$level' 
-                    and id != ALL(select field_ids from public.kln_report_template where id = '$template_id') order by id");
-            
-                    
+            column::getInstance()->settingDisplayForVIPReport();
         }
 
         if ($operate == "save"){
-            $template_id = common::deCode($_POST['template_id'], 'D');
-            $name = common::check_input($_POST['name']);
-            $description = common::check_input($_POST['description']);
-            $level = common::check_input($_POST['level']);
+            $serial_no = common::deCode($_POST['serial_no'], 'D');
+            $name = common::check_input($_POST['report_name']);
+            $description = common::check_input($_POST['report_description']);
+            $level = common::check_input($_POST['report_level']);
             $access_type = common::check_input($_POST['access_type']);
             $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'");
             $sql = "";
             if (!empty($serial_no)){
-                $updateSqlSet = " modify_by = '"._getLoginName()."',update_time = now()";
+                $updateSqlSet = " report_sql = '$report_sql', modify_by = '"._getLoginName()."',update_time = now()";
                 if (!empty($name)) {
                     $updateSqlSet.= ", name = '$name' ";
                 }
@@ -123,19 +162,63 @@ class report {
                     $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
                     $updateSqlSet.= ", group_names = '{".$pgsql_array."}'::text[]";
                 }
+                if (!empty($field_ids)) {
+                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
+                    $updateSqlSet.= ", field_ids = '{".$pgsql_array."}'::INTEGER[]";
+                }
                 //代表update 
-                $sql .= "update public.kln_report_config set ".$updateSqlSet."
+                $sql .= "update public.kln_report_template set ".$updateSqlSet."
                     where serial_no = '$serial_no';";
             } else {
-                //检查配置的站点是否于以前的配置的,是否重合
-                
+                $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[]";
+                }
+
+                $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[]";
+                }
+
+                $ids_filed = null;
+                if (!empty($field_ids)) {
+                    $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
+                    $ids_filed = "'{".$pgsql_array."}'::INTEGER[]";
+                }
+
+                $serial_no = common::uuid();
+                $sql .= "INSERT INTO public.kln_report_template(
+                                serial_no,name, description, level, field_ids, access_type, report_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());";
             }
 
             $errmsg = "";
             //柜子是先删除,后添加
-            $sql .= "delete from  public.kln_report_rule where recommended_delivery_serial_no = '';";
-           
+            $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];
+                $sql .=  "INSERT INTO public.kln_report_field_config(
+                            template_serial_no, 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, created_time)
+                    VALUES ('$serial_no', '$_field_id', '$_field_level', '$_ield_type', '$_field_db', 
+                            '$_field_code', '$_display_name', '$_data_type', '$_value_type', 
+                            '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
 
+            }
             if (empty($errmsg) && !empty($sql)){
                 common::excuteUpdateSql($sql);
                 $data = array("msg" =>"success");
@@ -148,9 +231,8 @@ class report {
 
         if ($operate == "delete"){
             $serial_no = common::deCode($_POST['a'], 'D');
-            $sql = "delete from public.kln_report_config where serial_no = '$serial_no';";
-            $sql .= "delete from public.kln_report_rule where recommended_delivery_serial_no = '$serial_no';";
-            error_log($sql);
+            $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';";
             common::excuteUpdateSql($sql);
             $data = array("msg" =>"success");
             common::echo_json_encode(200,$data);                
@@ -167,45 +249,74 @@ class report {
         $operate = strtolower($operate);
 
         if ($operate == "report_search") {
-            //search
-            //栏位信息
-            $column = column::getInstance()->getDisplayColumn('report_Search');
-            $BookingTableColumns = column::getInstance()->tableColumns('report_Search',$column);
-            $data['TrackingTableColumns'] = $BookingTableColumns;
-            common::echo_json_encode(200,$data);
-            exit();
+           $cp = common::check_input($_POST ['cp']); //current_page
+            $ps = common::check_input($_POST ['ps']); //ps
+            if (empty($ps))
+                $ps = 100;
+            if (empty($cp))
+                $cp = 1;
+
+            $sqlWhere = "1=1 and is_active = true";
+            $text_search = $_POST['text_search'];
+            if (!empty($text_search)){
+                $sqlWhere .= " and (lower(name) like '%".strtolower($text_search)."%')";
+            }
+           
+            $rc = $_POST ['rc'];
+            if ($rc == - 1) {
+                $sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
+                $rc = common::excuteOneSql($sql);
+            }
+            $tp = ceil($rc / $ps);
+            if ($rc > 0) {
+                $sql = "select name,description from public.kln_report_template where " .$sqlWhere;
+                $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
+                $rs = common::excuteListSql($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();
+            }
         }
-    }
 
-    /**
-     * 关于report 页面的所有的静态加载数据查询
-    */
-    public function report_load(){
-        $operate = utils::_get('operate');
-        $operate = strtolower($operate);
+        if ($operate == "report_detail") {
+            $serial_no = common::check_input($_POST ['serial_no']); 
+            
+            common::excuteListSql("select * from kln_report_field_config where template_serial_no = '".$serial_no."' and field_type = 'System' order by id ");
+           
 
-        /**
-         * select country
-         */
-        if ($operate == "country") {
-            $term = $_POST['term'];
-            $term = trim($term);
-            $sql = "select DISTINCT category AS country_code from public.kerry_system_code
-                        where description='COUNTRY-STATION' 
-                              and category ilike '" . common::check_input($term) . "%'";
-            $sql .= " order by category";
-
-            $rs = common::excuteListSql($sql);
-            //前端要加上id 从1开始
-            $retData = array();
-            foreach($rs as $key => $val){
-                if(!empty($val['country_code'])){
-                    $retData[] = array("value" =>$val['country_code'] ,"label"=>$val['country_code']);
-                }
+            //第一次进来,把查询放到一起了
+            $cp = 10;
+            $ps = 1;
+            $rc = $_POST ['rc'];
+            if ($rc == - 1) {
+                $sql = "select count(*) from public.kln_report_template where " ;
+                $rc = common::excuteOneSql($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);
+                $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();
             }
-            common::echo_json_encode(200,$retData);
-            exit();
-
         }
     }
 }

Some files were not shown because too many files changed in this diff