| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of auto
- *
- * @author Administrator
- */
- class ajax {
- private static $_ajax;
- public static function getInstance() {
- if (!self::$_ajax) {
- $c = __CLASS__;
- self::$_ajax = new $c;
- }
- return self::$_ajax;
- }
- public function run() {
- $time = time() - $_SESSION["LAST_OPERATE_TIME"];
- if ($time > $_SESSION['SESSION_TIMEOUT']) {
- exit(json_encode("session_time_out"));
- } else {
- $_SESSION["LAST_OPERATE_TIME"] = time();
- }
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- switch ($operate) {
- case 'save_setting_display':
- $this->save_setting_display();
- break;
- case 'autody':
- return json_encode($this->autody());
- break;
- case 'autoport':
- return json_encode($this->autoPort());
- break;
- default :
- break;
- }
- }
- public function save_setting_display() {
- $ids = $_POST['ids'];
- if(!empty($ids)){
- $ss = utils::implode(",", $_POST['ids']);
- column::getInstance()->saveSettingDisplay(utils::implode(",", $_POST['ids']),"", $_POST['model_name']);
- $data = array(
- 'msg' => 'success'
- );
- common::echo_json_encode(200,$data);
- }else{
- $data = array(
- 'msg' => 'data error'
- );
- common::echo_json_encode(500,$data);
- }
- }
- //不查询全局的信息,查询该用户,最近3个月内输入过的信息自动补全
- public function autody(){
- $term = $_POST['term'];
- $type = $_POST['type'];
- $search_field = $_POST['search_field'];
- $search_mode = $_POST['search_mode'];
-
- $term = trim($term);
- if (strtolower($type) == "apex" || strtolower($type) == "contanct" || strtolower($type) == "sales"
- || strtolower($type) == "vessel" || strtolower($type) == "voyage") {
- if($search_mode == "tracking"){
- $sqlWhere = $this->getTrackingSearchWhere();
- }elseif($search_mode == "booking"){
- $sqlWhere = $this->getBookingSearchWhere();
- }
- //Notify Party Bill to Destination Operator 是tracking里的,但booking没有,所以不影响
- $search_field_mapping = array("Origin Agent"=>"origin as code",
- "Destination Agent"=>"agent as code",
- "Shipper Name"=>"shipper as code",
- "Consignee Name"=>"consignee as code",
- "Notify Party" =>"notify_party as code",
- "Bill to" =>"billto as code",
- "Destination Operator"=>"dest_op as code",
- "Sales"=>"sales_rep as code",
- "Voyage/Flight_booking"=>"f_voyage as code,m_voyage as code_2",
- "Vessel_booking"=>"f_vessel as code,m_vessel as code_2",
- "Voyage/Flight_tracking"=>"voyage as code,f_voyage as code_2",
- "Vessel_tracking"=>"vessel as code,f_vessel as code_2");
- $sql_where_mapping = array("Origin Agent"=>" and (origin ilike '%" . common::check_input($term) . "%')",
- "Destination Agent"=>" and (agent ilike '%" . common::check_input($term) . "%')",
- "Shipper Name"=>" and (shipper ilike '%" . common::check_input($term) . "%')",
- "Consignee Name"=>" and (consignee ilike '%" . common::check_input($term) . "%')",
- "Notify Party"=>" and (notify_party ilike 'v" . common::check_input($term) . "%')",
- "Bill to"=>" and (billto ilike '%" . common::check_input($term) . "%')",
- "Destination Operator"=>" and (dest_op ilike '%" . common::check_input($term) . "%')",
- "Sales"=>" and (sales_rep ilike '%" . common::check_input($term) . "%')",
- "Voyage/Flight_booking"=>" and (f_voyage ilike '%" . common::check_input($term) . "%' or m_voyage ilike '%" . common::check_input($term) . "%')",
- "Vessel_booking"=>" and (f_vessel ilike '%" . common::check_input($term) . "%' or m_vessel ilike '%" . common::check_input($term) . "%')",
- "Voyage/Flight_tracking"=>" and (voyage ilike '%" . common::check_input($term) . "%' or f_voyage ilike '%" . common::check_input($term) . "%')",
- "Vessel_tracking"=>" and (vessel ilike '%" . common::check_input($term) . "%' or f_vessel ilike '%" . common::check_input($term) . "%')");
- //特殊处理一下合并Voyage和Vessel
- $_search_field = $search_field;
- if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
- $_str = $search_mode == "tracking" ? "tracking" : "booking";
- $_search_field = $search_field ."_".$_str;
- }
- $str = $search_field_mapping[$_search_field];
- $sql_where = $sql_where_mapping[$_search_field];
- $table = $search_mode == "tracking" ? "public.kln_ocean " : "public.kln_booking ";
- if($search_mode == "booking"){
- $order_by = " f_etd desc NULLS LAST";
- }else{
- $order_by = " etd desc NULLS LAST";
- if (_isCustomerLogin()) {
- $order_by = " eta desc NULLS LAST";
- }
- }
-
- $sql = "select DISTINCT * from (select $str from $table $sqlWhere $sql_where order by $order_by ) as temp";
- $sql .= " order by code limit 20";
- error_log($sql);
- $rs = common::excuteListSql($sql);
- }
- $rs = common::excuteListSql($sql);
- $array = array();
- foreach($rs as $v){
- if(!empty($v['code'])){
- $array[] = $v['code'];
- }
- if ($search_field == "Voyage/Flight" || $search_field == "Vessel"){
- $array[] = $v['code_2'];
- }
- }
- $array = utils::removeDuplicateArray($array);
- common::echo_json_encode(200,$array);
- exit();
- }
- public function autoPort() {
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- if (empty($ps))
- $ps = 20;
- $term = $_POST['term'];
- $term = trim($term);
- $search_field = $_POST['search_field'];
- $search_mode = $_POST['search_mode'];
- $_sql_arr = $this->getPortsUncity($search_field,$search_mode,$term);
- $rc = $_POST ['rc'];
- if ($rc == - 1) {
- $sql = $_sql_arr['count_sql'];
- $rc = common::excuteOneSql($sql);
- error_log($sql);
- }
- $tp = ceil($rc / $ps);
- if ($rc > 0) {
- $sql = $_sql_arr['sql'];
- $sql = "select DISTINCT ON (city) country, city,uncode from ($sql) as temp ";
- $sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
-
- $rs = common::excuteListSql($sql);
- error_log($sql);
- //前端要加上id 从1开始
- $retData = array();
- $i = 0;
- foreach($rs as $key => $val){
- if($search_field == "Port of Loading"){
- if(!empty($val['uncode'])){
- $val["id"] = $i +1;
- $retData[] = $val;
- $i = $i +1;
- }
- }else{
- if(!empty($val['city'])){
- $val["id"] = $i +1;
- $retData[] = $val;
- $i = $i +1;
- }
- }
- }
- $arrTmp = array('searchData' => $retData,
- 'rc' => $rc,
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp);
- common::echo_json_encode(200,$arrTmp);
- exit();
- }else{
- $arrTmp = array('searchData' => array(), 'rc' => 0);
- common::echo_json_encode(200, $arrTmp);
- exit();
- }
- }
- public function autoPort_old() {
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- if (empty($ps))
- $ps = 20;
- $term = $_POST['term'];
- $term = trim($term);
- $_curr_schemas = $_POST['model'];
- if (empty($_curr_schemas)) {
- $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
- if (empty($_curr_schemas)) {
- $_curr_schemas = "public";
- }
- }
- $rc = $_POST ['rc'];
- if ($rc == - 1) {
- $sql = "SELECT count(1) from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
- or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
- $rc = common::excuteOneSql($sql);
- }
- $tp = ceil($rc / $ps);
- if ($rc > 0) {
- $sql = "SELECT isoname as country, uncity as city,uncode from $_curr_schemas.ports where (isoname ilike '" . common::check_input($term) . "%'
- or uncity ilike '" . common::check_input($term) . "%' or uncode ilike '" . common::check_input($term) . "%')";
- $sql .= " order by code limit " . $ps . " offset " . ($cp - 1) * $ps;
- $rs = common::excuteListSql($sql);
- //前端要加上id 从1开始
- $retData = array();
- foreach($rs as $key => $val){
- if(!empty($val['country'])){
- $val["id"] = $key +1;
- $retData[] = $val;
- }
- }
- $arrTmp = array('searchData' => $retData,
- 'rc' => $rc,
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp);
- common::echo_json_encode(200,$arrTmp);
- exit();
- }else{
- $arrTmp = array('searchData' => array());
- common::echo_json_encode(200, $arrTmp);
- exit();
- }
- }
- public function autody_old() {
- $term = $_POST['term'];
- $type = $_POST['type'];
-
- $term = trim($term);
- if (strtolower($type) == "apex") {
- $_curr_schemas = $_POST['model'];
- if (empty($_curr_schemas)) {
- $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
- if (empty($_curr_schemas)) {
- $_curr_schemas = "public";
- }
- }
- if ($_curr_schemas == "public") {
- $sql = "select contact_id as code from ocean.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
- . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
- . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
- } else {
- $sql = "select contact_id as code from $_curr_schemas.contacts where ('Apex-DST'=any(regexp_split_to_array(contact_type::text, ';'::text))"
- . " or 'Apex-AGT'=any(regexp_split_to_array(contact_type::text, ';'::text))) "
- . "and active=true and coalesce(hblcode, '')<>'' and (contact_id ilike '" . common::check_input($term) . "%' or company ilike '" . common::check_input($term) . "%')";
- }
- $sql .= " order by contact_id limit 20";
- $rs = common::excuteListSql($sql);
- }
- //Shipper 和Consignee 的查询,但是表contact_v ,从ocean和air. 如果不做区分的话,可以上面的apex的Origin Agent/Destination Agent,合并
- if (strtolower($type) == "contanct") {
- $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) . "%')";
- $sql .= " order by contact_id limit 20";
- $rs = common::excuteListSql($sql);
- }
- if (strtolower($type) == "sales") {
- $_curr_schemas = $_POST['model'];
- if (empty($_curr_schemas)) {
- $_curr_schemas = $_SESSION['ONLINE_USER']['main_schemas'];
- if (empty($_curr_schemas)) {
- $_curr_schemas = "public";
- }
- }
- $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) . "%')";
- $sql .= " order by salesopcode limit 20";
- }
- if (strtolower($type) == "vessel") {
- $vessel = $_POST['vessel'];
- $sql = "SELECT carrier, vessel as code, flag from vessel_infor where vessel ilike '" . common::check_input($vessel) . "%'";
- $sql .= " order by vessel limit 20";
- }
- $rs = common::excuteListSql($sql);
- $array = array();
- foreach($rs as $v){
- if(!empty($v['code'])){
- $array[] = $v['code'];
- }
- }
- common::echo_json_encode(200,$array);
- exit();
- }
- public function getTrackingSearchWhere(){
- $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
- $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
-
- if (!empty($_REQUEST["_reportRef"])) {
- $_reportType = $_REQUEST["_reportType"];
- $_reportRef = $_REQUEST["_reportRef"];
- if ($_reportType == "r3") {
- if ($_reportRef == "Previous 7 Days") {
- $sqlWhere .= " and eta>(current_date-interval '7 days') and eta<current_date";
- } else if ($_reportRef == "0 Day") {
- $sqlWhere .= " and eta=current_date";
- } else if ($_reportRef == "1-2 Days") {
- $sqlWhere .= " and eta>current_date and eta<=(current_date+interval '2 days')";
- } else if ($_reportRef == "3-6 Days") {
- $sqlWhere .= " and eta>(current_date+interval '2 days') and eta<=(current_date+interval '6 days')";
- } else if ($_reportRef == "7 Days") {
- $sqlWhere .= " and eta>(current_date+interval '6 days')";
- } else {
- $sqlWhere .= " and 1<>1";
- }
- } else if ($_reportType == "r4") {
- if ($_reportRef == "Previous 7 Days") {
- $sqlWhere .= " and etd>(current_date-interval '7 days') and etd<current_date";
- } else if ($_reportRef == "0 Day") {
- $sqlWhere .= " and etd=current_date";
- } else if ($_reportRef == "1-2 Days") {
- $sqlWhere .= " and etd>current_date and etd<=(current_date+interval '2 days')";
- } else if ($_reportRef == "3-6 Days") {
- $sqlWhere .= " and etd>(current_date+interval '2 days') and etd<=(current_date+interval '6 days')";
- } else if ($_reportRef == "7 Days") {
- $sqlWhere .= " and etd>(current_date+interval '6 days')";
- } else {
- $sqlWhere .= " and 1<>1";
- }
- } else if ($_reportType == "ata_r3") {
- if ($_reportRef == "0 Day") {
- $sqlWhere .= " and ata >= etd and (ata-etd) >= 0 and (ata-etd) < 1";
- } else if ($_reportRef == "1-2 Days") {
- $sqlWhere .= " and ata >= etd and (ata-etd) >= 1 and (ata-etd) < 2";
- } else if ($_reportRef == "3-6 Days") {
- $sqlWhere .= " and ata >= etd and (ata-etd) >= 2 and (ata-etd) < 6";
- } else if ($_reportRef == "7 Days") {
- $sqlWhere .= " and ata >= etd and (ata-etd) >= 6";
- } else {
- $sqlWhere .= " and 1<>1";
- }
- } else if ($_reportType == "atd_r4") {
- if ($_reportRef == "0 Day") {
- $sqlWhere .= " and atd >= etd and (atd-etd) >= 0 and (atd-etd) < 1";
- } else if ($_reportRef == "1-2 Days") {
- $sqlWhere .= " and atd >= etd and (atd-etd) >= 1 and (atd-etd) < 2";
- } else if ($_reportRef == "3-6 Days") {
- $sqlWhere .= " and atd >= etd and (atd-etd) >= 2 and (atd-etd) < 6";
- } else if ($_reportRef == "7 Days") {
- $sqlWhere .= " and atd >= etd and (atd-etd) >= 6 ";
- } else {
- $sqlWhere .= " and 1<>1";
- }
- } else if ($_reportType == "top") {
- if (!empty($_reportRef)) {
- $_reportStationType = $_REQUEST["_reportStationType"];
-
- if($_reportStationType == 'shippr_uncode'){
- $sqlWhere .= " and shippr_uncode = '$_reportRef'";
- }
- if($_reportStationType == 'fport_of_loading_un'){
- $sqlWhere .= " and fport_of_loading_un = '$_reportRef'";
- }
- if($_reportStationType == 'consignee_uncode'){
- $sqlWhere .= " and consignee_uncode = '$_reportRef'";
- }
- if($_reportStationType == 'mport_of_discharge_un'){
- $sqlWhere .= " and mport_of_discharge_un = '$_reportRef'";
- }
- } else {
- $sqlWhere .= " and 1<>1";
- }
- } else if ($_reportType == "co2e") {
- $_reportDataType = $_REQUEST["_reportDataType"];
- //查询sea 其他的为空
- if (!empty($_reportRef) && $_reportDataType == "sea") {
- $_reportStationType = $_REQUEST["_reportStationType"];
- if($_reportStationType == 'origin'){
- $sqlWhere .= " and shippr_uncode = '$_reportRef'";
- }else{
- $sqlWhere .= " and consignee_uncode = '$_reportRef'";
- }
-
- } else {
- $sqlWhere .= " and 1<>1";
- }
- } else {
- $_reportRef = explode("-", $_REQUEST["_reportRef"]);
- $_reportRefb_date = $_REQUEST["_reportRefb_date"];
- $bdate = common::excuteOneSql("select to_date('$_reportRefb_date','mm/YYYY')");
- $_reportRefe_date = $_REQUEST["_reportRefe_date"];
- $edate = common::excuteOneSql("select to_date('$_reportRefe_date','mm/YYYY') + interval '1 month' - interval '1 day'");
- //$sqlWhere .= " and eta>='$bdate' and eta<='$edate'";
- if ($_REQUEST["_reportRef"] == "Over 80 Days") {
- $sqlWhere .= " and (eta-etd)>80";
- } else {
- $sqlWhere .= " and (eta-etd)>" . $_reportRef[0] . " and (eta-etd)<=" . substr($_reportRef[1], 0, 2);
- }
- }
- }
- //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
- if (!empty($_POST["_textSearch"])) {
- $textSearch_arr = $_POST['_textSearch'];
- if(!is_array($textSearch_arr)){
- $textSearch_arr = str_replace(",", ";", $textSearch_arr);
- $textSearch_arr = array($textSearch_arr);
- }
- $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
- //$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)],''))";
- $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))
- or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%'
- or lower(invoice_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
- }
- return $sqlWhere;
- }
- public function getBookingSearchWhere(){
- $sqlWhere = ' where ' . common::searchExtendHand_KLN("booking", $_SESSION["ONLINE_USER"]);
- $sqlWhere .= search::getInstance()->getSearchSQL("Booking_Search");
- //移除掉全文检索 但保留代码
- // if (!empty($_POST["_textSearch"])) {
- // $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
- // }
- //处理reference类型的组合查询 Search booking No./HBL No./PO No./Carrier Booking No.
- if (!empty($_POST["_textSearch"])) {
- $textSearch_arr = $_POST['_textSearch'];
- if(!is_array($textSearch_arr)){
- $textSearch_arr = str_replace(",", ";", $textSearch_arr);
- $textSearch_arr = array($textSearch_arr);
- }
- $more_param = common::getInNotInSqlForSearch(strtolower(utils::implode(';',$textSearch_arr)));
- $sqlWhere .= " and ((ARRAY[$more_param] && array_append(array[lower(booking_no)::text,lower(h_bol)::text, lower(po_no),lower(carrier_booking)],''))
- or lower(po_no) like '%" . strtolower(common::check_input($_POST["_textSearch"])) . "%')";
- }
- return $sqlWhere;
- }
- PUBLIC function getPortsUncity($search_field,$search_mode,$term){
- //uncode 前两位便是 isoname,不用模糊查询这个了
- if($search_field == "Origin" && $search_mode == "booking"){
- $sqlWhere = $this->getBookingSearchWhere();
- $count_sql = "select COUNT(DISTINCT shipper_city)
- from public.kln_booking $sqlWhere
- and COALESCE(shippr_uncode,'')<>''
- and (shipper_city ilike '%" . common::check_input($term) . "%'
- or shippr_uncode ilike '%" . common::check_input($term) . "%') ";
- $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
- from public.kln_booking $sqlWhere
- and COALESCE(shippr_uncode,'')<>''
- and (shipper_city ilike '%" . common::check_input($term) . "%'
- or shippr_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Destination" && $search_mode == "booking"){
- $sqlWhere = $this->getBookingSearchWhere();
- $count_sql = "select count(DISTINCT consignee_city)
- from public.kln_booking $sqlWhere
- and COALESCE(consignee_uncode,'')<>''
- and (consignee_city ilike '%" . common::check_input($term) . "%'
- or consignee_uncode ilike '%" . common::check_input($term) . "%') ";
- $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
- from public.kln_booking $sqlWhere
- and COALESCE(consignee_uncode,'')<>''
- and (consignee_city ilike '%" . common::check_input($term) . "%'
- or consignee_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Place of Receipt" && $search_mode == "booking"){
- $sqlWhere = $this->getBookingSearchWhere();
- $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
- from public.kln_booking $sqlWhere
- and COALESCE(place_of_receipt_uncode,'')<>''
- and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
- or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(place_of_receipt_uncode, 2) as country,place_of_receipt_exp as city, place_of_receipt_uncode as uncode
- from public.kln_booking $sqlWhere
- and COALESCE(place_of_receipt_uncode,'')<>''
- and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
- or place_of_receipt_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Port of Loading" && $search_mode == "booking"){
- $sqlWhere = $this->getBookingSearchWhere();
- $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
- from public.kln_booking $sqlWhere
- and COALESCE(fport_of_loading_uncode,'')<>''
- and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
- or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%')";
-
- $sql = "select left(fport_of_loading_uncode, 2) as country,fport_of_loading_exp as city, fport_of_loading_uncode as uncode
- from public.kln_booking $sqlWhere
- and COALESCE(fport_of_loading_uncode,'')<>''
- and (fport_of_loading_exp ilike '%" . common::check_input($term) . "%'
- or fport_of_loading_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Place of delivery" && $search_mode == "booking"){
- $sqlWhere = $this->getBookingSearchWhere();
- $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
- from public.kln_booking $sqlWhere
- and COALESCE(place_of_delivery_uncode,'')<>''
- and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
- or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(place_of_delivery_uncode, 2) as country,place_of_delivery_exp as city, place_of_delivery_uncode as uncode
- from public.kln_booking $sqlWhere
- and COALESCE(place_of_delivery_uncode,'')<>''
- and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
- or place_of_delivery_uncode ilike '%" . common::check_input($term) . "%') order by f_etd desc NULLS LAST";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- //tracking
- $order_by = " etd desc NULLS LAST";
- if (_isCustomerLogin()) {
- $order_by = " eta desc NULLS LAST";
- }
- if($search_field == "Origin" && $search_mode == "tracking"){
- $sqlWhere = $this->getTrackingSearchWhere();
- $count_sql = "select COUNT(DISTINCT shipper_city)
- from public.kln_ocean $sqlWhere
- and COALESCE(shippr_uncode,'')<>''
- and (shipper_city ilike '%" . common::check_input($term) . "%'
- or shippr_uncode ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(shippr_uncode, 2) as country,shipper_city as city, shippr_uncode as uncode
- from public.kln_ocean $sqlWhere
- and COALESCE(shippr_uncode,'')<>''
- and (shipper_city ilike '%" . common::check_input($term) . "%'
- or shippr_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Destination" && $search_mode == "tracking"){
- $sqlWhere = $this->getTrackingSearchWhere();
- $count_sql = "select COUNT(DISTINCT consignee_city)
- from public.kln_ocean $sqlWhere
- and COALESCE(consignee_uncode,'')<>''
- and (consignee_city ilike '%" . common::check_input($term) . "%'
- or consignee_uncode ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(consignee_uncode, 2) as country,consignee_city as city, consignee_uncode as uncode
- from public.kln_ocean $sqlWhere
- and COALESCE(consignee_uncode,'')<>''
- and (consignee_city ilike '%" . common::check_input($term) . "%'
- or consignee_uncode ilike '%" . common::check_input($term) . "%') order by $order_by";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Place of Receipt" && $search_mode == "tracking"){
- $sqlWhere = $this->getTrackingSearchWhere();
- $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
- from public.kln_ocean $sqlWhere
- and COALESCE(place_of_receipt_un,'')<>''
- and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
- or place_of_receipt_un ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(place_of_receipt_un, 2) as country,place_of_receipt_exp as city, place_of_receipt_un as uncode
- from public.kln_ocean $sqlWhere
- and COALESCE(place_of_receipt_un,'')<>''
- and (place_of_receipt_exp ilike '%" . common::check_input($term) . "%'
- or place_of_receipt_un ilike '%" . common::check_input($term) . "%') order by $order_by";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Port of Loading" && $search_mode == "tracking"){
- $sqlWhere = $this->getTrackingSearchWhere();
- $count_sql = "select COUNT(DISTINCT port_of_loading)
- from public.kln_ocean $sqlWhere
- and COALESCE(fport_of_loading_un,'')<>''
- and (port_of_loading ilike '%" . common::check_input($term) . "%'
- or fport_of_loading_un ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(fport_of_loading_un, 2) as country,port_of_loading as city, fport_of_loading_un as uncode
- from public.kln_ocean $sqlWhere
- and COALESCE(fport_of_loading_un,'')<>''
- and (port_of_loading ilike '%" . common::check_input($term) . "%'
- or fport_of_loading_un ilike '%" . common::check_input($term) . "%') order by $order_by";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Place of Discharge" && $search_mode == "tracking"){
- $sqlWhere = $this->getTrackingSearchWhere();
- $count_sql = "select COUNT(DISTINCT port_of_discharge)
- from public.kln_ocean $sqlWhere
- and COALESCE(mport_of_discharge_un,'')<>''
- and (port_of_discharge ilike '%" . common::check_input($term) . "%'
- or mport_of_discharge_un ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(mport_of_discharge_un, 2) as country,port_of_discharge as city, mport_of_discharge_un as uncode
- from public.kln_ocean $sqlWhere
- and COALESCE(mport_of_discharge_un,'')<>''
- and (port_of_discharge ilike '%" . common::check_input($term) . "%'
- or mport_of_discharge_un ilike '%" . common::check_input($term) . "%') order by $order_by";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- if($search_field == "Place of delivery" && $search_mode == "tracking"){
- $sqlWhere = $this->getTrackingSearchWhere();
- $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
- from public.kln_ocean $sqlWhere
- and COALESCE(place_of_delivery_un,'')<>''
- and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
- or place_of_delivery_un ilike '%" . common::check_input($term) . "%')";
- $sql = "select left(place_of_delivery_un, 2) as country,place_of_delivery_exp as city, place_of_delivery_un as uncode
- from public.kln_ocean $sqlWhere
- and COALESCE(place_of_delivery_un,'')<>''
- and (place_of_delivery_exp ilike '%" . common::check_input($term) . "%'
- or place_of_delivery_un ilike '%" . common::check_input($term) . "%') order by $order_by";
- return array("count_sql"=>$count_sql,"sql"=>$sql);
- }
- }
- }
- ?>
|