column.class.php 21 KB

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