ShuanghongS hace 1 año
padre
commit
f5a4325607
Se han modificado 3 ficheros con 161 adiciones y 66 borrados
  1. 141 51
      service/login.class.php
  2. 12 11
      service/ocean_order.class.php
  3. 8 4
      utils/common.class.php

+ 141 - 51
service/login.class.php

@@ -1174,13 +1174,25 @@ class login {
     }
 
     private function getTrackingInfo($reference_number){
-        $sql = "SELECT o.* ,sh.*, cn.* ,aa.*,dd.*,
-                oo.*
-                from public.ocean o 
-                LEFT JOIN LATERAL ( SELECT incoterms as incoterms,tracking_no as _tracking_no,
-                    shippr_uncode,shipper_city,
-                    consignee_uncode,consignee_city,
-                    fport_of_loading_un,mport_of_discharge_un,
+        $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.*,fd.*,oo.*,
+                (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un
+            from public.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,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.fport_of_loading_un limit 1) as pol_timezone,
+                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
+                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_receipt_un limit 1) as por_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_delivery_un limit 1) as pod_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) 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
@@ -1189,39 +1201,45 @@ class login {
                         WHEN (m_iffafd is not null) THEN 'Completed'::text
                         ELSE 'Created'::text
                     END AS new_status
-                FROM online_ocean  WHERE online_ocean.serial_no = o.serial_no) oo ON true
-                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 ocean.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 ocean.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 ocean.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 ocean.contacts c WHERE o.destination_station::text = c.contact_id::text) dd ON true
+                FROM  public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
+            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 ocean.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 ocean.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,
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as aa_timezone
+            FROM ocean.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,
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) as dd_timezone
+            FROM ocean.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,'') limit 1) as fd_timezone
+            FROM ocean.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true
             where (lower(tracking_no) = '" . strtolower($reference_number) . "' 
                 or lower(booking_no) = '" . strtolower($reference_number) . "'
                 or lower(h_bol) = '" . strtolower($reference_number) . "'
@@ -1315,8 +1333,61 @@ class login {
         //Packing 不确定信息
         $packing = array("Quantity/Unit"=>$quantity_tolal,"G. Weight" => $g_weight_tolal." KGS","Ch. Weight" => $ch_weight_tolal." LBS","Volume" => $cbm_tolal." CBM");
 
+        /* Container Status */
+        //数据库里配置好
+        //$sql = "SELECT " . column::getInstance()->getSearchSql('Ocean_Container_Status') . " from oc_container_v where lower(serial_no) = '" . strtolower($serial_no) . "'";
+        $serial_no = $ocean["serial_no"];
+        $ctnr_sql = "SELECT oc.ctnr, oc.serial_no,oc.size FROM oc_container oc LEFT JOIN ocean o ON oc.serial_no = o.serial_no 
+                WHERE o.serial_no='$serial_no'";
+        $ctnr_data = common::excuteListSql($ctnr_sql); 
+        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,
+                    (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";
+            $ctnr_status = common::excuteListSql($ctnr_status_sql);       
+            //记录所有的信息
+            $EDI315TimeAndLocation = array();
+            foreach($ctnr_status as $event){
+                if(!empty($EDI315TimeAndLocation['IFFARR']) && $EDI315TimeAndLocation['IFFARR']['code'] == "EB"){
+                    //如果存在EB 的EB 的优先级最高
+                    continue;
+                }
+                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']);
+            }
+        }
+
         //Milestones 数据信息待定
-        $Milestones = common::getMilestonesInfo($ocean);
+        $Milestones = common::getMilestonesInfo($ocean,$EDI315TimeAndLocation);
 
         global $_COPYRIGHT;
         $data = array('transportInfo' => $transportInfo, 
@@ -1330,21 +1401,34 @@ class login {
     }
 
     private function trackingSfsSql($reference_number){
-        $sql = "SELECT o.* ,sh.*, cn.* ,aa.*,dd.*,oo.*
+        $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.*,fd.*,oo.*,
+                (select uncode from ports where  code = o.port_of_transshipment) as port_of_transshipment_un
             from sfs.ocean o 
-            LEFT JOIN LATERAL ( SELECT incoterms as incoterms,tracking_no as _tracking_no,
-                    shippr_uncode,shipper_city,
-                    consignee_uncode,consignee_city,
-                    fport_of_loading_un,mport_of_discharge_un,
+            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,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.fport_of_loading_un limit 1) as pol_timezone,
+                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
+                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_receipt_un limit 1) as por_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_delivery_un limit 1) as pod_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) 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
                         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
-		        END AS new_status
-                FROM online_ocean  WHERE online_ocean.serial_no = o.serial_no) oo ON true
+                        ELSE 'Created'::text
+                    END AS new_status
+                FROM  public.online_ocean oo WHERE oo.serial_no::text = o.serial_no::text) oo ON true
             LEFT JOIN LATERAL ( SELECT company as cn_company,
                 address_1 as cn_address_1,
                 address_2 as cn_address_2,
@@ -1367,7 +1451,8 @@ class login {
                 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,'') limit 1) as aa_timezone
             FROM sfs.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,
@@ -1375,8 +1460,13 @@ class login {
                 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,'') limit 1) as dd_timezone
             FROM sfs.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,'') limit 1) as fd_timezone
+            FROM sfs.contacts c WHERE o.final_desination::text = c.contact_id::text) fd ON true
         where (lower(tracking_no) = '" . strtolower($reference_number) . "' 
             or lower(booking_no) = '" . strtolower($reference_number) . "'
             or lower(h_bol) = '" . strtolower($reference_number) . "'

+ 12 - 11
service/ocean_order.class.php

@@ -1107,14 +1107,14 @@ class ocean_order {
                     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,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.fport_of_loading_un limit 1) as pol_timezone,
+                    (select uncity from public.ports where uncode = oo.fport_of_loading_un limit 1) as pol_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.mport_of_discharge_un limit 1) as mpod_timezone,
+                    (select uncity from public.ports where uncode = oo.mport_of_discharge_un limit 1) as mpod_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_receipt_un limit 1) as por_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_receipt_un limit 1) as por_uncity,
+                    (select timezonecode from public.city_ports where ctrycitycode = oo.place_of_delivery_un limit 1) as pod_timezone,
+                    (select uncity from public.ports where uncode = oo.place_of_delivery_un limit 1) 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
@@ -1148,7 +1148,7 @@ class ocean_order {
                 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,
-                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'')) as aa_timezone
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) 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,
@@ -1157,13 +1157,14 @@ class ocean_order {
                 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,
-                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'')) as dd_timezone
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) 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
+                (select timezonecode from public.city_ports where ctrycitycode = LEFT(country, 2) || COALESCE(city_code,'') limit 1) 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) . "'";
+        //error_log($sql);
         return $sql;
     }
 

+ 8 - 4
utils/common.class.php

@@ -1572,12 +1572,16 @@ class common {
             $timezone = "";
             if(!empty($EDI315TimeAndLocation[$mda['code']])){
                 $edi315Info = $EDI315TimeAndLocation[$mda['code']];
-                $locations = $edi315Info['location'];
-                $timezone = $edi315Info['timezone'];
+                if(!empty($edi315Info)){
+                    $locations = $edi315Info['location'];
+                    $timezone = $edi315Info['timezone'];
+                }
             }else{
                 $edi315Info =  $Milestones_NO_Mapping[$mda['code']];
-                $locations = $edi315Info['location'];
-                $timezone = $edi315Info['timezone'];
+                if(!empty($edi315Info)){
+                    $locations = $edi315Info['location'];
+                    $timezone = $edi315Info['timezone'];
+                }
             }
             $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$timezone,
                 "locations" => $locations, "remarks" =>$mda['remark']);