ShuanghongS hai 3 meses
pai
achega
adf3523922

+ 1 - 1
main_new_version.php

@@ -25,7 +25,7 @@ include 'service/destination_delivery.class.php';
 //为了调用,临时做一个登录动作  如果是正式版 要注释掉菜单System Settings
  //$_POST['uname'] = "ra.admin";
  //$_POST['psw'] = common::excuteOneSql("select ra_password from public.ra_online_user where user_login = 'ra.admin'");
-//  $name =strpos(common::ip(), "192.168.0.158") !== false || strpos(common::ip(), "192.168.0.161") !== false ? "dddde" : 'ra.admin';
+//  $name =strpos(common::ip(), "192.168.0.158s") !== false || strpos(common::ip(), "192.168.0.161s") !== false ? "dddde" : 'ra.admin';
 //  $_POST['uname'] = $name;
 //  $_POST['psw'] = common::excuteOneSql("select ra_password from public.ra_online_user where user_login = '".$name."'");
 //  login::getInstance()->do_login_auto();

+ 37 - 21
service/destination_delivery.class.php

@@ -150,11 +150,11 @@ class destination_delivery {
         if ($operate == "manage_address"){
             $consignee = $_REQUEST['consignee_id'];
 
-            $consignee =array('COMGEN38002','FGB050132','ATOZTI35005','WILSON80001');
+            //$consignee =array('COMGEN38002','FGB050132','ATOZTI35005','WILSON80001');
             $more_param = common::getInNotInSqlForSearch(utils::implode(';',$consignee));
 
             $country = $_REQUEST['country'];
-            $country =array('GB','DE','US');
+            //$country =array('GB','DE','US');
             $more_param_country = common::getInNotInSqlForSearch(utils::implode(';',$country));
 
             $delivery_serial_no = common::deCode($_REQUEST['delivery_serial_no'], 'D');
@@ -593,10 +593,10 @@ class destination_delivery {
 
             $sqlWhere = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
             //兜底规则
-            //$sqlWhere .= " and eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
+            $sqlWhere .= " and eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
             //代表employee 
             if(_isApexLogin()){
-                //$sqlWhere .= " and kln_pic = '"._getLoginEamil()."'";
+                $sqlWhere .= " and kln_pic = '"._getLoginEamil()."'";
             }    
 
             //条件带入
@@ -669,7 +669,7 @@ class destination_delivery {
                         sum(case when status ='Cancel' then 1 else 0 end) as cancelled_rc
                     from public.kln_destination_delivery 
                         where exists(select 1 from public.kln_ocean oo ". $sqlWhere_befrom_filterTag."  and oo.serial_no = any(h_serial_no))";
-                 error_log("kln_destination_delivery_count:".$sql);        
+                error_log("kln_destination_delivery_count:".$sql);        
                 $statusRc = common::excuteObjectSql($sql);
                 $rc = $statusRc['rc'];
                 $search_rc = $statusRc['seach_rc'];
@@ -808,7 +808,6 @@ class destination_delivery {
             }
         
             $delivery_address = common::check_input($_POST['delivery_address']);
-            $delivery_address_detail = common::check_input(json_encode(common::returnDAddress(),JSON_UNESCAPED_UNICODE));
             $special_requirements = common::check_input($_POST['special_requirements']);
 
             //检查不能重复添加booking  这里空运没问题,但是会遇到相同hbol 不同的柜子情况,本质上来说就是一条
@@ -841,6 +840,7 @@ class destination_delivery {
                     $updateSqlSet.= ", status = '$status' ";
                 }
                 if (!empty($delivery_address)) {
+                    $delivery_address_detail = common::check_input(json_encode(common::returnDAddress(),JSON_UNESCAPED_UNICODE));
                     $updateSqlSet.= ", delivery_address = '$delivery_address' ";
                     $updateSqlSet.= ", delivery_address_detail = '$delivery_address_detail' ";
                 }
@@ -894,8 +894,9 @@ class destination_delivery {
 
                     $delivery_date = empty($_POST['delivery_date']) ? "null": "'".common::usDate2sqlDate($_POST['delivery_date'])." ".$delivery_time."'";
 
-                    //修改记录临时表
-                    common::saveDAddressTempTable($serial_no,$sData['consignee_id']);
+                    //修改记录临时表,有值代表选择的add
+                    $_sync_key_add = common::saveDAddressTempTable($serial_no,$sData['consignee_id']);
+                    $delivery_address_detail = common::check_input(json_encode(common::returnDAddress($_sync_key_add),JSON_UNESCAPED_UNICODE));
 
                     $sql .= "INSERT INTO public.kln_destination_delivery(
                             serial_no, h_serial_no,address_country,
@@ -958,7 +959,7 @@ class destination_delivery {
         }
 
         /**
-         * 审核 approved  or rejected  cancelled
+         * 审核 Approve  or Reject  Cancel  Pending Approval
         */
         if ($operate == "review"){
             $serial_no = common::deCode($_POST['serial_no'], 'D');
@@ -976,6 +977,10 @@ class destination_delivery {
                 $sql .= "delete from public.contacts_address_online where delivery_serial_no = '$serial_no';";
                 $sql .=common::returnDAddressRecord($address_country,$onine_address);
             }
+            if ($status == "Reject" || $status == "Cancel") {
+                //这种情况,清除当前用户对这一票的修改和添加的信息
+                $sql .= "delete from public.contacts_address_online where delivery_serial_no = '$serial_no';";
+            }
 
             $sql .= "update public.kln_destination_delivery set status = '$status', modify_by = '"._getLoginName()."',update_time = now() where serial_no = '$serial_no';";
             $sql .="INSERT INTO public.kln_destination_delivery_operation_log(
@@ -1050,9 +1055,14 @@ class destination_delivery {
                     $cc_email = $communication_cc;
                 }
                 $user_from = _getLoginName();
+
+                $h_bol_str = array();
+                foreach($_POST["h_bol"] as $obj){
+                    $h_bol_str[] = $obj['key'];
+                }
                 
                 //邮件发送
-                $title = "Destination Delivery from " . _getLoginName() . ", Shipment No: " . $_POST["h_bol"];
+                $title = "Destination Delivery from " . _getLoginName() . ", Shipment No: " . utils::implode(',',$h_bol_str);
                 $emailContent = $content;
 
                 common::excuteUpdateSql("insert into public.email_record (type,title,from_email,to_email,cc_email,content,insert_date)values('Delivery_Comm','$title','$from_email','$to_email','$cc_email','$emailContent',now());");
@@ -1156,7 +1166,7 @@ class destination_delivery {
         //根據用戶的賬號權限所能看到的全部shipment數據的目的地站點,去匹配是否有開通destination delivery的服務,如果未開通,則展示此提示頁面
         //兜底规则
         $sqlWhere = $sqlWhere_common;
-        //$sqlWhere .= " and  eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
+        $sqlWhere .= " and  eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
         // $checkOpenSql = "with oo as ( select DISTINCT agent from public.kln_ocean oo ". $sqlWhere.")
         //         select agent from  oo 
         //             where exists(select 1 from public.kln_destination_delivery_config where oo.agent in (select regexp_split_to_table(station, E','))) 
@@ -1173,7 +1183,7 @@ class destination_delivery {
         
         //根據用戶的賬號權限所能看到的全部shipment數據的目的地站點,去匹配是否有開通destination delivery的服務,如果有開通,但沒有符合條件的shipment,則展示此提示頁面
         $sqlWhere = $sqlWhere_common;
-        //$sqlWhere .= " and  eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
+        $sqlWhere .= " and  eta >= now() - INTERVAL '6 months' and eta <= now() + INTERVAL '6 months'";
 
         $text_search = $_REQUEST['text_search'];
         if (!empty($text_search)){
@@ -1219,12 +1229,12 @@ class destination_delivery {
                 from public.kln_destination_delivery_config dc
                     Inner Join oo
                         on oo.agent in (select regexp_split_to_table(dc.station, ','))
-                    where  1=1 --and 
-                        --case when dc.booking_window = 'Restrictions_ETD_ATD' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
-                        --        then COALESCE(atd, etd) >= (NOW() - (dc.booking_window_date_start ||' days')::INTERVAL)::date and  COALESCE(atd, etd) <= (NOW() + (dc.booking_window_date_end ||' days')::INTERVAL)::date
-                        --    when dc.booking_window = 'Restrictions_ETA_ATA' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
-                        --        then COALESCE(ata, eta) >= (NOW() - (dc.booking_window_date_start ||' days')::INTERVAL)::date and  COALESCE(ata, eta) <= (NOW() + (dc.booking_window_date_end ||' days')::INTERVAL)::date
-                        --else 1=1 end 
+                    where  1=1 and 
+                        case when dc.booking_window = 'Restrictions_ETD_ATD' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
+                                then COALESCE(atd, etd) >= (NOW() - (dc.booking_window_date_start ||' days')::INTERVAL)::date and  COALESCE(atd, etd) <= (NOW() + (dc.booking_window_date_end ||' days')::INTERVAL)::date
+                            when dc.booking_window = 'Restrictions_ETA_ATA' and COALESCE(dc.booking_window_date_start,'')<>'' and 	COALESCE(dc.booking_window_date_end,'')<>''
+                                then COALESCE(ata, eta) >= (NOW() - (dc.booking_window_date_start ||' days')::INTERVAL)::date and  COALESCE(ata, eta) <= (NOW() + (dc.booking_window_date_end ||' days')::INTERVAL)::date
+                        else 1=1 end 
             ),
             matched_data as (
                 select
@@ -1379,7 +1389,7 @@ class destination_delivery {
                     ORDER BY priority asc
                     LIMIT 1
                 ) r ON true
-            order by md.eta desc  limit 100";
+            order by md.eta desc";
          
         $rs = common::excuteListSql($sql);
         error_log($sql);
@@ -1393,6 +1403,12 @@ class destination_delivery {
      * 不依赖配置的规则查询,如果规则已经移除或者修改不在查询范围内,開通期間創建的booking數據正常保留和展示
     */
     function search_shipment_with_booking($serial_no,$h_serial_no,$ctnr){
+
+        $sqlCtnr = "";
+        if(!empty($ctnr)){
+            $sqlCtnr = "and oc.ctnr in (select regexp_split_to_table('".$ctnr."', ','))";
+        }
+
         $sqlWhere =  "where oo.serial_no = ANY('".$h_serial_no."'::TEXT[])";
         $sql = "with ooc as(
                 select * from public.kln_ocean oo ". $sqlWhere ."
@@ -1428,7 +1444,7 @@ class destination_delivery {
                     ooc.order_from
                 from ooc  
                     LEFT JOIN public.oc_container oc ON oc.serial_no::text = ooc.serial_no::text  
-                where  ooc.order_from = 'public' and transport_mode = 'sea' and oc.ctnr in (select regexp_split_to_table('".$ctnr."', ','))
+                where  ooc.order_from = 'public' and transport_mode = 'sea' ".$sqlCtnr."
                 union all
                 select 
                     ooc.serial_no,
@@ -1460,7 +1476,7 @@ class destination_delivery {
                     ooc.order_from
                 from ooc  
                     LEFT JOIN sfs.oc_container oc ON oc.serial_no::text = ooc.serial_no::text  
-                where  ooc.order_from = 'sfs' and transport_mode = 'sea' and oc.ctnr in (select regexp_split_to_table('".$ctnr."', ','))
+                where  ooc.order_from = 'sfs' and transport_mode = 'sea' ".$sqlCtnr."
                 union all
                 select 
                     ooc.serial_no,

+ 8 - 0
service/ocean_order.class.php

@@ -1210,6 +1210,14 @@ class ocean_order {
             if(!empty($rss[$key]['grs_lbs'])){
                 $rss[$key]['grs_lbs'] = $rs['grs_lbs']."LBS";
             }
+
+            //为每个柜子下面单独加状态信息 ctnr_label  content
+            $rss[$key]['containerStatusData'] = array();
+            foreach($containerStatusData as $_containerStatusData){
+                if(trim($_containerStatusData["ctnr_label"]) == trim($rs["ctnr"])){
+                    $rss[$key]['containerStatusData'] = $_containerStatusData["content"];
+                }
+            }
         }
         $quantity_tolal = "";
         foreach($quantity_unit as $uk => $uv){

+ 48 - 26
utils/common.class.php

@@ -2048,7 +2048,8 @@ class common {
                             $eventdate.= " " . $event["eventtime"];
                         }
                         $location_code = $event["eventcode"];
-                        $content[] = array("code" =>$event['event'],"title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code,"timezone"=>$event['timezone']);
+                        $content[] = array("code" =>$event['event'],"title" =>$event['description'],"date"=>$eventdate,"country"=>$location_code,"timezone"=>$event['timezone'],
+                            "uncity"=>$event['uncity']);
                         if(strtolower($event['event']) == "vd" && !empty($eventdate)){
                             $VD = $eventdate;
                         }
@@ -2079,6 +2080,7 @@ class common {
             }
 
             $containerStatusDataTemp['label'] = $cd['ctnr']." / ".$cd['size'];
+            $containerStatusDataTemp['ctnr_label'] = $cd['ctnr'];
             $containerStatusDataTemp['content'] = $content;
             $containerStatusData[] = $containerStatusDataTemp;
         }
@@ -3461,7 +3463,7 @@ class common {
         $kln_pic_email = $data['kln_pic'];
         //这票的创建者email
         $customer_email = common::excuteOneSql("select email from public.ra_online_user where user_login = '".$data['create_by']."'");
-        if ($status == "Rejected" || $status == "Cancelled") {
+        if ($status == "Reject" || $status == "Cancel") {
             $log = common::excuteObjectSql("select *,
                     TO_CHAR(created_time, 'Mon-DD-YYYY') as _created_time
                 from public.kln_destination_delivery_operation_log 
@@ -3477,12 +3479,13 @@ class common {
         }
 
         //邮件模板填充字段准备
+        $address = json_decode($data["delivery_address_detail"],true);
         $tplData = array("customer_email"=>$customer_email,
             "customer_name"=>$data['create_by'],
             "delivery_mode"=>$data['delivery_mode'],
             "delivery_date"=>$data['_delivery_date'],
-            "location_name"=>"",
-            "address_1"=>"",
+            "location_name"=>empty($address['contact_person']) ? "" : $address['contact_person'].":".$address['contact_number'],
+            "address_1"=>$address['address_1'],
             "contact"=>"",
             "kln_pic_email"=>$kln_pic_email,
             "booking_no" =>$data['booking_no'],
@@ -3753,7 +3756,7 @@ class common {
         }
 
         //固定
-        $legal = true;
+        //$legal = true;
         if(!$legal){
             $data = array("msg" =>"Illegal access");
             common::echo_json_encode(200,$data); 
@@ -3764,6 +3767,7 @@ class common {
     public static function saveDAddressTempTable($delivery_serial_no,$consignee_id){
         //deliver address is new
         $addressSql = "";
+        $_sync_key_add = "";
         $address_1 = $_POST['address_1'];
         foreach($address_1 as $key => $_address_1){
             $_address_1 = common::check_input($_address_1); 
@@ -3780,6 +3784,7 @@ class common {
             $_sync_key = common::check_input($_POST['sync_key'][$key]);
             $_from_station = common::check_input($_POST['from_station'][$key]);
             $_contact_type = common::check_input($_POST['contact_type'][$key]);
+            $_create_user = common::check_input($_POST['create_user'][$key]);
 
             $uniqueAC =array();
             if ($_contact_type ==  "Add"){
@@ -3801,10 +3806,14 @@ class common {
                             '$_country','$_city','$_postal_code',
                             '$_add_create_user',now(),'$_add_create_user',now(),
                             true,'$_sync_key','$_from_station','$_contact_person','$_contact_number');";
+                    $_sync_key_add = $_sync_key;        
                 }
             } else {
                 if(!empty($_sync_key)){
                     $_add_create_user = "Online_D_Address";
+                    if($_contact_type == "Unedit"){
+                        $_add_create_user = $_create_user;
+                    }
                     $exist = common::excuteObjectSql("select sync_key,action from public.contacts_address_online where sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no'");
                     if(empty($exist)){
                         $addressSql .= "INSERT INTO public.contacts_address_online(
@@ -3822,28 +3831,38 @@ class common {
                         if ($_contact_type ==  "Delete" && $exist['action'] == "Add"){
                             //代表未审核新加的,这次提交为删除
                             $addressSql .= "delete from public.contacts_address_online where sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no';";
-                        } elseif ($_contact_type ==  "Delete" && ($exist['action'] == "Modify" || $exist['action'] == "Unedit")){
-                            //代表未审核编辑的,这次提交为删除,修改action固定为Detele
-                            $addressSql .="UPDATE public.contacts_address_online
-                                    SET addr1='$_address_1', addr2='$_address_2', addr3='$_address_3', addr4='$_address_4',
-                                        ctry_code='$_country', city_code='$_city', postal_code='$_postal_code', 
-                                        modify_user='$_add_create_user', modify_date=now(),
-                                        contact_person='$_contact_person', contact_number='$_contact_number',
-                                        action='Delete'
-                                    WHERE sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no';"; 
-                        } else {
+                        } 
+                        // elseif ($_contact_type ==  "Delete" && ($exist['action'] == "Modify" || $exist['action'] == "Unedit")){
+                        //     //代表未审核编辑的,这次提交为删除,修改action固定为Detele
+                        //     $addressSql .="UPDATE public.contacts_address_online
+                        //             SET addr1='$_address_1', addr2='$_address_2', addr3='$_address_3', addr4='$_address_4',
+                        //                 ctry_code='$_country', city_code='$_city', postal_code='$_postal_code', 
+                        //                 modify_user='$_add_create_user', modify_date=now(),
+                        //                 contact_person='$_contact_person', contact_number='$_contact_number',
+                        //                 action='Delete'
+                        //             WHERE sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no';"; 
+                        // } 
+                        else {
+                            //Modify  Unedit :如果是用户完全新加的,这里不做action的修改,保留记录的Add
+                            $temp_action = $_contact_type;
+                            if ($exist['action'] == "Add"){
+                                $temp_action = "Add";
+                            }
                             $addressSql .="UPDATE public.contacts_address_online
                                 SET addr1='$_address_1', addr2='$_address_2', addr3='$_address_3', addr4='$_address_4',
                                     ctry_code='$_country', city_code='$_city', postal_code='$_postal_code', 
                                     modify_user='$_add_create_user', modify_date=now(),
-                                    contact_person='$_contact_person', contact_number='$_contact_number'
+                                    contact_person='$_contact_person', contact_number='$_contact_number',
+                                    action='$temp_action'
                                 WHERE sync_key = '$_sync_key' and delivery_serial_no = '$delivery_serial_no';";
+                            
                         }
                     }
                 }
             }
         }
         common::excuteUpdateSql($addressSql);
+        return $_sync_key_add;
     }
 
     public static function returnDAddressRecord($address_country,$onine_address){
@@ -3868,12 +3887,12 @@ class common {
             $_contact_type = common::check_input($_onine_address['action']);
 
             //适应前端逻辑,如果遇到Unedit 代表该地址未变动,移除变动记录里
-            if ( $_contact_type == "Unedit"){
+            if ($_contact_type == "Unedit"){
                 continue;
             }
 
             foreach($address_country as $ck => $_country){
-                //如果需要新加的时候 用户固定名称,用作标记
+                //如果需要新加的时候 用户固定名称,用作标记   //contact_person,contact_number  '$_contact_person','$_contact_number'
                 $_add_create_user = "Online_D_Address";
                 if ($_contact_type == "Add"){
                     $sync_key = common::uuid();
@@ -3882,14 +3901,14 @@ class common {
                             addr_type,contact_id, addr1, addr2,addr3, addr4, 
                             ctry_code, city_code, postal_code,  
                             create_user, create_date, modify_user, modify_date,
-                            is_sync_country, sync_key, from_station,contact_person,contact_number)
+                            is_sync_country, sync_key, from_station)
                     VALUES ('D','$_contact_id','$_address_1','$_address_2','$_address_3','$_address_4',
                             '$_country','$_city','$_postal_code',
                             '$_add_create_user',now(),'$_add_create_user',now(),
-                            true,'$sync_key','$from_station','$_contact_person','$_contact_number');";
+                            true,'$sync_key','$from_station');";
                 }
                 if ($_contact_type == "Modify"){
-                    //代表在一个国家内的编辑
+                    //代表在一个国家内的编辑 //contact_person='$_contact_person', contact_number='$_contact_number'  
                     $from_station_country = "";
                     if (strpos($_from_station, "Online_") === 0) { // 确保字符串以 Online_ 开头
                         $from_station_country = substr($_from_station, strlen("Online_"));
@@ -3898,8 +3917,7 @@ class common {
                         $addressSql .= "UPDATE public.contacts_address
                             SET addr1='$_address_1', addr2='$_address_2', 
                                 ctry_code='$_country', city_code='$_city', postal_code='$_postal_code',  
-                                modify_user='"._getLoginName()."', modify_date=now(),
-                                contact_person='$_contact_person', contact_number='$_contact_number'  
+                                modify_user='"._getLoginName()."', modify_date=now()
                             WHERE sync_key = '$_sync_key';";
                     } else {
                         $sync_key = common::uuid();
@@ -3908,11 +3926,11 @@ class common {
                                 addr_type,contact_id, addr1, addr2,addr3, addr4, 
                                 ctry_code, city_code, postal_code,  
                                 create_user, create_date, modify_user, modify_date,
-                                is_sync_country, sync_key, from_station,contact_person,contact_number)
+                                is_sync_country, sync_key, from_station)
                         VALUES ('D','$_contact_id','$_address_1','$_address_2','$_address_3','$_address_4',
                                 '$_country','$_city','$_postal_code',
                                 '$_add_create_user',now(),'$_add_create_user',now(),
-                                true,'$sync_key','$from_station','$_contact_person','$_contact_number');";
+                                true,'$sync_key','$from_station');";
                     }
                 }
                 if ($_contact_type == "Delete"){
@@ -3930,7 +3948,7 @@ class common {
     }
 
 
-    public static function returnDAddress(){
+    public static function returnDAddress($_sync_key_add=""){
         //deliver address is new
         $$delivery_address = "";
         $address_1 = $_POST['address_1'];
@@ -3950,6 +3968,10 @@ class common {
             $_from_station = $_POST['from_station'][$key];
             $_contact_type = $_POST['contact_type'][$key];
 
+            if($_contact_type == "Add"){
+                //add 这么生成的唯一key
+                $_sync_key = $_sync_key_add;
+            }
 
             if ($_contact_type <> "Delete"){
                 $delivery_address = array("address_1"=>$_address_1,