Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Description : Manager class for Sold_Service_Modification__c object
- Created by : Tomasz Bogdański (tomasz.bogdanski@enxoo.com)
- Date created : 2016-03-14
- ************************************************************************/
- public without sharing class CPQ_SSM01_Manager {
- public static Schema.DescribeSObjectResult ssmobj = Schema.getGlobalDescribe().get('Sold_Service_Modification__c').getDescribe();
- public static Map<String, Schema.SObjectField> ssmschemaFieldMap = ssmobj.fields.getMap();
- public static Schema.DescribeSObjectResult obj = Schema.getGlobalDescribe().get('Sold_Service__c').getDescribe();
- public static Map<String, Schema.SObjectField> schemaFieldMap = obj.fields.getMap();
- public static Map<Id, String> ssOliMap = new Map<Id, String>();
- public static Map<Id, Sold_Service_Modification__c> alreadyExistingSSM = new Map<Id, Sold_Service_Modification__c>();
- public static Set<String> ssmFields = CPQ_Utils01_SObjectHelperCls.getFieldDescriptions('Sold_Service_Modification__c').keyset();
- //Map used to save SSM related to cease & reprovide action
- public static Map<String, String> ceaseReprovideMap = new Map<String, String>();
- public static Map<Id, Opportunity> oppMap;
- public CPQ_SSM01_Manager(){}
- public static Map<Id, Sold_Service_Modification__c> createSoldServiceModifications(List<CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper> soldServiceProductList, List<CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper> soldServiceComponentList, List<Sold_Service_Modification__c> ssmFromIFC) {
- CPQ_Utils04_RequestStateCls.setOn('STAGE_AUTOMATION');
- Map<Id, Sold_Service_Modification__c> parentSSMMap = new Map<Id, Sold_Service_Modification__c>();
- Map<Id, Sold_Service_Modification__c> soldServiceModMap = new Map<Id, Sold_Service_Modification__c>();
- Set<Id> oppIds = new Set<Id>();
- Set<Id> quoteItemIds = new Set<Id>();
- List<Id> ssProcessedIds = new List<Id>();
- Map<Id, String> ssChildsProcessedIds = new Map<Id, String>(); //component ss id, parent ss id
- List<Id> ssPrevInstanceIds = new List<Id>();
- List<CPQ_QuoteItem__c> quoteItems = new List<CPQ_QuoteItem__c>();
- Map<Id,List<X3rd_Party_Services__c>> ssToTpsMap = new Map<Id,List<X3rd_Party_Services__c>>();
- Map<Id,List<X3rd_Party_Services__c>> ssToTpsChildMap = new Map<Id,List<X3rd_Party_Services__c>>();
- if(soldServiceProductList != null) {
- for(CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper ss : soldServiceProductList) {
- if(!oppIds.contains(ss.soldService.Opp_Link__c)) {
- oppIds.add(ss.soldService.Opp_Link__c);
- }
- ssProcessedIds.add(ss.soldService.Id);
- if(ss.oldSoldService != null && ss.parallelBuild) {
- ssPrevInstanceIds.add(ss.oldSoldService.Id);
- }
- if(ss.quoteItem != null) {
- quoteItems.add(ss.quoteItem);
- }
- }
- }
- if(soldServiceComponentList != null) {
- for(CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper ss : soldServiceComponentList) {
- if(!oppIds.contains(ss.soldService.Opp_Link__c)) {
- oppIds.add(ss.soldService.Opp_Link__c);
- }
- ssProcessedIds.add(ss.soldService.Id);
- ssChildsProcessedIds.put(ss.soldService.CRM_Parent_Sold_Service__c, ss.soldService.CRM_Parent_Sold_Service__c);
- if(ss.oldSoldService != null && ss.parallelBuild) {
- ssPrevInstanceIds.add(ss.oldSoldService.Id);
- }
- if(ss.quoteItem != null) {
- quoteItems.add(ss.quoteItem);
- }
- }
- }
- if(UserInfo.getLastName() == 'Rudnicki') {
- ERR_UTL01_ErrorManagerCls.logError(JSON.serialize(soldServiceComponentList), 'Integration', null, 'C', 'CPQ_SSM01_Manager', 'createSoldServiceModifications', '2.6.1');
- }
- oppMap = new Map<Id, Opportunity>([SELECT Id, PopUp__c, TSIC_Contracting_Company__c, TSIC_Contracting_Company__r.TSIC_Contracting_Company_Name__c, TSIC_Contracting_Company__r.FDC_Code__c FROM Opportunity WHERE Id IN : oppIds]);
- String oldServicesQuery = 'select Renewed_To__r.RFS_Date__c, ' + CPQ_Utils01_SObjectHelperCls.getFieldListForSOQL('Sold_Service__c', null, null) + ' from Sold_Service__c where Id in:ssProcessedIds OR Id in :ssPrevInstanceIds';
- Map<Id, Sold_Service__c> idToServiceMap = new Map<Id, Sold_Service__c>((List<Sold_Service__c>)Database.query(oldServicesQuery));
- //this query fetches only newly created tpses (by any action) to be reattached from sold service to its modification
- for(X3rd_Party_Services__c tps : [SELECT Id, Sold_Service__c, Sold_Service__r.CRM_Parent_Sold_Service__c, Sold_Service_Modification__c, MRE__c, OTE_COGS__c, OTE_Capex__c, TPI_Final_MRE__c, TPI_Final_OTE_COGS__c, Status__c, CurrencyIsoCode FROM X3rd_Party_Services__c WHERE (Sold_Service__c IN :ssProcessedIds OR Sold_Service__c IN :ssPrevInstanceIds) AND Sold_Service_Modification__c = null]) {
- List<X3rd_Party_Services__c> tempList = ssToTpsMap.get(tps.Sold_Service__c);
- if(tempList == null) {
- tempList = new List<X3rd_Party_Services__c>();
- }
- tempList.add(tps);
- // child tpses add
- if (tps.Sold_Service__r.CRM_Parent_Sold_Service__c != null) {
- List<X3rd_Party_Services__c> tempChildList = ssToTpsChildMap.get(tps.Sold_Service__r.CRM_Parent_Sold_Service__c);
- if(tempChildList == null) {
- tempChildList = new List<X3rd_Party_Services__c>();
- }
- tempChildList.add(tps);
- ssToTpsChildMap.put(tps.Sold_Service__r.CRM_Parent_Sold_Service__c, tempChildList);
- }
- ssToTpsMap.put(tps.Sold_Service__c, tempList);
- }
- Map<Id, Sold_Service__c> currentlyUsedSS = new Map<Id, Sold_Service__c>();
- Map<Id, CPQ_QuoteItem__c> quoteItemAttrMap = new Map<Id, CPQ_QuoteItem__c>();
- if(!quoteItems.isEmpty()) {
- for(CPQ_QuoteItem__c items : quoteItems) {
- quoteItemAttrMap.put(items.Quote__r.Opportunity__c, items);
- }
- }
- CPQ_Utils04_RequestStateCls.setOn('SOLD_SERVICE_SYNCED');
- CPQ_Utils04_RequestStateCls.setOn('RUN_SS_ROLLUPS_ONES');
- Boolean fromTrigger = CPQ_Utils04_RequestStateCls.isOn('MODIFICATION') && CPQ_Utils04_RequestStateCls.isOn('SOLD_SERVICE_SYNCED');
- CPQ_Utils04_RequestStateCls.setOn('SOLD_SERVICE_SYNCED');
- CPQ_Utils04_RequestStateCls.setOn('MODIFICATION');
- if(soldServiceProductList != null) {
- parentSSMMap = mapSoldServiceModificationFields(soldServiceProductList, idToServiceMap, quoteItemAttrMap, ssToTpsMap, null, ssToTpsChildMap, ssChildsProcessedIds);
- if(System.isBatch() && CPQ_PRD08_CreateSoldServiceBatchHlpr.ss2ssm != null){
- CPQ_PRD08_CreateSoldServiceBatchHlpr.ss2ssm.putAll(parentSSMMap);
- }
- }
- if(soldServiceComponentList != null) {
- soldServiceModMap = mapSoldServiceModificationFields(soldServiceComponentList, idToServiceMap, quoteItemAttrMap, ssToTpsMap, parentSSMMap, null, null);
- }
- soldServiceModMap.putAll(parentSSMMap);
- if(!fromTrigger) {
- CPQ_Utils04_RequestStateCls.setOff('SOLD_SERVICE_SYNCED');
- CPQ_Utils04_RequestStateCls.setOff('MODIFICATION');
- }
- //if(System.isQueueable()) CPQ_Utils04_RequestStateCls.setOn('DISMANTLE_QUEUEABLE');
- for(Sold_Service_Modification__c ssmIFC : ssmFromIFC){
- if(!soldServiceModMap.containsKey(ssmIFC.Sold_Service__c)){
- soldServiceModMap.put(ssmIFC.Sold_Service__c, ssmIFC);
- }
- else if(ssmIFC.Action__c == 'Change' && ssmIFC.Stage__c == ApplicationConstant.SSM_STAGE_LIVE){
- System.debug('ssmIFC.Stage__c: ' + ssmIFC.Stage__c);
- soldServiceModMap.get(ssmIFC.Sold_Service__c).Stage__c = ssmIFC.Stage__c;
- }
- }
- upsert soldServiceModMap.values();
- /**
- *** Logic used to retrieve SSM for cease & reprovide in order to fill in the lookup field from Cease to Reprovide SSM record
- **/
- List<Sold_Service_Modification__c> ceaseUpdateSSM = new List<Sold_Service_Modification__c>();
- for(Sold_Service_Modification__c ssmRecords : soldServiceModMap.values()) {
- if(ceaseReprovideMap.containsKey(ssmRecords.Upsert_Cease_Key__c)) {
- ssmRecords.TECH_Related_SSM__r = new Sold_Service_Modification__c(Upsert_Cease_Key__c = ceaseReprovideMap.get(ssmRecords.Upsert_Cease_Key__c));
- ceaseUpdateSSM.add(ssmRecords);
- }
- }
- CPQ_Utils04_RequestStateCls.setOn('CPQ_SSM_SoldServiceModificationAllTriggers');
- update ceaseUpdateSSM;
- CPQ_Utils04_RequestStateCls.setOff('CPQ_SSM_SoldServiceModificationAllTriggers');
- return soldServiceModMap;
- }
- /************************************************************************
- Description : creates default modification for new Sold Services on Add operation.
- soldService - Sold Services for which Sold Service Modifications are created
- No of DML stmt : 2
- ************************************************************************/
- public static Map<Id, Sold_Service_Modification__c> mapSoldServiceModificationFields(List<CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper> soldServiceList, Map<Id, Sold_Service__c> idToServiceMap, Map<Id, CPQ_QuoteItem__c> quoteItemAttrMap, Map<Id,List<X3rd_Party_Services__c>> ssToTpsMap, Map<Id, Sold_Service_Modification__c> parentSSM, Map<Id,List<X3rd_Party_Services__c>> ssChildsToTpsMap, Map<Id, String> ssChildsToTPS) {
- Map<Id, Sold_Service_Modification__c> result = new Map<Id, Sold_Service_Modification__c>();
- List<Sold_Service__c> ssToUpdate = new List<Sold_Service__c>();
- Set<Id> ssDuplicates = new Set<Id>();
- List<X3rd_Party_Services__c> tpsToUpdate = new List<X3rd_Party_Services__c>();
- Map<Id, String> ssToCeaseAndReprovideType = new Map<Id, String>();
- Set<Id> oppLineItemsIds = new Set<Id>();
- for(CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper singleService : soldServiceList){
- oppLineItemsIds.add(singleService.quoteItem.OpportunityLineItem_ID__c);
- }
- Map<Id,Id> ss2ssm = new Map<Id,Id>();
- List<OpportunityLineItem> oliList = [SELECT Existing_Object_ID__c, Existing_SSM_Id__c FROM OpportunityLineItem WHERE id IN :oppLineItemsIds AND Existing_Object_ID__c <> null];
- for(OpportunityLineItem oli : oliList){
- ss2ssm.put(oli.Existing_Object_ID__c, oli.Existing_SSM_Id__c);
- }
- Id devRecordTypeId = Schema.SObjectType.Sold_Service_Modification__c.getRecordTypeInfosByName().get('Sold Service Modification').getRecordTypeId();
- for(CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper singleService : soldServiceList) {
- ssToCeaseAndReprovideType.put(singleService.soldService.Id, singleService.quoteItem.Cease_and_Reprovide_Type__c);
- String strSobjects = ' ';
- Sold_Service_Modification__c soldServiceMod = new Sold_Service_Modification__c();
- Sold_Service_Modification__c oldSoldServiceMod;
- Sold_Service__c updatedSS = new Sold_Service__c(Id = singleService.soldService.Id);
- if(singleService.quoteItem != null) {
- Decimal leadTime = singleService.quoteItem.Lead_Time__c == null ? 0 : singleService.quoteItem.Lead_Time__c;
- soldServiceMod.Estimated_Delivery_Date__c = singleService.quoteItem.Opportunity__r.CloseDate.addDays(leadTime.intValue());
- }
- //@@ Maciej Rudnicki (maciej.rudnicki@enxoo.com) default field fill
- if(ApplicationConstant.SOLDSERVICEMOD_FIELDS_LINKNET_ADDRESSING.contains(singleService.SoldService.Type_of_Service_Description__c)) {
- soldServiceMod.Linknet_IPv4_Addressing__c = '/31';
- }
- System.debug('@@ MARUD Diverse_from__c :: ' + singleService.SoldService.Diverse_from__c);
- //@@ Maciej Rudnicki (maciej.rudnicki@enxoo.com) default field fill
- if(singleService.SoldService.Diverse_from__c != null) {
- soldServiceMod.Diverse_from__c = singleService.SoldService.Diverse_from__c;
- }
- soldServiceMod.Sold_Service__c = singleService.soldService.Id;
- soldServiceMod.CRM_Account__c = singleService.soldService.CRM_Account__c;
- soldServiceMod.RecordTypeId = devRecordTypeId;
- soldServiceMod.Opp_Link__c = singleService.soldService.Opp_Link__c;
- if(singleService.quoteItem.A_Port__c != null){
- soldServiceMod.LAG_LACP__c = singleService.quoteItem.A_Port__r.LAG_LACP__c;
- soldServiceMod.LAG_LACP_Details__c = singleService.quoteItem.A_Port__r.LAG_LACP_Details__c;
- }
- if(singleService.quoteItem != null){
- soldServiceMod.Quote_Item__c = singleService.quoteItem.Id;
- }
- String h1 = EncodingUtil.ConvertTohex(Crypto.GenerateAESKey(128));
- String newSSMupsertKey = h1.substring(0, 8) + '-' + h1.substring(8, 12) + '-' + h1.substring(12, 16) + '-' + h1.substring(16, 20) + '-' + h1.substring(20);
- soldServiceMod.Upsert_Cease_Key__c = newSSMupsertKey;
- if(singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_ADD) {
- Set<String> doNotCopy = new Set<String>{'Id', 'RecordType', 'RecordTypeId', 'Name', 'Details__c', 'TECH_Mod_Attributes_List__c', 'Stage__c',
- 'Account__c', 'Action__c', 'Sold_Service__c', 'TECH_Definition_JSON__c', 'Latest_Service_Comment__c',
- 'Escalation_Status__c', 'Internal_Escalation_Level__c', 'Modification_Cycle_Time__c', 'Missed_Delivery_Date_Reason__c',
- 'Minimum_Status_Assignment__c', 'Minimum_Status_TPS__c', 'WO_Group_Status_SSCR__c', 'Maximum_RFS_Date_Assignment__c',
- 'Maximum_RFS_Date_TPS__c','Committed_Delivery_Date__c', 'Date_Sold_Service_Stage_was_modified__c', 'RFS_Date__c', 'Estimated_Delivery_Date__c',
- 'FDC_Code__c', 'TSIC_Contracting_Company2__c'};
- Set<String> fieldsToCopy = ssmFields;
- fieldsToCopy.removeAll(doNotCopy);
- soldServiceMod.Name = singleService.soldService.Name + ' '+ singleService.soldService.Item_Action__c + ' '+ String.valueOf(System.today());
- soldServiceMod.Action__c = singleService.soldService.Item_Action__c;
- Sold_Service__c oldService = idToServiceMap.get(singleService.soldService.Id);
- buildSsmJSON(singleService.soldService, oldService, soldServiceMod);
- //since API names between Sold Service and its Modfication match API Names we can copy automaticly all of them:
- for(String field : fieldsToCopy) {
- try {
- if(singleService.soldService.get(field) != null) soldServiceMod.put(field,singleService.soldService.get(field));
- } catch(Exception e) {
- System.debug('XXX cannot convert field: '+field);
- }
- }
- syncStage(updatedSS, soldServiceMod);
- if(singleService.soldService.CRM_Parent_Sold_Service__c != null && (!parentSSM.isEmpty() || (CPQ_PRD08_CreateSoldServiceBatchHlpr.ss2ssm != null && !CPQ_PRD08_CreateSoldServiceBatchHlpr.ss2ssm.isEmpty() ) ) ) {
- Sold_Service_Modification__c tempSsm;
- if(CPQ_PRD08_CreateSoldServiceBatchHlpr.ss2ssm != null && CPQ_PRD08_CreateSoldServiceBatchHlpr.ss2ssm.containsKey(singleService.soldService.CRM_Parent_Sold_Service__c)){
- tempSsm = CPQ_PRD08_CreateSoldServiceBatchHlpr.ss2ssm.get(singleService.soldService.CRM_Parent_Sold_Service__c);
- } else {
- tempSsm = parentSSM.get(singleService.soldService.CRM_Parent_Sold_Service__c);
- }
- if(tempSsm != null){
- soldServiceMod.CRM_Parent_Sold_Service_Modification__c = tempSsm.Id;
- soldServiceMod.FDC_Code__c = tempSsm.FDC_Code__c;
- }
- }
- } else if(singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_RENEWAL
- || singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CHANGE
- || singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CEASE) {
- soldServiceMod.Name = singleService.soldService.Name + ' '+ singleService.soldService.Item_Action__c + ' '+
- //we use created date for migration purposes
- String.valueOf(singleService.soldService.CreatedDate != null ? (Date) singleService.soldService.CreatedDate : System.today());
- Set<String> doNotCopy = new Set<String>{'Id', 'RecordType', 'RecordTypeId', 'Name', 'Stage__c', 'Details__c', 'TECH_Mod_Attributes_List__c', 'TECH_Cease_Parallel_Build__c', 'Action__c', 'Account__c', 'Sold_Service__c',
- 'TECH_Definition_JSON__c', 'Latest_Service_Comment__c' , 'Escalation_Status__c', 'Internal_Escalation_Level__c', 'Modification_Cycle_Time__c', 'Missed_Delivery_Date_Reason__c',
- 'Minimum_Status_Assignment__c', 'Minimum_Status_TPS__c', 'WO_Group_Status_SSCR__c', 'Maximum_RFS_Date_Assignment__c', 'Maximum_RFS_Date_TPS__c','Committed_Delivery_Date__c',
- 'Date_Sold_Service_Stage_was_modified__c', 'RFS_Date__c', 'Estimated_Delivery_Date__c', 'Dismantle_Notes__c', 'Person_requesting_the_dismantle__c', 'Specification_Received_Date__c',
- 'FDC_Code__c', 'TSIC_Contracting_Company2__c'};
- Set<String> fieldsToCopy = ssmFields;
- fieldsToCopy.removeAll(doNotCopy);
- //since API names between Sold Service and its Modfication match API Names we can copy automaticly all of them:
- for(String field : fieldsToCopy) {
- try {
- if(singleService.soldService.get(field) != null) soldServiceMod.put(field,singleService.soldService.get(field));
- } catch(Exception e) {
- System.debug('XXX cannot convert field: '+ field);
- }
- }
- if(parentSSM != null) {
- if(parentSSM.containsKey(singleService.soldService.CRM_Parent_Sold_Service__c)) soldServiceMod.CRM_Parent_Sold_Service_Modification__c = parentSSM.get(singleService.soldService.CRM_Parent_Sold_Service__c).Id;
- }
- if(singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_RENEWAL) {
- soldServiceMod.Action__c = CPQ_PRD04_SoldServiceMappingHlpr.ACTION_RENEWAL;
- soldServiceMod.Stage__c = ApplicationConstant.SSM_STAGE_RENEWAL_PENDING;
- if(idToServiceMap.containsKey(singleService.soldService.Id)) buildSsmJSON(singleService.soldService, idToServiceMap.get(singleService.soldService.Id), soldServiceMod);
- } else if(singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CHANGE) {
- soldServiceMod.Action__c = CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CHANGE;
- if(idToServiceMap.containsKey(singleService.soldService.Id)) buildSsmJSON(singleService.soldService, idToServiceMap.get(singleService.soldService.Id), soldServiceMod);
- } else if(singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CEASE) {
- soldServiceMod.Action__c = CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CEASE;
- if(singleService.parallelBuild) {
- soldServiceMod.Action__c = ApplicationConstant.SSM_ITEM_ACTION_REPROVIDE_PARALLEL;
- if(singleService.oldSoldService != null) soldServiceMod.Sold_Service_Previous_Instance__c = singleService.oldSoldService.Id;
- soldServiceMod.TECH_Cease_Parallel_Build__c = true;
- soldServiceMod.Stage__c = ApplicationConstant.SSM_STAGE_NEW;
- soldServiceMod.Name = singleService.soldService.Name + ' '+ ApplicationConstant.SSM_ITEM_ACTION_REPROVIDE_PARALLEL + ' '+
- //we use created date for migration purposes
- String.valueOf(singleService.soldService.CreatedDate != null ? (Date) singleService.soldService.CreatedDate : System.today());
- soldServiceMod.Item_Type__c = CPQ_PRD04_SoldServiceMappingHlpr.PROD_TYPE_OPERATIONAL;
- // REPROVIDE Dismantle Request Received Date
- //soldServiceMod.Specification_Received_Date__c = singleService.soldService.CreatedDate != null ? (Date) singleService.soldService.CreatedDate : System.today();
- soldServiceMod.Service_Description__c =singleService.soldService.Service_Description__c;
- //if(idToServiceMap.containsKey(singleService.soldService.Id)) {
- // Sold_Service__c oldService = idToServiceMap.get(singleService.soldService.Id);
- // DateTime datetimeBuffer = oldService.Renewed_To__r.RFS_Date__c;
- // try {
- // soldServiceMod.Date_for_Dismantle__c = datetimeBuffer.addDays((Integer)soldServiceMod.Days_of_Parallel_Running__c);
- // } catch(NullPointerException npe) {
- // soldServiceMod.Date_for_Dismantle__c = datetimeBuffer;
- // }
- //}
- if(parentSSM != null) {
- if(parentSSM.containsKey(singleService.soldService.CRM_Parent_Sold_Service__c)) soldServiceMod.CRM_Parent_Sold_Service_Modification__c = parentSSM.get(singleService.soldService.CRM_Parent_Sold_Service__c).Id;
- }
- oldSoldServiceMod = new Sold_Service_Modification__c();
- oldSoldServiceMod.TECH_Cease_Parallel_Build__c = true;
- oldSoldServiceMod.Stage__c = ApplicationConstant.SSM_STAGE_NEW;
- oldSoldServiceMod.Sold_Service__c = singleService.oldSoldService.Id;
- oldSoldServiceMod.CRM_Account__c = singleService.oldSoldService.CRM_Account__c;
- oldSoldServiceMod.RecordTypeId = devRecordTypeId;
- oldSoldServiceMod.Opp_Link__c = singleService.oldSoldService.Opp_Link__c;
- oldSoldServiceMod.Action__c = ApplicationConstant.SSM_ITEM_ACTION_CEASE_PARALLEL;
- if(singleService.SoldService != null) oldSoldServiceMod.Next_Sold_Service_Instance__c = singleService.SoldService.Id;
- //TSIC Contracting Company and FDC Code from Opunity -> Tsic Contracting company relation
- if (oppMap != null && oldSoldServiceMod.Opp_Link__c != null && oppMap.get(oldSoldServiceMod.Opp_Link__c) != null && oppMap.get(oldSoldServiceMod.Opp_Link__c).TSIC_Contracting_Company__c != null) {
- oldSoldServiceMod.FDC_Code__c = oppMap.get(oldSoldServiceMod.Opp_Link__c).TSIC_Contracting_Company__r.FDC_Code__c;
- oldSoldServiceMod.TSIC_Contracting_Company2__c = oppMap.get(oldSoldServiceMod.Opp_Link__c).TSIC_Contracting_Company__r.TSIC_Contracting_Company_Name__c;
- }
- //Dismantle details fields
- oldSoldServiceMod.Person_requesting_the_dismantle__c = singleService.soldService.Person_requesting_the_dismantle__c;
- oldSoldServiceMod.Dismantle_Notes__c = singleService.soldService.Dismantle_Notes__c;
- oldSoldServiceMod.Specification_Received_Date__c = singleService.soldService.Specification_Received_Date__c;
- String h2 = EncodingUtil.ConvertTohex(Crypto.GenerateAESKey(128));
- String oldSSMupsertKey = h2.substring(0, 8) + '-' + h2.substring(8, 12) + '-' + h2.substring(12, 16) + '-' + h2.substring(16, 20) + '-' + h2.substring(20);
- oldSoldServiceMod.Upsert_Cease_Key__c = oldSSMupsertKey;
- if(!ceaseReprovideMap.containsKey(oldSSMupsertKey)) {
- ceaseReprovideMap.put(oldSSMupsertKey, newSSMupsertKey);
- }
- //oldSoldServiceMod.TECH_Related_SSM__r = new Sold_Service_Modification__c(Upsert_Cease_Key__c = soldServiceMod.Upsert_Cease_Key__c);
- oldSoldServiceMod.Name = singleService.oldSoldService.Name + ' '+ ApplicationConstant.SSM_ITEM_ACTION_CEASE_PARALLEL + ' ' +
- //we use created date for migration purposes
- String.valueOf(singleService.oldSoldService.CreatedDate != null ? (Date) singleService.oldSoldService.CreatedDate : System.today());
- for(String field : fieldsToCopy) {
- try {
- if(singleService.oldSoldService.get(field) != null) oldSoldServiceMod.put(field,singleService.oldSoldService.get(field));
- } catch(Exception e) {
- System.debug('XXX cannot convert field: '+field);
- }
- }
- Sold_Service__c updatedOldSS = new Sold_Service__c(Id = singleService.oldSoldService.Id);
- syncStage(updatedOldSS, oldSoldServiceMod);
- if(!ssDuplicates.contains(updatedOldSS.Id)) {
- ssDuplicates.add(updatedOldSS.Id);
- ssToUpdate.add(updatedOldSS);
- }
- Id ssID;
- if(oldSoldServiceMod.Sold_Service__c != null) ssID = oldSoldServiceMod.Sold_Service__c;
- Set<String> locationFieldsToQuery = new Set<String>{'A_Connector__c','A_Demarc_Type__c','B_Demarc_Type__c','B_Connector__c', 'A_Interface__c','B_Interface__c','A_Port_Type__c', 'B_Port_Type__c','A_Demarc_Site__c','B_Demarc_Site__c','A_Rack_Cabinet__c','B_Rack_Cabinet__c','A_Room__c','B_Room__c','A_Floor__c','B_Floor__c','A_Demarc_Comments__c','B_Demarc_Comments__c','A_Site__c', 'B_Site__c','Service_Description__c', 'A_Port__c', 'A_Location__c', 'A_Homing_Gateway_Location__c', 'B_Port__c', 'B_Location__c', 'B_Homing_Gateway_Location__c'};
- String queryString = 'SELECT ' + SoldServiceUtility.buildQueryFields(locationFieldsToQuery) + ' FROM Sold_Service__c WHERE id =: ssID';
- for(Sold_Service__c ss :(List<Sold_Service__c>)Database.query(queryString)){
- for(String field : locationFieldsToQuery){
- try {
- oldSoldServiceMod.put(field, ss.get(field));
- }catch(Exception e) {
- System.debug('XXX cannot convert field: '+field);
- }
- }
- }
- }
- //Location must be fetched from old sold service as SSM is 'Cease'. For 'Reprovide' SSM, it is fetched earlier from new SS
- Sold_Service__c oldService;
- if(singleService.oldSoldService != null) {
- oldService = idToServiceMap.get(singleService.oldSoldService.Id);
- } else {
- oldService = idToServiceMap.get(singleService.soldService.Id);
- }
- buildSsmJSON(singleService.soldService, oldService, soldServiceMod);
- }
- syncStage(updatedSS, soldServiceMod);
- } else if(singleService.soldService.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_DISMANTLE) {
- soldServiceMod.Name = singleService.soldService.Name + ' '+ singleService.soldService.Item_Action__c + ' '+ String.valueOf(System.today());
- soldServiceMod.Opp_Link__c = singleService.soldService.Opp_Link__c;
- soldServiceMod.Stage__c = ApplicationConstant.SSM_STAGE_NEW;
- soldServiceMod.Action__c = CPQ_PRD04_SoldServiceMappingHlpr.ACTION_DISMANTLE;
- soldServiceMod.Date_for_Dismantle__c = singleService.soldService.Date_for_Dismantle__c;
- soldServiceMod.Person_requesting_the_dismantle__c = singleService.soldService.Person_requesting_the_dismantle__c;
- soldServiceMod.Dismantle_Notes__c = singleService.soldService.Dismantle_Notes__c;
- soldServiceMod.Specification_Received_Date__c = singleService.soldService.Specification_Received_Date__c;
- soldServiceMod.RecordTypeId = devRecordTypeId;
- soldServiceMod.Sold_Service__c = singleService.soldService.Id;
- soldServiceMod.A_Cabling_Point__c = singleService.soldService.A_Cabling_Point__c;
- soldServiceMod.B_Cabling_Point__c = singleService.soldService.B_Cabling_Point__c;
- if (parentSSM != null)
- soldServiceMod.Dismantle_Related_Services__c = ApplicationConstant.SOLDSERVICE_DISMANTLE_CHILD_SERVICES_YES;
- else
- soldServiceMod.Dismantle_Related_Services__c = ApplicationConstant.SOLDSERVICE_DISMANTLE_CHILD_SERVICES_NO;
- syncStage(updatedSS, soldServiceMod);
- Set<String> doNotCopy = new Set<String>{'Id', 'Delivery_Coordinator__c', 'OLI_Link_name__c', 'OLI_Link_ID__c', 'RecordType', 'RecordTypeId',
- 'Latest_Service_Comment__c' , 'Escalation_Status__c',
- 'Internal_Escalation_Level__c', 'Modification_Cycle_Time__c',
- 'Missed_Delivery_Date_Reason__c', 'Minimum_Status_Assignment__c',
- 'Minimum_Status_TPS__c', 'WO_Group_Status_SSCR__c',
- 'Maximum_RFS_Date_Assignment__c', 'Maximum_RFS_Date_TPS__c',
- 'Committed_Delivery_Date__c', 'Date_Sold_Service_Stage_was_modified__c',
- 'RFS_Date__c', 'Name', 'Stage__c', 'CreatedBy', 'CreatedDate',
- 'LastModifiedDate', 'CreatedById', 'Details__c', 'TECH_Mod_Attributes_List__c',
- 'TECH_Cease_Parallel_Build__c', 'Action__c', 'Account__c', 'Sold_Service__c',
- 'CRM_Parent_Sold_Service__c', 'TECH_Definition_JSON__c', 'Estimated_Delivery_Date__c', 'Opp_Link__c',
- 'Sold_Service_Opportunity__c'};
- Set<String> fieldsToCopy = ssmFields;
- fieldsToCopy.removeAll(doNotCopy);
- Sold_Service__c soldServiceSource = idToServiceMap.get(singleService.soldService.Id);
- //since API names between Sold Service and its Modfication match API Names we can copy automaticly all of them:
- String helper = '';
- for(String field : fieldsToCopy) {
- try {
- helper += '{' + field + ' - > ' + soldServiceSource.get(field) + ' },';
- if(soldServiceSource.get(field) != null) soldServiceMod.put(field,soldServiceSource.get(field));
- } catch(Exception e) {
- System.debug('XXX cannot convert field: '+field);
- }
- }
- if(parentSSM != null) {
- if(parentSSM.containsKey(singleService.soldService.CRM_Parent_Sold_Service__c)) soldServiceMod.CRM_Parent_Sold_Service_Modification__c = parentSSM.get(singleService.soldService.CRM_Parent_Sold_Service__c).Id;
- }
- } else if(singleService.soldService.Item_Action__c == null || singleService.soldService.Item_Action__c == '') {//this should happen only during migration of bad data. Still has to be handled.
- soldServiceMod = new Sold_Service_Modification__c();
- Set<String> doNotCopy = new Set<String>{'Id', 'RecordType', 'RecordTypeId', 'Stage__c', 'Sold_Service__c', 'TECH_Definition_JSON__c', 'Latest_Service_Comment__c',
- 'Escalation_Status__c', 'Internal_Escalation_Level__c', 'Modification_Cycle_Time__c', 'Missed_Delivery_Date_Reason__c',
- 'Minimum_Status_Assignment__c', 'Minimum_Status_TPS__c', 'WO_Group_Status_SSCR__c', 'Maximum_RFS_Date_Assignment__c',
- 'Maximum_RFS_Date_TPS__c','Committed_Delivery_Date__c', 'Date_Sold_Service_Stage_was_modified__c', 'RFS_Date__c', 'Estimated_Delivery_Date__c'};
- Set<String> fieldsToCopy = ssmFields;
- fieldsToCopy.removeAll(doNotCopy);
- //since API names between Sold Service and its Modfication match API Names we can copy automaticly all of them:
- for(String field : fieldsToCopy) {
- try {
- soldServiceMod.put(field,singleService.soldService.get(field));
- } catch(Exception e) {
- System.debug('XXX cannot convert field: '+field);
- }
- }
- soldServiceMod.RecordTypeId = devRecordTypeId;
- soldServiceMod.TECH_Definition_JSON__c = strSobjects;
- soldServiceMod.Sold_Service__c = singleService.soldService.Id;
- }
- if (oppMap != null && soldServiceMod.Opp_Link__c != null && oppMap.get(soldServiceMod.Opp_Link__c) != null && oppMap.get(soldServiceMod.Opp_Link__c).TSIC_Contracting_Company__c != null) {
- soldServiceMod.FDC_Code__c = oppMap.get(soldServiceMod.Opp_Link__c).TSIC_Contracting_Company__r.FDC_Code__c;
- soldServiceMod.TSIC_Contracting_Company2__c = oppMap.get(soldServiceMod.Opp_Link__c).TSIC_Contracting_Company__r.TSIC_Contracting_Company_Name__c;
- }
- if(!(ss2ssm.containsKey(soldServiceMod.Sold_Service__c) && soldServiceMod.Action__c == 'Add')){
- if(soldServiceMod != null && !result.containsKey(singleService.soldService.Id)) {
- result.put(singleService.soldService.Id, soldServiceMod);
- }if(oldSoldServiceMod != null && !result.containsKey(singleService.oldSoldService.Id)) {
- result.put(singleService.oldSoldService.Id, oldSoldServiceMod);
- }
- if(!ssDuplicates.contains(updatedSS.Id)) {
- ssDuplicates.add(updatedSS.Id);
- ssToUpdate.add(updatedSS);
- }
- }
- }
- Map<Id, List<String>> existingModifications = checkExistingSSM(result);
- List<Opportunity> oppList = Trigger.new;
- if(oppList!= null) {
- for(Id ssId : result.keyset()) {
- if(existingModifications.containsKey(ssId)) {
- for(Opportunity singleOpp : oppList) {
- if(singleOpp.Id == result.get(ssId).Opp_Link__c) {
- if(!alreadyExistingSSM.isEmpty() && !existingModifications.get(ssID).isEmpty()) {
- singleOpp.addError('There is already open SSM record: <a target="_blank" href="/' + alreadyExistingSSM.get(ssId).Id +'">'+alreadyExistingSSM.get(ssId).Name+'</a> below attributes must be corrected: ' +'<br/> ' + existingModifications.get(ssID), false);
- }
- }
- }
- }
- }
- }
- Set<Id> ssIds = new Set<Id>();
- Set<Id> oppIds = new Set<Id>();
- for(Sold_Service_Modification__c ssm : result.values()){
- ssIds.add(ssm.Sold_Service__c);
- oppIds.add(ssm.Opp_Link__c);
- }
- List<CPQ_QuoteItem__c> ssmChildQiList = [SELECT Id, Existing_Object_ID__r.CRM_Parent_Sold_Service__c
- FROM CPQ_QuoteItem__c
- WHERE Existing_Object_ID__r.CRM_Parent_Sold_Service__c = :ssIds
- AND Item_Action__c = :ApplicationConstant.OLI_ITEM_ACTION_DESCRIPTION_IN_FLIGHT_CHANGE
- AND Opportunity__c = :oppIds];
- Map<Id, CPQ_QuoteItem__c> ss2QiMap = new Map<Id, CPQ_QuoteItem__c>();
- for(CPQ_QuoteItem__c qi : ssmChildQiList){
- ss2QiMap.put(qi.Existing_Object_ID__r.CRM_Parent_Sold_Service__c, qi);
- }
- for(Sold_Service_Modification__c ssm : result.values()){
- if(ss2QiMap.containsKey(ssm.Sold_Service__c) && ssm.Action__c == ApplicationConstant.ACTION_CHANGE){
- ssm.Stage__c = ApplicationConstant.SSM_STAGE_LIVE;
- }
- }
- //PRTUS - 05-11-17 TSIC-1581 // to chceck, currently this records are upserted later, which breaks flow
- if(result != null && result.size() > 0 ) {
- //if(result != null && result.size() > 0 && existingModifications != null && existingModifications.isEmpty()) {
- System.debug(LoggingLevel.WARN, 'SSM RECORDS = '+result.values());
- CPQ_Utils04_RequestStateCls.setOn('SSM_UPDATE_FLAG');
- insert result.values();
- CPQ_Utils04_RequestStateCls.setOff('SSM_UPDATE_FLAG');
- }
- //based on Action handle TPSes
- for(Id ssID : result.keySet()) {
- Sold_Service_Modification__c soldServiceMod = result.get(ssId);
- Id ssForTps;
- if(soldServiceMod.TECH_Cease_Parallel_Build__c == true && soldServiceMod.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_REPROVIDE) {
- ssForTps = soldServiceMod.Sold_Service__c;
- } else if (soldServiceMod.TECH_Cease_Parallel_Build__c == true) {
- ssForTps = soldServiceMod.Sold_Service_Previous_Instance__c;
- } else {
- ssForTps = soldServiceMod.Sold_Service__c;
- }
- if(soldServiceMod.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_ADD || soldServiceMod.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_RENEWAL || soldServiceMod.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_REPROVIDE ||
- (soldServiceMod.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CEASE && soldServiceMod.Quote_Item__r.Cease_and_Reprovide_Type__c == CPQ_PRD04_SoldServiceMappingHlpr.CEASE_PARALLEL_BUILD)) {
- if(ssToTpsMap.get(ssForTps) != null) {
- for(X3rd_Party_Services__c tps : ssToTpsMap.get(ssForTps)) {
- tps.Sold_Service_Modification__c = soldServiceMod.Id;
- }
- }
- } else if(soldServiceMod.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CHANGE ||
- (soldServiceMod.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CEASE && ssToCeaseAndReprovideType.get(ssForTps) == CPQ_PRD04_SoldServiceMappingHlpr.CEASE_HOT_CUT)) {
- if (ssToTpsMap.get(ssForTps) != null) {
- for (X3rd_Party_Services__c tps : ssToTpsMap.get(ssForTps)) {
- tps.Sold_Service_Modification__c = soldServiceMod.Id;
- }
- }
- }
- for(CPQ_PRD04_SoldServiceMappingHlpr.soldServiceWrapper singleService : soldServiceList) {
- if(soldServiceMod.Sold_Service__c == singleService.soldService.Id) {
- if(singleService.soldService.OLI_Link_ID__c != null) {
- ssOliMap.put(soldServiceMod.Id, singleService.soldService.OLI_Link_ID__c);
- }
- }
- }
- if (ssToTpsMap.get(ssForTps) != null || ssChildsToTpsMap != null)
- soldServiceMod = ThirdPartyServiceTriggerHandler.setSoldServiceModificationFinancial(ssToTpsMap.get(ssForTps), ssChildsToTpsMap, soldServiceMod, ssChildsToTPS);
- }
- for(List<X3rd_Party_Services__c> tpsList : ssToTpsMap.values()) {
- tpsToUpdate.addAll(tpsList);
- }
- update tpsToUpdate;
- update ssToUpdate;
- return result;
- }
- public static void syncStage(Sold_Service__c ss, Sold_Service_Modification__c ssm) {
- String key = ssm.Action__c;
- if(ssm.Stage__c != null && key != null){
- if (ssm.Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_CEASE) {
- key = ApplicationConstant.HOT_CUT_BLOCK;
- } else if (ssm.Action__c == ApplicationConstant.SSM_ITEM_ACTION_REPROVIDE_PARALLEL) {
- key = ApplicationConstant.C_AND_R_NEW_BLOCK;
- } else if (ssm.Action__c == ApplicationConstant.SSM_ITEM_ACTION_CEASE_PARALLEL) {
- key = ApplicationConstant.C_AND_R_BLOCK;
- }
- if (ssm.Stage__c != null && ApplicationConstant.stageMap.containsKey(key + '_' + ssm.Stage__c)){
- key += '_' + ssm.Stage__c;
- }
- ss.Stage__c = ApplicationConstant.stageMap.get(key).stage;
- System.debug('@@@MAGAR STAGE key: '+key);
- System.debug('@@@MAGAR STAGE GETKEY: '+ApplicationConstant.stageMap.get(key));
- System.debug('@@@MAGAR STAGE : '+ApplicationConstant.stageMap.get(key).stage);
- if (!(ss.Stage__c == ApplicationConstant.SOLDSERVICE_STAGE_DISMANTLE_PENDING && ss.Status__c == ApplicationConstant.SOLDSERVICE_STATUS_INACTIVE)) {
- System.debug('@@@MAGAR jeste w tym ciezkim ifie : '+ApplicationConstant.stageMap.get(key).stage);
- ss.Status__c = ApplicationConstant.stageMap.get(key).status;
- }
- }
- }
- public static Map<Id, List<String>> checkExistingSSM(Map<Id, Sold_Service_Modification__c> soldServiceModMap) {
- Map<Id, Sold_Service__c> currentlyUsedSS = new Map<Id, Sold_Service__c>();
- Map<Id, List<String>> result = new Map<Id, List<String>>();
- /**
- ** Check if there are some open SSM modifying same atributes, if yes display warning message
- **/
- for(Sold_Service_Modification__c existingSSM : [SELECT Id, Sold_Service__c, Name, Action__c, TECH_Mod_Attributes_List__c FROM Sold_Service_Modification__c WHERE Sold_Service__c IN : soldServiceModMap.keyset() AND (Stage__c != :ApplicationConstant.SSM_STAGE_LIVE AND Stage__c != :ApplicationConstant.SSM_STAGE_CANCELLED AND Stage__c != :ApplicationConstant.SSM_STAGE_REJECTED)]) {
- if(existingSSM.TECH_Mod_Attributes_List__c!= null && existingSSM.Action__c != ApplicationConstant.ACTION_DISMANTLE) {
- List<String> currentlyUpdatingFields = existingSSM.TECH_Mod_Attributes_List__c.split('\r\n');
- if(soldServiceModMap.containsKey(existingSSM.Sold_Service__c) && soldServiceModMap.get(existingSSM.Sold_Service__c).TECH_Mod_Attributes_List__c != null) {
- List<String> alreadyExistingUpdates = soldServiceModMap.get(existingSSM.Sold_Service__c).TECH_Mod_Attributes_List__c.split('\r\n');
- List<String> sameValues = new List<String>();
- for(String attribute : currentlyUpdatingFields) {
- for(String oldAttribute : alreadyExistingUpdates) {
- if(attribute == oldAttribute) {
- sameValues.add(attribute);
- }
- }
- }
- if(result.containsKey(existingSSM.Sold_Service__c)) {
- result.get(existingSSM.Sold_Service__c).addAll(sameValues);
- } else {
- result.put(existingSSM.Sold_Service__c, sameValues);
- }
- }
- if(!alreadyExistingSSM.containsKey(existingSSM.Sold_Service__c)) alreadyExistingSSM.put(existingSSM.Sold_Service__c, existingSSM);
- }
- }
- return result;
- }
- public static void refreshConnectedWoOfGivenType(Map<Id, Sold_Service_Modification__c> ssmInputMap, String woType, String woRecordTypeId) {
- List<WorkOrder> woToUpdateList = [
- SELECT Id
- FROM WorkOrder
- WHERE Sold_Service_Modification__c IN :ssmInputMap.keySet()
- AND RecordTypeId = :woRecordTypeId
- AND Type__c = :woType
- ];
- if (woToUpdateList != null && !woToUpdateList.isEmpty()) update woToUpdateList;
- }
- /**
- * @author Grzegorz Długosz - grzegorz.dlugosz@enxoo.com
- * @description This method is used to refresh work orders based on input arguments.
- * Its needed mostly for milestone recalculations.
- * @param ssmInputMap - ssms for which work orders need to be refreshed
- * @param woTypes - types of work orders that need to be refreshed
- * @param woRecordTypeId - record type of work orders that need to be refreshed
- */
- public static void refreshConnectedWoOfGivenTypes(Map<Id, Sold_Service_Modification__c> ssmInputMap, List<String> woTypes, String woRecordTypeId) {
- List<WorkOrder> woToUpdateList = [
- SELECT Id
- FROM WorkOrder
- WHERE Sold_Service_Modification__c IN :ssmInputMap.keySet()
- AND RecordTypeId = :woRecordTypeId
- AND Type__c IN :woTypes
- ];
- if (woToUpdateList != null && !woToUpdateList.isEmpty()) update woToUpdateList;
- }
- public static void closeCDDMilestoneOnWo(Map<Id, Sold_Service_Modification__c> ssmInputMap) {
- Map<Id, WorkOrder> woMapToUpdate = new Map<Id, WorkOrder>([
- SELECT Id
- FROM WorkOrder
- WHERE Sold_Service_Modification__c IN :ssmInputMap.keySet()
- AND RecordTypeId = :ApplicationConstant.WORK_ORDER_RECORD_TYPE_ID_DELIVERY
- AND Type__c = :ApplicationConstant.WORK_ORDER_TYPE_DELIVERY_COORDINATOR
- ]);
- List<String> milestonesToCloseList = new List<String>();
- milestonesToCloseList.add(CPQ_MIL01_UtilsCls.MIL_NAME_DELIVERY_ON_TIME);
- CPQ_MIL01_UtilsCls.completeWorkOrderMilestone(woMapToUpdate, milestonesToCloseList, System.now());
- }
- public static void populateDateForDismantleOnReprovideSSM(Map<Id, Sold_Service_Modification__c> ssmInputMap) {
- Map<Id,Sold_Service_Modification__c> listOfCeaseSSM = new Map<Id,Sold_Service_Modification__c>([SELECT Id , RFS_Date__c, Days_of_Parallel_Running__c ,(SELECT Id, Date_for_Dismantle__c, TECH_Related_SSM__c FROM Sold_Service_Modifications__r WHERE Action__c = 'Cease' LIMIT 1) FROM Sold_Service_Modification__c WHERE Id IN: ssmInputMap.keyset() AND RFS_Date__c <> NULL AND Stage__c = '30. Modification Complete' AND Action__c = 'Reprovide']);
- List<Sold_Service_Modification__c> listOfCeaseSSMReadyForUpdate = new List<Sold_Service_Modification__c>();
- for(Sold_Service_Modification__c tempSSMReprovide : ssmInputMap.values()){
- if(!listOfCeaseSSM.get(tempSSMReprovide.Id).Sold_Service_Modifications__r.isEmpty()){
- Sold_Service_Modification__c tempCeaseSSM = listOfCeaseSSM.get(tempSSMReprovide.Id).Sold_Service_Modifications__r[0];
- DateTime datetimeBuffer = tempSSMReprovide.RFS_Date__c;
- try {
- tempCeaseSSM.Date_for_Dismantle__c = datetimeBuffer.addDays((Integer)tempSSMReprovide.Days_of_Parallel_Running__c);
- } catch(NullPointerException npe) {
- tempCeaseSSM.Date_for_Dismantle__c = datetimeBuffer;
- }
- listOfCeaseSSMReadyForUpdate.add(tempCeaseSSM);
- }
- }
- if(!listOfCeaseSSMReadyForUpdate.isEmpty()) {
- try{
- update listOfCeaseSSMReadyForUpdate;
- } catch( Exception e ){
- System.debug('@@@CPQ_SSM01_Manager Method : populateDateForDismantleOnReprovide : Catch Exception: '+e.getMessage());
- }
- }
- }
- /***************************************************************************************
- Developer Michał Pastuszka (Enxoo) michal.pastuszka@enxoo.com
- Date 2017-08-09
- Function Method used for building JSON file with current changes performed on SS record.
- ****************************************************************************************/
- public static Sold_Service_Modification__c buildSsmJSON(Sold_Service__c newSS, Sold_Service__c oldSS, Sold_Service_Modification__c result) {
- Sold_Service__c ssResult = new Sold_Service__c();
- String changedFields = '';
- String modDetails = '';
- Schema.DescribeSObjectResult obj = Schema.getGlobalDescribe().get('Sold_Service__c').getDescribe();
- Map<String, Schema.SObjectField> schemaFieldMap = obj.fields.getMap();
- if(newSS.Item_Action__c == CPQ_PRD04_SoldServiceMappingHlpr.ACTION_ADD) {
- ssResult = newSS.clone(false, true, false, false);
- } else {
- for(String fieldName : schemaFieldMap.keySet()){
- if(newSS.get(fieldName) != null && !ApplicationConstant.SOLDSERVICE_FIELDS_EXCLUDE.contains(fieldName) && newSS.get(fieldName) != oldSS.get(fieldName)) {
- ssResult.put(obj.Fields.getMap().get(fieldName).getDescribe().getName(), newSS.get(fieldName));
- changedFields = changedFields + obj.Fields.getMap().get(fieldName).getDescribe().getLabel() + '\r\n';
- modDetails = modDetails + obj.Fields.getMap().get(fieldName).getDescribe().getLabel() + ': ' + oldSS.get(fieldName) + ' => ' + newSS.get(fieldName) + '\r\n';
- }
- }
- }
- result.Details__c = modDetails;
- result.TECH_Mod_Attributes_List__c = changedFields;
- result.TECH_Definition_JSON__c = JSON.Serialize(ssResult);
- return result;
- }
- public static void updateSsmDetailFieldList(Map<Id, Sold_Service_Modification__c> newSSM, Map<Id, Sold_Service_Modification__c> oldSSM, Set<Id> idsList) {
- String oldServicesQuery = 'SELECT ' + CPQ_Utils01_SObjectHelperCls.getFieldListForSOQL('Sold_Service__c', null, null) + ' FROM Sold_Service__c WHERE Id IN: idsList';
- Map<Id, Sold_Service__c> oldSsMap = new Map<Id, Sold_Service__c>((List<Sold_Service__c>)Database.query(oldServicesQuery));
- for(Id ssmId : newSSM.keyset()) {
- if(newSSM.get(ssmId).Stage__c != ApplicationConstant.SSM_STAGE_LIVE) {
- updateSsmDetailField(newSSM.get(ssmId), oldSSM.get(ssmId), oldSsMap);
- }
- }
- }
- private static String prepareDetailString(sObject object2check, String fieldName){
- if(object2check.get(fieldName) instanceof Decimal){
- Decimal tempDecimal = (Decimal)object2check.get(fieldName);
- return String.valueOf(tempDecimal.setScale(2));
- } else {
- return String.valueOf(object2check.get(fieldName));
- }
- }
- /***************************************************************************************
- Developer Michał Pastuszka (Enxoo) michal.pastuszka@enxoo.com
- Date 2017-08-09
- Function Method used for updating Detail field, everytime user changes some field on SSM record.
- Edit 2019-08-13
- Developer Alan Moczulski (Enxoo) alan.moczulski@enxoo.com
- Function All values from moddetails are stored in map and BP are converting from id's to names
- ****************************************************************************************/
- public static void updateSsmDetailField(Sold_Service_Modification__c newSSM, Sold_Service_Modification__c oldSSM, Map<Id, Sold_Service__c> oldSSMap) {
- Map<String,List<Id>> referenceFields = new Map<String,List<Id>>();
- //ALMOC MAP<FIELDNAME,MAP<OLDVALUE,NEWVALUE>
- Map<String,Map<String,String>> mapOfFields= new Map<String,Map<String,String>>();
- Set<String> changedFields = new Set<String>();
- for(String fieldName : ssmschemaFieldMap.keySet()) {
- if(!ApplicationConstant.SOLDSERVICE_FIELDS_EXCLUDE.contains(fieldName)) {
- if(newSSM.get(fieldName) != oldSSM.get(fieldName)) {
- changedFields.add(fieldName);
- }
- }
- }
- //obj.smap = JSON.serialize(obj)
- Sold_Service_Modification__c ssmSerialize;
- if(newSSM.TECH_Changed_Values_JSON__c != null) {
- ssmSerialize = (Sold_Service_Modification__c)JSON.deserialize(newSSM.TECH_Changed_Values_JSON__c, Sold_Service_Modification__c.class);
- }
- String modDetails = '';
- if(newSSM.TECH_Definition_JSON__c != null) {
- Sold_Service__c tempSS = (Sold_Service__c)JSON.deserialize(newSSM.TECH_Definition_JSON__c, Sold_Service__c.class);
- for(String fieldName : schemaFieldMap.keySet()) {
- if(schemaFieldMap.get(fieldName).getDescribe().isUpdateable()) {
- if(!ApplicationConstant.SOLDSERVICE_FIELDS_EXCLUDE.contains(fieldName)){
- String key = newSSM.Sold_Service_Previous_Instance__c != null ? newSSM.Sold_Service_Previous_Instance__c : newSSM.Sold_Service__c;
- if(ssmschemaFieldMap.keySet().contains(fieldName) && tempSS.get(fieldName) != null && oldSSMap.get(key).get(fieldName) != null && tempSS.get(fieldName) != oldSSMap.get(key).get(fieldName)) {
- if(ssmSerialize != null && ssmSerialize.get(fieldName) != null) {
- String oldValue = prepareDetailString((sObject)oldSSMap.get(key), fieldName);
- String newValue = prepareDetailString((sObject)tempSS, fieldName);
- if(!ApplicationConstant.FIELDS_TO_NOT_COPY_IN_DETAILS_ONLY.contains(fieldName) && newValue == String.valueOf(newSSM.get(fieldName))){
- modDetails = modDetails + obj.Fields.getMap().get(fieldName).getDescribe().getLabel() + ': ' + oldValue + ' => ' + newValue + '\r\n';
- String valueOfField = String.valueof(ssmobj.Fields.getMap().get(fieldName).getDescribe().getLabel());
- mapOfFields = putValuesToMap(mapOfFields,valueOfField,oldValue,newValue);
- }
- }
- }
- if(ssmSerialize != null && ssmschemaFieldMap.keySet().contains(fieldName) && ssmSerialize.get(fieldName) != null && tempSS.get(fieldName) != ssmSerialize.get(fieldName) && !changedFields.contains(fieldName)) {
- String oldValue = prepareDetailString((sObject)tempSS, fieldName);
- String newValue = prepareDetailString((sObject)ssmSerialize, fieldName);
- if(!ApplicationConstant.FIELDS_TO_NOT_COPY_IN_DETAILS_ONLY.contains(fieldName)){
- modDetails = modDetails + obj.Fields.getMap().get(fieldName).getDescribe().getLabel() + ': ' + oldValue + ' => ' + newValue + '\r\n';
- String valueOfField = String.valueof(ssmobj.Fields.getMap().get(fieldName).getDescribe().getLabel());
- mapOfFields = putValuesToMap(mapOfFields,valueOfField,oldValue,newValue);
- }
- }
- }
- }
- }
- }
- /**
- ** Update Details field based on manually changed fields on SSM record
- **/
- for(String fieldName : ssmschemaFieldMap.keySet()) {
- if(ssmschemaFieldMap.get(fieldName).getDescribe().isUpdateable()) {
- if(!ApplicationConstant.SOLDSERVICE_FIELDS_EXCLUDE.contains(fieldName)) {
- if(newSSM.get(fieldName) != oldSSM.get(fieldName) ) {
- /**
- ** Update TECH_Changed_Values_JSON__c field with current changes, skip all fields listed in SOLDSERVICEMOD_FIELDS_EXCLUDE
- **/
- if(!ApplicationConstant.SOLDSERVICEMOD_FIELDS_EXCLUDE.contains(fieldName)) {
- if(ssmSerialize != null) {
- ssmSerialize.put(ssmobj.Fields.getMap().get(fieldName).getDescribe().getName(), newSSM.get(fieldName));
- if(!ApplicationConstant.FIELDS_TO_NOT_COPY_IN_DETAILS_ONLY.contains(fieldName)){
- String oldValue = prepareDetailString((sObject)oldSSM, fieldName);
- String newValue = prepareDetailString((sObject)newSSM, fieldName);
- modDetails = modDetails + ssmobj.Fields.getMap().get(fieldName).getDescribe().getLabel() + ': ' + oldSSM.get(fieldName) + ' => ' + newSSM.get(fieldName) + '\r\n';
- String valueOfField = String.valueof(ssmobj.Fields.getMap().get(fieldName).getDescribe().getLabel());
- mapOfFields = putValuesToMap(mapOfFields,valueOfField,oldValue , newValue);
- }
- } else {
- ssmSerialize = new Sold_Service_Modification__c();
- ssmSerialize.put(ssmobj.Fields.getMap().get(fieldName).getDescribe().getName(), newSSM.get(fieldName));
- if(!ApplicationConstant.FIELDS_TO_NOT_COPY_IN_DETAILS_ONLY.contains(fieldName)){
- String oldValue = prepareDetailString((sObject)oldSSM, fieldName);
- String newValue = prepareDetailString((sObject)newSSM, fieldName);
- modDetails = modDetails + ssmobj.Fields.getMap().get(fieldName).getDescribe().getLabel() + ': ' + oldSSM.get(fieldName) + ' => ' + newSSM.get(fieldName) + '\r\n';
- String valueOfField = String.valueof(ssmobj.Fields.getMap().get(fieldName).getDescribe().getLabel());
- mapOfFields = putValuesToMap(mapOfFields,valueOfField,oldValue , newValue);
- }
- }
- }
- }
- }
- }
- }
- if(newSSM.Action__c == 'Technical Change')System.debug('TC!!!!');
- if(!String.isEmpty(modDetails)){
- modDetails = returnDetailsFromMap(mapOfFields);
- newSSM.Details__c = modDetails;
- }
- if(ssmSerialize != null) {
- newSSM.TECH_Changed_Values_JSON__c = JSON.Serialize(ssmSerialize);
- }
- }
- public static Map<String,Map<String,String>> putValuesToMap(Map<String,Map<String,String>> fields, String fieldToMap, String oldValues,String newValues){
- String key = fieldToMap;
- String detailss = '';
- Map<String,String> oldValueNewValue = new Map<String,String>();
- if(key != null && !key.containsIgnoreCase('Billing Profile') && !fields.containsKey(key)){
- oldValueNewValue.put(oldValues,newValues);
- fields.put(key, oldValueNewValue);
- }else if(key.containsIgnoreCase('Billing Profile') && !fields.containsKey(key)){
- Id newId =(Id) oldValues;
- Id oldId =(Id) newValues;
- String oldValToMap = '';
- String newValToMap = '';
- if(newId != null){
- Map<Id,Billing_Profile__c> bpNew = new Map<Id, Billing_Profile__c>([SELECT Name,Id FROM Billing_Profile__c WHERE Id = :newId]);
- if(bpNew.containsKey(newId) != null){
- newValToMap = (String)bpNew.get(newId).Name;
- }
- }else{
- newValToMap = 'null';
- }
- if(oldId != null){
- Map<Id,Billing_Profile__c> bpOld = new Map<Id, Billing_Profile__c>([SELECT Name,Id FROM Billing_Profile__c WHERE Id = :oldId]);
- if(bpOld.containsKey(oldId) != null){
- oldValToMap = (String)bpOld.get(oldId).Name;
- }
- }else{
- oldValToMap = 'null';
- }
- oldValueNewValue.put(newValToMap,oldValToMap);
- fields.put(key, oldValueNewValue);
- }
- return fields;
- }
- public static String returnDetailsFromMap(Map<String,Map<String,String>> fields){
- String modDetailsAfterMapping = '';
- for(String outerKey : fields.keySet()){
- for(String innerKey : fields.get(outerKey).keySet()){
- modDetailsAfterMapping += outerKey + ':' + innerKey + '=>' + fields.get(outerKey).get(innerKey) + '\r\n';
- }
- }
- return modDetailsAfterMapping;
- }
- public static void lockSsmFields(Sold_Service_Modification__c newSsm, Sold_Service_Modification__c oldSsm) {
- Schema.DescribeSObjectResult ssmobj = Schema.getGlobalDescribe().get('Sold_Service_Modification__c').getDescribe();
- Map<String, Schema.SObjectField> ssmschemaFieldMap = ssmobj.fields.getMap();
- for(String fieldName : ssmschemaFieldMap.keySet()) {
- if((!ApplicationConstant.SOLDSERVICEMOD_UNLOCK_FIELDS.contains(fieldName) &&
- ((newSsm.TECH_Financial_Update__c && !ApplicationConstant.SOLDSERVICEMOD_UNLOCK_FINANCIALS_FIELDS.contains(fieldName)) || !newSsm.TECH_Financial_Update__c))
- && newSsm.get(fieldName) != null && newSsm.get(fieldName) != oldSsm.get(fieldName)) {
- try{
- newSsm.addError('This field is locked and cannot be changed: ' + fieldName);
- } catch (Exception ex){
- System.debug('This field was locked and cannot be changed, but transaction is not corrupted');
- }
- }
- }
- }
- public static void attachSStoOM(Map<Id, Sold_Service_Modification__c> rfsSSM) {
- Map<Id, Id> ssm2ss = new Map<Id, Id>();
- for(Id key : rfsSSM.keySet()){
- if(rfsSSM.get(key).Sold_Service__c != null){
- ssm2ss.put(key, rfsSSM.get(key).Sold_Service__c);
- }
- }
- List<OM_External_Order__c> orderList = new List<OM_External_Order__c>();
- for (OM_External_Order__c omex : [SELECT Sold_Service__c, Sold_Service_Modification__c FROM OM_External_Order__c WHERE Sold_Service_Modification__c IN: ssm2ss.keyset() ]) {
- omex.Sold_Service__c = ssm2ss.get(omex.Sold_Service_Modification__c);
- orderList.add(omex);
- }
- if (!orderList.isEmpty()){
- update orderList;
- }
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function Method used for updating Stage of SSM based on Configuration
- (Delivery Administration -> Configure Status Automation)
- ****************************************************************************************/
- public static void runStageAutomation(Set<Id> inputSsmIdSet) {
- CPQ_Utils04_RequestStateCls.setOn('STAGE_AUTOMATION_STOP');
- List<Sold_Service_Modification__c> ssmToUpdateList = new List<Sold_Service_Modification__c>();
- List<Delivery_Steps__c> dsConfigList = getStatusAutomationConfiguration();
- Map<Id, Sold_Service_Modification__c> parentSsmMap = getSsmInfo(inputSsmIdSet);
- Map<Id, List<String>> ssmToNboWoStatusMap = new Map<Id, List<String>>();
- Map<Id, List<String>> ssmToTpsWoStatusMap = new Map<Id, List<String>>();
- Map<Id, Map<String, String>> ssmToWoGroupMinStatusMap = getConnectedWoMinGroupStatuses(parentSsmMap, ssmToNboWoStatusMap, ssmToTpsWoStatusMap);
- for (Id key : parentSsmMap.keySet()) {
- Sold_Service_Modification__c ssmRecord = parentSsmMap.get(key);
- for (Delivery_Steps__c ds : dsConfigList) {
- if(ds.Action__c != null && ds.Action__c != ''){
- Set<String> actionSet = convertMPLtoApexSet(ds.Action__c);
- if (ds.Action__c != null && ssmRecord.Action__c != null && actionSet.contains(ssmRecord.Action__c)
- && ssmToWoGroupMinStatusMap.get(key) != null
- && areRequiredWoInFinalStage(ssmToWoGroupMinStatusMap.get(key), ds.Work_Order_Type__c, ds.Required_Work_Order_Type__c)
- && areNboTpsInRequiredStage(ssmToTpsWoStatusMap.get(key), ds.Consider_Connected_TPS_Status__c, ds.Minimum_TPS_Status__c)
- && areNboTpsInRequiredStage(ssmToNboWoStatusMap.get(key), ds.Consider_Connected_NBO_Status__c, ds.Minimum_NBO_Status__c)) {
- if (ssmRecord.Stage__c != ds.TECH_SSM_Stage__c || !CPQ_Utils04_RequestStateCls.isOn('MODIFICATION')) {
- ssmRecord.Stage__c = ds.TECH_SSM_Stage__c;
- ssmToUpdateList.add(new Sold_Service_Modification__c(Id = ssmRecord.ID, Stage__c = ds.TECH_SSM_Stage__c, CRM_Parent_Sold_Service_Modification__c = ssmRecord.CRM_Parent_Sold_Service_Modification__c));
- }
- break;
- }
- }
- }
- }
- if (!ssmToUpdateList.isEmpty()){
- /**
- ** MIPAS [TSIC-1481] SS is not changing to Live Service when SSM Tech Change changes to 30.
- ** If 500 fails, check those flags
- **/
- if(!CPQ_Utils04_RequestStateCls.isOn('WORK_ORDER_CUSTOM_ASSIGNMENT_RULE')) {
- CPQ_Utils04_RequestStateCls.setOff('SOLD_SERVICE_SYNCED');
- CPQ_Utils04_RequestStateCls.setOff('MODIFICATION');
- } else {
- CPQ_Utils04_RequestStateCls.setOn('ORCHESTRATOR');
- }
- update ssmToUpdateList;
- CPQ_Utils04_RequestStateCls.setOn('SOLD_SERVICE_SYNCED');
- CPQ_Utils04_RequestStateCls.setOn('MODIFICATION');
- Set<Id> ssmIDs = new Set<Id>();
- for(Sold_Service_Modification__c ssm : ssmToUpdateList){
- ssmIDs.add(ssm.Id);
- if(ssm.CRM_Parent_Sold_Service_Modification__c != null){
- ssmIDs.add(ssm.CRM_Parent_Sold_Service_Modification__c);
- }
- }
- CPQ_Utils04_RequestStateCls.setOn('ORCHESTRATOR');
- CPQ_SSM10_ModificationHlprCls.updateSSMRecords(ssmIDs);
- }
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function Method used to check if connected to SSM work orders of type NBO fulfill
- the requirements from Stage Automation Configuration
- ****************************************************************************************/
- public static Boolean areNboTpsInRequiredStage(List<String> inputNboTpsWoStatusList, Boolean inputIsNboTpsRequired, String inputAllowedNboTpsStatuses) {
- Boolean result = false;
- if (inputAllowedNboTpsStatuses == null) {
- result = true;
- } else if (inputIsNboTpsRequired != true && (inputNboTpsWoStatusList == null || inputNboTpsWoStatusList.isEmpty()) ) {
- result = true;
- } else if (inputNboTpsWoStatusList != null && !inputNboTpsWoStatusList.isEmpty() && inputAllowedNboTpsStatuses != null) {
- result = true;
- Set<String> allowedNboStatusSet = convertMPLtoApexSet(inputAllowedNboTpsStatuses);
- if (!allowedNboStatusSet.containsAll(inputNboTpsWoStatusList)) {
- result = false;
- }
- }
- return result;
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function Method used to convert multi picklist to Set of strings
- ****************************************************************************************/
- public static Set<String> convertMPLtoApexSet(String multiPickList) {
- Set<String> mplValuesSet = new Set<String>(multiPickList.split(';'));
- return mplValuesSet;
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function Method used to check if different type of work orders
- (specified in Stage Automation Configuration) are in their final stage
- ****************************************************************************************/
- public static Boolean areRequiredWoInFinalStage(Map<String, String> inputWoStatusMap, String woThatNeedToBeCompleted, String inputRequiredWo) {
- Boolean result = true;
- if (woThatNeedToBeCompleted != null) {
- Set<String> typesOfWoToCompleteSet = convertMPLtoApexSet(woThatNeedToBeCompleted);
- for (String woTypeName : typesOfWoToCompleteSet) {
- if (inputWoStatusMap.get(woTypeName) != null && !ApplicationConstant.HELPER_STATUS_COMPLETED.equalsIgnoreCase(inputWoStatusMap.get(woTypeName))) {
- result = false;
- break;
- } else if (inputWoStatusMap.get(woTypeName) == null && inputRequiredWo != null && inputRequiredWo.contains(woTypeName)) {
- result = false;
- break;
- }
- }
- }
- return result;
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function Method used to find if different types of Work orders connected to given SSM
- are in their final stage and mark them either as 'Completed' or 'Incomplete'
- ****************************************************************************************/
- public static Map<Id, Map<String, String>> getConnectedWoMinGroupStatuses(Map<Id, Sold_Service_Modification__c> inputSsmMap, Map<Id, List<String>> inputSsmToNboWoMap, Map<Id, List<String>> inputSsmToTpsoWoMap) {
- Map<Id, Map<String, String>> result = new Map<Id, Map<String, String>>();
- for (Id key : inputSsmMap.keySet()) {
- for (WorkOrder wo : inputSsmMap.get(key).Work_Orders__r) {
- if (CPQ_Utils.recordTypeId('WorkOrder.Network_Buildout_Request') == wo.RecordTypeId) {
- if (inputSsmToNboWoMap.get(key) != null) {
- inputSsmToNboWoMap.get(key).add(wo.Status);
- } else {
- inputSsmToNboWoMap.put(key, new List<String>{wo.Status});
- }
- } else if (CPQ_Utils.recordTypeId('WorkOrder.Third_Party_Service') == wo.RecordTypeId) {
- if (inputSsmToTpsoWoMap.get(key) != null) {
- inputSsmToTpsoWoMap.get(key).add(wo.Status);
- } else {
- inputSsmToTpsoWoMap.put(key, new List<String>{wo.Status});
- }
- }
- if (result.get(key) != null) {
- if (result.get(key).get(wo.Type__c) != null) {
- if (!CPQ_WOR50_DefaultTH.woGroupStatusClosed.contains(wo.StatusCategory)
- && ApplicationConstant.HELPER_STATUS_COMPLETED.equalsIgnoreCase(result.get(key).get(wo.Type__c))) {
- result.get(key).put(wo.Type__c, ApplicationConstant.HELPER_STATUS_INCOMPLETE);
- }
- } else {
- result.get(key).put(wo.Type__c, checkStatusCategoryStage(wo.StatusCategory));
- }
- } else {
- result.put(key, new Map<String, String>{wo.Type__c => checkStatusCategoryStage(wo.StatusCategory)});
- }
- }
- }
- return result;
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function This Method is used to tell if specified StatusCategory is one of the
- final statuses or not.
- ****************************************************************************************/
- public static String checkStatusCategoryStage(String inputStatusCategoryName) {
- if (CPQ_WOR50_DefaultTH.woGroupStatusClosed.contains(inputStatusCategoryName)) {
- return ApplicationConstant.HELPER_STATUS_COMPLETED;
- } else {
- return ApplicationConstant.HELPER_STATUS_INCOMPLETE;
- }
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function This Method is used to gather information about SSM, connected to this SSM
- Work Orders and Third party Services
- ****************************************************************************************/
- public static Map<Id, Sold_Service_Modification__c> getSsmInfo(Set<Id> inputSsmIdSet) {
- Map<Id, Sold_Service_Modification__c> ssmMap = new Map<Id, Sold_Service_Modification__c>([
- SELECT Action__c, Stage__c, Item_Type__c, CRM_Parent_Sold_Service_Modification__c, (SELECT Status, StatusCategory, Type__c, RecordTypeId, RecordType.Name FROM Work_Orders__r WHERE Type__c != null)
- FROM Sold_Service_Modification__c
- WHERE Id IN :inputSsmIdSet
- AND (Stage__c != :ApplicationConstant.SSM_STAGE_CANCELLED AND Stage__c != :ApplicationConstant.SSM_STAGE_REJECTED AND Stage__c != :ApplicationConstant.SSM_STAGE_LIVE) FOR UPDATE]);
- return ssmMap;
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-09-03
- Function This Method is used to get information about Stage Automation Configuration
- (Accessible from GUI - Delivery Administration).
- ****************************************************************************************/
- public static List<Delivery_Steps__c> getStatusAutomationConfiguration() {
- final Id DS_STATUS_AUTOMATION_RT_ID = CPQ_Utils.recordTypeId('Delivery_Steps__c.Status_Automation');
- List<Delivery_Steps__c> dsList = [
- SELECT Action__c, Consider_Connected_NBO_Status__c, Consider_Connected_TPS_Status__c, Minimum_NBO_Status__c, Minimum_TPS_Status__c,
- Required_Work_Order_Type__c, Work_Order_Type__c, TECH_SSM_Stage__c
- FROM Delivery_Steps__c
- WHERE RecordTypeId = :DS_STATUS_AUTOMATION_RT_ID
- ORDER BY TECH_SSM_Stage__c DESC];
- return dsList;
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-10-09
- Function This Method is used to update information about connected Port on SSM.
- The input is map of SSMs where at least one Port lookup changed.
- SOQL: 1
- DML: 0
- ****************************************************************************************/
- public static void updateChangedPortInfoOnSSM(List<Sold_Service_Modification__c> inputSsmPortChangedList) {
- Set<Id> connectedPortIdSet = new Set<Id>();
- for (Sold_Service_Modification__c ssm : inputSsmPortChangedList) {
- if (ssm.A_Port__c != null) connectedPortIdSet.add(ssm.A_Port__c);
- if (ssm.B_Port__c != null) connectedPortIdSet.add(ssm.B_Port__c);
- }
- Map<Id, Port__c> connectedPortsList = new Map<Id, Port__c>([
- SELECT Location__c, Homing_Gateway__c, Site__c, Interface__c, Connector__c, Demarc_Type__c, Demarc_Site__c,
- Demarc_Comments__c, Floor__c, Room__c, Rack__c, Port_Type__c
- FROM Port__c
- WHERE Id in :connectedPortIdSet
- ]);
- for (Sold_Service_Modification__c ssm : inputSsmPortChangedList) {
- if (ssm.A_Port__c != null) {
- Port__c aPort = connectedPortsList.get(ssm.A_Port__c);
- for(String portField : CPQ_LOC01_MANAGER.PORT_A_TO_SS_FIELD_MAP.keySet()) {
- ssm.put(CPQ_LOC01_MANAGER.PORT_A_TO_SS_FIELD_MAP.get(portField), aPort.get(portField));
- }
- } else {
- for(String portField : CPQ_LOC01_MANAGER.PORT_A_TO_SS_FIELD_MAP.keySet()) {
- ssm.put(CPQ_LOC01_MANAGER.PORT_A_TO_SS_FIELD_MAP.get(portField), null);
- }
- }
- if (ssm.B_Port__c != null) {
- Port__c bPort = connectedPortsList.get(ssm.B_Port__c);
- for(String portField : CPQ_LOC01_MANAGER.PORT_B_TO_SS_FIELD_MAP.keySet()) {
- ssm.put(CPQ_LOC01_MANAGER.PORT_B_TO_SS_FIELD_MAP.get(portField), bPort.get(portField));
- }
- } else {
- for(String portField : CPQ_LOC01_MANAGER.PORT_B_TO_SS_FIELD_MAP.keySet()) {
- ssm.put(CPQ_LOC01_MANAGER.PORT_B_TO_SS_FIELD_MAP.get(portField), null);
- }
- }
- }
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-10-18
- Function This Async Method is used to update Stage of Port Change Requests that are connected
- to given Sold Service Modification (wchich changed stage to 30. Complete). This is used if
- the context is not a batch.
- SOQL: 0
- DML: 0
- ****************************************************************************************/
- @future
- public static void updateChangedPortInfoOnSSMAsync(Map<Id, String> ssmToStageInputMap) {
- updateChangedPortInfoOnSSM(ssmToStageInputMap);
- }
- /***************************************************************************************
- Developer Grzegorz Długosz (Enxoo) grzegorz.dlugosz@enxoo.com
- Date 2017-10-18
- Function This Method is used to update Stage of Port Change Requests that are connected
- to given Sold Service Modification (wchich changed stage to 30. Complete).
- This is used if context is a batch.
- SOQL: 1
- DML: 1
- ****************************************************************************************/
- public static void updateChangedPortInfoOnSSM(Map<Id, String> ssmToStageInputMap) {
- List<Port_Change_Request__c> pcrToUpdateList = new List<Port_Change_Request__c>();
- List<Port_Change_Request__c> pcrQuery = [
- SELECT Stage__c, Sold_Service_Modification__c
- FROM Port_Change_Request__c
- WHERE Sold_Service_Modification__c IN :ssmToStageInputMap.keySet()
- AND Stage__c != :ApplicationConstant.SSM_STAGE_LIVE
- FOR UPDATE
- ];
- for (Port_Change_Request__c pcr : pcrQuery) {
- if(pcr.Stage__c != ssmToStageInputMap.get(pcr.Sold_Service_Modification__c)) {
- pcr.Stage__c = ssmToStageInputMap.get(pcr.Sold_Service_Modification__c);
- pcrToUpdateList.add(pcr);
- }
- }
- if (!pcrToUpdateList.isEmpty()) update pcrToUpdateList;
- }
- /**
- * @author Grzegorz Długosz - grzegorz.dlugosz@enxoo.com
- * @description This method is used to fill information about parent (SS) of Sold Service
- * that this SSM is connected to. (Parent_of_Sold_Service__c field on SSM)
- * @param ssmInputList - List of SSMs that might need
- * reference to parent of Sold Service filled.
- */
- public static void fillParentSSFieldOnSSM(List<Sold_Service_Modification__c> ssmInputList) {
- Set<Id> soldServiceSet = new Set<Id>();
- for (Sold_Service_Modification__c ssm : ssmInputList) {
- soldServiceSet.add(ssm.Sold_Service__c);
- }
- Map<Id, Sold_Service__c> parentSSMap = new Map<Id, Sold_Service__c>([
- SELECT CRM_Parent_Sold_Service__c
- FROM Sold_Service__c
- WHERE CRM_Parent_Sold_Service__c != null
- AND Id IN :soldServiceSet
- ]);
- for (Sold_Service_Modification__c ssm : ssmInputList) {
- if (parentSSMap.get(ssm.Sold_Service__c) != null) {
- ssm.Parent_of_Sold_Service__c = parentSSMap.get(ssm.Sold_Service__c).CRM_Parent_Sold_Service__c;
- }
- }
- }
- /***************************************************************************************
- Developer David Lindstrom (Enxoo) david.lindstroem@enxoo.com
- Date 2018-01-12
- Function This Method is used to rollup the OLI_Capex__c from Opportunity Line Item to
- SSM and SS when SSM Stage is set to '30. Modification Complete'
- SOQL: 1
- DML: 1
- ****************************************************************************************/
- public static void rollupOliCapexOnSSMandSS(Map<Id, Sold_Service_Modification__c> ssmInputMap) {
- Set<Id> oppLineItemIds = new Set<Id>();
- for (Sold_Service_Modification__c ssm : ssmInputMap.values()) {
- oppLineItemIds.add(ssm.OLI_Link_ID__c);
- }
- Map<Id, OpportunityLineItem> oliMap = new Map<Id, OpportunityLineItem>([
- SELECT OLI_Capex__c
- FROM OpportunityLineItem
- WHERE Id IN :oppLineItemIds
- ]);
- List<Sold_Service__c> ssToUpdate = new List<Sold_Service__c>();
- for(Sold_Service_Modification__c ssm : ssmInputMap.values()) {
- if(oliMap.containsKey(ssm.OLI_Link_ID__c)) {
- Double capexValue = oliMap.get(ssm.OLI_Link_ID__c).OLI_Capex__c;
- ssm.Service_Capex__c = capexValue;
- if(ssm.Sold_Service__c != null) {
- Sold_Service__c ss = new Sold_Service__c(Id = ssm.Sold_Service__c);
- ss.Service_Capex__c = capexValue;
- ssToUpdate.add(ss);
- }
- }
- }
- CPQ_Utils04_RequestStateCls.SetOn('DISABLE_RECURSIVE_SS_UPDATE');
- update ssToUpdate;
- CPQ_Utils04_RequestStateCls.SetOff('DISABLE_RECURSIVE_SS_UPDATE');
- }
- /***************************************************************************************
- Developer David Lindstrom (Enxoo) david.lindstroem@enxoo.com
- Date 2019-01-04
- Function This Async Method is used to cancel/reject the other related Cease & Reprovide SSM
- when one of them are cancelled/rejected. This is used if
- the context is not a batch.
- SOQL: 1
- DML: 1
- ****************************************************************************************/
- @future
- public static void cancelRelatedCeaseAndReprovideSsmAsync(Set<Id> ssmCeaseAndReproviceIds) {
- Map<Id, Sold_Service_Modification__c> ssmMap =
- new Map<Id, Sold_Service_Modification__c>(
- [SELECT Id, Opp_Link__c, Action__c, Stage__c, Next_Sold_Service_Instance__c, Sold_Service__c
- FROM Sold_Service_Modification__c
- WHERE Id IN: ssmCeaseAndReproviceIds]);
- cancelRelatedCeaseAndReprovideSsm(ssmMap);
- }
- /***************************************************************************************
- Developer David Lindstrom (Enxoo) david.lindstroem@enxoo.com
- Date 2018-12-18
- Function This Method is used to cancel/reject the other related Cease & Reprovide SSM
- when one of them are cancelled/rejected.
- Note: If one of the Cease & Reprovide SSMs is cancelled/rejected and the
- other one has already been Completed, we leave it as is and don't force it
- to be cancelled/rejected also.
- SOQL: 2
- DML: 2
- ****************************************************************************************/
- public static void cancelRelatedCeaseAndReprovideSsm(Map<Id, Sold_Service_Modification__c> ssmCeaseAndReproviceMap){
- Map<Id, Sold_Service_Modification__c> mapOppIdToSsm = new Map<Id, Sold_Service_Modification__c>();
- for(Sold_Service_Modification__c cancelledSsm : ssmCeaseAndReproviceMap.values()){
- mapOppIdToSsm.put(cancelledSsm.Opp_Link__c, cancelledSsm);
- }
- Set<Id> oppIds = mapOppIdToSsm.keySet();
- Set<Id> cancelledOrRejectedSsm = ssmCeaseAndReproviceMap.keySet();
- List<Sold_Service_Modification__c> relatedCeaseAndReproviceSsm =
- [SELECT Id, Stage__c, Opp_Link__c, Sold_Service__c, Next_Sold_Service_Instance__c, TECH_Allow_Stage_Change__c
- FROM Sold_Service_Modification__c
- WHERE Opp_Link__c IN: oppIds
- AND Id NOT IN: cancelledOrRejectedSsm
- AND Stage__c != :ApplicationConstant.SSM_STAGE_LIVE
- FOR UPDATE];
- List<Sold_Service_Modification__c> ssmToUpdate = new List<Sold_Service_Modification__c>();
- for(Sold_Service_Modification__c relatedSsm : relatedCeaseAndReproviceSsm){
- if(mapOppIdToSsm.containsKey(relatedSsm.Opp_Link__c)){
- Sold_Service_Modification__c cancelledSsm = mapOppIdToSsm.get(relatedSsm.Opp_Link__c);
- if(cancelledSsm.Action__c == 'Cease' && cancelledSsm.Next_Sold_Service_Instance__c == relatedSsm.Sold_Service__c){
- relatedSsm.Stage__c = cancelledSsm.Stage__c;
- relatedSsm.TECH_Allow_Stage_Change__c = !relatedSsm.TECH_Allow_Stage_Change__c;
- ssmToUpdate.add(relatedSsm);
- }
- else if(cancelledSsm.Action__c == 'Reprovide' && cancelledSsm.Sold_Service__c == relatedSsm.Next_Sold_Service_Instance__c){
- relatedSsm.Stage__c = cancelledSsm.Stage__c;
- relatedSsm.TECH_Allow_Stage_Change__c = !relatedSsm.TECH_Allow_Stage_Change__c;
- ssmToUpdate.add(relatedSsm);
- }
- }
- }
- if(!CPQ_Utils04_RequestStateCls.isOn('UPDATING_RELATED_C&R_SSM')){
- CPQ_Utils04_RequestStateCls.setOn('UPDATING_RELATED_C&R_SSM');
- try {
- update ssmToUpdate;
- }
- catch (Exception e) {
- System.debug('@@ CPQ_SSM01_Manager.cancelRelatedCeaseAndReprovideSsm exception message: ' + e.getMessage());
- }
- cancelRelatedWorkOrders(ssmToUpdate);
- }
- }
- public static void cancelRelatedWorkOrders(List<Sold_Service_Modification__c> cancelledSsmList){
- Set<Id> ssmIds = (new Map<Id, Sold_Service_Modification__c>(cancelledSsmList)).keySet();
- List<WorkOrder> fetchedWorkOrders =
- [SELECT Id, Sold_Service_Modification__c, StatusCategory, Type__c, RecordTypeId, Record_Type_Name__c FROM WorkOrder
- WHERE Sold_Service_Modification__c IN: ssmIds FOR UPDATE];
- Set<String> closedStatuses = new Set<String>{'Completed', 'Closed'};
- Set<String> inProgressStatusCategory = new Set<String>{'InProgress'};
- List<WorkOrder> woToUpdate = new List<WorkOrder>();
- List<WorkOrder> woToInsert = new List<WorkOrder>();
- for(WorkOrder wo : fetchedWorkOrders){
- if(closedStatuses.contains(wo.StatusCategory)){
- WorkOrder newWo = new WorkOrder();
- newWo.Status = 'New';
- newWo.Subject = 'Cancelled: Revert Any Changes';
- newWo.Sold_Service_Modification__c = wo.Sold_Service_Modification__c;
- newWo.Type__c = wo.Type__c;
- if(wo.Record_Type_Name__c == 'Automated Work Order'){
- newWo.RecordTypeId = wo.RecordTypeId;
- }
- woToInsert.add(newWo);
- }
- else if(inProgressStatusCategory.contains(wo.StatusCategory)) {
- wo.Status = ApplicationConstant.WORK_ORDER_STATUS_CANCELLED;
- woToUpdate.add(wo);
- }
- else {
- // Do nothing
- }
- }
- CPQ_Utils04_RequestStateCls.setOn('WORK_ORDER_CUSTOM_ASSIGNMENT_RULE');
- try {
- insert woToInsert;
- }
- catch(Exception e) {
- System.debug('@@ CPQ_SSM01_Manager.cancelRelatedCeaseAndReprovideSsm insert WorkOrder exception message: ' + e.getMessage());
- System.debug('@@ CPQ_SSM01_Manager.cancelRelatedCeaseAndReprovideSsm failed to insert WorkOrders: ' + woToInsert);
- }
- CPQ_Utils04_RequestStateCls.setOff('WORK_ORDER_CUSTOM_ASSIGNMENT_RULE');
- CPQ_Utils04_RequestStateCls.setOn('WORK_ORDER_CUSTOM_ASSIGNMENT_RULE');
- try {
- update woToUpdate;
- }
- catch(Exception e) {
- System.debug('@@ CPQ_SSM01_Manager.cancelRelatedCeaseAndReprovideSsm update WorkOrder exception message: ' + e.getMessage());
- System.debug('@@ CPQ_SSM01_Manager.cancelRelatedCeaseAndReprovideSsm failed to update WorkOrders: ' + woToUpdate);
- }
- CPQ_Utils04_RequestStateCls.setOff('WORK_ORDER_CUSTOM_ASSIGNMENT_RULE');
- }
- public static void checkWayOfDelivery(List<Sold_Service_Modification__c> ssmList){
- Set<Id> ssIdSet = gatherSSfromSSM(ssmList);
- Map<Id, Id> provisionedSS = findSSprovisioned(ssIdSet);
- if(provisionedSS.isEmpty() && !CPQ_Utils04_RequestStateCls.isOn('ISBATCH_SSM') ){
- checkAllAsManual(ssmList);
- return;
- }
- Set<String> tosSet = prepareToSSet(ssmList, provisionedSS.keySet());
- Map<String, String> nsoDSMap = getNSODS(tosSet);
- if(nsoDSMap.isEmpty()){
- checkAllAsManual(ssmList);
- } else {
- Map<Id, Service_Group__c> groups2update = new Map<Id, Service_Group__c>();
- for(Sold_Service_Modification__c ssm: ssmList){
- if(ssm.Type_of_Service__c == null){
- ssm.Manual_Work_Delivery__c = true;
- continue;
- }
- String key = ssm.Type_of_Service__c;
- if(ssm.CPQ_Component__c != null){
- key += '_' + ssm.CPQ_Component__c;
- } else if(ssm.CPQ_Product__c != null){
- key += '_' + ssm.CPQ_Product__c;
- }
- if(!nsoDSMap.containsKey(key) && !nsoDSMap.containsKey(ssm.Type_of_Service__c)){
- ssm.Manual_Work_Delivery__c = true;
- } else if( provisionedSS.containsKey(ssm.Sold_Service__c) && nsoDSMap.get(key).containsIgnoreCase(ssm.Action__c)){
- ssm.Manual_Work_Delivery__c = false;
- } else if( CPQ_Utils04_RequestStateCls.isOn('ISBATCH_SSM') && !provisionedSS.containsKey(ssm.Sold_Service__c) && nsoDSMap.get(key).containsIgnoreCase(ssm.Action__c) ){
- ssm.Manual_Work_Delivery__c = false;
- } else {
- ssm.Manual_Work_Delivery__c = true;
- }
- if(ssm.Manual_Work_Delivery__c && provisionedSS.containsKey(ssm.Sold_Service__c)){
- Id serviceGroupId = provisionedSS.get(ssm.Sold_Service__c);
- groups2update.put(serviceGroupId, new Service_Group__c(Id = serviceGroupId, NSO_Available__c = false));
- }
- }
- if(!groups2update.isEmpty()){
- database.update(groups2update.values(), false);
- }
- }
- }
- private static Set<String> prepareToSSet(List<Sold_Service_Modification__c> ssmForToS, Set<Id> provisionedByGroup){
- Set<String> resultSet = new Set<String>();
- for(Sold_Service_Modification__c ssm : ssmForToS){
- if(ssm.Type_of_Service__c != null){
- if(provisionedByGroup.contains(ssm.Sold_Service__c)){
- resultSet.add(ssm.Type_of_Service__c);
- } else if( CPQ_Utils04_RequestStateCls.isOn('ISBATCH_SSM') ){
- resultSet.add(ssm.Type_of_Service__c);
- }
- }
- }
- return resultSet;
- }
- private static Map<String, String> getNSODS(Set<String> tosSet){
- Map<String, String> resultMap = new Map<String, String>();
- for(Delivery_Steps__c ds: [SELECT Attribute_Type_of_Service__r.Name__c, Attribute_Type_of_Service__r.Exclusive_for_Product__c, Attribute_Type_of_Service__r.Exclusive_for_Component__c, Delivery_Step__r.Action__c FROM Delivery_Steps__c
- WHERE RecordTypeId =: CPQ_WOR20_CreatorBaseCls.DELIVERY_STEP_ATR_JUNCTION_RT AND Delivery_Step__r.Active__c = true
- AND Attribute_Type_of_Service__r.Name__c IN: tosSet]){
- String key = ds.Attribute_Type_of_Service__r.Name__c;
- if(ds.Attribute_Type_of_Service__r.Exclusive_for_Component__c != null){
- key += '_' + ds.Attribute_Type_of_Service__r.Exclusive_for_Component__c;
- } else if(ds.Attribute_Type_of_Service__r.Exclusive_for_Product__c != null){
- key += '_' + ds.Attribute_Type_of_Service__r.Exclusive_for_Product__c;
- }
- if(!resultMap.containsKey(key)){
- resultMap.put(key, ds.Delivery_Step__r.Action__c);
- } else {
- resultMap.put(key, resultMap.get(key) + ds.Delivery_Step__r.Action__c);
- }
- }
- return resultMap;
- }
- private static void checkAllAsManual(List<Sold_Service_Modification__c> ssmList){
- for(Sold_Service_Modification__c ssm: ssmList){
- ssm.Manual_Work_Delivery__c = true;
- }
- }
- private static Set<Id> gatherSSfromSSM(List<Sold_Service_Modification__c> ssmList){
- Set<Id> resultSet = new Set<Id>();
- for(Sold_Service_Modification__c ssm : ssmList){
- resultSet.add(ssm.Sold_Service__c);
- }
- return resultSet;
- }
- private static Map<Id, Id> findSSprovisioned(Set<Id> ssList){
- Map<Id, Id> resultMap = new Map<Id, Id>();
- for( Sold_Service__c ss : [SELECT Id, Service_Group__c FROM Sold_Service__c WHERE Id IN: ssList AND Service_Group__c != null AND Service_Group__r.NSO_Available__c = true]){
- resultMap.put(ss.Id, ss.Service_Group__c);
- }
- return resultMap;
- }
- public static void updateConnnectedGroups(Set<Id> ssIdSet){
- Map<Id, Id> provisionedSS = findSSprovisioned(ssIdSet);
- List<Service_Group__c> groups2update = new List<Service_Group__c>();
- for(Id ssId : ssIdSet){
- groups2update.add(new Service_Group__c(Id = provisionedSS.get(ssId), NSO_Available__c = false));
- }
- if(!groups2update.isEmpty()){
- database.update(groups2update, false);
- }
- }
- public static void markSSMlistWithInflightChange(List<Sold_Service_Modification__c> ssmList){
- List<Sold_Service_Modification__c> validetedSSM = validateSSM(ssmList);
- changeWOstatus(gatherConnectedWo(validetedSSM));
- for(Sold_Service_Modification__c ssm : validetedSSM){
- markSSM(ssm);
- }
- update validetedSSM;
- }
- public static List<Sold_Service_Modification__c> validateSSM(List<Sold_Service_Modification__c> ssmList){
- List<Sold_Service_Modification__c> validatedSsmList = new List<Sold_Service_Modification__c>();
- for(Sold_Service_Modification__c ssm : ssmList){
- if(ssm.Action__c =='Add' && (!ssm.Stage__c.contains(ApplicationConstant.SSM_STAGE_CANCELLED) || !ssm.Stage__c.contains(ApplicationConstant.SSM_STAGE_PENDING_CUST_ACCEPTANCE)
- || !ssm.Stage__c.contains(ApplicationConstant.SSM_STAGE_REJECTED) || !ssm.Stage__c.contains(ApplicationConstant.SSM_STAGE_LIVE))){
- validatedSsmList.add(ssm);
- }
- }
- return validatedSsmList;
- }
- public static List<WorkOrder> gatherConnectedWo(List<Sold_Service_Modification__c> validatedSsmList){
- List<WorkOrder> connectedWO = [SELECT Id, Status, WorkOrderNumber FROM WorkOrder WHERE Sold_Service_Modification__c IN : validatedSsmList AND RecordType.DeveloperName != 'Automated_Work_Order'];
- return connectedWO;
- }
- public static void changeWOstatus(List<WorkOrder> woList){
- List<WorkOrder> changedWo = new List<WorkOrder>();
- for (WorkOrder wo : woList){
- if(wo.Status == 'New' || wo.Status == 'In Progress'){
- wo.Previous_Status__c = wo.Status;
- wo.Status = 'On Hold';
- changedWo.add(wo);
- }
- }
- update changedWo;
- }
- public static void markSSM(Sold_Service_Modification__c ssm){
- ssm.In_flight_Change_Requested__c = true;
- ssm.Stage__c = ApplicationConstant.SSM_STAGE_ON_HOLD;
- ssm.TECH_Allow_Stage_Change__c = !ssm.TECH_Allow_Stage_Change__c;
- ssm.TECH_SSM_Snapshot__c = JSON.serialize(ssm);
- }
- public static void markSSMlistWithInflightChange(Set<Id> ssmIdSet){
- Set<Id> validetedSsmIds = validateSSM(ssmIdSet);
- changeWOstatus(gatherConnectedWo(validetedSsmIds));
- for(Id ssmId : validetedSsmIds){
- markSSM(ssmId);
- }
- }
- public static Set<Id> validateSSM(Set<Id> ssmIdSet){
- Set<String> stageList = new Set<String>{ApplicationConstant.SSM_STAGE_CANCELLED, ApplicationConstant.SSM_STAGE_PENDING_CUST_ACCEPTANCE,
- ApplicationConstant.SSM_STAGE_REJECTED, ApplicationConstant.SSM_STAGE_LIVE};
- List<Sold_Service_Modification__c> validatedSsmList = [SELECT Id FROM Sold_Service_Modification__c WHERE Id IN :ssmIdSet AND Action__c = 'Add' AND Stage__c NOT IN :stageList];
- Set<Id> validatedSsmIdSet = (new Map<Id,Sold_Service_Modification__c>(validatedSsmList)).keySet();
- return validatedSsmIdSet;
- }
- public static List<WorkOrder> gatherConnectedWo(Set<Id> validatedSsmIdSet){
- List<WorkOrder> connectedWO = [SELECT Id, Status, WorkOrderNumber FROM WorkOrder WHERE Sold_Service_Modification__c IN : validatedSsmIdSet AND RecordType.DeveloperName != 'Automated_Work_Order'];
- return connectedWO;
- }
- public static void markSSM(Id ssmId){
- Sold_Service_Modification__c ssm = new Sold_Service_Modification__c(Id = ssmId);
- ssm.In_flight_Change_Requested__c = true;
- ssm.Stage__c = ApplicationConstant.SSM_STAGE_ON_HOLD;
- ssm.TECH_Allow_Stage_Change__c = !ssm.TECH_Allow_Stage_Change__c;
- ssm.TECH_SSM_Snapshot__c = JSON.serialize(ssm);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement