Aura component Example
<aura:component controller="FOCDraftEmailController" implements="force:lightningQuickActionWithoutHeader,flexipage:availableForAllPageTypes,force:hasRecordId">
<aura:attribute name="focWithFocLineItem" type="FOC__c" default=""/>
<aura:attribute name="opportunityRecords" type="List" default=""/>
<aura:attribute name="hideAndShow" type="Boolean" default="false"/>
<aura:attribute name="fullHide" type="Boolean" default="true"/>
<aura:attribute name="key" type="String" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="userInfo" type="user"/>
<aura:html tag="style">
.sticky{
position: absolute;
bottom: 30px;
padding: 10px;
}
/*.stickyHeader{
position: absolute;
top: 4px;
padding: 10px;
}*/
.cuf-content {
padding: 0 0rem !important;
}
.slds-p-around--medium {
padding: 0rem !important;
}
.slds-modal__content{
overflow-y:hidden !important;
height:unset !important;
max-height:unset !important;
}
</aura:html>
<aura:if isTrue="{!v.fullHide}">
<aura:if isTrue="{!v.hideAndShow}">
<div class="modal-header slds-modal__header slds-size_1-of-1">
<h4 class="title slds-text-heading--medium" style="font-family:sans-serif;">FOC Email Template</h4>
</div>
<div class="slds-form">
<div style="margin:20px;">
<div class="slds-form-element__control slds-m-top_small">
<abbr class="slds-required" title="required">*</abbr>To
<lightning:input aura:id="inputValue" placeholder="Please Enter To Email Id" variant="label-hidden" class="slds-button" type="Text"/>
</div>
<div class="slds-form-element__control slds-m-top_small">
<label class="slds-form-element__label" for="inputValue">CC</label>
<lightning:input aura:id="inputValue2" placeholder="Please Enter CC Email Id" variant="label-hidden" class="slds-button" type="Text"/>
</div>
</div>
<div class="modal-footer slds-modal__footer slds-size_1-of-1">
<div class="forceChangeRecordTypeFooter">
<lightning:button class="slds-button slds-button_neutral" label="Back" onclick="{!c.backModal}"/>
<lightning:button class="slds-button slds-button--brand" label="Send Email" onclick="{!c.searchKeyChange}"/>
</div>
</div>
</div>
<aura:set attribute="else">
<div class="modal-header slds-modal__header slds-size_1-of-1 stickyHeader">
<h4 class="title slds-text-heading--medium" style="font-family: sans-serif;">FOC Email Template</h4>
</div>
<div style="margin:20px;">
<!--<html><head><title>Page Title</title></head><body>-->
<form>
<div class="row">
<p style="padding-left:10px;">FOC Sales Order | {!v.focWithFocLineItem.Customer_Name__c} {!v.focWithFocLineItem.Ship_To_Address1__c}</p><br/>
<ol class="slds-list_dotted" type="disc">
<li>Dear Sir<ul type="disc">
<p style="padding-left:30px;">It is required to send certain parts on FOC basis against the referred Sales Order.</p><br/>
<div style="padding-left:30px; padding-bottom:0px;">You are requested to please arrange to transfer below listed material to Store Loc. {!v.focWithFocLineItem.FOC_Store_Loc__c} ({!v.focWithFocLineItem.Location_Name__c}) issue
and hand over to Packing Dept. However, if parts are not available in store, kindly inform the shortage to concerned person/ department for
necessary action.
</div>
</ul>
</li><br/>
<li>Dear Packing Team
<ul type="disc">
<p style="padding-left:30px;">Please arrange to get the material packed once issued from Store
enabling us to perform further formalities.
</p>
</ul>
</li><br/>
<li>List of parts under referred Sales Order is given under.
<ul type="disc"></ul>
</li>
</ol>
<br/>
<div style="padding-left:54px">
<table border="1" style="min-width: 100%; border-collapse: collapse;">
<tr>
<th colspan="4" style="background-color:#E4F2CB"> FREE OF COST SALES ORDER FOR</th>
</tr>
<tr>
<td style="background-color:#EAE4EA"> Customer</td>
<td rowspan="1" colspan="3" style="padding-left:15px;">{!v.focWithFocLineItem.Customer_Name__c} {!v.focWithFocLineItem.Ship_To_Address1__c}</td>
</tr>
<tr>
<td style="background-color:#EAE4EA"> SAP Sales Order</td>
<td style="padding-left:15px;">{!v.focWithFocLineItem.SAP_FOC_Sales_Order_No__c}</td>
<td style="background-color:#EAE4EA"> CRM FOC No.</td>
<td style="padding-left:15px;">{!v.focWithFocLineItem.Name}</td>
</tr>
<tr>
<td style="background-color:#EAE4EA; width:30%"> SAP Service Notification</td>
<td style="padding-left:15px;">{!v.focWithFocLineItem.SAP_Service_Notification_No__c}</td>
<td style="background-color:#EAE4EA"> CRM Work Order</td>
<td style="padding-left:15px;">{!v.focWithFocLineItem.Work_Order__r.WorkOrderNumber}</td>
</tr>
<tr>
<td style="background-color:#EAE4EA"> Machine Model</td>
<td style="padding-left:15px;">{!v.focWithFocLineItem.Model__c}</td>
<td style="background-color:#EAE4EA"> CRM Case No.</td>
<td style="padding-left:15px;">{!v.focWithFocLineItem.Case_No__c}</td>
</tr>
<tr>
<td style="background-color:#EAE4EA"> Machine No(s). </td>
<td rowspan="1" colspan="3" style="padding-left:15px;">{!v.focWithFocLineItem.Machine_No__c}</td>
</tr>
</table>
<table border="1" style="min-width: 100%; border-collapse: collapse;">
<tr>
<th style="background-color:#EAE4EA"> Sr No.</th>
<th style="background-color:#EAE4EA"> Item Code</th>
<th style="background-color:#EAE4EA"> Item Description</th>
<th style="background-color:#EAE4EA"> Qty</th>
<th style="background-color:#EAE4EA"> Unit</th>
<th style="background-color:#EAE4EA">FOC Reason</th>
</tr>
<aura:iteration items="{!v.focWithFocLineItem.FOC_Order_Line_Items__r}" var="focObj" indexVar="i">
<tr>
<td style="text-align:center;">{!i+1}.</td>
<td style="text-align:center;">{!focObj.Product_Code__c}</td>
<td style="text-align:center;">{!focObj.Description__c}</td>
<td style="text-align:center;">{!focObj.Quantity__c}</td>
<td style="text-align:center;">{!focObj.Unit__c}</td>
<td style="text-align:center;">{!focObj.FOC_Reason__c}</td>
</tr>
</aura:iteration>
</table>
<table border="1" style="min-width: 100%; border-collapse: collapse;">
<tr>
<td> Remarks if any: </td>
<td rowspan="1" colspan="5" style="padding-left:15px;">{!v.focWithFocLineItem.Remark__c }</td>
</tr>
<tr>
<td rowspan="1" colspan="6" style="background-color:#F9EBB5;">
<b><center> PACKING DETAIL (To be filled by Packing Department)</center></b>
</td>
</tr>
</table>
<table border="1" style="min-width: 100%; border-collapse: collapse;">
<tr>
<td style="width:30%;"> CASE NO.</td>
<td style="width:20%; text-align:center;"></td>
<td style="width:30%"> NET WEIGHT (KGS)</td>
<td style="width:20%; text-align:center;"></td>
</tr>
<tr>
<td> PACKING DATE</td>
<td style="text-align:center;"></td>
<td> GROSS WEIGHT (KGS)</td>
<td style="text-align:center;"></td>
</tr>
<tr>
<td> PACKING BOX (W/C*) </td>
<td style="text-align:center;"></td>
<td> CASE SIZE (CMxCMxCM)</td>
<td style="text-align:center;"></td>
</tr>
</table>
<p><br/>Regards,<br/>{!v.userInfo.Name} <br/><br/>Copy to: <br/>MDM IT - Please run the MRP against above referred Sales Order.</p>
</div>
</div>
</form>
</div>
<div class="sticky modal-footer slds-modal__footer slds-size_1-of-1">
<div class="forceChangeRecordTypeFooter">
<lightning:button class="slds-button slds-button_neutral" label="Cancel" onclick="{!c.cancelModal}"/>
<lightning:button class="slds-button slds-button--brand" label="Next" onclick="{!c.handleInputValueChange}"/>
</div>
</div>
</aura:set>
</aura:if>
</aura:if>
</aura:component>
-----------------------------------------------------------------------------
JS Controller
({
doInit : function(component, event, helper) {
var action = component.get("c.fetchUser");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
var storeResponse = response.getReturnValue();
component.set("v.userInfo", storeResponse);
}
});
$A.enqueueAction(action);
var recordId = component.get('v.recordId');
var action = component.get('c.findRecordId');
console.log('action :'+ action);
console.log('recordId '+ recordId);
var action = component.get("c.findRecordId");
action.setParams({
recordId: component.get("v.recordId")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set('v.focWithFocLineItem', response.getReturnValue());
console.log('response.getReturnValue',response.getReturnValue());
console.log('focWithFocLineItem :'+v.focWithFocLineItem);
$A.get('e.force:showToast').setParams
({
"title": "Success",
"message": "Email has been sent successfully!",
"type": "success",
}).fire();
} else {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : 'Error',
message:'Failed to send email. Error: '+ response.getError()[0].message,
key: 'info_alt',
type: 'error',
mode: 'pester'
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
},
cancelModal : function(component, event, helper) {
$A.get("e.force:closeQuickAction").fire();
},
backModal : function(component, event, helper) {
component.set('v.hideAndShow', false);
},
handleInputValueChange : function(component, event, helper) {
component.set('v.hideAndShow', true);
hideAndShow = true;
var inputValue = component.find("inputValue").get("v.value");
component.set("v.inputValue", inputValue);
},
searchKeyChange: function(component, event) {
var recordId = component.get('v.recordId');
var action = component.get('c.findByAmt');
var searchKey = component.find("inputValue");
var ccEmails = component.find("inputValue2");
var sub = searchKey.get("v.value");
var ccMails = ccEmails.get("v.value");
console.log('sub '+ sub);
if( sub == ''){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : 'Error',
message:'Please Enter To-Email Id',
key: 'info_alt',
type: 'warning',
mode: 'pester'
});
toastEvent.fire();
}
var action = component.get("c.findByAmt");
console.log('ccMails : ', ccMails);
console.log('action : ', action);
if(sub != ''){
action.setParams({
searchKey: sub,
ccEmails: ccMails,
recordId:recordId
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
$A.get('e.force:showToast').setParams
({
"title": "Success",
"message": "Email has been sent successfully!",
"type": "success",
}).fire();
$A.get("e.force:closeQuickAction").fire();
} else {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : 'Error',
message:'Failed to send email. Error: '+ response.getError()[0].message,
key: 'info_alt',
type: 'error',
mode: 'pester'
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
}
},
previewFormat: function(component, event) {
}
})
----------------------------------------------------------------
Apex controller
public class FOCDraftEmailController {
@AuraEnabled
public static user fetchUser(){
User u = [select id,Name from User where id =: userInfo.getUserId()];
System.debug('u:'+u);
return u;
}
@AuraEnabled
public static FOC__c findRecordId(String recordId) {
System.debug('recordId :'+ recordId);
FOC__c focObj = [SELECT Id, OwnerId, IsDeleted, Name, CurrencyIsoCode, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, LastActivityDate, LastViewedDate, LastReferencedDate, Bill_To__c, Work_Order__r.WorkOrderNumber, Machine_No__c, OrderType__c, Plant__c, SAP_FOC_Sales_Order_No__c, Work_Order__c, Case_No__c, Customer_Name__c, Model__c, Product_Family__c, SAP_Service_Notification_No__c, Sub_Product__c, Work_Order_No__c, Approval_Status__c, Service_Head_Approval_Required__c, VP_Approval_Required__c, SAP_Error_Message__c, Ship_To_Code__c, Bill_To_Name__c, Bill_To_Payee__c, Case_Creation_Date__c, City__c, Country__c, Distribution_Channel__c, Equipment_No__c, Material_Code__c, Notication_Descp__c, SAP_Model__c, Sales_Region__c, Ship_to_Name__c, Ship_to_Number__c, Sold_To_Name__c, Sold_to_Number__c, Work_Order_Created_Date__c, Status__c, Foc_Order_Line_Item_Count__c, Ship_To__c, Ship_To_Name1__c, Ship_To_Address1__c, SAP_Warning_Message__c, Sold_To__c, Temp_Status__c, FOC_Store_Loc__c, Location_Name__c, FOC_Category__c, Remark__c,
(SELECT Id, OwnerId, IsDeleted, Name, CurrencyIsoCode, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, LastViewedDate, LastReferencedDate, Basic_Price__c, CRP__c, Category__c, Description__c, FOC_Order__c, FOC_Reason__c, Product__c, Quantity__c, Return_Order_LI__c, Return_Order_No__c, SAP_Line_No__c, Item_Description__c, Total_Net_Weight__c, Unit_Net_Weight__c, Unit__c, UoM__c, Approval_Status__c, Delivered_Quantity__c, Value__c, Material_Code__c, Reason_For_Cancellation__c, Product_Code__c, SAP_Material_Ref__c, FOC_Reason_Label_Name__c FROM FOC_Order_Line_Items__r )FROM FOC__c Where Id =: recordId];
return focObj;
}
@AuraEnabled
public static FOC__c findByAmt(String searchKey, String ccEmails, String recordId) {
System.debug('ccEmails : '+ ccEmails);
System.debug('recordId : '+ recordId);
String userId = UserInfo.getUserId();
String firstName = UserInfo.getFirstName();
String lastName = UserInfo.getLastName();
FOC__c focObj = [SELECT Id, OwnerId, IsDeleted, Name, CurrencyIsoCode, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, LastActivityDate, LastViewedDate, LastReferencedDate, Bill_To__c, Work_Order__r.WorkOrderNumber, Machine_No__c, OrderType__c, Plant__c, SAP_FOC_Sales_Order_No__c, Work_Order__c, Case_No__c, Customer_Name__c, Model__c, Product_Family__c, SAP_Service_Notification_No__c, Sub_Product__c, Work_Order_No__c, Approval_Status__c, Service_Head_Approval_Required__c, VP_Approval_Required__c, SAP_Error_Message__c, Ship_To_Code__c, Bill_To_Name__c, Bill_To_Payee__c, Case_Creation_Date__c, City__c, Country__c, Distribution_Channel__c, Equipment_No__c, Material_Code__c, Notication_Descp__c, SAP_Model__c, Sales_Region__c, Ship_to_Name__c, Ship_to_Number__c, Sold_To_Name__c, Sold_to_Number__c, Work_Order_Created_Date__c, Status__c, Foc_Order_Line_Item_Count__c, Ship_To__c, Ship_To_Name1__c, Ship_To_Address1__c, SAP_Warning_Message__c, Sold_To__c, Temp_Status__c, FOC_Store_Loc__c, Location_Name__c, FOC_Category__c, Remark__c FROM FOC__c Where Id =: recordId];
List<FOC_Order_Line_Items__c > focLineItems = [SELECT Id, OwnerId, IsDeleted, Name, CurrencyIsoCode, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, LastViewedDate, LastReferencedDate, Basic_Price__c, CRP__c, Category__c, Description__c, FOC_Order__c, FOC_Reason__c, Product__c, Quantity__c, Return_Order_LI__c, Return_Order_No__c, SAP_Line_No__c, Item_Description__c, Total_Net_Weight__c, Unit_Net_Weight__c, Unit__c, UoM__c, Approval_Status__c, Delivered_Quantity__c, Value__c, Material_Code__c, Reason_For_Cancellation__c, Product_Code__c, SAP_Material_Ref__c, FOC_Reason_Label_Name__c FROM FOC_Order_Line_Items__c where FOC_Order__c =: recordId];
List<String> inputValue = new List<String>();
String[] listOfToEmails = new string[]{};
String[] listOfCCEmails = new string[]{};
listOfToEmails = searchKey.split(',');
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.setToAddresses(listOfToEmails);
if(ccEmails != ''){
System.debug('cc emails');
listOfCCEmails = ccEmails.split(',');
message.setCcAddresses(listOfCCEmails);
}
String cusName = focObj.Customer_Name__c != Null ? focObj.Customer_Name__c : '-';
String shipToAdd = focObj.Ship_To_Address1__c != Null ? focObj.Ship_To_Address1__c : '-';
String locStore = focObj.FOC_Store_Loc__c != null ? focObj.FOC_Store_Loc__c : '-';
String locName = focObj.Location_Name__c != Null ? focObj.Location_Name__c : '-';
String SAPSalesOrdName = focObj.SAP_FOC_Sales_Order_No__c != Null ? focObj.SAP_FOC_Sales_Order_No__c : '-';
String CRMFocName = focObj.Name != Null ? focObj.Name : '-';
String SAPServicecNotif = focObj.SAP_Service_Notification_No__c != Null ? focObj.SAP_Service_Notification_No__c : '-';
String crmWorkOrd = focObj.Work_Order__r.WorkOrderNumber != Null ? focObj.Work_Order__r.WorkOrderNumber : '-';
String machineModel = focObj.Model__c != Null ? focObj.Model__c : '-';
String crmCaseNo = focObj.Case_No__c != Null ? focObj.Case_No__c : '-';
String machineNo = focObj.Machine_No__c != Null ? focObj.Machine_No__c : '-';
String remark = focObj.Remark__c != Null ? focObj.Remark__c : '-';
message.setSubject('FOC Sales Order | '+ cusName +' '+ shipToAdd);
String htmlBody2 = '<!DOCTYPE html><html><head><title>Page Title</title></head><body><!DOCTYPE html><html><head><title>Page Title</title></head><body>';
htmlBody2 += '<ul type="disc"><li>Dear Sir<ul type="disc"><p>It is required to send certain parts on FOC basis against the referred Sales Order.<br/><br/>';
htmlBody2 += 'You are requested to please arrange to transfer below listed material to Store Loc.' +locStore+'('+locName+')'+ ' & issue';
htmlBody2 += 'and hand over to Packing Dept. However, if parts are not available in store, kindly inform the shortage to concerned person/ department for';
htmlBody2 += 'necessary action.</p></ul></li><li>Dear Packing Team<ul type="disc"><p>Please arrange to get the material packed once issued from Store';
htmlBody2 += 'enabling us to perform further formalities.</p></ul></li><li>List of parts under referred Sales Order is given under.<ul type="disc"></ul>';
htmlBody2 += '</li></ul><div style="padding-left:82px"><table border="1" style="min-width: 100%; border-collapse: collapse;"><tr> <th colspan="4" ';
htmlBody2 += 'style="background-color:#E4F2CB">FREE OF COST SALES ORDER FOR</th></tr><tr> <td style="background-color:#EAE4EA"> Customer</td> <td rowspan="1"';
htmlBody2 += 'colspan="3" > '+cusName+' '+shipToAdd+'</td></tr><tr> <td style="background-color:#EAE4EA"> SAP Sales Order</td>';
htmlBody2 += '<td > '+SAPSalesOrdName+'</td> <td style="background-color:#EAE4EA"> CRM FOC No.</td><td> '+CRMFocName+'</td></tr><tr>';
htmlBody2 += '<td style="background-color:#EAE4EA; width:30%"> SAP Service Notification</td><td> '+SAPServicecNotif+'</td><td style="background-color:#EAE4EA"> CRM ';
htmlBody2 += 'Work Order</td> <td> '+crmWorkOrd +'</td></tr><tr> <td style="background-color:#EAE4EA"> Machine Model</td>';
htmlBody2 += '<td> '+machineModel+'</td> <td style="background-color:#EAE4EA"> CRM Case No. </td> <td> '+crmCaseNo+'</td></tr><tr> <td style="background-color:#EAE4EA"> Machine No(s). </td> <td rowspan="1" colspan="3"> '+machineNo+'</td></tr></table><table border="1" style="min-width: 100%; border-collapse: collapse;">';
htmlBody2 += '<tr><th style="background-color:#EAE4EA"> Sr No.</th><th style="background-color:#EAE4EA"> Item Code </th> <th style="background-color:#EAE4EA"> Item Description </th> <th style="background-color:#EAE4EA"> Qty </th> <th style="background-color:#EAE4EA"> Unit </th> <th style="background-color:#EAE4EA"> FOC Reason </th></tr>';
Integer srNo = 1;
if(!focLineItems.isEmpty()){
for(FOC_Order_Line_Items__c focLineItm : focLineItems){
String itemCode = focLineItm.Product_Code__c != Null ? focLineItm.Product_Code__c : '-';
String itemDescription = focLineItm.Description__c != Null ? focLineItm.Description__c : '-';
String Qty = focLineItm.Quantity__c != Null ? String.valueOf(focLineItm.Quantity__c) : '-';
String Unit = focLineItm.Unit__c != Null ? focLineItm.Unit__c : '-';
String focReason = focLineItm.FOC_Reason__c != Null ? focLineItm.FOC_Reason__c : '-';
htmlBody2 += '<tr style="text-align:center;"><td>'+srNo+'.</td><td>'+itemCode+'</td><td>'+itemDescription+'</td><td>'+Qty+'</td><td>'+Unit+'</td><td>'+focReason+'</td></tr>';
srNo++;
}
}
htmlBody2 += '<tr><td> Remarks if any: </td><td rowspan="1" colspan="5" > '+remark+'</td></tr><tr> <td rowspan="1" colspan="6" style="background-color:#F9EBB5;"><b><center>PACKING DETAIL (To be filled by Packing Department)</center></b></td></tr></table><table border="1" style="min-width: 100%; border-collapse: collapse;">';
htmlBody2 += '<tr><td> CASE NO.</td><td style="width:20%"></td><td> NET WEIGHT (KGS)</td> <td style="width:20%"></td></tr><tr> <td> PACKING DATE</td> <td></td> <td> GROSS WEIGHT (KGS) </td> <td></td></tr><tr> <td> PACKING BOX (W/C*) </td> <td></td> <td> CASE SIZE (CMxCMxCM)</td> <td></td></tr></table><p><br/>Regards,<br/>'+firstName+' '+lastName+'<br/><br/>Copy to: <br/>MDM IT - Please run the MRP against above referred Sales Order.</p></div></body></html></body></html>';
message.setHtmlBody(htmlBody2);
mails.add(message);
Messaging.SendEmailResult[] results = Messaging.sendEmail( new List<Messaging.SingleEmailMessage> {message} );
return null;
}
}
Comments
Post a Comment