PipelineByManufacturerWidget = function( widgetOptions ) { let defaultShowCases = true; let defaultShowLbs = true; let defaultShowDollars = true; let defaultShowCommission = false; let defaultShowOpportunities = false; if( Fse.Portal.appConfiguration.STP.ownerType === "BRO" ) { defaultShowCases = true; defaultShowLbs = false; defaultShowDollars = false; defaultShowCommission = false; } let configDefaults = { showCases : defaultShowCases, showLbs : defaultShowLbs, showDollars : defaultShowDollars, showCommission : defaultShowCommission, showOpportunities : defaultShowOpportunities, topCount : 10, effectiveRepId : null, territoryPath : null, uom : "cases", typeCode : null } if( Fse.Portal.appConfiguration.STP.ownerType === "MFR" ) { configDefaults.budgetCategoryId = null; } if( Fse.Portal.appConfiguration.STP.ownerType !== "MFR" ) { configDefaults.mfr_id = null; } this.widgetOptions = widgetOptions; this.widgetOptions.config = $.extend( true, {}, configDefaults, this.widgetOptions.config ); this.dataGrid = null; // this.preferencesPopup = null; this.activeFilterPreferences = {}; this.init(); } PipelineByManufacturerWidget.prototype.constructor = PipelineByManufacturerWidget; PipelineByManufacturerWidget.prototype.element = function() { return this.dataGrid.element(); } PipelineByManufacturerWidget.prototype.init = function() { let widget = this; // create a copy of the config to use for the datasource creationg (scrum 46030) let configForDataSource = $.extend( true, {}, widget.widgetOptions.config ); // begin apply filter preferences (scrum 46030) // global filters suppored by this widget, when the global filters are expressed with different variable names, they need to translated to this widgets variable names const globalFilters = { // widgetVariableName : "globalFilterVariableName" effectiveRepId : "salesRepId", mfr_id : "mfr_id", territoryPath : "territoryPath", budgetCategoryId : "budgetCategoryId", }; for( let p in globalFilters ) { // apply translation - global filter param is not the same name as widget param let gp = globalFilters[p]; // if the global filter preferences have the propery and it has a value, update the objectparams if( widget.widgetOptions.filterPreferences.hasOwnProperty( gp ) && widget.widgetOptions.filterPreferences[gp]) { if( configForDataSource[p] == null ) { configForDataSource[p] = widget.widgetOptions.filterPreferences[gp]; widget.activeFilterPreferences[p] = configForDataSource[p]; // indicate that this widget parameter has an active filter preference - used when displaying the edit page } } } // end apply filter preferences (scrum 46030) let objectParams = { territoryPath : configForDataSource.territoryPath, effectiveRepId : configForDataSource.effectiveRepId, uom : configForDataSource.uom, typeCode : configForDataSource.typeCode, topCount : configForDataSource.topCount } if( Fse.Portal.appConfiguration.STP.ownerType === "MFR" ) { objectParams.budgetCategoryId = configForDataSource.budgetCategoryId; } if( Fse.Portal.appConfiguration.STP.ownerType !== "MFR" ) { objectParams.mfr_id = configForDataSource.mfr_id; } let dataSource = Fse.Data.newDataSource( { object : "SPL.pipelineByManufacturer", objectParams : objectParams } ); widget.dataGrid = $("
").dxDataGrid( { dataSource: dataSource, columns : [ { dataField : "mfr_name", caption : "Manufacturer", showInColumnChooser : false }, { dataField : "cases", dataType : "number", format : { type : "fixedPoint", precision : 0 }, visible : widget.widgetOptions.config.showCases }, { dataField : "lbs", dataType : "number", format : { type : "fixedPoint", precision : 0 }, visible : widget.widgetOptions.config.showLbs}, { dataField : "dollars", dataType : "number", format : "currency", visible : widget.widgetOptions.config.showDollars }, { dataField : "commission", caption : "Commission", dataType : "number", format : "currency", visible : widget.widgetOptions.config.showCommission }, { dataField : "opportunities", caption : "Opportunities", dataType : "number", format : { type : "fixedPoint", precision : 0 }, visible : widget.widgetOptions.config.showOpportunities } ], onContextMenuPreparing : function( e ) { if( e.target != "content" ) { return; } if( widget.widgetOptions.dashboard.hasTab( "OpportunityAnalyzer" )) { if( ! e.items ) { e.items = []; } e.items.push( { text : "Goto Opportunity Analyzer", onItemClick : function( ee ) { let searchParams = { pastDue : "N", statusCode : "A", mfr_id : e.row.data.mfr_id, territoryPath : objectParams.territoryPath, typeCode : objectParams.typeCode, effectiveRepId : objectParams.effectiveRepId, } if( widget.widgetOptions.config.budgetCategoryId ) { searchParams.budgetCategoryId = objectParams.budgetCategoryId } if( widget.widgetOptions.config.mfr_id ) { searchParams.mfr_id = objectParams.mfr_id } widget.widgetOptions.dashboard.tabSearch( "OpportunityAnalyzer", searchParams ) } }) } } }).dxDataGrid( "instance" ); } PipelineByManufacturerWidget.prototype.edit = function( applyFn ) { if( ! this.widgetPreferencesEditor ) { this.widgetPreferencesEditor = new PipelineWidgetPreferenceEditor( this, { budgetCategoryId : false, showCommission : true, showOpportunities : true } ); } this.widgetPreferencesEditor.show( applyFn ); } Fse.Portal.addWidgetFactory( "PipelineByManufacturerWidget", function( widgetDef ) { return new PipelineByManufacturerWidget( widgetDef ); })