({
doInit : function(component, event, helper) {
var action = component.get("c.getOppData");
var oppid;
action.setParams({
"oppId": component.get("v.recordId")
});
action.setCallback(this, function(response) {
alert('time is 1246');
var state = response.getState();
if (state === "SUCCESS") {
var resp = response.getReturnValue();
//console.log(' response: ' + JSON.stringify(resp));
alert('OppData is'+ JSON.stringify(resp));
component.set("v.name", resp.Name);
alert('OppData Name is'+resp.Name);
component.set("v.oppPacode", resp.Referral_ID__c);
alert('OppData Referral_ID__c is'+resp.Referral_ID__c);
component.set("v.partner", resp.Bank_Lookup__c);
alert('OppData Bank_Lookup__r.Name is'+resp.Bank_Lookup__r.Name);
component.set("v.recordtype", resp.RecordTypeId);
alert('OppData Rectypeid is'+resp.RecordTypeId);
var OppName=resp.Name;
var partner=resp.Bank_Lookup__r.Name;
var oppPacode=resp.Referral_ID__c;
var Rectypeid=resp.RecordTypeId;
alert('OppData is'+OppName+' '+partner+' '+oppPacode+' '+Rectypeid);
//Start-
var initial;
var msg = '';
var pMid='';
var sMid='';
var partsOppID='';
var servOppID='';
var partValue;
var servValue;
var err = false;
var retValue;
if(partner!='CITI' ||(oppPacode!=''&&oppPacode.length!=5))
alert('This functionality applies only to Ford Dealers.');
else if(oppPacode==''||oppPacode=='undefined')
alert('The Opportunity(' +oppname + ')has no PA Code available. Call cannot be made.');
else{
//var result =sforce.apex.execute("PennyTestRequestCallout","validateOppDetailsForCallout",{paCode:oppPacode,recordtype:recordtype,partner:partner});
var action1 = component.get("c.validateOppDetailsForCallout");
action1.setParams({
"paCode": oppPacode,
"recordtype":Rectypeid,
"partner":partner
});
var result = '';
action1.setCallback(this, function(response) {
alert('response on validateOppDetailsForCallout'+response.getReturnValue());
result = response.getReturnValue();
result= result.join('');
});
alert('response on validateOppDetailsForCallout result is'+result);
if(result == 'Error')
{
err = true;
alert('There was an error occured. Please Contact SFDCOPS or SF Admin Team.');
}
else{
retValue = result.split("||");
}
if(retValue.length > 0 && err == false)
{
if(retValue[0] == 'Valid')
{
if(retValue.length == 4){
pMid = retValue[1].split(":")[1];
partsOppID=retValue[1].split(":")[2];
sMid = retValue[2].split(":")[1];
servOppID=retValue[2].split(":")[2];
msg = 'The below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' , ' +
'Parts MID: ' + pMid + ' & Service MID: ' + sMid + '\n\n Do you want to continue sending the details?';
}
else if(retValue.length == 3){
if(retValue[1].split(":")[0] != 'S'){
alert(retValue[retValue.length - 1]);
pMid = retValue[1].split(":")[1];
partsOppID=retValue[1].split(":")[2];
msg = 'Now, the below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Parts MID: ' + pMid + '\n\n Do you want to continue sending the details?';
}
else if(retValue[1].split(":")[0] == 'S'){
alert(retValue[retValue.length - 1]);
sMid = retValue[1].split(":")[1];
servOppID=retValue[1].split(":")[2];
msg = 'Now, the below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Service MID: ' + sMid + '\n\n Do you want to continue sending the details?';
}
}
else if(retValue.length==2){
if(retValue[1].split(":")[0] != 'P' && retValue[1].split(":")[0] != 'S'){
alert(retValue[retValue.length - 1]);
}
if(retValue[1].split(":")[0] == 'P')
{
pMid = retValue[1].split(":")[1];
partsOppID=retValue[1].split(":")[2];
msg = 'The below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Parts MID: ' + pMid + '\n\n Do you want to continue sending the details?';
}
else if(retValue[1].split(":")[0] == 'S')
{
sMid = retValue[1].split(":")[1];
servOppID=retValue[1].split(":")[2];
msg = 'The below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Service MID: ' + sMid + '\n\n Do you want to continue sending the details?';
}
}
if(confirm(msg))
{
alert('You have confirmed to submit the Penny Test request');
if(pMid.length > 0 && sMid.length > 0)
{
//var iwerkCall = sforce.apex.execute("PennyTestRequestCallout","makeCallout",{paCode:oppPacode,partsMID:pMid,servMID:sMid,partsOppID:partsOppID,servOppID:servOppID});
var action = component.get("c.makeCallout");
action.setParams({
"paCode": oppPacode,
"partsMID":pMid,
"servMID":sMid,
"partsOppID":partsOppID,
"servOppID":servOppID
});
}
else if(pMid.length > 0 && sMid.length == 0)
{
var iwerkCall = sforce.apex.execute("PennyTestRequestCallout","makeCallout",{paCode:oppPacode,partsMID:pMid,servMID:null,partsOppID:partsOppID,servOppID:null});
}
else if(pMid.length == 0 && sMid.length > 0)
{
var iwerkCall = sforce.apex.execute("PennyTestRequestCallout","makeCallout",{paCode:oppPacode,partsMID:null,servMID:sMid,partsOppID:null,servOppID:servOppID});
}
if(iwerkCall=='Success'){
alert('Penny Test request has been submitted successfully');
document.location.reload(true);
}
else if(iwerkCall=='Failed')
{
alert('There was an error in confirming the PA code. Please Contact SFDCOPS or SF Admin Team.');
document.location.reload(true);
}
else if(iwerkCall == 'ErrorConn')
{
alert('There was a connection error in sending the PA code. Please Contact SFDCOPS or SF Admin Team.');
document.location.reload(true);
}
else if(iwerkCall == 'ErrorSF')
{
alert('Error occured while updating Data in Salesforce. Please Contact SFDCOPS or SF Admin Team.');
document.location.reload(true);
}
}
else
{
alert('You have selected to stop');
}
}
else
{
alert(retValue[1]);
}
}
}
//end
}
else{
alert("No response from the Server. Please try again");
}
});
// Invoke the service
$A.enqueueAction(action);
}
})
doInit : function(component, event, helper) {
var action = component.get("c.getOppData");
var oppid;
action.setParams({
"oppId": component.get("v.recordId")
});
action.setCallback(this, function(response) {
alert('time is 1246');
var state = response.getState();
if (state === "SUCCESS") {
var resp = response.getReturnValue();
//console.log(' response: ' + JSON.stringify(resp));
alert('OppData is'+ JSON.stringify(resp));
component.set("v.name", resp.Name);
alert('OppData Name is'+resp.Name);
component.set("v.oppPacode", resp.Referral_ID__c);
alert('OppData Referral_ID__c is'+resp.Referral_ID__c);
component.set("v.partner", resp.Bank_Lookup__c);
alert('OppData Bank_Lookup__r.Name is'+resp.Bank_Lookup__r.Name);
component.set("v.recordtype", resp.RecordTypeId);
alert('OppData Rectypeid is'+resp.RecordTypeId);
var OppName=resp.Name;
var partner=resp.Bank_Lookup__r.Name;
var oppPacode=resp.Referral_ID__c;
var Rectypeid=resp.RecordTypeId;
alert('OppData is'+OppName+' '+partner+' '+oppPacode+' '+Rectypeid);
//Start-
var initial;
var msg = '';
var pMid='';
var sMid='';
var partsOppID='';
var servOppID='';
var partValue;
var servValue;
var err = false;
var retValue;
if(partner!='CITI' ||(oppPacode!=''&&oppPacode.length!=5))
alert('This functionality applies only to Ford Dealers.');
else if(oppPacode==''||oppPacode=='undefined')
alert('The Opportunity(' +oppname + ')has no PA Code available. Call cannot be made.');
else{
//var result =sforce.apex.execute("PennyTestRequestCallout","validateOppDetailsForCallout",{paCode:oppPacode,recordtype:recordtype,partner:partner});
var action1 = component.get("c.validateOppDetailsForCallout");
action1.setParams({
"paCode": oppPacode,
"recordtype":Rectypeid,
"partner":partner
});
var result = '';
action1.setCallback(this, function(response) {
alert('response on validateOppDetailsForCallout'+response.getReturnValue());
result = response.getReturnValue();
result= result.join('');
});
alert('response on validateOppDetailsForCallout result is'+result);
if(result == 'Error')
{
err = true;
alert('There was an error occured. Please Contact SFDCOPS or SF Admin Team.');
}
else{
retValue = result.split("||");
}
if(retValue.length > 0 && err == false)
{
if(retValue[0] == 'Valid')
{
if(retValue.length == 4){
pMid = retValue[1].split(":")[1];
partsOppID=retValue[1].split(":")[2];
sMid = retValue[2].split(":")[1];
servOppID=retValue[2].split(":")[2];
msg = 'The below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' , ' +
'Parts MID: ' + pMid + ' & Service MID: ' + sMid + '\n\n Do you want to continue sending the details?';
}
else if(retValue.length == 3){
if(retValue[1].split(":")[0] != 'S'){
alert(retValue[retValue.length - 1]);
pMid = retValue[1].split(":")[1];
partsOppID=retValue[1].split(":")[2];
msg = 'Now, the below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Parts MID: ' + pMid + '\n\n Do you want to continue sending the details?';
}
else if(retValue[1].split(":")[0] == 'S'){
alert(retValue[retValue.length - 1]);
sMid = retValue[1].split(":")[1];
servOppID=retValue[1].split(":")[2];
msg = 'Now, the below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Service MID: ' + sMid + '\n\n Do you want to continue sending the details?';
}
}
else if(retValue.length==2){
if(retValue[1].split(":")[0] != 'P' && retValue[1].split(":")[0] != 'S'){
alert(retValue[retValue.length - 1]);
}
if(retValue[1].split(":")[0] == 'P')
{
pMid = retValue[1].split(":")[1];
partsOppID=retValue[1].split(":")[2];
msg = 'The below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Parts MID: ' + pMid + '\n\n Do you want to continue sending the details?';
}
else if(retValue[1].split(":")[0] == 'S')
{
sMid = retValue[1].split(":")[1];
servOppID=retValue[1].split(":")[2];
msg = 'The below details will be sent to iWerks. \n\n PA Code: ' + oppPacode + ' & ' +
'Service MID: ' + sMid + '\n\n Do you want to continue sending the details?';
}
}
if(confirm(msg))
{
alert('You have confirmed to submit the Penny Test request');
if(pMid.length > 0 && sMid.length > 0)
{
//var iwerkCall = sforce.apex.execute("PennyTestRequestCallout","makeCallout",{paCode:oppPacode,partsMID:pMid,servMID:sMid,partsOppID:partsOppID,servOppID:servOppID});
var action = component.get("c.makeCallout");
action.setParams({
"paCode": oppPacode,
"partsMID":pMid,
"servMID":sMid,
"partsOppID":partsOppID,
"servOppID":servOppID
});
}
else if(pMid.length > 0 && sMid.length == 0)
{
var iwerkCall = sforce.apex.execute("PennyTestRequestCallout","makeCallout",{paCode:oppPacode,partsMID:pMid,servMID:null,partsOppID:partsOppID,servOppID:null});
}
else if(pMid.length == 0 && sMid.length > 0)
{
var iwerkCall = sforce.apex.execute("PennyTestRequestCallout","makeCallout",{paCode:oppPacode,partsMID:null,servMID:sMid,partsOppID:null,servOppID:servOppID});
}
if(iwerkCall=='Success'){
alert('Penny Test request has been submitted successfully');
document.location.reload(true);
}
else if(iwerkCall=='Failed')
{
alert('There was an error in confirming the PA code. Please Contact SFDCOPS or SF Admin Team.');
document.location.reload(true);
}
else if(iwerkCall == 'ErrorConn')
{
alert('There was a connection error in sending the PA code. Please Contact SFDCOPS or SF Admin Team.');
document.location.reload(true);
}
else if(iwerkCall == 'ErrorSF')
{
alert('Error occured while updating Data in Salesforce. Please Contact SFDCOPS or SF Admin Team.');
document.location.reload(true);
}
}
else
{
alert('You have selected to stop');
}
}
else
{
alert(retValue[1]);
}
}
}
//end
}
else{
alert("No response from the Server. Please try again");
}
});
// Invoke the service
$A.enqueueAction(action);
}
})
No comments:
Post a Comment