Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
88 kB
1
Indexable
Never
import { LightningElement, api, track, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import isLargeSmeUser from '@salesforce/customPermission/CEP_Large_Sme_Permission';
import isSmallBusinessUser from '@salesforce/customPermission/CEP_Small_Business_Permission';
import isAgencyReseller from '@salesforce/customPermission/CEP_CP_AgencyReseller';
import isLargeAema from '@salesforce/customPermission/CEP_Large_Aema_Permission';
import isUmbriaEnergy from '@salesforce/customPermission/CEP_isUmbriaEnergy';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getRemiCode from "@salesforce/apex/CEP_LC_DedicatedProcessWizard.callEbdm";
import getPreviousTraderName from "@salesforce/apex/CEP_LC_DedicatedProcessWizard.getPreviousTraderName";
import { error } from 'c/notificationSvc';
import { usoEleMatrice } from "c/cepTakeOverWizardRes";
import isD2DTeleselling from '@salesforce/customPermission/CEP_isD2DTeleselling';
import isWind3 from '@salesforce/customPermission/NTT_isWind3';
import IsAcea  from '@salesforce/customPermission/NTT_isAcea';


export default class CepSwitchingWinFieldProvider extends LightningElement {
    consumptionCodeFields;
    additionalTechnicalFields;
    imposteFields;
    switchingFields;
    energyServiceFields;
    remiFields;
    changeProductData;
    specifichePaFields;
    wind3 = isWind3;
    acea = IsAcea;


    @api opportunity;
    @api opportunityServiceItem;
    @api contestablePod;
    @api servicePoint;
    @api account;
    @api atecoObject;
    @api contractType;
    @api distributor;
    @api distributorName;
    @api isDistributorLogicheCampiUso;
    @api commodity;
    @api process;
    @api pod;
    @api channel;
    @track isGas;
    @track distNameOptionList;
    @track remiCodeOptionList;
    @track remiCodeMatrice;
    @track previousTraderName= '';
    @track isListino = false;
    @track usoEle = usoEleMatrice();
    @track isSegmentReseller = false;
    @track today;
    @track signatureDate;
    @track isMassMarket = false;
    @track accountRecordType;
    @track isSwitching;
    @track isChangeProduct;
    @api isRinovoRemiDirette;


    connectedCallback() {
        this.wind3 = this.wind3 ? true : false; 
        this.acea = this.acea ? true: false;
        let accountFields = this.account?.fields;
        this.segment = accountFields?.Segment__c?.value;
        this.isMassMarket = this.segment?.toUpperCase() === 'MASS MARKET';
        this.isGas = this.commodity && this.commodity.toLowerCase().includes('gas');
        this.today = new Date();
        this.signatureDate = this.opportunity?.fields?.SignatureDate__c?.value?.substring(0, 10);
        console.log('data firma: '+this.signatureDate);
        this.isChangeProduct = this.process && (this.process.toLowerCase() == "cambio prodotto" || this.process.toLowerCase() == "cambio prodotto cross brand");
        this.isModificaTipologiaPDR = this.process && this.process.toLowerCase().includes('modifica tipologia');
        this.isSwitching = this.process && this.process.toLowerCase() == "switching win";
        
        if(this.account.Segment__c == 'Mass Market'){
            this.isSegmentReseller = false;
            this.isMassMarket = true;
            this.accountRecordType = this.account.RecordTypeDeveloperName__c;
        }
        else if(this.segment == 'Reseller' || isAgencyReseller || isUmbriaEnergy){
            this.isSegmentReseller = true;
            this.accountRecordType = this.account.fields.RecordTypeDeveloperName__c.value;
        }
        console.log('reseller: '+this.isSegmentReseller);
        if (this.opportunityServiceItem && this.isGas)
            this.retriveRemiCode();
        else {
            console.log("OSIII conncted callback acc" + JSON.stringify(this.opportunityServiceItem));
                this.initializeFields();

        }
        console.log('process: '+this.process);
        console.log('isChangeProduct: '+this.isChangeProduct);
        console.log('isSwitching: '+this.isSwitching);
        console.log('isModificaTipologiaPDR: '+this.isModificaTipologiaPDR);
    }

    initializeFields() {
        var newDate = new Date();
        this.dateValue = newDate.toISOString();
        this.isGas = this.commodity && this.commodity.toLowerCase().includes('gas');

        /* Check if Opportunity Request type is Listino and set the flag */
        if(this.opportunity !== undefined) {
            if(this.opportunity.fields.RequestType__c.value == 'A Listino') {            
                this.isListino = true;
            }
        }

        if (this.process && this.process !== '' && this.commodity && this.commodity !== '') {
            this.consumptionCodeFields = [
                {
                    name: 'Consumer__c',
                    label: 'Consumatore',
                    visible: true,
                    value: this.isChangeProduct && !this.isMassMarket ? (this.contractType && (this.contractType.toLowerCase() == 'ditta individuale' || this.contractType.toLowerCase() == 'persona fisica')) && this.getValue('Usage__c') == 'Domestico' ? 'SI' : 'NO' : this.getValue('Consumer__c') ? this.getValue('Consumer__c') : this.accountRecordType == 'CEP_RT_Organization' ? 'NO' : '',
                    valid: false,
                    required: true,
                    disabled: this.isChangeProduct && !this.isMassMarket ? true : this.accountRecordType == 'CEP_RT_Organization',
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'Consumer__c'
                        }
                    }
                },
                {
                    name: 'RightToRethink__c',
                    label: 'Diritto al ripensamento',
                    visible: true,
                    value: this.isChangeProduct && !this.isMassMarket ? 'NO' : this.getValue('RightToRethink__c') ? this.getValue('RightToRethink__c') : this.accountRecordType == 'CEP_RT_Organization' ? 'NO' : '',
                    valid: false,
                    required: true,
                    disabled: this.isChangeProduct && !this.isMassMarket,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'RightToRethink__c'
                        }
                    }
                },
                {
                    name: 'ImmediateActivation__c',
                    label: 'Attivazione immediata',
                    visible: true,
                    value: this.isChangeProduct && !this.isMassMarket ? 'SI' : this.getValue('ImmediateActivation__c') ? this.getValue('ImmediateActivation__c') : this.accountRecordType == 'CEP_RT_Organization' ? 'SI' : '',
                    valid: false,
                    required: true,
                    disabled: this.isChangeProduct && !this.isMassMarket ? true : this.accountRecordType == 'CEP_RT_Organization' ? true : false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'ImmediateActivation__c'
                        }
                    }
                }

            ];

            this.changeProductData = [
                {
                    name: 'EffectiveDate__c',
                    label: 'Data decorrenza',
                    visible: this.isChangeProduct,
                    value: this.getValue('EffectiveDate__c') ? this.getValue('EffectiveDate__c') : this.opportunity?.fields?.SupplyStartDate__c?.value ? this.opportunity?.fields?.SupplyStartDate__c?.value : '',
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'date',
                        typeAttributes: {
                            minDate: this.opportunity?.fields?.SupplyStartDate__c?.value ? this.opportunity.fields.SupplyStartDate__c.value : '',
                            maxDate: this.opportunity?.fields?.SupplyEndDate__c?.value ? this.opportunity.fields.SupplyEndDate__c.value : ''
                        }
                    }
                },
                {
                    name: 'DailyConsumption__c',
                    label: 'Capacità Giornaliera',
                    visible: this.isGas && (this.channel === 'Vendita SME-TOP'),
                    value: this.getValue('DailyConsumption__c') ? this.getValue('DailyConsumption__c') : this.getValue(null,'DailyConsumption__c') ? this.getValue(null,'DailyConsumption__c') : '',
                    valid: true,
                    required: this.opportunity?.fields?.Rate__c?.value ? this.opportunity.fields.Rate__c.value  === 'Binomia' : false,
                    disabled: false,
                    type: {
                        type: 'text',
                    }
                }
            ];
            //NTT W3
            if(this.wind3 && !this.acea)
            {
                if(this.isGas)
                {
                    this.additionalTechnicalFields = [
                        {
                            name: 'AtecoDescription__c',
                            label: 'Ateco',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isSegmentReseller && !this.isModificaTipologiaPDR,
                            value: this.getValue('AtecoDescription__c') ? this.getValue('AtecoDescription__c') : this.atecoObject && this.atecoObject.Description__c ? this.atecoObject.Description__c : this.contractType == 'Persona fisica' ? '' : '',
                            valid: true,
                            required: (!this.atecoObject && this.contractType !== 'Persona fisica') || this.atecoObject?.required,
                            // disabled: (this.atecoObject || (!this.atecoObject && this.contractType == 'Persona fisica') || isD2DTeleselling) && this.isMassMarket,
                            disabled: this.isMassMarket,
                            size: 8,
                            type: {
                                type: 'text'
                            }
                        },
                        {
                            name: 'searchAteco',
                            label: 'Seleziona Ateco',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isSegmentReseller && !this.isModificaTipologiaPDR,
                            value: 'button',
                            disabled: (this.atecoObject || (!this.atecoObject && this.contractType == 'Persona fisica')) && this.isMassMarket,
                            type: {
                                type: 'button'
                            }
                        },
                        //RIGO UNO
                        {
                            name: 'Residence__c',
                            label: 'Residenza',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR,
                            value: this.getValue('Residence__c') ? this.getValue('Residence__c') : this.isMassMarket && this.account.RecordTypeDeveloperName__c && this.account.RecordTypeDeveloperName__c == 'CEP_RT_Organization' ? 'NO' : !this.isMassMarket && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione' ? 'NO' : '',
                            valid: false,
                            required: true,
                            disabled: this.isChangeProduct || (this.isMassMarket && this.account.RecordTypeDeveloperName__c && this.account.RecordTypeDeveloperName__c == 'CEP_RT_Organization') || (!this.isMassMarket && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione'),
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'Residence__c'
                                }
                            }
                        },
                        /*{  
                            name : 'PreviousTraderVATNumber__c', 
                            label : 'Trader Uscente', 
                            visible : this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR, 
                            value : this.getValue('PreviousTraderName__c'),
                            valid : false, 
                            required : !this.isGas && this.account.Segment__c == 'Mass Market',
                            disabled : false,
                            type : {
                                type: 'text'
                            }
                        },*/
                        {
                            name: 'ServicePointCode__c',
                            label: 'Codice PDR',
                            visible: this.isGas,
                            value: this.getValue(null, 'Code__c') ? this.getValue(null, 'Code__c') : this.pod,
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'text',
        
                            }
                        },
                        {
                            visible: true,
                            /*value: '',
                            valid: true,
                            required: false,
                            disabled: true,*/
                            type: {
                                type: 'hidden',

                            }
                        },
                        //RIGO DUE
                        {
                            name: 'PDRType__c',
                            label: 'Tipo PDR',
                            visible: this.isGas,
                            value: this.getValue('PDRType__c') ? this.getValue('PDRType__c') : (this.isChangeProduct || this.isModificaTipologiaPDR) ? this.getValue(null, 'PDRType__c') : '',
                            valid: false,
                            required: true,
                            disabled: this.isChangeProduct || this.isModificaTipologiaPDR,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'PDRType__c'
                                }
                            }
                        },
                        {
                            name: 'ResidentialFlag__c',
                            label: 'Flag Residenziale',
                            visible: !this.isMassMarket && this.isSwitching && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione',
                            value: this.getValue('ResidentialFlag__c') ? 'SI' : 'NO',
                            valid: false,
                            required: false,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    options: [{label : 'SI', value : 'SI'}, {label : 'NO', value : 'NO'}]
                                }
                            }
                        },
                        
                        {
                            name: 'TISGUseType__c',
                            label: 'Tipologia d\'uso TISG',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('TISGUseType__c') ? this.getValue('TISGUseType__c') : '',
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'TISGUseType__c'
                                }
                            }
                        },
                        {
                            name: 'MeterSerialNumber__c',
                            label: 'Matricola Misuratore',
                            visible: this.isGas && !this.isModificaTipologiaPDR,
                            value: this.wind3 ? '111111111' : (this.getValue('MeterSerialNumber__c') ? this.getValue('MeterSerialNumber__c') : ''),
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'text',
                                typeAttributes: {
                                    maxLength: '20'
                                }
                            }
                        },     
                        //RIGO TRE                   
                        {
                            name: 'ExpectedAnnualWithdrawal__c',
                            label: 'Prelievo annuo previsto',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('ExpectedAnnualWithdrawal__c') ? this.getValue('ExpectedAnnualWithdrawal__c') : '',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'number',
                                typeAttributes: {
                                    max: 1000000000,
                                    min: 1
                                }
        
                            }
                        },
                        {
                            name: 'TakingClass__c',
                            label: 'Classe Prelievo',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('TakingClass__c') ? this.getValue('TakingClass__c') : '',
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'TakingClass__c'
                                }
                            }
                        },
                        {
                            name: 'AutomotiveUsage__c',
                            label: 'Uso autotrazione',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('AutomotiveUsage__c') ? this.getValue('AutomotiveUsage__c') : 'NO',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'AutomotiveUsage__c'
                                }
                            }
                        },
                        //QUARTO RIGO
                        {
                            name: 'searchPreviousTrader',
                            label: 'Seleziona Trader Uscente',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR,
                            value: 'button',
                            required: false,
                            disabled: false,
                            type: {
                                type: 'button'
                            }
                        },
                        {
                            name: 'UsageCategory__c',
                            label: 'Uso',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('UsageCategory__c') ? this.getValue('UsageCategory__c') : '',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'UsageCategory__c'
                                }
                            }
                        },
                        {
                            name: 'RequestedUsageCategory__c',
                            label: 'Categoria d\'Uso',
                            visible: this.isGas,
                            value: this.getValue('RequestedUsageCategory__c') ? this.getValue('RequestedUsageCategory__c') : this.getValue(null,'Usage__c'),
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'RequestedUsageCategory__c'
                                }
                            }
                        },
                        {
                            name: 'ConnectionContractSelfDeclaration__c',
                            label: 'Autocertificazione Contratto Connessione',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isGas,
                            value: this.getValue('ConnectionContractSelfDeclaration__c') ? this.getValue('ConnectionContractSelfDeclaration__c') : 'Procura',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'ConnectionContractSelfDeclaration__c'
                                }
                            }
                        },
                        {
                            name: 'Extraterritorial_Service_Point__c',
                            label: 'POD Extraterritoriale',
                            visible:  this.isSegmentReseller || isSmallBusinessUser,
                            value: this.getValue('Extraterritorial_Service_Point__c') == 'SI' ? 'SI' : 'NO',
                            valid: false,
                            required: true,
                            disabled: this.isChangeProduct,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    options: [{label : 'SI', value : 'SI'}, {label : 'NO', value : 'NO'}]
                                }
                            }
                        },
                        {
                            name: 'PDRRequesttype__c',
                            label: 'Tipo PDR Richiesto',
                            visible: this.isGas && this.isModificaTipologiaPDR,
                            value: this.getValue('PDRRequesttype__c') ? this.getValue('PDRRequesttype__c') : '',
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'PDRRequesttype__c'
                                }
                            }
                        },
                    ];
                }
                else
                //this.isEle
                {
                    this.additionalTechnicalFields = [
                        {
                            name: 'AtecoDescription__c',
                            label: 'Ateco',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isSegmentReseller && !this.isModificaTipologiaPDR,
                            value: this.getValue('AtecoDescription__c') ? this.getValue('AtecoDescription__c') : this.atecoObject && this.atecoObject.Description__c ? this.atecoObject.Description__c : this.contractType == 'Persona fisica' ? '' : '',
                            valid: true,
                            required: (!this.atecoObject && this.contractType !== 'Persona fisica') || this.atecoObject?.required,
                            // disabled: (this.atecoObject || (!this.atecoObject && this.contractType == 'Persona fisica') || isD2DTeleselling) && this.isMassMarket,
                            disabled: this.isMassMarket,
                            size: 8,
                            type: {
                                type: 'text'
                            }
                        },
                        {
                            name: 'searchAteco',
                            label: 'Seleziona Ateco',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isSegmentReseller && !this.isModificaTipologiaPDR,
                            value: 'button',
                            disabled: (this.atecoObject || (!this.atecoObject && this.contractType == 'Persona fisica')) && this.isMassMarket,
                            type: {
                                type: 'button'
                            }
                        },
                        {
                            name: 'ServicePointCode__c',
                            label: 'Codice Pod',
                            visible: !this.isGas,
                            value: this.getValue(null, null, 'PodCode__c') ? this.getValue(null, null, 'PodCode__c') : this.getValue(null, 'Code__c') ? this.getValue(null, 'Code__c') : this.pod,
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'text'
                            }
                        },
                        {
                            name: 'ServicePointCode__c',
                            label: 'Codice PDR',
                            visible: this.isGas,
                            value: this.getValue(null, 'Code__c') ? this.getValue(null, 'Code__c') : this.pod,
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'text',
        
                            }
                        },
                        {
                            name: 'DistributorName__c',
                            label: 'Distributore',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isGas,
                            value: this.distributor ? this.distributor : this.distributorName ? this.distributorName : this.getValue('DistributorName__c'),
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'text'
                            }
                        },
        

                        {
                            name: 'ConnectionContractSelfDeclaration__c',
                            label: 'Autocertificazione Contratto Connessione',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isGas,
                            value: this.getValue('ConnectionContractSelfDeclaration__c') ? this.getValue('ConnectionContractSelfDeclaration__c') : 'Procura',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'ConnectionContractSelfDeclaration__c'
                                }
                            }
                        },
                        {
                            name: 'Extraterritorial_Service_Point__c',
                            label: 'POD Extraterritoriale',
                            visible:  this.isSegmentReseller || isSmallBusinessUser,
                            value: this.getValue('Extraterritorial_Service_Point__c') == 'SI' ? 'SI' : 'NO',
                            valid: false,
                            required: true,
                            disabled: this.isChangeProduct,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    options: [{label : 'SI', value : 'SI'}, {label : 'NO', value : 'NO'}]
                                }
                            }
                        },
                        {
                            name: 'searchPreviousTrader',
                            label: 'Seleziona Trader Uscente',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR,
                            value: 'button',
                            required: false,
                            disabled: false,
                            type: {
                                type: 'button'
                            }
                        },
                        {
                            name: 'Residence__c',
                            label: 'Residenza',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR,
                            value: this.getValue('Residence__c') ? this.getValue('Residence__c') : this.isMassMarket && this.account.RecordTypeDeveloperName__c && this.account.RecordTypeDeveloperName__c == 'CEP_RT_Organization' ? 'NO' : !this.isMassMarket && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione' ? 'NO' : '',
                            valid: false,
                            required: true,
                            disabled: this.isChangeProduct || (this.isMassMarket && this.account.RecordTypeDeveloperName__c && this.account.RecordTypeDeveloperName__c == 'CEP_RT_Organization') || (!this.isMassMarket && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione'),
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'Residence__c'
                                }
                            }
                        },
                        {
                            visible: true,
                            /*value: '',
                            valid: true,
                            required: false,
                            disabled: true,*/
                            type: {
                                type: 'hidden',

                            }
                        },
                        /*{  
                            name : 'PreviousTraderVATNumber__c', 
                            label : 'Trader Uscente', 
                            visible : this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR, 
                            value : this.getValue('PreviousTraderName__c'),
                            valid : false, 
                            required : !this.isGas && this.account.Segment__c == 'Mass Market',
                            disabled : false,
                            type : {
                                type: 'text'
                            }
                        },*/
                        {
                            name: 'ResidentialFlag__c',
                            label: 'Flag Residenziale',
                            visible: !this.isMassMarket && this.isSwitching && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione',
                            value: this.getValue('ResidentialFlag__c') ? 'SI' : 'NO',
                            valid: false,
                            required: false,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    options: [{label : 'SI', value : 'SI'}, {label : 'NO', value : 'NO'}]
                                }
                            }
                        },
                        {
                            name: 'PDRType__c',
                            label: 'Tipo PDR',
                            visible: this.isGas,
                            value: this.getValue('PDRType__c') ? this.getValue('PDRType__c') : (this.isChangeProduct || this.isModificaTipologiaPDR) ? this.getValue(null, 'PDRType__c') : '',
                            valid: false,
                            required: true,
                            disabled: this.isChangeProduct || this.isModificaTipologiaPDR,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'PDRType__c'
                                }
                            }
                        },
                        {
                            name: 'PDRRequesttype__c',
                            label: 'Tipo PDR Richiesto',
                            visible: this.isGas && this.isModificaTipologiaPDR,
                            value: this.getValue('PDRRequesttype__c') ? this.getValue('PDRRequesttype__c') : '',
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'PDRRequesttype__c'
                                }
                            }
                        },
                        {
                            name: 'TISGUseType__c',
                            label: 'Tipologia d\'uso TISG',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('TISGUseType__c') ? this.getValue('TISGUseType__c') : '',
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'TISGUseType__c'
                                }
                            }
                        },
                        {
                            name: 'TakingClass__c',
                            label: 'Classe Prelievo',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('TakingClass__c') ? this.getValue('TakingClass__c') : '',
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'TakingClass__c'
                                }
                            }
                        },
                        {
                            name: 'AutomotiveUsage__c',
                            label: 'Uso autotrazione',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('AutomotiveUsage__c') ? this.getValue('AutomotiveUsage__c') : 'NO',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'AutomotiveUsage__c'
                                }
                            }
                        },
                        {
                            name: 'MeterSerialNumber__c',
                            label: 'Matricola Misuratore',
                            visible: this.isGas && !this.isModificaTipologiaPDR,
                            value: this.wind3 ? '111111111' : (this.getValue('MeterSerialNumber__c') ? this.getValue('MeterSerialNumber__c') : ''),
                            valid: false,
                            required: true,
                            disabled: false,
                            type: {
                                type: 'text',
                                typeAttributes: {
                                    maxLength: '20'
                                }
                            }
                        },
                        {
                            name: 'UsageCategory__c',
                            label: 'Uso',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('UsageCategory__c') ? this.getValue('UsageCategory__c') : '',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'UsageCategory__c'
                                }
                            }
                        },
                        {
                            name: 'ExpectedAnnualWithdrawal__c',
                            label: 'Prelievo annuo previsto',
                            visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                            value: this.getValue('ExpectedAnnualWithdrawal__c') ? this.getValue('ExpectedAnnualWithdrawal__c') : '',
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'number',
                                typeAttributes: {
                                    max: 1000000000,
                                    min: 1
                                }
        
                            }
                        },
                        {
                            name: 'RequestedUsageCategory__c',
                            label: 'Categoria d\'Uso',
                            visible: this.isGas,
                            value: this.getValue('RequestedUsageCategory__c') ? this.getValue('RequestedUsageCategory__c') : this.getValue(null,'Usage__c'),
                            valid: false,
                            required: true,
                            disabled: true,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    objectName: 'OpportunityServiceItem__c',
                                    fieldName: 'RequestedUsageCategory__c'
                                }
                            }
                        },
                        {
                            name: 'RequestedIndustrialSector__c',
                            label: 'Settore Industriale',
                            visible: this.isChangeProduct && !this.isGas,
                            value: this.opportunityServiceItem && this.opportunityServiceItem.RequestedIndustrialSector__c ? this.opportunityServiceItem.RequestedIndustrialSector__c : this.getValue(null,"IndustrialSector__c"),                
                            valid: true,
                            required: true,
                            disabled: this.isChangeProduct,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    options: [
                                        this.opportunityServiceItem && this.opportunityServiceItem.RequestedIndustrialSector__c ? { label: this.opportunityServiceItem.RequestedIndustrialSector__c, value: this.opportunityServiceItem.RequestedIndustrialSector__c } : this.getValue(null, "IndustrialSector__c") ? { label: this.getValue(null,"IndustrialSector__c"), value: this.getValue(null, "IndustrialSector__c") } : {},
                                    ]
                                }
                            }
                        },
                        {
                            name: 'Usage__c',
                            label: 'Categoria d\'Uso',
                            visible: this.isChangeProduct && !this.isGas,
                            value : this.opportunityServiceItem && this.opportunityServiceItem.Usage__c ? this.opportunityServiceItem.Usage__c : this.getValue(null, "Usage__c"),
                            valid: true,
                            required: true,
                            disabled: this.isChangeProduct || this.isModificaTipologiaPDR,
                            type: {
                                type: 'picklist',
                                typeAttributes: {
                                    options: this.usoEle
                                }
                            }
                        },
                    ]
                }
            }
            else
            //NON OnlyW3
            this.additionalTechnicalFields = [
                {
                    name: 'AtecoDescription__c',
                    label: 'Ateco',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isSegmentReseller && !this.isModificaTipologiaPDR,
                    value: this.getValue('AtecoDescription__c') ? this.getValue('AtecoDescription__c') : this.atecoObject && this.atecoObject.Description__c ? this.atecoObject.Description__c : this.contractType == 'Persona fisica' ? '' : '',
                    valid: true,
                    required: (!this.atecoObject && this.contractType !== 'Persona fisica') || this.atecoObject?.required,
                    // disabled: (this.atecoObject || (!this.atecoObject && this.contractType == 'Persona fisica') || isD2DTeleselling) && this.isMassMarket,
                    disabled: this.isMassMarket,
                    size: 8,
                    type: {
                        type: 'text'
                    }
                },
                {
                    name: 'searchAteco',
                    label: 'Seleziona Ateco',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isSegmentReseller && !this.isModificaTipologiaPDR,
                    value: 'button',
                    disabled: (this.atecoObject || (!this.atecoObject && this.contractType == 'Persona fisica')) && this.isMassMarket,
                    type: {
                        type: 'button'
                    }
                },
                {
                    name: 'ServicePointCode__c',
                    label: 'Codice Pod',
                    visible: !this.isGas,
                    value: this.getValue(null, null, 'PodCode__c') ? this.getValue(null, null, 'PodCode__c') : this.getValue(null, 'Code__c') ? this.getValue(null, 'Code__c') : this.pod,
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'text'
                    }
                },
                {
                    name: 'ServicePointCode__c',
                    label: 'Codice PDR',
                    visible: this.isGas,
                    value: this.getValue(null, 'Code__c') ? this.getValue(null, 'Code__c') : this.pod,
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'text',

                    }
                },
                {
                    name: 'DistributorName__c',
                    label: 'Distributore',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isGas,
                    value: this.distributor ? this.distributor : this.distributorName ? this.distributorName : this.getValue('DistributorName__c'),
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'text'
                    }
                },

                {
                    name: 'ConnectionContractSelfDeclaration__c',
                    label: 'Autocertificazione Contratto Connessione',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isGas,
                    value: this.getValue('ConnectionContractSelfDeclaration__c') ? this.getValue('ConnectionContractSelfDeclaration__c') : 'Procura',
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'ConnectionContractSelfDeclaration__c'
                        }
                    }
                },
                {
                    name: 'Extraterritorial_Service_Point__c',
                    label: 'POD Extraterritoriale',
                    visible:  this.isSegmentReseller || isSmallBusinessUser,
                    value: this.getValue('Extraterritorial_Service_Point__c') == 'SI' ? 'SI' : 'NO',
                    valid: false,
                    required: true,
                    disabled: this.isChangeProduct,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            options: [{label : 'SI', value : 'SI'}, {label : 'NO', value : 'NO'}]
                        }
                    }
                },
                {  
                    name : 'PreviousTraderVATNumber__c', 
                    label : 'Trader Uscente', 
                    visible : this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR, 
                    value : this.getValue('PreviousTraderName__c'),
                    valid : false, 
                    required : !this.isGas && this.account.Segment__c == 'Mass Market',
                    disabled : false,
                    type : {
                        type: 'text'
                    }
                },
                {
                    name: 'searchPreviousTrader',
                    label: 'Seleziona Trader Uscente',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR,
                    value: 'button',
                    required: false,
                    disabled: false,
                    type: {
                        type: 'button'
                    }
                },
                {
                    name: 'Residence__c',
                    label: 'Residenza',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : !this.isModificaTipologiaPDR,
                    value: this.getValue('Residence__c') ? this.getValue('Residence__c') : this.isMassMarket && this.account.RecordTypeDeveloperName__c && this.account.RecordTypeDeveloperName__c == 'CEP_RT_Organization' ? 'NO' : !this.isMassMarket && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione' ? 'NO' : '',
                    valid: false,
                    required: true,
                    disabled: this.isChangeProduct || (this.isMassMarket && this.account.RecordTypeDeveloperName__c && this.account.RecordTypeDeveloperName__c == 'CEP_RT_Organization') || (!this.isMassMarket && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione'),
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'Residence__c'
                        }
                    }
                },
                {
                    name: 'ResidentialFlag__c',
                    label: 'Flag Residenziale',
                    visible: !this.isMassMarket && this.isSwitching && this.account.fields.Type.value && this.account.fields.Type.value == 'Organizzazione',
                    value: this.getValue('ResidentialFlag__c') ? 'SI' : 'NO',
                    valid: false,
                    required: false,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            options: [{label : 'SI', value : 'SI'}, {label : 'NO', value : 'NO'}]
                        }
                    }
                },
                {
                    name: 'PDRType__c',
                    label: 'Tipo PDR',
                    visible: this.isGas,
                    value: this.getValue('PDRType__c') ? this.getValue('PDRType__c') : (this.isChangeProduct || this.isModificaTipologiaPDR) ? this.getValue(null, 'PDRType__c') : '',
                    valid: false,
                    required: true,
                    disabled: this.isChangeProduct || this.isModificaTipologiaPDR,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'PDRType__c'
                        }
                    }
                },
                {
                    name: 'PDRRequesttype__c',
                    label: 'Tipo PDR Richiesto',
                    visible: this.isGas && this.isModificaTipologiaPDR,
                    value: this.getValue('PDRRequesttype__c') ? this.getValue('PDRRequesttype__c') : '',
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'PDRRequesttype__c'
                        }
                    }
                },
                {
                    name: 'TISGUseType__c',
                    label: 'Tipologia d\'uso TISG',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                    value: this.getValue('TISGUseType__c') ? this.getValue('TISGUseType__c') : '',
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'TISGUseType__c'
                        }
                    }
                },
                {
                    name: 'TakingClass__c',
                    label: 'Classe Prelievo',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                    value: this.getValue('TakingClass__c') ? this.getValue('TakingClass__c') : '',
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'TakingClass__c'
                        }
                    }
                },
                {
                    name: 'AutomotiveUsage__c',
                    label: 'Uso autotrazione',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                    value: this.getValue('AutomotiveUsage__c') ? this.getValue('AutomotiveUsage__c') : 'NO',
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'AutomotiveUsage__c'
                        }
                    }
                },
                {
                    name: 'MeterSerialNumber__c',
                    label: 'Matricola Misuratore',
                    visible: this.isGas && !this.isModificaTipologiaPDR,
                    value: this.wind3 ? '111111111' : (this.getValue('MeterSerialNumber__c') ? this.getValue('MeterSerialNumber__c') : ''),
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'text',
                        typeAttributes: {
                            maxLength: '20'
                        }
                    }
                },
                {
                    name: 'UsageCategory__c',
                    label: 'Uso',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                    value: this.getValue('UsageCategory__c') ? this.getValue('UsageCategory__c') : '',
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'UsageCategory__c'
                        }
                    }
                },
                {
                    name: 'ExpectedAnnualWithdrawal__c',
                    label: 'Prelievo annuo previsto',
                    visible: this.process.toLowerCase()=='cambio prodotto cross brand' ? false : (this.isGas && !this.isModificaTipologiaPDR),
                    value: this.getValue('ExpectedAnnualWithdrawal__c') ? this.getValue('ExpectedAnnualWithdrawal__c') : '',
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'number',
                        typeAttributes: {
                            max: 1000000000,
                            min: 1
                        }

                    }
                },
                {
                    name: 'RequestedUsageCategory__c',
                    label: 'Categoria d\'Uso',
                    visible: this.isGas,
                    value: this.getValue('RequestedUsageCategory__c') ? this.getValue('RequestedUsageCategory__c') : this.getValue(null,'Usage__c'),
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'RequestedUsageCategory__c'
                        }
                    }
                },
                {
                    name: 'RequestedIndustrialSector__c',
                    label: 'Settore Industriale',
                    visible: this.isChangeProduct && !this.isGas,
                    value: this.opportunityServiceItem && this.opportunityServiceItem.RequestedIndustrialSector__c ? this.opportunityServiceItem.RequestedIndustrialSector__c : this.getValue(null,"IndustrialSector__c"),                
                    valid: true,
                    required: true,
                    disabled: this.isChangeProduct,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            options: [
                                this.opportunityServiceItem && this.opportunityServiceItem.RequestedIndustrialSector__c ? { label: this.opportunityServiceItem.RequestedIndustrialSector__c, value: this.opportunityServiceItem.RequestedIndustrialSector__c } : this.getValue(null, "IndustrialSector__c") ? { label: this.getValue(null,"IndustrialSector__c"), value: this.getValue(null, "IndustrialSector__c") } : {},
                            ]
                        }
                    }
                },
                {
                    name: 'Usage__c',
                    label: 'Categoria d\'Uso',
                    visible: this.isChangeProduct && !this.isGas,
                    value : this.opportunityServiceItem && this.opportunityServiceItem.Usage__c ? this.opportunityServiceItem.Usage__c : this.getValue(null, "Usage__c"),
                    valid: true,
                    required: true,
                    disabled: this.isChangeProduct || this.isModificaTipologiaPDR,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            options: this.usoEle
                        }
                    }
                },
            ];
            
            this.switchingFields = [
                {
                    name: 'EffectiveDate__c',
                    label: 'Data decorrenza',
                    visible: isLargeSmeUser || isSmallBusinessUser || isLargeAema || this.isSegmentReseller,
                    value: this.getValue('EffectiveDate__c') ? this.getValue('EffectiveDate__c') : '',
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'date',
                        typeAttributes: {
                            minDate: this.opportunity?.fields?.SupplyStartDate__c?.value ? this.opportunity.fields.SupplyStartDate__c.value : '',
                            maxDate: this.opportunity?.fields?.SupplyEndDate__c?.value ? this.opportunity.fields.SupplyEndDate__c.value : ''
                        }
                    }
                },
                {
                    name: 'ContractDate__c',
                    label: 'Data contratto',
                    visible: isLargeSmeUser || isSmallBusinessUser || isLargeAema || this.isSegmentReseller,
                    value: this.getValue('ContractDate__c') ? this.getValue('ContractDate__c') : (!this.isSegmentReseller ? this.signatureDate : ''),
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'date',
                        typeAttributes: {
                            maxDate: this.today
                        }
                    }
                },
                {
                    name: 'SwitchInframonth__c',
                    label: 'Switch Inframese',
                    visible: !this.isGas && (isLargeSmeUser || isSmallBusinessUser || isLargeAema || this.isSegmentReseller),
                    value: this.getValue('SwitchInframonth__c') == 'SI' ? 'SI' : 'NO',
                    valid: false,
                    required: false,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'SwitchInframonth__c'
                        }
                    }
                },
                {
                    name: 'SwitchEarlyWithdrawal__c',
                    label: 'Switch Recesso anticipato',
                    visible: this.isGas && !this.isListino && (isLargeSmeUser || isSmallBusinessUser || isLargeAema || this.isSegmentReseller),
                    value: this.getValue('SwitchEarlyWithdrawal__c') == 'SI' ? 'SI' : 'NO',
                    valid: false,
                    required: false,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'SwitchEarlyWithdrawal__c'
                        }
                    }
                },
                {
                    name: 'SwitchSkipPreCheck__c',
                    label: 'Switch Skip Pre-check',
                    visible: !this.isGas && !this.isListino && !this.isSegmentReseller && (isLargeSmeUser || isSmallBusinessUser || isLargeAema),
                    value: this.getValue('SwitchSkipPreCheck__c') == 'SI' ? 'SI' : 'NO',
                    valid: false,
                    required: false,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'SwitchSkipPreCheck__c'
                        }
                    }
                },
                {
                    name: 'TIMOERevocation__c',
                    label: 'Revoca TIMOE',
                    visible: !this.isGas,
                    value: (this.getValue('TIMOERevocation__c') == 'NO' || isLargeAema) ? 'NO' : 'SI',
                    valid: false,
                    required: true,
                    disabled: !isLargeSmeUser && !isSmallBusinessUser && !isLargeAema && ! this.isSegmentReseller,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'TIMOERevocation__c'
                        }
                    }
                },
                {
                    name: 'TIMGTIVGRevocation__c',
                    label: 'Revoca TIMG/TIVG',
                    visible: this.isGas,
                    value: (this.getValue('TIMGTIVGRevocation__c') == 'NO' || isLargeAema) ? 'NO' : 'SI',
                    valid: false,
                    required: true,
                    disabled: !isLargeSmeUser && !isSmallBusinessUser && !isLargeAema && ! this.isSegmentReseller,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'TIMGTIVGRevocation__c'
                        }
                    }
                },
                {
                    name: 'CreditAcquisition__c',
                    label: 'Acquisto credito',
                    visible: true,
                    value: (this.getValue('CreditAcquisition__c') || isLargeAema) ? 'SI' : 'NO',
                    valid: false,
                    required: true,
                    disabled: !isLargeSmeUser && !isSmallBusinessUser && !isLargeAema && !this.isSegmentReseller,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            options: [{label : 'SI', value : 'SI'}, {label : 'NO', value : 'NO'}]
                        }
                    }
                },
                {
                    name: 'DispatchingContractCode__c',
                    label: 'Codice contratto dispacciamento',
                    visible: !this.isGas,
                    value: this.getValue('Extraterritorial_Service_Point__c') == 'SI' ? 'DP1706' : 'DP1005',
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'text',
                        typeAttributes: {
                            maxLength: '6'
                        }
                    }
                },
                {
                    name: 'CommercialDirectorSwitchApprover__c',
                    label: 'Direttore Commerciale Approvatore',
                    visible: false,
                    value: this.getValue('CommercialDirectorSwitchApprover__c') ? this.getValue('CommercialDirectorSwitchApprover__c') : '',
                    valid: false,
                    required: false,
                    disabled: false,
                    type: {
                        type: 'text'
                    }
                },
                {
                    name : 'Status__c',
                    label : 'Status',
                    visible : false,
                    value : this.getValue('Status__c') ? this.getValue('Status__c') : '',
                    valid : false, 
                    required : false, 
                    disabled : false, 
                    type : {
                        type : 'text'
                    }
                },
                {
                    name: 'DailyConsumption__c',
                    label: 'Capacità Giornaliera',
                    visible: this.isGas && (this.channel === 'Vendita SME-TOP'),
                    value: this.getValue('DailyConsumption__c') ? this.getValue('DailyConsumption__c') : this.getValue(null,'DailyConsumption__c') ? this.getValue(null,'DailyConsumption__c') : '',
                    valid: true,
                    required: this.opportunity?.fields?.Rate__c?.value ? this.opportunity.fields.Rate__c.value  === 'Binomia' : false,
                    disabled: false,
                    type: {
                        type: 'text',
                    }
                }
            ];
            this.energyServiceFields = [
                {
                    name: 'SupplyEnergyService__c',
                    label: 'Erogazione Servizio Energetico',
                    visible: this.isGas,
                    value: this.wind3 ? 'NO' : (this.getValue('SupplyEnergyService__c') ? this.getValue('SupplyEnergyService__c') : 'NO'),
                    valid: false,
                    required: true,
                    disabled: false,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'SupplyEnergyService__c'
                        }
                    }
                },
                {
                    name: 'BeneficiaryAccount__c',
                    label: 'Beneficiario',
                    visible: this.isGas,
                    value: this.getValue('BeneficiaryAccount__c'),
                    valid: false,
                    required: false,
                    disabled: true,
                    type: {
                        type: 'text' /*'lookup' ,
                        typeAttributes : {
                            objectName : 'Account',
                            fieldNames : { primaryField : 'Name', subField1 : 'FiscalCode__c' }
                        }*/
                    }
                },
                {
                    name: 'BeneficiaryAccount',
                    label: 'Seleziona Account',
                    visible: this.isGas,
                    value: 'button',
                    required: false,
                    disabled: true,
                    type: {
                        type: 'button'
                    }
                }

            ]
            this.remiFields = [
                {
                    name: 'DistributorName__c',
                    label: 'Nome distributore',
                    visible: this.isGas,
                    value: this.getValue('DistributorName__c'),
                    valid: false,
                    required: false,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'DistributorName__c',
                            options: this.getValue('DistributorName__c') ? this.distNameOptionList ? this.distNameOptionList : [{ label: this.getValue('DistributorName__c'), value: this.getValue('DistributorName__c') }] : []
                        }
                    }
                },
                {
                    name: 'REMICode__c',
                    label: 'Codice Remi',
                    visible: this.isGas,
                    value: this.getValue('REMICode__c'),
                    valid: false,
                    required: false,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldNames: 'REMICode__c',
                            options: this.getValue('REMICode__c') ? this.remiCodeOptionList ? this.remiCodeOptionList : [{ label: this.getValue('REMICode__c'), value: this.getValue('REMICode__c') }] : []
                        }
                    }
                }
            ];
            this.specifichePaFields = [
                {
                    name: 'IPA__c',
                    label: 'Codice IPA',
                    visible: true,
                    value: this.getValue('IPA__c') ? this.getValue('IPA__c') : this.getValue(null,'IPA__c') ? this.getValue(null,'IPA__c') : '',
                    valid: false,
                    required: !this.isMassMarket ? this.account.fields.BusinessType__c.value == 'Pubblica amministrazione' : '',
                    disabled: false,
                    type: {
                        type: 'text',
                    }
                }, 
                {
                    name: 'CIG__c',
                    label: 'CIG',
                    visible: true,
                    value: this.getValue('CIG__c') ? this.getValue('CIG__c') : this.getValue(null,'CIG__c') ? this.getValue(null,'CIG__c') : '',
                    valid: false,
                    required: false,
                    disabled: false,
                    type: {
                        type: 'text',
                    }
                },
                {
                    name: 'CUP__c',
                    label: 'CUP',
                    visible: true,
                    value: this.getValue('CUP__c') ? this.getValue('CUP__c') : this.getValue(null,'CUP__c') ? this.getValue(null,'CUP__c') : '',
                    valid: false,
                    required: false,
                    disabled: false,
                    type: {
                        type: 'text',
                    }
                },
                {
                    name: 'CostCenter__c',
                    label: 'Centro di Costo',
                    visible: true,
                    value: this.getValue('CostCenter__c'),
                    valid: false,
                    required: !this.isMassMarket ? this.account.fields.BusinessType__c.value == 'Gruppo acea' : '',
                    disabled: false,
                    type: {
                        type: 'text',
                    }
                },
            ];
            this.imposteFields = [
                {
                    name: 'VATTreatment__c',
                    label: 'Aliquota Iva',
                    visible: true,
                    value: this.getValue('VATTreatment__c') ? this.getValue('VATTreatment__c') : this.getValue(null,null,null,null,'VATTreatment__c') ? this.getValue(null,null,null,null,'VATTreatment__c') : '',
                    valid: false,
                    required: true,
                    disabled: !this.isModificaTipologiaPDR,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            options: []
                        }
                    }
                },
                {
                    name: 'Excise__c',
                    label: 'Accisa',
                    visible: this.isGas && !this.isChangeProduct,
                    value: this.getValue('Excise__c') ? this.getValue('Excise__c') : this.getValue(null,'Excise__c') ? this.getValue(null,'Excise__c') : '',
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'Excise__c'
                        }
                    }
                },
                {
                    name: 'RegionalAdition__c',
                    label: 'Addizionale Regionale',
                    visible: this.isGas && !this.isChangeProduct && !this.isModificaTipologiaPDR,
                    value: this.getValue('RegionalAdition__c') ? this.getValue('RegionalAdition__c') : this.getValue(null,'RegionalAdition__c') ? this.getValue(null,'RegionalAdition__c') : '',
                    valid: false,
                    required: true,
                    disabled: true,
                    type: {
                        type: 'picklist',
                        typeAttributes: {
                            objectName: 'OpportunityServiceItem__c',
                            fieldName: 'RegionalAdition__c'
                        }
                    }
                }
            ];
            this.throwFieldInitializedEvent()
        }
    }

    throwFieldInitializedEvent() {
        this.dispatchEvent(new CustomEvent('fieldsinit', {
            detail: this.getForms()
        }));
    }

    getValue(osiField, servicePointField, contestablePodField, expectedReturnType, assetField) {

        var result;
        if (!this.opportunityServiceItem && this.isChangeProduct) {
            if (osiField == 'Residence__c')
                result = this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value ? (this.servicePoint.fields['CurrentAsset__r'].value.fields['ResidentialFlag__c'].value ? 'SI' : 'NO') : '';
            if (osiField == "RequestedIndustrialSector__c")
                result = this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['RequestedIndustrialSector__c'].value : '';
        }
        if(assetField){
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields[assetField].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields[assetField].value : '' : '';
        }

        if(servicePointField == 'IPA__c')
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value && this.servicePoint.fields['CurrentAsset__r'].value.fields['IPA__c'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['IPA__c'].value : '';
        if(servicePointField == 'CIG__c')
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value && this.servicePoint.fields['CurrentAsset__r'].value.fields['CIG__c'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['CIG__c'].value : '';
        if(servicePointField == 'CUP__c')
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value && this.servicePoint.fields['CurrentAsset__r'].value.fields['CUP__c'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['CUP__c'].value : '';
        if(servicePointField == 'VATTreatment__c')
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value && this.servicePoint.fields['CurrentAsset__r'].value.fields['VATTreatment__c'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['VATTreatment__c'].value : '';
        if(servicePointField == 'Excise__c')
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value && this.servicePoint.fields['CurrentAsset__r'].value.fields['Excise__c'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['Excise__c'].value : '';
        if(servicePointField == 'RegionalAdition__c')
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value && this.servicePoint.fields['CurrentAsset__r'].value.fields['RegionalAdition__c'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['RegionalAdition__c'].value : '';
        if(servicePointField == 'DailyConsumption__c')
            result = this.servicePoint && this.servicePoint.fields['CurrentAsset__r'] && this.servicePoint.fields['CurrentAsset__r'].value && this.servicePoint.fields['CurrentAsset__r'].value.fields['DailyConsumption__c'].value ? this.servicePoint.fields['CurrentAsset__r'].value.fields['DailyConsumption__c'].value : '';
        
        if (this.opportunityServiceItem
            && this.opportunityServiceItem[osiField]) {

            console.log(osiField + ' -- Value returned = ' + this.opportunityServiceItem[osiField]);

            result = this.opportunityServiceItem[osiField];
        }
        else if (this.servicePoint
            && this.servicePoint.fields
            && this.servicePoint.fields[servicePointField]) {

            console.log(servicePointField + ' -- Value returned = ' + this.servicePoint.fields[servicePointField].value);
            result = this.servicePoint.fields[servicePointField].value;
        }
        else if (this.contestablePod
            && this.contestablePod.fields
            && this.contestablePod.fields[contestablePodField]) {
            result = this.contestablePod.fields[contestablePodField].value;
        }

        if (result) {
            if (expectedReturnType === 'number') {
                return parseInt(result);
            }
            else if (expectedReturnType === 'float') {
                return parseFloat(result);
            }
            else if (expectedReturnType === 'boolean') {
                return result == 'true';
            }
            else {
                if (typeof result === 'string') {
                    return result;
                }

                return JSON.stringify(result)
            }
        }
    }

    getForms() {
        let formObj = {
            'consumptionCodeFields': this.consumptionCodeFields,
            'additionalTechnicalFields': this.additionalTechnicalFields,
            'imposteFields': this.imposteFields,
            'switchingFields': this.switchingFields,
            'energyServiceFields': this.energyServiceFields,
            'remiFields': this.remiFields,
            'specifichePaFields' : this.specifichePaFields,
            'changeProductData' : this.changeProductData
        }
        return formObj;
    }


    retriveRemiCode() {
        let istat = this.opportunityServiceItem.PointIstatCode__c;
        if (istat && istat !== '') {
            this.activateSpinner(true);
            getRemiCode({ istatCode: istat }).then(response => {
                if (response) {
                    if (Object.keys(response.distRemicode).length === 0) {
                        this.showToastMessage('Recupero Distributore', 'Non è presente alcun distributore per l \'ISTAT selezionato', 'warning');
                        this.initializeFields();
                    }
                    else {
                        this.distNameOptionList = [];
                        this.remiCodeMatrice = [];
                        for (let key in response.distRemicode) {
                            console.log('key : ' + key + '  Map value: ', response.distRemicode[key]);
                            this.distNameOptionList.push({ label: key, value: key });

                            for (let i in response.distRemicode[key]) {
                                console.log('key1 : ' + i + '  Map value:1 ', response.distRemicode[key][i]);

                                this.remiCodeMatrice.push({ distributore: key, remiCodeValue: response.distRemicode[key][i] })
                            }
                        }
                        this.manageRemiCodePicklist(this.opportunityServiceItem.DistributorName__c);
                    }
                    this.activateSpinner(false);
                }
                else {
                    this.activateSpinner(false);
                    this.showToastMessage('Recupero Distributore', 'Errore tecnico: impossibile recuperare i dati', 'error');
                    this.initializeFields();
                }
            }).catch((errorMsg) => {
                error(this, JSON.stringify(errorMsg.body.message));
                this.initializeFields();
                this.activateSpinner(false);
            });
        }
        else {
            this.activateSpinner(false);
            this.initializeFields();

        }
    }

    manageRemiCodePicklist(value) {
        this.remiCodeOptionList = [];
        this.remiCodeMatrice.forEach(element => {
            if (element.distributore.includes(value)) {
                this.remiCodeOptionList.push({ label: element.remiCodeValue, value: element.remiCodeValue })
            }
        });
        this.initializeFields();
        this.activateSpinner(false);
    }

    activateSpinner(active) {
        this.dispatchEvent(new CustomEvent('spinner', {
            detail: { 'active': active }
        }));
    }

    showToastMessage(title, message, variant) {
        this.dispatchEvent(
            new ShowToastEvent({
                title: title,
                message: message,
                variant: variant,
            }),
        );
    }

    // getPreviousTraderValue(field) {
    //     getPreviousTraderName({ Piva: this.opportunityServiceItem[field] }).then(response => {
    //         if (response.name) {
    //             this.previousTraderName = response.name;
    //             this.initializeFields();
    //         }
    //     }).catch((errorMsg) => {
    //         error(this, JSON.stringify(errorMsg));
    //         this.initializeFields();
    //     });
    // }

}