/**
* @name QuoteDocumentWrapper2
* @description Quote Document Wrapper class for Quote with all columns and school Summary grouped by School → Product Family → Segment
**/
public class QuoteDocumentWrapper2 {
private static String IMPLEMENTATION_PHASE = 'Implementation Phase';
private static Boolean IS_STUB_INDEX = false;
private static Set<String> quoteIncludesFamily = new Set<String>();
private static Set<Id> schoolIdSet = new Set<Id>();
public class QuoteOutput {
public String quoteProductFamily;
public Integer schoolCount;
public List<SchoolOutputWrapper> schools;
}
public class SchoolOutputWrapper {
public String name;
public Decimal subListAmount = 0.0;
public Decimal subTotalDiscount = 0.0;
public Decimal subTotalAmount = 0.0;
public List<ProductFamilyOutputWrapper> productFamilies;
public Boolean hasDiscount = false;
public Boolean isNegativeSubTotalAmount = false;
public SchoolOutputWrapper(
String Name,
Decimal SubListAmount,
Decimal SubTotalDiscount,
Decimal SubTotalAmount,
List<ProductFamilyOutputWrapper> productFamilies
) {
this.Name = Name;
this.SubListAmount = SubListAmount;
this.SubTotalAmount = SubTotalAmount;
this.SubTotalDiscount = SubTotalDiscount;
this.productFamilies = productFamilies;
this.isNegativeSubTotalAmount = SubTotalAmount < 0;
}
}
public class ProductFamilyOutputWrapper {
public String name;
public Decimal subTotalAmount = 0.0;
public Decimal subTotalDiscount = 0.0;
public Decimal quantity = 0;
public List<SegmentOutputWrapper> segments;
public Boolean hasDiscount = false;
public Boolean isNegativeSubTotalAmount = false;
public ProductFamilyOutputWrapper(
String name,
Decimal subTotalAmount,
Decimal subTotalDiscount,
Decimal quantity,
List<SegmentOutputWrapper> segments
) {
this.name = name;
this.subTotalAmount = subTotalAmount;
this.subTotalDiscount = subTotalDiscount;
this.quantity = quantity;
this.segments = segments;
this.hasDiscount = subTotalDiscount != 0;
this.isNegativeSubTotalAmount = subTotalAmount < 0;
}
}
public class SegmentOutputWrapper implements Comparable {
public String segmentIndex;
public Boolean additionalPhase;
public Decimal subTotalAmount = 0.0;
public Decimal subTotalDiscount = 0.0;
public Decimal quantity = 0;
public String effectiveEndDate;
public String effectiveStartDate;
public List<ProductOutput> products;
public Boolean hasDiscount = false;
public Boolean isNegativeSubTotalAmount = false;
public String cqlStartDate;
public String cqlEndDate;
public SegmentOutputWrapper(
String segmentIndex,
Decimal subTotalAmount,
Decimal subTotalDiscount,
Decimal quantity,
String effectiveEndDate,
String effectiveStartDate,
String cqlStartDate,
String cqlEndDate,
List<ProductOutput> products
) {
this.segmentIndex = IS_STUB_INDEX == true && segmentIndex.isNumeric()
? String.valueOf(Integer.valueOf(segmentIndex) + 1)
: segmentIndex;
this.additionalPhase = segmentIndex == IMPLEMENTATION_PHASE;
this.subTotalAmount = subTotalAmount;
this.subTotalDiscount = subTotalDiscount;
this.quantity = quantity;
this.effectiveEndDate = effectiveEndDate;
this.effectiveStartDate = effectiveStartDate;
this.products = products;
this.hasDiscount = subTotalDiscount != 0;
this.isNegativeSubTotalAmount = subTotalAmount < 0;
}
public Integer compareTo(Object obj) {
SegmentOutputWrapper that = (SegmentOutputWrapper) obj;
if (this.segmentIndex == IMPLEMENTATION_PHASE) {
return -1;
} else if (that.segmentIndex == IMPLEMENTATION_PHASE) {
return 1;
} else {
return Integer.valueOf(this.segmentIndex) -
Integer.valueOf(that.segmentIndex);
}
}
}
public class SchoolOutput {
public String Name;
public Decimal SubListAmount = 0.0;
public Decimal SubTotalDiscount = 0.0;
public Decimal SubTotalAmount = 0.0;
public Map<String, ProductFamilyOutput> productFamilies;
public Boolean hasDiscount = false;
public SchoolOutput(
String Name,
Decimal SubListAmount,
Decimal SubTotalDiscount,
Decimal SubTotalAmount,
Map<String, ProductFamilyOutput> productFamilies
) {
this.Name = Name;
this.SubListAmount = SubListAmount;
this.SubTotalAmount = SubTotalAmount;
this.SubTotalDiscount = SubTotalDiscount;
this.productFamilies = productFamilies;
}
}
public class ProductFamilyOutput {
public String name;
public Decimal subTotalAmount = 0.0;
public Decimal subTotalDiscount = 0.0;
public Decimal quantity = 0;
public Map<String, SegmentOutput> segments;
public Boolean hasDiscount = false;
public ProductFamilyOutput(
String name,
Decimal subTotalAmount,
Decimal subTotalDiscount,
Decimal quantity,
Map<String, SegmentOutput> segments
) {
this.name = name;
this.subTotalAmount = subTotalAmount;
this.subTotalDiscount = subTotalDiscount;
this.quantity = quantity;
this.segments = segments;
this.hasDiscount = subTotalDiscount != 0;
}
}
public class SegmentOutput {
public String segmentIndex;
public Boolean additionalPhase;
public Decimal subTotalAmount = 0.0;
public Decimal subTotalDiscount = 0.0;
public Decimal quantity = 0;
public String effectiveEndDate;
public String effectiveStartDate;
public String cqlStartDate;
public String cqlEndDate;
public List<ProductOutput> products;
public Boolean hasDiscount = false;
public SegmentOutput(
String segmentIndex,
Decimal subTotalAmount,
Decimal subTotalDiscount,
Decimal quantity,
String effectiveEndDate,
String effectiveStartDate,
String cqlStartDate,
String cqlEndDate,
List<ProductOutput> products
) {
this.segmentIndex = segmentIndex;
this.additionalPhase = segmentIndex == IMPLEMENTATION_PHASE;
this.subTotalAmount = subTotalAmount;
this.subTotalDiscount = subTotalDiscount;
this.quantity = quantity;
if (effectiveEndDate == null || effectiveEndDate == '') {
this.effectiveEndDate = effectiveEndDate;
} else {
DateTime dtEffectiveEndDate = Date.valueOf(effectiveEndDate);
this.effectiveEndDate = String.valueOf(
dtEffectiveEndDate.formatGmt('dd-MMM-yyyy')
);
}
this.effectiveStartDate = effectiveStartDate;
DateTime dtEffectiveStartDate = Date.valueOf(effectiveStartDate);
this.effectiveStartDate = String.valueOf(
dtEffectiveStartDate.formatGmt('dd-MMM-yyyy')
);
this.products = products;
this.hasDiscount = subTotalDiscount != 0;
this.cqlStartDate = cqlStartDate;
this.cqlEndDate = cqlStartDate;
}
}
public class ProductOutput {
public String name;
public Decimal listPrice;
public Decimal netPrice;
public Decimal discountAmount;
public Decimal netTotal;
public Decimal listTotal;
public Decimal quantity;
public Boolean hasDiscount = false;
public Boolean isNegativeNetTotal = false;
public Boolean isCreditProduct = false;
public String creditUsage = '';
public Boolean hidden;
public Decimal netUnitPrice;
public Decimal totalCost;
public ProductOutput(
String name,
Decimal listPrice,
Decimal netPrice,
Decimal discountAmount,
Decimal netTotal,
Decimal listTotal,
Decimal quantity
) {
this.name = name;
this.listPrice = listPrice;
this.netPrice = netPrice;
this.discountAmount = discountAmount;
this.netTotal = netTotal;
this.listTotal = listTotal;
this.quantity = quantity;
this.hasDiscount = discountAmount != 0;
this.isNegativeNetTotal = netTotal < 0;
}
}
public class Quote {
public String name;
public List<QuoteLine> quoteLines;
}
public class QuoteLine {
public Integer segmentIndex;
public Decimal quantity;
public Decimal netTotal;
public Decimal listPrice;
public Decimal additionalDiscountAmount;
public String effectiveEndDate;
public String effectiveStartDate;
public Integer effectiveSubscriptionTerm;
public Decimal effectiveQuantity;
public Decimal netPrice;
public Decimal listTotal;
public String creditUsage;
public List<ChildQuoteLine> childQuoteLines;
}
public class ChildQuoteLine {
public School school;
public Decimal effectiveQuantity;
public Id childQuoteLineId;
public Product product;
public Integer SegmentIndex;
public Boolean hidden;
public Decimal netUnitPrice;
public Decimal totalCost;
public String cqlEndDate;
public String cqlStartDate;
}
public class Product {
public String name;
public String family;
public String quoteIncludesFamily;
public String subscriptionPricing;
public String productCategory;
}
public class School {
public String name;
public String schoolId;
}
/**
* @description Method to create the document data to be displayed in the quote document
* @param Object arg
* @return QuoteOutput
**/
public QuoteOutput createDocumentData(Object arg) {
List<Quote> quotes = parseQuoteJson(JSON.serialize(arg));
Map<String, SchoolOutput> schoolOutputList = processQuotes(quotes);
List<SchoolOutputWrapper> schoolOutput = convertToNewFormat(
schoolOutputList
);
QuoteOutput outputWrapper = new QuoteOutput();
outputWrapper.quoteProductFamily = getQuoteIncludesFamily(
new List<String>(quoteIncludesFamily)
);
outputWrapper.schoolCount = schoolIdSet.size();
outputWrapper.schools = schoolOutput;
return outputWrapper;
}
/**
* @description Method to parse the JSON string to Input Wrapper classes
* @param String jsonString
* @return List<Quote>
**/
public static List<Quote> parseQuoteJson(String jsonString) {
List<Quote> result = new List<Quote>();
List<Object> parsed = (List<Object>) JSON.deserializeUntyped(jsonString);
for (Object obj : parsed) {
Map<String, Object> quoteRecord = (Map<String, Object>) obj;
Quote quote = new Quote();
quote.name = (String) quoteRecord.get('Name');
IMPLEMENTATION_PHASE = (String) quoteRecord.get(
'OverrideImplementationPhaseText'
) == null
? IMPLEMENTATION_PHASE
: (String) quoteRecord.get('OverrideImplementationPhaseText');
IS_STUB_INDEX = (Boolean) quoteRecord.get('OverrideNonstubIndex');
Boolean displayUnchangedProducts = (Boolean) quoteRecord.get(
'Display_Unchanged_Products__c'
);
// Deserialize quote lines
List<Object> quoteLines = new List<Object>();
if (quoteRecord.get('QuoteLines') instanceof Map<String, Object>) {
quoteLines.add(quoteRecord.get('QuoteLines'));
} else {
quoteLines = (List<Object>) quoteRecord.get('QuoteLines');
}
List<QuoteLine> quoteLineList = new List<QuoteLine>();
for (Object quoteLineRecord : quoteLines) {
Map<String, Object> qlwMap = (Map<String, Object>) quoteLineRecord;
if ((Decimal) qlwMap.get('EffectiveQuantity') == 0) {
continue;
}
QuoteLine quoteLine = new QuoteLine();
quoteLine.segmentIndex = (Integer) qlwMap.get('SegmentIndex');
quoteLine.quantity = (Decimal) qlwMap.get('Quantity');
quoteLine.netTotal = (Decimal) qlwMap.get('NetTotal');
quoteLine.listPrice = (Decimal) qlwMap.get('ListPrice');
quoteLine.netPrice = (Decimal) qlwMap.get('NetPrice');
quoteLine.listTotal = (Decimal) qlwMap.get('ListTotal');
quoteLine.effectiveEndDate = (String) qlwMap.get('EffectiveEndDate');
quoteLine.effectiveStartDate = (String) qlwMap.get(
'EffectiveStartDate'
);
quoteLine.effectiveSubscriptionTerm = (Integer) qlwMap.get(
'EffectiveSubscriptionTerm'
);
quoteLine.effectiveQuantity = (Decimal) qlwMap.get('EffectiveQuantity');
quoteLine.additionalDiscountAmount = (Decimal) qlwMap.get(
'AdditionalDiscountAmount'
);
quoteLine.creditUsage = (String) qlwMap.get('CreditUsage');
// Deserialize child quote lines
List<Object> childQuoteLines = new List<Object>();
if (qlwMap.get('ChildQuoteLines') instanceof Map<String, Object>) {
childQuoteLines.add(qlwMap.get('ChildQuoteLines'));
} else {
childQuoteLines = (List<Object>) qlwMap.get('ChildQuoteLines');
}
List<ChildQuoteLine> childQuoteLineList = new List<ChildQuoteLine>();
String segmentStartDate = null; // Temporary storage
String segmentEndDate = null; // Temporary storage
if (childQuoteLines != null) {
for (Object childQuoteLineWrapperRecord : childQuoteLines) {
Map<String, Object> childQuoteLineWrapperRecordMap = (Map<String, Object>) childQuoteLineWrapperRecord;
Boolean hidden = (Boolean) childQuoteLineWrapperRecordMap.get(
'Hidden'
);
if (hidden != null && hidden == true) {
continue; // Skip this child quote line if Hidden is true
}
if (
displayUnchangedProducts == false &&
(Decimal) childQuoteLineWrapperRecordMap.get(
'EffectiveQuantity'
) == 0
) {
continue;
}
ChildQuoteLine childQuoteLine = new ChildQuoteLine();
childQuoteLine.effectiveQuantity = (Decimal) childQuoteLineWrapperRecordMap.get(
'EffectiveQuantity'
);
childQuoteLine.netUnitPrice = (Decimal) childQuoteLineWrapperRecordMap.get(
'NetUnitPrice'
);
childQuoteLine.totalCost = (Decimal) childQuoteLineWrapperRecordMap.get(
'TotalCost'
);
childQuoteLine.hidden = hidden;
childQuoteLine.childQuoteLineId = (Id) childQuoteLineWrapperRecordMap.get(
'ChildQuoteLineId'
);
childQuoteLine.segmentIndex = (Integer) childQuoteLineWrapperRecordMap.get(
'SegmentIndex'
);
childQuoteLine.cqlStartDate = (String) childQuoteLineWrapperRecordMap.get(
'CQL_Start_Date__c'
);
childQuoteLine.cqlEndDate = (String) childQuoteLineWrapperRecordMap.get(
'CQL_End_Date__c'
);
// Safely deserialize nested School
Object schoolObj = childQuoteLineWrapperRecordMap.get('School');
if (schoolObj != null) {
childQuoteLine.school = (School) JSON.deserialize(
JSON.serialize(schoolObj),
School.class
);
}
// Safely deserialize nested Product
Object productObj = childQuoteLineWrapperRecordMap.get('Product');
if (productObj != null) {
childQuoteLine.product = (Product) JSON.deserialize(
JSON.serialize(productObj),
Product.class
);
}
if (
childQuoteLine.product != null &&
childQuoteLine.product.productCategory == 'Subscription (Credits)'
) {
childQuoteLine.effectiveQuantity = (Decimal) childQuoteLineWrapperRecordMap.get(
'StudentsCreditsCover'
);
quoteLine.effectiveQuantity = (Decimal) qlwMap.get(
'StudentsCreditsCover'
);
}
childQuoteLineList.add(childQuoteLine);
}
}
quoteLine.childQuoteLines = childQuoteLineList;
quoteLineList.add(quoteLine);
}
quote.quoteLines = quoteLineList;
result.add(quote);
}
return result;
}
/**
* @description Method to get the Quote Includes Family
* @param List<String> families
* @return String
**/
public static String getQuoteIncludesFamily(
List<String> quoteIncludesFamily
) {
String quoteProductFamily = '';
if (quoteIncludesFamily.size() > 1) {
for (Integer i = 0; i < quoteIncludesFamily.size(); i++) {
if (i == quoteIncludesFamily.size() - 1) {
quoteProductFamily += ' and ' + quoteIncludesFamily[i];
} else if (i == 0) {
quoteProductFamily += quoteIncludesFamily[i];
} else {
quoteProductFamily += ', ' + quoteIncludesFamily[i];
}
}
} else if (quoteIncludesFamily == null || quoteIncludesFamily.size() == 0) {
return '';
} else {
quoteProductFamily = quoteIncludesFamily[0];
}
return quoteProductFamily;
}
/**
* @description Method to process the quotes and create a map of SchoolOutputWrapper
* @param List<Quote> quotes
* @return Map<String, SchoolOutputWrapper>
**/
public static Map<String, SchoolOutput> processQuotes(List<Quote> quotes) {
Map<String, SchoolOutput> schoolOutputList = new Map<String, SchoolOutput>();
for (Quote quote : quotes) {
for (QuoteLine quoteLine : quote.quoteLines) {
if (quoteLine.childQuoteLines.size() > 0) {
for (ChildQuoteLine childQuoteLine : quoteLine.childQuoteLines) {
processChildQuoteLine(childQuoteLine, quoteLine, schoolOutputList);
schoolIdSet.add(childQuoteLine.school.schoolId);
}
}
}
}
return schoolOutputList;
}
/**
* @description Method to process a quote line and populate the product family output map
* @param QuoteLineInputWrapper quoteLineWrapper
* @param Map<String, ProductFamilyOutputWrapper> productFamilyOutputWrapperMap
**/
public static void processChildQuoteLine(
ChildQuoteLine childQuoteLineWrapper,
QuoteLine quoteLineWrapper,
Map<String, SchoolOutput> schoolOutputList
) {
SchoolOutput schoolOutputWrapper = getSchoolOutput(
childQuoteLineWrapper,
schoolOutputList
);
ProductFamilyOutput productFamilyOutputWrapper = getProductFamilyOutput(
schoolOutputWrapper,
childQuoteLineWrapper
);
String segmentIndex = getSegmentIndex(
quoteLineWrapper.effectiveSubscriptionTerm,
childQuoteLineWrapper.segmentIndex == null
? 1
: childQuoteLineWrapper.segmentIndex
);
SegmentOutput segmentOutputWrapper = getSegmentOutput(
segmentIndex,
productFamilyOutputWrapper,
quoteLineWrapper
);
ProductOutput productOutputWrapper = createProductOutputWrapper(
childQuoteLineWrapper,
quoteLineWrapper
);
addProductToSegment(segmentOutputWrapper, productOutputWrapper);
updateTotals(
schoolOutputWrapper,
segmentOutputWrapper,
productOutputWrapper,
productFamilyOutputWrapper
);
if (
childQuoteLineWrapper.product.quoteIncludesFamily != null &&
childQuoteLineWrapper.product.quoteIncludesFamily != ''
)
quoteIncludesFamily.add(
String.valueOf(childQuoteLineWrapper.product.quoteIncludesFamily)
);
}
/**
* @description Retrieves or creates a SchoolOutputWrapper for a given school id
* @param ChildQuoteLine childQuoteLineWrapper
* @param Map<String, SchoolOutputWrapper> schoolOutputList
* @return SchoolOutputWrapper
**/
private static SchoolOutput getSchoolOutput(
ChildQuoteLine childQuoteLineWrapper,
Map<String, SchoolOutput> schoolOutputList
) {
SchoolOutput schoolOutputWrapper = schoolOutputList.get(
childQuoteLineWrapper.school.schoolId
);
if (schoolOutputWrapper == null) {
schoolOutputWrapper = new SchoolOutput(
childQuoteLineWrapper.school.name,
0.0,
0.0,
0.0,
new Map<String, ProductFamilyOutput>()
);
schoolOutputList.put(
childQuoteLineWrapper.school.schoolId,
schoolOutputWrapper
);
}
return schoolOutputWrapper;
}
/**
* @description Retrieves or creates a ProductFamilyOutputWrapper for a given product family
* @param SegmentOutputWrapper segmentOutputWrapper
* @param ChildQuoteLine childQuoteLineWrapper
* @return ProductFamilyOutputWrapper
**/
private static ProductFamilyOutput getProductFamilyOutput(
SchoolOutput schoolOutputWrapper,
ChildQuoteLine childQuoteLineWrapper
) {
ProductFamilyOutput productFamilyOutputWrapper = schoolOutputWrapper.productFamilies.get(
childQuoteLineWrapper.product.family
);
if (productFamilyOutputWrapper == null) {
productFamilyOutputWrapper = new ProductFamilyOutput(
childQuoteLineWrapper.product.family,
0.0,
0.0,
0.0,
new Map<String, SegmentOutput>()
);
schoolOutputWrapper.productFamilies.put(
childQuoteLineWrapper.product.family,
productFamilyOutputWrapper
);
}
return productFamilyOutputWrapper;
}
/**
* @description Retrieves or creates a SegmentOutputWrapper for a given segment index
* @param String segmentIndex
* @param ProductFamilyOutputWrapper productFamilyOutputWrapper
* @param QuoteLineInputWrapper quoteLineWrapper
* @return SegmentOutputWrapper
**/
private static SegmentOutput getSegmentOutput(
String segmentIndex,
ProductFamilyOutput productFamilyOutputWrapper,
QuoteLine quoteLineWrapper
) {
SegmentOutput segmentOutputWrapper = productFamilyOutputWrapper.segments.get(
segmentIndex
);
if (segmentOutputWrapper == null) {
segmentOutputWrapper = new SegmentOutput(
segmentIndex,
0.0,
0.0,
0.0,
quoteLineWrapper.effectiveEndDate,
quoteLineWrapper.effectiveStartDate,
cqlStartDate,
cqlEndDate,
new List<ProductOutput>()
);
productFamilyOutputWrapper.segments.put(
segmentIndex,
segmentOutputWrapper
);
} else if (
(segmentOutputWrapper.effectiveEndDate == null ||
segmentOutputWrapper.effectiveEndDate == '') &&
(quoteLineWrapper.effectiveEndDate != null &&
quoteLineWrapper.effectiveEndDate != '')
) {
DateTime dtEffectiveEndDate = Date.valueOf(
quoteLineWrapper.effectiveEndDate
);
segmentOutputWrapper.effectiveEndDate = String.valueOf(
dtEffectiveEndDate.formatGmt('dd-MMM-yyyy')
);
}
return segmentOutputWrapper;
}
/**
* @description Determines the segment index based on the subscription term
* @param Integer effectiveSubscriptionTerm
* @param Integer segmentIndex
* @return String
**/
private static String getSegmentIndex(
Integer effectiveSubscriptionTerm,
Integer segmentIndex
) {
return effectiveSubscriptionTerm < 12
? IMPLEMENTATION_PHASE
: String.valueOf(segmentIndex);
}
/**
* @description Adds a product to a product family
* @param ProductFamilyOutputWrapper productFamilyOutputWrapper
* @param ProductOutputWrapper productOutputWrapper
* @return void
**/
private static void addProductToSegment(
SegmentOutput segmentOutputWrapper,
ProductOutput productOutputWrapper
) {
// segmentOutputWrapper.subTotalAmount += productOutputWrapper.netTotal;
// segmentOutputWrapper.subTotalDiscount += productOutputWrapper.discountAmount;
segmentOutputWrapper.quantity += productOutputWrapper.quantity;
segmentOutputWrapper.products.add(productOutputWrapper);
}
/**
* @description Creates a ProductOutputWrapper from a QuoteLineInputWrapper
* @param QuoteLineInput quoteLineWrapper
* @return ProductOutputWrapper
**/
private static ProductOutput createProductOutputWrapper(
ChildQuoteLine childQuoteLineWrapper,
QuoteLine quoteLineWrapper
) {
ProductOutput productOutputWrapper = new ProductOutput(
childQuoteLineWrapper.product.name,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
);
productOutputWrapper.name = childQuoteLineWrapper.product.name;
if (
childQuoteLineWrapper.effectiveQuantity == 0 ||
quoteLineWrapper.effectiveQuantity == 0
) {
ProductOutputWrapper.quantity = quoteLineWrapper.Quantity;
ProductOutputWrapper.discountAmount = quoteLineWrapper.AdditionalDiscountAmount;
ProductOutputWrapper.netTotal = 0;
} else {
ProductOutputWrapper.Quantity = childQuoteLineWrapper.EffectiveQuantity;
ProductOutputWrapper.DiscountAmount =
(quoteLineWrapper.AdditionalDiscountAmount /
quoteLineWrapper.effectiveQuantity) *
childQuoteLineWrapper.EffectiveQuantity;
ProductOutputWrapper.netTotal =
(quoteLineWrapper.NetTotal / quoteLineWrapper.effectiveQuantity) *
childQuoteLineWrapper.EffectiveQuantity;
ProductOutputWrapper.listTotal =
(quoteLineWrapper.ListTotal / quoteLineWrapper.effectiveQuantity) *
childQuoteLineWrapper.EffectiveQuantity;
}
productOutputWrapper.listPrice = quoteLineWrapper.listPrice;
productOutputWrapper.netPrice = quoteLineWrapper.netPrice;
productOutputWrapper.quantity = childQuoteLineWrapper.effectiveQuantity;
productOutputWrapper.isNegativeNetTotal = productOutputWrapper.netTotal < 0;
productOutputWrapper.isCreditProduct =
quoteLineWrapper.childQuoteLines[0].product.productCategory ==
'Subscription (Credits)';
productOutputWrapper.creditUsage = quoteLineWrapper.creditUsage;
productOutputWrapper.hidden = childQuoteLineWrapper.hidden;
productOutputWrapper.netUnitPrice = childQuoteLineWrapper.netUnitPrice;
productOutputWrapper.totalCost = childQuoteLineWrapper.totalCost;
return productOutputWrapper;
}
/**
* @description Method to update totals for the segment
* @param SegmentOutputWrapper segmentWrapper
* @param ProductOutputWrapper productOutputWrapper
**/
public static void updateTotals(
SchoolOutput schoolOutputWrapper,
SegmentOutput segmentWrapper,
ProductOutput productOutputWrapper,
ProductFamilyOutput productFamilyOutputWrapper
) {
productFamilyOutputWrapper.subTotalAmount += productOutputWrapper.netTotal;
productFamilyOutputWrapper.subTotalDiscount += productOutputWrapper.discountAmount;
productFamilyOutputWrapper.hasDiscount =
productFamilyOutputWrapper.subTotalDiscount != 0;
segmentWrapper.subTotalAmount += productOutputWrapper.netTotal;
segmentWrapper.subTotalDiscount += productOutputWrapper.discountAmount;
schoolOutputWrapper.subTotalAmount += productOutputWrapper.netTotal;
schoolOutputWrapper.subTotalDiscount += productOutputWrapper.discountAmount;
}
/**
* @description Method to convert the processed data into the new format of SchoolOutputWrapper
* @param Map<String, SchoolOutput> schoolOutputMap
* @return List<SchoolOutputWrapper>
**/
public static List<SchoolOutputWrapper> convertToNewFormat(
Map<String, SchoolOutput> schoolOutputMap
) {
List<SchoolOutputWrapper> schoolOutputList = new List<SchoolOutputWrapper>();
for (SchoolOutput schoolOutput : schoolOutputMap.values()) {
List<ProductFamilyOutputWrapper> productFamilies = new List<ProductFamilyOutputWrapper>();
for (
ProductFamilyOutput productFamilyOutput : schoolOutput.productFamilies.values()
) {
List<SegmentOutputWrapper> segments = new List<SegmentOutputWrapper>();
for (
SegmentOutput segmentOutput : productFamilyOutput.segments.values()
) {
List<ProductOutput> products = segmentOutput.products;
segments.add(
new SegmentOutputWrapper(
segmentOutput.segmentIndex,
segmentOutput.subTotalAmount,
segmentOutput.subTotalDiscount,
segmentOutput.quantity,
segmentOutput.effectiveEndDate,
segmentOutput.effectiveStartDate,
segmentOutput.cqlStartDate,
segmentOutput.cqlEndDate,
products
)
);
}
segments.sort();
productFamilies.add(
new ProductFamilyOutputWrapper(
productFamilyOutput.name,
productFamilyOutput.subTotalAmount,
productFamilyOutput.subTotalDiscount,
productFamilyOutput.quantity,
segments
)
);
}
schoolOutputList.add(
new SchoolOutputWrapper(
schoolOutput.Name,
schoolOutput.SubListAmount,
schoolOutput.SubTotalDiscount,
schoolOutput.SubTotalAmount,
productFamilies
)
);
}
return schoolOutputList;
}
}