| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787 |
- <?php
- if (!defined('IN_ONLINE')) {
- exit('Access Denied');
- }
- /**
- * Description of ocean
- *
- * @author Administrator
- */
- class ocean_order {
- private static $_ocean;
- function __construct() {
-
- }
- public static function getInstance() {
- global $memory_limit;
- $memory_limit = ini_get("memory_limit");
- ini_set("memory_limit", '2048M');
- if (!self::$_ocean) {
- $c = __CLASS__;
- self::$_ocean = new $c;
- }
- return self::$_ocean;
- }
- public function ocean_order() {
- $operate = utils::_get('operate');
- $operate = strtolower($operate);
- /*
- * index page
- */
- if (empty($operate)) {
- //search
- //$search = search::getInstance()->getDisplaySearch("Ocean_Search
- //栏位信息
- $column = column::getInstance()->getDisplayColumn('Ocean_Search');
- $BookingTableColumns = column::getInstance()->tableColumns('Ocean_Search',$column);
- $data['TrackingTableColumns'] = $BookingTableColumns;
- common::echo_json_encode(200,$data);
- exit();
- }
- /*
- * ocean order search
- */
- if ($operate == "search") {
- $this->_ocean_search();
- }
- /*
- * ocean order detail
- */
- if ($operate == "detail") {
- $this->_ocean_detail();
- }
- if ($operate == "ams_isf_log"){
- $this->_ams_isf_log();
- }
- /*
- * export ocean order to excel
- */
- if ($operate == "excel") {
- $this->_ocean_excel();
- }
-
- if ($operate == 'setting_ocean_order_display') {
- column::getInstance()->settingDisplay('Ocean_Search', 'main_new_version.php?action=ocean_order');
- }
- /*
- * download document
- */
- if ($operate == "download") {
- $this->_download();
- }
- if ($operate == "save_communication") {
- try {
- $content = $_POST["content"];
- $content = common::check_input($content);
- $text = $_POST["text"];
- $content = urldecode($content);
- $web_content = urldecode($text);
- $communication_cc = $_POST["communication_cc"];
- $serial_no = common::uuid();
- $email_uuid = $_POST["serial_no"];
- $add_by = _getLoginName();
- $refer_id = 0;
-
- $email = $this->getEmail($email_uuid);
- $from_email = "US.KApex.Online@kerryapex.com";
- $to_email = $email["email"];
- $cc_email = $_SESSION['ONLINE_USER']['email'] . ";ApexOnlineCommunication@apexshipping.com";
- $communication_cc = trim($communication_cc);
- if (!empty($communication_cc)) {
- $communication_cc = common::check_input($communication_cc);
- $cc_email .= ";" . $communication_cc;
- }
- $user_from = _getLoginName();
- $user_to = $email["name"];
- $user_cc = $_SESSION['ONLINE_USER']['first_name'];
- if (empty($user_cc)) {
- $user_cc = _getLoginName();
- }
- $user_cc .= ";ApexOnlineCommunication";
- //邮件发送
- $poKey = "<br><br>Important note: when you reply this email, do not remove ApexOnlineCommunication@apexshipping.com<br>Below is system code, do not delete.<br>@@";
- $emailSql = "select encode(public.pgp_sym_encrypt('" . $serial_no . "','pom_key'), 'base64')::text;";
- $key = common::excuteOneSql($emailSql);
- $historyEmails = "";
- $title = "Communication from " . _getLoginName() . ", HBOL: " . $email["h_bol"] . ", Consignee: " . $email["consignee"];
- $emailContent = $content . $poKey . $key . ";" . "@@<br>For your convenience weblink: https://ra.kerryapex.com/<br><br>" . $historyEmails;
- common::excuteUpdateSql("insert into public.email_record (type,title,from_email,to_email,cc_email,content,insert_date)values('Communication','$title','$from_email','$to_email','$cc_email','$emailContent',now());");
- $rs = common::excuteUpdateSql("INSERT INTO public.online_ocean_communication(serial_no, email_uuid, content,web_content,user_from, user_to, user_cc, refer_id, add_by, add_time, cc_email)
- VALUES ('$serial_no', '$email_uuid', '$emailContent','$web_content', '$user_from', '$to_email', '$cc_email', $refer_id, '$add_by', now(), '$communication_cc');");
- $emailRecords = $this->getCommunicationNew($email_uuid);
- common::echo_json_encode(200,array("msg" => "Sent Successfully", "emailRecords" => $emailRecords));
- exit();
- } catch (Exception $e) {
- common::echo_json_encode(500,array("msg" => "Sent Error."));
- exit();
- }
- }
- }
- /*
- * ocean order search
- */
- private function _ocean_search() {
- $cp = common::check_input($_POST ['cp']); //current_page
- $ps = common::check_input($_POST ['ps']); //ps
- if (empty($ps))
- $ps = 50;
- $sqlWhere = ' where ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
- $sqlWhere .= search::getInstance()->getSearchSQL("Ocean_Search");
- //查询tag
- // IFFBCF;Booking Confirmation
- // IFFREC;Cargo Arrived at Origin
- // IFFDEP;Departure
- // IFFARR;Arrived at Final Destination Port
- // IFFAFD;Arrived at Final Destination
- if (!empty($_POST["filterTag"])) {
- $tempsql = "1<>1";
- foreach($_POST["filterTag"] as $tag){
- if ($tag == "All"){
- continue;
- } elseif ($tag == "Booked"){
- //$tempsql .=" or code ";
- } elseif ($tag == "Cargo Received"){
-
- } elseif ($tag == "Departure"){
-
- }elseif ($tag == "Arrived"){
-
- }elseif ($tag == "Completed"){
-
- }
- }
- if ($tempsql <> "1<>1"){
- $sqlWhere .= " and (exists(select 1 from public.ocean_milestone where $tempsql))";
- }
- }
- if (!empty($_POST["_textSearch"])) {
- $sqlWhere .= " and text_search @@ (str_to_tsquery('" . common::check_input($_POST["_textSearch"]) . "'))";
- }
- $rc = $_POST ['rc'];
- if ($rc == - 1) {
- $sql = "SELECT count(1) from public.online_ocean" . $sqlWhere;
- $rc = common::excuteOneSql($sql);
- if (!empty($_POST["filterTag"])) {
- $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=>in_array('All', $_POST["filterTag"])? true : false),
- array("name"=>"Booked","number"=>0,"type"=>"booked","checked"=>in_array('Booked', $_POST["filterTag"])? true : false),
- array("name"=>"Cargo Received","number"=>0,"type"=>"cargo_received","checked"=>in_array('Cargo Received', $_POST["filterTag"])? true : false),
- array("name"=>"Departure","number"=>0,"type"=>"departure","checked"=>in_array('Departure', $_POST["filterTag"])? true : false),
- array("name"=>"Arrived","number"=>0,"type"=>"arrived","checked"=>in_array('Arrived', $_POST["filterTag"])? true : false),
- array("name"=>"Completed","number"=>0,"type"=>"completed","checked"=>in_array('Completed', $_POST["filterTag"])? true : false));
- }else{
- //初始,前端有选择着带入选择
- $tagsList = array(array("name"=>"All","number"=>$rc,"type"=>"all","checked"=> true ),
- array("name"=>"Booked","number"=>0,"type"=>"booked","checked"=> false),
- array("name"=>"Cargo Received","number"=>0,"type"=>"cargo_received","checked"=> false),
- array("name"=>"Departure","number"=>0,"type"=>"departure","checked"=> false),
- array("name"=>"Arrived","number"=>0,"type"=>"arrived","checked"=> false),
- array("name"=>"Completed","number"=>0,"type"=>"completed","checked"=>false));
- }
- $TransportList = array(
- array("name"=>"Ocean Freight","number"=>$rc,"checked"=>false,"icon"=>"#icon-icon_ocean_b"));
- //现在下载交给前端,后台预先只返回全部字段的列,
- $allColumn = column::getInstance()->getDisplayColumnAllReomveDefault('Ocean_Search');
- $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
- }
- $tp = ceil($rc / $ps);
- $order_by = " etd desc NULLS LAST, id";
- if (_isCustomerLogin()) {
- $order_by = " eta desc NULLS LAST, id";
- }
- if ($rc > 0) {
- $ocean_ref_sql = "LEFT JOIN LATERAL ( SELECT string_agg(ref_code ||ref_value, ', ') AS other_refenrence_no
- FROM public.ocean_reference temp WHERE temp.serial_no = online_ocean.serial_no) aa ON true ";
- if (!empty($_POST["_textSearch"])) {
- $sql = "SELECT order_from as _schemas, serial_no as __serial_no,serial_no, h_bol as _hbol, isf_bol as _isfbol, " .
- column::getInstance()->getSearchSql('Ocean_Search') . " from public.online_ocean $ocean_ref_sql " . $sqlWhere . " "
- . "order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
- } else {
- $sql = "SELECT order_from as _schemas,serial_no as __serial_no, serial_no, h_bol as _hbol, isf_bol as _isfbol, " .
- column::getInstance()->getSearchSql('Ocean_Search') . " from public.online_ocean $ocean_ref_sql " . $sqlWhere .
- " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps;
- }
- $rs = common::excuteListSql($sql);
- //对查询的结果做特殊处理,比如要拼接某个值,合并值等
- foreach($rs as $index => $val) {
- //返回加密serial_no
- $rs[$index]["__serial_no"] = common::deCode($val['__serial_no'], 'E');
- $rs[$index]["mode"] = "Ocean Frieght";
- }
-
- $arrTmp = array('searchData' => $rs,
- 'tagsList' => array(),
- 'TransportList' => $TransportList,
- 'allColums' => $allBookingColumns,
- 'rc' => $rc,
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp,
- 'tmp_search' => common::deCode($sql, 'E'),
- 'type' => common::check_input($_POST ['_ntype']));
- } else {
- $arrTmp = array('searchData' => array(),
- 'tagsList' => array(),
- 'TransportList' => $TransportList,
- 'allColums' => $allBookingColumns,
- 'rc' => $rc,
- 'ps' => $ps,
- 'cp' => $cp,
- 'tp' => $tp,
- 'tmp_search' => common::deCode($sql, 'E'),
- 'type' => common::check_input($_POST ['_ntype']));
- }
- common::echo_json_encode(200,$arrTmp);
- exit();
- }
- private function _ocean_detail() {
- $serial_no = common::deCode($_GET['a'], 'D');
- $status = $_GET['status'];
- $sql = "SELECT m_eta as _m_eta, h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
- public.z_get_eta_dest(o.final_eta::date, o.eta_dest::text, o.service::text, o.m_eta::date, o.place_of_delivery::text, o.mport_of_discharge::text) as _eta_dest,
- to_char(final_eta, 'MM/DD/YYYY') as _final_eta,o.* ,sh.*, cn.* ,aa.*,dd.*
- from ocean o
- LEFT JOIN LATERAL ( SELECT company as cn_company,
- address_1 as cn_address_1,
- address_2 as cn_address_2,
- address_3 as cn_address_3,
- address_4 as cn_address_4,
- city as cn_city, state as cn_state, zipcode as cn_zipcode, country as cn_country,
- phone_1 as cn_phone
- FROM contacts c WHERE o.consignee::text = c.contact_id::text) cn ON true
- LEFT JOIN LATERAL ( SELECT company as sh_company,
- address_1 as sh_address_1,
- address_2 as sh_address_2,
- address_3 as sh_address_3,
- address_4 as sh_address_4,
- city as sh_city, state as sh_state, zipcode as sh_zipcode, country as sh_country,
- phone_1 as sh_phone
- FROM contacts c WHERE o.shipper::text = c.contact_id::text) sh ON true
- LEFT JOIN LATERAL ( SELECT company as aa_company,
- address_1 as aa_address_1,
- address_2 as aa_address_2,
- address_3 as aa_address_3,
- address_4 as aa_address_4,
- city as aa_city, state as aa_state, zipcode as aa_zipcode, country as aa_country,
- phone_1 as aa_phone
- FROM contacts c WHERE o.origin_station::text = c.contact_id::text) aa ON true
- LEFT JOIN LATERAL ( SELECT company as dd_company,
- address_1 as dd_address_1,
- address_2 as dd_address_2,
- address_3 as dd_address_3,
- address_4 as dd_address_4,
- city as dd_city, state as dd_state, zipcode as dd_zipcode, country as dd_country,
- phone_1 as dd_phone
- FROM contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
- where lower(serial_no) = '" . strtolower($serial_no) . "'";
- $ocean = common::excuteObjectSql($sql);
- if (!empty($ocean)) {
-
- $ocean['_isf_bol'] = $ocean['isf_bol'];
- if (empty($ocean['_isf_bol'])) {
- $ocean['_isf_bol'] = "AMAW" . $ocean['_h_bol'];
- }
- $isf_ss = md5(md5($ocean['_isf_bol']));
- $isf_ss = substr($isf_ss, 7) . substr($isf_ss, 0, 7);
- if (!empty($ocean['_final_eta'])) {
- $ocean['ETA Dest'] = $ocean['_final_eta'];
- } else if (!empty($ocean['_eta_dest'])) {
- if (strpos($ocean['_eta_dest'], "-") > 0) {
- $ocean['ETA Dest'] = substr($ocean['_eta_dest'], 5, 2) . "/" . substr($ocean['_eta_dest'], 8, 2) . "/" . substr($ocean['_eta_dest'], 0, 4);
- } elseif (strpos($ocean['_eta_dest'], "/") > 0) {
- $ocean['ETA Dest'] = $ocean['_eta_dest'];
- } else {
- $ocean['ETA Dest'] = substr($ocean['_eta_dest'], 4, 2) . "/" . substr($ocean['_eta_dest'], 6, 2) . "/" . substr($ocean['_eta_dest'], 0, 4);
- }
- } else {
- if (!empty($ocean['_m_eta']))
- $ocean['ETA Dest'] = utils::calculate_ETA_Des($serial_no);
- }
- // most update status
- $_schemas = $_REQUEST["_schemas"];
- $mostStatusSql = "select last_status_loc, last_status_city, to_char(last_status_315_date, 'MM/DD/YYYY') as last_status_315_date,last_status_315_code "
- . ", fport_of_loading_un, mport_of_discharge_un, place_of_receipt_un, place_of_delivery_un FROM public.online_ocean "
- . "where serial_no= '" . $ocean["serial_no"] . "'";
- if (!empty($_schemas)) {
- $mostStatusSql .= " and order_from='" . $_schemas . "'";
- }
- $mostStatus = common::excuteObjectSql($mostStatusSql);
- $state = -1;
- if (!empty($mostStatus["last_status_315_code"])) {
- $desc = $mostStatus["last_status_315_code"] . "(" . common::getStatusDesc($mostStatus["last_status_315_code"]) . "): " . $mostStatus["last_status_315_date"];
- $mostStatus = $desc;
- $state = common::getStatusStage($mostStatus["last_status_315_code"]);
- }
- //请求地图是需要的参数
- $uncode = "'";
- if ($mostStatus["place_of_receipt_un"] != $mostStatus["fport_of_loading_un"]) {
- $uncode .= $mostStatus["place_of_receipt_un"];
- }
- $uncode .= "'|'" . $mostStatus["fport_of_loading_un"] . "'|'" . $mostStatus["mport_of_discharge_un"] . "'|'";
- if ($mostStatus["mport_of_discharge_un"] != $mostStatus["place_of_delivery_un"]) {
- $uncode .= $mostStatus["place_of_delivery_un"];
- }
- $uncode .= "'";
- }
- //处理shipment data 暂时写死
- $simplexData = array();
- $simplexData[] = array("index" =>1,"label" =>"Place of Receipt",
- "path" =>$ocean['place_of_receipt_exp']."/".$ocean['place_of_receipt'],"isArrival" =>$state == 1 ? true : false);
- $simplexData[] = array("index" =>2,"label" =>"Port of Loading",
- "path" =>$ocean['fport_of_loading_exp_exp']."/".$ocean['fport_of_loading_exp'],"isArrival" =>$state == 2 ? true : false,
- "children" =>array(array("label" =>"Cargo arrival at Origin","date" =>"2024-02-01"),array("label" =>"'Departure","date" =>"2024-02-01")));
- $simplexData[] = array("index" =>3,"label" =>"Port of Discharge",
- "path" =>$ocean['mport_of_discharge_exp']."/".$ocean['mport_of_discharge'],"isArrival" =>$state == 3 ? true : false,
- "children" =>array(array("label" =>"ETA","date" =>"2024-02-01")));
- $simplexData[] = array("index" =>4,"label" =>"Place of Delivery",
- "path" =>$ocean['place_of_delivery_exp']."/".$ocean['place_of_delivery'],"isArrival" =>$state == 4 ? true : false);
- //处理transportInfo信息数据
- $transportInfo = array("Tracking No." =>$ocean['tracking_no'],"status"=>$status,"mode" => "","origin" =>$ocean['origin_station'],"destination" =>$ocean['destination_station'],
- "etd" =>$ocean['f_etd'],"atd" =>"","eta" =>$ocean['m_eta'],"ata" =>"");
- //处理basicInfo信息数据
- $vessel = utils::outDisplayForMerge($ocean['f_vessel'],$ocean['m_vessel']);
- $voyage = utils::outDisplayForMerge($ocean['f_voyage'],$ocean['m_voyage']);
- $basicInfo = array("MAWB/MBL No." =>$ocean['m_bol'],"HAWB/HBOL" => $ocean['h_bol'],"Carrier_Booking_No" =>$ocean['carrier_booking'],
- "PO_NO" =>$ocean['po_no'],"Vessel/Airline" =>$vessel,"Voyage/Filght" =>$voyage,
- "Incoterm" =>$ocean['terms'],"Service_Type" =>$ocean['service']);
- //处理 拼接地址 ocean表单exp 字段无法精准分割电话和地址信息,只能从contacts表里查询
- $shipper_address = $this->retStationInfo($ocean['sh_address_1'], $ocean['sh_address_2'], $ocean['sh_address_3'], $ocean['sh_address_4'],
- $ocean['sh_city'], $ocean['sh_state'], $ocean['sh_zipcode'], $ocean['sh_country']);
- $consignee_address = $this->retStationInfo($ocean['cn_address_1'], $ocean['cn_address_2'], $ocean['cn_address_3'], $ocean['cn_address_4'],
- $ocean['cn_city'], $ocean['cn_state'], $ocean['cn_zipcode'], $ocean['cn_country']);
- $origin_address = $this->retStationInfo($ocean['aa_address_1'], $ocean['aa_address_2'], $ocean['aa_address_3'], $ocean['aa_address_4'],
- $ocean['aa_city'], $ocean['aa_state'], $ocean['aa_zipcode'], $ocean['aa_country']);
- $destination_address = $this->retStationInfo($ocean['dd_address_1'], $ocean['dd_address_2'], $ocean['dd_address_3'], $ocean['dd_address_4'],
- $ocean['dd_city'], $ocean['dd_state'], $ocean['dd_zipcode'], $ocean['dd_country']);
- $shipperPartners = array("company" =>$ocean['sh_company'],"address"=>$shipper_address,"phone"=>$ocean['sh_phone']);
- $consigneePartners = array("company" =>$ocean['cn_company'],"address"=>$consignee_address,"phone"=>$ocean['cn_phone']);
- $originPartners = array("company" =>$ocean['aa_company'],"address"=>$origin_address,"phone"=>$ocean['aa_phone']);
- $destinationPartners = array("company" =>$ocean['dd_company'],"address"=>$destination_address,"phone"=>$ocean['dd_phone']);
- $businessPartners = array("shipper"=>$shipperPartners,"consignee" => $consigneePartners,"origin" => $originPartners,"destination" => $destinationPartners);
-
- //todo 不确定信息
- $packing = array("Quantity/Unit"=>"47 CTN","G. Weight" => "480.25 KGS","Ch. Weight" => "689.26 KGS","Volume" => "3.801 CBM");
- //处理routes
- $routes = array(array("mode" =>"Sea", "origin" =>$ocean['origin_station'],
- "destination" => $ocean['destination_station'], "etd" => $ocean['f_etd'],"atd" => "",
- "eta" =>$ocean['m_eta'],"ata" =>"","vessel" =>$vessel,"voyageNo" =>$voyage));
- //处理ocean_reference
- $ref_no = array();
- $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
- if(!empty($ref_arr)){
- foreach($ref_arr as $ref) {
- $ref_no[] = array("label"=>$ref["ref_code"],"value"=>$ref["ref_value"]);
- }
- }
- //处理marksAndDescription
- $marksAndDescription = array("marks"=>$ocean['marks'],"description"=>$ocean['description']);
-
- //配置Ocean_Container字段 UI 需要的字段有:Container.no Packing,quantity,Gross weight(kg),Gross weight(LB),CBM,seal#,size.service
- //处理Container
- $ocean_container_column = array();
- $container_column = column::getInstance()->getDisplayColumnAll('Ocean_Container');
- foreach($container_column as $cc){
- $ocean_container_column[] =array("field" =>$cc['database_column_name'],"title" =>$cc['name'],"formatter" =>"","type" =>"normal");
- }
- $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container') . " from oc_container where lower(serial_no) = '" . strtolower($serial_no) . "'";
- $rss = common::excuteListSql($sql);
- foreach ($rss as $key => $rs) {
- //特殊处理weight
- if(!empty($rss[$key]['grs_kgs'])){
- $rss[$key]['grs_kgs'] = $rs['grs_kgs']."KG";
- }
- if(!empty($rss[$key]['grs_lbs'])){
- $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LB";
- }
- }
- $containers = array("container_column"=>$ocean_container_column,"container_data" =>$rss);
-
- /* Container Status */
- //数据库里配置好
- $sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
- $rss = common::excuteListSql($sql);
- $containerStatusData = array();
- if (!empty($rss)) {
- //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
- $container_status_column = array("EE","I","AE","VD","VA");
- foreach ($rss as $rsk => $rs) {
- $containerStatusDataTemp = array();
- $content = array();
- //新UI 还有站点取值,但不清楚取的什么值,CN,SHK 暂时写死
- foreach($container_status_column as $status){
- $dec = common::excuteOneSql("select description from ra_online_edi_event where ra_name = '" . $status . "'");
- $status = strtolower($status);
- $content[] = array("title" =>$dec,"date"=>common::date2usdate($rs[$status]),"country"=>"CN,SHK");
- }
- $containerStatusDataTemp['label'] = $rs['ctnr']." / ".$rs['size'];
- $containerStatusDataTemp['content'] = $content;
- $containerStatusData[] = $containerStatusDataTemp;
- }
- }
- //Milestones info 列名固定
- $Milestones_column = array();
- $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"","type" =>"normal");
- $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"","type" =>"normal");
- $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"","type" =>"normal");
- $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"","type" =>"normal");
- //假数据
- $Milestones_data = array(array("milestones"=>"booking submit","date_time"=>"2024-02-21","locations" => "china", "remarks" =>""));
- $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
- //页面固定写死的信息
- $document_column = array();
- $document_column[] = array("title" =>"File Type","field" =>"file_type","formatter" =>"","type" =>"normal");
- $document_column[] = array("title" =>"File","field" =>"file","formatter" =>"","type" =>"normal");
- $document_data = array();
- $document = _getViewDocType($_REQUEST["_schemas"]);
- $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
- $ocean_can_view_file = common::excuteOneSql("select ocean_can_view_file from ra_online_user where lower(user_login)='".strtolower($_SESSION['ONLINE_USER']['user_login'])."'");
- if (!empty($document)) {
- foreach ($document as $v) {
- $file_type = $v['display_name'];
- $file_arr = $this->getFileByHbol($ocean['_m_bol'], $ocean['_h_bol'], $v['serial_no'], $v['m_h'], $v['display_name'], TRUE,$ocean['_job_bol']) ;
- $tar = json_decode($ocean_can_view_file,true);
- if(!empty($tar[$v['display_name']])){
- foreach ($tar[$v['display_name']] as $dkey => $dvalue) {
- switch ($v['display_name']) {
- case 'HBL':
- $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
- from ra_online_doc_upload
- where lower(bol) = lower('".$ocean['_h_bol']."') and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
- order by id desc";
- break;
- case 'MBL':
- $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
- from ra_online_doc_upload
- where ( lower(bol) = lower('".strtolower($ocean['_m_bol'])."') or lower(bol) = lower('".strtolower($ocean['_job_bol'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
- order by id desc";
- break;
- case 'Others':
- $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date
- from ra_online_doc_upload
- where (lower(bol) = lower('".strtolower($ocean['_h_bol'])."') or lower(bol) = lower('".strtolower($ocean['_m_bol'])."') or lower(bol) = lower('".strtolower($ocean['_job_bol'])."')) and lower(format_serailno) in ('".strtolower(str_replace(";","','",$dvalue['value']))."') and upper((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2]) = '".$dvalue['type']."'
- order by id desc";
- break;
- default:
- $sql = "";
- break;
- }
- if (!empty($sql)) {
- $rss = common::excuteListSql($sql);
- foreach ($rss as $rs) {
- if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
- $file_arr[] = array("url"=>$OutFileURL."/download.php?_schemas=&a=".base64_encode(base64_encode($rs['serial_no'])),
- "file_name" => $rs['file_name'],
- "detail"=>$rs['upload_date'],
- "can_delete"=>_getLoginName() == $rs['upload_by']);
- }else{
- $file[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
- "file_name" => $rs['file_name'],
- "detail"=>$rs['upload_date'],
- "can_delete"=>_getLoginName() == $rs['upload_by']);
- }
- }
- }
- }
- }
- //$document_data[] = array("file_type"=>$file_type,"file"=>$file_arr);
- //按现在的逻辑,有值才会显示
- foreach($file_arr as $f){
- $document_data[] = array("file_type"=>$file_type,"file"=>$f);
- }
- }
- }
- $document_info = array("document_column"=>$document_column,"document_data" =>$document_data);
- $emailRecords = $this->getCommunicationNew($ocean["serial_no"]);
- $cc_email = common::excuteOneSql("select cc_email from public.online_ocean_communication where email_uuid='" . $ocean["serial_no"] . "' order by id desc limit 1");
- $email = $this->getEmail($ocean["serial_no"]);
- $email['cc_email'] = $cc_email;
- $email['emailRecords'] = $emailRecords;
- global $_COPYRIGHT;
- $data = array('transportInfo' => $transportInfo,
- 'basicInfo' => $basicInfo,
- 'businessPartners' => $businessPartners,
- 'ref_no' => $ref_no,
- 'packing' => $packing,
- 'marksAndDescription' => $marksAndDescription,
- 'containers' => $containers,
- 'simplexData' =>$simplexData,
- 'containerStatusData' => $containerStatusData,
- 'document_info' => $document_info,
- 'containers' => $containers,
- 'Milestones' => $Milestones,
- 'routes' => $routes,
- 'email' => $email,
- 'ams_ss' => md5(md5($ocean['serial_no'])),
- 'isf_ss' => $isf_ss,
- '_schemas' =>$_schemas,
- 'can_upload_doc' => strtolower($_SESSION['ONLINE_USER']['can_upload_doc']) == 't' || strtolower($_SESSION['ONLINE_USER']['can_view_doc']) == 't',
- 'canEdiVgm' => _canEdiVgm(),
- 'copyright' =>$_COPYRIGHT);
- common::echo_json_encode(200,$data);
- exit();
- }
- private function _ocean_excel() {
- //现在下载交给前端,后台最后只返回全部字段的列,
- $allColumn = column::getInstance()->getDisplayColumnAll('Ocean_Search');
- $allBookingColumns = column::getInstance()->tableColumns('Ocean_Search',$allColumn);
- common::echo_json_encode(200,array("msg"=>"success","allColums" => $allBookingColumns));
- exit;
- }
-
- private function _ams_isf_log(){
- global $cbpdb;
- $ams_ss = $_POST['ams_ss'];
- $isf_ss = $_POST['isf_ss'];
- $amsLog = array();
- //页面固定写死的信息
- $amsLog_column = array();
- $amsLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
- $amsLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
- $amsLog_column[] = array("title" =>"Name","field" =>"isams_submit","formatter" =>"","type" =>"normal");
- $amsLog_column[] = array("title" =>"Description","field" =>"amslog","formatter" =>"","type" =>"normal");
- $amsLog["amsLog_column"] = $amsLog_column;
- $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
- $amsLog["data"] = array();
- if (_canViewAMSLog()) {
- $s = $ams_ss;
- $s = "PDLA200127H";
- if (!empty($s)) {
- //$cc = $cbpdb->GetAll("select distinct h_bol from ams_information where md5(md5(from_serial_no)) = '" . pg_escape_string($s) . "'");
- $cc = $cbpdb->GetAll("select distinct h_bol from ams_information where h_bol = '" . pg_escape_string($s) . "'");
- foreach ($cc as $v){
- $amses[] = $cbpdb->GetAll("select * from ams_info where h_bol = '" . pg_escape_string($v['h_bol']) . "'");
- }
- //考虑一个情况
- if (count($amses) > 0) {
- $ams = $amses[0];
- $carrier_hbol = substr($ams[0]['m_bol'], 4);
- $carrier_scac = substr($ams[0]['m_bol'], 0, 4);
- if (empty($ams[0]['h_bol'])){
- $amsLog["msg"] = "Origin have not filed ACE-M1, no data found";
- $amsLog["data"] = array();
- }else{
- $log = $cbpdb->GetAll("select cbpreplytime as atime, amslog, cbperrorcode, isams_submit
- from v_e_amslog where hbol = '" . pg_escape_string($ams[0]['h_bol']) . "'
- and split_part(stationname, ',', 1) = split_part('" . pg_escape_string($ams[0]['station_name']) . "', ',', 1)
- order by cbpreplytime desc, substr(cbperrorcode, 2, 1) desc");
- $amsLog["msg"] = "";
- $amsLog["data"] = $log;
- }
- }
- }
- }
- $isfLog = array();
- //页面固定写死的信息
- $isfLog_column = array();
- $isfLog_column[] = array("title" =>"Date Time","field" =>"atime","formatter" =>"","type" =>"normal");
- $isfLog_column[] = array("title" =>"Code","field" =>"cbperrorcode","formatter" =>"","type" =>"normal");
- $isfLog_column[] = array("title" =>"Name","field" =>"isfsubmit","formatter" =>"","type" =>"normal");
- $isfLog_column[] = array("title" =>"Description","field" =>"isflog","formatter" =>"","type" =>"normal");
- $isfLog["isfLog_column"] = $isfLog_column;
- $isfLog["msg"] = "Origin have not filed ISF, no data found";
- $isfLog["data"] = array();
- if (_canViewISFLog()) {
- if (!empty($isf_ss)) {
- $ss = $isf_ss;
- $len = strlen($ss);
- $b = substr($ss, $len - 7) . substr($ss, 0, $len - 7);
- if (empty($b)){
- $isfLog["msg"] = "Origin have not filed ISF, no data found";
- $isfLog["data"] = array();
- }else{
- $isf = $cbpdb->GetRow("select * from ocean_isf where md5(md5(bol)) = '" . pg_escape_string($b) . "' or md5(md5(substr(bol, 5))) = '" . pg_escape_string($b) . "' order by id desc limit 1");
- }
- if (!empty($isf)) {
- if (!empty($isf['dob'])){
- $isf['dob'] = date("m/d/Y", strtotime($isf['dob']));
- }
- $msg = $cbpdb->GetAll("select cbpreplytime as atime, isflog, cbperrorcode, isfsubmit, hbol
- from v_e_isflog where (case when coalesce(isf_no, '')<>''
- then isf_no = '" . pg_escape_string($isf["isf_no"]) . "' else hbol = '" . pg_escape_string($isf["bol"]) . "'
- and stationname = '" . pg_escape_string($isf["station_name"]) . "' end)
- order by cbpreplytime desc, rowid desc");
- $isfLog["msg"] = "";
- $isfLog["data"] = $msg;
- }else{
- $isfLog["msg"] = "Origin have not filed ISF, no data found";
- $isfLog["data"] = array();
- }
-
- }
- }
- $data =array("msg"=>"success",
- "canViewAMSLog" => _canViewAMSLog(),
- "canViewISFLog" => _canViewISFLog(),
- "amsLog" =>$amsLog,
- "isfLog" =>$isfLog);
- common::echo_json_encode(200,$data);
- exit;
- }
-
- private function getEmail($serial_no) {
- return utils::getEmail($serial_no);
- }
- private function getCommunicationNew($serial_no) {
- $list = common::excuteListSql("select to_char(add_time, 'MM/dd/yyyy hh24:MI:ss') as add_times, * from public.online_ocean_communication where email_uuid='$serial_no' and refer_id = 0 order by id");
- $emialRecords =array();
- foreach ($list as $k => $v) {
- $msg =array();
- $msg["name"] = $v["add_by"];
- $msg["creatTime"] = $v["add_times"];
- $msg["content"] = urldecode($v["web_content"]);
- $emialRecords[] = $msg;
- }
- return $emialRecords;
- }
- private function retStationInfo($address_1,$address_2,$address_3,$address_4,$city,$state,$country,$zipcode){
- $stationInfo = "";
- if(!empty($address_1)){
- $stationInfo .= $address_1;
- }
- if(!empty($address_2)){
- $stationInfo .= " ".$address_2;
- }
- if(!empty($address_3)){
- $stationInfo .= " ".$address_3;
- }
- if(!empty($address_4)){
- $stationInfo .= " ".$address_4;
- }
- $temp_str = "";
- if(!empty($city)){
- $temp_str .= $city." ";
- }
- if(!empty($state)){
- $temp_str .= $state." ";
- }
- if(!empty($zipcode)){
- $temp_str .= $zipcode." ";
- }
- if(!empty($country)){
- $temp_str .= $country." ";
- }
- if(!empty($temp_str)){
- return $stationInfo." ".trim($temp_str);
- }
- return $stationInfo;
- }
- /*
- * get file by hbol/destination
- * H:HBL
- * M: MBL
- * F: FL
- * I: C/I & Packing list
- */
- private function getFileByHbol($m_bol, $h_bol, $types, $m_bs, $display, $detail = FALSE,$job_no="") {
- $types = strtolower($types);
- $types = explode(";", $types);
- $m_bs = explode(";", $m_bs);
- $otheres = NULL;
- $filefilter = " ('TELEX') ";//过滤掉类型,单独配置 3537
- $OutFileURL = common::excuteOneSql("select item_value from config where item='OutFileURL'");
- $file = array();
- foreach ($types as $k => $type) {
- $m_b = $m_bs[$k];
- if (strtolower($m_b) == 'm')
- $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) ='".strtolower($job_no)."' ) and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
- if (strtolower($m_b) == 'h')
- $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where lower(bol) = '" . strtolower($h_bol) . "' and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
- if (strtolower($m_b) == 'a')
- $sql = "SELECT from_system,serial_no,file_path, file_name, upload_by, to_char(upload_date, 'MM/DD/YYYY') as upload_date from ra_online_doc_upload where (lower(bol) = '" . strtolower($m_bol) . "' or lower(bol) = '" . strtolower($h_bol) . "' or lower(bol) ='".strtolower($job_no)."') and lower(format_serailno) = '$type' and upper(coalesce((string_to_array((string_to_array(file_name,'.'))[1], '_'))[2],'')) not in ".$filefilter." order by id desc";
- if (!empty($sql)) {
- $rss = common::excuteListSql($sql);
- foreach ($rss as $rs) {
- if ($rs['from_system']=="TOPOCEAN"||$rs['from_system']=="KSMART") {
- $file[] = array("url"=>$OutFileURL.'/download.php?_schemas=&a='.base64_encode(base64_encode($rs['serial_no'])),
- "file_name" => $rs['file_name'],
- "detail"=>$rs['upload_date'],
- "can_delete"=>_getLoginName() == $rs['upload_by']);
- }else {
- $file[] = array("url"=>"main_new_version?action=ocean_order&operate=download&url=". (common::deCode($rs['file_path'] . DS . $rs['file_name'], 'E')),
- "file_name" => $rs['file_name'],
- "detail"=>$rs['upload_date'],
- "can_delete"=>_getLoginName() == $rs['upload_by']);
- }
- }
- }
- }
- return $file;
- }
- /*
- * download file
- */
- private function _download() {
- $url = common::deCode($_GET['url'], 'D');
- common::download_file($url);
- }
-
- }
- ?>
|