column.class.php 21 KB

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