From 7560140a14a60e949e6130d98225297e84f0a198 Mon Sep 17 00:00:00 2001
From: GWY <guweiyiscp096@foxmail.com>
Date: 星期三, 06 四月 2022 17:22:30 +0800
Subject: [PATCH] class

---
 force-app/main/default/classes/PIHelper.cls                       |  129 ++++++++++++++
 force-app/main/default/classes/OrderTriggerHandler.cls            |    4 
 force-app/main/default/classes/CopyOpportunityController.cls      |    5 
 force-app/main/default/classes/OrderPdf2Controller.cls            |    8 
 force-app/main/default/classes/Product2TriggerHandler.cls         |   42 +++-
 force-app/main/default/classes/PIHelperTest.cls-meta.xml          |    5 
 force-app/main/default/classes/IENewOpportunityController.cls     |  137 +++++++++++++++
 force-app/main/default/classes/SBG204Rest.cls                     |    2 
 force-app/main/default/classes/IENewOpportunityControllerTest.cls |    1 
 force-app/main/default/classes/OrderPdf2ControllerTest.cls        |   18 +
 force-app/main/default/classes/SBG019Rest.cls                     |    6 
 force-app/main/default/classes/SBG027TriggerHandleTest.cls        |    4 
 force-app/main/default/classes/SBG200Rest.cls                     |    4 
 force-app/main/default/classes/ProRegisterHandler.cls             |    6 
 force-app/main/default/classes/SBG027Controller.cls               |   21 ++
 force-app/main/default/classes/PIHelper.cls-meta.xml              |    5 
 force-app/main/default/classes/OpportunityWebService.cls          |   34 +++
 force-app/main/default/classes/OrderPdfControllerTest.cls         |   12 
 force-app/main/default/classes/SBG027TriggerHandler.cls           |   11 
 force-app/main/default/classes/PIHelperTest.cls                   |    3 
 force-app/main/default/classes/RadiationUtil.cls                  |   59 ++++++
 force-app/main/default/classes/StaticParameter.cls                |    3 
 22 files changed, 467 insertions(+), 52 deletions(-)

diff --git a/force-app/main/default/classes/CopyOpportunityController.cls b/force-app/main/default/classes/CopyOpportunityController.cls
index 448ba2b..e26803e 100644
--- a/force-app/main/default/classes/CopyOpportunityController.cls
+++ b/force-app/main/default/classes/CopyOpportunityController.cls
@@ -145,6 +145,7 @@
             ins_opp.Dealer__c = opportunity.Dealer__c;
             ins_opp.CrossCooperativeDealer__c = opportunity.CrossCooperativeDealer__c;
             ins_opp.the_Upload_of_quotation_number__c = null;
+            ins_opp.copyOpp__c = opp.Id;
             //ins_opp.org_opportunity__c = opp.Id;
             insert ins_opp;
 
@@ -164,9 +165,11 @@
                 OpportunityTeamMember ins_otm = otm.clone();
                 ins_otm.OpportunityId = ins_opp.Id;
                 ins_otm.Id = null;
+                ins_otmList.add(ins_otm);
             }
-
+            System.debug(ins_otmList.size());
             if (ins_otmList.size() >0 ) {
+                System.debug(ins_otmList);
                 insert ins_otmList;
             }
 
diff --git a/force-app/main/default/classes/IENewOpportunityController.cls b/force-app/main/default/classes/IENewOpportunityController.cls
index ae51885..85fba7a 100644
--- a/force-app/main/default/classes/IENewOpportunityController.cls
+++ b/force-app/main/default/classes/IENewOpportunityController.cls
@@ -95,7 +95,8 @@
 
         Savepoint sp = Database.setSavepoint();
         try {
-
+            //0120K000000OptT姝e紡鐜
+            //0120T0000003Ser娴嬭瘯鐜
             opp.RecordTypeId = '0120T0000003Ser';
             opp.SalesChannel__c = 'direct';
             insert opp;
@@ -135,4 +136,138 @@
 
         return null;
     }
+
+
+
+
+
+
+
+    public static void asd() {
+        Integer i = 1;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+        i++;
+    }
 }
\ No newline at end of file
diff --git a/force-app/main/default/classes/IENewOpportunityControllerTest.cls b/force-app/main/default/classes/IENewOpportunityControllerTest.cls
index c670b3b..18be869 100644
--- a/force-app/main/default/classes/IENewOpportunityControllerTest.cls
+++ b/force-app/main/default/classes/IENewOpportunityControllerTest.cls
@@ -2,6 +2,7 @@
 private class IENewOpportunityControllerTest {
 
 	@isTest static void test_method_one() {
+        IENewOpportunityController.asd();
 		List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
         Account accIE = new Account(
             Name = '*',
diff --git a/force-app/main/default/classes/OpportunityWebService.cls b/force-app/main/default/classes/OpportunityWebService.cls
index 8b52fc2..d6008fb 100644
--- a/force-app/main/default/classes/OpportunityWebService.cls
+++ b/force-app/main/default/classes/OpportunityWebService.cls
@@ -209,7 +209,41 @@
 
     }
 
+    WebService static String checkDealerId(String dealerId) {
+        String rtn = '0';
+        // 鑾峰彇绯荤粺绠$悊鍛業d
+        String getUserId = System.label.SystemAdmin1_2_GPI;
+        // 鑾峰彇褰撳墠鐢ㄦ埛Id
+        String userId = UserInfo.getUserId().subString(0,15);
+        dealerId.subString(0,15);
 
+        String userDealerId;
+        List<User> userList = new List<User>();
+        User user = new User();
+
+        if (String.isNotBlank(getUserId)) {
+            if (!getUserId.contains(userId)) {
+                userList = [select mu_Dealer__c  
+                from User 
+                where id =: userId];
+
+                user = userList[0];
+                userDealerId = user.mu_Dealer__c;
+                if (String.isNotBlank(userDealerId)) {
+                    userDealerId.substring(0,15);
+                }
+                if (userDealerId == dealerId) {
+                    rtn = '1';
+                }
+            }else {
+                rtn = '0';
+            }
+        }else {
+            rtn = '0';
+        }
+        System.debug('rtn='+rtn);
+        return rtn;
+    }
 
 
 
diff --git a/force-app/main/default/classes/OrderPdf2Controller.cls b/force-app/main/default/classes/OrderPdf2Controller.cls
index 6bea583..8383a32 100644
--- a/force-app/main/default/classes/OrderPdf2Controller.cls
+++ b/force-app/main/default/classes/OrderPdf2Controller.cls
@@ -103,7 +103,7 @@
         List<Order> orderList = [select Id, AccountId, OpportunityId, Opportunity.Dealer__c, Opportunity.SpecialDeliveryAddress__c, Opportunity.SpecialDeliveryContact__c,Opportunity.InquiryNumber__c,
                                         PDF_S_Name__c, PDF_S_Address__c, PDF_S_City__c, PDF_S_Province__c, PDF_S_Phone__c,Opportunity.CreatedBy.ContactId,CreatedBy.ContactId,
                                         Name, Opportunity.ExpectedDeliveryDate__c, PDF_Sap_No__c, OrderNumber, Opportunity.SubDealer__c,
-                                        PDF_Property__c, Opportunity.Name, PDF_No__c, Description, PDF_Order_No__c,CrossCooperativeProject__c,Dealer_A__c,
+                                        PDF_Property__c, Opportunity.Name, PDF_No__c, Description, PDF_Order_No__c,CrossCooperativeProject__c,
                                         Olympus_Price_BeforeDiscount_D__c, Discount_D__c, OlympusContractPricesD__c, CustomerContractPriceD__c,
                                         Opportunity.ProductSegment__c, Opportunity.SalesChannel__c, Opportunity.Machine_Parts__c,
                                         SpecialDeliveryAccount__c, SpecialDeliveryAccount_D__c, SpecialDeliveryContact2__c, SpecialDeliveryContact2_D__c
@@ -132,12 +132,12 @@
         }*/
         buyer = new Account();
         if (order.Opportunity.Dealer__c != null) {
-             if (order.CrossCooperativeProject__c) {
+             /*if (order.CrossCooperativeProject__c) {
                 buyer = [select Id, Name, Address1__c,Business_license__c, City__c, Province__c, Phone from Account where Id = :order.Dealer_A__c];
             }else{
                 buyer = [select Id, Name, Address1__c,Business_license__c, City__c, Province__c, Phone from Account where Id = :order.Opportunity.Dealer__c];
-            }
-            //buyer = [select Id, Name, Address1__c,Business_license__c, City__c, Province__c, Phone from Account where Id = :order.Opportunity.Dealer__c];
+            }*/
+            buyer = [select Id, Name, Address1__c,Business_license__c, City__c, Province__c, Phone from Account where Id = :order.Opportunity.Dealer__c];
         }
         notSpecialDealer = !StaticParameter.specialDealerMap.containsKey(((String)order.Opportunity.Dealer__c));
         system.debug('order.Opportunity.Dealer__c' + order.Opportunity.Dealer__c);
diff --git a/force-app/main/default/classes/OrderPdf2ControllerTest.cls b/force-app/main/default/classes/OrderPdf2ControllerTest.cls
index 1cca8b0..efc5fdb 100644
--- a/force-app/main/default/classes/OrderPdf2ControllerTest.cls
+++ b/force-app/main/default/classes/OrderPdf2ControllerTest.cls
@@ -105,7 +105,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
            //ProductListApproveStatus__c = 'Reject'
         );
         insert order;
@@ -286,7 +287,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
         );
         insert order;
 
@@ -421,7 +423,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
            //ProductListApproveStatus__c = 'Reject'
         );
         insert order;
@@ -547,7 +550,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
         );
         insert order;
 
@@ -683,7 +687,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
            //ProductListApproveStatus__c = 'Reject'
         );
         insert order;
@@ -810,7 +815,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
         );
         insert order;
 
diff --git a/force-app/main/default/classes/OrderPdfControllerTest.cls b/force-app/main/default/classes/OrderPdfControllerTest.cls
index fccaee2..b88b5f7 100644
--- a/force-app/main/default/classes/OrderPdfControllerTest.cls
+++ b/force-app/main/default/classes/OrderPdfControllerTest.cls
@@ -118,7 +118,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
         );
         insert order;
 
@@ -281,7 +282,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
         );
         insert order;
 
@@ -429,7 +431,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
         );
         insert order;
 
@@ -570,7 +573,8 @@
             EffectiveDate = Date.today(),
             Status = 'Draft',
             Pricebook2Id = pricebook.Id,
-            EndUser__c = contact.Id
+            EndUser__c = contact.Id,
+            EndUserD__c = contact.Id
         );
         insert order;
 
diff --git a/force-app/main/default/classes/OrderTriggerHandler.cls b/force-app/main/default/classes/OrderTriggerHandler.cls
index dabed1b..ad164af 100644
--- a/force-app/main/default/classes/OrderTriggerHandler.cls
+++ b/force-app/main/default/classes/OrderTriggerHandler.cls
@@ -107,8 +107,8 @@
                     
                     system.debug('2222222'+getModelQuantityMap);
                     String accountDealerErrorMessage = RadiationUtil.updateCertificationDetails(oliList[0].Opportunity.DealerId__c, null, getModelQuantityMap, false);
-                    String olympusDealerErrorMessage = RadiationUtil.updateCertificationDetails(olympusAccountId, null, getModelQuantityMap, false) == '' ? '' : '濂ユ灄宸存柉鍙攢鍞暟閲忎笉瓒�';
-                    //result = accountDealerErrorMessage + (olympusDealerErrorMessage == '' ? '' : '濂ユ灄宸存柉鍙攢鍞暟閲忎笉瓒�') ;
+                    String olympusDealerErrorMessage = RadiationUtil.updateCertificationDetails(olympusAccountId, null, getModelQuantityMap, false) == '' ? '' : '浠櫙閫氬彲閿�鍞暟閲忎笉瓒�';
+                    //result = accountDealerErrorMessage + (olympusDealerErrorMessage == '' ? '' : '浠櫙閫氬彲閿�鍞暟閲忎笉瓒�') ;
                     Boolean temp = accountDealerErrorMessage.startsWith('浣犱笉鑳�');
                     String strOly = LicenseCheckUtil.LicenseCheckOly();
                     if(temp){
diff --git a/force-app/main/default/classes/PIHelper.cls b/force-app/main/default/classes/PIHelper.cls
new file mode 100644
index 0000000..3572a68
--- /dev/null
+++ b/force-app/main/default/classes/PIHelper.cls
@@ -0,0 +1,129 @@
+/*
+ * Author: Bubba Li
+ * Created Date: 01/26/2022
+ * Purpose: Utility class for PI 
+ * Test Class: PIHelper
+ * History: 
+ *      01/26/2022 - Bubba Li - Initial Code.
+ * 
+ * */
+global without sharing class PIHelper {
+    public static String getObjectKeyPrefix(String objName){
+        try{
+            schema.sObjectType sObjType = Schema.getGlobalDescribe().get(objName);
+            return (sObjType.getDescribe().getKeyPrefix());
+        }catch(Exception e){
+            system.debug('Exception from get key prefix:'+e.getMessage());
+            return '';
+        }    
+    }
+
+    // Use this log method
+    public static void saveTransLog(String module,String awsDataId,String sfId, String transId,String content,String status,String respMsg){
+        Transaction_Log__c traLog = new Transaction_Log__c();
+        traLog.AWS_Data_Id__c = awsDataId;
+        traLog.SFRecordId__c = sfId;
+        traLog.Module__c = 'Upsert SF ' + module;
+        traLog.TransId__c = transId;
+        traLog.Request__c = content;
+        traLog.Status__c = status;
+        traLog.Response__c = respMsg;
+        traLog.Interface_URL__c = traLog.Module__c;
+        insert traLog;
+    }
+    public static PIIntegration getPIIntegrationInfo(String sobjectType){
+        PIIntegration piIntegration = new PIIntegration();
+        //鏌ヨurl
+        PI_Policy_Configuration__c config = [select Full_New_URL__c,Full_Search_URL__c,Full_Update_URL__c,Full_Undelete_URL__c,Full_Read_URL__c,Full_Delete_URL__c,TransactionURL__c from PI_Policy_Configuration__c where Sobject_Type__c =: sobjectType];
+        System.debug('config = ' + config);
+
+        //鑾峰彇appid鍜宎ppsecret
+        AWS_Integration_Info__mdt awsConfiguration = [SELECT App_Id__c,Token_URL__c,App_Secret__c,Host_URL__c FROM AWS_Integration_Info__mdt  WHERE DeveloperName = 'AWS_Default_Configuration'];
+        if (awsConfiguration == null) {
+            System.debug('AWS_Integration_Info__mdt娌¢厤缃�');
+            return null;
+        }
+        String awsAppId = awsConfiguration.App_Id__c;
+        String awsAppSecret = awsConfiguration.App_Secret__c;
+
+        System.debug('awsAppId = ' + awsAppId);
+        System.debug('awsAppSecret = ' + awsAppSecret);
+        System.debug('Host_URL__c = ' + awsConfiguration.Host_URL__c);
+        System.debug('Token URL = ' + awsConfiguration.Token_URL__c);
+
+        //鑾峰彇token
+        String token = '';
+        try{
+            Http http = new Http();
+            HttpRequest request = new HttpRequest();
+            String url = awsConfiguration.Token_URL__c;
+            request.setEndpoint(url);
+            request.setMethod('GET');
+            HttpResponse response = http.send(request);
+            System.debug('response = ' + response);
+            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
+            token = (String)results.get('object');
+            System.debug('token = ' + token);
+        }catch(Exception e){
+            // System.debug(e.getMessage());
+            // System.debug(e.getStackTraceString());
+            Transaction_Log__c traLog = new Transaction_Log__c();
+            traLog.Module__c = 'Get Token';
+            traLog.Status__c = 'fail';
+            traLog.Response__c = e.getMessage();
+            traLog.Interface_URL__c = awsConfiguration.Token_URL__c;
+            insert traLog;
+        }
+    
+        //Insert Get Token Log
+
+        //鑾峰彇鏁忔劅瀛楁
+        piIntegration.PIDetails = [select id,PI_Policy_Configuration__r.Full_New_URL__c, Enable_Encrypt__c, SF_Field_API_Name__c,SF_Field_Encrypted_API__c, AWS_Field_API__c,AWS_Encrypted_Field_API__c,Field_Type__c from PI_Field_Policy_Detail__c  where PI_Policy_Configuration_Name__c =:sobjectType and Enable_Encrypt__c=true];
+        List<String> vLookUpFields = new List<String>();
+        List<String> PIFields = new List<String>();
+        for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) {
+            if(PIDetail.Field_Type__c == 'Reference'){
+                vLookUpFields.add(PIDetail.SF_Field_API_Name__c);
+            }
+            PIFields.add(PIDetail.SF_Field_API_Name__c);
+        }
+
+        System.debug('vLookUpFields = ' + vLookUpFields.toString());
+        System.debug('PIFields = ' + PIFields.toString());
+
+        //濉厖鏁版嵁
+        piIntegration.newUrl = config.Full_New_URL__c;
+        piIntegration.updateUrl = config.Full_Update_URL__c;
+        piIntegration.queryUrl = config.Full_Read_URL__c;
+        piIntegration.deleteUrl = config.Full_Delete_URL__c;
+        piIntegration.undeleteUrl = config.Full_Undelete_URL__c;
+        piIntegration.transactionURL = config.TransactionURL__c;
+        piIntegration.hostUrl = awsConfiguration.Host_URL__c;
+        piIntegration.searchUrl = config.Full_Search_URL__c;
+        piIntegration.token = token;
+        piIntegration.awsAppId = awsAppId;
+        piIntegration.awsAppSecret = awsAppSecret;
+        piIntegration.vLookUpFields = vLookUpFields;
+        piIntegration.PIFields = PIFields;
+        piIntegration.sobjectPrefix = getObjectKeyPrefix(sobjectType);
+        System.debug('piIntegration' + piIntegration);
+        return piIntegration;
+    }
+    global class PIIntegration{
+        public String sobjectPrefix{set;get;}
+        public String searchUrl{set;get;}
+        public String newUrl{set;get;}
+        public String updateUrl{set;get;}
+        public String queryUrl{set;get;}
+        public String deleteUrl{set;get;}
+        public String undeleteUrl{set;get;}
+        public String hostUrl{set;get;}
+        public String token{set;get;}
+        public String awsAppId{set;get;}
+        public String awsAppSecret{set;get;}
+        public String transactionUrl{set;get;}
+        public List<String> vLookUpFields{set;get;}
+        public List<String> PIFields{set;get;}
+        public List<PI_Field_Policy_Detail__c > PIDetails{set;get;}
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/PIHelper.cls-meta.xml b/force-app/main/default/classes/PIHelper.cls-meta.xml
new file mode 100644
index 0000000..dd61d1f
--- /dev/null
+++ b/force-app/main/default/classes/PIHelper.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>52.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/classes/PIHelperTest.cls b/force-app/main/default/classes/PIHelperTest.cls
new file mode 100644
index 0000000..8b1bb00
--- /dev/null
+++ b/force-app/main/default/classes/PIHelperTest.cls
@@ -0,0 +1,3 @@
+public class PIHelperTest {
+
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/PIHelperTest.cls-meta.xml b/force-app/main/default/classes/PIHelperTest.cls-meta.xml
new file mode 100644
index 0000000..40d6793
--- /dev/null
+++ b/force-app/main/default/classes/PIHelperTest.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>54.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/classes/ProRegisterHandler.cls b/force-app/main/default/classes/ProRegisterHandler.cls
index ff0ddb9..f290e50 100644
--- a/force-app/main/default/classes/ProRegisterHandler.cls
+++ b/force-app/main/default/classes/ProRegisterHandler.cls
@@ -98,16 +98,12 @@
 		if (UpdProMap.keySet().size() > 0)  update UpdProMap.values();
 	}
 
-	//浜у搧闄嶇被,鍙娉ㄥ唽璇佹洿鏂颁簡,灏辨鏌ヤ竴閬嶏紝閲嶆柊缁欎骇鍝佷笂鐨勭瓑绾х被鍒瓧娈佃祴鍊笺��
-	//鍙互鎵惧嚭闇�瑕佺殑Id,鐒跺悗璋冪敤鏂规硶銆�
+	//鐢ㄤ簬闄嶇被,浜у搧娉ㄥ唽璇佹洿鏂颁簡,灏辨妸浜у搧娉ㄥ唽璇佷笅鐨勪骇鍝佺殑绛夌骇绫诲埆瀛楁璧嬬┖,瑙﹀彂浜у搧鐨勮Е鍙戝櫒
 	public static void checkRegistervervaldatum(List<Product_Register__c> newList, Map<Id, Product_Register__c> newMap, List<Product_Register__c> oldList, Map<Id, Product_Register__c> oldMap) {
 		List<String> prcList = new List<String>();
 		for (Product_Register__c pr : newList) {
 			Product_Register__c oldpr = oldMap.get(pr.Id);
-			//鏈夋晥鏈熺殑濮嬩笌缁堝彉浜�,灏辨妸杩欎釜浜у搧娉ㄥ唽璇佺殑id鏀惧叆涓�涓狶ist闆嗗悎閲岄潰
-			//if (pr.ValidTo__c != oldpr.ValidTo__c || pr.ValidFrom__c != oldpr.ValidFrom__c) {
 			    prcList.add(pr.id);
-			//}
 		}
 		//鏀惧埌Map閲岋紝鐢ㄤ簬娉ㄥ唽璇佹洿鏂颁骇鍝�
 		Map<Id,Product2> prt2Map = new Map<Id,Product2>();
diff --git a/force-app/main/default/classes/Product2TriggerHandler.cls b/force-app/main/default/classes/Product2TriggerHandler.cls
index d0ec9c5..0d7da62 100644
--- a/force-app/main/default/classes/Product2TriggerHandler.cls
+++ b/force-app/main/default/classes/Product2TriggerHandler.cls
@@ -46,14 +46,16 @@
        }
     }
 
+    //鐢ㄤ簬闄嶇被
     public static void checkProduct2Level(List<Product2> newList, Map<Id, Product2> newMap, List<Product2> oldList, Map<Id, Product2> oldMap) {
+        //鍙栦骇鍝乮d
         List<String> p2ids = new List<String>();
         for(Product2 p2 : newList)
         {
             p2ids.add(p2.id);
         }
 
-        //瀛樻斁鏌ユ壘鐨剆oql鏂�
+        //瀛樻斁鏌ユ壘鐨剆oql鏂�,鍏崇郴琛ㄩ噷鐨勪骇鍝佸拰娉ㄥ唽璇佺浉鍏冲瓧娈�
         List<Product_Register_Link__c> pro2List = new List<Product_Register_Link__c>();
         pro2List = [select Product2__r.id,Product2__r.demoteer_Sap__c,Product2__r.Diedatvanink__c,Product_Register__r.Stelsedag__c,Product_Register__r.MedPrdClass__c,Product_Register__r.ValidTo__c,Product_Register__r.ValidFrom__c,Product_Register__c,Product2__c 
         from Product_Register_Link__c 
@@ -66,32 +68,38 @@
         Map<Id,Date> prSte1Map = new Map<Id,Date>();//瀛樹簩绫荤淮鎶ゆ棩
         if (pro2List.size()>0) {
             for (Product_Register_Link__c prl: pro2List) {
+                //鏈夊尰鐤楀櫒姊板垎绫诲氨澧炲姞,娌℃湁灏辨斁杩涘幓
                 if (pro2Map.containsKey(prl.Product2__r.Id)) {
                     pro2Map.get(prl.Product2__r.Id).add(prl.Product_Register__r.MedPrdClass__c);
                 }else {
                     pro2Map.put(prl.Product2__r.Id, new List<String>());
                     pro2Map.get(prl.Product2__r.Id).add(prl.Product_Register__r.MedPrdClass__c);
                 }
-
+                //涓�绫昏瘉.缁存姢鏃ヤ笉涓虹┖.浜у搧鐢熶骇鏃ユ湡鍦ㄦ敞鍐岃瘉鏈夋晥鏈熶箣鍐�,涓嬮潰鐨勬槸浜岀被
                 if (prl.Product_Register__r.MedPrdClass__c == '1' && prl.Product_Register__r.Stelsedag__c <> null && 
-                    newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c) {
+                    (newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c)) {
                     if (prSteMap.containsKey(prl.Product2__r.Id)) {
-                        if (prSteMap.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c) {
+                        //杩欎竴姝�,map鍙兘鏈塱d,浣嗘槸鍊兼槸null,鎵�浠ユ槸null鏃朵篃缁欎粬璧嬪��
+                        if (prSteMap.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c || prSteMap.get(prl.Product2__r.Id) == null) {
                             prSteMap.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c);
                         }
                     }else {
                         prSteMap.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c);
                     }
                 }else {
+                    //涓嶇鍚堝氨璧嬬┖,鍜屼笂闈㈢殑鍒ゆ柇鏉′欢鏈夊叧鑱�***
                     if (!prSteMap.containsKey(prl.Product2__r.Id) || prSteMap.get(prl.Product2__r.Id) == null) {
                         prSteMap.put(prl.Product2__r.Id,null);
                     }  
                 }
-
+                //鍜屼笂闈竴鏍�               
                 if ((prl.Product_Register__r.MedPrdClass__c == '2' || prl.Product_Register__r.MedPrdClass__c == '3') && prl.Product_Register__r.Stelsedag__c <> null && 
-                    newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c) {
+                    (newMap.get(prl.Product2__r.Id).demoteer_Sap__c <= prl.Product_Register__r.ValidTo__c && newMap.get(prl.Product2__r.Id).demoteer_Sap__c >= prl.Product_Register__r.ValidFrom__c)) {
+                    System.debug(prSte1Map.containsKey(prl.Product2__r.Id));
+                    System.debug(prSte1Map);
                     if (prSte1Map.containsKey(prl.Product2__r.Id)) {
-                        if (prSte1Map.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c) {
+                        System.debug(prSte1Map.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c);
+                        if (prSte1Map.get(prl.Product2__r.Id) > prl.Product_Register__r.Stelsedag__c || prSte1Map.get(prl.Product2__r.Id) == null) {
                             prSte1Map.put(prl.Product2__r.Id,prl.Product_Register__r.Stelsedag__c);
                         }
                     }else {
@@ -114,15 +122,20 @@
         System.debug('prSte1Map='+prSte1Map);
         Date stedate;
 
-        //閫氳繃涓婇潰鐨勫惊鐜紝鎶婂叧绯昏〃杩囪幏鍙栫殑鏁版嵁璇诲嚭鏉ワ紝浼犵粰map
+        //閫氳繃涓婇潰鐨勫惊鐜紝鎶婂叧绯昏〃杩囪幏鍙栫殑鏁版嵁璇诲嚭鏉ワ紝浼犵粰map锛屼竴鍏卞垎涓�3涓猰ap锛岃娉ㄦ剰
         if (pro2Map.size()>0) {
             for (Product_Register_Link__c pr: pro2List) {
+                //淇濊瘉id鍦ㄤ笂闈㈢殑map閲屽瓨鍦�,浣嗘槸杩欎竴姝ユ湁娌℃湁濂藉儚娌″暐鍖哄埆,鍙堟病閿欒,绱㈡�т笉鍒犳帀
                 if (pro2Map.containsKey(pr.Product2__r.Id) && (prSteMap.containsKey(pr.Product2__r.Id) || prSte1Map.containsKey(pr.Product2__r.Id))) {
+                    //鍙栧緱鏄骇鍝佺殑鐢熶骇鏃ユ湡鍦ㄦ敞鍐岃瘉鐨勬湁鏁堟湡鍐呯殑娉ㄥ唽璇佷笂闈㈢殑缁存姢鏃�,涓�绫讳紭鍏�,鍏舵浜岀被
                     stedate = prSteMap.get(pr.Product2__r.Id)==null?(prSte1Map.get(pr.Product2__r.Id)==null?null:prSte1Map.get(pr.Product2__r.Id)):prSteMap.get(pr.Product2__r.Id);
                     if (stedate <> null) {
-                        if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <> null && newMap.get(pr.Product2__r.Id).Diedatvanink__c <> null) {
+                        //淇濊瘉浜у搧涓婄殑鐢熶骇鏃ユ湁鍊�
+                        if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <> null) {
+                            //娉ㄥ唽璇佺淮鎶ゆ棩鏈夊��
                             if (pr.Product_Register__r.Stelsedag__c <> null) {
-                                if (newMap.get(pr.Product2__r.Id).Diedatvanink__c <= stedate) {
+                                //鍏ュ簱鏃ュ皬浜庣瓑浜庣淮鎶ゆ棩
+                                if (newMap.get(pr.Product2__r.Id).Diedatvanink__c == null || newMap.get(pr.Product2__r.Id).Diedatvanink__c <= stedate) {
                                    if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
                                         && pr.Product_Register__r.MedPrdClass__c == '2' || pr.Product_Register__r.MedPrdClass__c == '3') {
                                         System.debug('2');
@@ -144,7 +157,8 @@
                                                 prlMap.put(pr.Product2__r.Id, Lins);
                                             }
                                     }
-                                }else if (newMap.get(pr.Product2__r.Id).Diedatvanink__c > stedate) {
+                                //鍏ュ簱鏃ュぇ浜庣淮鎶ゆ棩
+                                }else if (newMap.get(pr.Product2__r.Id).Diedatvanink__c <> null && newMap.get(pr.Product2__r.Id).Diedatvanink__c > stedate) {
                                     if (newMap.get(pr.Product2__r.Id).demoteer_Sap__c <= pr.Product_Register__r.ValidTo__c && newMap.get(pr.Product2__r.Id).demoteer_Sap__c >= pr.Product_Register__r.ValidFrom__c
                                         && pr.Product_Register__r.MedPrdClass__c == '1') {
                                         if (prl1Map.get(pr.Product2__r.Id) == null || !prl1Map.containsKey(pr.Product2__r.Id)) {
@@ -166,10 +180,12 @@
                                     }
                                 }
                             }else {
+                                //缁存姢鏃ョ┖锛岃繖涓猰ap缃┖
                                 prl2Map.put(pr.Product2__r.Id, '绌�');
                             }
                         }
                     }else {
+                        //鍓嶉潰map鏃犲�硷紝杩欎釜map缃┖
                         prl2Map.put(pr.Product2__r.Id, '绌�');
                     }
                 }
@@ -195,9 +211,11 @@
                     pr2.Level_Category__c = '浜岀被';
                 }
             }else if (prl2Map.containsKey(pr2.Id)) {
+                //涓轰簡閬垮厤楹荤儲涓庡悗缁慨鏀癸紝缁熶竴闈炵洃绠′簡銆�
                 pr2.Level_Category__c = '闈炵洃绠�';
             }
-            if (pr2.demoteer_Sap__c == null || pr2.Diedatvanink__c == null) {
+            //鐢熶骇鏃ユ棤鍊硷紝绛夌骇绫诲埆缃┖
+            if (pr2.demoteer_Sap__c == null) {
                 pr2.Level_Category__c = null;
             }
             System.debug('pr2.Level_Category__c='+pr2.Level_Category__c);
diff --git a/force-app/main/default/classes/RadiationUtil.cls b/force-app/main/default/classes/RadiationUtil.cls
index cfd9051..02ebb2f 100644
--- a/force-app/main/default/classes/RadiationUtil.cls
+++ b/force-app/main/default/classes/RadiationUtil.cls
@@ -2,6 +2,8 @@
 
     public static Boolean oldOrder = false;
 
+    public static BOolean is_oly = false;
+
     public static Boolean EscapeOrderTriggerHandler = true;
     /**
      * [updateRadiationTypeQuantity description]鏇存柊浠g悊鍟嗚瘉鐓ф槑缁嗭紝鏇存柊濂ユ灄宸存柉浠g悊鍟嗙殑璇佺収鏄庣粏
@@ -13,7 +15,7 @@
     public static void updateRadiationTypeQuantity (String Id, String orderFounder, String dealerId, Boolean toloseFlag, String operationType, String operator) {
 
 
-        String olympusAccountId = oldOrder ? System.label.Olympus_Id : System.label.newOlympus_Id;
+        String olympusAccountId =  System.label.Olympus_Id ;
 
         String orderId = Id;
         //鑾峰彇鍚堝悓鐨勮緪灏勭被鍨嬪拰鏁伴噺
@@ -23,7 +25,9 @@
             //鏌ヤ唬鐞嗗晢鐨勪唬鐞嗗晢璐拱鏄庣粏
             Map<String, PurchaseDetails__c> dealerModelQuantityMap = GetPurchaseDetailsMap(dealerId);
             //鏌ュゥ鏋楀反鏂殑浠g悊鍟嗚喘涔版槑缁�
+            is_oly = true;
             Map<String, PurchaseDetails__c> olympusModelQuantityMap = GetPurchaseDetailsMap(olympusAccountId);
+            is_oly = false;
             // 鏌ユ壘 鍚堝悓鎻愪氦瀵瑰簲鐨勪唬鐞嗗晢璐拱鏄庣粏
             Map<String, PurchaseDetails__c> dealerResult = new Map<String, PurchaseDetails__c>();
             Map<String, PurchaseDetails__c> olympusResult = new Map<String, PurchaseDetails__c>();
@@ -117,7 +121,9 @@
 
                     } else {//澧炲姞宸插敭浜у搧鏁伴噺
                         reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, quantity, operator));
+                        is_oly = true;
                         olympusModelQuantityMap = insertPurchaseDetail(olympusModelQuantityMap, olympusAccountId, radiationType, radiationTypeQuantityMap);
+                        is_oly = false;
                     }
                 } else {//鍑忓幓宸插敭浜у搧鏁伴噺
                     if (toloseFlag) {
@@ -125,7 +131,9 @@
                         olympusResult.get(radiationType).SoldNumber__c -= quantity;
                     } else {//澧炲姞宸插敭浜у搧鏁伴噺
                         reportMap.putAll(upsertChangedReport(olympusAccountId, radiationType, operationType, orderId, quantity, operator));
+                        is_oly = true;
                         olympusModelQuantityMap = insertPurchaseDetail(olympusModelQuantityMap, olympusAccountId, radiationType, radiationTypeQuantityMap);
+                        is_oly = false;
                     }
                     
                 }
@@ -140,7 +148,9 @@
 
                 if ( olympusResult.size() > 0 && olympusResult != null) {
                     upsert olympusResult.values();
+                    is_oly = true;
                     insertReportMap.putAll(insertChangedReport(olympusResult, reportMap));
+                    is_oly = false;
                 }
 
             } else {
@@ -151,7 +161,9 @@
 
                 if ( olympusModelQuantityMap.size() > 0 && olympusModelQuantityMap != null) {
                     upsert olympusModelQuantityMap.values();
+                    is_oly = true;
                     insertReportMap.putAll(insertChangedReport(olympusModelQuantityMap, reportMap));
+                    is_oly = false;
                 }
             }
                 
@@ -161,7 +173,9 @@
             
             Map<String, Integer> radiationMap =  new Map<String, Integer>();
             String accountDealerErrorMessage = updateCertificationDetails(dealerId, orderFounder, radiationMap, true);
+            is_oly = true;
             String olympusDealerErrorMessage = updateCertificationDetails(olympusAccountId, orderFounder, radiationMap, true);
+            is_oly = false;
         }
 
     }
@@ -178,6 +192,7 @@
             String accountId = detail.PurchaseAccount__c;
             //String accountIdafter = accountId.subString(0,15);
             String key = accountId.subString(0, 15) + detail.PurProductModel__c;
+
             if (reportMap.containsKey(key)) {
                 reportMap.get(key).ChangedPurchase__c = detail.Id;
             }
@@ -194,9 +209,11 @@
      * @return              [description]
      */
     public static String updateCertificationDetails( String accountId, String orderFounder, Map<String, Decimal> dataMap, Boolean updateFlag) {
-
+        
         Map<String, CertificationDetails__c> certificationDetailMap = GetAccountCertificationDetail(accountId);
+        
         Map<String, CertificationDetails__c> temporaryCertificationDetailMap = GetAccountCertificationDetail(accountId);
+
         Map<String, PurchaseDetails__c> purchaseDetailMap = GetPurchaseDetailsMap(accountId);
 
         Map<String, CertificationDetails__c> updatecertificationDetailMap = new Map<String, CertificationDetails__c>();
@@ -370,7 +387,19 @@
      */
     public static Map<String, CertificationDetails__c> GetAccountCertificationDetail (String accountId) {
         Map<String, CertificationDetails__c> result = new Map<String, CertificationDetails__c>();
-        List<CertificationDetails__c> certificationDetailsList = [ select Id, Name, ProdustionType__c, 
+        List<CertificationDetails__c> certificationDetailsList = new List<CertificationDetails__c>();
+        if (oldOrder && is_oly) {
+            certificationDetailsList = [ select Id, Name, ProdustionType__c, 
+                                    ProductModelNumber__c, Ceiling80__c, Record80__c, Ceiling90__c, Record90__c , 
+                                    CertificationDetailAccount__c, CertificationDetailAccountName__c,
+                                    LicenseInformation__r.IfQuantityCtrl__c,AccountRecordType__c,Record100__c,
+                                    Ceiling100__c
+                                    from CertificationDetails__c 
+                                    where CertificationDetailAccount__c = :accountId  
+                                        and ActivitieTypes__c = '閿�鍞�' and IsActive__c = false];
+            
+        }else{
+            certificationDetailsList = [ select Id, Name, ProdustionType__c, 
                                     ProductModelNumber__c, Ceiling80__c, Record80__c, Ceiling90__c, Record90__c , 
                                     CertificationDetailAccount__c, CertificationDetailAccountName__c,
                                     LicenseInformation__r.IfQuantityCtrl__c,AccountRecordType__c,Record100__c,
@@ -378,6 +407,8 @@
                                     from CertificationDetails__c 
                                     where CertificationDetailAccount__c = :accountId  
                                         and ActivitieTypes__c = '閿�鍞�' and IsActive__c = true];
+        }
+        
 
         for  (CertificationDetails__c detail : certificationDetailsList) {
             result.put(detail.ProdustionType__c, detail);
@@ -407,6 +438,11 @@
         purchaseDetail.PurProductModel__c = productModel;
         purchaseDetail.PurchaseAccount__c = id;
         purchaseDetail.TakeEffectInYear__c = effectiveYear;
+        if (oldOrder && is_oly) {
+            purchasedetail.company__c = '濂ユ灄宸存柉';
+        }else if(is_oly){
+            purchaseDetail.company__c = '浠櫙閫氬厜瀛︾鎶�';
+        }
 
         for (String model:certificationDetailMap.keySet()) {
             if ('Delta鍜孷anta'.equals(model)) {
@@ -463,10 +499,25 @@
     public static Map<String, PurchaseDetails__c> GetPurchaseDetailsMap( String accountId) {
         String effectiveYear = String.valueOf(Date.today().year());
         Map<String, PurchaseDetails__c> result = new Map<String, PurchaseDetails__c>();
-        List<PurchaseDetails__c> purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
+        List<PurchaseDetails__c> purchaseDetailsList = new List<PurchaseDetails__c>();
+        if(is_oly == false){
+            purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
                                  PurProductModel__c, PurchaseAccount__c
                                  from PurchaseDetails__c
                                  where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId];
+        }else{
+            if (oldOrder) {
+                purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
+                                 PurProductModel__c, PurchaseAccount__c
+                                 from PurchaseDetails__c
+                                 where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId and company__c = '濂ユ灄宸存柉'];
+            }else{
+                purchaseDetailsList = [select Id, Name, RemainingNumber__c, SoldNumber__c,
+                                 PurProductModel__c, PurchaseAccount__c
+                                 from PurchaseDetails__c
+                                 where TakeEffectInYear__c = :effectiveYear and PurchaseAccount__c = :accountId and company__c = '浠櫙閫氬厜瀛︾鎶�'];
+            }
+        }
         if (purchaseDetailsList.size() > 0) {
             for (PurchaseDetails__c purchaseDetail : purchaseDetailsList) {
                 result.put(purchaseDetail.PurProductModel__c, purchaseDetail);
diff --git a/force-app/main/default/classes/SBG019Rest.cls b/force-app/main/default/classes/SBG019Rest.cls
index 95b0e69..0307f9a 100644
--- a/force-app/main/default/classes/SBG019Rest.cls
+++ b/force-app/main/default/classes/SBG019Rest.cls
@@ -22,7 +22,7 @@
 
         public String ProductCode;//鐗╂枡
         public String ProductDate;//鐩戠浜у搧鏈�鏃╃敓浜ф棩鏈�
-
+        public String StorageDate;//鐩戠浜у搧鍏ュ簱鏃ユ湡
     }
 
 
@@ -153,7 +153,7 @@
         String result = '';
     	//鏍规嵁浜у搧Code鏌ヨ浜у搧淇℃伅
     	List<Product2> getProductList = 
-    				[SELECT Id, Name, ProductCode,demoteer_Sap__c 
+    				[SELECT Id, Name, ProductCode,demoteer_Sap__c,Diedatvanink__c 
     				FROM Product2 
     				WHERE ProductCode 
     				IN:satisfyGeDataDetailMap.keyset() 
@@ -168,8 +168,10 @@
 			if (productMap.containsKey(productCode)) {
 				GeDataDetails geDataDetails = satisfyGeDataDetailMap.get(productCode);
 				Date demoteer_Sap = NFMUtil.parseStr2Date(geDataDetails.ProductDate, false);
+                Date Diedatvanink = NFMUtil.parseStr2Date(geDataDetails.StorageDate, false);
             	Product2  product = productMap.get(productCode);
             	product.demoteer_Sap__c = demoteer_Sap;
+                product.Diedatvanink__c = Diedatvanink;
 
             	productMap.put(productCode,product);
                 result += 'productCode [ ' + productCode + ' ]\n';  
diff --git a/force-app/main/default/classes/SBG027Controller.cls b/force-app/main/default/classes/SBG027Controller.cls
index 8ca0d67..096e73a 100644
--- a/force-app/main/default/classes/SBG027Controller.cls
+++ b/force-app/main/default/classes/SBG027Controller.cls
@@ -107,7 +107,7 @@
                                                 Opportunity.SalesChannel__c, Opportunity.ExpectedDeliveryDate__c, Opportunity.DealerId__c,Opportunity.DealerSalesStaffName__c,OlympusContractPricesD__c,SpecialDeliveryContact_D__c,Opportunity.SpecialDeliveryContact_D__r.ManagementCode_F__c,
                                                 Opportunity.ForeignTradeCompany__c, Opportunity.SpecialDeliveryAddress__c,PaymentTerms__c,SpecialDeliveryContact__c,PDF_Sp_Shipment_Term__c,PDF_Sp_ShippingTerms__c,
                                                 ForeignTradeCompany_D__r.ManagementCode_F__c, SpecialDeliveryAccount_D__r.ManagementCode_F__c, SpecialDeliveryContact2_D__r.ManagementCode_F__c,Opportunity.Dealer__r.DummyDealer__c,ContractPriceTotal__c,
-                                                If_Supervise__c,CrossCooperativeDealerCode__c,SplitRatio__c,CrossCooperativeProject__c,Level_Category__c,DealerSalesStaffNameA__c,Dealer_A__r.ManagementCode_Ext__c,Dealer_B__r.ManagementCode_F__c
+                                                If_Supervise__c,CrossCooperativeDealerCode__c,SplitRatio__c,CrossCooperativeProject__c,Level_Category__c,DealerSalesStaffNameA__c,Dealer_A__r.ManagementCode_Ext__c,Dealer_B__r.ManagementCode_F__c 
                                              from order where Id IN :ordIds ];
             //List<order> ordList = [select Id,Name,Opportunity.Name, Opportunity.CurrencyIsoCode,OrderNumber,Opportunity.ForeignTradeCompany__r.ManagementCode_F__c,CustomerContractPriceD__c,SpecialCondition_text__c,SalesChannel__c,
             //                                    Owner.Name,Opportunity.AccountId__c,Opportunity.InquiryNumber__c,Opportunity.SpecialDeliveryAddress__r.ManagementCode_F__c, ServiceFee_D__c,Opportunity.SpecialDeliveryAddress_D__c,Opportunity.SpecialDeliveryAddress_D__r.ManagementCode_F__c,
@@ -190,7 +190,11 @@
                 //CBPR
                 if (ord.Opportunity.Dealer__r.DummyDealer__c == true || ord.Opportunity.SalesChannel__c == 'direct'){
                 quotation.DealerCode          = ord.Opportunity.Account.ManagementCode_F__c;
-                quotation.SalesAccountCode                   = ord.SpecialDeliveryAccount_D__r.ManagementCode_F__c;
+                    if (ord.Opportunity.TradeType__c == 'Tax Exemption' && ord.Opportunity.SalesChannel__c == 'direct') {
+                        quotation.SalesAccountCode = ord.Opportunity.Account.ManagementCode_F__c;
+                    }else {
+                        quotation.SalesAccountCode = ord.SpecialDeliveryAccount_D__r.ManagementCode_F__c;
+                    }
                 }
                 else{
                 quotation.DealerCode          = ord.Opportunity.Dealer__r.ManagementCode_Ext__c;
@@ -238,7 +242,7 @@
                 quotation.Other2            = other2;//ord.SpecialCondition_text__c;
                 quotation.Other3            = ord.Shipment_Term_D__c + ',' + ord.Shipment_Term2_D__c;
                 // 璺ㄥ尯鍩熼攢鍞� XHL 20210831 Start
-                quotation.CoopAgent = '';
+                /*quotation.CoopAgent = '';
                 quotation.CoopAgentPCT = '';
                 if (ord.CrossCooperativeProject__c) {//璺ㄧ渷浠藉悎浣滈」鐩�
                     quotation.CoopAgent = ord.Dealer_B__r.ManagementCode_F__c;//鍚堜綔鍖哄煙浠g悊鍟咰ode
@@ -249,6 +253,17 @@
                         Integer pct = Integer.valueOf(splitRatio.split(':')[1].trim())*10;
                         quotation.CoopAgentPCT = String.valueof(pct);//涓氱哗鎷嗗垎姣斾緥(鍙�:鍚庤竟鐨勫��*10)
                     } 
+                } */
+
+                quotation.CoopAgent = '';
+                quotation.CoopAgentPCT = '';
+                if (ord.CrossCooperativeProject__c) {//璺ㄧ渷浠藉悎浣滈」鐩�
+                    quotation.CoopAgent = ord.CrossCooperativeDealerCode__c;//鍚堜綔鍖哄煙浠g悊鍟咰ode
+                    String splitRatio = ord.SplitRatio__c;
+                    if (String.isNotBlank(splitRatio) && splitRatio.indexof(':') > 0) {
+                        Integer pct = Integer.valueOf(splitRatio.split(':')[1].trim())*10;
+                        quotation.CoopAgentPCT = String.valueof(pct);//涓氱哗鎷嗗垎姣斾緥(鍙�:鍚庤竟鐨勫��*10)
+                    } 
                 } 
                 // 璺ㄥ尯鍩熼攢鍞� XHL 20210831 End
                 quotation.GeDataDetails = new List<GeDataDetails_element>();
diff --git a/force-app/main/default/classes/SBG027TriggerHandleTest.cls b/force-app/main/default/classes/SBG027TriggerHandleTest.cls
index 25eef90..94f341e 100644
--- a/force-app/main/default/classes/SBG027TriggerHandleTest.cls
+++ b/force-app/main/default/classes/SBG027TriggerHandleTest.cls
@@ -216,7 +216,9 @@
             RecordTypeId = '01228000000NJt6',
             confirm__c = false,
             SP_21__c = true,
-            EndUser__c = con.Id
+            Discount_D__c = 10,
+            EndUser__c = con.Id,
+            EndUserD__c = con.Id
         );
         insert odr;
 
diff --git a/force-app/main/default/classes/SBG027TriggerHandler.cls b/force-app/main/default/classes/SBG027TriggerHandler.cls
index 7f4b0dc..abf6168 100644
--- a/force-app/main/default/classes/SBG027TriggerHandler.cls
+++ b/force-app/main/default/classes/SBG027TriggerHandler.cls
@@ -6,19 +6,22 @@
         }   
 System.debug('-----SBG027OrderTrigger start');    
         Map<Id, Id> accIds = new Map<Id, Id>();
-            List<String> strlist = new List<String>();
-                for (Order newOrd : newList) {
+           
+                /*for (Order newOrd : newList) {
                     strlist.add(newOrd.id);
-                }
+                }*/
 
                 for (Order newOrd : newList) {
                      Order oldOrd = oldMap.get(newOrd.Id);
-                     if (oldOrd.confirm__c ==false && newOrd.confirm__c == true ){
+                     if ((oldOrd.confirm__c ==false && newOrd.confirm__c == true)  || newOrd.Is_batch__c == true){
+                        newOrd.Is_batch__c = false;
                         SBG027TriggerHandler.SBG027_Ids.add(newOrd.Id);
                         BatchIF_Log__c iflog = new BatchIF_Log__c();
                         iflog.Type__c = 'SBG027';
                         iflog.Log__c  = 'callout start\n';
                         insert iflog;
+                        List<String> strlist = new List<String>();
+                        strlist.add(newOrd.id);
                         iflog = [Select Id, Name from BatchIF_Log__c where Id = :iflog.Id];
                         //SBG027TriggerHandler.callout(iflog.id,strlist, new Map<String, String>());
                         SBG027Controller.callout(iflog.id,strlist, new Map<String, String>());
diff --git a/force-app/main/default/classes/SBG200Rest.cls b/force-app/main/default/classes/SBG200Rest.cls
index 0398cd6..75b17eb 100644
--- a/force-app/main/default/classes/SBG200Rest.cls
+++ b/force-app/main/default/classes/SBG200Rest.cls
@@ -390,8 +390,8 @@
 	public static void deleteAccountLicenseInformation(Map<String, Account> accountMap) {
 
 		System.debug('deleteAccountLicenseInformation--->Start');
-		List<License_Information__c> existList = [select id, Name, AccountManagementCode__c
-		        from License_Information__c where AccountManagementCode__c In :accountMap.keySet()];
+		List<License_Information__c> existList = [select id, Name, AccountManagementCode__c,Is_Active_Formula__c 
+		        from License_Information__c where AccountManagementCode__c In :accountMap.keySet() and Is_Active_Formula__c = true];
 
 		if (existList.size() > 0) {
 			delete existList;
diff --git a/force-app/main/default/classes/SBG204Rest.cls b/force-app/main/default/classes/SBG204Rest.cls
index 05378fa..111ac3d 100644
--- a/force-app/main/default/classes/SBG204Rest.cls
+++ b/force-app/main/default/classes/SBG204Rest.cls
@@ -17,6 +17,7 @@
         public String ValidFrom;          //娉ㄥ唽璇佸彿鏁堟湡浠�
         public String ValidTo;            //娉ㄥ唽璇佸彿鏁堟湡鑷�
         public String MedPrdClass;        //鍖荤枟鍣ㄦ鍒嗙被
+        public String EffectDate;         //绯荤粺缁存姢鏃�
 
         public String Model;              //浜у搧鍨嬪彿
         public String ProductName;        //浜у搧鍚嶇О(濮旀墭浜у搧鍚嶇О)
@@ -252,6 +253,7 @@
                     pr.RegisterNoClass_Old__c = data.RegisterNoClass_Old; //娉ㄥ唽璇佸彿鍒嗙被缂栧彿(鏃�)
                     pr.ValidFrom__c           = NFMUtil.parseStr2Date(data.ValidFrom);          //娉ㄥ唽璇佸彿鏁堟湡浠�
                     pr.ValidTo__c             = NFMUtil.parseStr2Date(data.ValidTo);            //娉ㄥ唽璇佸彿鏁堟湡鑷�
+                    pr.Stelsedag__c           = NFMUtil.parseStr2Date(data.EffectDate);         //绯荤粺缁存姢鏃�
                     pr.MedPrdClass__c         = data.MedPrdClass;        //鍖荤枟鍣ㄦ鍒嗙被
                     pr.PrdCompanyLicense__c   = data.PrdCompanyLicense;  //鐢熶骇浼佷笟璁稿彲璇佸彿/澶囨鍑瘉鍙�
                     pr.PrdCompanyAddr__c      = data.PrdCompanyAddr;     //鐢熶骇浼佷笟鍦板潃
diff --git a/force-app/main/default/classes/StaticParameter.cls b/force-app/main/default/classes/StaticParameter.cls
index e75d528..a2a5e86 100644
--- a/force-app/main/default/classes/StaticParameter.cls
+++ b/force-app/main/default/classes/StaticParameter.cls
@@ -242,7 +242,8 @@
         '0010K00002W6zlh' => '00G0K000004AYjU',//鎴愰兘鐩涢敶绉戞妧鏈夐檺鍏徃(NDT)
         '0010K00002ZVOwt' => '00G0K000004c0oG',//澶╂触瀹忓熀浼熶笟绉戞妧鍙戝睍鏈夐檺鍏徃(NDT)
         '0010K00002b6v6W' => '00G0K000004c4xH',//鎴愰兘涓诲绉戞妧鏈夐檺璐d换鍏徃(NDT)
-        '0010T00000LO3ph' => '00G0T0000029vfq'//鍖椾含娣辨櫙閲忓厜绉戞妧鏈夐檺鍏徃(BS)
+        /*'0010T00000LO3ph' => '00G0T0000029vfq'//鍖椾含娣辨櫙閲忓厜绉戞妧鏈夐檺鍏徃(BS)*/
+        '0010K00002dmXEJ' => '00G0K0000059tJo'//鍖椾含涓诲绉戞妧鏈夐檺璐d换鍏徃(NDT)
     };
 
     public static List<String> specialDealerList = new List<String>{

--
Gitblit v1.9.1