PrescriptiveResolutionTool.cmp
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable" access="global" controller="nfm_PrescriptiveToolPricingCtrl">
<aura:attribute name="orderNumber" type="String" default="0"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="orderPrescPriceLineItemList" type="List" Description="nfm_PrescriptiveToolPricingCtrl.PrescriptivePriceLineItemWrapperClass"/>
<lightning:workspaceAPI aura:id="workspace"/>
<aura:attribute name="isLoading" type="Boolean" default="true"/>
<aura:if isTrue="{!v.isLoading}">
<lightning:spinner alternativeText="Loading" size="medium" variant="brand"/>
</aura:if>
<aura:if isTrue="{!v.orderPrescPriceLineItemList.length > 0}">
<article class="slds-card">
<div class="slds-card__header slds-grid">
<!-- code to display card header -->
<header class="slds-media slds-media_center slds-has-flexi-truncate">
<div class="slds-media__figure">
<span class="slds-icon_container">
<lightning:icon style="background-color: rgba(32,178,170,1);" iconName="custom:custom29" size="small"/>
</span>
</div>
<div class="slds-media__body">
<h2 class="slds-card__header-title">
<a href="javascript:void(0);" class="slds-card__header-link slds-truncate" title="Prescriptive Order Line Items">
<span>
Prescriptive Resolution Items
</span>
</a>
</h2>
</div>
</header>
</div>
<div class="slds-card__body slds-card__body_inner">
<table class="slds-table slds-table--bordered slds-table--fixed-layout" style="padding-top:0.1rem" role="grid" id="summaryTable">
<!-- CODE TO DISPLAY THE TABLE HEADER STARTS HERE -->
<thead class="slds-table_bordered">
<tr class="slds-text-title--caps">
<th scope="col">
<p class="slds-truncate" title="Order Line Items">Order Line Items </p>
</th>
<th scope="col">
<p class="slds-truncate" title="Product Description">Product Description</p>
</th>
<th scope="col">
<p class="slds-truncate" title="Sales Price">Sales Price Per Item</p>
</th>
<th scope="col">
<p class="slds-truncate" title="Order Status">Order Status</p>
</th>
<th scope="col">
<p class="slds-truncate" title="C/A Amount">C/A Amount Per Item</p>
</th>
<th scope="col">
<p class="slds-truncate" title="CDL Amount">CDL Amount Per Item</p>
</th>
<th scope="col">
<p class="slds-truncate" title="Maximum Resolution Amount">Maximum Resolution Amount Per Item</p>
</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.orderPrescPriceLineItemList}" var="record">
<tr>
<td class="slds-cell-wrap">
{!record.OrderLineItems }
</td>
<td class="slds-cell-wrap">
{!record.ProductDescription}
</td>
<td class="slds-cell-wrap">
{!record.SalesPrice}
</td>
<td class="slds-cell-wrap">
{!record.OrderStatus}
</td>
<td class="slds-cell-wrap">
{!record.CAAmount}
</td>
<td class="slds-cell-wrap">
{!record.CDLAmount}
</td>
<td class="slds-cell-wrap">
{!record.MaximumResolutionAmount}
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</article>
<aura:set attribute="else">
<div align="center">
<hr></hr>
No Records Found
</div>
</aura:set>
</aura:if>
</aura:component>
nfm_PrescriptiveResolutionToolHelper.js
({
getPrescriptivePriceLineItemsInfo : function(component, event, helper) {
var orderNumber = component.get("v.orderNumber");
console.log('OrderId to Apex call' + orderNumber);
var action = component.get('c.getOrderPrescriptivePriceLineItems');
action.setParams({
orderId: component.get("v.orderNumber")
});
action.setCallback(this, function(response) {
component.set('v.isLoading',false);
var state = response.getState();
var dataRetrieved = response.getReturnValue();
if (state === "SUCCESS") {
console.log(JSON.parse(JSON.stringify(dataRetrieved)));
//console.log('Response of Prescriptive Resolution for an OrderNumber--' + dataRetrieved);
component.set('v.orderPrescPriceLineItemList', dataRetrieved);
}else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
$A.enqueueAction(action);
}
})
nfm_PrescriptiveResolutionToolController.js
({
doInit : function(component, event, helper) {
var orderId = component.get("v.orderNumber");
var myPageRef = component.get("v.pageReference");
if(myPageRef!=null){
orderId = myPageRef && myPageRef.state ? myPageRef.state.c__orderNumber : component.get('v.recordId');
console.log(JSON.parse(JSON.stringify(myPageRef.state)));
console.log(orderId);
}else{
orderId = component.get('v.recordId');
}
if(orderId!=undefined && orderId!=null){
component.set('v.orderNumber',orderId);
window.setTimeout(
$A.getCallback(function() {
helper.getPrescriptivePriceLineItemsInfo(component, event, helper);
}),3000
);
}
}
})
public class nfm_PrescriptiveToolPricingCtrl {
@AuraEnabled
public static List<PrescriptivePriceLineItemWrapperClass> getOrderPrescriptivePriceLineItems(String orderId) {
System.debug('OrderNumber Apex:' + orderId);
List<ResolutionItems__x> resolutionItemList = nfm_ExternalResolutionItemRequest.getByOrderNumber(orderId);
List<PrescriptivePriceLineItemWrapperClass> lineItemWrapperList = new List<PrescriptivePriceLineItemWrapperClass>();
For(ResolutionItems__x objOrderLineItems : resolutionItemList){
lineItemWrapperList.add(createLineItemWrapperObject(objOrderLineItems));
}
UserActivityController.createRecord('Prescriptive Tool', 'Order', orderId);
return lineItemWrapperList;
}
private static PrescriptivePriceLineItemWrapperClass createLineItemWrapperObject(ResolutionItems__x objOrderLineItems){
PrescriptivePriceLineItemWrapperClass objOrderLineItemWrapper = new PrescriptivePriceLineItemWrapperClass();
objOrderLineItemWrapper.OrderLineItems = objOrderLineItems.OrderLineItemNumber__c;
objOrderLineItemWrapper.ProductDescription = objOrderLineItems.ProductDescription__c;
objOrderLineItemWrapper.SalesPrice = '$' + string.ValueOf(objOrderLineItems.SalesPrice__c);
objOrderLineItemWrapper.OrderStatus = objOrderLineItems.OrderStatus__c;
objOrderLineItemWrapper.CAAmount = '$' + string.ValueOf(objOrderLineItems.CreditAdjustmentAmount__c);
objOrderLineItemWrapper.CDLAmount = '$' + string.ValueOf(objOrderLineItems.CDLAmount__c);
objOrderLineItemWrapper.MaximumResolutionAmount = '$' + string.ValueOf(objOrderLineItems.MaximumResolutionAmount__c);
return objOrderLineItemWrapper;
}
public class PrescriptivePriceLineItemWrapperClass{
@AuraEnabled public String OrderLineItems{get;set;}
@AuraEnabled public String ProductDescription{get;set;}
@AuraEnabled public String SalesPrice {get;set;}
@AuraEnabled public String OrderStatus {get;set;}
@AuraEnabled public String CAAmount {get;set;}
@AuraEnabled public String CDLAmount {get;set;}
@AuraEnabled public String MaximumResolutionAmount {get;set;}
}
}
