ShuanghongS 1 년 전
부모
커밋
51e9e3be54
3개의 변경된 파일352개의 추가작업 그리고 176개의 파일을 삭제
  1. 113 42
      main_new_version.php
  2. 24 87
      service/ocean_order.class.php
  3. 215 47
      utils/common.class.php

+ 113 - 42
main_new_version.php

@@ -120,28 +120,81 @@ switch ($action) {
         common::echo_json_encode(200, $data);
         exit();
         break;
-    case 'main_report_kpi':
-        $type = $_REQUEST["r_type"];
-        $container_type = $_REQUEST["container_type"];
-        if (empty($_REQUEST["b_date"])) {
+    case 'main_report_etd':
+        //这里只有r1查询
+        $type = "r1";
+        $container_type = "";
+        $date_type = strtolower($_REQUEST["date_type"]);
+        if (empty($_REQUEST["date_start"])) {
             $bdate = "null";
         } else {
-            $bdate = $_REQUEST["b_date"];
+            $bdate = $_REQUEST["date_start"];
             $bdate = "'$bdate'";
         }
-        if (empty($_REQUEST["e_date"])) {
+        if (empty($_REQUEST["date_end"])) {
             $edate = "null";
         } else {
-            $edate = $_REQUEST["e_date"];
+            $edate = $_REQUEST["date_end"];
             $edate = "'$edate'";
         }
-        //Demo测试数据 日期全为空 
-        //$edate = "null";
-        //$bdate = "null";
+    
+        $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
+        $sqlWhere = common::check_input($sqlWhere);
+        $sqlWhere = " " . $sqlWhere;
 
+        $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text,'$data_type'::text) "
+                            . "r (c bigint, e integer, b integer, d text)");               
+        $key = "[";
+        $value = "[";
+        $totalValue = 0;
+        foreach ($list as $vv) {
+            if ($key != "[") {
+                $key .= ",";
+                $value .= ",";
+            }
+            if ($type == "r2" || $type == "r3" || $type == "r3_1" || $type == "r4" || $type == "r4_1") {
+                $key .= '"' . $vv["d"] . '"';
+                $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["d"] . '" }';
+                $totalValue = $totalValue + $vv["c"];
+            } else {
+                if ($vv["e"] == -1) {
+                    $key .= '"Over 80 Days"';
+                    $value .= '{"value":"' . $vv["c"] . '","name":"Over 80 Days"}';
+                } else {
+                    $key .= '"' . $vv["b"] . '-' . $vv["e"] . ' Days"';
+                    $value .= '{"value":"' . $vv["c"] . '","name":"' . $vv["b"] . '-' . $vv["e"] . ' Days"}';
+                }
+                $totalValue = $totalValue + $vv["c"];
+            }
+        }
+        $key .= "]";
+        $value .= "]";
+        //处理返回原表数据格式
+        $data = common::mian_repot_do($value,$type,$totalValue);
+        common::echo_json_encode(200, $data);
+        exit();
+        break;    
+    case 'main_report_kpi':
+        $type = $_REQUEST["r_type"];
         $sqlWhere = ' and ' . common::searchExtendHandNew("ocean", $_SESSION["ONLINE_USER"]);
         $sqlWhere = common::check_input($sqlWhere);
         $sqlWhere = " " . $sqlWhere;
+        
+        $date_type = strtolower($_REQUEST["date_type"]);
+        if (isset($_POST['date_start']) && !empty($_POST['date_start']))
+            $sqlWhere .= " and $date_type >= '" . common::usDate2sqlDate($_POST['date_start']) . " 00:00:00'";
+        if (isset($_POST['date_end']) && !empty($_POST['date_end']))
+            $sqlWhere .= " and $date_type <= '" . common::usDate2sqlDate($_POST['date_end']) . " 23:59:59'";
+         
+        $transportation = strtolower($_REQUEST["transportation"]);
+        if(!is_array($transportation)){
+            $transportation = array($transportation);
+        }
+        if(count($transportation) == 1 && strtolower($transportation[0]) == 'all' ){
+
+        }else{
+            //这里不用处理,只有sea的数据
+        }
 
         $list = common::excuteListSql("select * from public.online_order_status_date_kpi_new('$type'::text,'$sqlWhere'::text) "
                         . "r (c bigint, d text)");                
@@ -165,15 +218,16 @@ switch ($action) {
         //处理返回原表数据格式
         $ETDList = array();
         $value_arr = json_decode($value,true);
+        
         foreach($value_arr as $arr){
-                $color = common::getItemStyle($type,$arr['name']);
-                if($arr['name'] == "0 Day"){
-                    $arr['name'] = "≤1 Day";
-                }
-                if($arr['name'] == "7 Days"){
-                    $arr['name'] = "≥7 Days";
-                }
-                $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
+            $color = common::getItemStyle($type,$arr['name']);
+            if($arr['name'] == "0 Day"){
+                $arr['name'] = "≤1 Day";
+            }
+            if($arr['name'] == "7 Days"){
+                $arr['name'] = "≥7 Days";
+            }
+            $ETDList[] = array("value" =>intval($arr['value']),"name" =>$arr['name'],"itemStyle" =>array("color" =>$color));
         }
         if($type == 'atd_r4'){
             $data = array("ETDList" =>$ETDList,"ETD_Radius"=>array('30%','50%'),"title1" =>"Departure","title2" =>"(ATD-ETD)","download_name" => "KPI Departure");
@@ -192,17 +246,18 @@ switch ($action) {
 
         foreach($container_type_arr as $_container_type){
             $container_type = $_container_type;
+            $date_type = strtolower($_REQUEST["date_type"]);
             $type = $_REQUEST["r_type"];
-            if (empty($_REQUEST["b_date"])) {
+            if (empty($_REQUEST["date_start"])) {
                 $bdate = "null";
             } else {
-                $bdate = $_REQUEST["b_date"];
+                $bdate = $_REQUEST["date_start"];
                 $bdate = "'$bdate'";
             }
-            if (empty($_REQUEST["e_date"])) {
+            if (empty($_REQUEST["date_end"])) {
                 $edate = "null";
             } else {
-                $edate = $_REQUEST["e_date"];
+                $edate = $_REQUEST["date_end"];
                 $edate = "'$edate'";
             }
             $list= array();
@@ -212,11 +267,11 @@ switch ($action) {
             $sqlWhere = " " . $sqlWhere;
             //如果页面查询的是ALL 这个20  40  45都查询出来。否则值查询都对应的size,其他的不查询
             if(strtolower($container_type_param) == "all"){
-                $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
+                $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$data_type'::text) "
                                 . "r (c bigint, e integer, b integer, d text)");               
             }else{
                 if($container_type_param == $_container_type){
-                    $list = common::excuteListSql("select * from public.online_order_status_date('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text) "
+                    $list = common::excuteListSql("select * from public.online_order_status_date_new_r1_r2('$type'::text, 'eta'::text, 'etd'::text, $bdate, $edate, '$sqlWhere'::text, '$container_type'::text, '$data_type'::text) "
                                 . "r (c bigint, e integer, b integer, d text)");
                 }
             }
@@ -441,7 +496,7 @@ switch ($action) {
         // $_POST['is_default'] = "no";
         // $_POST['date_start'] =null;
         // $_POST['date_end'] = null;
-        //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天 这个移除默认条件
+        //默认初始条件:ALL& ETD& Current Month 当前月的1号到最后一天 这个默认条件已经废除,前端不会这样传参数
         if (isset($_POST['is_default']) && strtolower($_POST['is_default']) == "yes" && false){
             $sqlWhere .= "and etd>='" . date("Y-m") . "-01' and etd<='" . date("Y-m") . "-01'::date + interval '1 month'";
         } else {
@@ -456,7 +511,6 @@ switch ($action) {
                 or consignee ilike '%".common::check_input($_POST['customer'])."%' or consignee_id ilike '%".common::check_input($_POST['customer'])."%')";
         }
 
-
         $rc = $_POST ['rc'];
         if ($rc == - 1) {
             $sql = "SELECT count(1) from public.online_ocean" . $sqlWhere ." and last_status_315_update_time is not null";
@@ -508,29 +562,46 @@ switch ($action) {
                     $_schemas = "ocean";
                 }
                 $timezone = "";
+                //按照最新execl Timezone From 来自于origin 
                 if($value['dd_code'] == "IFFBCF" || $value['dd_code'] == "IFFCPU"){
                     $sql = "SELECT (select time_zone from public.city_timezone where uncode = 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 time_zone from public.city_timezone where uncode = '".$value['place_of_receipt_un']."'";
-                    $timezone = common::excuteOneSql($sql);
-                    if(empty($timezone)){
-                        $sql = "select time_zone from public.city_timezone where uncode = '".$value['fport_of_loading_un']."'";
-                        $timezone = common::excuteOneSql($sql);
-                    }     
-                }
-                if($value['dd_code'] == "IFFARR"){
-                    $sql = "select time_zone from public.city_timezone where uncode = '".$value['mport_of_discharge_un']."'";
-                    $timezone = common::excuteOneSql($sql);
-                }
+                if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP" || $value['dd_code'] == "IFFARR" || $value['dd_code'] == "IFFAFD"){
+                    //Timezone From 来自于EDI315
+                    $serial_no = $value["serial_no"];
+                    $EDI315Time = common::getEDI315Time($serial_no);
 
-                if($value['dd_code'] == "IFFAFD"){
-                    $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_delivery_un']."'";
-                    $timezone = common::excuteOneSql($sql);
+                    if($value['dd_code'] == "IFFREC" || $value['dd_code'] == "IFFDEP"){
+                        //先以EDI315 时区为准,如果没有这代表数据是手动输入,或者没有同步情况
+                        $timezone = $EDI315Time[$value['dd_code']]['timezone'];
+                        if(empty($timezone)){
+                            if($value['dd_code'] == "IFFREC"){
+                                $sql = "select time_zone from public.city_timezone where uncode = '".$value['place_of_receipt_un']."'"; 
+                            }else{
+                                $sql = "select time_zone from public.city_timezone where uncode = '".$value['fport_of_loading_un']."'";
+                            }
+                            $timezone = common::excuteOneSql($sql);
+                        }     
+                    }
+                    if($value['dd_code'] == "IFFARR"){
+                        $timezone = $EDI315Time[$value['dd_code']]['timezone'];
+                        if(empty($timezone)){
+                            $sql = "select time_zone from public.city_timezone where uncode = '".$value['mport_of_discharge_un']."'";
+                            $timezone = common::excuteOneSql($sql);
+                        }
+                    }
+    
+                    if($value['dd_code'] == "IFFAFD"){
+                        $timezone = $EDI315Time[$value['dd_code']]['timezone'];
+                        if(empty($timezone)){
+                            $sql = "select time_zone from public.city_timezone where uncode = '".$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']),

+ 24 - 87
service/ocean_order.class.php

@@ -550,6 +550,20 @@ class ocean_order {
                     column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean " . $sqlWhere . 
                 " order by $order_by limit " . $ps . " offset " . ($cp - 1) * $ps.") 
             select oo.* ,aa.other_refenrence_no as \"Other refenrence No.\" from oo $ocean_ref_sql";
+
+            $tmp_search_without_limit = "with oo  as (SELECT order_from as _schemas,serial_no as __serial_no, serial_no,
+                    h_bol as _hbol, isf_bol as _isfbol, consignee_city as _consignee_city,
+                    CASE
+	    	            WHEN (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'
+		            END AS new_status, ".
+                    column::getInstance()->getSearchSqlForDisplay('Ocean_Search') . " from public.online_ocean " . $sqlWhere . 
+                " order by $order_by) 
+            select oo.* ,aa.other_refenrence_no as \"Other refenrence No.\" from oo $ocean_ref_sql";
             
             $rs = common::excuteListSql($sql);
             error_log("online_ocean_search_SQL: ".$sql);
@@ -574,7 +588,7 @@ class ocean_order {
                'ps' => $ps,
                'cp' => $cp,
                'tp' => $tp,
-               'tmp_search' => common::deCode($sql, 'E'),
+               'tmp_search' => common::deCode($tmp_search_without_limit, 'E'),
                'type' => common::check_input($_POST ['_ntype']));
         } else {
             $arrTmp = array('searchData' => array(), 
@@ -588,7 +602,7 @@ class ocean_order {
                 'ps' => $ps,
                 'cp' => $cp,
                 'tp' => $tp,
-                'tmp_search' => common::deCode($sql, 'E'),
+                'tmp_search' => "",
                 'type' => common::check_input($_POST ['_ntype']));
         }
         common::echo_json_encode(200,$arrTmp);
@@ -823,7 +837,7 @@ class ocean_order {
 
     private function _ocean_excel() {
         $sql = common::deCode($_POST ['tmp_search'], 'D');
-        $sql = substr($sql, 0, strripos($sql, " limit"));
+        //$sql = substr($sql, 0, strripos($sql, " limit"));
         if(!empty($sql)){
             $rs = common::excuteListSql($sql);
         }
@@ -1176,90 +1190,13 @@ class ocean_order {
         $data = array();
 
         /* 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); 
-        $containerStatusData = array();
-        $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,
-                    (select time_zone from public.city_timezone where uncode = 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);       
-
-            //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
-            $container_status_column = array("EE","I","AE","VD","VA");
-            $containerStatusDataTemp = array();
-            $content = array();
-            //按顺序处理 新版只显示几个状态
-            foreach($container_status_column as $status){
-                foreach($ctnr_status as $event){
-                    if(strtolower($event['event']) == strtolower($status)){
-                        $eventdate = $event["eventdate"];
-                        if (empty($event["source_id"]) || $event["source_id"]==0) {
-                            $eventdate.= " " . $event["eventtime"];
-                        }
-                        $location_code = $event["eventcode"];
-                        $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;
-                        }
-                    }
-                }
-            }
-            //记录所有的信息
-            $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']);
-            }
-
-            $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
-            $containerStatusDataTemp['content'] = $content;
-            $containerStatusData[] = $containerStatusDataTemp;
-        }
-        $data['containerStatusData'] = $containerStatusData;
-        $data['EDI315TimeAndLocation'] = $EDI315TimeAndLocation;
+        //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
+        //记录所有的信息 EDI315TimeAndLocation
+        $EDIDate = common::getEDI315StatusForDetail($ocean["serial_no"]);
+        $data['containerStatusData'] = $EDIDate['containerStatusData'];
+        $data['EDI315TimeAndLocation'] = $EDIDate['EDI315TimeAndLocation'];
+        $VD = $EDIDate['VD'];
+        $VA = $EDIDate['VA'];
 
         //处理shipment data
         $ocean_milestone_status = common::excuteListSql("select code,

+ 215 - 47
utils/common.class.php

@@ -1121,6 +1121,42 @@ class common {
             if(!empty($dashboard_filter['date_start'])){
                 $dashboard_filter['date_start'] = common::usDate2sqlDate($dashboard_filter['date_start']);
             }
+        }else{
+            $threeMonthsAgoTimestamp = strtotime('-3 months');
+            $date_start = date('Y-m-01', $threeMonthsAgoTimestamp);
+            $date_end = date('Y-m-t');
+            $date_start_two = date('m/01/Y', $threeMonthsAgoTimestamp);
+            $date_end_two = date('m/t/Y');
+
+            $date_start_ym = date('Y-m', $threeMonthsAgoTimestamp);
+            $date_end_ym = date('Y-m');
+            $date_start_two_ym = date('m/01/Y', $threeMonthsAgoTimestamp);
+            $date_end_two_ym = date('m/t/Y');
+
+            //柜子
+            $MonthsAgoTimestamp = strtotime('-12 months');
+            $date_start_ctnr = date('Y-m', $MonthsAgoTimestamp);
+            $date_end_ctnr = date('Y-m');
+            $date_start_two_ctnr = date('m/Y', $MonthsAgoTimestamp);
+            $date_end_two_ctnr = date('m/Y');
+
+            //KPIDefaulteData
+            $dashboard_filter['KPIDefaulteData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start,"date_start_two"=>$date_start_two,
+            "date_end"=>$date_end,"date_end_two"=>$date_end_two);
+            //PendingDefaultData
+            $dashboard_filter['PendingDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>"","date_start_two"=>"",
+                "date_end"=>"","date_end_two"=>"");
+            //RecentDefaultData
+            $dashboard_filter['RecentDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETD","date_start"=>$date_start,"date_start_two"=>$date_start_two,
+                "date_end"=>$date_end,"date_end_two"=>$date_end_two);
+            
+            //ETDDefaultData
+            $dashboard_filter['ETDDefaultData'] = array("transportation" =>array('All'),"date_type"=>"ETA","date_start"=>$date_start_ym,"date_start_two"=>$date_start_two_ym,
+            "date_end"=>$date_end_ym,"date_end_two"=>$date_end_two_ym);
+
+            //ContainerefaultData
+            $dashboard_filter['ContainerefaultData'] = array("transportation" =>array('Sea'),"date_type"=>"ETA","date_start"=>$date_start_two_ctnr,"date_start_two"=>$date_start_ctnr,
+             "date_end"=>$date_end_two_ctnr,"date_end_two"=>$date_end_ctnr);
         }
         return  array("Management" => $Management,"dashboard_filter" =>$dashboard_filter);
     }
@@ -1609,21 +1645,31 @@ class common {
             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 = "";
             $timezone = "";
             if(!empty($EDI315TimeAndLocation[$mda['code']])){
                 $edi315Info = $EDI315TimeAndLocation[$mda['code']];
                 if(!empty($edi315Info)){
-                    $locations = $edi315Info['location'];
                     $timezone = $edi315Info['timezone'];
                 }
+                //IFFICC 比较特殊用EDI的locations
+                if($mda['code'] == "IFFICC"){
+                    $IFFICC_locations = $edi315Info['location'];
+                }
             }else{
                 $edi315Info =  $Milestones_NO_Mapping[$mda['code']];
                 if(!empty($edi315Info)){
-                    $locations = $edi315Info['location'];
                     $timezone = $edi315Info['timezone'];
                 }
             }
+            //locations 以配置的信息为准
+            $locations = "";
+            $edi315Info =  $Milestones_NO_Mapping[$mda['code']];
+            if(!empty($edi315Info)){
+                $locations = $edi315Info['location'];
+                if($mda['code'] == "IFFICC" && !empty($IFFICC_locations)){
+                    $locations = $IFFICC_locations;
+                }
+            }
             $Milestones_data[] = array("milestones"=>$mda['description'],"date_time"=>$mda['date_time'],"timezone" =>$timezone,
                 "locations" => $locations, "remarks" =>$mda['remark']);
         }  
@@ -1650,62 +1696,184 @@ class common {
      */
     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']);
+        //取origin  $ocean['aa_city'] 不是必需,对应文件里未提location来源
+        $Milestones_NO_Mapping['IFFBCF'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
+        $Milestones_NO_Mapping['IFFBCR'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
+        $Milestones_NO_Mapping['IFFCPU'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
+        $Milestones_NO_Mapping['IFFSIL'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
+        $Milestones_NO_Mapping['IFFEDO'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
+        $Milestones_NO_Mapping['IFFECC'] = array("code"=>"origin","timezone"=>$ocean['aa_timezone'],"location"=>"");
+
+        //Place of Receipt
+        $Milestones_NO_Mapping['IFFREC'] = 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']);
+      
+        //Port of loading
+        $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']);
+        
+        //取destination $ocean['dd_city']不是必需
+        $Milestones_NO_Mapping['IFFCSN'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
+        $Milestones_NO_Mapping['IFFIDO'] = array("code"=>"destination","timezone"=>$ocean['dd_timezone'],"location"=>"");
 
         //取Port of discharge
         $Milestones_NO_Mapping['IFFARR'] = array("code"=>"mpod","timezone"=>$ocean['mpod_timezone'],"location"=>$ocean['mpod_uncity']);
+        $Milestones_NO_Mapping['IFFUND'] = array("code"=>"mpod/pod/fd","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['IFFCTA'] = array("code"=>"pod/mpod","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']);
-        }
+        $Milestones_NO_Mapping['IFFPPD'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_uncity']);
+        $Milestones_NO_Mapping['IFFECR'] = array("code"=>"mpod/pod/fd","timezone"=>$ocean['pod_timezone'],"location"=>$ocean['pod_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']);
+        //final_destination $ocean['fd_city']不是必需
+        $Milestones_NO_Mapping['IFFDEL'] = array("code"=>"fd","timezone"=>$ocean['fd_timezone'],"location"=>"");
+        $Milestones_NO_Mapping['IFFHBL'] = array("code"=>"fd","timezone"=>$ocean['fd_timezone'],"location"=>"");
 
         return $Milestones_NO_Mapping;
     }
+
+    public static function getEDI315StatusForDetail($serial_no){
+        $data = array();
+        $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); 
+        $containerStatusData = array();
+        $VD = "";
+        $VA = "";    
+        foreach ($ctnr_data as $cd){
+            //存在柜号为空的数据情况
+            if(empty($cd['ctnr'])){
+                continue;
+            }
+            //(select uncity from public.ports where uncode = s.event_code) as uncity, 按新版的逻辑这个先取消掉
+            $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 time_zone from public.city_timezone where uncode = s.event_code) as timezone,
+                    '' as uncity,
+                    case when event ='I' or event ='TR'  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 ='RD'  then 'IFFECR'::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);       
+
+            //Container_Status 新版只显示几个状态, CTNR# EE I AE VD VA
+            $container_status_column = array("EE","I","AE","VD","VA");
+            $containerStatusDataTemp = array();
+            $content = array();
+            //按顺序处理 新版只显示几个状态
+            foreach($container_status_column as $status){
+                foreach($ctnr_status as $event){
+                    if(strtolower($event['event']) == strtolower($status)){
+                        $eventdate = $event["eventdate"];
+                        if (empty($event["source_id"]) || $event["source_id"]==0) {
+                            $eventdate.= " " . $event["eventtime"];
+                        }
+                        $location_code = $event["eventcode"];
+                        $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;
+                        }
+                    }
+                }
+            }
+            //记录所有的信息
+            $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']);
+            }
+
+            $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
+            $containerStatusDataTemp['content'] = $content;
+            $containerStatusData[] = $containerStatusDataTemp;
+        }
+        $data['containerStatusData'] = $containerStatusData;
+        $data['EDI315TimeAndLocation'] = $EDI315TimeAndLocation;
+        $data['VD'] = $VD;
+        $data['VA'] = $VA;
+    }
+
+    public static function getEDI315Time($serial_no){
+        //Timezone From 来自于EDI315
+        $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); 
+        $EDI315TimeAndLocation = array();
+        foreach ($ctnr_data as $cd){
+            //存在柜号为空的数据情况
+            if(empty($cd['ctnr'])){
+                continue;
+            }
+            $ctnr_status_sql = "select 
+                    (select time_zone from public.city_timezone where uncode = s.event_code) as timezone,
+                    case when event ='I' or event ='TR' 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 ='RD'  then 'IFFECR'::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']);
+            }
+        }
+        return $EDI315TimeAndLocation;
+    }
 }
 ?>