ajax.class.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. /**
  6. * Description of auto
  7. *
  8. * @author Administrator
  9. */
  10. class ajax {
  11. private static $_ajax;
  12. public static function getInstance() {
  13. if (!self::$_ajax) {
  14. $c = __CLASS__;
  15. self::$_ajax = new $c;
  16. }
  17. return self::$_ajax;
  18. }
  19. public function run() {
  20. $time = time() - $_SESSION["LAST_OPERATE_TIME"];
  21. if ($time > $_SESSION['SESSION_TIMEOUT']) {
  22. exit(json_encode("session_time_out"));
  23. } else {
  24. $_SESSION["LAST_OPERATE_TIME"] = time();
  25. }
  26. $operate = utils::_get('operate');
  27. $operate = strtolower($operate);
  28. switch ($operate) {
  29. case 'save_setting_display':
  30. $this->save_setting_display();
  31. break;
  32. case 'autody':
  33. return json_encode($this->autody());
  34. break;
  35. case 'autoport':
  36. return json_encode($this->autoPort());
  37. break;
  38. case 'autody_extend':
  39. return json_encode($this->autody_extend());
  40. break;
  41. default :
  42. break;
  43. }
  44. }
  45. public function save_setting_display() {
  46. $ids = $_POST['ids'];
  47. if(!empty($ids)){
  48. $ss = utils::implode(",", $_POST['ids']);
  49. column::getInstance()->saveSettingDisplay(utils::implode(",", $_POST['ids']),"", $_POST['model_name']);
  50. $data = array(
  51. 'msg' => 'success'
  52. );
  53. common::echo_json_encode(200,$data);
  54. }else{
  55. $data = array(
  56. 'msg' => 'data error'
  57. );
  58. common::echo_json_encode(500,$data);
  59. }
  60. }
  61. //不查询全局的信息,查询该用户,最近3个月内输入过的信息自动补全
  62. public function autody(){
  63. //分担查询
  64. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  65. $term = $_POST['term'];
  66. $type = $_POST['type'];
  67. $search_field = $_POST['search_field'];
  68. $search_mode = $_POST['search_mode'];
  69. $term = trim($term);
  70. if (strtolower($type) == "apex" || strtolower($type) == "contanct" || strtolower($type) == "sales"
  71. || strtolower($type) == "vessel" || strtolower($type) == "voyage") {
  72. if($search_mode == "tracking"){
  73. $sqlWhere = $this->getTrackingSearchWhere();
  74. }elseif($search_mode == "booking"){
  75. $sqlWhere = $this->getBookingSearchWhere();
  76. }
  77. //Notify Party Bill to Destination Operator 是tracking里的,但booking没有,所以不影响
  78. $search_field_mapping = array("Origin Agent"=>"origin as code",
  79. "Destination Agent"=>"agent as code",
  80. "Shipper Name"=>"shipper as code",
  81. "Consignee Name"=>"consignee as code",
  82. "Notify Party" =>"notify_party as code",
  83. "Bill to" =>"billto as code",
  84. "Destination Operator"=>"dest_op as code",
  85. "Sales"=>"sales_rep as code",
  86. "Voyage/Flight_booking"=>"f_voyage as code,m_voyage as code_2",
  87. "Vessel_booking"=>"f_vessel as code,m_vessel as code_2",
  88. "Voyage/Flight_tracking"=>"voyage as code,f_voyage as code_2",
  89. "Vessel_tracking"=>"vessel as code,f_vessel as code_2");
  90. $search_field_group_mapping = array("Origin Agent"=>"group by origin",
  91. "Destination Agent"=>"group by agent",
  92. "Shipper Name"=>"group by shipper",
  93. "Consignee Name"=>"group by consignee",
  94. "Notify Party" =>"group by notify_party",
  95. "Bill to" =>"group by billto",
  96. "Destination Operator"=>"group by dest_op",
  97. "Sales"=>"group by sales_rep",
  98. "Voyage/Flight_booking"=>"group by f_voyage,m_voyage",
  99. "Vessel_booking"=>"group by f_vessel,m_vessel",
  100. "Voyage/Flight_tracking"=>"group by voyage,f_voyage",
  101. "Vessel_tracking"=>"group by vessel,f_vessel");
  102. $sql_where_mapping = array("Origin Agent"=>" and (origin ilike '%" . common::check_input($term) . "%')",
  103. "Destination Agent"=>" and (agent ilike '%" . common::check_input($term) . "%')",
  104. "Shipper Name"=>" and (shipper ilike '%" . common::check_input($term) . "%')",
  105. "Consignee Name"=>" and (consignee ilike '%" . common::check_input($term) . "%')",
  106. "Notify Party"=>" and (notify_party ilike '%" . common::check_input($term) . "%')",
  107. "Bill to"=>" and (billto ilike '%" . common::check_input($term) . "%')",
  108. "Destination Operator"=>" and (dest_op ilike '%" . common::check_input($term) . "%')",
  109. "Sales"=>" and (sales_rep ilike '%" . common::check_input($term) . "%')",
  110. "Voyage/Flight_booking"=>" and (f_voyage ilike '%" . common::check_input($term) . "%' or m_voyage ilike '%" . common::check_input($term) . "%')",
  111. "Vessel_booking"=>" and (f_vessel ilike '%" . common::check_input($term) . "%' or m_vessel ilike '%" . common::check_input($term) . "%')",
  112. "Voyage/Flight_tracking"=>" and (voyage ilike '%" . common::check_input($term) . "%' or f_voyage ilike '%" . common::check_input($term) . "%')",
  113. "Vessel_tracking"=>" and (vessel ilike '%" . common::check_input($term) . "%' or f_vessel ilike '%" . common::check_input($term) . "%')");
  114. //特殊处理一下合并Voyage和Vessel
  115. $_search_field = $search_field;
  116. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  117. $_str = $search_mode == "tracking" ? "tracking" : "booking";
  118. $_search_field = $search_field ."_".$_str;
  119. }
  120. $str = $search_field_mapping[$_search_field];
  121. $sql_where = $sql_where_mapping[$_search_field];
  122. $group_by = $search_field_group_mapping[$_search_field];
  123. $table = $search_mode == "tracking" ? "public.kln_ocean " : "public.kln_booking ";
  124. // if($search_mode == "booking"){
  125. // $order_by = " f_etd desc";
  126. // }else{
  127. // $order_by = " etd desc";
  128. // if (_isCustomerLogin()) {
  129. // $order_by = " eta desc";
  130. // }
  131. // }
  132. //$sql = "select DISTINCT * from (select $str from $table $sqlWhere $sql_where order by $order_by ) as temp";
  133. //$sql .= " order by code limit 20";
  134. if($search_mode == "booking"){
  135. $order_by = " max(f_etd) desc";
  136. }else{
  137. $order_by = " max(etd) desc";
  138. if (_isCustomerLogin()) {
  139. $order_by = " max(eta) desc";
  140. }
  141. }
  142. $sql = "select $str from $table $sqlWhere $sql_where $group_by order by $order_by";
  143. $sql .= " limit 20";
  144. }
  145. if(!empty($sql)){
  146. //$rs = common::excuteListSql($sql);
  147. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  148. error_log($sql);
  149. }
  150. $array = array();
  151. foreach($rs as $v){
  152. if(!empty($v['code'])){
  153. $array[] = $v['code'];
  154. }
  155. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  156. $array[] = $v['code_2'];
  157. }
  158. }
  159. $array = utils::removeDuplicateArray($array);
  160. common::echo_json_encode(200,$array);
  161. exit();
  162. }
  163. public function autoPort() {
  164. //分担查询
  165. include ONLINE_ROOT . 'libs' . DS . 'map_config.ini.php';
  166. $cp = common::check_input($_POST ['cp']); //current_page
  167. $ps = common::check_input($_POST ['ps']); //ps
  168. if (empty($ps))
  169. $ps = 20;
  170. $term = $_POST['term'];
  171. $term = trim($term);
  172. $search_field = $_POST['search_field'];
  173. $search_mode = $_POST['search_mode'];
  174. $_sql_arr = $this->getPortsUncity($search_field,$search_mode,$term);
  175. $rc = $_POST ['rc'];
  176. if ($rc == - 1) {
  177. $sql = $_sql_arr['count_sql'];
  178. //$rc = common::excuteOneSql($sql);
  179. $rc = $mapdb->GetOne($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  180. error_log($sql);
  181. }
  182. $tp = ceil($rc / $ps);
  183. if ($rc > 0) {
  184. $sql = $_sql_arr['sql'];
  185. $sql = "select DISTINCT ON (city) country, city,uncode from ($sql) as temp ";
  186. $sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
  187. //$rs = common::excuteListSql($sql);
  188. $rs = $mapdb->GetAll($sql) or ( (!$mapdb->ErrorMsg()) or error_log(common::dbLog($mapdb, $sql), 0));
  189. error_log($sql);
  190. //前端要加上id 从1开始
  191. $retData = array();
  192. $i = 0;
  193. foreach($rs as $key => $val){
  194. if($search_field == "Port of Loading"){
  195. if(!empty($val['uncode'])){
  196. $val["id"] = $i +1;
  197. $retData[] = $val;
  198. $i = $i +1;
  199. }
  200. }else{
  201. if(!empty($val['city'])){
  202. $val["id"] = $i +1;
  203. $retData[] = $val;
  204. $i = $i +1;
  205. }
  206. }
  207. }
  208. $arrTmp = array('searchData' => $retData,
  209. 'rc' => $rc,
  210. 'ps' => $ps,
  211. 'cp' => $cp,
  212. 'tp' => $tp);
  213. common::echo_json_encode(200,$arrTmp);
  214. exit();
  215. }else{
  216. $arrTmp = array('searchData' => array(), 'rc' => 0);
  217. common::echo_json_encode(200, $arrTmp);
  218. exit();
  219. }
  220. }
  221. public function autody_extend(){
  222. $term = $_POST['term'];
  223. $type = $_POST['type'];
  224. $append = $_POST['append'];
  225. if (utils::checkExist($term, ";") && $append != 'f') {
  226. $input = substr($term, 0, strripos($term, ";"));
  227. $term = substr($term, strripos($term, ";") + 1);
  228. }
  229. $term = trim($term);
  230. if (strtolower($type) == "contact_group") {
  231. $_curr_schemas = $_POST['model'];
  232. if (empty($_curr_schemas)) {
  233. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  234. if (empty($_curr_schemas)) {
  235. $_curr_schemas = "public";
  236. }
  237. }
  238. $sql = "SELECT company_name as code, contacts_id as id from $_curr_schemas.contacts_group where company_name ilike '" . common::check_input($term) . "%'";
  239. if (!empty($input))
  240. $sql .= " and lower(company_name) " . utils::getInSql($input, TRUE);
  241. $sql .= " order by company_name limit 20";
  242. }
  243. // if (strtolower($type) == "contact_group_user") {
  244. // $_curr_schemas = $_POST['model'];
  245. // if (empty($_curr_schemas)) {
  246. // $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  247. // if (empty($_curr_schemas)) {
  248. // $_curr_schemas = "public";
  249. // }
  250. // }
  251. // $sql = "SELECT contacts_id as id, company_name as code from $_curr_schemas.contacts_group where contacts_id ilike '%" . common::check_input($term) . "%'";
  252. // if (!empty($input))
  253. // $sql .= " and lower(contacts_id) " . utils::getInSql($input, TRUE);
  254. // $sql .= " order by company_name limit 20";
  255. // }
  256. if (strtolower($type) == "apex") {
  257. $_curr_schemas = $_POST['model'];
  258. if (empty($_curr_schemas)) {
  259. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  260. if (empty($_curr_schemas)) {
  261. $_curr_schemas = "public";
  262. }
  263. }
  264. if ($_curr_schemas == "public") {//apex ocean和air 分开
  265. $sql = "SELECT contact_id as code, company as id from ocean.contacts where contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%'";
  266. } else {
  267. $sql = "SELECT contact_id as code, company as id from $_curr_schemas.contacts where contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%'";
  268. }
  269. if (!empty($input))
  270. $sql .= " and lower(contact_id) " . utils::getInSql($input, TRUE);
  271. $sql .= " order by contact_id limit 20";
  272. }
  273. //system account
  274. if (strtolower($type) == "system_account") {
  275. $sql = "SELECT user_login as code, user_id as id from public.ra_online_user where user_login ilike '" . common::check_input($term) . "%'";
  276. if (!empty($input))
  277. $sql .= " and lower(user_login) " . utils::getInSql($input, TRUE);
  278. $sql .= " order by user_login limit 20";
  279. }
  280. $rs = common::excuteListSql($sql);
  281. foreach ($rs as $value) {
  282. $array[] = array(
  283. 'label' => $value['code'],
  284. 'id' => $value['id'],
  285. 'code' => $value['code']
  286. );
  287. }
  288. common::echo_json_encode(200,$array);
  289. exit();
  290. }
  291. public function autoPort_old() {
  292. $cp = common::check_input($_POST ['cp']); //current_page
  293. $ps = common::check_input($_POST ['ps']); //ps
  294. if (empty($ps))
  295. $ps = 20;
  296. $term = $_POST['term'];
  297. $term = trim($term);
  298. $_curr_schemas = $_POST['model'];
  299. if (empty($_curr_schemas)) {
  300. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  301. if (empty($_curr_schemas)) {
  302. $_curr_schemas = "public";
  303. }
  304. }
  305. $rc = $_POST ['rc'];
  306. if ($rc == - 1) {
  307. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  308. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  309. $rc = common::excuteOneSql($sql);
  310. }
  311. $tp = ceil($rc / $ps);
  312. if ($rc > 0) {
  313. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  314. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  315. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  316. $rs = common::excuteListSql($sql);
  317. //前端要加上id 从1开始
  318. $retData = array();
  319. foreach($rs as $key => $val){
  320. if(!empty($val['country'])){
  321. $val["id"] = $key +1;
  322. $retData[] = $val;
  323. }
  324. }
  325. $arrTmp = array('searchData' => $retData,
  326. 'rc' => $rc,
  327. 'ps' => $ps,
  328. 'cp' => $cp,
  329. 'tp' => $tp);
  330. common::echo_json_encode(200,$arrTmp);
  331. exit();
  332. }else{
  333. $arrTmp = array('searchData' => array());
  334. common::echo_json_encode(200, $arrTmp);
  335. exit();
  336. }
  337. }
  338. public function autody_old() {
  339. $term = $_POST['term'];
  340. $type = $_POST['type'];
  341. $term = trim($term);
  342. if (strtolower($type) == "apex") {
  343. $_curr_schemas = $_POST['model'];
  344. if (empty($_curr_schemas)) {
  345. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  346. if (empty($_curr_schemas)) {
  347. $_curr_schemas = "public";
  348. }
  349. }
  350. if ($_curr_schemas == "public") {
  351. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  352. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  353. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  354. } else {
  355. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  356. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  357. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  358. }
  359. $sql .= " order by contact_id limit 20";
  360. $rs = common::excuteListSql($sql);
  361. }
  362. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  363. if (strtolower($type) == "contanct") {
  364. $sql = "SELECT company as code from contact_v where active = true and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  365. $sql .= " order by contact_id limit 20";
  366. $rs = common::excuteListSql($sql);
  367. }
  368. if (strtolower($type) == "sales") {
  369. $_curr_schemas = $_POST['model'];
  370. if (empty($_curr_schemas)) {
  371. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  372. if (empty($_curr_schemas)) {
  373. $_curr_schemas = "public";
  374. }
  375. }
  376. $sql = "SELECT salesopcode as code from $_curr_schemas.employee where salesopcode is not null and salesopcode !='' and (salesopcode ilike '" . common::check_input($term) . "%' or employee_id ilike '" . common::check_input($term) . "%')";
  377. $sql .= " order by salesopcode limit 20";
  378. }
  379. if (strtolower($type) == "vessel") {
  380. $vessel = $_POST['vessel'];
  381. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  382. $sql .= " order by vessel limit 20";
  383. }
  384. $rs = common::excuteListSql($sql);
  385. $array = array();
  386. foreach($rs as $v){
  387. if(!empty($v['code'])){
  388. $array[] = $v['code'];
  389. }
  390. }
  391. common::echo_json_encode(200,$array);
  392. exit();
  393. }
  394. public function getTrackingSearchWhere(){
  395. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  396. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  397. if (!empty($_REQUEST["_reportRef"])) {
  398. $_reportType = $_REQUEST["_reportType"];
  399. $_reportRef = $_REQUEST["_reportRef"];
  400. if ($_reportType == "r3") {
  401. if ($_reportRef == "Previous 7 Days") {
  402. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  403. } else if ($_reportRef == "0 Day") {
  404. $sqlWhere .= " and eta=current_date";
  405. } else if ($_reportRef == "1-2 Days") {
  406. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  407. } else if ($_reportRef == "3-6 Days") {
  408. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  409. } else if ($_reportRef == "7 Days") {
  410. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  411. } else {
  412. $sqlWhere .= " and 1<>1";
  413. }
  414. } else if ($_reportType == "r4") {
  415. if ($_reportRef == "Previous 7 Days") {
  416. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  417. } else if ($_reportRef == "0 Day") {
  418. $sqlWhere .= " and etd=current_date";
  419. } else if ($_reportRef == "1-2 Days") {
  420. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  421. } else if ($_reportRef == "3-6 Days") {
  422. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  423. } else if ($_reportRef == "7 Days") {
  424. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  425. } else {
  426. $sqlWhere .= " and 1<>1";
  427. }
  428. } else if ($_reportType == "ata_r3") {
  429. if ($_reportRef == "0 Day") {
  430. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  431. } else if ($_reportRef == "1-2 Days") {
  432. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  433. } else if ($_reportRef == "3-6 Days") {
  434. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  435. } else if ($_reportRef == "7 Days") {
  436. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  437. } else {
  438. $sqlWhere .= " and 1<>1";
  439. }
  440. } else if ($_reportType == "atd_r4") {
  441. if ($_reportRef == "0 Day") {
  442. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  443. } else if ($_reportRef == "1-2 Days") {
  444. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  445. } else if ($_reportRef == "3-6 Days") {
  446. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  447. } else if ($_reportRef == "7 Days") {
  448. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  449. } else {
  450. $sqlWhere .= " and 1<>1";
  451. }
  452. } else if ($_reportType == "top") {
  453. if (!empty($_reportRef)) {
  454. $_reportStationType = $_REQUEST["_reportStationType"];
  455. if($_reportStationType == 'shippr_uncode'){
  456. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  457. }
  458. if($_reportStationType == 'fport_of_loading_un'){
  459. $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
  460. }
  461. if($_reportStationType == 'consignee_uncode'){
  462. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  463. }
  464. if($_reportStationType == 'mport_of_discharge_un'){
  465. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  466. }
  467. } else {
  468. $sqlWhere .= " and 1<>1";
  469. }
  470. } else if ($_reportType == "co2e") {
  471. $_reportDataType = $_REQUEST["_reportDataType"];
  472. //查询sea 其他的为空
  473. if (!empty($_reportRef) && $_reportDataType == "sea") {
  474. $_reportStationType = $_REQUEST["_reportStationType"];
  475. if($_reportStationType == 'origin'){
  476. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  477. }else{
  478. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  479. }
  480. } else {
  481. $sqlWhere .= " and 1<>1";
  482. }
  483. } else {
  484. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  485. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  486. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  487. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  488. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  489. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  490. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  491. $sqlWhere .= " and (eta-etd)>80";
  492. } else {
  493. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  494. }
  495. }
  496. }
  497. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  498. if (!empty($_POST["_textSearch"])) {
  499. $textSearch_arr = $_POST['_textSearch'];
  500. if(!is_array($textSearch_arr)){
  501. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  502. $textSearch_arr = array($textSearch_arr);
  503. }
  504. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  505. //$sqlWhere .= " and (ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking),lower(tracking_no)],''))";
  506. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(ARRAY[lower(booking_no::text), lower(h_bol::text), lower(m_bol), lower(carrier_booking), lower(quote_no), lower(tracking_no)]||string_to_array(lower(ctnrs),','), ''::text))
  507. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
  508. or lower(invoice_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  509. }
  510. return $sqlWhere;
  511. }
  512. public function getBookingSearchWhere(){
  513. $sqlWhere = ' where ' . common::searchExtendHand_KLN("booking", $_SESSION["ONLINE_USER"]);
  514. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  515. //移除掉全文检索 但保留代码
  516. // if (!empty($_POST["_textSearch"])) {
  517. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  518. // }
  519. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  520. if (!empty($_POST["_textSearch"])) {
  521. $textSearch_arr = $_POST['_textSearch'];
  522. if(!is_array($textSearch_arr)){
  523. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  524. $textSearch_arr = array($textSearch_arr);
  525. }
  526. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  527. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
  528. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  529. }
  530. return $sqlWhere;
  531. }
  532. PUBLIC function getPortsUncity($search_field,$search_mode,$term){
  533. //uncode 前两位便是 isoname,不用模糊查询这个了
  534. if($search_field == "Origin" && $search_mode == "booking"){
  535. $sqlWhere = $this->getBookingSearchWhere();
  536. $count_sql = "select COUNT(DISTINCT shipper_city)
  537. from public.kln_booking $sqlWhere
  538. and COALESCE(shippr_uncode,'')<>''
  539. and (shipper_city ilike '%" . common::check_input($term) . "%'
  540. or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
  541. $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  542. from public.kln_booking $sqlWhere
  543. and COALESCE(shippr_uncode,'')<>''
  544. and (shipper_city ilike '%" . common::check_input($term) . "%'
  545. or shippr_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  546. return array("count_sql"=>$count_sql,"sql"=>$sql);
  547. }
  548. if($search_field == "Destination" && $search_mode == "booking"){
  549. $sqlWhere = $this->getBookingSearchWhere();
  550. $count_sql = "select count(DISTINCT consignee_city)
  551. from public.kln_booking $sqlWhere
  552. and COALESCE(consignee_uncode,'')<>''
  553. and (consignee_city ilike '%" . common::check_input($term) . "%'
  554. or consignee_uncode ilike '%" . common::check_input($term) . "%') ";
  555. $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  556. from public.kln_booking $sqlWhere
  557. and COALESCE(consignee_uncode,'')<>''
  558. and (consignee_city ilike '%" . common::check_input($term) . "%'
  559. or consignee_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  560. return array("count_sql"=>$count_sql,"sql"=>$sql);
  561. }
  562. if($search_field == "Place of Receipt" && $search_mode == "booking"){
  563. $sqlWhere = $this->getBookingSearchWhere();
  564. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  565. from public.kln_booking $sqlWhere
  566. and COALESCE(place_of_receipt_uncode,'')<>''
  567. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  568. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
  569. $sql = "select left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode
  570. from public.kln_booking $sqlWhere
  571. and COALESCE(place_of_receipt_uncode,'')<>''
  572. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  573. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  574. return array("count_sql"=>$count_sql,"sql"=>$sql);
  575. }
  576. if($search_field == "Port of Loading" && $search_mode == "booking"){
  577. $sqlWhere = $this->getBookingSearchWhere();
  578. $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
  579. from public.kln_booking $sqlWhere
  580. and COALESCE(fport_of_loading_uncode,'')<>''
  581. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  582. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
  583. $sql = "select left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode
  584. from public.kln_booking $sqlWhere
  585. and COALESCE(fport_of_loading_uncode,'')<>''
  586. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  587. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  588. return array("count_sql"=>$count_sql,"sql"=>$sql);
  589. }
  590. if($search_field == "Place of delivery" && $search_mode == "booking"){
  591. $sqlWhere = $this->getBookingSearchWhere();
  592. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  593. from public.kln_booking $sqlWhere
  594. and COALESCE(place_of_delivery_uncode,'')<>''
  595. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  596. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
  597. $sql = "select left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
  598. from public.kln_booking $sqlWhere
  599. and COALESCE(place_of_delivery_uncode,'')<>''
  600. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  601. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  602. return array("count_sql"=>$count_sql,"sql"=>$sql);
  603. }
  604. //tracking
  605. $order_by = " etd desc";
  606. if (_isCustomerLogin()) {
  607. $order_by = " eta desc";
  608. }
  609. if($search_field == "Origin" && $search_mode == "tracking"){
  610. $sqlWhere = $this->getTrackingSearchWhere();
  611. $count_sql = "select COUNT(DISTINCT shipper_city)
  612. from public.kln_ocean $sqlWhere
  613. and COALESCE(shippr_uncode,'')<>''
  614. and (shipper_city ilike '%" . common::check_input($term) . "%'
  615. or shippr_uncode ilike '%" . common::check_input($term) . "%')";
  616. $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  617. from public.kln_ocean $sqlWhere
  618. and COALESCE(shippr_uncode,'')<>''
  619. and (shipper_city ilike '%" . common::check_input($term) . "%'
  620. or shippr_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
  621. return array("count_sql"=>$count_sql,"sql"=>$sql);
  622. }
  623. if($search_field == "Destination" && $search_mode == "tracking"){
  624. $sqlWhere = $this->getTrackingSearchWhere();
  625. $count_sql = "select COUNT(DISTINCT consignee_city)
  626. from public.kln_ocean $sqlWhere
  627. and COALESCE(consignee_uncode,'')<>''
  628. and (consignee_city ilike '%" . common::check_input($term) . "%'
  629. or consignee_uncode ilike '%" . common::check_input($term) . "%')";
  630. $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  631. from public.kln_ocean $sqlWhere
  632. and COALESCE(consignee_uncode,'')<>''
  633. and (consignee_city ilike '%" . common::check_input($term) . "%'
  634. or consignee_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
  635. return array("count_sql"=>$count_sql,"sql"=>$sql);
  636. }
  637. if($search_field == "Place of Receipt" && $search_mode == "tracking"){
  638. $sqlWhere = $this->getTrackingSearchWhere();
  639. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  640. from public.kln_ocean $sqlWhere
  641. and COALESCE(place_of_receipt_un,'')<>''
  642. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  643. or place_of_receipt_un ilike '%" . common::check_input($term) . "%')";
  644. $sql = "select left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
  645. from public.kln_ocean $sqlWhere
  646. and COALESCE(place_of_receipt_un,'')<>''
  647. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  648. or place_of_receipt_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  649. return array("count_sql"=>$count_sql,"sql"=>$sql);
  650. }
  651. if($search_field == "Port of Loading" && $search_mode == "tracking"){
  652. $sqlWhere = $this->getTrackingSearchWhere();
  653. $count_sql = "select COUNT(DISTINCT port_of_loading)
  654. from public.kln_ocean $sqlWhere
  655. and COALESCE(fport_of_loading_un,'')<>''
  656. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  657. or fport_of_loading_un ilike '%" . common::check_input($term) . "%')";
  658. $sql = "select left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
  659. from public.kln_ocean $sqlWhere
  660. and COALESCE(fport_of_loading_un,'')<>''
  661. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  662. or fport_of_loading_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  663. return array("count_sql"=>$count_sql,"sql"=>$sql);
  664. }
  665. if($search_field == "Place of Discharge" && $search_mode == "tracking"){
  666. $sqlWhere = $this->getTrackingSearchWhere();
  667. $count_sql = "select COUNT(DISTINCT port_of_discharge)
  668. from public.kln_ocean $sqlWhere
  669. and COALESCE(mport_of_discharge_un,'')<>''
  670. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  671. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%')";
  672. $sql = "select left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
  673. from public.kln_ocean $sqlWhere
  674. and COALESCE(mport_of_discharge_un,'')<>''
  675. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  676. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  677. return array("count_sql"=>$count_sql,"sql"=>$sql);
  678. }
  679. if($search_field == "Place of delivery" && $search_mode == "tracking"){
  680. $sqlWhere = $this->getTrackingSearchWhere();
  681. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  682. from public.kln_ocean $sqlWhere
  683. and COALESCE(place_of_delivery_un,'')<>''
  684. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  685. or place_of_delivery_un ilike '%" . common::check_input($term) . "%')";
  686. $sql = "select left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
  687. from public.kln_ocean $sqlWhere
  688. and COALESCE(place_of_delivery_un,'')<>''
  689. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  690. or place_of_delivery_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  691. return array("count_sql"=>$count_sql,"sql"=>$sql);
  692. }
  693. }
  694. }
  695. ?>