column.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. class column {
  6. private static $_column;
  7. public static function getInstance() {
  8. if (!self::$_column) {
  9. $c = __CLASS__;
  10. self::$_column = new $c;
  11. }
  12. return self::$_column;
  13. }
  14. public function settingDisplayForVIPReport() {
  15. $data = array();
  16. //判断是否重置
  17. $level = common::check_input($_REQUEST['level']);
  18. $serial_no = common::check_input($_REQUEST['serial_no']);
  19. $defualt = common::check_input($_REQUEST['default']);
  20. if(strtolower($level) == strtolower("Shipment Level")){
  21. //这个是kln_report_field level :"Shipment level" 不变
  22. $levelSQlWhere = " is_enabled = true and level = 'Shipment level'";
  23. $rightSqlwhere = " and is_enabled = true and shipment_level_default = true order by shipment_level_default_order";
  24. $leftSqlwhere = " and is_enabled = true and coalesce(shipment_level_default,false) = false";
  25. }elseif(strtolower($level) == strtolower("Container Level")){
  26. $levelSQlWhere = "is_enabled = true and level in ('Shipment level','Container Level')";
  27. $rightSqlwhere = " and is_enabled = true and ctnr_level_default = true order by ctnr_level_default_order";
  28. $leftSqlwhere = " and coalesce(ctnr_level_default,false) = false";
  29. }else {
  30. $levelSQlWhere = " is_enabled = true and 1=1 ";
  31. $rightSqlwhere = " and is_enabled = true and item_level_default = true order by item_level_default_order";
  32. $leftSqlwhere = " and is_enabled = true and coalesce(item_level_default,false) = false";
  33. }
  34. $kln_report_field_str = " id as ids,
  35. code as \"fieldBb\",
  36. display_name as field,
  37. display_name as label,
  38. level as \"fieldLevel\",
  39. 'System' as \"fieldType\",
  40. data_type as \"dataType\",
  41. is_field_data_mapping as \"isFieldDataMapping\",
  42. group_name as \"groupName\" ";
  43. $kln_report_field_config = " field_id as ids,
  44. field_db as \"fieldBb\",
  45. field_display_name as field,
  46. field_display_name as label,
  47. field_level as \"fieldLevel\",
  48. field_type as \"fieldType\",
  49. data_type as \"dataType\",
  50. (select is_field_data_mapping from public.kln_report_field where display_name = field_display_name limit 1) as \"isFieldDataMapping\",
  51. field_group_name as \"groupName\" ";
  52. $allData = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." order by id");
  53. if ($defualt == 'true'){
  54. //代表第一次添加或者用户恢复默认顺序
  55. $groupSetting = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." ".$rightSqlwhere);
  56. $dataLeft = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." ".$leftSqlwhere." order by id");
  57. }else{
  58. // $groupSetting = common::excuteListSql("select ".$kln_report_field_config." from public.kln_report_field_config
  59. // where template_serial_no = '$serial_no' and field_type = 'System' order by id");
  60. // $dataLeft = common::excuteListSql("select ".$kln_report_field_str."from public.kln_report_field
  61. // where lower(level) = '".strtolower($level)."' and id != ALL(select field_ids from public.kln_report_template where serial_no = '$serial_no' and field_type = 'System')
  62. // order by id");
  63. }
  64. $children['All'] = array();
  65. $children['Reference No.'] = array();
  66. $children['General'] = array();
  67. $children['CO2 Emission'] = array();
  68. $children['Parties'] = array();
  69. $children['Packing'] = array();
  70. $children['Time'] = array();
  71. $children['Places'] = array();
  72. $children['Transportation'] = array();
  73. $children['Milestone'] = array();
  74. $children['Container info'] = array();
  75. $children['Container Status'] = array();
  76. $children['Item info'] = array();
  77. $children['Others'] = array();
  78. $groupColumns_all = $this->allGroupVipReprotColumns($allData,$children);
  79. //总分组的检索要去掉右边的已经选中的部分
  80. $groupColumns_left = $this->allGroupVipReprotColumns($dataLeft,$children);
  81. $data['GroupColumnsAll'] = $groupColumns_all;
  82. $data['GroupColumnsLeft'] = $groupColumns_left;
  83. $data['GroupColumnsRight'] = $groupSetting;
  84. //false特殊逻辑
  85. if ($defualt == 'false'){
  86. $data['GroupColumnsAll'] = $groupColumns_all;
  87. $data['GroupColumnsLeft'] = $groupColumns_all;
  88. $data['GroupColumnsRight'] = array();
  89. }
  90. common::echo_json_encode(200,$data);
  91. exit;
  92. }
  93. public function settingDisplay($model_name, $url, $type = null) {
  94. $data = array();
  95. //判断是否重置
  96. if(!empty($_REQUEST['reset']) && $_REQUEST['reset'] == "yes"){
  97. // common::excuteUpdateSql("update ra_online_search_display_config_cso set ids = ''
  98. // where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'");
  99. }
  100. if (empty($type)) {
  101. if($model_name <> 'destination_delivery_shipment_search'){
  102. //预先初始化,空的也要保留
  103. $children['All'] = array();
  104. $children['Reference No.'] = array();
  105. $children['General'] = array();
  106. $children['Parties'] = array();
  107. $children['Packing'] = array();
  108. $children['Time'] = array();
  109. $children['Places'] = array();
  110. $children['Transportation'] = array();
  111. $children['Others'] = array();
  112. }else{
  113. //预先初始化,空的也要保留.只需要ALL
  114. $children['All'] = array();
  115. }
  116. $allData = $this->getDisplayColumnAllReomveDefault($model_name);
  117. $groupColumns_all = $this->allGroupColumns($allData,$children);
  118. //总分组的检索要去掉右边的已经选中的部分
  119. $dataLeft = $this->getDisplayColumn($model_name,false);
  120. $groupColumns_left = $this->allGroupColumns($dataLeft,$children);
  121. $setting = $this->getDisplayColumn($model_name);
  122. $groupSetting = $this->groupColumnsSetting($setting);
  123. $data['GroupColumnsAll'] = $groupColumns_all;
  124. $data['GroupColumnsLeft'] = $groupColumns_left;
  125. $data['GroupColumnsRight'] = $groupSetting;
  126. }
  127. //search目前页面没有
  128. //$data['search_setting'] = search::getInstance()->getDisplayColumn($model_name);
  129. //$data['search_diff'] = search::getInstance()->getDisplayColumn($model_name, FALSE);
  130. $data['model_name'] = $model_name;
  131. $data['url'] = $url;
  132. common::echo_json_encode(200,$data);
  133. exit;
  134. }
  135. //改为从新的配置表和配置信息,与旧的分开
  136. public function getDisplayColumn($model_name, $isin = true) {
  137. //测试服务器,改为UAT字段
  138. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  139. $model_name = "UAT_".$model_name;
  140. }
  141. $rs = null;
  142. $sql = "select ids from public.ra_online_search_display_config_cso where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'";
  143. $rs = common::excuteOneSql($sql);
  144. if(!empty($_REQUEST['reset']) && $_REQUEST['reset'] == "yes"){
  145. $rs = array();
  146. }
  147. if (empty($rs)) {
  148. $sql = "select array_to_string(array(select id from public.ra_online_search_display_cso where active = true and default_display = true and lower(model_name) = '" . strtolower($model_name) . "'";
  149. if (_isCustomerLogin())
  150. $sql .= " and customer_display = true";
  151. $sql .= " order by default_order asc), ',')";
  152. $rs = common::excuteOneSql($sql);
  153. }
  154. if ($isin) {
  155. $sql = $this->_getSql($rs);
  156. $rss = common::excuteListSql($sql);
  157. } else {
  158. $sql = "SELECT id, display_name as name, database_column_name, column_width,group_name FROM public.ra_online_search_display_cso WHERE active = true and lower(model_name) = '" . strtolower($model_name) . "' and id not in ($rs)";
  159. if (_isCustomerLogin())
  160. $sql .= ' and customer_display=true';
  161. $rss = common::excuteListSql($sql);
  162. }
  163. //旧版本去除新加__字段
  164. $action = strtolower($_REQUEST['action']);
  165. if (Soure == 'TopOcean' && empty(common::isNewVersion())
  166. && ($action =="ocean_order" || $action == "ocean_booking" || $action == "containers")){
  167. $rss = common::removeTopOceanOldVersionSpecialField($rss);
  168. }
  169. return $rss;
  170. }
  171. public function _getSql($ids) {
  172. $ids_arr = explode(',', $ids);
  173. $sql = "";
  174. foreach ($ids_arr as $value) {
  175. if (!empty($value)) {
  176. if (empty($sql)) {
  177. $sql .= 'SELECT id, display_name as name, database_column_name,column_width,group_name FROM public.ra_online_search_display_cso where active=true and id = ' . $value;
  178. if (_isCustomerLogin())
  179. $sql .= ' and CUSTOMER_DISPLAY = true';
  180. } else {
  181. $sql .= ' union all SELECT id, display_name as name, database_column_name,column_width,group_name FROM public.ra_online_search_display_cso where active=true and id = ' . $value;
  182. if (_isCustomerLogin())
  183. $sql .= ' and CUSTOMER_DISPLAY = true';
  184. }
  185. }
  186. }
  187. return $sql;
  188. }
  189. public function saveSettingDisplay($newid, $search_id, $model_name) {
  190. //测试服务器,改为UAT字段
  191. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  192. $model_name = "UAT_".$model_name;
  193. }
  194. global $db;
  195. $login_name = _getLoginName();
  196. $db->StartTrans();
  197. if ($this->checkUserDisplaySetting($model_name) === TRUE) {
  198. $sql = "UPDATE public.ra_online_search_display_config_cso SET ids = '" . common::check_input($newid) . "' WHERE lower(model_name) = '" . common::check_input(strtolower($model_name)) . "' AND lower(login_name) = '" . common::check_input(strtolower($login_name)) . "'";
  199. } else {
  200. $sql = "INSERT INTO public.ra_online_search_display_config_cso (LOGIN_NAME, MODEL_NAME, ids) VALUES ('" . common::check_input($login_name) . "', '" . common::check_input($model_name) . "', '" . common::check_input($newid) . "')";
  201. }
  202. //search 部分的数据不做查询
  203. //search::getInstance()->saveSettingDisplay($search_id, $model_name);
  204. common::excuteUpdateSql($sql);
  205. $db->CompleteTrans();
  206. }
  207. /*
  208. * check user had setting display
  209. */
  210. public function checkUserDisplaySetting($model_name) {
  211. $login_name = _getLoginName();
  212. $sql = "select ids from public.ra_online_search_display_config_cso where lower(login_name)='" . strtolower($login_name) . "' and lower(model_name) = '" . strtolower($model_name) . "'"; //check login_name is setting
  213. $rs = common::excuteObjectSql($sql);
  214. if (!empty($rs)) {
  215. return TRUE;
  216. }
  217. return FALSE;
  218. }
  219. public function getSearchSql($model_name) {
  220. //测试服务器,改为UAT字段
  221. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  222. $model_name = "UAT_".$model_name;
  223. }
  224. $sql = "";
  225. $ss = "SELECT database_column_name, display_name FROM public.ra_online_search_display_cso WHERE lower(model_name) = '" . strtolower($model_name) . "'";
  226. if (_isCustomerLogin())
  227. $ss .= ' and customer_display=true';
  228. $rss = common::excuteListSql($ss);
  229. //旧版本去除新加__字段
  230. $action = strtolower($_REQUEST['action']);
  231. $rss = common::removeTopOceanOldVersionSpecialField($rss);
  232. //不和以前重命名有冲突,改为database_column_name,display 显示由固定配置设置
  233. foreach ($rss as $v) {
  234. if ($sql == '')
  235. $sql .= $v['database_column_name'];
  236. else
  237. $sql .= ',' . $v['database_column_name'];
  238. }
  239. return ' ' . $sql . ' ';
  240. }
  241. //search 查询
  242. public function getSearchSqlForDisplay($model_name) {
  243. //测试服务器,改为UAT字段
  244. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  245. $model_name = "UAT_".$model_name;
  246. }
  247. $sql = "";
  248. $ss = "SELECT database_column_name, display_name FROM public.ra_online_search_display_cso WHERE lower(model_name) = '" . strtolower($model_name) . "'";
  249. if (_isCustomerLogin())
  250. $ss .= ' and customer_display=true';
  251. $rss = common::excuteListSql($ss);
  252. //旧版本去除新加__字段
  253. $action = strtolower($_REQUEST['action']);
  254. $rss = common::removeTopOceanOldVersionSpecialField($rss);
  255. foreach ($rss as $v) {
  256. if($v['database_column_name'] == "other_refenrence_no" && $model_name = "Ocean_Search"){
  257. continue;
  258. }
  259. if (empty($v['database_column_name'])) {
  260. if ($sql == '')
  261. $sql .= '\'' . $v['display_name'] . '\'';
  262. else
  263. $sql .= ', \'' . $v['display_name'] . '\'';
  264. }else {
  265. if ($sql == '')
  266. $sql .= $v['database_column_name'] . ' as "' . $v['display_name'] . '"';
  267. else
  268. $sql .= ', ' . $v['database_column_name'] . ' as "' . $v['display_name'] . '"';
  269. }
  270. }
  271. return ' ' . $sql . ' ';
  272. }
  273. public function getDisplayColumnAll($model_name) {
  274. $sql = "SELECT id, display_name as name, database_column_name as db,database_column_name, column_width,group_name FROM public.ra_online_search_display_cso WHERE default_display = true and active=true and lower(model_name) = '" . strtolower($model_name) . "'";
  275. if (_isCustomerLogin())
  276. $sql .= ' and customer_display=true';
  277. $sql .= " order by order_by,display_name";
  278. $rss = common::excuteListSql($sql);
  279. return $rss;
  280. }
  281. public function getDisplayColumnAllReomveDefault($model_name) {
  282. //测试服务器,改为UAT字段
  283. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  284. $model_name = "UAT_".$model_name;
  285. }
  286. $sql = "SELECT id, display_name as name, database_column_name as db,database_column_name, column_width,group_name FROM public.ra_online_search_display_cso WHERE active=true and lower(model_name) = '" . strtolower($model_name) . "'";
  287. if (_isCustomerLogin())
  288. $sql .= ' and customer_display=true';
  289. $sql .= " order by order_by";
  290. $rss = common::excuteListSql($sql);
  291. return $rss;
  292. }
  293. public function tableColumns($type,$column){
  294. $tableColumns = array();
  295. foreach ($column as $key => $rs) {
  296. $temp = array();
  297. $temp['field'] = $rs['database_column_name'];
  298. $temp['title'] = $rs['name'];
  299. $spconfig = $this->specialTableConfig($type);
  300. if (!empty($spconfig[$rs['database_column_name']]['type'])){
  301. $temp['type'] = $spconfig[$rs['database_column_name']]['type'];
  302. }else{
  303. $temp['type'] = "normal";
  304. }
  305. //formatter
  306. if (!empty($spconfig[$rs['database_column_name']]['formatter'])){
  307. $temp['formatter'] = $spconfig[$rs['database_column_name']]['formatter'];
  308. if($temp['formatter'] == "number"){
  309. $temp['digits'] = $spconfig[$rs['database_column_name']]['digits'];
  310. }
  311. }else{
  312. $temp['formatter'] = "";
  313. }
  314. //这两个的field 不用as display
  315. if(!($type == "Destination_Delivery_Search" || $type == "destination_delivery_shipment_search")){
  316. $temp['field'] = $rs['name'];
  317. }
  318. $tableColumns[] = $temp;
  319. }
  320. return $tableColumns;
  321. }
  322. public function groupColumnsSetting($column){
  323. $groupSetting = array();
  324. foreach ($column as $key => $rs) {
  325. $temp = array();
  326. $temp['ids'] = $rs['id'];
  327. $temp['field'] = $rs['database_column_name'];
  328. $temp['label'] = $rs['name'];
  329. $groupSetting[] = $temp;
  330. }
  331. return $groupSetting;
  332. }
  333. public function specialTableConfig($type){
  334. if ($type == "Booking_Search"){
  335. return array("booking_no" =>array("type" =>"link"),
  336. "h_bol" =>array("type" =>"link"),
  337. "mode" =>array("type" =>"mode"),
  338. "transport_mode" =>array("type" =>"mode"),
  339. "status" =>array("type" =>"status"),
  340. "created_time" =>array("formatter" =>"dateTime"),
  341. "confirmation_time" =>array("formatter" =>"dateTime"),
  342. "f_etd" =>array("formatter" =>"date"),
  343. "m_eta" =>array("formatter" =>"date"),
  344. "qty" =>array("formatter" =>"number","digits"=>0),
  345. "piece_count" =>array("formatter" =>"number","digits"=>3),
  346. "weight" =>array("formatter" =>"number","digits"=>3));
  347. }
  348. if ($type == "Ocean_Search"){
  349. return array("booking_no" =>array("type" =>"link"),
  350. "h_bol" =>array("type" =>"link"),
  351. "mode" =>array("type" =>"mode"),
  352. "transport_mode" =>array("type" =>"mode"),
  353. "status" =>array("type" =>"status"),
  354. "created_time" =>array("formatter" =>"dateTime"),
  355. "etd" =>array("formatter" =>"date"),
  356. "eta" =>array("formatter" =>"date"),
  357. "qty" =>array("formatter" =>"number","digits"=>0),
  358. "piece_count" =>array("formatter" =>"number","digits"=>3),
  359. "weight" =>array("formatter" =>"number","digits"=>3),
  360. "cbm" =>array("formatter" =>"number","digits"=>3));
  361. }
  362. if ($type == "Operation_Search"){
  363. return array("operation_time" =>array("formatter" =>"dateTime"));
  364. }
  365. if ($type == "Robot_Chat_Search"){
  366. return array("request_time" =>array("formatter" =>"dateTime"),
  367. "response_time" =>array("formatter" =>"dateTime"));
  368. }
  369. if ($type == "Robot_API_Search"){
  370. return array("request_time" =>array("formatter" =>"dateTime"),
  371. "response_time" =>array("formatter" =>"dateTime"),
  372. "request_id" =>array("type" =>"link"));
  373. }
  374. if ($type == "Destination_Delivery_Search"){
  375. return array("delivery_date" =>array("formatter" =>"date"),
  376. "created_time" =>array("formatter" =>"date"),
  377. "status" =>array("type" =>"status"),
  378. "h_bol" =>array("type" =>"multiple_link"),
  379. "date_range" =>array("formatter" =>"range"));
  380. }
  381. if ($type == "destination_delivery_shipment_search"){
  382. return array("eta" =>array("formatter" =>"date"),
  383. "ata" =>array("formatter" =>"date"),
  384. "date_range" =>array("type" =>"recommend"),
  385. "packing_list" =>array("type" =>"download"),
  386. "commercial_invoice" =>array("type" =>"download"));
  387. }
  388. }
  389. /**
  390. * 通用返回setting 分组数据
  391. */
  392. public function allGroupColumns($allData,$children){
  393. foreach ($allData as $key => $data) {
  394. //固定ALl的分组
  395. if (array_key_exists("All", $children)) {
  396. $temp = $children['All'];
  397. $temp[] = array("ids"=>$data['id'],"label"=>$data['name'],"field"=>$data['database_column_name']);
  398. $children['All'] = $temp;
  399. }
  400. if (array_key_exists($data['group_name'], $children)) {
  401. $temp = $children[$data['group_name']];
  402. $temp[] = array("ids"=>$data['id'],"label"=>$data['name'],"field"=>$data['database_column_name']);
  403. $children[$data['group_name']] = $temp;
  404. }
  405. }
  406. $groupColumns = array();
  407. foreach ($children as $k => $ch) {
  408. $groupColumns[] = array("name"=>$k,"children" =>$ch);
  409. }
  410. return $groupColumns;
  411. }
  412. /**
  413. * 通用返回setting vip_reprot 分组数据
  414. */
  415. public function allGroupVipReprotColumns($allData,$children){
  416. foreach ($allData as $key => $data) {
  417. //固定ALl的分组
  418. if (array_key_exists("All", $children)) {
  419. $temp = $children['All'];
  420. $temp[] = $data;
  421. $children['All'] = $temp;
  422. }
  423. if (array_key_exists($data['groupName'], $children)) {
  424. $temp = $children[$data['groupName']];
  425. $temp[] = $data;
  426. $children[$data['groupName']] = $temp;
  427. }
  428. }
  429. $groupColumns = array();
  430. foreach ($children as $k => $ch) {
  431. $groupColumns[] = array("name"=>$k,"children" =>$ch);
  432. }
  433. return $groupColumns;
  434. }
  435. }
  436. ?>