import { LightningElement, track,api, wire } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import fetchDetailVerification from '@salesforce/apex/BGEAuthenticatedConsumerController.fetchDetailVerification';
import searchFilterList from '@salesforce/apex/BGEAuthenticatedConsumerController.searchFilterList';
import updateCaseWithContact from '@salesforce/apex/BGEAuthenticatedConsumerController.updateCaseWithContact';
import { refreshApex } from '@salesforce/apex';
import bgeFullAccessMessage from '@salesforce/label/c.bgeFullAccessMessage';
import dynamicMeteringChange from '@salesforce/apex/BGEAuthenticatedConsumerController.dynamicMeteringChange';
import dynamicPaymentChangeMethod from '@salesforce/apex/BGEAuthenticatedConsumerController.dynamicPaymentChangeMethod';
const chatVoiceColumns = [
{
label: "Source",
fieldName: "Source",
type: "text",
cellAttributes: {
iconName: { fieldName: "iconName" },
iconPosition: "left"
}
},
{
label: "Name",
fieldName: "Id",
type: "url",
typeAttributes: {
label: {
fieldName: "Name",
type: "text"
}
}
},
{ label: "Email", fieldName: "Email", type: "text" },
{ label: "Home Phone", fieldName: "Phone", type: "text" },
{ label: "Account Id", fieldName: "AccountId", type: "text" }
];
const recordLevelActions = [
{ label : 'Edit', name:'editContact'},
{ label : 'Change Email', name:'changeEmail'},
];
const contactColumns = [
{label: 'Contact Name', fieldName: 'ContactId', type: 'url',
typeAttributes: {
label: {
fieldName: 'Name', type: 'text'
}
},
cellAttributes:{ class: { fieldName : 'highlightRow'}}
},
{label: 'Email', fieldName: 'Email', type: 'text',cellAttributes:{ class: { fieldName : 'highlightRow'}} },
{label: 'Home Phone', fieldName: 'Phone', type: 'text',cellAttributes:{ class: { fieldName : 'highlightRow'}}},
{label: 'Primary', fieldName: 'isPrimary', type: 'boolean', cellAttributes:{ class: { fieldName : 'highlightRow'}}},
{label: 'IsDeceased', fieldName: 'IsDeceased', type: 'boolean', cellAttributes:{ class: { fieldName : 'highlightRow'}}},
{label: 'Status', fieldName: 'ContactStatus', type: 'text', cellAttributes:{ class: { fieldName : 'highlightRow'}}},
{label: 'Access Level',fieldName: '',
cellAttributes:{
style: { fieldName: 'iconClass' },
class: { fieldName : 'highlightRow'},
iconName: { fieldName: 'displayIconName'},
iconPosition: 'left',
iconAlternativeText:'test'
},fieldName:'status'
},
{label: 'Update Contact',
type: 'action',
typeAttributes: {
rowActions: recordLevelActions
},
cellAttributes:{
class: { fieldName : 'highlightRow'}
}
}
];
const assetColumns = [
{label: 'Customer Account', fieldName: 'consumerAccountURL', type: 'url',
typeAttributes: {
label: {
fieldName: 'consumerAccountName', type: 'text'
}
},
},
{label: 'Billing Account', fieldName: 'billingAccountURL', type: 'url',
typeAttributes: {
label: {
fieldName: 'billingAccountName', type: 'text'
}
},
},
{label: 'Billing Account Number', fieldName: 'billingAccountNumber', type: 'text'},
{label: 'Fuel Type', fieldName: 'AssetSubtype__c', type: 'text'},
];
const filterContactColumns = [
{
label: "Consumer Account",
fieldName: "consumerAccountId",
type: "url",
typeAttributes: {
label: {
fieldName: "consumerAccountName"
}
}
},
{ label: "Billing Account", fieldName: "billingAccountName", type: "text" },
{
label: "Contact",
fieldName: "contactId",
type: "url",
typeAttributes: {
label: {
fieldName: "contactName"
}
}
},
{ label: "Phone", fieldName: "contactPhone", type: "text" },
{ label: "Email", fieldName: "contactEmail", type: "text" },
{ label: "Primary", fieldName: "contactPrimary", type: "boolean" },
{ label: "Access Level", fieldName: "contactAccessLevel", type: "text" }
];
const altBillNameColumns = [
{label: "Account name", fieldName: "AccountPage", type: "url",
typeAttributes: {
label: {
fieldName: 'AccountName', type: 'text'
},
}
},
{label: "Alternative name", fieldName: "Id", type: "url",
typeAttributes: {
label: {
fieldName: 'AlternativeBillingName__c', type: 'text'
},
}
},
];
const filterType = [
{label : 'Contact Name', value: 'ContactName'},
{label : 'Account Id', value: 'AccountId'},
{label : 'Contact Phone', value: 'ContactPhone'},
{label : 'Contact Email', value: 'ContactEmail'},
{label : 'Postal Code', value: 'PostalCode'},
{label : 'Premise Address', value: 'PremiseAddress'}
];
export default class BgeAuthenticatedConsumer extends NavigationMixin(LightningElement) {
label = {
bgeFullAccessMessage,
}
chatVoiceColumns = chatVoiceColumns;
contactColumns = contactColumns;
assetColumns = assetColumns;
filterType = filterType;
filterContactColumns = filterContactColumns;
recordLevelActions = recordLevelActions;
altBillNameColumns = altBillNameColumns;
@track paymentMethod;
@track paymentFrequency;
@track paymentDetails;
@track brandJs;
@track salesOriginJs;
@track gasSupplyStartDateJs;
@track gasWithdrawalDateJs;
@track elecSupplyStartDateJs;
@track elecWithdrawalDateJs;
@api recordId;
boolIsLoading = true;
boolIsModalOpen=false;
boolContact = false;
boolAsset = false;
boolIsloggedin = false;
boolLoggedIn = false;
boolIsSearchContact = false;
boolIsEnterSearchValue = true;
boolIsContactUpdate = false;
boolIsUpdateEmail = false;
boolIsFullAccess = false;
boolCheckAnyFlag = false;
strSelectedFilterValue = 'ContactName';
strSearchText;
strError;
strConsumerAccount;
strVisitorSubject;
strIDVStatus;
strClassName;
strConsumerId;
strSelectedContactId;
strDefaultValue;
strContactURL = '/lightning/r/Contact/';
strMarketingConsent = 'Marketing consent - ';
strBillingAccountId;
strContactPrefs = "Communication preference - ";
strCommsPrefFormat = "Communications format - ";
strAltBillAddress = "Alternative billing address - ";
strBillingAccountBrand;
strSmartMeterRefusal;
strSmartMeterRefusalURL;
strTariffName;
strTariffElectric = 'Electric - ';
strTariffGas = 'Gas - ';
strTariffElectricURL;
strTariffGasURL;
strTariffRenewalURL;
strTariffRenewal = 'Tariff renewal';
strTariffElectricStartDate = 'Tariff Start Date: ';
strTariffElectricEndDate = 'Tariff End Date: ';
strTariffGasStartDate = 'Tariff Start Date: ';
strTariffGasEndDate = 'Tariff End Date: ';
@track lstWireData
@track lstVisitorContactDetail;
@track selectedContactRow;
@track lstVisitorDetail;
@track lstContact;
@track lstAssets;
@track lstFilterContact;
@track lstTotalContactRecords;
@track lstActiveSessions = [];
@track lstPremises;
@track selectedBillingAccount;
@track latestQuoteRecord;
@track mapFlags = [];
@track mapOfBillingAccount = new Map();
selectedAssets = false;
tempRecords = false;
dynamicMeteringDisplay(accountid) {
dynamicMeteringChange({strRecordId:accountid})
.then((result) => {
this.brandJs = result.salesBrandCls;
this.salesOriginJs = result.salesOriginCls;
this.gasSupplyStartDateJs = result.gasSupplyStartDateCls;
this.gasWithdrawalDateJs = result.gasWithdrawalDateCls;
this.elecSupplyStartDateJs = result.elecSupplyStartDateCls;
this.elecWithdrawalDateJs = result.elecWithdrawalDateCls;
})
.catch(error => {
this.strError = error;
console.error(this.strError);
});
}
dynamicPaymentInfoDisplay(accountid) {
dynamicPaymentChangeMethod({strRecordId:accountid})
.then((result) => {
this.paymentMethod = result.paymentMethod;
this.paymentFrequency = result.paymentFrequency;
})
.catch(error => {
this.strError = error;
console.error(this.strError);
});
}
@wire(fetchDetailVerification, { strRecordId: '$recordId' })
fetchDetailVerification(wireResult) {
const { data, error } = wireResult;
this.lstWireData= wireResult;
if (data) {
this.lstVisitorContactDetail = JSON.parse(JSON.stringify(data));
if(this.lstVisitorContactDetail.consumerAccount){
this.strConsumerAccount = this.lstVisitorContactDetail.consumerAccount.Name;
this.strConsumerId = this.lstVisitorContactDetail.consumerAccount.Id;
this.strConsumerURL = '/lightning/r/Account/'+this.lstVisitorContactDetail.consumerAccount.Id+'/view';
if(this.lstVisitorContactDetail.consumerAccount.PasswordForHomeVisit__c){
this.boolHomeVisitPassword = true;
}
}
let visitorDetail = {};
visitorDetail.Source = 'Provided by Web Customer';
visitorDetail.Name = visitorDetail.Email = visitorDetail.Phone = visitorDetail.AccountId = visitorDetail.Subject = '';
visitorDetail.iconName = 'standard:contact';
let caseContactDetail = {};
caseContactDetail.Source = 'Case Contact';
caseContactDetail.Name = caseContactDetail.Email = caseContactDetail.Phone = caseContactDetail.AccountId = caseContactDetail.Subject = '';
caseContactDetail.iconName = 'standard:live_chat_visitor';
if(this.lstVisitorContactDetail.lstConversationRecords && !this.lstVisitorContactDetail.boolCTLCase){
for (let i = 0; i < this.lstVisitorContactDetail.lstConversationRecords.length; i++) {
let row = this.lstVisitorContactDetail.lstConversationRecords[i];
if (row){
if(row.CustomDetailContextKey === 'First Name' || row.CustomDetailContextKey === 'Last Name'){
visitorDetail.Name += row.CustomDetailContextValue!=undefined ? (row.CustomDetailContextValue+' ') : '';
visitorDetail.Id = '/';
}
if(row.CustomDetailContextKey === 'Email'){
visitorDetail.Email = row.CustomDetailContextValue;
}
if(row.CustomDetailContextKey === 'Phone'){
visitorDetail.Phone = row.CustomDetailContextValue;
}
if(row.CustomDetailContextKey === 'Account Number'){
visitorDetail.AccountId = row.CustomDetailContextValue;
}
if(row.CustomDetailContextKey === 'Subject'){
this.strVisitorSubject = row.CustomDetailContextValue!=undefined? 'Subject :'+row.CustomDetailContextValue : '';
}
if(row.CustomDetailContextKey === 'Logged In'){
this.boolLoggedIn = row.CustomDetailContextValue;
}
}
}
this.strIDVStatus = this.boolLoggedIn == 'true' ? 'Logged In' : (this.lstVisitorContactDetail.caseContact != undefined ? 'Please Verify!' : 'Please Identify!' );
this.strClassName = this.boolLoggedIn == 'true' ? 'greenIcon slds-button_icon-border' : (this.lstVisitorContactDetail.caseContact != undefined ? 'orangeIcon slds-button_icon-border' : 'redIcon slds-button_icon-border' );
}
else if(this.lstVisitorContactDetail.caseCTIDetail && this.lstVisitorContactDetail.boolCTLCase){
visitorDetail.Source = this.lstVisitorContactDetail.caseCTIDetail.Origin!= undefined ? (this.lstVisitorContactDetail.caseCTIDetail.Origin == 'WhatsApp' ? 'Provided by WhatsApp Customer' : 'Provided by Phone Customer') : 'Provided by Phone Customer' ;
visitorDetail.Name = this.lstVisitorContactDetail.caseCTIDetail.connectCTISuggestedAccount__c!=undefined ? this.lstVisitorContactDetail.caseCTIDetail.connectCTISuggestedAccount__r.Name : '' ;
visitorDetail.Id = '';
visitorDetail.Email = this.lstVisitorContactDetail.caseCTIDetail.Email!= undefined ? this.lstVisitorContactDetail.caseCTIDetail.Email : '';
visitorDetail.Phone = this.lstVisitorContactDetail.caseCTIDetail.ConnectCTISearchedPhone__c != undefined ? (this.lstVisitorContactDetail.caseCTIDetail.ConnectCTISearchedPhone__c.length >10 ? '0'+this.lstVisitorContactDetail.caseCTIDetail.ConnectCTISearchedPhone__c.slice(this.lstVisitorContactDetail.caseCTIDetail.ConnectCTISearchedPhone__c.length-10): this.lstVisitorContactDetail.caseCTIDetail.ConnectCTISearchedPhone__c):'';
visitorDetail.AccountId = this.lstVisitorContactDetail.caseCTIDetail.ConnectCTISearchedAccount__c!=undefined ? 'A'+this.lstVisitorContactDetail.caseCTIDetail.ConnectCTISearchedAccount__c : '';
this.strIDVStatus = this.lstVisitorContactDetail.caseCTIDetail.ConnectCTIIDVStatus__c!=undefined ? (this.lstVisitorContactDetail.caseCTIDetail.ConnectCTIIDVStatus__c.toLowerCase() == 'full' ? 'Logged In' : (this.lstVisitorContactDetail.caseCTIDetail.ConnectCTIIDVStatus__c.toLowerCase() == 'partial' ? 'Please Verify!' : 'Please Identify!' )):'Please Identify!';
this.strClassName = this.lstVisitorContactDetail.caseCTIDetail.ConnectCTIIDVStatus__c!=undefined ? (this.lstVisitorContactDetail.caseCTIDetail.ConnectCTIIDVStatus__c.toLowerCase() == 'full' ? 'greenIcon slds-button_icon-border' : (this.lstVisitorContactDetail.caseCTIDetail.ConnectCTIIDVStatus__c.toLowerCase() == 'partial' ? 'orangeIcon slds-button_icon-border' : 'redIcon slds-button_icon-border' )):'redIcon slds-button_icon-border';
}
if(this.lstVisitorContactDetail.caseContact) {
caseContactDetail.Name = this.lstVisitorContactDetail.caseContact.Name!= undefined ? this.lstVisitorContactDetail.caseContact.Name : '';
caseContactDetail.Id = this.lstVisitorContactDetail.caseContact.Id!= undefined ? '/lightning/r/Contact/'+this.lstVisitorContactDetail.caseContact.Id+'/view' : '';
caseContactDetail.Email = this.lstVisitorContactDetail.caseContact.Email!= undefined ? this.lstVisitorContactDetail.caseContact.Email : '';
caseContactDetail.Phone = (this.lstVisitorContactDetail.caseContact.HomePhone!= undefined? this.lstVisitorContactDetail.caseContact.HomePhone:'');
//caseContactDetail.AccountId = this.lstVisitorContactDetail.strBillingAccount;
/*-----#36965-----*/
caseContactDetail.AccountName = this.lstVisitorContactDetail.caseContact.Account.Name!= undefined ? this.lstVisitorContactDetail.caseContact.Account.Name : ' ';
caseContactDetail.AlternativeBillingName__c = this.lstVisitorContactDetail.caseContact.AlternativeBillingName__c!= undefined ? this.lstVisitorContactDetail.caseContact.AlternativeBillingName__c : ' ';
caseContactDetail.AccountPage = '/lightning/r/Account/'+this.lstVisitorContactDetail.consumerAccount.Id+'/view';
this.caseContact = this.lstVisitorContactDetail.caseContact;
this.strContactPrefs += this.caseContact.ContactPreferences__c!= undefined? this.caseContact.ContactPreferences__c:'';
this.strCommsPrefFormat += this.caseContact.PreferredCommunicationFormat__c!= undefined? this.caseContact.PreferredCommunicationFormat__c:'';
this.strContactURL += this.caseContact.Id+'/view';
this.strAltBillAddress += [this.caseContact.MailingFlatNumber__c, this.caseContact.MailingHouseNumber__c, this.caseContact.MailingHouseName__c, this.caseContact.MailingStreet__c, this.caseContact.MailingStreet2__c, this.caseContact.MailingDoubleDependentLocality__c, this.caseContact.MailingDependentLocality__c, this.caseContact.MailingLocality__c, this.caseContact.MailingCounty__c, this.caseContact.MailingPostalCode__c].filter(Boolean).join(", ");
if(this.lstVisitorContactDetail.caseContact.IsDeceased__c){
this.mapFlags.push({value:'standard:network_contract', key:'Bereavement'});
this.boolCheckAnyFlag = this.mapFlags.length > 0 ? true : false;
}
if(this.lstVisitorContactDetail.consumerAccount.Cases){
this.mapFlags.push({value:'standard:incident', key:'Complaint'});
this.boolCheckAnyFlag = this.mapFlags.length > 0 ? true : false;
}
}
this.lstVisitorDetail = [caseContactDetail,visitorDetail];
this.communicationsDetail = [caseContactDetail];
if(this.lstVisitorContactDetail.caseContact && this.lstVisitorContactDetail.caseContact.Individual && this.lstVisitorContactDetail.caseContact.Individual.HasOptedOutSolicit){
this.strMarketingConsent += 'Opt Out';
}else if(this.lstVisitorContactDetail.lstContactPointTypeConsent.length > 0 && this.lstVisitorContactDetail.lstContactPointTypeConsent.length < 5){
this.optInNames = JSON.stringify(this.lstVisitorContactDetail.lstContactPointTypeConsent.map(({ Name }) => Name));
this.strMarketingConsent += this.optInNames.replaceAll('"', '').replaceAll('[','').replaceAll(']','');
}else if(this.lstVisitorContactDetail.lstContactPointTypeConsent.length === 5){
this.strMarketingConsent += 'Opt In';
}
if(this.lstVisitorContactDetail.lstContact){
let rowsContact = this.lstVisitorContactDetail.lstContact;
let lstContact=[];
for (let i = 0; i < rowsContact.length; i++) {
let row = rowsContact[i];
if (row){
row.Name = row.Name!=undefined?row.Name:'';
row.ContactId = row.Id!=undefined?'/lightning/r/Contact/'+row.Id+'/view':'';
row.Email = row.Email!=undefined?row.Email:'';
row.Phone = row.HomePhone!=undefined?row.HomePhone:'';
row.Birthdate = row.Birthdate!=undefined?row.Birthdate:'';
row.isPrimary = row.PrimaryContact__c!=undefined?row.PrimaryContact__c:false;
row.ContactStatus= row.vlocity_cmt__Status__c!=undefined?row.vlocity_cmt__Status__c:'';
row.iconClass = row.AccessLevel__c =='A01'? '--slds-c-icon-color-background:green;':(row.AccessLevel__c == 'A20' ? '--slds-c-icon-color-background:orange':'--slds-c-icon-color-background:grey') ;
row.status = row.AccessLevel__c =='A01'? 'Full Access':(row.AccessLevel__c == 'A20' ? 'Enquiry Only':'No Status') ;
row.displayIconName='standard:note';
row.highlightRow = this.lstVisitorContactDetail.caseContact!= undefined ? (row.Id == this.lstVisitorContactDetail.caseContact.Id ? 'slds-theme_warning':''):'';
row.IsDeceased = row.IsDeceased__c!=undefined?row.IsDeceased__c:'';
lstContact.push(row);
}
}
this.lstContact =lstContact;
this.boolContact = lstContact.length>0?true:false;
}
if(this.lstVisitorContactDetail.lstBillingAccounts){
let options = [];
for (var billingAccount of this.lstVisitorContactDetail.lstBillingAccounts) {
caseContactDetail.AccountId += (billingAccount.CustomerReferenceNumber__c!=undefined?billingAccount.CustomerReferenceNumber__c:'')+',';
if(billingAccount.vlocity_cmt__PremisesId__c){
options.push({
label: (billingAccount.vlocity_cmt__PremisesId__r.Name +
' (' + (billingAccount.CustomerReferenceNumber__c!=undefined?billingAccount.CustomerReferenceNumber__c:'')
+ ' - ' + (billingAccount.vlocity_cmt__Status__c!=undefined?billingAccount.vlocity_cmt__Status__c:'') + ')'
+ ', ' + (billingAccount.FuelType__c!=undefined?billingAccount.FuelType__c:'')),
value: billingAccount.Id
});
}
this.mapOfBillingAccount.set(billingAccount.Id, billingAccount);
}
this.lstPremises = options;
if(this.lstPremises.length === 1){
this.strBillingAccountId = this.lstPremises[0].value;
this.boolOnePremies = true;
this.showHideFlagsIcon();
this.filterMetering();
this.filterTariff();
this.dynamicMeteringDisplay(this.strBillingAccountId);
this.dynamicPaymentInfoDisplay(this.strBillingAccountId);
}
if(this.lstPremises.length === 0){
this.boolNoPremies = true;
}
}
}
this.boolIsLoading=false;
}
openSearchContact() {
// to open modal set isModalOpen tarck value as true
this.boolIsModalOpen = true;
this.boolIsSearchContact=true;
}
closeModal() {
// to close modal set isModalOpen tarck value as false
this.boolIsModalOpen = false;
this.boolIsSearchContact = false;
this.boolIsContactUpdate = false;
this.boolIsUpdateEmail = false;
this.boolIsFullAccess=false;
this.strSearchText='';
this.strSelectedContactId=undefined;
this.strSearchPlaceHolder='';
this.lstFilterContact=undefined;
this.lstTotalContactRecords=undefined;
this.strSelectedFilterValue = 'ContactName';
this.strDefaultValue='';
}
handleRowSelection = event => {
let selectedRows=event.detail.selectedRows;
this.selectedContactRow = selectedRows[0];
this.strSelectedContactId = this.selectedContactRow.Id;
}
handleSearchInputChange(event){
this.strSearchText = event.target.value;
if(this.strSearchText.length>3){
this.boolIsEnterSearchValue = false;
} else {
this.boolIsEnterSearchValue = true;
}
}
handleSearch() {
this.boolIsLoading = true;
this.lstTotalContactRecords=[];
searchFilterList({ strSearchObject : this.strSelectedFilterValue, strSearchValue : this.strSearchText})
.then((result) => {
this.boolFilter = JSON.parse(JSON.stringify(result)).length>0?true:false;
this.lstTotalContactRecords = JSON.parse(JSON.stringify(result));
})
.catch(error => {
this.strError = error;
console.error(this.strError);
});
this.boolIsLoading = false;
}
updateContactHandler(event){
this.lstFilterContact=[...event.detail.records];
}
handleChangeType(event){
this.strSelectedFilterValue = event.target.value;
}
handleUpdateCaseWithContact(){
this.boolIsLoading = true;
updateCaseWithContact({ strRecordId : this.recordId, strContactId : this.selectedContactRow.Id })
.then((result) => {
this.boolIsLoading = false;
refreshApex( this.lstWireData);
eval("$A.get('e.force:refreshView').fire();");
this.closeModal();
})
.catch(error => {
this.boolIsLoading = false;
this.strError = error.body.message;
});
}
handleSuccess(){
this.boolIsLoading=false;
refreshApex( this.lstWireData);
this.closeModal();
}
handleError(event){
this.boolIsLoading=false;
console.error(event.detail);
}
handleRowAction(event) {
const actionName = event.detail.action.name;
const row = event.detail.row;
this.strDefaultValue=row.AccessLevel__c;
if(actionName == 'editContact'){
this.boolIsFullAccess = (row.AccessLevel__c == 'A01' && row.PrimaryContact__c == false ? true : false);
this.boolIsModalOpen = true;
this.boolIsContactUpdate = true;
this.strSelectedContactId=row.Id;
}
else if (actionName == 'changeEmail'){
this.boolIsFullAccess = row.AccessLevel__c == 'A01' ? true : false;
this.boolIsModalOpen = true;
this.boolIsUpdateEmail = true;
this.strSelectedContactId=row.Id;
}
}
handleSecondaryContact() {
this.boolIsModalOpen = true;
this.boolIsContactUpdate = true;
this.boolIsFullAccess=false;
this.strSelectedContactId='';
this.strDefaultValue = 'A20';
}
handleLoading(){
let isValid = [...this.template.querySelectorAll('lightning-input-field')].reduce( (val, inp) => {
}, true);
if(isValid) {
this.boolIsLoading=true;
}
}
copyToClipBoard() {
const container = this.template.querySelector(".container");
const range = document.createRange();
range.selectNode(container);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
}
changeFullAccess(){
this.template.querySelectorAll('lightning-input-field').forEach(element => {
if(element.fieldName == 'AccessLevel__c'){
this.boolIsFullAccess = element.value == 'A01' ? true : false;
}
});
}
handleChangePremieses(event){
this.strBillingAccountId = event.target.value;
this.showHideFlagsIcon();
this.filterMetering();
this.filterTariff();
this.dynamicMeteringDisplay(this.strBillingAccountId);
this.dynamicPaymentInfoDisplay(this.strBillingAccountId);
}
showHideFlagsIcon(){
var billingAccount = this.mapOfBillingAccount.get(this.strBillingAccountId);
let checkPSR = JSON.parse(JSON.stringify(this.mapFlags)).find(map=>map.key==='PSR');
let checkDebt = JSON.parse(JSON.stringify(this.mapFlags)).find(map=>map.key==='Debt');
if(billingAccount && billingAccount.Debt_Status__c ){
if(this.mapFlags.length==0 ||(this.mapFlags.length>0 && !checkDebt )){
this.mapFlags.push({value:'standard:currency', key:'Debt'});
}
} else if(checkDebt && checkDebt.key === 'Debt'){
this.mapFlags = JSON.parse(JSON.stringify(this.mapFlags)).filter(map=>map.key !=='Debt');
}
if(billingAccount && billingAccount.PriorityServicesRegister__r && billingAccount.PriorityServicesRegister__r.length >0 ){
if(this.mapFlags.length==0 ||(this.mapFlags.length>0 && !checkPSR)){
this.mapFlags.push({value:'standard:partners', key:'PSR'});
}
} else if(checkPSR && checkPSR.key == 'PSR'){
this.mapFlags = JSON.parse(JSON.stringify(this.mapFlags)).filter(map=>map.key !=='PSR');
}
this.boolCheckAnyFlag = this.mapFlags.length > 0 ? true : false;
}
filterMetering(){
this.selectedBillingAccount = this.mapOfBillingAccount.get(this.strBillingAccountId);
// this.strBillingAccountBrand = this.selectedBillingAccount.vlocity_cmt__PremisesId__r.Name + ', Brand - ' + this.selectedBillingAccount.Brand__c;
this.strSmartMeterRefusal = this.selectedBillingAccount.SmartRefuserFlag__c != undefined ? 'Smart Refusal - ' + this.selectedBillingAccount.SmartRefuserFlag__c : '';
this.strSmartMeterRefusalURL = '/lightning/r/Account/'+this.strBillingAccountId+'/view';
let tempRecords = this.selectedBillingAccount.vlocity_cmt__BillingAccountAssets__r!=undefined ? JSON.parse( JSON.stringify( this.selectedBillingAccount.vlocity_cmt__BillingAccountAssets__r) ): undefined;
/* if(tempRecords){
tempRecords = tempRecords.map( row => {
return {...row, consumerAccountName: row.vlocity_cmt__BillingAccountId__r.Parent.Name,
consumerAccountURL : '/lightning/r/Account/'+ row.vlocity_cmt__BillingAccountId__r.ParentId + '/view',
billingAccountName : row.vlocity_cmt__BillingAccountId__r.Name,
billingAccountURL : '/lightning/r/Account/'+ row.vlocity_cmt__BillingAccountId__c + '/view',
billingAccountNumber : row.vlocity_cmt__BillingAccountId__r.CustomerReferenceNumber__c };
})
} */
this.selectedAssets = tempRecords;
}
filterTariff(){
this.selectedBillingAccount = this.mapOfBillingAccount.get(this.strBillingAccountId);
this.latestQuoteRecord = this.selectedBillingAccount.vlocity_cmt__BillingAccountQuotes__r!=undefined ? this.selectedBillingAccount.vlocity_cmt__BillingAccountQuotes__r[0]:undefined;
if(this.latestQuoteRecord){
if( this.latestQuoteRecord.ElectricityUnitPrice__c !== undefined ){
this.strTariffName = this.latestQuoteRecord.Tariff__c;
this.strTariffElectric = 'Electric';
this.strTariffElectricURL = '/lightning/r/Quote/'+this.latestQuoteRecord.Id+'/view';
this.strTariffElectricStartDate = 'Tariff Start Date: ';
this.strTariffElectricEndDate = this.latestQuoteRecord.CurrentTariffEndDate__c != undefined ? 'Tariff End Date: ' + this.latestQuoteRecord.CurrentTariffEndDate__c : 'Tariff End Date: ';
}
if (this.latestQuoteRecord.GasUnitPrice__c !== undefined ){
this.strTariffName = this.latestQuoteRecord.Tariff__c;
this.strTariffGas = 'Gas';
this.strTariffGasURL = '/lightning/r/Quote/'+this.latestQuoteRecord.Id+'/view';
this.strTariffGasStartDate = 'Tariff Start Date: ';
this.strTariffGasEndDate = this.latestQuoteRecord.CurrentTariffEndDate__c != undefined ? 'Tariff End Date: ' + this.latestQuoteRecord.CurrentTariffEndDate__c : 'Tariff End Date: ';
}
this.strTariffRenewalURL = '/lightning/r/Account/'+this.strBillingAccountId+'/related/Opportunities__r/view';
}
}
handleMeterSelection(event) {
if(event.detail.openSections == 'SmartConsent'){
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: this.strBillingAccountId,
objectApiName: 'Account',
actionName: 'view'
},
});
}
}
handleTariffSelection(event) {
/*
if(event.detail.openSections == 'TariffElectric' || event.detail.openSections == 'TariffGas' ){
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: this.latestQuoteRecord.Id,
objectApiName: 'Quote',
actionName: 'view'
},
});
} else
*/
if(event.detail.openSections == 'TariffRenewal'){
this[NavigationMixin.Navigate]({
type: 'standard__recordRelationshipPage',
attributes: {
recordId: this.strBillingAccountId,
relationshipApiName: 'Opportunities__r',
objectApiName: 'Account',
actionName: 'view'
},
});
}
}
/* PSR Flag Buttons*/
PsrButton() {
const scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTo({
top: scrollingElement.scrollHeight,
behavior: 'smooth'
})
}
DebtButton() {
const scrollingElement = (document.scrollingElement || document.body);
scrollingElement.scrollTo({
top: scrollingElement.scrollHeight,
behavior: 'smooth'
})
}
}