ShuanghongS 1 an în urmă
părinte
comite
37c10c45c2
5 a modificat fișierele cu 214 adăugiri și 121 ștergeri
  1. 32 3
      main_new_version.php
  2. 22 22
      service/ajax.class.php
  3. 2 2
      service/login.class.php
  4. 79 50
      service/ocean_order.class.php
  5. 79 44
      utils/common.class.php

+ 32 - 3
main_new_version.php

@@ -469,7 +469,8 @@ switch ($action) {
 	    	            WHEN dd.status is null THEN 'Created'::text
 	    	            ELSE dd.status::text
 		            END AS new_status,
-                    dd.act_date,dd.description,dd.timezone,dd.act_time
+                    dd.act_date,dd.act_time,dd.description,
+                    dd.timezone,dd.code as dd_code
                     FROM public.online_ocean
                     left join LATERAL (select case when a.code='IFFBCF' then 'Created'
                                     when a.code='IFFCPU' then 'Cargo Received'
@@ -480,7 +481,7 @@ switch ($action) {
                                     else 'Created' END as status,
                                     act_date,act_time,
                                     _dd.description as description,
-                                    timezone
+                                    timezone,code
                             from  ocean_milestone a 
                                 left join LATERAL (select sno,description  from  milestone where code=a.code and project_no = '*'  order by sno limit 1) _dd on true
                     where a.serial_no=online_ocean.serial_no 
@@ -497,6 +498,34 @@ switch ($action) {
             //RecentStatusList
             $RecentStatusList = array();
             foreach ($rss as $key => $value) {
+                $_schemas = $value['_schemas'];
+                if($_schemas == "public"){
+                    $_schemas = "ocean";
+                }
+                $timezone = "";
+                if($value['dd_code'] == "IFFBCF" || $value['dd_code'] == "IFFCPU"){
+                    $sql = "SELECT (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'')) as timezone
+                         FROM $_schemas.contacts c WHERE  c.contact_id = '".$value['origin']."'";
+                    $timezone = common::excuteOneSql($sql);     
+                }
+                if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP"){
+                    $sql = "select timezonecode from public.city_ports where ctrycitycode = '".$value['place_of_receipt_un']."'";
+                    $timezone = common::excuteOneSql($sql);
+                    if(empty($timezone)){
+                        $sql = "select timezonecode from public.city_ports where ctrycitycode = '".$value['fport_of_loading_un']."'";
+                        $timezone = common::excuteOneSql($sql);
+                    }     
+                }
+                if($value['dd_code'] == "IFFARR"){
+                    $sql = "select timezonecode from public.city_ports where ctrycitycode = '".$value['mport_of_discharge_un']."'";
+                    $timezone = common::excuteOneSql($sql);
+                }
+
+                if($value['dd_code'] == "IFFAFD"){
+                    $sql = "select timezonecode from public.city_ports where ctrycitycode = '".$value['place_of_delivery_un']."'";
+                    $timezone = common::excuteOneSql($sql);
+                }
+
                 $Arrived = $value['description'];
                 $RecentStatusList[] = array("Title"=>$value['h_bol'],
                     "name"=>utils::outDisplayForMerge($value['f_vessel'],$value['f_voyage']),
@@ -512,7 +541,7 @@ switch ($action) {
                     "Arrived"=>$Arrived,
                     "Time"=>$value["act_date"],
                     "act_time" =>$value["act_time"],
-                    "timezone"=>$value["timezone"],
+                    "timezone"=>$timezone,
                     "_schemas"=>$value["_schemas"],
                     "a" =>common::deCode($value['serial_no'], 'E'));
             }

+ 22 - 22
service/ajax.class.php

@@ -473,13 +473,13 @@ class ajax {
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT shipper_city)
                 from public.online_booking $sqlWhere 
-                    and COALESCE(shippr_uncode)<>''
+                    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.online_booking $sqlWhere 
-                    and COALESCE(shippr_uncode)<>''
+                    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);      
@@ -489,13 +489,13 @@ class ajax {
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select count(DISTINCT consignee_city)
                 from public.online_booking $sqlWhere
-                    and COALESCE(consignee_uncode)<>'' 
+                    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.online_booking $sqlWhere
-                    and COALESCE(consignee_uncode)<>'' 
+                    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);
@@ -505,13 +505,13 @@ class ajax {
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
                 from public.online_booking $sqlWhere
-                    and COALESCE(place_of_receipt_uncode)<>'' 
+                    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.online_booking $sqlWhere
-                    and COALESCE(place_of_receipt_uncode)<>'' 
+                    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);
@@ -521,13 +521,13 @@ class ajax {
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT fport_of_loading_exp)
                 from public.online_booking $sqlWhere
-                    and COALESCE(fport_of_loading_uncode)<>''  
+                    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.online_booking $sqlWhere
-                    and COALESCE(fport_of_loading_uncode)<>'' 
+                    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);
@@ -537,13 +537,13 @@ class ajax {
             $sqlWhere = $this->getBookingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
                 from public.online_booking $sqlWhere
-                    and COALESCE(place_of_delivery_uncode)<>'' 
+                    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.online_booking $sqlWhere
-                    and COALESCE(place_of_delivery_uncode)<>'' 
+                    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";
 
@@ -559,13 +559,13 @@ class ajax {
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT shipper_city)
                 from public.online_ocean $sqlWhere
-                    and COALESCE(shippr_uncode)<>'' 
+                    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.online_ocean $sqlWhere
-                    and COALESCE(shippr_uncode)<>'' 
+                    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);
@@ -575,13 +575,13 @@ class ajax {
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT consignee_city)
                 from public.online_ocean $sqlWhere
-                    and COALESCE(consignee_uncode)<>'' 
+                    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.online_ocean $sqlWhere
-                    and COALESCE(consignee_uncode)<>'' 
+                    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);             
@@ -591,13 +591,13 @@ class ajax {
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_receipt_exp)
                 from public.online_ocean $sqlWhere
-                    and COALESCE(place_of_receipt_un)<>'' 
+                    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.online_ocean $sqlWhere
-                    and COALESCE(place_of_receipt_un)<>'' 
+                    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);          
@@ -607,13 +607,13 @@ class ajax {
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT port_of_loading)
                 from public.online_ocean $sqlWhere 
-                    and COALESCE(fport_of_loading_un)<>''
+                    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.online_ocean $sqlWhere
-                    and COALESCE(fport_of_loading_un)<>'' 
+                    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);
@@ -623,13 +623,13 @@ class ajax {
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT port_of_discharge)
                 from public.online_ocean $sqlWhere
-                    and COALESCE(mport_of_discharge_un)<>'' 
+                    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.online_ocean $sqlWhere 
-                    and COALESCE(mport_of_discharge_un)<>''
+                    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);        
@@ -639,13 +639,13 @@ class ajax {
             $sqlWhere = $this->getTrackingSearchWhere();
             $count_sql = "select COUNT(DISTINCT place_of_delivery_exp)
                 from public.online_ocean $sqlWhere
-                    and COALESCE(place_of_delivery_un)<>'' 
+                    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.online_ocean $sqlWhere
-                    and COALESCE(place_of_delivery_un)<>'' 
+                    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);        

+ 2 - 2
service/login.class.php

@@ -1184,7 +1184,7 @@ class login {
                     CASE
                         WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
                         WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
-                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departure'::text
                         WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
                         WHEN (m_iffafd is not null) THEN 'Completed'::text
                         ELSE 'Created'::text
@@ -1339,7 +1339,7 @@ class login {
                     CASE
                         WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
                         WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
-                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departed'::text
+                        WHEN (m_iffdep is not null and m_iffarr is null and m_iffafd is null) THEN 'Departure'::text
                         WHEN (m_iffarr is not null and m_iffafd is null) THEN 'Arrived'::text
                         WHEN (m_iffafd is not null) THEN 'Completed'::text
 	    	        ELSE 'Created'::text

+ 79 - 50
service/ocean_order.class.php

@@ -163,16 +163,18 @@ class ocean_order {
             if ($schemas <> "public") {
                 $err_msg .= "This hbol do not support.";
             }
+            $err_msg_ctnr = "";
+            $err_msg_CFS = "";
             foreach ($rs as $cv) {
                 if (empty($cv["ctnr"])) {
-                    $err_msg .= "Container# is empty.";
+                    $err_msg_ctnr = "Container# is empty.";
                 }
                 if (substr($cv["service"], 0, 3) == "CFS") {
-                    $err_msg .= "CFS cannot support update.";
+                    $err_msg_CFS = "CFS cannot support update.";
                 }
             }
             if (!empty($err_msg)) {
-                $err_msg = "You cant't add this VGM, (" . $err_msg . ")";
+                $err_msg = "You cant't add this VGM, (" . $err_msg ." ". $err_msg_ctnr." ".$err_msg_CFS.")";
             }
             $serial_no = common::deCode($serial_no, "E");
 
@@ -646,6 +648,7 @@ class ocean_order {
         //处理containerStatusData
         $containerStatusData = $vueData['containerStatusData'];
 
+
         //处理ocean_reference
         $ref_no = array();
         $ref_arr = common::excuteListSql("select * from ocean_reference where lower(serial_no) = '" . strtolower($serial_no) . "'");
@@ -704,7 +707,7 @@ class ocean_order {
         $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
         
         //Milestones info  列名固定
-        $Milestones = common::getMilestonesInfo($ocean);
+        $Milestones = common::getMilestonesInfo($ocean,$vueData['EDI315TimeAndLocation']);
 
         //页面固定写死的信息
         $document_column = array();
@@ -779,7 +782,6 @@ class ocean_order {
         }
         $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"]);
@@ -1096,13 +1098,24 @@ class ocean_order {
             $_schemas = "ocean";
         }
         $sql = "SELECT m_eta as _m_eta,  h_bol as _h_bol, m_bol as _m_bol,job_no as _job_bol,
-                o.* ,sh.*, cn.* ,aa.*,dd.*,oo.*,
-                (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un
+                o.* ,sh.*, cn.* ,aa.*,dd.*,fd.*,oo.*,
+                (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un,
             from ocean o 
             LEFT JOIN LATERAL ( SELECT tracking_no as _tracking_no,shippr_uncode,shipper_city,
                     consignee_uncode,consignee_city,incoterms,
-                    fport_of_loading_un,mport_of_discharge_un,
-                    place_of_receipt_un,place_of_delivery_un,po_no as _po_no,
+                    fport_of_loading_un,
+                    mport_of_discharge_un,
+                    place_of_receipt_un,
+                    place_of_delivery_un,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.fport_of_loading_un) as pol_timezone,
+                    (select uncity from public.ports where uncode = oo.fport_of_loading_un) as pol_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.mport_of_discharge_un) as mpod_timezone,
+                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un) as mpod_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_receipt_un) as por_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_receipt_un) as por_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_delivery_un) as pod_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_delivery_un) as pod_uncity,
+                    po_no as _po_no,
                     CASE
                         WHEN ((m_iffbcf is not null or m_iffbcf is null) and m_iffcpu is null and m_iffrec is null and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Created'::text
                         WHEN ((m_iffcpu is not null or m_iffrec is not null) and m_iffdep is null and m_iffarr is null and m_iffafd is null) THEN 'Cargo Received'::text
@@ -1134,7 +1147,8 @@ class ocean_order {
                 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
+                phone_1 as aa_phone,
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'')) as aa_timezone
             FROM $_schemas.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,
@@ -1142,8 +1156,13 @@ class ocean_order {
                 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
+                phone_1 as dd_phone,
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'')) as dd_timezone
             FROM $_schemas.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
+            LEFT JOIN LATERAL ( SELECT 
+                city as fd_city,
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'')) as fd_timezone
+            FROM $_schemas.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true
         where lower(serial_no) = '" . strtolower($serial_no) . "'";
         return $sql;
     }
@@ -1162,25 +1181,42 @@ class ocean_order {
         $VD = "";
         $VA = "";    
         foreach ($ctnr_data as $cd){
+            //存在柜号为空的数据情况
+            if(empty($cd['ctnr'])){
+                continue;
+            }
             $ctnr_status_sql = "select s.source_id, s.event_base as event,
                     to_char(to_timestamp(s.event_date, 'YYYYMMDD'), 'YYYY-MM-DD') as eventdate,
                     to_char(to_timestamp(s.event_time, 'HH24MI'), 'HH24:MI') as eventtime,
                     e.description,s.event_type as eventtype, 
-                    s.event_code as eventcode, s.event_city as eventcity 
+                    s.event_code as eventcode, s.event_city as eventcity,
+                    (select timezonecode from public.city_ports where ctrycitycode = s.event_code) as timezone,
+                    (select uncity from public.ports where uncode = s.event_code) as uncity,
+                    case when event ='I'  then 'IFFREC'::text
+                        when event ='AE'  then 'IFFONB'::text
+                        when event ='VD'  then 'IFFDEP'::text
+                        when event ='EB' or event ='VA' then 'IFFARR'::text
+                        when event ='UV'  then 'IFFUND'::text
+                        when event ='VA'  then 'IFFAFD'::text
+                        when event ='AV'  then 'IFFCTA'::text
+                        when event ='CT'  then 'IFFICC'::text
+                        when event ='OA' or event ='D'  then 'IFFPPD'::text
+                        when event ='EE'  then 'IFFECP'::text
+                        else '' ::text
+                    end as milestone_code  
                 from public.ra_online_container_status_v s 
                     left join ra_online_edi_event e on s.event_base = e.ra_name 
                 where s.serial_no = '" . pg_escape_string($cd['serial_no']) . "' 
                     and s.container_no = '" . pg_escape_string($cd['ctnr']) . "' and is_display = true 
                 order by to_timestamp(s.event_date, 'YYYYMMDD') asc,
-                    to_timestamp(s.event_time, 'HH24MI') asc,
-                    e.ra_order asc";
+                    to_timestamp(s.event_time, 'HH24MI') asc,e.ra_order asc";
             $ctnr_status = common::excuteListSql($ctnr_status_sql);       
 
             //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
             $container_status_column = array("EE","I","AE","VD","VA");
             $containerStatusDataTemp = array();
-            $ctnr_uncodes = "";
             $content = array();
+            //按顺序处理 新版只显示几个状态
             foreach($container_status_column as $status){
                 foreach($ctnr_status as $event){
                     if(strtolower($event['event']) == strtolower($status)){
@@ -1189,24 +1225,28 @@ class ocean_order {
                             $eventdate.= " " . $event["eventtime"];
                         }
                         $location_code = $event["eventcode"];
-                        $content[] = array("code" =>$status,"title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code);
-                        $ctnr_uncodes .=$location_code.";";
+                        $content[] = array("code" =>$status,"title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code,"timezone"=>$event['timezone']);
+                        if(strtolower($event['event']) == "vd" && !empty($eventdate)){
+                            $VD = $eventdate;
+                        }
+                        if(strtolower($event['event']) == "va" && !empty($eventdate)){
+                            $VA = $eventdate;
+                        }
                     }
                 }
             }
-            //查询全部uncode timezone
-            $uncode_rs = common::getCityPortsInfo($ctnr_uncodes);
-            //循环去回填时区
-            foreach($content as $ck => $cv){
-                $content[$ck]['timezone'] = $uncode_rs[$cv['country']];
-                //记录vd
-                if($cv['code'] == "VD" && empty($cv['date'])){
-                    $VD = $cv['date'];
+            //记录所有的信息
+            $EDI315TimeAndLocation = array();
+            foreach($ctnr_status as $event){
+                if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
+                    //如果存在EB 的EB 的优先级最高
+                    continue;
                 }
-                //记录vd
-                if($cv['code'] == "VA" && empty($cv['date'])){
-                    $VA = $cv['date'];
+                if(!empty($EDI315TimeAndLocation['IFFPPD']) && $EDI315TimeAndLocation['IFFARR']['code'] == "OA"){
+                    //如果存在OA 的OA 的优先级最高
+                    continue;
                 }
+                $EDI315TimeAndLocation[$event['milestone_code']] = array("code"=>$event['event'],"timezone"=>$event['timezone'],"location"=>$event['uncity']);
             }
 
             $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
@@ -1214,6 +1254,7 @@ class ocean_order {
             $containerStatusData[] = $containerStatusDataTemp;
         }
         $data['containerStatusData'] = $containerStatusData;
+        $data['EDI315TimeAndLocation'] = $EDI315TimeAndLocation;
 
         //处理shipment data
         $ocean_milestone_status = common::excuteListSql("select code,
@@ -1226,14 +1267,6 @@ class ocean_order {
             $ocean_milestone_status_code[$oms['code']] = $oms;
         }
         
-        //当EDI315更新时,处理f_etd,m_eta(目前数据未同步,如果以后数据规范后,可以直接用milestone的值)
-        if(!empty($VD)){
-            $ocean['f_etd'] = $VD;
-        }
-        if(!empty($VA)){
-            $ocean['m_eta'] = $VA;
-        }
-
         if ($state < 1){
             //未发生前
             if(!empty($ocean_milestone_status_code['IFFDEP']['est_date'])){
@@ -1247,11 +1280,11 @@ class ocean_order {
             }
         }    
         //先处理一下 ATD 和 ATA,在进行后面的取值
-        if(empty($ocean['atd'])){
-            $ocean['atd'] = $ocean['f_etd'];
+        if(empty($ocean['atd']) && !empty($VD)){
+            $ocean['atd'] = $VD;
         }
-        if(empty($ocean['ata'])){
-            $ocean['ata'] = $ocean['m_eta'];
+        if(empty($ocean['ata']) && !empty($VA)){
+            $ocean['ata'] = $VA;
         } 
 
         $simplexData = array();
@@ -1321,19 +1354,15 @@ class ocean_order {
         $simplexData[] = $place_of_Delivery_status;
         $data['shipmentData'] = $simplexData;
 
-        //获取对应uncode 对应的时间
-        $uncodes = $ocean['fport_of_loading_un'].";".$ocean['mport_of_discharge_un'];
-        $codeinfo = common::getCityPortsInfo($uncodes);
-
         //处理transportInfo信息数据
         $transportInfo = array("Tracking No." =>$ocean['_tracking_no'],"status"=>$ocean['new_status'],"mode" => "Ocean Freight",
             "origin" =>$ocean['shippr_uncode'],"destination" =>$ocean['consignee_uncode'],
             "etd" =>$ocean['f_etd'],"atd" =>$ocean['atd'],
-            "etd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
-            "atd_timezone" =>$codeinfo[$ocean['fport_of_loading_un']],
+            "etd_timezone" =>$ocean['pol_timezone'],
+            "atd_timezone" =>$ocean['pol_timezone'],
             "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
-            "eta_timezone" =>$codeinfo[$ocean['mport_of_discharge_un']],
-            "ata_timezone" =>$codeinfo[$ocean['mport_of_discharge_un']]);
+            "eta_timezone" =>$ocean['mpod_timezone'],
+            "ata_timezone" =>$ocean['mpod_timezone']);
         $data['transportInfo'] = $transportInfo;
 
         //处理basicInfo信息数据
@@ -1367,11 +1396,11 @@ class ocean_order {
             $routes = array(array("mode" =>"Ocean Freight","mode_label" =>"Sea", "origin" =>$ocean['shippr_uncode'],
                 "destination" => $ocean['port_of_transshipment_un'],
                 "etd" => $ocean['f_etd'],"atd" => $ocean['atd'],
-                "eta" =>$ocean['f_eta'],"ata" => $ocean['f_eta'],
+                "eta" =>$ocean['f_eta'],"ata" =>"",
                 "vessel" =>$ocean['f_vessel'],"voyageNo" =>$ocean['f_voyage']));
             $routes[] = array("mode" =>"Ocean Freight", "mode_label" =>"Sea","origin" =>$ocean['port_of_transshipment_un'],
                 "destination" => $ocean['consignee_uncode'],
-                "etd" => $ocean['m_etd'],"atd" => $ocean['m_etd'],
+                "etd" => $ocean['m_etd'],"atd" => "",
                 "eta" =>$ocean['m_eta'],"ata" =>$ocean['ata'],
                 "vessel" =>$ocean['m_vessel'],"voyageNo" =>$ocean['m_voyage']);
         }else{

+ 79 - 44
utils/common.class.php

@@ -1276,9 +1276,6 @@ class common {
         $sqlWhere = " " . $sqlWhere;
 
         $toporiginType = "shippr_uncode";
-        // $shippr_uncode_10_sql = "select count(shippr_uncode) as num,shippr_uncode,
-        //     (array_agg(shipper_city))[1] AS shipper_city from online_ocean  
-        // where 1=1 and COALESCE(shippr_uncode)<>'' $sqlWhere group by shippr_uncode order by num desc limit 10";
         $shippr_uncode_10_sql ="with aa as  (select count(shippr_uncode) as num,shippr_uncode,
                                 (array_agg(shipper_city))[1] AS shipper_city from online_ocean  
                         where 1=1 and COALESCE(shippr_uncode)<>'' $sqlWhere group by shippr_uncode order by num desc limit 10)
@@ -1303,9 +1300,6 @@ class common {
         //$toporiginType = "fport_of_loading_un";
 
         $topdestinationinType = "consignee_uncode";
-        // $consignee_uncode_10_sql = "select count(consignee_uncode) as num,consignee_uncode,
-        // (array_agg(consignee_city))[1] AS consignee_city 
-        // from online_ocean  where 1=1  and COALESCE(consignee_uncode)<>''  $sqlWhere group by consignee_uncode order by num desc limit 10";
         $consignee_uncode_10_sql = "with aa as  (select count(consignee_uncode) as num,consignee_uncode,
                     (array_agg(consignee_city))[1] AS consignee_city 
                 from online_ocean  where 1=1  and COALESCE(consignee_uncode)<>''  $sqlWhere group by consignee_uncode order by num desc limit 10)
@@ -1555,59 +1549,37 @@ class common {
         return $str;
     }
 
-    public static function getMilestonesInfo($ocean){
-        //Milestones info  列名固定
+    public static function getMilestonesInfo($ocean,$EDI315TimeAndLocation){
+        //Milestones info列名固定
         $Milestones_column = array();
         $Milestones_column[] = array("title" =>"Milestones","field" =>"milestones","formatter" =>"normal","type" =>"normal");
         $Milestones_column[] = array("title" =>"Date Time","field" =>"date_time","formatter" =>"dateTime","type" =>"normal");
         $Milestones_column[] = array("title" =>"Locations","field" =>"locations","formatter" =>"normal","type" =>"normal");
         $Milestones_column[] = array("title" =>"Remarks","field" =>"remarks","formatter" =>"normal","type" =>"normal");
 
-        //IFF Event and EDI 315 Mapping
-        $Mapping = array("IFFREC","IFFONB","IFFDEP","IFFARR","IFFUND","IFFAFD","IFFCTA","IFFICC","IFFPPD","IFFECP");
-        $Mapping_location = array();
-        foreach($Mapping as $code){
-            if($code == "IFFREC" || $code == "IFFONB" || $code == "IFFDEP" || $code == "IFFECP"){
-                //Place of Receipt,Port of Loading
-                $Mapping_location[$code] = empty($ocean['place_of_receipt_exp']) ? $ocean['fport_of_loading_exp'] : $ocean['place_of_receipt_exp'];
-            }
-            if($code == "IFFARR" || $code == "IFFICC" || $code == "IFFPPD"){
-                //Port of discharge
-                $Mapping_location[$code] = $ocean['mport_of_discharge_exp'];
-            }
-            if($code == "IFFUND"){
-                //Port of discharge,place of delivery / Final Destination
-                $Mapping_location[$code] = empty($ocean['mport_of_discharge_exp']) ? $ocean['place_of_delivery_exp']." ".$ocean['final_desination_exp'] : $ocean['mport_of_discharge_exp'];
-            }
-            if($code == "IFFAFD"){
-                //Place of Delivery
-                $Mapping_location[$code] = $ocean['place_of_delivery_exp'];
-            }
-            if($code == "IFFCTA"){
-                //Place of Delivery,port of discharge
-                $Mapping_location[$code] = empty($ocean['place_of_delivery_exp']) ? $ocean['mport_of_discharge_exp'] : $ocean['place_of_delivery_exp'];
-            }
-        }
-        
+        //EDI315 有关联查询,以那个为准。但是如果是手工录入或者不是EDI 进去的Milestone的情况,这以这个为准
+        $Milestones_NO_Mapping = common::getMilestones_NO_Mapping_Data($ocean);
+    
         //Milestones 数据信息待定
         $Milestones_data = array();
-        $Milestones_data_arr = common::excuteListSql("select  sn.description,
-            act_date||' '||COALESCE(act_time,'') as date_time,
-            remark,timezone,a.code,create_by, '' as act_update_by
+        $Milestones_data_arr = common::excuteListSql("select  sn.description,act_date||' '||COALESCE(act_time,'') as date_time,
+            remark,timezone,a.code
         from  ocean_milestone a  
             inner join customer_service_milestone_sno sn on sn.code=a.code
         where a.serial_no='".$ocean["serial_no"]."' and act_date is not null  order by sn.sno asc");           
         foreach($Milestones_data_arr as $mda){
             $locations = "";
-            if(!empty($Mapping_location[$mda['code']])){
-                $locations = $Mapping_location[$mda['code']];
+            $timezone = "";
+            if(!empty($EDI315TimeAndLocation[$mda['code']])){
+                $edi315Info = $EDI315TimeAndLocation[$mda['code']];
+                $locations = $edi315Info['location'];
+                $timezone = $edi315Info['timezone'];
             }else{
-                //第二优先级:用Milestone更新的对应的站点的location
-                $user_login = empty($mda['act_update_by']) ?  $mda['create_by'] : $mda['act_update_by'];
-                $city_by_user = common::excuteObjectSql("select e.city from ra_online_user r,employee e where r.employee_id=e.employee_id and lower(r.user_login)=lower('$user_login') limit 1");
-                $locations = $city_by_user['city'];
+                $edi315Info =  $Milestones_NO_Mapping[$mda['code']];
+                $locations = $edi315Info['location'];
+                $timezone = $edi315Info['timezone'];
             }
-            $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$mda['timezone'],
+            $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$timezone,
                 "locations" => $locations, "remarks" =>$mda['remark']);
         }  
         $Milestones = array("Milestones_column"=>$Milestones_column,"Milestones_data" =>$Milestones_data);
@@ -1627,5 +1599,68 @@ class common {
         }
         return $data;
     }
+
+    /**
+     * EDI315 有关联查询,以那个为准。但是如果是手工录入或者没有对应的情况,这以这个为准
+     */
+    public static function getMilestones_NO_Mapping_Data($ocean){
+        $Milestones_NO_Mapping = array();
+        //取origin
+        $Milestones_NO_Mapping['IFFBCF'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
+        $Milestones_NO_Mapping['IFFBCR'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
+        $Milestones_NO_Mapping['IFFSIL'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
+        $Milestones_NO_Mapping['IFFEDO'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
+        $Milestones_NO_Mapping['IFFECC'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>$ocean['aa_city']);
+
+        //取 1:Place of Receipt   2:Port of Loading
+        if(!empty($ocean['por_uncity'])){
+            $Milestones_NO_Mapping['IFFREC'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
+            $Milestones_NO_Mapping['IFFONB'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
+            $Milestones_NO_Mapping['IFFDEP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
+            $Milestones_NO_Mapping['IFFECP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
+        }else{
+            $Milestones_NO_Mapping['IFFREC'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
+            $Milestones_NO_Mapping['IFFONB'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
+            $Milestones_NO_Mapping['IFFDEP'] = array("code"=>"por/pol","timezone"=>$ocean['pol_timezone'],"location"=>$ocean['pol_uncity']);
+            $Milestones_NO_Mapping['IFFECP'] = array("code"=>"por/pol","timezone"=>$ocean['por_timezone'],"location"=>$ocean['por_uncity']);
+        }
+    
+        //取destination
+        $Milestones_NO_Mapping['IFFCSN'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>$ocean['dd_city']);
+        $Milestones_NO_Mapping['IFFIDO'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>$ocean['dd_city']);
+
+        //取Port of discharge
+        $Milestones_NO_Mapping['IFFARR'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
+        $Milestones_NO_Mapping['IFFICC'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
+        $Milestones_NO_Mapping['IFFPPD'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
+
+        //取1:Port of discharge  2:place of delivery / Final Destination
+        if(!empty($ocean['mpod_uncity'])){
+            $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
+        }else if(!empty($ocean['pod_uncity'])){
+            $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
+        }else{
+            $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['fd_timezone'],"location"=>$ocean['fd_city']);
+        }
+
+        //Place of Delivery
+        $Milestones_NO_Mapping['IFFAFD'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
+        $Milestones_NO_Mapping['IFFADW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
+        $Milestones_NO_Mapping['IFFDDW'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
+        $Milestones_NO_Mapping['IFFDEL'] = array("code"=>"pod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
+
+        //1:Place of Delivery  2:port of discharge
+        if(!empty($ocean['pod_uncity'])){
+            $Milestones_NO_Mapping['IFFCTA'] = array("code"=>"pod/mpod","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
+        }else{
+            $Milestones_NO_Mapping['IFFCTA'] = array("code"=>"pod/mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
+        }
+
+        //final_destination
+        $Milestones_NO_Mapping['IFFECR'] = array("code"=>"fd","timezone"=>$ocean['fd_timezone'],"location"=>$ocean['fd_city']);
+        $Milestones_NO_Mapping['IFFHBL'] = array("code"=>"fd","timezone"=>$ocean['fd_timezone'],"location"=>$ocean['fd_city']);
+
+        return $Milestones_NO_Mapping;
+    }
 }
 ?>