ajax.class.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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. default :
  39. break;
  40. }
  41. }
  42. public function save_setting_display() {
  43. $ids = $_POST['ids'];
  44. if(!empty($ids)){
  45. $ss = utils::implode(",", $_POST['ids']);
  46. column::getInstance()->saveSettingDisplay(utils::implode(",", $_POST['ids']),"", $_POST['model_name']);
  47. $data = array(
  48. 'msg' => 'success'
  49. );
  50. common::echo_json_encode(200,$data);
  51. }else{
  52. $data = array(
  53. 'msg' => 'data error'
  54. );
  55. common::echo_json_encode(500,$data);
  56. }
  57. }
  58. //不查询全局的信息,查询该用户,最近3个月内输入过的信息自动补全
  59. public function autody(){
  60. $term = $_POST['term'];
  61. $type = $_POST['type'];
  62. $search_field = $_POST['search_field'];
  63. $search_mode = $_POST['search_mode'];
  64. $term = trim($term);
  65. if (strtolower($type) == "apex" || strtolower($type) == "contanct" || strtolower($type) == "sales"
  66. || strtolower($type) == "vessel") {
  67. if($search_mode == "tracking"){
  68. $sqlWhere = $this->getTrackingSearchWhere();
  69. }elseif($search_mode == "booking"){
  70. $sqlWhere = $this->getBookingSearchWhere();
  71. }
  72. //Notify Party Bill to Destination Operator 是tracking里的,但booking没有,所以不影响
  73. $search_field_mapping = array("Origin Agent"=>"origin as code",
  74. "Destination Agent"=>"agent as code",
  75. "Shipper Name"=>"shipper as code",
  76. "Consignee Name"=>"consignee as code",
  77. "Notify Party" =>"notify_party as code",
  78. "Bill to" =>"billto as code",
  79. "Destination Operator"=>"dest_op as code",
  80. "Sales"=>"sales_rep as code",
  81. "Voyage/Flight_booking"=>"f_voyage as code,m_voyage as code_2",
  82. "Vessel_booking"=>"f_vessel as code,m_vessel as code_2",
  83. "Voyage/Flight_tracking"=>"voyage as code,f_voyage as code_2",
  84. "Vessel_tracking"=>"vessel as code,f_vessel as code_2");
  85. $sql_where_mapping = array("Origin Agent"=>" and (origin ilike '" . common::check_input($term) . "%')",
  86. "Destination Agent"=>" and (agent ilike '" . common::check_input($term) . "%')",
  87. "Shipper Name"=>" and (shipper ilike '" . common::check_input($term) . "%')",
  88. "Consignee Name"=>" and (consignee ilike '" . common::check_input($term) . "%')",
  89. "Notify Party"=>" and (notify_party ilike '" . common::check_input($term) . "%')",
  90. "Bill to"=>" and (billto ilike '" . common::check_input($term) . "%')",
  91. "Destination Operator"=>" and (dest_op ilike '" . common::check_input($term) . "%')",
  92. "Sales"=>" and (sales_rep ilike '" . common::check_input($term) . "%')",
  93. "Voyage/Flight_booking"=>" and (f_voyage ilike '" . common::check_input($term) . "%' or m_voyage ilike '" . common::check_input($term) . "%')",
  94. "Vessel_booking"=>" and (f_vessel ilike '" . common::check_input($term) . "%' or m_vessel ilike '" . common::check_input($term) . "%')",
  95. "Voyage/Flight_tracking"=>" and (voyage ilike '" . common::check_input($term) . "%' or f_voyage ilike '" . common::check_input($term) . "%')",
  96. "Vessel_tracking"=>" and (vessel ilike '" . common::check_input($term) . "%' or f_vessel ilike '" . common::check_input($term) . "%')");
  97. //特殊处理一下合并Voyage和Vessel
  98. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  99. $_str = $search_mode == "tracking" ? "tracking" : "booking";
  100. $search_field = $search_field ."_".$_str;
  101. }
  102. $str = $search_field_mapping[$search_field];
  103. $sql_where = $sql_where_mapping[$search_field];
  104. $table = $search_mode == "tracking" ? "public.online_ocean " : "public.online_booking ";
  105. $sql = "select * from (select DISTINCT $str from $table $sqlWhere $sql_where) as temp";
  106. $sql .= " order by code limit 20";
  107. $rs = common::excuteListSql($sql);
  108. }
  109. $rs = common::excuteListSql($sql);
  110. $array = array();
  111. foreach($rs as $v){
  112. if(!empty($v['code'])){
  113. $array[] = $v['code'];
  114. }
  115. if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
  116. $array[] = $v['code_2'];
  117. }
  118. }
  119. $array = utils::removeDuplicateArray($array);
  120. common::echo_json_encode(200,$array);
  121. exit();
  122. }
  123. public function autoPort() {
  124. $cp = common::check_input($_POST ['cp']); //current_page
  125. $ps = common::check_input($_POST ['ps']); //ps
  126. if (empty($ps))
  127. $ps = 20;
  128. $term = $_POST['term'];
  129. $term = trim($term);
  130. $search_field = $_POST['search_field'];
  131. $search_mode = $_POST['search_mode'];
  132. $_sql_arr = $this->getPortsUncity($search_field,$search_mode,$term);
  133. $rc = $_POST ['rc'];
  134. if ($rc == - 1) {
  135. $sql = $_sql_arr['count_sql'];
  136. $rc = common::excuteOneSql($sql);
  137. error_log($sql);
  138. }
  139. $tp = ceil($rc / $ps);
  140. if ($rc > 0) {
  141. $sql = $_sql_arr['sql'];
  142. $sql = "select * from ($sql) as temp ";
  143. $sql .= " order by city limit " . $ps . " offset " . ($cp - 1) * $ps;
  144. $rs = common::excuteListSql($sql);
  145. //前端要加上id 从1开始
  146. $retData = array();
  147. $i = 0;
  148. foreach($rs as $key => $val){
  149. if($search_field == "Port of Loading"){
  150. if(!empty($val['uncode'])){
  151. $val["id"] = $i +1;
  152. $retData[] = $val;
  153. $i = $i +1;
  154. }
  155. }else{
  156. if(!empty($val['city'])){
  157. $val["id"] = $i +1;
  158. $retData[] = $val;
  159. $i = $i +1;
  160. }
  161. }
  162. }
  163. $arrTmp = array('searchData' => $retData,
  164. 'rc' => $rc,
  165. 'ps' => $ps,
  166. 'cp' => $cp,
  167. 'tp' => $tp);
  168. common::echo_json_encode(200,$arrTmp);
  169. exit();
  170. }else{
  171. $arrTmp = array('searchData' => array(), 'rc' => 0);
  172. common::echo_json_encode(200, $arrTmp);
  173. exit();
  174. }
  175. }
  176. public function autoPort_old() {
  177. $cp = common::check_input($_POST ['cp']); //current_page
  178. $ps = common::check_input($_POST ['ps']); //ps
  179. if (empty($ps))
  180. $ps = 20;
  181. $term = $_POST['term'];
  182. $term = trim($term);
  183. $_curr_schemas = $_POST['model'];
  184. if (empty($_curr_schemas)) {
  185. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  186. if (empty($_curr_schemas)) {
  187. $_curr_schemas = "public";
  188. }
  189. }
  190. $rc = $_POST ['rc'];
  191. if ($rc == - 1) {
  192. $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  193. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  194. $rc = common::excuteOneSql($sql);
  195. }
  196. $tp = ceil($rc / $ps);
  197. if ($rc > 0) {
  198. $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
  199. or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
  200. $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
  201. $rs = common::excuteListSql($sql);
  202. //前端要加上id 从1开始
  203. $retData = array();
  204. foreach($rs as $key => $val){
  205. if(!empty($val['country'])){
  206. $val["id"] = $key +1;
  207. $retData[] = $val;
  208. }
  209. }
  210. $arrTmp = array('searchData' => $retData,
  211. 'rc' => $rc,
  212. 'ps' => $ps,
  213. 'cp' => $cp,
  214. 'tp' => $tp);
  215. common::echo_json_encode(200,$arrTmp);
  216. exit();
  217. }else{
  218. $arrTmp = array('searchData' => array());
  219. common::echo_json_encode(200, $arrTmp);
  220. exit();
  221. }
  222. }
  223. public function autody_old() {
  224. $term = $_POST['term'];
  225. $type = $_POST['type'];
  226. $term = trim($term);
  227. if (strtolower($type) == "apex") {
  228. $_curr_schemas = $_POST['model'];
  229. if (empty($_curr_schemas)) {
  230. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  231. if (empty($_curr_schemas)) {
  232. $_curr_schemas = "public";
  233. }
  234. }
  235. if ($_curr_schemas == "public") {
  236. $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  237. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  238. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  239. } else {
  240. $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
  241. . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
  242. . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
  243. }
  244. $sql .= " order by contact_id limit 20";
  245. $rs = common::excuteListSql($sql);
  246. }
  247. //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
  248. if (strtolower($type) == "contanct") {
  249. $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) . "%')";
  250. $sql .= " order by contact_id limit 20";
  251. $rs = common::excuteListSql($sql);
  252. }
  253. if (strtolower($type) == "sales") {
  254. $_curr_schemas = $_POST['model'];
  255. if (empty($_curr_schemas)) {
  256. $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
  257. if (empty($_curr_schemas)) {
  258. $_curr_schemas = "public";
  259. }
  260. }
  261. $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) . "%')";
  262. $sql .= " order by salesopcode limit 20";
  263. }
  264. if (strtolower($type) == "vessel") {
  265. $vessel = $_POST['vessel'];
  266. $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
  267. $sql .= " order by vessel limit 20";
  268. }
  269. $rs = common::excuteListSql($sql);
  270. $array = array();
  271. foreach($rs as $v){
  272. if(!empty($v['code'])){
  273. $array[] = $v['code'];
  274. }
  275. }
  276. common::echo_json_encode(200,$array);
  277. exit();
  278. }
  279. public function getTrackingSearchWhere(){
  280. $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
  281. $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
  282. if (!empty($_REQUEST["_reportRef"])) {
  283. $_reportType = $_REQUEST["_reportType"];
  284. $_reportRef = $_REQUEST["_reportRef"];
  285. if ($_reportType == "r3") {
  286. if ($_reportRef == "Previous 7 Days") {
  287. $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
  288. } else if ($_reportRef == "0 Day") {
  289. $sqlWhere .= " and eta=current_date";
  290. } else if ($_reportRef == "1-2 Days") {
  291. $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
  292. } else if ($_reportRef == "3-6 Days") {
  293. $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
  294. } else if ($_reportRef == "7 Days") {
  295. $sqlWhere .= " and eta>(current_date+interval '6 days')";
  296. } else {
  297. $sqlWhere .= " and 1<>1";
  298. }
  299. } else if ($_reportType == "r4") {
  300. if ($_reportRef == "Previous 7 Days") {
  301. $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
  302. } else if ($_reportRef == "0 Day") {
  303. $sqlWhere .= " and etd=current_date";
  304. } else if ($_reportRef == "1-2 Days") {
  305. $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
  306. } else if ($_reportRef == "3-6 Days") {
  307. $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
  308. } else if ($_reportRef == "7 Days") {
  309. $sqlWhere .= " and etd>(current_date+interval '6 days')";
  310. } else {
  311. $sqlWhere .= " and 1<>1";
  312. }
  313. } else if ($_reportType == "ata_r3") {
  314. if ($_reportRef == "0 Day") {
  315. $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
  316. } else if ($_reportRef == "1-2 Days") {
  317. $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
  318. } else if ($_reportRef == "3-6 Days") {
  319. $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
  320. } else if ($_reportRef == "7 Days") {
  321. $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
  322. } else {
  323. $sqlWhere .= " and 1<>1";
  324. }
  325. } else if ($_reportType == "atd_r4") {
  326. if ($_reportRef == "0 Day") {
  327. $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
  328. } else if ($_reportRef == "1-2 Days") {
  329. $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
  330. } else if ($_reportRef == "3-6 Days") {
  331. $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
  332. } else if ($_reportRef == "7 Days") {
  333. $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
  334. } else {
  335. $sqlWhere .= " and 1<>1";
  336. }
  337. } else if ($_reportType == "top") {
  338. if (!empty($_reportRef)) {
  339. $_reportStationType = $_REQUEST["_reportStationType"];
  340. if($_reportStationType == 'shippr_uncode'){
  341. $sqlWhere = " and shippr_uncode = '$_reportRef'";
  342. }
  343. if($_reportStationType == 'fport_of_loading_un'){
  344. $sqlWhere = " and fport_of_loading_un = '$_reportRef'";
  345. }
  346. if($_reportStationType == 'consignee_uncode'){
  347. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  348. }
  349. if($_reportStationType == 'mport_of_discharge_un'){
  350. $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
  351. }
  352. } else {
  353. $sqlWhere .= " and 1<>1";
  354. }
  355. } else if ($_reportType == "co2e") {
  356. $_reportDataType = $_REQUEST["_reportDataType"];
  357. //查询sea 其他的为空
  358. if (!empty($_reportRef) && $_reportDataType == "sea") {
  359. $_reportStationType = $_REQUEST["_reportStationType"];
  360. if($_reportStationType == 'origin'){
  361. $sqlWhere .= " and shippr_uncode = '$_reportRef'";
  362. }else{
  363. $sqlWhere .= " and consignee_uncode = '$_reportRef'";
  364. }
  365. } else {
  366. $sqlWhere .= " and 1<>1";
  367. }
  368. } else {
  369. $_reportRef = explode("-", $_REQUEST["_reportRef"]);
  370. $_reportRefb_date = $_REQUEST["_reportRefb_date"];
  371. $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
  372. $_reportRefe_date = $_REQUEST["_reportRefe_date"];
  373. $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
  374. //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
  375. if ($_REQUEST["_reportRef"] == "Over 80 Days") {
  376. $sqlWhere .= " and (eta-etd)>80";
  377. } else {
  378. $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
  379. }
  380. }
  381. }
  382. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  383. if (!empty($_POST["_textSearch"])) {
  384. $textSearch_arr = $_POST['_textSearch'];
  385. if(!is_array($textSearch_arr)){
  386. $textSearch_arr = array($textSearch_arr);
  387. }
  388. $more_sql = "1<>1";
  389. foreach($textSearch_arr as $tsv){
  390. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  391. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  392. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  393. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  394. }
  395. if ($more_sql <> "1<>1"){
  396. $sqlWhere .= " and ($more_sql)";
  397. }
  398. }
  399. return $sqlWhere;
  400. }
  401. public function getBookingSearchWhere(){
  402. $sqlWhere = ' where ' . common::searchExtendHandNew("booking", $_SESSION["ONLINE_USER"]);
  403. $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
  404. //新版要排除type2情况,总数才会对的上
  405. $sqlWhere .= " and (not(bol_type != 'BOOKING' and booking_no is not null and booking_no <> ''))";
  406. //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
  407. if (!empty($_POST["_textSearch"])) {
  408. $textSearch_arr = $_POST['_textSearch'];
  409. if(!is_array($textSearch_arr)){
  410. $textSearch_arr = array($textSearch_arr);
  411. }
  412. $more_sql = "1<>1";
  413. foreach($textSearch_arr as $tsv){
  414. $more_sql .= " or booking_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  415. $more_sql .= " or h_bol ilike '%" . common::check_input(trim($tsv)) . "%'";
  416. $more_sql .= " or po_no ilike '%" . common::check_input(trim($tsv)) . "%'";
  417. $more_sql .= " or carrier_booking ilike '%" . common::check_input(trim($tsv)) . "%'";
  418. }
  419. if ($more_sql <> "1<>1"){
  420. $sqlWhere .= " and ($more_sql)";
  421. }
  422. }
  423. return $sqlWhere;
  424. }
  425. PUBLIC function getPortsUncity($search_field,$search_mode,$term){
  426. //uncode 前两位便是 isoname,不用模糊查询这个了
  427. if($search_field == "Origin" && $search_mode == "booking"){
  428. $sqlWhere = $this->getBookingSearchWhere();
  429. $count_sql = "select COUNT(DISTINCT shipper_city)
  430. from public.online_booking $sqlWhere
  431. and (shipper_city ilike '" . common::check_input($term) . "%'
  432. or shippr_uncode ilike '" . common::check_input($term) . "%') ";
  433. $sql = "select DISTINCT ON (shipper_city) left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  434. from public.online_booking $sqlWhere
  435. and (shipper_city ilike '" . common::check_input($term) . "%'
  436. or shippr_uncode ilike '" . common::check_input($term) . "%') ";
  437. return array("count_sql"=>$count_sql,"sql"=>$sql);
  438. }
  439. if($search_field == "Destination" && $search_mode == "booking"){
  440. $sqlWhere = $this->getBookingSearchWhere();
  441. $count_sql = "select count(DISTINCT consignee_city)
  442. from public.online_booking $sqlWhere
  443. and (consignee_city ilike '" . common::check_input($term) . "%'
  444. or consignee_uncode ilike '" . common::check_input($term) . "%') ";
  445. $sql = "select DISTINCT ON (consignee_city) left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  446. from public.online_booking $sqlWhere
  447. and (consignee_city ilike '" . common::check_input($term) . "%'
  448. or consignee_uncode ilike '" . common::check_input($term) . "%')";
  449. return array("count_sql"=>$count_sql,"sql"=>$sql);
  450. }
  451. if($search_field == "Place of Receipt" && $search_mode == "booking"){
  452. $sqlWhere = $this->getBookingSearchWhere();
  453. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  454. from public.online_booking $sqlWhere
  455. and (place_of_receipt_exp ilike '" . common::check_input($term) . "%'
  456. or place_of_receipt_uncode ilike '" . common::check_input($term) . "%')";
  457. $sql = "select DISTINCT ON (place_of_receipt_exp) left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode
  458. from public.online_booking $sqlWhere
  459. and (place_of_receipt_exp ilike '" . common::check_input($term) . "%'
  460. or place_of_receipt_uncode ilike '" . common::check_input($term) . "%')";
  461. return array("count_sql"=>$count_sql,"sql"=>$sql);
  462. }
  463. if($search_field == "Port of Loading" && $search_mode == "booking"){
  464. $sqlWhere = $this->getBookingSearchWhere();
  465. $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
  466. from public.online_booking $sqlWhere
  467. and (fport_of_loading_exp ilike '" . common::check_input($term) . "%'
  468. or fport_of_loading_uncode ilike '" . common::check_input($term) . "%')";
  469. $sql = "select DISTINCT ON (fport_of_loading_exp) left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode
  470. from public.online_booking $sqlWhere
  471. and (fport_of_loading_exp ilike '" . common::check_input($term) . "%'
  472. or fport_of_loading_uncode ilike '" . common::check_input($term) . "%')";
  473. return array("count_sql"=>$count_sql,"sql"=>$sql);
  474. }
  475. if($search_field == "Place of delivery" && $search_mode == "booking"){
  476. $sqlWhere = $this->getBookingSearchWhere();
  477. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  478. from public.online_booking $sqlWhere
  479. and (place_of_delivery_exp ilike '" . common::check_input($term) . "%'
  480. or place_of_delivery_uncode ilike '" . common::check_input($term) . "%')";
  481. $sql = "select DISTINCT ON (place_of_delivery_exp) left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
  482. from public.online_booking $sqlWhere
  483. and (place_of_delivery_exp ilike '" . common::check_input($term) . "%'
  484. or place_of_delivery_uncode ilike '" . common::check_input($term) . "%')";
  485. return array("count_sql"=>$count_sql,"sql"=>$sql);
  486. }
  487. //tracking
  488. if($search_field == "Origin" && $search_mode == "tracking"){
  489. $sqlWhere = $this->getTrackingSearchWhere();
  490. $count_sql = "select COUNT(DISTINCT city) from (select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  491. from public.online_ocean $sqlWhere
  492. and (shipper_city ilike '" . common::check_input($term) . "%'
  493. or shippr_uncode ilike '" . common::check_input($term) . "%')
  494. union
  495. select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  496. from public.online_ocean $sqlWhere
  497. and (consignee_city ilike '" . common::check_input($term) . "%'
  498. or consignee_uncode ilike '" . common::check_input($term) . "%')) as temp";
  499. $sql = "select * from(select DISTINCT ON (shipper_city) left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
  500. from public.online_ocean $sqlWhere
  501. and (shipper_city ilike '" . common::check_input($term) . "%'
  502. or shippr_uncode ilike '" . common::check_input($term) . "%')
  503. union
  504. select DISTINCT ON (consignee_city) left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
  505. from public.online_ocean $sqlWhere
  506. and (consignee_city ilike '" . common::check_input($term) . "%'
  507. or consignee_uncode ilike '" . common::check_input($term) . "%')) as temp";
  508. return array("count_sql"=>$count_sql,"sql"=>$sql);
  509. }
  510. if($search_field == "Destination" && $search_mode == "tracking"){
  511. $sqlWhere = $this->getTrackingSearchWhere();
  512. $count_sql = "select COUNT(DISTINCT final_desination_exp)
  513. from public.online_ocean $sqlWhere
  514. and (final_desination_exp ilike '" . common::check_input($term) . "%'
  515. or final_desination_uncode ilike '" . common::check_input($term) . "%')";
  516. $sql = "select DISTINCT ON (final_desination_exp) left(final_desination_uncode, 2) as country,final_desination_exp as city, final_desination_uncode as uncode
  517. from public.online_ocean $sqlWhere
  518. and (final_desination_exp ilike '" . common::check_input($term) . "%'
  519. or final_desination_uncode ilike '" . common::check_input($term) . "%')";
  520. return array("count_sql"=>$count_sql,"sql"=>$sql);
  521. }
  522. if($search_field == "Place of Receipt" && $search_mode == "tracking"){
  523. $sqlWhere = $this->getTrackingSearchWhere();
  524. $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
  525. from public.online_ocean $sqlWhere
  526. and (place_of_receipt_exp ilike '" . common::check_input($term) . "%'
  527. or place_of_receipt_un ilike '" . common::check_input($term) . "%')";
  528. $sql = "select DISTINCT ON (place_of_receipt_exp) left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
  529. from public.online_ocean $sqlWhere
  530. and (place_of_receipt_exp ilike '" . common::check_input($term) . "%'
  531. or place_of_receipt_un ilike '" . common::check_input($term) . "%')";
  532. return array("count_sql"=>$count_sql,"sql"=>$sql);
  533. }
  534. if($search_field == "Port of Loading" && $search_mode == "tracking"){
  535. $sqlWhere = $this->getTrackingSearchWhere();
  536. $count_sql = "select COUNT(DISTINCT port_of_loading)
  537. from public.online_ocean $sqlWhere
  538. and (port_of_loading ilike '" . common::check_input($term) . "%'
  539. or fport_of_loading_un ilike '" . common::check_input($term) . "%')";
  540. $sql = "select DISTINCT ON (port_of_loading) left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
  541. from public.online_ocean $sqlWhere
  542. and (port_of_loading ilike '" . common::check_input($term) . "%'
  543. or fport_of_loading_un ilike '" . common::check_input($term) . "%')";
  544. return array("count_sql"=>$count_sql,"sql"=>$sql);
  545. }
  546. if($search_field == "Place of Discharge" && $search_mode == "tracking"){
  547. $sqlWhere = $this->getTrackingSearchWhere();
  548. $count_sql = "select COUNT(DISTINCT port_of_discharge)
  549. from public.online_ocean $sqlWhere
  550. and (port_of_discharge ilike '" . common::check_input($term) . "%'
  551. or mport_of_discharge_un ilike '" . common::check_input($term) . "%')";
  552. $sql = "select DISTINCT ON (port_of_discharge) left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
  553. from public.online_ocean $sqlWhere
  554. and (port_of_discharge ilike '" . common::check_input($term) . "%'
  555. or mport_of_discharge_un ilike '" . common::check_input($term) . "%')";
  556. return array("count_sql"=>$count_sql,"sql"=>$sql);
  557. }
  558. if($search_field == "Place of delivery" && $search_mode == "tracking"){
  559. $sqlWhere = $this->getTrackingSearchWhere();
  560. $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
  561. from public.online_ocean $sqlWhere
  562. and (place_of_delivery_exp ilike '" . common::check_input($term) . "%'
  563. or place_of_delivery_un ilike '" . common::check_input($term) . "%')";
  564. $sql = "select DISTINCT ON (place_of_delivery_exp) left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
  565. from public.online_ocean $sqlWhere
  566. and (place_of_delivery_exp ilike '" . common::check_input($term) . "%'
  567. or place_of_delivery_un ilike '" . common::check_input($term) . "%')";
  568. return array("count_sql"=>$count_sql,"sql"=>$sql);
  569. }
  570. }
  571. }
  572. ?>