ajax.class.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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. $rs = common::excuteListSql($sql);
  274. foreach ($rs as $value) {
  275. $array[] = array(
  276. 'label' => $value['code'],
  277. 'id' => $value['id'],
  278. 'code' => $value['code']
  279. );
  280. }
  281. common::echo_json_encode(200,$array);
  282. exit();
  283. }
  284. public function autoPort_old() {
  285. $cp = common::check_input($_POST ['cp']); //current_page
  286. $ps = common::check_input($_POST ['ps']); //ps
  287. if (empty($ps))
  288. $ps = 20;
  289. $term = $_POST['term'];
  290. $term = trim($term);
  291. $_curr_schemas = $_POST['model'];
  292. if (empty($_curr_schemas)) {
  293. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  294. if (empty($_curr_schemas)) {
  295. $_curr_schemas = "public";
  296. }
  297. }
  298. $rc = $_POST ['rc'];
  299. if ($rc == - 1) {
  300. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  301. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  302. $rc = common::excuteOneSql($sql);
  303. }
  304. $tp = ceil($rc / $ps);
  305. if ($rc > 0) {
  306. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  307. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  308. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  309. $rs = common::excuteListSql($sql);
  310. //前端要加上id 从1开始
  311. $retData = array();
  312. foreach($rs as $key => $val){
  313. if(!empty($val['country'])){
  314. $val["id"] = $key +1;
  315. $retData[] = $val;
  316. }
  317. }
  318. $arrTmp = array('searchData' => $retData,
  319. 'rc' => $rc,
  320. 'ps' => $ps,
  321. 'cp' => $cp,
  322. 'tp' => $tp);
  323. common::echo_json_encode(200,$arrTmp);
  324. exit();
  325. }else{
  326. $arrTmp = array('searchData' => array());
  327. common::echo_json_encode(200, $arrTmp);
  328. exit();
  329. }
  330. }
  331. public function autody_old() {
  332. $term = $_POST['term'];
  333. $type = $_POST['type'];
  334. $term = trim($term);
  335. if (strtolower($type) == "apex") {
  336. $_curr_schemas = $_POST['model'];
  337. if (empty($_curr_schemas)) {
  338. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  339. if (empty($_curr_schemas)) {
  340. $_curr_schemas = "public";
  341. }
  342. }
  343. if ($_curr_schemas == "public") {
  344. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  345. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  346. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  347. } else {
  348. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  349. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  350. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  351. }
  352. $sql .= " order by contact_id limit 20";
  353. $rs = common::excuteListSql($sql);
  354. }
  355. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  356. if (strtolower($type) == "contanct") {
  357. $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) . "%')";
  358. $sql .= " order by contact_id limit 20";
  359. $rs = common::excuteListSql($sql);
  360. }
  361. if (strtolower($type) == "sales") {
  362. $_curr_schemas = $_POST['model'];
  363. if (empty($_curr_schemas)) {
  364. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  365. if (empty($_curr_schemas)) {
  366. $_curr_schemas = "public";
  367. }
  368. }
  369. $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) . "%')";
  370. $sql .= " order by salesopcode limit 20";
  371. }
  372. if (strtolower($type) == "vessel") {
  373. $vessel = $_POST['vessel'];
  374. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  375. $sql .= " order by vessel limit 20";
  376. }
  377. $rs = common::excuteListSql($sql);
  378. $array = array();
  379. foreach($rs as $v){
  380. if(!empty($v['code'])){
  381. $array[] = $v['code'];
  382. }
  383. }
  384. common::echo_json_encode(200,$array);
  385. exit();
  386. }
  387. public function getTrackingSearchWhere(){
  388. $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
  389. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  390. if (!empty($_REQUEST["_reportRef"])) {
  391. $_reportType = $_REQUEST["_reportType"];
  392. $_reportRef = $_REQUEST["_reportRef"];
  393. if ($_reportType == "r3") {
  394. if ($_reportRef == "Previous 7 Days") {
  395. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  396. } else if ($_reportRef == "0 Day") {
  397. $sqlWhere .= " and eta=current_date";
  398. } else if ($_reportRef == "1-2 Days") {
  399. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  400. } else if ($_reportRef == "3-6 Days") {
  401. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  402. } else if ($_reportRef == "7 Days") {
  403. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  404. } else {
  405. $sqlWhere .= " and 1<>1";
  406. }
  407. } else if ($_reportType == "r4") {
  408. if ($_reportRef == "Previous 7 Days") {
  409. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  410. } else if ($_reportRef == "0 Day") {
  411. $sqlWhere .= " and etd=current_date";
  412. } else if ($_reportRef == "1-2 Days") {
  413. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  414. } else if ($_reportRef == "3-6 Days") {
  415. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  416. } else if ($_reportRef == "7 Days") {
  417. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  418. } else {
  419. $sqlWhere .= " and 1<>1";
  420. }
  421. } else if ($_reportType == "ata_r3") {
  422. if ($_reportRef == "0 Day") {
  423. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  424. } else if ($_reportRef == "1-2 Days") {
  425. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  426. } else if ($_reportRef == "3-6 Days") {
  427. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  428. } else if ($_reportRef == "7 Days") {
  429. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  430. } else {
  431. $sqlWhere .= " and 1<>1";
  432. }
  433. } else if ($_reportType == "atd_r4") {
  434. if ($_reportRef == "0 Day") {
  435. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  436. } else if ($_reportRef == "1-2 Days") {
  437. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  438. } else if ($_reportRef == "3-6 Days") {
  439. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  440. } else if ($_reportRef == "7 Days") {
  441. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  442. } else {
  443. $sqlWhere .= " and 1<>1";
  444. }
  445. } else if ($_reportType == "top") {
  446. if (!empty($_reportRef)) {
  447. $_reportStationType = $_REQUEST["_reportStationType"];
  448. if($_reportStationType == 'shippr_uncode'){
  449. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  450. }
  451. if($_reportStationType == 'fport_of_loading_un'){
  452. $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
  453. }
  454. if($_reportStationType == 'consignee_uncode'){
  455. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  456. }
  457. if($_reportStationType == 'mport_of_discharge_un'){
  458. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  459. }
  460. } else {
  461. $sqlWhere .= " and 1<>1";
  462. }
  463. } else if ($_reportType == "co2e") {
  464. $_reportDataType = $_REQUEST["_reportDataType"];
  465. //查询sea 其他的为空
  466. if (!empty($_reportRef) && $_reportDataType == "sea") {
  467. $_reportStationType = $_REQUEST["_reportStationType"];
  468. if($_reportStationType == 'origin'){
  469. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  470. }else{
  471. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  472. }
  473. } else {
  474. $sqlWhere .= " and 1<>1";
  475. }
  476. } else {
  477. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  478. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  479. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  480. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  481. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  482. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  483. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  484. $sqlWhere .= " and (eta-etd)>80";
  485. } else {
  486. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  487. }
  488. }
  489. }
  490. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  491. if (!empty($_POST["_textSearch"])) {
  492. $textSearch_arr = $_POST['_textSearch'];
  493. if(!is_array($textSearch_arr)){
  494. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  495. $textSearch_arr = array($textSearch_arr);
  496. }
  497. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  498. //$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)],''))";
  499. $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))
  500. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
  501. or lower(invoice_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  502. }
  503. return $sqlWhere;
  504. }
  505. public function getBookingSearchWhere(){
  506. $sqlWhere = ' where ' . common::searchExtendHand_KLN("booking", $_SESSION["ONLINE_USER"]);
  507. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  508. //移除掉全文检索 但保留代码
  509. // if (!empty($_POST["_textSearch"])) {
  510. // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
  511. // }
  512. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  513. if (!empty($_POST["_textSearch"])) {
  514. $textSearch_arr = $_POST['_textSearch'];
  515. if(!is_array($textSearch_arr)){
  516. $textSearch_arr = str_replace(",", ";", $textSearch_arr);
  517. $textSearch_arr = array($textSearch_arr);
  518. }
  519. $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
  520. $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
  521. or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
  522. }
  523. return $sqlWhere;
  524. }
  525. PUBLIC function getPortsUncity($search_field,$search_mode,$term){
  526. //uncode 前两位便是 isoname,不用模糊查询这个了
  527. if($search_field == "Origin" && $search_mode == "booking"){
  528. $sqlWhere = $this->getBookingSearchWhere();
  529. $count_sql = "select COUNT(DISTINCT shipper_city)
  530. from public.kln_booking $sqlWhere
  531. and COALESCE(shippr_uncode,'')<>''
  532. and (shipper_city ilike '%" . common::check_input($term) . "%'
  533. or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
  534. $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  535. from public.kln_booking $sqlWhere
  536. and COALESCE(shippr_uncode,'')<>''
  537. and (shipper_city ilike '%" . common::check_input($term) . "%'
  538. or shippr_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  539. return array("count_sql"=>$count_sql,"sql"=>$sql);
  540. }
  541. if($search_field == "Destination" && $search_mode == "booking"){
  542. $sqlWhere = $this->getBookingSearchWhere();
  543. $count_sql = "select count(DISTINCT consignee_city)
  544. from public.kln_booking $sqlWhere
  545. and COALESCE(consignee_uncode,'')<>''
  546. and (consignee_city ilike '%" . common::check_input($term) . "%'
  547. or consignee_uncode ilike '%" . common::check_input($term) . "%') ";
  548. $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  549. from public.kln_booking $sqlWhere
  550. and COALESCE(consignee_uncode,'')<>''
  551. and (consignee_city ilike '%" . common::check_input($term) . "%'
  552. or consignee_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  553. return array("count_sql"=>$count_sql,"sql"=>$sql);
  554. }
  555. if($search_field == "Place of Receipt" && $search_mode == "booking"){
  556. $sqlWhere = $this->getBookingSearchWhere();
  557. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  558. from public.kln_booking $sqlWhere
  559. and COALESCE(place_of_receipt_uncode,'')<>''
  560. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  561. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
  562. $sql = "select left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode
  563. from public.kln_booking $sqlWhere
  564. and COALESCE(place_of_receipt_uncode,'')<>''
  565. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  566. or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  567. return array("count_sql"=>$count_sql,"sql"=>$sql);
  568. }
  569. if($search_field == "Port of Loading" && $search_mode == "booking"){
  570. $sqlWhere = $this->getBookingSearchWhere();
  571. $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
  572. from public.kln_booking $sqlWhere
  573. and COALESCE(fport_of_loading_uncode,'')<>''
  574. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  575. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
  576. $sql = "select left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode
  577. from public.kln_booking $sqlWhere
  578. and COALESCE(fport_of_loading_uncode,'')<>''
  579. and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
  580. or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  581. return array("count_sql"=>$count_sql,"sql"=>$sql);
  582. }
  583. if($search_field == "Place of delivery" && $search_mode == "booking"){
  584. $sqlWhere = $this->getBookingSearchWhere();
  585. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  586. from public.kln_booking $sqlWhere
  587. and COALESCE(place_of_delivery_uncode,'')<>''
  588. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  589. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
  590. $sql = "select left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
  591. from public.kln_booking $sqlWhere
  592. and COALESCE(place_of_delivery_uncode,'')<>''
  593. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  594. or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc";
  595. return array("count_sql"=>$count_sql,"sql"=>$sql);
  596. }
  597. //tracking
  598. $order_by = " etd desc";
  599. if (_isCustomerLogin()) {
  600. $order_by = " eta desc";
  601. }
  602. if($search_field == "Origin" && $search_mode == "tracking"){
  603. $sqlWhere = $this->getTrackingSearchWhere();
  604. $count_sql = "select COUNT(DISTINCT shipper_city)
  605. from public.kln_ocean $sqlWhere
  606. and COALESCE(shippr_uncode,'')<>''
  607. and (shipper_city ilike '%" . common::check_input($term) . "%'
  608. or shippr_uncode ilike '%" . common::check_input($term) . "%')";
  609. $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  610. from public.kln_ocean $sqlWhere
  611. and COALESCE(shippr_uncode,'')<>''
  612. and (shipper_city ilike '%" . common::check_input($term) . "%'
  613. or shippr_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
  614. return array("count_sql"=>$count_sql,"sql"=>$sql);
  615. }
  616. if($search_field == "Destination" && $search_mode == "tracking"){
  617. $sqlWhere = $this->getTrackingSearchWhere();
  618. $count_sql = "select COUNT(DISTINCT consignee_city)
  619. from public.kln_ocean $sqlWhere
  620. and COALESCE(consignee_uncode,'')<>''
  621. and (consignee_city ilike '%" . common::check_input($term) . "%'
  622. or consignee_uncode ilike '%" . common::check_input($term) . "%')";
  623. $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  624. from public.kln_ocean $sqlWhere
  625. and COALESCE(consignee_uncode,'')<>''
  626. and (consignee_city ilike '%" . common::check_input($term) . "%'
  627. or consignee_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
  628. return array("count_sql"=>$count_sql,"sql"=>$sql);
  629. }
  630. if($search_field == "Place of Receipt" && $search_mode == "tracking"){
  631. $sqlWhere = $this->getTrackingSearchWhere();
  632. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  633. from public.kln_ocean $sqlWhere
  634. and COALESCE(place_of_receipt_un,'')<>''
  635. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  636. or place_of_receipt_un ilike '%" . common::check_input($term) . "%')";
  637. $sql = "select left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
  638. from public.kln_ocean $sqlWhere
  639. and COALESCE(place_of_receipt_un,'')<>''
  640. and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
  641. or place_of_receipt_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  642. return array("count_sql"=>$count_sql,"sql"=>$sql);
  643. }
  644. if($search_field == "Port of Loading" && $search_mode == "tracking"){
  645. $sqlWhere = $this->getTrackingSearchWhere();
  646. $count_sql = "select COUNT(DISTINCT port_of_loading)
  647. from public.kln_ocean $sqlWhere
  648. and COALESCE(fport_of_loading_un,'')<>''
  649. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  650. or fport_of_loading_un ilike '%" . common::check_input($term) . "%')";
  651. $sql = "select left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
  652. from public.kln_ocean $sqlWhere
  653. and COALESCE(fport_of_loading_un,'')<>''
  654. and (port_of_loading ilike '%" . common::check_input($term) . "%'
  655. or fport_of_loading_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  656. return array("count_sql"=>$count_sql,"sql"=>$sql);
  657. }
  658. if($search_field == "Place of Discharge" && $search_mode == "tracking"){
  659. $sqlWhere = $this->getTrackingSearchWhere();
  660. $count_sql = "select COUNT(DISTINCT port_of_discharge)
  661. from public.kln_ocean $sqlWhere
  662. and COALESCE(mport_of_discharge_un,'')<>''
  663. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  664. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%')";
  665. $sql = "select left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
  666. from public.kln_ocean $sqlWhere
  667. and COALESCE(mport_of_discharge_un,'')<>''
  668. and (port_of_discharge ilike '%" . common::check_input($term) . "%'
  669. or mport_of_discharge_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  670. return array("count_sql"=>$count_sql,"sql"=>$sql);
  671. }
  672. if($search_field == "Place of delivery" && $search_mode == "tracking"){
  673. $sqlWhere = $this->getTrackingSearchWhere();
  674. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  675. from public.kln_ocean $sqlWhere
  676. and COALESCE(place_of_delivery_un,'')<>''
  677. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  678. or place_of_delivery_un ilike '%" . common::check_input($term) . "%')";
  679. $sql = "select left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
  680. from public.kln_ocean $sqlWhere
  681. and COALESCE(place_of_delivery_un,'')<>''
  682. and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
  683. or place_of_delivery_un ilike '%" . common::check_input($term) . "%') order by $order_by";
  684. return array("count_sql"=>$count_sql,"sql"=>$sql);
  685. }
  686. }
  687. }
  688. ?>