public without sharing class OrderTriggerHandler { /** * [liApprove description] * 李部长审批控制 */ public static void liApprove(List newList, Map newMap, List oldList, Map oldMap) { Order ord = newList[0]; if (ord.LiApprove__c == true && ord.If_Supervise__c == true) { ord.addError('批准需要取消\'临床标识\'的勾选。'); } } /** * [addressCopy description] * 收货地址拷文本 */ public static void addressCopy(List newList, Map newMap, List oldList, Map oldMap) { List IDList = new List(); for (Order ord : newList) { Order old = oldMap.get(ord.Id); if (old.SpecialDeliveryContact2_D__c != ord.SpecialDeliveryContact2_D__c) { ord.Shipping_Address_TextD__c = old.Shipping_Address_D__c; } if (old.SpecialDeliveryContact2__c != ord.SpecialDeliveryContact2__c) { //因在合同审批前 SpecialDeliveryContact2__c 为空 ,因此 old.Shipping_Address__c 为空 // ord.Shipping_Address_Text__c = old.Shipping_Address__c; //因在合同审批后 在更新前 SpecialDeliveryContact2__c 为空 ord.Shipping_Address__c 为空 // ord.Shipping_Address_Text__c = ord.Shipping_Address__c; // 因此,直接获取SpecialDeliveryContact2_D__c的地址,给 送货地址(文本) 赋值 // 20200918-XHL,合同审批后 送货地址(文本) 字段原名 收货地址(文本) 没有赋值成功,做出如下修改,上边为解释 ord.Shipping_Address_Text__c = ord.Shipping_Address_D__c; //送达方公司(公式) ==> 送达方公司(文本) // 20200918-XHL WLIG-BTGAPE Start ord.SpecialDeliveryAccountText__c = ord.SpecialDeliveryAccountFormula__c; //送达方联系人(公式) ==> 送达方联系人(文本) ord.SpecialDeliveryContactText__c = ord.SpecialDeliveryContactFormula__c; // 20200918-XHL WLIG-BTGAPE End } } } /** * [checkAdderss description] * 收货地址控制 */ public static void checkAdderss(List newList, Map newMap, List oldList, Map oldMap) { for (Order ord : newList) { Order old = oldMap.get(ord.Id); if (ord.Is_Already_Splited__c == true && ord.ProductSegment__c == 'BS' && ord.Opportunity != null && ord.ApproveStatus__c == 'OrderPass' && (ord.Shipping_Address__c != old.Shipping_Address__c || ord.Shipping_Address_D__c != old.Shipping_Address_D__c || ord.SpecialDeliveryAccount_D__c != old.SpecialDeliveryAccount_D__c || ord.SpecialDeliveryAccount__c != old.SpecialDeliveryAccount__c || ord.SpecialDeliveryContact2_D__c != old.SpecialDeliveryContact2_D__c || ord.SpecialDeliveryContact2__c != old.SpecialDeliveryContact2__c)) { Opportunity oppor = [select id, AccountId, Dealer__r.DummyDealer__c, Dealer__r.ParentID, Account.MarketVerticals__c, Trade_Type_D__c from Opportunity where id = :ord.OpportunityId]; if (oppor.Account.MarketVerticals__c == 'Clinical' && oppor.Trade_Type_D__c == 'Taxation' ) { ord.addError('内贸医疗订单批准后拆分,不能修收货地址'); } } } } /** * [check description] * LS内贸医疗合同证照检查,OSSA辐射产品检查,产品首营状态检查 */ public static void check(List newList, Map newMap, List oldList, Map oldMap) { String oppId = newList[0].OpportunityId; Date endDate = Date.valueOf('2019-12-28'); String stri = ''; if (newList[0].ProductSegment__c == 'BS' && (newList[0].ApproveStatus__c == 'Draft' || newList[0].ApproveStatus__c == 'Reject' || newList[0].ApproveStatus__c == 'OrderDraft' || newList[0].ApproveStatus__c == 'OrderReject' )) { Opportunity oppor = [select id, AccountId, Dealer__r.DummyDealer__c, Dealer__r.ParentID, Account.MarketVerticals__c, Trade_Type_D__c from Opportunity where id = :oppId]; if (oppor.Account.MarketVerticals__c == 'Clinical' && oppor.Trade_Type_D__c == 'Taxation' && (newList[0].date_P__c > endDate || newList[0].date_P__c == null)) { newList[0].If_Supervise__c = true; if (oppor.Dealer__r.DummyDealer__c == true) { newList[0].check__c = LicenseCheckUtil.LicenseCheck(oppor.AccountId); } else { newList[0].check__c = LicenseCheckUtil.LicenseCheck(oppor.Dealer__r.ParentID); //newList[0].addCheck__c = LicenseCheckUtil.AddressCheck(oppor.Dealer__r.ParentID,newList[0].Shipping_Address_D__c) == true ? '1' : '0'; } } else { system.debug('*()*'); } } if (newList[0].ProductSegment__c == 'ANI' || newList[0].ProductSegment__c == 'NDT') { List oliList = [select id, Product2.If_Exempt_Product__c, Product2.If_Radiation_Product__c, Opportunity.DealerId__c from OpportunityLineItem where opportunityId = :oppId]; Boolean hasA = false; for (OpportunityLineItem oli : oliList) { if (oli.Product2.If_Exempt_Product__c == false && oli.Product2.If_Radiation_Product__c == true) { hasA = true; } } if (hasA == true) { stri = LicenseCheckUtil.LicenseCheck1(oliList[0].Opportunity.DealerId__c); system.debug(stri); newList[0].check__c = (stri == '0' ? '1':stri); } if(Trigger.isInsert){ String result = ''; String olympusAccountId = System.label.Olympus_Id; Map getModelQuantityMap = RadiationUtil.GetOpportunityLineMap(oppId); if (newList[0].ProductSegment__c == 'ANI' && newList[0].TradeType__c == '内贸' ) { String errorStr = RadiationUtil.GetCertificationDetail(oliList[0].Opportunity.DealerId__c,getModelQuantityMap); if(errorStr != ''){ newList[0].addError(errorStr +'不能创建合同'); } //stri = LicenseCheckUtil.LicenseCheck1(oliList[0].Opportunity.DealerId__c); 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 == '' ? '' : '仪景通可销售数量不足') ; Boolean temp = accountDealerErrorMessage.startsWith('你不能'); String strOly = LicenseCheckUtil.LicenseCheckOly(); if(temp){ newList[0].addError('产品中包含不能销售的辐射产品系列' +'不能创建合同'); }else{ if(olympusDealerErrorMessage == '-1'){ newList[0].addError('产品中包含不能销售的辐射产品系列' +'不能创建合同'); }else if(olympusDealerErrorMessage != ''){ newList[0].addError(olympusDealerErrorMessage +'不能创建合同'); } if(stri == '1'){ if(accountDealerErrorMessage != '' && strOly == '1'){ newList[0].addError(accountDealerErrorMessage +'不能创建合同'); }else if(accountDealerErrorMessage != '' && strOly == '0'){ newList[0].check__c = accountDealerErrorMessage; } } } } } } if (Trigger.isInsert) { List qliList = [select id, Product2.NMPAStatus__c, Product2.ProductCode ,oppLiVerifyProductValid__c from OpportunityLineItem where opportunityId = :oppId]; String str = ''; Boolean isok = true; for (OpportunityLineItem qli : qliList) { // WLIG-BTA8C2 XHL 20200925 -Start // 合同变更 并且 询价产品的 验证产品有效性 为 false 时跳过验证 if (newList[0].OrderIsChange__c && qli.oppLiVerifyProductValid__c == false) { // WLIG-BTA8C2 XHL 20200925 -End } else { if (qli.Product2.NMPAStatus__c == '首营状态变更' || qli.Product2.NMPAStatus__c == '首营不通过') { str += (' ' + qli.Product2.ProductCode); isok = false; } } } if (isok == false) { newList[0].addError(str + '首营未通过'); } } } public static void setIsNew(List newList, Map newMap, List oldList, Map oldMap) { List oppidList = new List(); for (Order newOrd : newList) { /* if(newOrd.SubDealer__c == '无'){ newOrd.SubDealer__c = ''; }*/ oppIdList.add(newOrd.OpportunityId); /*if (String.isNotBlank(newOrd.org_order__c)) { newOrd.SharedFlag__c = false; }*/ } List orderCnt = [select Count(Id) ocnt, OpportunityId from Order where OpportunityId = :oppIdList and Status__c = 'Active' group by OpportunityId]; Map orderCntMap = new Map(); for (AggregateResult temp : orderCnt) { orderCntMap.put((String) temp.get('OpportunityId'), (Integer) temp.get('ocnt')); } // String profileId = UserInfo.getProfileId().substring(0, 15); //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 //String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); for (Order newOrd : newList) { if (new_profileId <> System.Label.SystemAdmin && new_profileId <> System.Label.SystemAdmin2 && orderCntMap.containsKey(newOrd.OpportunityId) == true && orderCntMap.get(newOrd.OpportunityId) > 0) { newOrd.addError('存在有效合同,不能创建创新合同!'); } } //王鹏伟 新建和同时,和询价对比客户、最终用户 //戴宇,添加合同关联逻辑 List oppList = [select id,Association_Opportunity__c,CrossCooperativeProject__c,HeadOfCooperationArea__c,CrossCooperativeDealer__r.ManagementCode_F__c,CrossCooperativeDealer__r.Name,SyncedQuoteId, SyncedQuote.PaymentTerms__c, TradeType__c, Quote_PaymentTerms__c,AccountId,customerType__c,useing__c,compo_opp__c from Opportunity where id = :oppidList]; Map syncedQuoteIdMap = new Map(); Map paymentTermsMap = new Map(); Map tradeTypeMap = new Map(); Map oppAccountMap = new Map(); Map oppMap = new Map(); for (Opportunity opp : oppList) { syncedQuoteIdMap.put(opp.id, opp.SyncedQuoteId); //paymentTermsMap.put(opp.id, opp.SyncedQuote.PaymentTerms__c); paymentTermsMap.put(opp.Id, opp.Quote_PaymentTerms__c); system.debug('paymentTermsMap:' + paymentTermsMap); tradeTypeMap.put(opp.id, opp.TradeType__c); oppAccountMap.put(opp.Id,opp.AccountId); oppMap.put(opp.Id,opp); } for (Order newOrd : newList) { if(newOrd.ProductSegment__c == 'IE' && newOrd.IE_SP8_D__c != oppMap.get(newOrd.OpportunityId).compo_opp__c){ newOrd.addError('不能修改特殊条件COMPO'); } /*if(newOrd.ProductSegment__c == 'BS'){ String temp = oppMap.get(newOrd.OpportunityId).useing__c; if(newOrd.SP_61D__c != (temp == ''?false:true)){ newOrd.addError('不能修改特殊条件 OEM 采购'); } }*/ if (OrderDivisionController.OrderDivision == true) { /* if (newOrd.ApproveStatus__c == 'Submit') { newOrd.ApproveStatus__c = 'Draft'; } else if (newOrd.ApproveStatus__c == 'OrderSubmit') { newOrd.ApproveStatus__c = 'OrderDraft'; } else { // 保持状态 }*/ // 保持状态 } else if (newOrd.IsCopy__c == true) { // 保持状态 } else if (newOrd.Order_IsSpecial__c == true || newOrd.Order_IsSpecial_Service__c == true) { newOrd.ApproveStatus__c = 'Draft'; newOrd.date_P__c = null; } else { newOrd.ApproveStatus__c = 'OrderDraft'; newOrd.date_P__c = null; } newOrd.CrossCooperativeProject__c = oppMap.get(newOrd.OpportunityId) == null ? false :oppMap.get(newOrd.OpportunityId).CrossCooperativeProject__c; newOrd.SP_901D__c = oppMap.get(newOrd.OpportunityId) == null ? false :oppMap.get(newOrd.OpportunityId).CrossCooperativeProject__c; newOrd.CrossCooperativeDealerCode__c = oppMap.get(newOrd.OpportunityId) == null ? '' :oppMap.get(newOrd.OpportunityId).CrossCooperativeDealer__r.ManagementCode_F__c; newOrd.HeadOfCooperationArea__c = oppMap.get(newOrd.OpportunityId) == null ? null :oppMap.get(newOrd.OpportunityId).HeadOfCooperationArea__c; newOrd.CrossCooperativeDealerText__c = oppMap.get(newOrd.OpportunityId) == null ? null :oppMap.get(newOrd.OpportunityId).CrossCooperativeDealer__r.Name; //王鹏伟新加,合同中带入 询价 贸易管理客户分类 开始 newOrd.TradeMagCategory__c = oppMap.get(newOrd.OpportunityId) == null ? '' :oppMap.get(newOrd.OpportunityId).customerType__c; //王鹏伟新加,合同中带入 询价 贸易管理客户分类 结束 newOrd.IsNew__c = true; newOrd.QuoteId = syncedQuoteIdMap.get(newOrd.OpportunityId); newOrd.PaymentTerms__c = paymentTermsMap.get(newOrd.OpportunityId); newOrd.Status__c = 'Active'; //IE,只有compo被选中,则不需要审批 gwy 2021-06-02 if(newOrd.ProductSegment__c=='IE' && newOrd.Status__c == 'Active' && newOrd.OrderDraft__c == false && newOrd.IE_SP5_D__c == false && newOrd.IE_SP6_D__c == false && newOrd.IE_SP7_D__c == false && newOrd.IE_SP8_D__c == true){ newOrd.ApproveStatus__c = 'Pass'; newOrd.IsSpPassed__c = true; newOrd.IE_SP8__c = true; } //IE,只有compo被选中,则不需要审批 gwy 2021-06-02 boolean individualCase = newOrd.RecordTypeId == System.Label.RT_Contract_IndividualCase_ANI || newOrd.RecordTypeId == System.Label.RT_Contract_IndividualCase_BS || newOrd.RecordTypeId == System.Label.RT_Contract_IndividualCase_IE || newOrd.RecordTypeId == System.Label.RT_Contract_IndividualCase_NDT || newOrd.RecordTypeId == System.Label.RT_Contract_IndividualCase_RVI; if (UserInfo.getUserType() == 'PowerPartner' || newOrd.RecordTypeId == System.Label.RT_ServiceContract || newOrd.RecordTypeId == System.Label.RT_ServiceContractIE || newOrd.RecordTypeId == System.Label.RT_ServiceContractRVI || individualCase) { // 外贸送达方默认为外贸公司 if (tradeTypeMap.get(newOrd.OpportunityId) == System.Label.Trade_Type) { newOrd.SpecialDeliveryAccount_D__c = newOrd.ForeignTradeCompany_D__c; } } else { newOrd.SP_11D__c = newOrd.SP_11__c; newOrd.SP_901D__c = newOrd.SP_901__c; newOrd.SP_101D__c = newOrd.SP_101__c; newOrd.SP_102D__c = newOrd.SP_102__c; newOrd.SP_103D__c = newOrd.SP_103__c; newOrd.SP_106D__c = newOrd.SP_106__c; newOrd.SP_107D__c = newOrd.SP_107__c; newOrd.Theoinp_D__c = newOrd.Theoinp__c; newOrd.SP_745D__c = newOrd.SP_745__c; newOrd.SP_111D__c = newOrd.SP_111__c; newOrd.SP_121D__c = newOrd.SP_121__c; newOrd.SP_131D__c = newOrd.SP_131__c; newOrd.SP_141D__c = newOrd.SP_141__c; newOrd.SP_151D__c = newOrd.SP_151__c; newOrd.SP_161D__c = newOrd.SP_161__c; newOrd.SP_171D__c = newOrd.SP_171__c; newOrd.SP_181D__c = newOrd.SP_181__c; newOrd.SP_191D__c = newOrd.SP_191__c; newOrd.SP_201D__c = newOrd.SP_201__c; newOrd.SP_202D__c = newOrd.SP_202__c; newOrd.SP_21D__c = newOrd.SP_21__c; newOrd.SP_22D__c = newOrd.SP_22__c; newOrd.SP_31D__c = newOrd.SP_31__c; newOrd.SP_32D__c = newOrd.SP_32__c; newOrd.SP_33D__c = newOrd.SP_33__c; newOrd.SP_41D__c = newOrd.SP_41__c; newOrd.SP_51D__c = newOrd.SP_51__c; newOrd.SP_52D__c = newOrd.SP_52__c; newOrd.SP_61D__c = newOrd.SP_61__c; newOrd.SP_62D__c = newOrd.SP_62__c; newOrd.SP_71D__c = newOrd.SP_71__c; newOrd.SP_81D__c = newOrd.SP_81__c; newOrd.SP_91D__c = newOrd.SP_91__c; //newOrd.ConditionContract_D__c = newOrd.ConditionContract__c; newOrd.Contract_StatusD__c = newOrd.Contract_Status__c; newOrd.CustomerContractPriceD__c = newOrd.CustomerContractPrice__c; //newOrd.EffectiveDateD__c = newOrd.EffectiveDate; newOrd.OlympusContractPricesD__c = newOrd.OlympusContractPrices__c; newOrd.EndUserD__c = newOrd.EndUser__c; newOrd.IE_SP1_D__c = newOrd.IE_SP1__c; newOrd.IE_SP2_D__c = newOrd.IE_SP2__c; newOrd.IE_SP3_D__c = newOrd.IE_SP3__c; newOrd.IE_SP4_D__c = newOrd.IE_SP4__c; newOrd.IE_SP5_D__c = newOrd.IE_SP5__c; newOrd.IE_SP6_D__c = newOrd.IE_SP6__c; newOrd.IE_SP7_D__c = newOrd.IE_SP7__c; newOrd.IE_SP8_D__c = newOrd.IE_SP8__c; newOrd.RVI_SP1_D__c = newOrd.RVI_SP1__c; newOrd.RVI_SP2_D__c = newOrd.RVI_SP2__c; newOrd.RVI_SP3_D__c = newOrd.RVI_SP3__c; newOrd.RVI_SP4_D__c = newOrd.RVI_SP4__c; newOrd.RVI_SP5_D__c = newOrd.RVI_SP5__c; newOrd.RVI_SP6_D__c = newOrd.RVI_SP6__c; newOrd.NDT_SP1_D__c = newOrd.NDT_SP1__c; newOrd.NDT_SP2_D__c = newOrd.NDT_SP2__c; newOrd.NDT_SP3_D__c = newOrd.NDT_SP3__c; newOrd.NDT_SP4_D__c = newOrd.NDT_SP4__c; newOrd.NDT_SP5_D__c = newOrd.NDT_SP5__c; newOrd.NDT_SP6_D__c = newOrd.NDT_SP6__c; newOrd.NDT_SP7_D__c = newOrd.NDT_SP7__c; newOrd.NDT_SP8_D__c = newOrd.NDT_SP8__c; newOrd.NDT_SP9_D__c = newOrd.NDT_SP9__c; newOrd.NDT_SP10_D__c = newOrd.NDT_SP10__c; newOrd.NDT_SP11_D__c = newOrd.NDT_SP11__c; newOrd.ANI_SP1_D__c = newOrd.ANI_SP1__c; newOrd.ANI_SP2_D__c = newOrd.ANI_SP2__c; newOrd.ANI_SP3_D__c = newOrd.ANI_SP3__c; newOrd.ANI_SP4_D__c = newOrd.ANI_SP4__c; newOrd.ANI_SP5_D__c = newOrd.ANI_SP5__c; newOrd.ANI_SP6_D__c = newOrd.ANI_SP6__c; newOrd.NormalDis_SerContractCondition_D__c = newOrd.NormalDis_SerContractCondition__c; newOrd.HighDis_SerContractCondition_D__c = newOrd.HighDis_SerContractCondition__c; newOrd.SpecialDis_SerContractCondition_D__c = newOrd.SpecialDis_SerContractCondition__c; newOrd.Warranty_SerContractCondition_D__c = newOrd.Warranty_SerContractCondition__c; newOrd.Discount_D__c = newOrd.Discount__c; newOrd.Olympus_Price_BeforeDiscount_D__c = newOrd.Olympus_Price_BeforeDiscount__c; newOrd.PaymentCondition_D__c = newOrd.PaymentCondition__c; newOrd.SpecialDelivery_D__c = newOrd.SpecialDelivery__c; newOrd.SpecialDeliveryContact_D__c = newOrd.SpecialDeliveryContact__c; newOrd.SpecialDeliveryPhone_D__c = newOrd.SpecialDeliveryPhone__c; newOrd.SpecialDeliveryAddress_D__c = newOrd.SpecialDeliveryAddress__c; newOrd.SpecialParkage_D__c = newOrd.SpecialParkage__c; newOrd.SpecialWarranty_D__c = newOrd.SpecialWarranty__c; newOrd.DealerProfit_D__c = newOrd.DealerProfit__c; newOrd.SpecialDelDate_D__c = newOrd.SpecialDelDate__c; newOrd.OtherApply_D__c = newOrd.OtherApply__c; newOrd.Andor_D__c = newOrd.Andor__c; newOrd.Bitplane_D__c = newOrd.Bitplane__c; newOrd.CoolLED_D__c = newOrd.CoolLED__c; newOrd.Lumen_D__c = newOrd.Lumen__c; newOrd.Lumenera_D__c = newOrd.Lumenera__c; newOrd.Media_Cybernetics_D__c = newOrd.Media_Cybernetics__c; newOrd.Narishige_D__c = newOrd.Narishige__c; newOrd.Newport_D__c = newOrd.Newport__c; newOrd.OSIS_Germany_D__c = newOrd.OSIS_Germany__c; newOrd.OSIS_Singapore_D__c = newOrd.OSIS_Singapore__c; newOrd.Photometrics_D__c = newOrd.Photometrics__c; newOrd.Prior_Scientific_D__c = newOrd.Prior_Scientific__c; newOrd.Q_Imaging_D__c = newOrd.Q_Imaging__c; newOrd.Tokai_Hit_D__c = newOrd.Tokai_Hit__c; newOrd.Other_Third_D__c = newOrd.Other_Third__c; newOrd.ServiceFee_D__c = newOrd.ServiceFee__c; newOrd.AlongProduct_D__c = newOrd.AlongProduct__c; newOrd.Cost_D__c = newOrd.Cost__c; newOrd.Cost_D__c = newOrd.Cost__c; newOrd.Sub_DealerC_D__c = newOrd.Sub_DealerC__c; newOrd.ForeignTradeCompany_D__c = newOrd.ForeignTradeCompany__c; // 外贸送达方默认为外贸公司 if (tradeTypeMap.get(newOrd.OpportunityId) == System.Label.Trade_Type) { newOrd.SpecialDeliveryAccount__c = newOrd.ForeignTradeCompany__c; } newOrd.SpecialDeliveryAccount_D__c = newOrd.SpecialDeliveryAccount__c; newOrd.SpecialDeliveryContact2_D__c = newOrd.SpecialDeliveryContact2__c; newOrd.Shipment_Term_D__c = newOrd.Shipment_Term__c; newOrd.Shipment_Term2_D__c = newOrd.Shipment_Term2__c; } } //王鹏伟 新建和同时,和询价对比客户、最终用户 //添加 开始 /* List role_list = new List(); role_list = [select Id,Role,IsPrimary,OpportunityId,ContactId from OpportunityContactRole where OpportunityId = :oppidList and Role = 'End user' and IsPrimary = true]; Map roleMap = new Map(); for(OpportunityContactRole oppor:role_list){ roleMap.put(oppor.OpportunityId,oppor.ContactId); } for(Order orOne:newList){ System.debug(oppAccountMap.get(orOne.OpportunityId)+'---'+orOne.AccountId); System.debug(roleMap.get(orOne.OpportunityId)+'---'+orOne.EndUserD__c); if (oppAccountMap.containsKey(orOne.OpportunityId)) { if(oppAccountMap.get(orOne.OpportunityId) != orOne.AccountId || !roleMap.containsKey(orOne.OpportunityId) || orOne.EndUserD__c != roleMap.get(orOne.OpportunityId)){ orOne.addError('客户名或最终用户与询价不一致!'); } } } */ //王鹏伟添加 结束 } public static void setPriceBook(List newList, Map newMap, List oldList, Map oldMap) { List oppidList = new List(); for (Order o : newList) { oppidList.add(o.OpportunityId); } List oppList = [select Id, Pricebook2Id from Opportunity where Id = :oppidList]; Map pricebookMap = new Map(); for (Opportunity opp : oppList) { pricebookMap.put(opp.Id, opp.Pricebook2Id); } for (Order o : newList) { o.Pricebook2Id = pricebookMap.get(o.OpportunityId); } } public static void addItem(List newList, Map newMap, List oldList, Map oldMap) { List oppidList = new List(); // Map order2oppMap = new Map(); Boolean hasBS = false; for (Order o : newList) { oppidList.add(o.OpportunityId); // order2oppMap.put(o.Id, o.OpportunityId); } // XHL20210830 List oppTM = new List(); // 查找询价下询价团队,用户必须有效 oppTM = [select userId,opportunityId,user.IsActive,opportunity.OwnerId from OpportunityTeamMember where user.IsActive = true AND opportunityId In :oppidList]; if(oppTM.size() >0){ Map> orderShareMap = new Map>(); for (Order newOrd : newList) { for (OpportunityTeamMember otm : oppTM) { // 排除 客户团队用户 是 合同所有人 // 排除 客户团队用户 是 询价所有人 if(otm.OpportunityId == newOrd.OpportunityId && otm.userId != newOrd.OwnerId){ Map shareMap = new Map(); if (orderShareMap.containsKey(newOrd.Id)) { shareMap = orderShareMap.get(newOrd.Id); } shareMap.put(otm.UserId,DataAssembly(newOrd.Id,otm.UserId)); //排除 合同所有人 与 询价所有人 相同 if (newOrd.OwnerId != otm.opportunity.OwnerId) { shareMap.put(otm.opportunity.OwnerId,DataAssembly(newOrd.Id,otm.opportunity.OwnerId)); } orderShareMap.put(newOrd.Id,shareMap); } } } if (orderShareMap.size() > 0 ) { List shareList = new List(); for (Id orderId :orderShareMap.keySet()) { Map shareMap = orderShareMap.get(orderId); for (Id userId: shareMap.keySet()) { shareList.add(shareMap.get(userId)); } } if (shareList.size() > 0) { insert shareList; } } } /* List oppTM = new List(); oppTM = [select userId,opportunityId,user.IsActive from OpportunityTeamMember where opportunityId = :oppidList]; if(oppTM.size() >0){ List shareList = new List(); for (Order newOrd : newList) { for (OpportunityTeamMember otm : oppTM) { if(otm.OpportunityId == newOrd.OpportunityId && otm.User.IsActive == true){ system.debug(newOrd.Id); System.debug(otm.UserId); OrderShare aos = new OrderShare( RowCause = 'Manual', orderId = newOrd.Id, UserOrGroupId = otm.UserId, OrderAccessLevel = 'Edit'); shareList.add(aos); } } } System.debug(shareList); insert shareList; }*/ List quoidList = new List(); Map opp2quoMap = new Map(); List oppList = [select Id, SyncedQuoteId,Association_Opportunity__c from Opportunity where Id = :oppidList]; /* List dqpList = new List(); dqpList = [select id from DecideQuoteProductSet__c where DecideOpportunity__c in :oppIdList]; */ Map associationMap = new Map(); for (Opportunity opp : oppList) { if (opp.SyncedQuoteId != null) { quoidList.add(opp.SyncedQuoteId); opp2quoMap.put(opp.Id, opp.SyncedQuoteId); } if(opp.Association_Opportunity__c != null){ associationMap.put(opp.Id,opp.Association_Opportunity__c); } } List updateOrderList = new List(); if(associationMap.size() > 0){ List ordList = new List(); ordList = [select id,Association_Order__c,OpportunityId from Order where OpportunityId in : associationMap.values() and Status__c = 'Active']; if(ordList.size() > 0){ for(Order neword : newList){ if(associationMap.containsKey(neword.OpportunityId)){ for(Order o : ordList){ if(o.OpportunityId == associationMap.get(neword.OpportunityId)){ Order neworder = new Order(); neworder.Id = neword.Id; neworder.Association_Order__c = o.Id; //neword.Association_Order__c = o.Id; Order order = new Order(); order.Id = o.Id; order.Association_Order__c = neword.Id; updateOrderList.add(order); updateOrderList.add(neworder); } } } } } } List oliList = [select Id, OpportunityId, Description, Quantity, ProductSegment__c, PricebookEntryId, PricebookEntry.CostPrice__c, UnitPrice from OpportunityLineItem where OpportunityId = :oppidList order by OpportunityId,Id]; Map> oliMap = new Map>(); String pre_oppid = ''; List tmpList = null; for (OpportunityLineItem oli : oliList) { if (oli.ProductSegment__c == 'BS') { hasBS = true; } if (pre_oppid == '' || oli.OpportunityId != pre_oppid) { //syetem.debug('=====new list : key = ' + oli.OpportunityId);52200 tmpList = new List(); oliMap.put(oli.OpportunityId, tmpList); tmpList.add(oli); pre_oppid = oli.OpportunityId; } else { tmpList.add(oli); //syetem.debug('=====list : ' + tmpList); } // tmpList = new List(); // if (oliMap.containsKey(oli.OpportunityId)) { // oliMap.get(oli.OpportunityId).add(oli); // } else { // oliMap.put(oli.OpportunityId, tmpList); // oliMap.get(oli.OpportunityId).add(oli); // } } //syetem.debug('=====oliMap : ' + oliMap); Map> qliMap = new Map>(); String pre_quoid = ''; List tmpList2 = null; Map> dqpMap = new Map>(); if (hasBS) { List qliList = [select Id, QuoteId, Description, Quantity, PricebookEntryId, PricebookEntry.CostPrice__c, UnitPrice from QuoteLineItem where QuoteId = :quoidList order by QuoteId,Id]; for (QuoteLineItem qli : qliList) { if (pre_quoid == '' || qli.QuoteId != pre_quoid) { //syetem.debug('=====new list : key = ' + qli.QuoteId); tmpList2 = new List(); qliMap.put(qli.QuoteId, tmpList2); tmpList2.add(qli); pre_quoid = qli.QuoteId; } else { tmpList2.add(qli); //syetem.debug('=====list : ' + tmpList2); } } //syetem.debug('=====qliMap : ' + qliMap); List dqpList = new List(); dqpList = [select id, DecideOpportunity__c from DecideQuoteProductSet__c where DecideOpportunity__c in :oppIdList]; for (DecideQuoteProductSet__c dqp : dqpList) { if (dqpMap.containsKey(dqp.DecideOpportunity__c)) { dqpMap.get(dqp.DecideOpportunity__c).add(dqp); } else { dqpMap.put(dqp.DecideOpportunity__c, new List()); dqpMap.get(dqp.DecideOpportunity__c).add(dqp); } } } /*if(hasBS){ List dqpList = new List(); dqpList = [select id,DecideOpportunity__c from DecideQuoteProductSet__c where DecideOpportunity__c in :oppIdList]; for(DecideQuoteProductSet__c dqp : dqpList){ dqpMap.put(dqp.DecideOpportunity__c, dqp); } }*/ List insList = new List(); List updateList = new List(); for (Order o : newList) { if (qliMap.containsKey(opp2quoMap.get(o.OpportunityId)) == true) { for (QuoteLineItem qli : qliMap.get(opp2quoMap.get(o.OpportunityId))) { OrderItem oi = new OrderItem(); oi.Description = qli.Description; oi.Quantity = qli.Quantity; oi.PricebookEntryId = qli.PricebookEntryId; oi.UnitPrice = qli.UnitPrice; oi.OrderId = o.Id; oi.QuoteLineItemId = qli.Id; oi.TotalCostPrice_Text__c = qli.PricebookEntry.CostPrice__c * qli.Quantity; insList.add(oi); } } else { if (oliMap.get(o.OpportunityId) != null) { for (OpportunityLineItem oli : oliMap.get(o.OpportunityId)) { OrderItem oi = new OrderItem(); oi.Description = oli.Description; oi.Quantity = oli.Quantity; oi.PricebookEntryId = oli.PricebookEntryId; oi.UnitPrice = oli.UnitPrice; oi.OrderId = o.Id; oi.TotalCostPrice_Text__c = oli.PricebookEntry.CostPrice__c * oli.Quantity; insList.add(oi); } } } if (dqpMap.size() > 0 && dqpMap.containsKey(o.OpportunityId)) { // DecideQuoteProductSet__c temp = dqpMap.get(o.OpportunityId); for (DecideQuoteProductSet__c temp : dqpMap.get(o.OpportunityId)) { temp.DecideOrder__c = o.id; } updateList.addAll(dqpMap.get(o.OpportunityId)); } } if (insList.size() > 0) insert insList; if (updateList.size() > 0) update updateList; if (updateOrderList.size() > 0) update updateOrderList; } public static void updateForDealer(List newList, Map newMap, List oldList, Map oldMap) { //for循环里有用到获取简档信息,新的获取简档有SQOL 放到for循环外面 //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 //String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); for (Order newOrd : newList) { Order oldOrd = oldMap.get(newOrd.Id); /* if(newOrd.SubDealer__c == '无'){ newOrd.SubDealer__c = ''; }*/ // if (oldOrd.ShippedDate__c != null && oldOrd.ShippedDate__c != newOrd.ShippedDate__c) { // newOrd.addError('出货日期填写后不能修改。'); // } system.debug('=====' + newOrd.SP_11D__c + '|' + oldOrd.SP_11D__c); system.debug('=====' + newOrd.SP_101D__c + '|' + oldOrd.SP_101D__c); system.debug('=====' + newOrd.SP_102D__c + '|' + oldOrd.SP_102D__c); system.debug('=====' + newOrd.SP_103D__c + '|' + oldOrd.SP_103D__c); system.debug('=====' + newOrd.SP_106D__c + '|' + oldOrd.SP_106D__c); system.debug('=====' + newOrd.SP_107D__c + '|' + oldOrd.SP_107D__c); system.debug('=====' + newOrd.Theoinp_D__c + '|' + oldOrd.Theoinp_D__c); system.debug('=====' + newOrd.SP_745D__c + '|' + oldOrd.SP_745D__c); system.debug('=====' + newOrd.SP_111D__c + '|' + oldOrd.SP_111D__c); system.debug('=====' + newOrd.SP_121D__c + '|' + oldOrd.SP_121D__c); system.debug('=====' + newOrd.SP_131D__c + '|' + oldOrd.SP_131D__c); system.debug('=====' + newOrd.SP_141D__c + '|' + oldOrd.SP_141D__c); system.debug('=====' + newOrd.SP_151D__c + '|' + oldOrd.SP_151D__c); system.debug('=====' + newOrd.SP_161D__c + '|' + oldOrd.SP_161D__c); system.debug('=====' + newOrd.SP_171D__c + '|' + oldOrd.SP_171D__c); system.debug('=====' + newOrd.SP_181D__c + '|' + oldOrd.SP_181D__c); system.debug('=====' + newOrd.SP_191D__c + '|' + oldOrd.SP_191D__c); system.debug('=====' + newOrd.SP_201D__c + '|' + oldOrd.SP_201D__c); system.debug('=====' + newOrd.SP_202D__c + '|' + oldOrd.SP_202D__c); system.debug('=====' + newOrd.SP_21D__c + '|' + oldOrd.SP_21D__c); system.debug('=====' + newOrd.SP_22D__c + '|' + oldOrd.SP_22D__c); system.debug('=====' + newOrd.SP_31D__c + '|' + oldOrd.SP_31D__c); system.debug('=====' + newOrd.SP_32D__c + '|' + oldOrd.SP_32D__c); system.debug('=====' + newOrd.SP_33D__c + '|' + oldOrd.SP_33D__c); system.debug('=====' + newOrd.SP_41D__c + '|' + oldOrd.SP_41D__c); system.debug('=====' + newOrd.SP_51D__c + '|' + oldOrd.SP_51D__c); system.debug('=====' + newOrd.SP_52D__c + '|' + oldOrd.SP_52D__c); system.debug('=====' + newOrd.SP_61D__c + '|' + oldOrd.SP_61D__c); system.debug('=====' + newOrd.SP_62D__c + '|' + oldOrd.SP_62D__c); system.debug('=====' + newOrd.SP_71D__c + '|' + oldOrd.SP_71D__c); system.debug('=====' + newOrd.SP_81D__c + '|' + oldOrd.SP_81D__c); system.debug('=====' + newOrd.SP_91D__c + '|' + oldOrd.SP_91D__c); system.debug('=====' + newOrd.IE_SP1_D__c + '|' + oldOrd.IE_SP1_D__c); system.debug('=====' + newOrd.IE_SP2_D__c + '|' + oldOrd.IE_SP2_D__c); system.debug('=====' + newOrd.IE_SP3_D__c + '|' + oldOrd.IE_SP3_D__c); system.debug('=====' + newOrd.IE_SP4_D__c + '|' + oldOrd.IE_SP4_D__c); system.debug('=====' + newOrd.IE_SP5_D__c + '|' + oldOrd.IE_SP5_D__c); system.debug('=====' + newOrd.IE_SP6_D__c + '|' + oldOrd.IE_SP6_D__c); system.debug('=====' + newOrd.IE_SP7_D__c + '|' + oldOrd.IE_SP7_D__c); system.debug('=====' + newOrd.IE_SP8_D__c + '|' + oldOrd.IE_SP8_D__c); system.debug('=====' + newOrd.RVI_SP1_D__c + '|' + oldOrd.RVI_SP1_D__c); system.debug('=====' + newOrd.RVI_SP2_D__c + '|' + oldOrd.RVI_SP2_D__c); system.debug('=====' + newOrd.RVI_SP3_D__c + '|' + oldOrd.RVI_SP3_D__c); system.debug('=====' + newOrd.RVI_SP4_D__c + '|' + oldOrd.RVI_SP4_D__c); system.debug('=====' + newOrd.RVI_SP5_D__c + '|' + oldOrd.RVI_SP5_D__c); system.debug('=====' + newOrd.RVI_SP6_D__c + '|' + oldOrd.RVI_SP6_D__c); system.debug('=====' + newOrd.NDT_SP1_D__c + '|' + oldOrd.NDT_SP1_D__c); system.debug('=====' + newOrd.NDT_SP2_D__c + '|' + oldOrd.NDT_SP2_D__c); system.debug('=====' + newOrd.NDT_SP3_D__c + '|' + oldOrd.NDT_SP3_D__c); system.debug('=====' + newOrd.NDT_SP4_D__c + '|' + oldOrd.NDT_SP4_D__c); system.debug('=====' + newOrd.NDT_SP5_D__c + '|' + oldOrd.NDT_SP5_D__c); system.debug('=====' + newOrd.NDT_SP6_D__c + '|' + oldOrd.NDT_SP6_D__c); system.debug('=====' + newOrd.NDT_SP7_D__c + '|' + oldOrd.NDT_SP7_D__c); system.debug('=====' + newOrd.NDT_SP8_D__c + '|' + oldOrd.NDT_SP8_D__c); system.debug('=====' + newOrd.NDT_SP9_D__c + '|' + oldOrd.NDT_SP9_D__c); system.debug('=====' + newOrd.NDT_SP10_D__c + '|' + oldOrd.NDT_SP10_D__c); system.debug('=====' + newOrd.NDT_SP11_D__c + '|' + oldOrd.NDT_SP11_D__c); system.debug('=====' + newOrd.ANI_SP1_D__c + '|' + oldOrd.ANI_SP1_D__c); system.debug('=====' + newOrd.ANI_SP2_D__c + '|' + oldOrd.ANI_SP2_D__c); system.debug('=====' + newOrd.ANI_SP3_D__c + '|' + oldOrd.ANI_SP3_D__c); system.debug('=====' + newOrd.ANI_SP4_D__c + '|' + oldOrd.ANI_SP4_D__c); system.debug('=====' + newOrd.ANI_SP5_D__c + '|' + oldOrd.ANI_SP5_D__c); system.debug('=====' + newOrd.ANI_SP6_D__c + '|' + oldOrd.ANI_SP6_D__c); system.debug('=====' + newOrd.Discount_D__c + '|' + oldOrd.Discount_D__c); system.debug('=====' + newOrd.Olympus_Price_BeforeDiscount_D__c + '|' + oldOrd.Olympus_Price_BeforeDiscount_D__c); system.debug('=====' + newOrd.PaymentCondition_D__c + '|' + oldOrd.PaymentCondition_D__c); system.debug('=====' + newOrd.SpecialDelivery_D__c + '|' + oldOrd.SpecialDelivery_D__c); system.debug('=====' + newOrd.SpecialDeliveryContact_D__c + '|' + oldOrd.SpecialDeliveryContact_D__c); system.debug('=====' + newOrd.SpecialDeliveryPhone_D__c + '|' + oldOrd.SpecialDeliveryPhone_D__c); system.debug('=====' + newOrd.SpecialDeliveryAddress_D__c + '|' + oldOrd.SpecialDeliveryAddress_D__c); system.debug('=====' + newOrd.SpecialParkage_D__c + '|' + oldOrd.SpecialParkage_D__c); system.debug('=====' + newOrd.SpecialWarranty_D__c + '|' + oldOrd.SpecialWarranty_D__c); system.debug('=====' + newOrd.DealerProfit_D__c + '|' + oldOrd.DealerProfit_D__c); system.debug('=====' + newOrd.SpecialDelDate_D__c + '|' + oldOrd.SpecialDelDate_D__c); system.debug('=====' + newOrd.OtherApply_D__c + '|' + oldOrd.OtherApply_D__c); system.debug('=====' + newOrd.NormalDis_SerContractCondition_D__c + '|' + oldOrd.NormalDis_SerContractCondition_D__c); system.debug('=====' + newOrd.HighDis_SerContractCondition_D__c + '|' + oldOrd.HighDis_SerContractCondition_D__c); system.debug('=====' + newOrd.SpecialDis_SerContractCondition_D__c + '|' + oldOrd.SpecialDis_SerContractCondition_D__c); system.debug('=====' + newOrd.Warranty_SerContractCondition_D__c + '|' + oldOrd.Warranty_SerContractCondition_D__c); boolean sp_change = newOrd.SP_11D__c != oldOrd.SP_11D__c || newOrd.SP_901D__c != oldOrd.SP_901D__c || newOrd.SP_101D__c != oldOrd.SP_101D__c || newOrd.SP_102D__c != oldOrd.SP_102D__c || newOrd.SP_103D__c != oldOrd.SP_103D__c || newOrd.SP_106D__c != oldOrd.SP_106D__c || newOrd.SP_107D__c != oldOrd.SP_107D__c || newOrd.SP_745D__c != oldOrd.SP_745D__c || newOrd.SP_111D__c != oldOrd.SP_111D__c || newOrd.SP_121D__c != oldOrd.SP_121D__c || newOrd.SP_131D__c != oldOrd.SP_131D__c || newOrd.SP_141D__c != oldOrd.SP_141D__c || newOrd.SP_151D__c != oldOrd.SP_151D__c || newOrd.SP_161D__c != oldOrd.SP_161D__c || newOrd.SP_171D__c != oldOrd.SP_171D__c || newOrd.SP_181D__c != oldOrd.SP_181D__c || newOrd.SP_191D__c != oldOrd.SP_191D__c || newOrd.SP_201D__c != oldOrd.SP_201D__c || newOrd.SP_202D__c != oldOrd.SP_202D__c || newOrd.SP_21D__c != oldOrd.SP_21D__c || newOrd.SP_22D__c != oldOrd.SP_22D__c || newOrd.SP_31D__c != oldOrd.SP_31D__c || newOrd.SP_32D__c != oldOrd.SP_32D__c || newOrd.SP_33D__c != oldOrd.SP_33D__c || newOrd.SP_41D__c != oldOrd.SP_41D__c || newOrd.SP_51D__c != oldOrd.SP_51D__c || newOrd.SP_52D__c != oldOrd.SP_52D__c || newOrd.SP_61D__c != oldOrd.SP_61D__c || newOrd.SP_62D__c != oldOrd.SP_62D__c || newOrd.SP_71D__c != oldOrd.SP_71D__c || newOrd.SP_81D__c != oldOrd.SP_81D__c || newOrd.SP_91D__c != oldOrd.SP_91D__c || newOrd.Theoinp_D__c != oldOrd.Theoinp_D__c || newOrd.IE_SP1_D__c != oldOrd.IE_SP1_D__c || newOrd.IE_SP2_D__c != oldOrd.IE_SP2_D__c || newOrd.IE_SP3_D__c != oldOrd.IE_SP3_D__c || newOrd.IE_SP4_D__c != oldOrd.IE_SP4_D__c || newOrd.IE_SP5_D__c != oldOrd.IE_SP5_D__c || newOrd.IE_SP6_D__c != oldOrd.IE_SP6_D__c || newOrd.IE_SP7_D__c != oldOrd.IE_SP7_D__c || newOrd.IE_SP8_D__c != oldOrd.IE_SP8_D__c || newOrd.RVI_SP1_D__c != oldOrd.RVI_SP1_D__c || newOrd.RVI_SP2_D__c != oldOrd.RVI_SP2_D__c || newOrd.RVI_SP3_D__c != oldOrd.RVI_SP3_D__c || newOrd.RVI_SP4_D__c != oldOrd.RVI_SP4_D__c || newOrd.RVI_SP5_D__c != oldOrd.RVI_SP5_D__c || newOrd.RVI_SP6_D__c != oldOrd.RVI_SP6_D__c || newOrd.NDT_SP1_D__c != oldOrd.NDT_SP1_D__c || newOrd.NDT_SP2_D__c != oldOrd.NDT_SP2_D__c || newOrd.NDT_SP3_D__c != oldOrd.NDT_SP3_D__c || newOrd.NDT_SP4_D__c != oldOrd.NDT_SP4_D__c || newOrd.NDT_SP5_D__c != oldOrd.NDT_SP5_D__c || newOrd.NDT_SP6_D__c != oldOrd.NDT_SP6_D__c || newOrd.NDT_SP7_D__c != oldOrd.NDT_SP7_D__c || newOrd.NDT_SP8_D__c != oldOrd.NDT_SP8_D__c || newOrd.NDT_SP9_D__c != oldOrd.NDT_SP9_D__c || newOrd.NDT_SP10_D__c != oldOrd.NDT_SP10_D__c || newOrd.NDT_SP11_D__c != oldOrd.NDT_SP11_D__c || newOrd.ANI_SP1_D__c != oldOrd.ANI_SP1_D__c || newOrd.ANI_SP2_D__c != oldOrd.ANI_SP2_D__c || newOrd.ANI_SP3_D__c != oldOrd.ANI_SP3_D__c || newOrd.ANI_SP4_D__c != oldOrd.ANI_SP4_D__c || newOrd.ANI_SP5_D__c != oldOrd.ANI_SP5_D__c || newOrd.ANI_SP6_D__c != oldOrd.ANI_SP6_D__c || (newOrd.Discount_D__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.Discount_D__c)).setScale(2).setScale(0)) != (oldOrd.Discount_D__c == null ? 0 : Decimal.valueOf(String.valueOf(oldOrd.Discount_D__c)).setScale(2).setScale(0)) || (newOrd.Olympus_Price_BeforeDiscount_D__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.Olympus_Price_BeforeDiscount_D__c)).setScale(2).setScale(0)) != (oldOrd.Olympus_Price_BeforeDiscount_D__c == null ? 0 : Decimal.valueOf(String.valueOf(oldOrd.Olympus_Price_BeforeDiscount_D__c)).setScale(2).setScale(0)) || newOrd.PaymentCondition_D__c != oldOrd.PaymentCondition_D__c || newOrd.SpecialDelivery_D__c != oldOrd.SpecialDelivery_D__c || newOrd.SpecialDeliveryContact_D__c != oldOrd.SpecialDeliveryContact_D__c || newOrd.SpecialDeliveryPhone_D__c != oldOrd.SpecialDeliveryPhone_D__c || newOrd.SpecialDeliveryAddress_D__c != oldOrd.SpecialDeliveryAddress_D__c || newOrd.SpecialParkage_D__c != oldOrd.SpecialParkage_D__c || newOrd.SpecialWarranty_D__c != oldOrd.SpecialWarranty_D__c || newOrd.DealerProfit_D__c != oldOrd.DealerProfit_D__c || newOrd.SpecialDelDate_D__c != oldOrd.SpecialDelDate_D__c || newOrd.OtherApply_D__c != oldOrd.OtherApply_D__c || newOrd.NormalDis_SerContractCondition_D__c != oldOrd.NormalDis_SerContractCondition_D__c || newOrd.HighDis_SerContractCondition_D__c != oldOrd.HighDis_SerContractCondition_D__c || newOrd.SpecialDis_SerContractCondition_D__c != oldOrd.SpecialDis_SerContractCondition_D__c || newOrd.Warranty_SerContractCondition_D__c != oldOrd.Warranty_SerContractCondition_D__c; system.debug('=====' + newOrd.CustomerContractPriceD__c + '|' + oldOrd.CustomerContractPriceD__c); system.debug('=====' + newOrd.OlympusContractPricesD__c + '|' + oldOrd.OlympusContractPricesD__c); system.debug('=====' + newOrd.EndUserD__c + '|' + oldOrd.EndUserD__c); system.debug('=====' + newOrd.IsUpload__c + '|' + oldOrd.IsUpload__c); system.debug('=====' + newOrd.Andor_D__c + '|' + oldOrd.Andor_D__c); system.debug('=====' + newOrd.Bitplane_D__c + '|' + oldOrd.Bitplane_D__c); system.debug('=====' + newOrd.CoolLED_D__c + '|' + oldOrd.CoolLED_D__c); system.debug('=====' + newOrd.Lumen_D__c + '|' + oldOrd.Lumen_D__c); system.debug('=====' + newOrd.Lumenera_D__c + '|' + oldOrd.Lumenera_D__c); system.debug('=====' + newOrd.Media_Cybernetics_D__c + '|' + oldOrd.Media_Cybernetics_D__c); system.debug('=====' + newOrd.Narishige_D__c + '|' + oldOrd.Narishige_D__c); system.debug('=====' + newOrd.Newport_D__c + '|' + oldOrd.Newport_D__c); system.debug('=====' + newOrd.OSIS_Germany_D__c + '|' + oldOrd.OSIS_Germany_D__c); system.debug('=====' + newOrd.OSIS_Singapore_D__c + '|' + oldOrd.OSIS_Singapore_D__c); system.debug('=====' + newOrd.Photometrics_D__c + '|' + oldOrd.Photometrics_D__c); system.debug('=====' + newOrd.Prior_Scientific_D__c + '|' + oldOrd.Prior_Scientific_D__c); system.debug('=====' + newOrd.Q_Imaging_D__c + '|' + oldOrd.Q_Imaging_D__c); system.debug('=====' + newOrd.Tokai_Hit_D__c + '|' + oldOrd.Tokai_Hit_D__c); system.debug('=====' + newOrd.Other_Third_D__c + '|' + oldOrd.Other_Third_D__c); system.debug('=====' + newOrd.ServiceFee_D__c + '|' + oldOrd.ServiceFee_D__c); system.debug('=====' + newOrd.AlongProduct_D__c + '|' + oldOrd.AlongProduct_D__c); system.debug('=====' + newOrd.Cost_D__c + '|' + oldOrd.Cost_D__c); system.debug('=====' + newOrd.ForeignTradeCompany_D__c + '|' + oldOrd.ForeignTradeCompany_D__c); system.debug('=====' + newOrd.SpecialDeliveryAccount_D__c + '|' + oldOrd.SpecialDeliveryAccount_D__c); system.debug('=====' + newOrd.SpecialDeliveryContact2_D__c + '|' + oldOrd.SpecialDeliveryContact2_D__c); system.debug('=====' + newOrd.Shipment_Term_D__c + '|' + oldOrd.Shipment_Term_D__c); system.debug('=====' + newOrd.Shipment_Term2_D__c + '|' + oldOrd.Shipment_Term2_D__c); system.debug('*************' + newOrd.IsUpload__c + '****' + oldOrd.IsUpload__c + '****' + newOrd.Is_Already_Splited__c + '****' + newOrd.ApproveStatus__c); system.debug('*************' + (newOrd.IsUpload__c != oldOrd.IsUpload__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true))); boolean contract_change = (newOrd.CustomerContractPriceD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.CustomerContractPriceD__c)).setScale(2).setScale(0)) != (oldOrd.CustomerContractPriceD__c == null ? 0 : Decimal.valueOf(String.valueOf(oldOrd.CustomerContractPriceD__c)).setScale(2).setScale(0)) || (newOrd.OlympusContractPricesD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.OlympusContractPricesD__c)).setScale(2).setScale(0)) != (oldOrd.OlympusContractPricesD__c == null ? 0 : Decimal.valueOf(String.valueOf(oldOrd.OlympusContractPricesD__c)).setScale(2).setScale(0)) || newOrd.EndUserD__c != oldOrd.EndUserD__c || (newOrd.IsUpload__c != oldOrd.IsUpload__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)) || newOrd.Andor_D__c != oldOrd.Andor_D__c || newOrd.Bitplane_D__c != oldOrd.Bitplane_D__c || newOrd.CoolLED_D__c != oldOrd.CoolLED_D__c || newOrd.Lumen_D__c != oldOrd.Lumen_D__c || newOrd.Lumenera_D__c != oldOrd.Lumenera_D__c || newOrd.Media_Cybernetics_D__c != oldOrd.Media_Cybernetics_D__c || newOrd.Narishige_D__c != oldOrd.Narishige_D__c || newOrd.Newport_D__c != oldOrd.Newport_D__c || newOrd.OSIS_Germany_D__c != oldOrd.OSIS_Germany_D__c || newOrd.OSIS_Singapore_D__c != oldOrd.OSIS_Singapore_D__c || newOrd.Photometrics_D__c != oldOrd.Photometrics_D__c || newOrd.Prior_Scientific_D__c != oldOrd.Prior_Scientific_D__c || newOrd.Q_Imaging_D__c != oldOrd.Q_Imaging_D__c || newOrd.Tokai_Hit_D__c != oldOrd.Tokai_Hit_D__c || newOrd.Other_Third_D__c != oldOrd.Other_Third_D__c || newOrd.ServiceFee_D__c != oldOrd.ServiceFee_D__c || newOrd.AlongProduct_D__c != oldOrd.AlongProduct_D__c || newOrd.Cost_D__c != oldOrd.Cost_D__c || newOrd.ForeignTradeCompany_D__c != oldOrd.ForeignTradeCompany_D__c || newOrd.Shipment_Term_D__c != oldOrd.Shipment_Term_D__c || newOrd.Shipment_Term2_D__c != oldOrd.Shipment_Term2_D__c || (newOrd.SpecialDeliveryAccount_D__c != oldOrd.SpecialDeliveryAccount_D__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)) || (newOrd.SpecialDeliveryContact2_D__c != oldOrd.SpecialDeliveryContact2_D__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)); system.debug('=====' + newOrd.CustomerContractPriceD__c + '|' + oldOrd.CustomerContractPriceD__c); system.debug('=====' + newOrd.OlympusContractPricesD__c + '|' + oldOrd.OlympusContractPricesD__c); system.debug('=====' + newOrd.EndUserD__c + '|' + oldOrd.EndUserD__c); system.debug('=====' + newOrd.AlongProduct_D__c + '|' + oldOrd.AlongProduct_D__c); system.debug('=====' + newOrd.ServiceFee_D__c + '|' + oldOrd.ServiceFee_D__c); boolean contractInfo_change = (newOrd.CustomerContractPriceD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.CustomerContractPriceD__c)).setScale(2).setScale(0)) != (oldOrd.CustomerContractPriceD__c == null ? 0 : Decimal.valueOf(String.valueOf(oldOrd.CustomerContractPriceD__c)).setScale(2).setScale(0)) || (newOrd.OlympusContractPricesD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.OlympusContractPricesD__c)).setScale(2).setScale(0)) != (oldOrd.OlympusContractPricesD__c == null ? 0 : Decimal.valueOf(String.valueOf(oldOrd.OlympusContractPricesD__c)).setScale(2).setScale(0)) || newOrd.EndUserD__c != oldOrd.EndUserD__c || newOrd.AlongProduct_D__c != oldOrd.AlongProduct_D__c || newOrd.ServiceFee_D__c != oldOrd.ServiceFee_D__c; boolean pdf_change = newOrd.IsUpload__c != oldOrd.IsUpload__c; //产品配置 // boolean product_change = newOrd.ProductConfig_D__c != oldOrd.ProductConfig_D__c && oldOrd.Pr; if (newOrd.Contract_StatusD__c != oldOrd.Contract_StatusD__c && newOrd.Contract_StatusD__c == 'Cancel') { if (sp_change == false && contract_change == false) { newOrd.ApproveStatus__c = 'OrderDraft'; newOrd.date_P__c = null; } else { newOrd.addError('取消合同时,不能改变其他项目。'); } } // String profileId = UserInfo.getProfileId().substring(0, 15); boolean is_admin = new_profileId == System.Label.SystemAdmin || new_profileId == System.Label.SystemAdmin2 || new_profileId == System.Label.SystemAdmin_GPI; if (newOrd.IsSpPassed__c == true && (sp_change == true || contractInfo_change == true) && OrderDivisionController.OrderDivision == false && is_admin == false) { newOrd.addError('特殊条件批准后,不能更改。'); } system.debug('***************' + newOrd.IsOrderPassed__c + '***' + sp_change + '***' + contract_change + '***' + OrderDivisionController.OrderDivision + '***' + is_admin + ''); if (newOrd.IsOrderPassed__c == true && (sp_change == true || contract_change == true) && OrderDivisionController.OrderDivision == false && is_admin == false) { newOrd.addError('合同批准后,不能更改。'); } if (OrderDivisionController.OrderDivision == true) { /* if (newOrd.ApproveStatus__c == 'Submit') { newOrd.ApproveStatus__c = 'Draft'; } else if (newOrd.ApproveStatus__c == 'OrderSubmit') { newOrd.ApproveStatus__c = 'OrderDraft'; } else { // 保持状态 }*/ // 保持状态 } else if (sp_change && (newOrd.Order_IsSpecial__c == true || newOrd.Order_IsSpecial_Service__c == true)) { system.debug('=====Draft 1====='); newOrd.ApproveStatus__c = 'Draft'; newOrd.date_P__c = null; } else if (contract_change && (newOrd.Order_IsSpecial__c == true || newOrd.Order_IsSpecial_Service__c == true) && newOrd.IsSpPassed__c == false) { system.debug('=====Draft 2====='); newOrd.ApproveStatus__c = 'Draft'; newOrd.date_P__c = null; } else if (contract_change || (newOrd.Order_IsSpecial__c != oldOrd.Order_IsSpecial__c && newOrd.Order_IsSpecial__c == false) || (newOrd.Order_IsSpecial_Service__c != oldOrd.Order_IsSpecial_Service__c && newOrd.Order_IsSpecial_Service__c == false)) { system.debug('=====OrderDraft 1====='); newOrd.ApproveStatus__c = 'OrderDraft'; neword.date_P__c = null; } /*else if(product_change && newOrd.Is_Already_Splited__c == false && oldOrd.ProductConfig_D__c != null){ // system.debug('=====Draft 3====='); newOrd.ApproveStatus__c = 'Draft'; newOrd.ProductConfig_IsChanged__c = true; }*/ boolean sp_change2 = newOrd.SpecialField_IsChanged_ANI__c || newOrd.SpecialField_IsChanged_BS__c || newOrd.SpecialField_IsChanged_BS_1__c || newOrd.SpecialField_IsChanged_Common__c || newOrd.SpecialField_IsChanged_IE__c || newOrd.SpecialField_IsChanged_NDT__c || newOrd.SpecialField_IsChanged_RVI__c; boolean contract_change2 = (newOrd.CustomerContractPrice__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.CustomerContractPrice__c)).setScale(2).setScale(0)) != (newOrd.CustomerContractPriceD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.CustomerContractPriceD__c)).setScale(2).setScale(0)) || (newOrd.OlympusContractPrices__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.OlympusContractPrices__c)).setScale(2).setScale(0)) != (newOrd.OlympusContractPricesD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.OlympusContractPricesD__c)).setScale(2).setScale(0)) || newOrd.EndUser__c != newOrd.EndUserD__c || newOrd.Andor__c != newOrd.Andor_D__c || newOrd.Bitplane__c != newOrd.Bitplane_D__c || newOrd.CoolLED__c != newOrd.CoolLED_D__c || newOrd.Lumen__c != newOrd.Lumen_D__c || newOrd.Lumenera__c != newOrd.Lumenera_D__c || newOrd.Media_Cybernetics__c != newOrd.Media_Cybernetics_D__c || newOrd.Narishige__c != newOrd.Narishige_D__c || newOrd.Newport__c != newOrd.Newport_D__c || newOrd.OSIS_Germany__c != newOrd.OSIS_Germany_D__c || newOrd.OSIS_Singapore__c != newOrd.OSIS_Singapore_D__c || newOrd.Photometrics__c != newOrd.Photometrics_D__c || newOrd.Prior_Scientific__c != newOrd.Prior_Scientific_D__c || newOrd.Q_Imaging__c != newOrd.Q_Imaging_D__c || newOrd.Tokai_Hit__c != newOrd.Tokai_Hit_D__c || newOrd.Other_Third__c != newOrd.Other_Third_D__c || newOrd.ServiceFee__c != newOrd.ServiceFee_D__c || newOrd.AlongProduct__c != newOrd.AlongProduct_D__c || newOrd.Cost__c != newOrd.Cost_D__c || newOrd.Sub_DealerC__c != newOrd.Sub_DealerC_D__c || (newOrd.IsUpload__c != oldOrd.IsUpload__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)) || //附件是否修改 newOrd.Upload_IsChanged__c || newOrd.ForeignTradeCompany__c != newOrd.ForeignTradeCompany_D__c || newOrd.Shipment_Term__c != newOrd.Shipment_Term_D__c || newOrd.Shipment_Term2__c != newOrd.Shipment_Term2_D__c || (newOrd.SpecialDeliveryAccount__c != newOrd.SpecialDeliveryAccount_D__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)) || (newOrd.SpecialDeliveryContact2__c != newOrd.SpecialDeliveryContact2_D__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)); if (newOrd.IsCopy__c && (newOrd.ApproveStatus__c != 'Completed2' && newOrd.ApproveStatus__c != 'OrderSubmit')&& sp_change2 == false && contract_change2) { system.debug('=====OrderDraft 2====='); //system.debug(newOrd.CustomerContractPrice__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.CustomerContractPrice__c)).setScale(2).setScale(0)) != (newOrd.CustomerContractPriceD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.CustomerContractPriceD__c)).setScale(2).setScale(0)); //system.debug(newOrd.OlympusContractPrices__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.OlympusContractPrices__c)).setScale(2).setScale(0)) != (newOrd.OlympusContractPricesD__c == null ? 0 : Decimal.valueOf(String.valueOf(newOrd.OlympusContractPricesD__c)).setScale(2).setScale(0)); system.debug(newOrd.EndUser__c != newOrd.EndUserD__c); system.debug(newOrd.Andor__c != newOrd.Andor_D__c); system.debug(newOrd.Bitplane__c != newOrd.Bitplane_D__c); system.debug(newOrd.CoolLED__c != newOrd.CoolLED_D__c); system.debug(newOrd.Lumen__c != newOrd.Lumen_D__c); system.debug(newOrd.Lumenera__c != newOrd.Lumenera_D__c); system.debug(newOrd.Media_Cybernetics__c != newOrd.Media_Cybernetics_D__c); system.debug(newOrd.Narishige__c != newOrd.Narishige_D__c); system.debug(newOrd.Newport__c != newOrd.Newport_D__c); system.debug(newOrd.OSIS_Germany__c != newOrd.OSIS_Germany_D__c); system.debug(newOrd.OSIS_Singapore__c != newOrd.OSIS_Singapore_D__c); system.debug(newOrd.Photometrics__c != newOrd.Photometrics_D__c); system.debug(newOrd.Prior_Scientific__c != newOrd.Prior_Scientific_D__c); system.debug(newOrd.Q_Imaging__c != newOrd.Q_Imaging_D__c); system.debug(newOrd.Tokai_Hit__c != newOrd.Tokai_Hit_D__c); system.debug(newOrd.Other_Third__c != newOrd.Other_Third_D__c); system.debug(newOrd.ServiceFee__c != newOrd.ServiceFee_D__c); system.debug(newOrd.AlongProduct__c != newOrd.AlongProduct_D__c); system.debug(newOrd.Cost__c != newOrd.Cost_D__c); system.debug(newOrd.Sub_DealerC__c != newOrd.Sub_DealerC_D__c); system.debug(newOrd.IsUpload__c != oldOrd.IsUpload__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)); system.debug(newOrd.Upload_IsChanged__c); system.debug(newOrd.ForeignTradeCompany__c != newOrd.ForeignTradeCompany_D__c); system.debug(newOrd.Shipment_Term__c != newOrd.Shipment_Term_D__c); system.debug(newOrd.Shipment_Term2__c != newOrd.Shipment_Term2_D__c); system.debug(newOrd.SpecialDeliveryAccount__c != newOrd.SpecialDeliveryAccount_D__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)); system.debug(newOrd.SpecialDeliveryContact2__c != newOrd.SpecialDeliveryContact2_D__c && ((newOrd.Is_Already_Splited__c == true && newOrd.ApproveStatus__c != 'OrderPass') || newOrd.Is_Already_Splited__c != true)); system.debug(newOrd.SpecialDeliveryAccount__c+'!'+newOrd.SpecialDeliveryAccount_D__c); system.debug(newOrd.SpecialDeliveryContact2__c+'!'+newOrd.SpecialDeliveryContact2_D__c); system.debug(newOrd.Is_Already_Splited__c+'!'+newOrd.ApproveStatus__c); newOrd.ApproveStatus__c = 'OrderDraft'; neword.date_P__c = null; } else if (newOrd.IsCopy__c && newOrd.ApproveStatus__c != 'Completed2' && sp_change2 == false && contract_change2 == false) { system.debug('=====CopyStatus====='); newOrd.ApproveStatus__c = newOrd.CopyStatus__c; } if (newOrd.SP_11__c != oldOrd.SP_11__c) { newOrd.SP_11D__c = newOrd.SP_11__c; } if (newOrd.SP_901__c != oldOrd.SP_901__c) { newOrd.SP_901D__c = newOrd.SP_901__c; } if (newOrd.SP_101__c != oldOrd.SP_101__c) { newOrd.SP_101D__c = newOrd.SP_101__c; } if (newOrd.SP_102__c != oldOrd.SP_102__c) { newOrd.SP_102D__c = newOrd.SP_102__c; } if (newOrd.SP_103__c != oldOrd.SP_103__c) { newOrd.SP_103D__c = newOrd.SP_103__c; } if (newOrd.SP_106__c != oldOrd.SP_106__c) { newOrd.SP_106D__c = newOrd.SP_106__c; } if (newOrd.SP_107__c != oldOrd.SP_107__c) { newOrd.SP_107D__c = newOrd.SP_107__c; } if (newOrd.Theoinp__c != oldOrd.Theoinp__c) { newOrd.Theoinp_D__c = newOrd.Theoinp__c; } if (newOrd.SP_745__c != oldOrd.SP_745__c) { newOrd.SP_745D__c = newOrd.SP_745__c; } if (newOrd.SP_111__c != oldOrd.SP_111__c) { newOrd.SP_111D__c = newOrd.SP_111__c; } if (newOrd.SP_121__c != oldOrd.SP_121__c) { newOrd.SP_121D__c = newOrd.SP_121__c; } if (newOrd.SP_131__c != oldOrd.SP_131__c) { newOrd.SP_131D__c = newOrd.SP_131__c; } if (newOrd.SP_141__c != oldOrd.SP_141__c) { newOrd.SP_141D__c = newOrd.SP_141__c; } if (newOrd.SP_151__c != oldOrd.SP_151__c) { newOrd.SP_151D__c = newOrd.SP_151__c; } if (newOrd.SP_161__c != oldOrd.SP_161__c) { newOrd.SP_161D__c = newOrd.SP_161__c; } if (newOrd.SP_171__c != oldOrd.SP_171__c) { newOrd.SP_171D__c = newOrd.SP_171__c; } if (newOrd.SP_181__c != oldOrd.SP_181__c) { newOrd.SP_181D__c = newOrd.SP_181__c; } if (newOrd.SP_191__c != oldOrd.SP_191__c) { newOrd.SP_191D__c = newOrd.SP_191__c; } if (newOrd.SP_201__c != oldOrd.SP_201__c) { newOrd.SP_201D__c = newOrd.SP_201__c; } if (newOrd.SP_202__c != oldOrd.SP_202__c) { newOrd.SP_202D__c = newOrd.SP_202__c; } if (newOrd.SP_21__c != oldOrd.SP_21__c) { newOrd.SP_21D__c = newOrd.SP_21__c; } if (newOrd.SP_22__c != oldOrd.SP_22__c) { newOrd.SP_22D__c = newOrd.SP_22__c; } if (newOrd.SP_31__c != oldOrd.SP_31__c) { newOrd.SP_31D__c = newOrd.SP_31__c; } if (newOrd.SP_32__c != oldOrd.SP_32__c) { newOrd.SP_32D__c = newOrd.SP_32__c; } if (newOrd.SP_33__c != oldOrd.SP_33__c) { newOrd.SP_33D__c = newOrd.SP_33__c; } if (newOrd.SP_41__c != oldOrd.SP_41__c) { newOrd.SP_41D__c = newOrd.SP_41__c; } if (newOrd.SP_51__c != oldOrd.SP_51__c) { newOrd.SP_51D__c = newOrd.SP_51__c; } if (newOrd.SP_52__c != oldOrd.SP_52__c) { newOrd.SP_52D__c = newOrd.SP_52__c; } if (newOrd.SP_61__c != oldOrd.SP_61__c) { newOrd.SP_61D__c = newOrd.SP_61__c; } if (newOrd.SP_62__c != oldOrd.SP_62__c) { newOrd.SP_62D__c = newOrd.SP_62__c; } if (newOrd.SP_71__c != oldOrd.SP_71__c) { newOrd.SP_71D__c = newOrd.SP_71__c; } if (newOrd.SP_81__c != oldOrd.SP_81__c) { newOrd.SP_81D__c = newOrd.SP_81__c; } if (newOrd.SP_91__c != oldOrd.SP_91__c) { newOrd.SP_91D__c = newOrd.SP_91__c; } //if (newOrd.ConditionContract__c != oldOrd.ConditionContract__c) { // newOrd.ConditionContract_D__c = newOrd.ConditionContract__c; //} if (newOrd.Contract_Status__c != oldOrd.Contract_Status__c) { newOrd.Contract_StatusD__c = newOrd.Contract_Status__c; } if (newOrd.CustomerContractPrice__c != oldOrd.CustomerContractPrice__c) { newOrd.CustomerContractPriceD__c = newOrd.CustomerContractPrice__c; } //if (newOrd.EffectiveDate != oldOrd.EffectiveDate) { // newOrd.EffectiveDateD__c = newOrd.EffectiveDate; //} if (newOrd.EndUser__c != oldOrd.EndUser__c) { newOrd.EndUserD__c = newOrd.EndUser__c; } if (newOrd.OlympusContractPrices__c != oldOrd.OlympusContractPrices__c) { newOrd.OlympusContractPricesD__c = newOrd.OlympusContractPrices__c; } if (newOrd.IE_SP1__c != oldOrd.IE_SP1__c) { newOrd.IE_SP1_D__c = newOrd.IE_SP1__c; } if (newOrd.IE_SP2__c != oldOrd.IE_SP2__c) { newOrd.IE_SP2_D__c = newOrd.IE_SP2__c; } if (newOrd.IE_SP3__c != oldOrd.IE_SP3__c) { newOrd.IE_SP3_D__c = newOrd.IE_SP3__c; } if (newOrd.IE_SP4__c != oldOrd.IE_SP4__c) { newOrd.IE_SP4_D__c = newOrd.IE_SP4__c; } if (newOrd.IE_SP5__c != oldOrd.IE_SP5__c) { newOrd.IE_SP5_D__c = newOrd.IE_SP5__c; } if (newOrd.IE_SP6__c != oldOrd.IE_SP6__c) { newOrd.IE_SP6_D__c = newOrd.IE_SP6__c; } if (newOrd.IE_SP7__c != oldOrd.IE_SP7__c) { newOrd.IE_SP7_D__c = newOrd.IE_SP7__c; } if (newOrd.IE_SP8__c != oldOrd.IE_SP8__c) { newOrd.IE_SP8_D__c = newOrd.IE_SP8__c; } if (newOrd.RVI_SP1__c != oldOrd.RVI_SP1__c) { newOrd.RVI_SP1_D__c = newOrd.RVI_SP1__c; } if (newOrd.RVI_SP2__c != oldOrd.RVI_SP2__c) { newOrd.RVI_SP2_D__c = newOrd.RVI_SP2__c; } if (newOrd.RVI_SP3__c != oldOrd.RVI_SP3__c) { newOrd.RVI_SP3_D__c = newOrd.RVI_SP3__c; } if (newOrd.RVI_SP4__c != oldOrd.RVI_SP4__c) { newOrd.RVI_SP4_D__c = newOrd.RVI_SP4__c; } if (newOrd.RVI_SP5__c != oldOrd.RVI_SP5__c) { newOrd.RVI_SP5_D__c = newOrd.RVI_SP5__c; } if (newOrd.RVI_SP6__c != oldOrd.RVI_SP6__c) { newOrd.RVI_SP6_D__c = newOrd.RVI_SP6__c; } if (newOrd.NDT_SP1__c != oldOrd.NDT_SP1__c) { newOrd.NDT_SP1_D__c = newOrd.NDT_SP1__c; } if (newOrd.NDT_SP2__c != oldOrd.NDT_SP2__c) { newOrd.NDT_SP2_D__c = newOrd.NDT_SP2__c; } if (newOrd.NDT_SP3__c != oldOrd.NDT_SP3__c) { newOrd.NDT_SP3_D__c = newOrd.NDT_SP3__c; } if (newOrd.NDT_SP4__c != oldOrd.NDT_SP4__c) { newOrd.NDT_SP4_D__c = newOrd.NDT_SP4__c; } if (newOrd.NDT_SP5__c != oldOrd.NDT_SP5__c) { newOrd.NDT_SP5_D__c = newOrd.NDT_SP5__c; } if (newOrd.NDT_SP6__c != oldOrd.NDT_SP6__c) { newOrd.NDT_SP6_D__c = newOrd.NDT_SP6__c; } if (newOrd.NDT_SP7__c != oldOrd.NDT_SP7__c) { newOrd.NDT_SP7_D__c = newOrd.NDT_SP7__c; } if (newOrd.NDT_SP8__c != oldOrd.NDT_SP8__c) { newOrd.NDT_SP8_D__c = newOrd.NDT_SP8__c; } if (newOrd.NDT_SP9__c != oldOrd.NDT_SP9__c) { newOrd.NDT_SP9_D__c = newOrd.NDT_SP9__c; } if (newOrd.NDT_SP10__c != oldOrd.NDT_SP10__c) { newOrd.NDT_SP10_D__c = newOrd.NDT_SP10__c; } if (newOrd.NDT_SP11__c != oldOrd.NDT_SP11__c) { newOrd.NDT_SP11_D__c = newOrd.NDT_SP11__c; } if (newOrd.ANI_SP1__c != oldOrd.ANI_SP1__c) { newOrd.ANI_SP1_D__c = newOrd.ANI_SP1__c; } if (newOrd.ANI_SP2__c != oldOrd.ANI_SP2__c) { newOrd.ANI_SP2_D__c = newOrd.ANI_SP2__c; } if (newOrd.ANI_SP3__c != oldOrd.ANI_SP3__c) { newOrd.ANI_SP3_D__c = newOrd.ANI_SP3__c; } if (newOrd.ANI_SP4__c != oldOrd.ANI_SP4__c) { newOrd.ANI_SP4_D__c = newOrd.ANI_SP4__c; } if (newOrd.ANI_SP5__c != oldOrd.ANI_SP5__c) { newOrd.ANI_SP5_D__c = newOrd.ANI_SP5__c; } if (newOrd.ANI_SP6__c != oldOrd.ANI_SP6__c) { newOrd.ANI_SP6_D__c = newOrd.ANI_SP6__c; } if (newOrd.NormalDis_SerContractCondition__c != oldOrd.NormalDis_SerContractCondition__c) { newOrd.NormalDis_SerContractCondition_D__c = newOrd.NormalDis_SerContractCondition__c; } if (newOrd.HighDis_SerContractCondition__c != oldOrd.HighDis_SerContractCondition__c) { newOrd.HighDis_SerContractCondition_D__c = newOrd.HighDis_SerContractCondition__c; } if (newOrd.SpecialDis_SerContractCondition__c != oldOrd.SpecialDis_SerContractCondition__c) { newOrd.SpecialDis_SerContractCondition_D__c = newOrd.SpecialDis_SerContractCondition__c; } if (newOrd.Warranty_SerContractCondition__c != oldOrd.Warranty_SerContractCondition__c) { newOrd.Warranty_SerContractCondition_D__c = newOrd.Warranty_SerContractCondition__c; } if (newOrd.Discount__c != oldOrd.Discount__c) { newOrd.Discount_D__c = newOrd.Discount__c; } if (newOrd.Olympus_Price_BeforeDiscount__c != oldOrd.Olympus_Price_BeforeDiscount__c) { newOrd.Olympus_Price_BeforeDiscount_D__c = newOrd.Olympus_Price_BeforeDiscount__c; } if (newOrd.PaymentCondition__c != oldOrd.PaymentCondition__c) { newOrd.PaymentCondition_D__c = newOrd.PaymentCondition__c; } if (newOrd.SpecialDelivery__c != oldOrd.SpecialDelivery__c) { newOrd.SpecialDelivery_D__c = newOrd.SpecialDelivery__c; } if (newOrd.SpecialDeliveryContact__c != oldOrd.SpecialDeliveryContact__c) { newOrd.SpecialDeliveryContact_D__c = newOrd.SpecialDeliveryContact__c; } if (newOrd.SpecialDeliveryPhone__c != oldOrd.SpecialDeliveryPhone__c) { newOrd.SpecialDeliveryPhone_D__c = newOrd.SpecialDeliveryPhone__c; } if (newOrd.SpecialDeliveryAddress__c != oldOrd.SpecialDeliveryAddress__c) { newOrd.SpecialDeliveryAddress_D__c = newOrd.SpecialDeliveryAddress__c; } if (newOrd.SpecialParkage__c != oldOrd.SpecialParkage__c) { newOrd.SpecialParkage_D__c = newOrd.SpecialParkage__c; } if (newOrd.SpecialWarranty__c != oldOrd.SpecialWarranty__c) { newOrd.SpecialWarranty_D__c = newOrd.SpecialWarranty__c; } if (newOrd.DealerProfit__c != oldOrd.DealerProfit__c) { newOrd.DealerProfit_D__c = newOrd.DealerProfit__c; } if (newOrd.SpecialDelDate__c != oldOrd.SpecialDelDate__c) { newOrd.SpecialDelDate_D__c = newOrd.SpecialDelDate__c; } if (newOrd.OtherApply__c != oldOrd.OtherApply__c) { newOrd.OtherApply_D__c = newOrd.OtherApply__c; } if (newOrd.Andor__c != oldOrd.Andor__c) { newOrd.Andor_D__c = newOrd.Andor__c; } if (newOrd.Bitplane__c != oldOrd.Bitplane__c) { newOrd.Bitplane_D__c = newOrd.Bitplane__c; } if (newOrd.CoolLED__c != oldOrd.CoolLED__c) { newOrd.CoolLED_D__c = newOrd.CoolLED__c; } if (newOrd.Lumen__c != oldOrd.Lumen__c) { newOrd.Lumen_D__c = newOrd.Lumen__c; } if (newOrd.Lumenera__c != oldOrd.Lumenera__c) { newOrd.Lumenera_D__c = newOrd.Lumenera__c; } if (newOrd.Media_Cybernetics__c != oldOrd.Media_Cybernetics__c) { newOrd.Media_Cybernetics_D__c = newOrd.Media_Cybernetics__c; } if (newOrd.Narishige__c != oldOrd.Narishige__c) { newOrd.Narishige_D__c = newOrd.Narishige__c; } if (newOrd.Newport__c != oldOrd.Newport__c) { newOrd.Newport_D__c = newOrd.Newport__c; } if (newOrd.OSIS_Germany__c != oldOrd.OSIS_Germany__c) { newOrd.OSIS_Germany_D__c = newOrd.OSIS_Germany__c; } if (newOrd.OSIS_Singapore__c != oldOrd.OSIS_Singapore__c) { newOrd.OSIS_Singapore_D__c = newOrd.OSIS_Singapore__c; } if (newOrd.Photometrics__c != oldOrd.Photometrics__c) { newOrd.Photometrics_D__c = newOrd.Photometrics__c; } if (newOrd.Prior_Scientific__c != oldOrd.Prior_Scientific__c) { newOrd.Prior_Scientific_D__c = newOrd.Prior_Scientific__c; } if (newOrd.Q_Imaging__c != oldOrd.Q_Imaging__c) { newOrd.Q_Imaging_D__c = newOrd.Q_Imaging__c; } if (newOrd.Tokai_Hit__c != oldOrd.Tokai_Hit__c) { newOrd.Tokai_Hit_D__c = newOrd.Tokai_Hit__c; } if (newOrd.Other_Third__c != oldOrd.Other_Third__c) { newOrd.Other_Third_D__c = newOrd.Other_Third__c; } if (newOrd.ServiceFee__c != oldOrd.ServiceFee__c) { newOrd.ServiceFee_D__c = newOrd.ServiceFee__c; } if (newOrd.AlongProduct__c != oldOrd.AlongProduct__c) { newOrd.AlongProduct_D__c = newOrd.AlongProduct__c; } if (newOrd.Cost__c != oldOrd.Cost__c) { newOrd.Cost_D__c = newOrd.Cost__c; } if (newOrd.Sub_DealerC__c != oldOrd.Sub_DealerC__c) { newOrd.Sub_DealerC_D__c = newOrd.Sub_DealerC__c; } if (newOrd.SpecialDeliveryAccount__c != oldOrd.SpecialDeliveryAccount__c) { newOrd.SpecialDeliveryAccount_D__c = newOrd.SpecialDeliveryAccount__c; } if (newOrd.ForeignTradeCompany__c != oldOrd.ForeignTradeCompany__c) { newOrd.ForeignTradeCompany_D__c = newOrd.ForeignTradeCompany__c; // 外贸送达方默认为外贸公司 if (newOrd.TradeType__c == System.Label.Trade_Type) { newOrd.SpecialDeliveryAccount__c = newOrd.ForeignTradeCompany__c; newOrd.SpecialDeliveryAccount_D__c = newOrd.ForeignTradeCompany__c; } } if (newOrd.SpecialDeliveryContact2__c != oldOrd.SpecialDeliveryContact2__c) { newOrd.SpecialDeliveryContact2_D__c = newOrd.SpecialDeliveryContact2__c; } if (newOrd.TradeType__c == System.Label.Trade_Type) { if (newOrd.ForeignTradeCompany_D__c != newOrd.SpecialDeliveryAccount_D__c) { newOrd.SpecialDeliveryAccount_D__c = newOrd.ForeignTradeCompany_D__c; system.debug('=====set SpecialDeliveryAccount'); } } if (newOrd.Shipment_Term__c != oldOrd.Shipment_Term__c) { newOrd.Shipment_Term_D__c = newOrd.Shipment_Term__c; } if (newOrd.Shipment_Term2__c != oldOrd.Shipment_Term2__c) { newOrd.Shipment_Term2_D__c = newOrd.Shipment_Term2__c; } if (newOrd.ProductConfig__c != oldOrd.ProductConfig__c) { newOrd.ProductConfig_D__c = newOrd.ProductConfig__c; } if (newOrd.ProductConfig_D__c != oldOrd.ProductConfig_D__c && oldOrd.ProductConfig_D__c != null) { newOrd.ProductConfig_IsChanged__c = true; } //IE,只有compo被选中,则不需要审批 gwy 2021-06-02 if(newOrd.ProductSegment__c=='IE' && newOrd.Status__c == 'Active' && newOrd.OrderDraft__c == false && newOrd.IE_SP5_D__c == false && newOrd.IE_SP6_D__c == false && newOrd.IE_SP7_D__c == false && newOrd.IE_SP8_D__c == true){ newOrd.ApproveStatus__c = 'Pass'; newOrd.IsSpPassed__c = true; newOrd.IE_SP8__c = true; } //IE,只有compo被选中,则不需要审批 gwy 2021-06-02 } } /** * XHL20210830 * SSBD合同共享数据的拼接 * @param orderId [SSBD合同Id] * @param userId [待共享的用户Id] * @return [description] */ public static OrderShare DataAssembly(String orderId,String userId){ OrderShare aos = new OrderShare( RowCause = 'Manual', orderId = orderId, UserOrGroupId = userId, OrderAccessLevel = 'Edit'); return aos; } /** * 合同权限共享 XHL20210830 * @param newList [description] * @param newMap [description] * @param oldList [description] * @param oldMap [description] */ public static void setOrderShare (List newList, Map newMap, List oldList, Map oldMap) { List insertOrderShareList = new List(); /*BatchIF_Log__c iflog = new BatchIF_Log__c(); iflog.Type__c = 'OrderShare'; String datetimeStr = String.valueOf(Datetime.now()).replace('-','').replace(' ','').replace(':',''); iflog.MessageGroupNumber__c = datetimeStr; iflog.Log__c = ''; Boolean errrorFlag = false;*/ for (Order newOrd : newList) { Order oldOrd = oldMap == null ? new Order() : oldMap.get(newOrd.Id); //共享权限设置标识 变更 为 真 并且 所有人变更,将合同共享给 原所有人 System.debug('newOrd.SharedFlag__c--->'+newOrd.SharedFlag__c); System.debug('oldOrd.SharedFlag__c--->'+oldOrd.SharedFlag__c); System.debug('newOrd.SharedFlag__c--->'+newOrd.SharedFlag__c); System.debug('newOrd.OwnerId--->'+newOrd.OwnerId); System.debug('oldOrd.OwnerId--->'+oldOrd.OwnerId); if (newOrd.SharedFlag__c != oldOrd.SharedFlag__c && newOrd.SharedFlag__c && newOrd.OwnerId != oldOrd.OwnerId) { String userId = oldOrd.OwnerId; insertOrderShareList.add(DataAssembly(newOrd.Id,userId)); } /*else { if (newOrd.SharedFlag__c != oldOrd.SharedFlag__c && newOrd.SharedFlag__c) { iflog.Log__c += 'Order Id --->'+ newOrd.Id + '\n'; iflog.Log__c += 'newOrd.OwnerId--->'+newOrd.OwnerId + '\n'; iflog.Log__c += 'oldOrd.OwnerId--->'+oldOrd.OwnerId + '\n'; errrorFlag = true; } }*/ } if (insertOrderShareList.size() > 0) { system.debug('insertOrderShareList--->'+insertOrderShareList); insert insertOrderShareList; } /*if (errrorFlag) { insert iflog; }*/ } public static void dealerOrderApproval(List newList, Map newMap, List oldList, Map oldMap) { // List insertOrderShareList = new List(); for (Order newOrd : newList) { Order oldOrd = oldMap.get(newOrd.Id); // if (newOrd.OwnerId <> newOrd.OpportunityOwnerId__c && newOrd.OpportunityOwnerId__c <> null && newOrd.OpportunityOwnerId__c <> '') { // newOrd.OwnerId = newOrd.OpportunityOwnerId__c; // newOrd.SharedFlag__c = true; // } // XHL20210830 if (newOrd.SharedFlag__c != oldOrd.SharedFlag__c && newOrd.SharedFlag__c && newOrd.OwnerId != newOrd.OpportunityOwnerId__c && newOrd.OpportunityOwnerId__c <> null && newOrd.OpportunityOwnerId__c <> '') { newOrd.OwnerId = newOrd.OpportunityOwnerId__c; } if (newOrd.ApproveStatus__c != oldOrd.ApproveStatus__c) { if (newOrd.ApproveStatus__c == 'Pass' && newOrd.IsCopy__c == false) { newOrd.IsSpPassed__c = true; } //gwy 2021-06-03 修改IE成为特殊审批通过,后悔选了compo,修改合同不触发错误。 //这段不用了 /*if (newOrd.ApproveStatus__c == 'Pass' && newOrd.IsCopy__c == false) { if(newOrd.ProductSegment__c=='IE' && newOrd.Status__c == 'Active' && newOrd.IE_SP5_D__c == false && newOrd.IE_SP6_D__c == false && newOrd.IE_SP7_D__c == false && newOrd.IE_SP8_D__c == true){ newOrd.IsSpPassed__c = true; }else{ newOrd.IsSpPassed__c = true; } }*/ //if (newOrd.ApproveStatus__c == 'Pass' || newOrd.ApproveStatus__c == 'OrderPass') { if (newOrd.ApproveStatus__c == 'OrderPass' && newOrd.IsCopy__c == false) { // 合同创建时,嵌入画面更新owner //newOrd.OwnerId = newOrd.OpportunityOwnerId__c; newOrd.Contract_Status__c = newOrd.Contract_StatusD__c; if (newOrd.IsNew__c == true) { newOrd.IsNew__c = false; } if (newOrd.Upload_IsChanged__c == true) { newOrd.Upload_IsChanged__c = false; } //if (newOrd.ApproveStatus__c == 'Pass') { newOrd.SP_11__c = newOrd.SP_11D__c; newOrd.SP_901__c = newOrd.SP_901D__c; newOrd.SP_101__c = newOrd.SP_101D__c; newOrd.SP_102__c = newOrd.SP_102D__c; newOrd.SP_103__c = newOrd.SP_103D__c; newOrd.SP_106__c = newOrd.SP_106D__c; newOrd.SP_107__c = newOrd.SP_107D__c; newOrd.Theoinp__c = newOrd.Theoinp_D__c; newOrd.SP_745__c = newOrd.SP_745D__c; newOrd.SP_111__c = newOrd.SP_111D__c; newOrd.SP_121__c = newOrd.SP_121D__c; newOrd.SP_131__c = newOrd.SP_131D__c; newOrd.SP_141__c = newOrd.SP_141D__c; newOrd.SP_151__c = newOrd.SP_151D__c; newOrd.SP_161__c = newOrd.SP_161D__c; newOrd.SP_171__c = newOrd.SP_171D__c; newOrd.SP_181__c = newOrd.SP_181D__c; newOrd.SP_191__c = newOrd.SP_191D__c; newOrd.SP_201__c = newOrd.SP_201D__c; newOrd.SP_202__c = newOrd.SP_202D__c; newOrd.SP_21__c = newOrd.SP_21D__c; newOrd.SP_22__c = newOrd.SP_22D__c; newOrd.SP_31__c = newOrd.SP_31D__c; newOrd.SP_32__c = newOrd.SP_32D__c; newOrd.SP_33__c = newOrd.SP_33D__c; newOrd.SP_41__c = newOrd.SP_41D__c; newOrd.SP_51__c = newOrd.SP_51D__c; newOrd.SP_52__c = newOrd.SP_52D__c; newOrd.SP_61__c = newOrd.SP_61D__c; newOrd.SP_62__c = newOrd.SP_62D__c; newOrd.SP_71__c = newOrd.SP_71D__c; newOrd.SP_81__c = newOrd.SP_81D__c; newOrd.SP_91__c = newOrd.SP_91D__c; newOrd.IE_SP1__c = newOrd.IE_SP1_D__c; newOrd.IE_SP2__c = newOrd.IE_SP2_D__c; newOrd.IE_SP3__c = newOrd.IE_SP3_D__c; newOrd.IE_SP4__c = newOrd.IE_SP4_D__c; newOrd.IE_SP5__c = newOrd.IE_SP5_D__c; newOrd.IE_SP6__c = newOrd.IE_SP6_D__c; newOrd.IE_SP7__c = newOrd.IE_SP7_D__c; newOrd.IE_SP8__c = newOrd.IE_SP8_D__c; newOrd.RVI_SP1__c = newOrd.RVI_SP1_D__c; newOrd.RVI_SP2__c = newOrd.RVI_SP2_D__c; newOrd.RVI_SP3__c = newOrd.RVI_SP3_D__c; newOrd.RVI_SP4__c = newOrd.RVI_SP4_D__c; newOrd.RVI_SP5__c = newOrd.RVI_SP5_D__c; newOrd.RVI_SP6__c = newOrd.RVI_SP6_D__c; newOrd.NDT_SP1__c = newOrd.NDT_SP1_D__c; newOrd.NDT_SP2__c = newOrd.NDT_SP2_D__c; newOrd.NDT_SP3__c = newOrd.NDT_SP3_D__c; newOrd.NDT_SP4__c = newOrd.NDT_SP4_D__c; newOrd.NDT_SP5__c = newOrd.NDT_SP5_D__c; newOrd.NDT_SP6__c = newOrd.NDT_SP6_D__c; newOrd.NDT_SP7__c = newOrd.NDT_SP7_D__c; newOrd.NDT_SP8__c = newOrd.NDT_SP8_D__c; newOrd.NDT_SP9__c = newOrd.NDT_SP9_D__c; newOrd.NDT_SP10__c = newOrd.NDT_SP10_D__c; newOrd.NDT_SP11__c = newOrd.NDT_SP11_D__c; newOrd.ANI_SP1__c = newOrd.ANI_SP1_D__c; newOrd.ANI_SP2__c = newOrd.ANI_SP2_D__c; newOrd.ANI_SP3__c = newOrd.ANI_SP3_D__c; newOrd.ANI_SP4__c = newOrd.ANI_SP4_D__c; newOrd.ANI_SP5__c = newOrd.ANI_SP5_D__c; newOrd.ANI_SP6__c = newOrd.ANI_SP6_D__c; newOrd.NormalDis_SerContractCondition__c = newOrd.NormalDis_SerContractCondition_D__c; newOrd.HighDis_SerContractCondition__c = newOrd.HighDis_SerContractCondition_D__c; newOrd.SpecialDis_SerContractCondition__c = newOrd.SpecialDis_SerContractCondition_D__c; newOrd.Warranty_SerContractCondition__c = newOrd.Warranty_SerContractCondition_D__c; //} newOrd.Discount__c = newOrd.Discount_D__c; newOrd.Olympus_Price_BeforeDiscount__c = newOrd.Olympus_Price_BeforeDiscount_D__c; newOrd.PaymentCondition__c = newOrd.PaymentCondition_D__c; newOrd.SpecialDelivery__c = newOrd.SpecialDelivery_D__c; newOrd.SpecialDeliveryContact__c = newOrd.SpecialDeliveryContact_D__c; newOrd.SpecialDeliveryPhone__c = newOrd.SpecialDeliveryPhone_D__c; newOrd.SpecialDeliveryAddress__c = newOrd.SpecialDeliveryAddress_D__c; newOrd.SpecialParkage__c = newOrd.SpecialParkage_D__c; newOrd.SpecialWarranty__c = newOrd.SpecialWarranty_D__c; newOrd.DealerProfit__c = newOrd.DealerProfit_D__c; newOrd.SpecialDelDate__c = newOrd.SpecialDelDate_D__c; newOrd.OtherApply__c = newOrd.OtherApply_D__c; //if (newOrd.ApproveStatus__c == 'OrderPass') { newOrd.IsOrderPassed__c = true; newOrd.CustomerContractPrice__c = newOrd.CustomerContractPriceD__c; newOrd.OlympusContractPrices__c = newOrd.OlympusContractPricesD__c; newOrd.EndUser__c = newOrd.EndUserD__c; newOrd.Andor__c = newOrd.Andor_D__c; newOrd.Bitplane__c = newOrd.Bitplane_D__c; newOrd.CoolLED__c = newOrd.CoolLED_D__c; newOrd.Lumen__c = newOrd.Lumen_D__c; newOrd.Lumenera__c = newOrd.Lumenera_D__c; newOrd.Media_Cybernetics__c = newOrd.Media_Cybernetics_D__c; newOrd.Narishige__c = newOrd.Narishige_D__c; newOrd.Newport__c = newOrd.Newport_D__c; newOrd.OSIS_Germany__c = newOrd.OSIS_Germany_D__c; newOrd.OSIS_Singapore__c = newOrd.OSIS_Singapore_D__c; newOrd.Photometrics__c = newOrd.Photometrics_D__c; newOrd.Prior_Scientific__c = newOrd.Prior_Scientific_D__c; newOrd.Q_Imaging__c = newOrd.Q_Imaging_D__c; newOrd.Tokai_Hit__c = newOrd.Tokai_Hit_D__c; newOrd.Other_Third__c = newOrd.Other_Third_D__c; newOrd.ServiceFee__c = newOrd.ServiceFee_D__c; newOrd.AlongProduct__c = newOrd.AlongProduct_D__c; newOrd.Cost__c = newOrd.Cost_D__c; newOrd.Sub_DealerC__c = newOrd.Sub_DealerC_D__c; //} newOrd.ForeignTradeCompany__c = newOrd.ForeignTradeCompany_D__c; newOrd.SpecialDeliveryAccount__c = newOrd.SpecialDeliveryAccount_D__c; newOrd.SpecialDeliveryContact2__c = newOrd.SpecialDeliveryContact2_D__c; newOrd.Shipment_Term__c = newOrd.Shipment_Term_D__c; newOrd.Shipment_Term2__c = newOrd.Shipment_Term2_D__c; newOrd.ProductConfig__c = newOrd.ProductConfig_D__c; } if ((newOrd.ApproveStatus__c == 'Reject' || newOrd.ApproveStatus__c == 'OrderReject') && newOrd.IsNew__c == false) { //if (newOrd.ApproveStatus__c == 'Reject') { newOrd.SP_11D__c = newOrd.SP_11__c; newOrd.SP_101D__c = newOrd.SP_101__c; newOrd.SP_901D__c = newOrd.SP_901__c; newOrd.SP_102D__c = newOrd.SP_102__c; newOrd.SP_103D__c = newOrd.SP_103__c; newOrd.SP_106D__c = newOrd.SP_106__c; newOrd.SP_107D__c = newOrd.SP_107__c; newOrd.Theoinp__c = newOrd.Theoinp_D__c; newOrd.SP_745D__c = newOrd.SP_745__c; newOrd.SP_111D__c = newOrd.SP_111__c; newOrd.SP_121D__c = newOrd.SP_121__c; newOrd.SP_131D__c = newOrd.SP_131__c; newOrd.SP_141D__c = newOrd.SP_141__c; newOrd.SP_151D__c = newOrd.SP_151__c; newOrd.SP_161D__c = newOrd.SP_161__c; newOrd.SP_171D__c = newOrd.SP_171__c; newOrd.SP_181D__c = newOrd.SP_181__c; newOrd.SP_191D__c = newOrd.SP_191__c; newOrd.SP_201D__c = newOrd.SP_201__c; newOrd.SP_202D__c = newOrd.SP_202__c; newOrd.SP_21D__c = newOrd.SP_21__c; newOrd.SP_22D__c = newOrd.SP_22__c; newOrd.SP_31D__c = newOrd.SP_31__c; newOrd.SP_32D__c = newOrd.SP_32__c; newOrd.SP_33D__c = newOrd.SP_33__c; newOrd.SP_41D__c = newOrd.SP_41__c; newOrd.SP_51D__c = newOrd.SP_51__c; newOrd.SP_52D__c = newOrd.SP_52__c; newOrd.SP_61D__c = newOrd.SP_61__c; newOrd.SP_62D__c = newOrd.SP_62__c; newOrd.SP_71D__c = newOrd.SP_71__c; newOrd.SP_81D__c = newOrd.SP_81__c; newOrd.SP_91D__c = newOrd.SP_91__c; newOrd.IE_SP1_D__c = newOrd.IE_SP1__c; newOrd.IE_SP2_D__c = newOrd.IE_SP2__c; newOrd.IE_SP3_D__c = newOrd.IE_SP3__c; newOrd.IE_SP4_D__c = newOrd.IE_SP4__c; newOrd.IE_SP5_D__c = newOrd.IE_SP5__c; newOrd.IE_SP6_D__c = newOrd.IE_SP6__c; newOrd.IE_SP7_D__c = newOrd.IE_SP7__c; newOrd.IE_SP8_D__c = newOrd.IE_SP8__c; newOrd.RVI_SP1_D__c = newOrd.RVI_SP1__c; newOrd.RVI_SP2_D__c = newOrd.RVI_SP2__c; newOrd.RVI_SP3_D__c = newOrd.RVI_SP3__c; newOrd.RVI_SP4_D__c = newOrd.RVI_SP4__c; newOrd.RVI_SP5_D__c = newOrd.RVI_SP5__c; newOrd.RVI_SP6_D__c = newOrd.RVI_SP6__c; newOrd.NDT_SP1_D__c = newOrd.NDT_SP1__c; newOrd.NDT_SP2_D__c = newOrd.NDT_SP2__c; newOrd.NDT_SP3_D__c = newOrd.NDT_SP3__c; newOrd.NDT_SP4_D__c = newOrd.NDT_SP4__c; newOrd.NDT_SP5_D__c = newOrd.NDT_SP5__c; newOrd.NDT_SP6_D__c = newOrd.NDT_SP6__c; newOrd.NDT_SP7_D__c = newOrd.NDT_SP7__c; newOrd.NDT_SP8_D__c = newOrd.NDT_SP8__c; newOrd.NDT_SP9_D__c = newOrd.NDT_SP9__c; newOrd.NDT_SP10_D__c = newOrd.NDT_SP10__c; newOrd.NDT_SP11_D__c = newOrd.NDT_SP11__c; newOrd.ANI_SP1_D__c = newOrd.ANI_SP1__c; newOrd.ANI_SP2_D__c = newOrd.ANI_SP2__c; newOrd.ANI_SP3_D__c = newOrd.ANI_SP3__c; newOrd.ANI_SP4_D__c = newOrd.ANI_SP4__c; newOrd.ANI_SP5_D__c = newOrd.ANI_SP5__c; newOrd.ANI_SP6_D__c = newOrd.ANI_SP6__c; newOrd.NormalDis_SerContractCondition_D__c = newOrd.NormalDis_SerContractCondition__c; newOrd.HighDis_SerContractCondition_D__c = newOrd.HighDis_SerContractCondition__c; newOrd.SpecialDis_SerContractCondition_D__c = newOrd.SpecialDis_SerContractCondition__c; newOrd.Warranty_SerContractCondition_D__c = newOrd.Warranty_SerContractCondition__c; //} newOrd.Discount_D__c = newOrd.Discount__c; newOrd.Olympus_Price_BeforeDiscount_D__c = newOrd.Olympus_Price_BeforeDiscount__c; newOrd.PaymentCondition_D__c = newOrd.PaymentCondition__c; newOrd.SpecialDelivery_D__c = newOrd.SpecialDelivery__c; newOrd.SpecialDeliveryContact_D__c = newOrd.SpecialDeliveryContact__c; newOrd.SpecialDeliveryPhone_D__c = newOrd.SpecialDeliveryPhone__c; newOrd.SpecialDeliveryAddress_D__c = newOrd.SpecialDeliveryAddress__c; newOrd.SpecialParkage_D__c = newOrd.SpecialParkage__c; newOrd.SpecialWarranty_D__c = newOrd.SpecialWarranty__c; newOrd.DealerProfit_D__c = newOrd.DealerProfit__c; newOrd.SpecialDelDate_D__c = newOrd.SpecialDelDate__c; newOrd.OtherApply_D__c = newOrd.OtherApply__c; if (newOrd.ApproveStatus__c == 'OrderReject') { newOrd.CustomerContractPriceD__c = newOrd.CustomerContractPrice__c; newOrd.OlympusContractPricesD__c = newOrd.OlympusContractPrices__c; newOrd.EndUserD__c = newOrd.EndUser__c; newOrd.Andor_D__c = newOrd.Andor__c; newOrd.Bitplane_D__c = newOrd.Bitplane__c; newOrd.CoolLED_D__c = newOrd.CoolLED__c; newOrd.Lumen_D__c = newOrd.Lumen__c; newOrd.Lumenera_D__c = newOrd.Lumenera__c; newOrd.Media_Cybernetics_D__c = newOrd.Media_Cybernetics__c; newOrd.Narishige_D__c = newOrd.Narishige__c; newOrd.Newport_D__c = newOrd.Newport__c; newOrd.OSIS_Germany_D__c = newOrd.OSIS_Germany__c; newOrd.OSIS_Singapore_D__c = newOrd.OSIS_Singapore__c; newOrd.Photometrics_D__c = newOrd.Photometrics__c; newOrd.Prior_Scientific_D__c = newOrd.Prior_Scientific__c; newOrd.Q_Imaging_D__c = newOrd.Q_Imaging__c; newOrd.Tokai_Hit_D__c = newOrd.Tokai_Hit__c; newOrd.Other_Third_D__c = newOrd.Other_Third__c; newOrd.ServiceFee_D__c = newOrd.ServiceFee__c; newOrd.AlongProduct_D__c = newOrd.AlongProduct__c; newOrd.Cost_D__c = newOrd.Cost__c; newOrd.Sub_DealerC_D__c = newOrd.Sub_DealerC__c; newOrd.ForeignTradeCompany_D__c = newOrd.ForeignTradeCompany__c; newOrd.SpecialDeliveryAccount_D__c = newOrd.SpecialDeliveryAccount__c; newOrd.SpecialDeliveryContact2_D__c = newOrd.SpecialDeliveryContact2__c; newOrd.Shipment_Term_D__c = newOrd.Shipment_Term__c; newOrd.Shipment_Term2_D__c = newOrd.Shipment_Term2__c; } newOrd.Contract_StatusD__c = newOrd.Contract_Status__c; newOrd.ProductConfig_D__c = newOrd.ProductConfig__c; if (newOrd.Upload_IsChanged__c == true) { newOrd.Upload_IsChanged__c = false; } } } } // if (insertOrderShareList.size()>0) { // system.debug('insertOrderShareList--->'+insertOrderShareList); // insert insertOrderShareList; // } } public static void setApprover(List newList, Map newMap, List oldList, Map oldMap) { List ownerIdList = new List(); Map orderToOwner = new Map(); Map sObjectFieldMaps = Schema.getGlobalDescribe().get('Order').getDescribe().fields.getMap(); Map> orderMap = new Map>(); //存放订单行项目对应的订单的ID /*List otmIdList = new List();*/ //存放订单行项目有产品的订单ID List ordIdList = new List(); //显微镜降级,定义一个map用于接收最下面的levelcheck方法传来的MAP。 Map levelMap = new Map(); For (Order newOrder: newList) { if (newOrder.UpdateWithAG__c && newOrder.CrossCooperativeProject__c && (newOrder.SplitRatio__c == null || newOrder.SplitRatio__c == '')) { newOrder.addError('请填写业绩拆分比例。'); } Order oldOrder = oldMap.get(newOrder.Id); //显微镜降级 if (newOrder.ProductSegment__c == 'BS') { ordIdList.add(newOrder.Id); } if (oldOrder.ApproveStatus__c != newOrder.ApproveStatus__c && (newOrder.ApproveStatus__c == 'Completed' || newOrder.ApproveStatus__c == 'Completed2' || newOrder.ApproveStatus__c == 'CompletedC' || newOrder.ApproveStatus__c == 'CompletedS' )) { ownerIdList.add(newOrder.OpportunityOwnerId__c); orderToOwner.put(newOrder.Id, newOrder.OpportunityOwnerId__c); } if (newOrder.Description != null && newOrder.Description.length() > 0) { newOrder.Description += ' \r\n '; } if (newOrder.Description == null) { newOrder.Description = ''; } if (newOrder.SP_151__c == true && oldOrder.SP_151__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_151__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_161__c == true && oldOrder.SP_161__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_161__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_171__c == true && oldOrder.SP_171__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_171__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_191__c == true && oldOrder.SP_191__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_191__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_201__c == true && oldOrder.SP_201__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_201__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_202__c == true && oldOrder.SP_202__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_202__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_21__c == true && oldOrder.SP_21__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_21__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_22__c == true && oldOrder.SP_22__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_22__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_41__c == true && oldOrder.SP_41__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_41__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_61__c == true && oldOrder.SP_61__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_61__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_81__c == true && oldOrder.SP_81__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_81__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_181__c == true && oldOrder.SP_181__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_181__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_33__c == true && oldOrder.SP_33__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_33__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_11__c == true && oldOrder.SP_11__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_11__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_901__c == true && oldOrder.SP_901__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_901__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_111__c == true && oldOrder.SP_111__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_111__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_101__c == true && oldOrder.SP_101__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_101__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_106__c == true && oldOrder.SP_106__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_106__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_107__c == true && oldOrder.SP_107__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_107__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.Theoinp__c == true && oldOrder.Theoinp__c == false) { newOrder.Description += sObjectFieldMaps.get('Theoinp__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_745__c == true && oldOrder.SP_745__c == false) { newOrder.Description += sObjectFieldMaps.get('SP_745__c').getDescribe().getLabel() + ' \r\n '; } if (newOrder.SP_151__c == false && oldOrder.SP_151__c == true) { newOrder.Description = newOrder.Description.replace(sObjectFieldMaps.get('SP_151__c').getDescribe().getLabel() + ' \r\n ', ''); } if (newOrder.SP_161__c == false && oldOrder.SP_161__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_161__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_171__c == false && oldOrder.SP_171__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_171__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_191__c == false && oldOrder.SP_191__c == true) { newOrder.Description = newOrder.Description.replace(sObjectFieldMaps.get('SP_191__c').getDescribe().getLabel() + ' \r\n ', ''); } if (newOrder.SP_201__c == false && oldOrder.SP_201__c == true) { newOrder.Description = newOrder.Description.replace(sObjectFieldMaps.get('SP_201__c').getDescribe().getLabel() + ' \r\n ', ''); } if (newOrder.SP_202__c == false && oldOrder.SP_202__c == true) { newOrder.Description = newOrder.Description.replace(sObjectFieldMaps.get('SP_202__c').getDescribe().getLabel() + ' \r\n ', ''); } if (newOrder.SP_21__c == false && oldOrder.SP_21__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_21__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_22__c == false && oldOrder.SP_22__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_22__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_41__c == false && oldOrder.SP_41__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_41__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_61__c == false && oldOrder.SP_61__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_61__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_81__c == false && oldOrder.SP_81__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_81__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_181__c == false && oldOrder.SP_181__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_181__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_33__c == false && oldOrder.SP_33__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_33__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_11__c == false && oldOrder.SP_11__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_11__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_901__c == false && oldOrder.SP_901__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_901__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_111__c == false && oldOrder.SP_111__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_111__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_101__c == false && oldOrder.SP_101__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_101__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_106__c == false && oldOrder.SP_106__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_106__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_107__c == false && oldOrder.SP_107__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_107__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.Theoinp__c == false && oldOrder.Theoinp__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('Theoinp__c').getDescribe().getLabel() + ' \r\n '); } if (newOrder.SP_745__c == false && oldOrder.SP_745__c == true) { newOrder.Description = newOrder.Description.remove(sObjectFieldMaps.get('SP_745__c').getDescribe().getLabel() + ' \r\n '); } } //显微镜降级 if(OrderDivisionController.OrderDivision == false){ levelMap = levelCheck(ordIdList); } //for() Map copyUserMap = new Map([ SELECT Id, Name, SalesAsistManager__c, BusinessDepOwner_Tax__c, BusinessDepOwner_WithoutTax__c, SalesManager__c, AsistGenManger__c, CRM_Owner__c, BS_AsistGenManger__c,BS_AsistBGenManger__c,BS_BDepartment__c,BS_GeneralManager__c,BS_INDepartment__c,BS_Department__c,BS_Manager__c FROM User WHERE Id IN :ownerIdList ]); for (Order newOrder : newList) { Order oldOrder = oldMap.get(newOrder.Id); if (oldOrder.ApproveStatus__c != newOrder.ApproveStatus__c && (newOrder.ApproveStatus__c == 'Completed' || newOrder.ApproveStatus__c == 'Completed2' || newOrder.ApproveStatus__c == 'CompletedC' || newOrder.ApproveStatus__c == 'CompletedS' )) { // WLIG-C253VM NDT与ANI的合同,发送给 营业管理部担当 START if ('NDT'.equals(newOrder.ProductSegment__c) || 'ANI'.equals(newOrder.ProductSegment__c)) { String HaiXingYue = System.Label.NDT_ANI_Addressee_HaiXingYue; String WangJingQi = System.Label.NDT_ANI_Addressee_WangJingQi; String ZhenJiaLi = System.Label.NDT_ANI_Addressee_ZhenJiaLi; String ShangYun = System.Label.NDT_ANI_Addressee_ShangYun; if (String.isNotBlank(HaiXingYue) && HaiXingYue.indexOf(newOrder.DealerId__c) >= 0) { newOrder.NDT_ANI_Addressee__c = HaiXingYue.indexOf(';') >= 0 ?HaiXingYue.split(';')[1]:null; } else if (String.isNotBlank(WangJingQi) && WangJingQi.indexOf(newOrder.DealerId__c) >= 0 ) { newOrder.NDT_ANI_Addressee__c = WangJingQi.indexOf(';') >= 0 ?WangJingQi.split(';')[1]:null; } else if (String.isNotBlank(ZhenJiaLi) && ZhenJiaLi.indexOf(newOrder.DealerId__c) >= 0 ) { newOrder.NDT_ANI_Addressee__c = ZhenJiaLi.indexOf(';') >= 0 ?ZhenJiaLi.split(';')[1]:null; } else if (String.isNotBlank(ShangYun) && ShangYun.indexOf(newOrder.DealerId__c) >= 0 ) { newOrder.NDT_ANI_Addressee__c = ShangYun.indexOf(';') >= 0 ?ShangYun.split(';')[1]:null; } } // WLIG-C253VM NDT与ANI的合同,发送给 营业管理部担当 END User u = copyUserMap.get(orderToOwner.get(newOrder.Id)); if (u != null && (u.SalesAsistManager__c != null || u.BusinessDepOwner_Tax__c != null || u.BusinessDepOwner_WithoutTax__c != null || u.SalesManager__c != null || u.AsistGenManger__c != null)) { newOrder.SalesOwner_BS__c = newOrder.OpportunityOwnerId__c; newOrder.SalesAsistManager_BS__c = u.SalesAsistManager__c == null ? u.Id : u.SalesAsistManager__c; // 当黄平江的IE完税合同,以下省份业务部审批人为郑轶盈 2018/11/30 if (newOrder.ProductSegment__c == 'IE' && u.Id == '00528000000YVFs' && (newOrder.Province__c == '河南' || newOrder.Province__c == '山东' || newOrder.Province__c == '广东' || newOrder.Province__c == '福建' || newOrder.Province__c == '重庆' || newOrder.Province__c == '湖南' || newOrder.Province__c == '湖北')) { //2018/1/31 IE华南,南方,北方 郑->阙 newOrder.BusinessDepOwnerTax_BS__c = '0050K000009Qbjg'; } else { newOrder.BusinessDepOwnerTax_BS__c = u.BusinessDepOwner_Tax__c == null ? u.Id : u.BusinessDepOwner_Tax__c; //newOrder.BusinessDepOwnerTax_BS__c = '0050K000009Qbjg'; } // 当黄平江的IE完税合同其他省份,业务部审批人为阙文洁 2018/11/30 // RVI完税合同业务部审批人修改 2017/5/4 // if (newOrder.ProductSegment__c == 'RVI' && (newOrder.Area_RVI_Approve__c == '华东' || newOrder.Area_RVI_Approve__c == '西南' // )){ // newOrder.BusinessDepOwnerTax_BS__c = '00528000000YSW5'; // } // RVI完税合同业务部审批人修改 2017/5/4 // else {newOrder.BusinessDepOwnerTax_BS__c = u.BusinessDepOwner_Tax__c == null ? u.Id : u.BusinessDepOwner_Tax__c;} newOrder.BusinessDepOwnerWithoutTax_BS__c = u.BusinessDepOwner_WithoutTax__c == null ? u.Id : u.BusinessDepOwner_WithoutTax__c; newOrder.BS_Manager_BS__c = u.BS_Manager__c == null ? u.Id : u.BS_Manager__c; newOrder.SalesManager_BS__c = u.SalesManager__c == null ? u.Id : u.SalesManager__c; newOrder.AsistGenManger_BS__c = u.AsistGenManger__c == null ? u.Id : u.AsistGenManger__c; newOrder.CRM_Owner__c = u.CRM_Owner__c == null ? u.Id : u.CRM_Owner__c; if (newOrder.ProductSegment__c == 'BS') { newOrder.BS_Manager_BS__c = u.BS_Manager__c == null ? u.Id : u.BS_Manager__c; newOrder.BS_Department_BS__c = u.BS_Department__c == null ? u.Id : u.BS_Department__c; newOrder.BS_INDepartment_BS__c = u.BS_INDepartment__c == null ? u.Id : u.BS_INDepartment__c; newOrder.BS_GeneralManager_BS__c = u.BS_GeneralManager__c == null ? u.Id : u.BS_GeneralManager__c; newOrder.BS_BDepartment_BS__c = u.BS_BDepartment__c == null ? u.Id : u.BS_BDepartment__c; newOrder.BS_AsistBGenManger_BS__c = u.BS_AsistBGenManger__c == null ? u.Id : u.BS_AsistBGenManger__c; newOrder.BS_AsistGenManger_BS__c = u.BS_AsistGenManger__c == null ? u.Id : u.BS_AsistGenManger__c; newOrder.BS_MandAGM__c = u.BS_Manager__c == u.BS_AsistGenManger__c ? true : false; newOrder.BS_AGMandD__c = u.BS_AsistGenManger__c == u.BS_Department__c ? true : false; newOrder.BS_DandAB__c = u.BS_Department__c == u.BS_AsistBGenManger__c ? true : false; newOrder.BS_ABGandBD__c = u.BS_AsistBGenManger__c == u.BS_BDepartment__c ? true : false; newOrder.BS_BDandIND__c = u.BS_BDepartment__c == u.BS_INDepartment__c ? true : false; newOrder.BS_INDandGM__c = u.BS_INDepartment__c == u.BS_GeneralManager__c ? true : false; } } if (newOrder.ProductSegment__c != 'BS') { newOrder.SalesOwner_BS__c = newOrder.OpportunityOwnerId__c; } } //王鹏伟新加,非OT_IT用户更新合同时记录最后更新时间和更新用户 if (UserInfo.getUserId().substring(0,15) != '00528000004ooQW') { newOrder.OrderUpdateDateTime__c = Datetime.now(); newOrder.OrderUpdateUser__c = UserInfo.getUserId(); } //if (newOrder.RecordTypeId == '01228000000NJt8') { if ((newOrder.ProductSegment__c == 'BS' && newOrder.Is_TAX__c == true && newOrder.AccoutMatketD__c == 'Clinical') && (newOrder.confirm__c == false || (newOrder.confirm__c && String.isNotBlank(newOrder.original_order__c) && !'OrderPass'.equals(newOrder.ApproveStatus__c)))) { //显微镜降级 if(OrderDivisionController.OrderDivision == false){ newOrder.Level_Category__c = levelMap.get(newOrder.id); } } //} } } // Added by hanchao for profitcaculation check public static void ProfitApproveCheck(List newList, Map newMap, List oldList, Map oldMap) { //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 //String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); for (Order newOrder : newList) { Order oldOrder = oldMap.get(newOrder.Id); // String profileId = UserInfo.getProfileId().subString(0,15); // if (profileId.subString(0,15) == System.label.Business_department && newOrder.Discount_D__c != null && newOrder.BusinessOwner_IsApproved__c == true && // newOrder.BusinessOwner_IsApproved__c != oldOrder.BusinessOwner_IsApproved__c && (newOrder.Ben_2__c == null || newOrder.Ben_3__c == null // || newOrder.Ben_4__c == null || newOrder.Ben_5__c == null || newOrder.Ben_6__c == null || newOrder.Ben_7__c == null)) { // newOrder.addError('有折扣时,业务部人员需要填写利益计算值。'); // } if ( new_profileId.subString(0, 15) == System.label.Business_department && newOrder.ApproveStatus__c == 'OrderPass' && newOrder.ApproveStatus__c != oldOrder.ApproveStatus__c && (newOrder.OrderDate__c == null || newOrder.SAP_Contract__c == null)) { newOrder.addError('批准订单时,业务部人员必须填写SAP订单编号和订单日。'); } } } // Added by hanchao for trade management category check 171016 public static void TradeMagCategoryCheck(List newList, Map newMap, List oldList, Map oldMap) { //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); for (Order newOrder : newList) { Order oldOrder = oldMap.get(newOrder.Id); // String profileId = UserInfo.getProfileId().subString(0,15); if (new_profileId.subString(0, 15) == System.label.BusinessMagDep && (newOrder.ApproveStatus__c == 'OrderSubmit' || newOrder.ApproveStatus__c == 'OrderDraft') && newOrder.BusMagApp__c == true && newOrder.BusMagApp__c != oldOrder.BusMagApp__c ) { if (newOrder.TradeMagCategory__c == null) { newOrder.addError('批准订单时,业务管理部人员必须选择贸易管理客户分类。'); } else if ((newOrder.TradeMagCategory__c == 'B' || newOrder.TradeMagCategory__c == 'C' || newOrder.TradeMagCategory__c == 'C-') && newOrder.TradeMagNo__c == null) { newOrder.addError('贸易管理客户分类为B,C或C-时,必须输入贸易管理编号。'); } } } } // add by hanchao 2017/02/09 public static void BackToPreStatus(List newList, Map newMap, List oldList, Map oldMap) { //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是15位的 String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15)); for (Order newOrder : newList) { Order oldOrder = oldMap.get(newOrder.Id); // String profileId = UserInfo.getProfileId(); if (newOrder.BackToPreStatus__c != oldOrder.BackToPreStatus__c && newOrder.BackToPreStatus__c == true) { newOrder.ApproveStatus__c = newOrder.BeforeSubmitStatus__c; newOrder.RecordTypeId = newOrder.BeforeSubmitRecordType__c; newOrder.BackToPreStatus__c = false; } if ((newOrder.SpecialDeliveryAccount_D__c != oldOrder.SpecialDeliveryAccount_D__c || newOrder.SpecialDeliveryContact2_D__c != oldOrder.SpecialDeliveryContact2_D__c) && newOrder.ApproveStatus__c == 'OrderPass') { newOrder.SpecialDeliveryAccount__c = newOrder.SpecialDeliveryAccount_D__c; newOrder.SpecialDeliveryContact2__c = newOrder.SpecialDeliveryContact2_D__c; } } } public static void setOpportunity(List newList, Map newMap, List oldList, Map oldMap) { /*if(StaticParameter.OrderTriggerIsUpdate){ //StaticParameter.OrderTriggerIsUpdate = false; return; }*/ system.debug('@#@#@#@#'+StaticParameter.OrderTriggerIsUpdate); List updList = new List(); Map oppMap = new Map(); for (Order newOrder : newList) { Order oldOrder = oldMap.get(newOrder.Id); System.debug(newOrder.Name); System.debug(oldOrder.Name); if( StaticParameter.temp == false){ Opportunity opp = new Opportunity(); opp.Id = newOrder.OpportunityId; if (newOrder.OrderDate__c != oldOrder.OrderDate__c) { opp.Order_Date__c = newOrder.OrderDate__c; } if (newOrder.DeliveryTime__c != oldOrder.DeliveryTime__c) { opp.DeliveryDate__c = newOrder.DeliveryTime__c; } System.debug(newOrder.Name); System.debug(oldOrder.Name); if (newOrder.Name != oldOrder.Name) { opp.InquiryResult__c = newOrder.Name; } if(newOrder.ProductSegment__c == 'BS' && newOrder.SubDealer__c != oldOrder.SubDealer__c){ opp.SubDealer__c = newOrder.SubDealer__c; } opp.CanChangeOpp__c = (newOrder.ApproveStatus__c== 'OrderSubmit' || newOrder.ApproveStatus__c == 'OrderPass') ? false : true; opp.OrderId__c = newOrder.Id; // oppMap.put(newOrder.OpportunityId,opp); String oppId = newOrder.OpportunityId; // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 Start if(String.isNotBlank(oppId)){ oppMap.put(newOrder.OpportunityId,opp); } // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 End // oppMap.put(newOrder.OpportunityId,opp); system.debug('@@@@@@@@@@@@@@@@@!!!!'+opp); //updList.add(opp); } //王鹏伟新加开始 贸易管理客户分类,询价合同保持一致,合同修改更新询价 if(oldOrder.TradeMagCategory__c != newOrder.TradeMagCategory__c){ //更新询价跳过询价更新后的trigger StaticParameter.OpportunityTriggerIsUpdate = true; if(oppMap.containsKey(newOrder.OpportunityId)){ oppMap.get(newOrder.OpportunityId).customerType__c = newOrder.TradeMagCategory__c; }else{ // Opportunity opp = new Opportunity(); // opp.Id = newOrder.OpportunityId; // opp.customerType__c = newOrder.TradeMagCategory__c; // oppMap.put(newOrder.OpportunityId,opp); // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 Start String oppId = newOrder.OpportunityId; if(String.isNotBlank(oppId)){ Opportunity opp = new Opportunity(); opp.Id = newOrder.OpportunityId; opp.customerType__c = newOrder.TradeMagCategory__c; oppMap.put(newOrder.OpportunityId,opp); } // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 End } } //王鹏伟新加结束 贸易管理客户分类,询价合同保持一致,合同修改更新询价 // 王鹏伟 合同是IE,3.COMPO勾选,更新对应询价condition__c字段 // 开始 if(newOrder.ProductSegment__c=='IE' && newOrder.IE_SP8_D__c != oldOrder.IE_SP8_D__c && String.valueOf(newOrder.Status__c) == 'Active'){ System.debug('修改合同更新询价 COMPO'); if(oppMap.containsKey(newOrder.OpportunityId)){ if(newOrder.IE_SP8_D__c){ oppMap.get(newOrder.OpportunityId).condition__c = 'Y'; }else{ oppMap.get(newOrder.OpportunityId).condition__c = ''; } }else{ // Opportunity opp1 = new Opportunity(); // opp1.Id = newOrder.OpportunityId; // if(newOrder.IE_SP8_D__c){ // opp1.condition__c = 'Y'; // }else{ // opp1.condition__c = ''; // } // updList.add(opp1); String opp1Id = newOrder.OpportunityId; // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 Start if (String.isNotBlank(opp1Id)) { Opportunity opp1 = new Opportunity(); opp1.Id = opp1Id; if(newOrder.IE_SP8_D__c){ opp1.condition__c = 'Y'; }else{ opp1.condition__c = ''; } updList.add(opp1); } // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 End } } //王鹏伟 结束 //王鹏伟 开始 //询价关联的合同审批完成,有SAP合同编号和订单日 询价停止发送邮件(不再对询价更新进行检查跟踪) if((newOrder.ApproveStatus__c == 'OrderPass' && newOrder.ApproveStatus__c != oldOrder.ApproveStatus__c) || (newOrder.OrderDate__c !=null && newOrder.SAP_Contract__c!=null ) &&(newOrder.OrderDate__c != oldOrder.OrderDate__c || newOrder.SAP_Contract__c != oldOrder.SAP_Contract__c ) && StaticParameter.OpportunityTriggerIsUpdate == false){ System.debug('Order StaticParameter.OpportunityTriggerIsUpdate:'+StaticParameter.OpportunityTriggerIsUpdate); StaticParameter.OpportunityTriggerIsUpdate = true; if(oppMap.containsKey(newOrder.OpportunityId)){ oppMap.get(newOrder.OpportunityId).IsSendEmail__c = false; }else{ // Opportunity opp1 = new Opportunity(); // opp1.Id = newOrder.OpportunityId; // opp1.IsSendEmail__c = false; // updList.add(opp1); String opp1Id = newOrder.OpportunityId; // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 Start if (String.isNotBlank(opp1Id)) { Opportunity opp1 = new Opportunity(); opp1.Id = newOrder.OpportunityId; opp1.IsSendEmail__c = false; updList.add(opp1); } // 因订单数据中包含有 没有询价的历史数据 特此处理 XHL 20210705 End } } //询价关联的合同审批完成,有SAP合同编号和订单日 询价停止发送邮件(不再对询价更新进行检查跟踪) //王鹏伟 结束 } updList.addAll(oppMap.values()); if (updList.size() > 0){ /* StaticParameter.OppChangeopp = true; StaticParameter.OppCanChangeOpp = true; StaticParameter.temp = true;*/ for(Opportunity o : updList){ System.debug(o); } update updList; } } public static void setQuote(List newList, Map newMap, List oldList, Map oldMap) { /*if(StaticParameter.OrderTriggerIsUpdate){ //StaticParameter.OrderTriggerIsUpdate = false; return; }*/ List updList = new List(); List updList2 = new List(); for (Order newOrder : newList) { Order oldOrder = oldMap.get(newOrder.Id); if (newOrder.QuoteId != null && (newOrder.ApproveStatus__c != oldOrder.ApproveStatus__c && newOrder.ApproveStatus__c == 'Reject' || newOrder.ProductListApproveStatus__c != oldOrder.ProductListApproveStatus__c && newOrder.ProductListApproveStatus__c == 'Reject' ) ) { Quote quo = new Quote(Id = newOrder.QuoteId, Is_Decided__c = false); updList.add(quo); Opportunity opp = new Opportunity(Id = newOrder.OpportunityId, Is_Decided__c = false); updList2.add(opp); } } if (updList.size() > 0) update updList; if (updList2.size() > 0) update updList2; } public static void setTransferValue(List newList, Map newMap, List oldList, Map oldMap) { List oppidList = new List(); List quoidList = new List(); Boolean updateOrderAccount = false; Boolean hasBS = false; Boolean sharedFlag = false; for (Order target : newList) { oppIdList.add(target.OpportunityId); quoidList.add(target.QuoteId); if(Trigger.isUpdate ){ Order old = oldMap.get(target.Id); // 合同客户或最终用户变更进行数据验证 if (old.AccountId != target.AccountId || old.EndUserD__c != target.EndUserD__c) { updateOrderAccount = true; } if (target.SharedFlag__c && !old.SharedFlag__c) { sharedFlag = true; } } else if (Trigger.isInsert) { updateOrderAccount = true; } } Map oppAccountMap = new Map(); Map oppMap = new Map(); List oppList = [select id, Amount, Quote_Discount__c, Quote_Subtotal__c, Quote_PaymentTerms_Text__c, Quote_Warranty__c, ProductSegment__c, Quote_CustomPrice__c, Quote_ShipmentTerm__c, Quote_ShipmentTerm2__c, Quote_TotalPrice__c, IE_local_cost__c,AccountId, Account.MarketingStrategyCreated__c,Account.Province__c ,Account.Sub_Use__c ,Account.AreaForIEApproveText__c , Account.serviceCreate__c ,Account.ProvinceStr__c from Opportunity where id = :oppidList]; for (Opportunity opp : oppList) { oppMap.put(opp.id, opp); oppAccountMap.put(opp.Id,opp.AccountId); if (opp.ProductSegment__c == 'BS') { hasBS = true; } } if (updateOrderAccount && OrderDivisionController.OrderDivision == false) { // WLIG-C3M68P XHL 20210607 Start // 新建与变更合同客户、最终用户时,和询价对比客户、最终用户,若不相同直接报错提醒 CustomerConsistency(oppidList,oppAccountMap,newList); // WLIG-C3M68P XHL 20210607 End } Map quoMap = new Map(); if (hasBS) { List quoList = [select id, Discount, Subtotal, Warranty__c, Custom_Price_Total_Text__c, Shipment_Term__c, Shipment_Term2__c, TotalPrice from Quote where id = :quoidList]; for (Quote quo : quoList) { quoMap.put(quo.id, quo); } } for (Order target : newList) { Opportunity opp = oppMap.get(target.OpportunityId); Quote quo = quoMap.get(target.QuoteId); if (opp != null) { target.MarketingStrategyCreated__c = opp.Account.MarketingStrategyCreated__c ;//市场战略部创建(客户) target.Province_acc__c = opp.Account.Province__c ;//省(客户) target.Sub_Use__c = opp.Account.Sub_Use__c ;//Sub Use(客户) target.AreaForIEApproveText__c = opp.Account.AreaForIEApproveText__c ;//地区(IE审批文本) target.serviceCreate__c = opp.Account.serviceCreate__c ;//是否服务部创建(客户) target.ProvinceStr__c = opp.Account.ProvinceStr__c ;//省份文本(客户) } if (target.Status__c != 'Active') { continue; } if (quo != null) { target.Discount_D__c = quo.Discount; //target.Olympus_Price_BeforeDiscount_D__c = quo.Subtotal; target.Olympus_Price_BeforeDiscount_D__c = opp.Quote_Subtotal__c; target.PaymentCondition_D__c = opp.Quote_PaymentTerms_Text__c; Decimal warranty = quo.Warranty__c; target.SpecialWarranty_D__c = warranty == null ? '' : warranty.format(); target.CustomerContractPriceD__c = opp.Quote_CustomPrice__c == null ? 0 : opp.Quote_CustomPrice__c; target.Shipment_Term_D__c = quo.Shipment_Term__c; target.Shipment_Term2_D__c = quo.Shipment_Term2__c; //Decimal totalPrice = opp.Amount; Decimal totalPrice = opp.Quote_TotalPrice__c; if (target.ProductSegment__c == 'BS' && target.TradeType__c == System.Label.Trade_Type) { target.OlympusContractPricesD__c = totalPrice.setScale(2, System.RoundingMode.HALF_UP); } else { target.OlympusContractPricesD__c = totalPrice.setScale(0, System.RoundingMode.HALF_UP); } //target.OlympusContractPrices__c = target.OlympusContractPricesD__c; } else if (target.ProductSegment__c == 'IE' || target.ProductSegment__c == 'RVI' || target.ProductSegment__c == 'NDT' || target.ProductSegment__c == 'ANI') { target.Discount_D__c = opp.Quote_Discount__c; target.Olympus_Price_BeforeDiscount_D__c = opp.Quote_Subtotal__c; target.PaymentCondition_D__c = opp.Quote_PaymentTerms_Text__c; Decimal warranty = opp.Quote_Warranty__c; target.SpecialWarranty_D__c = warranty == null ? '' : warranty.format(); target.CustomerContractPriceD__c = opp.Quote_CustomPrice__c == null ? 0 : opp.Quote_CustomPrice__c; target.Shipment_Term_D__c = opp.Quote_ShipmentTerm__c; target.Shipment_Term2_D__c = opp.Quote_ShipmentTerm2__c; Decimal totalPrice = opp.Quote_TotalPrice__c; if (target.ProductSegment__c != 'NDT' && target.ProductSegment__c != 'ANI') { target.OlympusContractPricesD__c = totalPrice.setScale(0, System.RoundingMode.HALF_UP); } else { target.OlympusContractPricesD__c = totalPrice; } //target.OlympusContractPrices__c = target.OlympusContractPricesD__c; target.Cost_D__c = opp.IE_local_cost__c; } else if (target.ProductSegment__c == 'BS' && target.TradeType__c == System.Label.Trade_Type) { Decimal totalPrice = opp.Quote_TotalPrice__c; target.OlympusContractPricesD__c = totalPrice.setScale(2, System.RoundingMode.HALF_UP); } } } // Add by hanchao 201708101 for opportunity cancel lost control public static void Cancellostcontrol(List newList, Map newMap, List oldList, Map oldMap) { /*if(StaticParameter.OrderTriggerIsUpdate){ //StaticParameter.OrderTriggerIsUpdate = false; return; }*/ List updList = new List(); Map updMap = new Map(); for (Order newOrd : newList) { Order oldOrd = oldMap == null ? new Order() : oldMap.get(newOrd.Id); if (newOrd.Status__c != oldOrd.Status__c) { if (updMap.containsKey(newOrd.OpportunityId) == false) { updMap.put(newOrd.OpportunityId, new Opportunity(Id = newOrd.OpportunityId, ActiveContract__c = false)); } Opportunity opp = updMap.get(newOrd.OpportunityId); if (newOrd.Status__c == 'Active') { opp.ActiveContract__c = true; } } } updList = updMap.values(); if (updList.size() > 0) update updList; } // Add by hanchao 201708102 for opportunity automatically close public static void OppAutoClose(List newList, Map newMap, List oldList, Map oldMap) { /*if(StaticParameter.OrderTriggerIsUpdate){ //StaticParameter.OrderTriggerIsUpdate = false; return; }*/ List updList = new List(); Map updMap = new Map(); for (Order newOrd : newList) { Order oldOrd = oldMap == null ? new Order() : oldMap.get(newOrd.Id); if (newOrd.AllDelivery__c >= 1 && newOrd.AllDelivery__c != oldOrd.AllDelivery__c && updMap.containsKey(newOrd.OpportunityId) == false) { updMap.put(newOrd.OpportunityId, newOrd.OpportunityId); Opportunity opp = new Opportunity(); opp.Id = newOrd.OpportunityId; opp.StageName = 'Closed Won'; updList.add(opp); } } if (updList.size() > 0) update updList; } // Add by hanchao 20181210 for productconfigchange /*public static void Productconfigchange(List newList, Map newMap, List oldList, Map oldMap) { List updList = new List(); Map updMap = new Map(); for (Order newOrd : newList){ Order oldOrd = oldMap == null ? new Order() : oldMap.get(newOrd.Id); if (newOrd.ProductConfig_D__c != oldOrd.ProductConfig_D__c && oldOrd.ProductConfig_D__c != null) { Order ord1 = new Order(); ord1.Id = newOrd.Id; ord1.ProductConfig_IsChanged__c = true; updList.add(ord1); } } if (updList.size() > 0) update updList; }*/ public static void setRecordTypeHidden(List newList, Map newMap, List oldList, Map oldMap) { system.debug('set hidden type'); List odrIds = new List(); for (Order odr : newList) { Order oldOrd = oldMap == null ? new Order() : oldMap.get(odr.Id); if (odr.RecordTypeId != oldOrd.RecordTypeId && (odr.RecordTypeId == System.Label.RT_Contract_BS_Tax || odr.RecordTypeId == System.Label.RT_Contract_BS_Tax_Approval || odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax || odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax_Approval)) { odrIds.add(odr.Id); } } if (odrIds.size() == 0) return; Map hiddenFlagMap = new Map(); List oiList = [select id, OrderId, PricebookEntry.Hidden_flag__c from OrderItem where OrderId = :odrIds order by OrderId]; for (OrderItem oi : oiList) { if (hiddenFlagMap.containsKey(oi.OrderId) == false) { hiddenFlagMap.put(oi.OrderId, false); } if (oi.PricebookEntry.Hidden_flag__c == true) { hiddenFlagMap.put(oi.OrderId, true); } } for(Order o : newList){ if(StaticParameter.specialDealerMap.containsKey(o.DealerId__c.subString(0,15))){ hiddenFlagMap.put(o.Id, true); } } system.debug('hiddenFlagMap'+hiddenFlagMap); for (Order odr : newList) { Order oldOrd = oldMap == null ? new Order() : oldMap.get(odr.Id); if (odr.RecordTypeId != oldOrd.RecordTypeId && (odr.RecordTypeId == System.Label.RT_Contract_BS_Tax || odr.RecordTypeId == System.Label.RT_Contract_BS_Tax_Approval || odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax || odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax_Approval)) { if (hiddenFlagMap.get(odr.Id) == true) { if (odr.RecordTypeId == System.Label.RT_Contract_BS_Tax) { odr.RecordTypeId = System.Label.RT_Contract_BS_Tax_hidden; } else if (odr.RecordTypeId == System.Label.RT_Contract_BS_Tax_Approval) { odr.RecordTypeId = System.Label.RT_Contract_BS_Tax_Approval_hidden; } else if (odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax) { odr.RecordTypeId = System.Label.RT_Contract_BS_WithoutTax_hidden; } else if (odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax_Approval) { odr.RecordTypeId = System.Label.RT_Contract_BS_WithoutTax_hidden_Approval; } } else if (hiddenFlagMap.get(odr.Id) == false) { if (odr.RecordTypeId == System.Label.RT_Contract_BS_Tax_hidden) { odr.RecordTypeId = System.Label.RT_Contract_BS_Tax; } else if (odr.RecordTypeId == System.Label.RT_Contract_BS_Tax_Approval_hidden) { odr.RecordTypeId = System.Label.RT_Contract_BS_Tax_Approval; } else if (odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax_hidden) { odr.RecordTypeId = System.Label.RT_Contract_BS_WithoutTax; } else if (odr.RecordTypeId == System.Label.RT_Contract_BS_WithoutTax_hidden_Approval) { odr.RecordTypeId = System.Label.RT_Contract_BS_WithoutTax_hidden; } } } } } public static void setfile(List newList, Map newMap, List oldList, Map oldMap) { if (newList[0].ProductSegment__c == 'BS') { String targetlist4 = newList[0].QuoteId; String ordId = newList[0].Id; Map> dqpMap = new Map>(); List dqpList = new List(); dqpList = [select id, DecideOpportunity__c, DecideQuote__c from DecideQuoteProductSet__c where DecideQuote__c = :targetlist4]; system.debug('090909' + dqpList); for (DecideQuoteProductSet__c dqp : dqpList) { if (dqpMap.containsKey(dqp.DecideQuote__c)) { dqpMap.get(dqp.DecideQuote__c).add(dqp); } else { dqpMap.put(dqp.DecideQuote__c, new List()); dqpMap.get(dqp.DecideQuote__c).add(dqp); } } system.debug('123123000' + dqpMap); List updateList = new List(); if (dqpMap.size() > 0 && dqpMap.containsKey(targetlist4)) { // DecideQuoteProductSet__c temp = dqpMap.get(o.OpportunityId); for (DecideQuoteProductSet__c temp : dqpMap.get(targetlist4)) { temp.DecideOrder__c = ordId; } updateList.addAll(dqpMap.get(targetlist4)); } if (updateList.size() > 0) update updateList; List ospList = [select id from order_Single_product__c where Order__c = :ordId and OrderProduct__c = null]; if (ospList.size() > 0 ) { delete ospList; } } } /** * [radiation description]产品辐射 * @param newList [description] * @param newMap [description] * @param oldList [description] * @param oldMap [description] * @param updateFlag [description] */ public static void radiation(List newList, Map newMap, List oldList, Map oldMap, Boolean updateFlag) { for (Order newOrd : newList) { if ( newOrd.ProductSegment__c == 'ANI' && newOrd.TradeType__c == '内贸' && newOrd.BusMagDepRev_F__c) { String orderFounder = newOrd.CreatedById; if ( updateFlag) { // 合同变更 Order oldOrd = oldMap.get(newOrd.Id); // 审批状态 Boolean approveStatus = newOrd.ApproveStatus__c != oldOrd.ApproveStatus__c; if (newOrd.ApproveStatus__c == 'OrderPass') { // 状态 Boolean status = newOrd.Status__c != oldOrd.Status__c && newOrd.Status__c == 'Inactive'; // 合同-变更申请-原合同无效或者手动修改导致合同无效 if (!approveStatus && status) { RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, true,'无效或变更无效',newOrd.LastModifiedById ); } if (oldOrd.ApproveStatus__c == 'OrderDraft') { // WLIG-C3LA29 XHL Start //合同-变更申请-新增合同修改内容→订单草案→订单批准 RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, false,'合同草案中变批准',newOrd.LastModifiedById ); // WLIG-C3LA29 XHL End } } else if ( oldOrd.ApproveStatus__c == 'OrderPass') { // 合同-变更申请-新增合同修改内容→订单批准→订单草案 if (newOrd.ApproveStatus__c == 'OrderDraft' && newOrd.Status__c == 'Active') { if (RadiationUtil.EscapeOrderTriggerHandler) { RadiationUtil.EscapeOrderTriggerHandler = false; RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, true,'合同变更草案中',newOrd.LastModifiedById ); } } } else if (newOrd.ApproveStatus__c == 'OrderSubmit' && newOrd.Status__c == 'Active') { // 合同提交 if ( approveStatus ) { RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, false,'合同提交',newOrd.LastModifiedById ); } } else if (newOrd.ApproveStatus__c == 'OrderSubmit' ) { Boolean status = newOrd.Status__c != oldOrd.Status__c && newOrd.Status__c == 'Inactive'; // 合同提交状态变成无效 if ( status ) { RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, true,'合同提交变无效',newOrd.LastModifiedById ); } } else if (newOrd.ApproveStatus__c == 'CancelPass' && newOrd.Status__c == 'Active') { // 合同-合同批准→→→合同取消 if ( approveStatus && newOrd.BeforeSubmitStatus__c == 'OrderPass') { RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, true,'合同取消',newOrd.LastModifiedById ); } } else if (oldOrd.ApproveStatus__c == 'OrderSubmit' && newOrd.ApproveStatus__c == 'OrderReject' && newOrd.Status__c == 'Active') { // 合同提交→→→合同驳回 RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, true,'合同驳回',newOrd.LastModifiedById ); } else if (oldOrd.ApproveStatus__c == 'OrderSubmit' && newOrd.ApproveStatus__c == 'OrderDraft' && newOrd.Status__c == 'Active') { // 合同提交→→→合同调回 RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, true,'合同调回',newOrd.LastModifiedById ); } } else { // 合同新增-原合同变更申请审批后克隆出来的合同 if (newOrd.ApproveStatus__c == 'OrderPass' && newOrd.Status__c == 'Active' && !newOrd.Is_Already_Splited__c) { RadiationUtil.updateRadiationTypeQuantity(newOrd.Id,orderFounder , newOrd.DealerId__c, false,'合同变更新增',newOrd.LastModifiedById ); } } } } } //王鹏伟新建方法 合同是IE,3.COMPO勾选,更新对应询价condition__c字段 containsKey public static void setOpportunityCOMPO(List newList, Map newMap, List oldList, Map oldMap , Boolean temp){ // ProductSegment__c /* List oppId = new List(); for(Order o:newList){ oppId.add(o.OpportunityId); }*/ System.debug('新建合同更新询价 COMPO'); List oppList = new List(); //List oppNewList = new List(); //oppList = [select Id,condition__c from Opportunity where Id=:oppId]; for(Order o:newList){ Order old = new Order(); if(!temp){ old = oldMap.get(o.Id); } if (o.ProductSegment__c == 'BS' && temp) { Opportunity opp1 = new Opportunity(); opp1.Id = o.OpportunityId; opp1.SubDealer__c = o.SubDealer__c; oppList.add(opp1); } if(o.ProductSegment__c=='IE' && o.Status__c == 'Active' && ( temp || ( !temp && o.IE_SP8_D__c != old.IE_SP8_D__c ))){ Opportunity opp = new Opportunity(); opp.Id = o.OpportunityId; if(o.IE_SP8_D__c){ opp.condition__c = 'Y'; }else{ opp.condition__c = ''; } oppList.add(opp); /*for(Opportunity opp : oppList){ if (o.OpportunityId == opp.Id) { opp.condition__c = '3.COMPO'; oppNewList.add(opp); break; } }*/ } } StaticParameter.OpportunityTriggerIsUpdate = true; if(oppList.size()>0) update oppList; } public static void updateOpportunity(List newList, Map newMap, List oldList, Map oldMap, Boolean updateFlag){ Map updateOpportunityMap = new Map(); for (Order newOrd : newList) { String opportunityId = newOrd.OpportunityId; Opportunity updateOpportunity = new Opportunity(); updateOpportunity.Id = opportunityId; if (updateOpportunityMap.containsKey(opportunityId)) { updateOpportunity = updateOpportunityMap.get(opportunityId); } if (updateFlag) {// 合同更新 // 获取原合同 Order oldOrd = oldMap.get(newOrd.Id); // 合同 无效--->有效 if (oldOrd.Status__c != newOrd.Status__c && 'Active'.equals(newOrd.Status__c)) { // 更新有效合同 updateOpportunity.ActiveOrder__c = newOrd.Id; updateOpportunityMap.put(opportunityId,updateOpportunity); } // 合同 有效--->无效 if (String.isNotBlank(oldOrd.Status__c) && oldOrd.Status__c != newOrd.Status__c && 'Inactive'.equals(newOrd.Status__c)) { // 判断 有效合同字段 是否有值 有值不更新 if (updateOpportunity.ActiveOrder__c == null) { updateOpportunity.ActiveOrder__c = null; updateOpportunityMap.put(opportunityId,updateOpportunity); } } } else {//合同新增 if ('Active'.equals(newOrd.Status__c)) {// 合同有效 updateOpportunity.ActiveOrder__c = newOrd.Id; updateOpportunityMap.put(opportunityId,updateOpportunity); } } } // test(null,null,newList,oldMap); if (updateOpportunityMap != null && updateOpportunityMap.size() > 0) { StaticParameter.OpportunityTriggerIsUpdate = true; StaticParameter.StageProgressBarUpdate = true; update updateOpportunityMap.values(); } } public static void CustomerConsistency(List oppidList,Map oppAccountMap,List newList){ // 获取询价的最终用户 List role_list = new List(); role_list = [select Id,Role,IsPrimary,OpportunityId,ContactId from OpportunityContactRole where OpportunityId = :oppidList and Role = 'End user' and IsPrimary = true]; Map roleMap = new Map(); for(OpportunityContactRole oppor:role_list){ roleMap.put(oppor.OpportunityId,oppor.ContactId); } // 获取系统管理员Id String getUserId = System.label.SystemAdmin1_2_GPI; String errMessage = '客户名或最终用户与询价不一致!'; for(Order orOne:newList){ if (oppAccountMap.containsKey(orOne.OpportunityId)) { System.debug(oppAccountMap.get(orOne.OpportunityId) != orOne.AccountId); System.debug( !roleMap.containsKey(orOne.OpportunityId)); System.debug(orOne.EndUserD__c + '++'+ roleMap.get(orOne.OpportunityId)); if(oppAccountMap.get(orOne.OpportunityId) != orOne.AccountId || !roleMap.containsKey(orOne.OpportunityId) || orOne.EndUserD__c != roleMap.get(orOne.OpportunityId)){ // 获取用户Id String userId = UserInfo.getUserId().subString(0,15); if (String.isNotBlank(getUserId)) { if (getUserId.contains(userId)) { if (String.isNotBlank(orOne.Id)) { throw new ControllerUtil.myException('合同Id:'+orOne.Id+'_'+errMessage); } else { //订单ID没有取到 orOne.addError(errMessage+'1'+orOne.Id); } } else { //自定义标签里面没有当前用户的ID orOne.addError(errMessage + '2'); } } else { //自定义标签没有内容 orOne.addError(errMessage + '3'); } } } } } //检查合同上的等级类别是二类,一类,非监管(等级由高到底),单独一条记录里面的所有产品,放到一个list里面。 //根据订单上的行产品的对应的产品表里的等级类别字段,给订单上的等级类别字段赋值,newList为需要判断的传来的合同的Id。 //产品里的等级类别字段,赋值给订单行项目的 产品的等级类别字段。 public static Map levelCheck(List newList){ //定义个List,存放soql文 List orditemList = new List(); orditemList = [select OrderId,Pro_Level__c from OrderItem where Pro_Level__c <> null and OrderId in : newList]; //定义map,存放订单ID,和上面的提到的List Map> orditemMap = new Map>(); //这个Map存放(Id,等级类别的值) Map orderXMap = new Map(); //给Map里面放入订单ID,以订单ID,存放订单下面的所有产品的等级类别的字段的值 if (orditemList.size()>0) { for (OrderItem orditem: orditemList) { if (orditemMap.containsKey(orditem.OrderId)) { orditemMap.get(orditem.OrderId).add(orditem.Pro_Level__c); }else{ orditemMap.put(orditem.OrderId, new List()); orditemMap.get(orditem.OrderId).add(orditem.Pro_Level__c); } } } //开始逻辑判断,订单产品对应的产品的等级类别只要有二类,订单上的等级类别赋值二类(二类>一类>非监管,依此类推) for (String oe : newList) { if (orditemMap.containsKey(oe)) { if (orditemMap.get(oe).contains('二类')) { orderXMap.put(oe, '二类'); }else if (orditemMap.get(oe).contains('一类')) { orderXMap.put(oe, '一类'); }else{ orderXMap.put(oe, '非监管'); } }else{ orderXMap.put(oe, '非监管'); } } //最后返回一个Map方便别的方法调用 return orderXMap; } /** * [判断合同是一类、二类还是非监管] * @param idList [需要判断的合同的ID] * @return [合同ID和对应的分类] */ /* public static Map CheckProductType (List idList){ //返回参数使用的数据 Map returnMap = new Map(); //参数非空判断 if(idList != null && idList.size() > 0){ //检索合同对应的产品 List oiList = new List(); oiList = [SELECT id,OrderId,PricebookEntry.Product2.Product_ECCode__c FROM OrderItem WHERE OrderId in: idList]; //合同ID和对应合同产品的Map Map> orderMap = new Map>(); for (OrderItem oi : oiList) { //将合同产品于对用的合同ID关联 if (orderMap.containsKey(oi.OrderId)) { orderMap.get(oi.OrderId).add(oi.PricebookEntry.Product2.Product_ECCode__c); } else { orderMap.put(oi.OrderId, new List()); orderMap.get(oi.OrderId).add(oi.PricebookEntry.Product2.Product_ECCode__c); } } //判断合同是一类、二类还是非监管 //对多个合同分别进行处理 for (String id : orderMap.keySet()) { List tempList = orderMap.get(id); if(tempList.contains('二类')){ //如果包含二类,直接标记为二类并返回; returnMap.put(id, '二类'); }else if(tempList.contains('一类')){ //如果包含一类,将标记设置为一类 returnMap.put(id, '一类'); }else{ returnMap.put(id, '非监管'); } } } return returnMap; } */ 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++; 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++; 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++; 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++; } }