column.class.php 21 KB

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