DistributorPortfolio = function() { let instance = this; this.rootElement = null; this.distributorList = null; this.listRefreshNeeded = false; this.operations = DistributorPortfolio.distributorPortfolioPermissions(); DistributorPortfolio._distributorPortfolioInstance = this; Fse.CRM.addViewProfileHandler( { viewProfile : function( profileURL ) { let urlParams = Fse.Util.getURLParams( profileURL ); if( ! urlParams.app || urlParams.app != 'CDR.portfolio' ) { return false; } let distributorId = 0; if( urlParams.cdr_recordId ) { distributorId = urlParams.cdr_recordId } else if ( urlParams.partnerId && urlParams.partnerType == "CDR" ) { distributorId = urlParams.partnerId; } else if ( urlParams.distributorId ) { distributorId = urlParams.distributorId } else if ( urlParams.includeMyAccountsOnly && instance.distributorList ) { instance.distributorList.search( { includeMyAccountsOnly : true }); return true; } else { return false; } if( distributorId > 0 ) { let tabId = urlParams.tab; if( tabId ) { const validTabs = { "detail" : "detail", "contact" : "contact", "purchasing" : "purchasing", "interactions" : "interactions", "units" : "units", "members" : "members", "opportunities" : "opportunities", "objectives" : "objectives", "trade" : "trade", "bids" : "bids", "notes" : "notes", "files" : "files", // legacy tab translations "dtl" : "detail", "cntct" : "contact", "pp" : "purchasing", "inits" : "interactions", "tpm" : "trade", "affiliates" : "members" } if( validTabs[tabId] ) { tabId = validTabs[tabId]; } else { tabId = null; // null to use current tab or detail tab } } DistributorPortfolio.getDistributorDetails( distributorId ).done( function( data ) { instance.gotoProfile( data ); }) return true; } return false; }}) } DistributorPortfolio.distributorPortfolioPermissions = function( ){ const DistributorManagementAdd = Fse.Portal.checkPermission( "DistributorManagementAdd" ) const distributorManagementEdit = Fse.Portal.checkPermission( "DistributorManagementEdit" ) const distributorClassifcationChange = Fse.Portal.checkPermission( "DistributorAcctClassChange" ) const distributorAcctPriorityChange = Fse.Portal.checkPermission( "DistributorAcctPriorityChange" ) const distributorAcctSalesRepChange = Fse.Portal.checkPermission( "DistributorAcctSalesRepChange" ) const distributorAcctTerritoryChange = Fse.Portal.checkPermission( "DistributorAcctTerritoryChange" ) //convert portal setting to boolean const editAddrSettingString = Fse.Portal.appConfiguration["102"].distributorAddressEdit === "true" ? true : false; const editCompanyNameSettingString = Fse.Portal.appConfiguration["102"].distributorNameEdit === "true" ? true : false; let operations = { allowCreate : DistributorManagementAdd, allowDelete : DistributorManagementAdd, editAccountManagement : distributorManagementEdit, editCompanyName : distributorManagementEdit && editCompanyNameSettingString, editAddressInformation : distributorManagementEdit && editAddrSettingString, // distributorManagementEdit == false ? false : editAddrSettingString, editClassification : distributorClassifcationChange, editPriority : distributorAcctPriorityChange, editSalesRep : distributorAcctSalesRepChange, editSalesTerritory : distributorAcctTerritoryChange, editPrimaryContact : distributorManagementEdit, } return operations; } DistributorPortfolio.getHandler = function() { var oLink = document.getElementById( "cdrHandlerLink" ); return oLink.getAttribute( "href" ); }; DistributorPortfolio.openDistributorSummaryPDF = function( currentDistributor ){ let ownerType = Fse.Portal.appConfiguration.STP.ownerType; let reportCode = ownerType == "MFR" ? "distributorBusinessReview" : "stockingReport"; let distributorId = currentDistributor.cdr_recordId; let territoryId = currentDistributor.cdr_territoryid; if ( ownerType == "MFR"){ Fse.Portal.showReportCenter( { applicationCode : "102", reportCode : reportCode, params : { rpt_ter_opt : territoryId, rpt_cdr_opt : distributorId } }) } if ( ownerType == "BRO"){ let pdfURL = Fse.Util.updateURL2( DistributorPortfolio.getHandler(), { cdr_recordid : distributorId, ajax : "reportCenter", rc_report : reportCode, rc_format : "PDF" }) Fse.Portal.showReportCenter(pdfURL ) ; } } DistributorPortfolio.showDistributorProfileDialog = function( nDistributorId ) { let sURL = Fse.Util.updateURL( DistributorPortfolio.getHandler() + "?get=distributorProfileDialog&mode=direct", { distributorId : nDistributorId } ); let oOptions = { title : "Distributor Profile Quick View", width : "500px", src : sURL }; Fse.DialogManager.show( "distributorProfileDialog$", oOptions ); } DistributorPortfolio.getDistributorDetails = function( distributorId ) { let d = $.Deferred(); let distributorDataStore = Fse.Data.newDataSource( { object : "CDR.distributorDetails", paginate : false, keyField : "cdr_recordId", objectParams : { cdr_recordId : distributorId } }).store(); distributorDataStore.byKey( distributorId ).done( function( data ) { if( data ) { d.resolve( data ) } else { d.resolve( null ); } }) return d; } DistributorPortfolio.showDeleteDistributorDialog = function ( distributorId, distributorTk, onSuccess ) { let checkDeleteDataSource = Fse.Data.newDataSource( { object : "CDR.checkDistributorDelete", paginate : false, keyField : "distributorId", objectParams : { cdr_recordId : distributorId } }); checkDeleteDataSource.load().done( function( checkDelete ) { if( Array.isArray( checkDelete ) ) { checkDelete = checkDelete[0]; } DistributorPortfolio.getDistributorDetails( distributorId ).done( function( distributorData ) { let actionButton = null; let popup = null; let deleteForm = null; if( checkDelete.allowDelete ) { actionButton = $("
").html( `You are about to DELETE the following ${getText( 'DISTRIBUTOR' ).toLowerCase()} from the ${getText( 'DISTRIBUTOR' )} Portfolio:` )); let distributorElement = $("
").html( html )); } }, { label : { text : "Deleted By" }, dataField : "deletedBy", editorOptions : { readOnly : true } }, { label : { text : "Reason" }, dataField : "deleteReason", isRequired : true, editorType : "dxSelectBox", editorOptions : { items : [ "Duplicate", "No longer in business", "Low volume", "Not my Account", "Not within market range", "Other" ] } }, { label : { text : "Details" }, dataField : "deleteDetails", isRequired : true, editorType : "dxTextArea", editorOptions : { maxLength : 200 } } ] }).dxForm( "instance" ); content.append( deleteForm.element() ); } else { if( checkDelete.dependencies.length ) { content.append( $("
" ).html( `This ${getText( 'DISTRIBUTOR' )} cannot be deleted because it has the following dependents:` ).css( { "font-weight" : "bold" } ) ); $("
").addClass( "fse-alert" );
restrictionsElement.append( "You can not delete this distributor because there are " );
for( x = 0; x < checkDelete.restrictions.length; x++ ) {
if( x > 0 ) {
if( x == checkDelete.restrictions.length - 1 ) {
restrictionsElement.append( " and ")
} else {
restrictionsElement.append( ", " );
}
}
restrictionsElement.append( checkDelete.restrictions[x] )
}
restrictionsElement.append( "." );
restrictionsElement.append( $("
") );
restrictionsElement.append( "Click the Cancel button to close this dialog box.")
content.append( restrictionsElement );
}
}
return content;
},
toolbarItems : [
{ toolbar : "bottom", location : "after",
template : function() {
return actionButton.element();
}
}
],
onHidden : function( e ) {
e.component.element().remove();
e.component.dispose();
}
}).appendTo( "body" ).dxPopup("instance");
popup.show();
})
})
}
DistributorPortfolio.prototype.constructor = DistributorPortfolio;
DistributorPortfolio.prototype.element = function() {
let instance = this;
if( instance.multiView ) {
return instance.multiView.element();
}
instance.multiView = $("
").text( callOptions.message ).appendTo( content ); } dataGrid = $("