ajax.class.php 38 KB

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