Global class U4_Legacy_INC_MilestoneTimeCalculator implements Support.MilestoneTriggerTimeCalculator {
//** Constructor for this class.
global Integer calculateMilestoneTriggerTime(String caseId, String milestoneTypeId)
{
Integer MilestoneValue;
Product_Milestone_Times__c ProductMilestoneSet;
Milestone_Times__c EntitlementMilestoneSet;
//** Select values from case
Case caseRec = [SELECT Id, EntitlementId, ProductId, Priority, Contractual_Type__c FROM Case WHERE Id=:caseId LIMIT 1];
MilestoneType mtype = [SELECT Name FROM MilestoneType WHERE Id=:milestoneTypeId];
// Retrieve Milestone definition from Entitlement
EntitlementMilestoneSet = [SELECT Response_Time__c, Resolution_Time__c, Software_Resolution_Time__c FROM Milestone_Times__c WHERE Entitlement__c =: caseRec.EntitlementId AND Priority__c =: caseRec.Priority];
// Retrieve Internal Milestone definition from Product
ProductMilestoneSet = [SELECT Response_Time__c, Resolution_Time__c, Software_Resolution_Time__c FROM Product_Milestone_Times__c WHERE Product__c =: caseRec.ProductId AND Priority__c =: caseRec.Priority];
if(mtype.Name == SEConstants.FIRSTRESPONSETIME){
if(caseRec.Contractual_Type__c == SEConstants.INTERNAL_ONLY)
{
// Take First Response time from Product
MilestoneValue = ProductMilestoneSet.Response_Time__c.intValue();
}
else
{
// Take First Response time from Entitlement
MilestoneValue = EntitlementMilestoneSet.Response_Time__c.intValue();
}
} // Response Time
if(mtype.Name == SEConstants.RESOLUTIONTIME){
if(caseRec.Contractual_Type__c == SEConstants.INTERNAL_ONLY || caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_ONLY)
{
// Take Resolution time from Product
MilestoneValue = ProductMilestoneSet.Resolution_Time__c.intValue();
}
else
{
// Take Resolution time from Entitlement
MilestoneValue = EntitlementMilestoneSet.Resolution_Time__c.intValue();
}
} // Resolution Time
if(mtype.Name == SEConstants.SOFTWARERESOLUTIONTIME){
If(caseRec.Contractual_Type__c == SEConstants.INTERNAL_ONLY || caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_ONLY || caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_RESOLUTION_ONLY || (caseRec.Contractual_Type__c == SEConstants.FIRST_RESPONSE_RESOLUTION_P1_P2_SOFTWARE && (caseRec.Priority == SEConstants.PRIORITY_3 || caseRec.Priority == SEConstants.PRIORITY_4)))
{
// Take Software Resolution time from Product
MilestoneValue = ProductMilestoneSet.Software_Resolution_Time__c.intValue();
}
Else
{
// Take Software Resolution time from Entitlement
MilestoneValue = EntitlementMilestoneSet.Software_Resolution_Time__c.intValue();
}
} // Software Resolution Time
Return MilestoneValue;
}
}