3 Replies - 245 Views - Last Post: 19 September 2018 - 11:55 AM

#1 nico123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 16-October 13

MVC- Review the following URL and make sure it is spelled correctly

Posted 19 September 2018 - 10:52 AM

Hi, I get the attached error when I inspect the code that is driving me mad. The problem I have is that when I select "2018" I do not get back anything in this one section of the page(a grid for sales performance YTD; there are two more grids that work just fine) but if I select "2017" I get data(correct data) in the grid. The stored procedure attached to it runs fine in SQL Server when I execute it for both years. The second attachment shows the result I get for for both years: as mentioned, nothing for 2018 and data for 2017. If it would not work I would imagine it would not for both years. Below I am including the code for the model, view and controller, and javascript. For the javascript and controller files I am including only the part concerned. Apologize for the long code but I am trying to include as much details as possible. Any help is highly appreciated. Thank you

MODEL:
namespace FinancialReporting.Areas.mvc.Models.Sales.LeadershipDashboard
{
    public class Sales_SalesTeamPerformanceRow
    {
        public string vcSalesperson { get; set; }
        public decimal dAOP { get; set; }
        public decimal dTotalInvoice { get; set; }
        public decimal dTotalBookings { get; set; }
        public int dTotalOrders { get; set; }
        public decimal dGrossSales { get; set; }
        public decimal dDiscount { get; set; }
        public decimal dNetSales { get; set; }
        public decimal dFullMfgMARGIN { get; set; }
        public decimal DiscountPercent { get; set; }
        public decimal dFMM { get; set; }
    }
}



VIEW:
@model FinancialReporting.Areas.mvc.Models.Sales.LeadershipDashboardViewModel
@{
    ViewBag.Title = "Leadership Dashboard";
}
<div id="leadership-dashboard">
    <div class="row">
        <div class="col-md-12">
            <h2>@ViewBag.Title</h2>
        </div>
    </div>

    @* ********* Drop downs ********* *@
    <div class="row">
        <div class="col-sm-3">
            Year
            <select id="rptYear" name="@Html.NameFor(m => m.Years)" style="width: 100%;"
                data-role="dropdownlist"
                data-bind="value: year.selected, events: { change: year.changed }"
                >
                @foreach (var year in Model.Years)
                {
                    <option>@year</option>
                }
            </select>
        </div>
        <div class="col-sm-3">
            Quarter
            <select id="rptQuarter" name="@Html.NameFor(m => m.Quarters)" style="width: 100%;"
                data-role="dropdownlist"
                data-bind="value: quarter.selected, events: { change: quarter.changed }"
                >
                @foreach (var quarter in Model.Quarters)
                {
                    <option>@quarter</option>
                }
            </select>
        </div>
        <div class="col-sm-3">
            Vertical
            <select id="rptVertical" name="@Html.NameFor(m => m.BusinessTypes)" style="width: 100%"
                data-role="dropdownlist"
                data-bind="value: vertical.selected, events: { change: vertical.changed }"
                >
                @foreach (var type in Model.BusinessTypes)
                {
                    <option value="@type.uidBusinessType">@type.vcBusinessTypeName</option>
                }
            </select>
        </div>
        <div class="col-sm-3">
            Sales Leader
            <select id="rptSalesLeader" style="width: 100%;"
                data-role="dropdownlist"
                data-bind="value: leader.selected, events: { change: leader.changed }">
                @foreach (var manager in Model.SalesManagers)
                {
                    <option value="@manager.uidSalesLeader">@manager.vcManager</option>
                }
            </select>
        </div>
    </div>
    @* ****************************** *@


    @* *********** Charts *********** *@
    <div class="row top10">
        <div class="col-sm-12 col-md-6">
            <div id="salesQTD" class="chart-loading"></div>
        </div>
        <div class="col-sm-12 col-md-6">
            <div id="salesYTD" class="chart-loading"></div>
        </div>
    </div>
    @* ****************************** *@

    @* *********** Details ********** *@
    <div class="row top10">
        <div class="col-sm-12 col-md-6">
            <div id="detailQTD" class="chart-loading" style="width: 100%;"></div>
            <div id="qtd-bookings-summary">
                <h5>QUARTERLY BOOKINGS</h5>
                <div class="stats">
                    <span id="bookingsQTD" class="chart-loading" style="width: 100%; height: 25px;"></span>
                </div>
            </div>
        </div>
        <div class="col-sm-12 col-md-6">
            <div id="detailYTD" class="chart-loading"></div>
            <div id="ytd-bookings-summary">
                <h5>ANNUAL BOOKINGS</h5>
                <div class="stats">
                    <span id="bookingsYTD" class="chart-loading" style="width: 100%; height: 25px;"></span>
                </div>
            </div>
        </div>
    </div>

    <div class="row top10">
        <div class="col-sm-12">
            <h5>SALES PERFORMANCE YTD</h5>
            <div id="salesTeamPerformance" class="chart-loading"></div>
        </div>
    </div>
    @* ****************************** *@

    <div class="row">
        <div class="col-sm-12 col-md-6">
            <div id="industryPie" class="chart-loading"></div>
        </div>
        <div class="col-sm-12 col-md-6">
            <div id="productPie" class="chart-loading"></div>
        </div>
    </div>
</div>

@section scripts {
    @System.Web.Optimization.Scripts.Render("~/bundles/sales-leadership-dashboard")

    @*<script src="@Url.Content("~/Scripts/kendo-view-scripts/Sales/LeadershipDashboard.js")" ></script>*@

    <script type="text/javascript">
        // Add grid URLs to global object (to be used in external js files)
        $.kendoPageUrls.urls({
            Sales_GetInvoiceSummary: '@Url.Action("GetInvoiceSummary", "Sales")',
            Sales_GetIndustrySummary: '@Url.Action("GetIndustrySummary", "Sales")',
            Sales_GetOrderSummary: '@Url.Action("GetOrderSummary", "Sales")',
            Sales_GetProductSummary: '@Url.Action("GetProductSummary", "Sales")',

            Sales_GetInvoiceDetail: '@Url.Action("GetInvoiceDetail", "Sales")',
            Sales_GetSalesTeamData: '@Url.Action("GetSalesTeamData", "Sales")',
        });

        FR.LeadershipDashboard.load();
        //kendo.ui.progress($(".chart-loading"), true);
    </script>
}



CONTROLLER:
namespace FinancialReporting.Areas.mvc.Controllers
{
    [Authorize(Roles = "Admin, SalesReports")]
    //[SessionState(SessionStatebehavior.Disabled)]
    public class SalesController : Controller
    {
        //private static readonly FinancialReportingEntities _context;

        //static SalesController()
        //{
        //    _context = new FinancialReportingEntities();
        //}

        //
        // GET: /mvc/Sales/LeadershipDashboard
        public async Task<ActionResult> LeadershipDashboard()
        {
            LeadershipDashboardViewModel dashboardViewModel = new LeadershipDashboardViewModel();

            // Get business types
            dashboardViewModel.BusinessTypes = await new UtilityController().getBusinessTypes();
            dashboardViewModel.SalesManagers = await new UtilityController().getSalesManagers();

            // Get years for previous 2 and next year as selectable years
            dashboardViewModel.Years = new List<int>();
            dashboardViewModel.Years.Add(DateTime.Now.Year + 1);
            dashboardViewModel.Years.Add(DateTime.Now.Year);
            dashboardViewModel.Years.Add(DateTime.Now.Year - 1);
            dashboardViewModel.Years.Add(DateTime.Now.Year - 2);

            dashboardViewModel.Quarters = new List<int>();
            dashboardViewModel.Quarters.Add(1);
            dashboardViewModel.Quarters.Add(2);
            dashboardViewModel.Quarters.Add(3);
            dashboardViewModel.Quarters.Add(4);

            return View(dashboardViewModel);
        }

        public async Task<ActionResult> SalesPersonDashboard()
        {

            //Set the view Model Type
            var SalesDashboardModel = new SalesPersonDashboardViewModel();

            //Get Sales People
            SalesDashboardModel.SalesPeopleNames = new UtilityController().getSalesPeople(User.Identity.Name);

            //Get Business Types
            SalesDashboardModel.BusinessTypes = await new UtilityController().getBusinessTypeNumbers();

            //Get Business Unites
            SalesDashboardModel.BusinessUnitNames = new UtilityController().getBusinessUnits();

            //Return the View
            return View(SalesDashboardModel);
        }
 [HttpPost]
        public async Task<ActionResult> GetSalesTeamData(int year, int quarter, Guid uidBusinessType, Guid uidSalesLeader)
        {
            using (FinancialReportingEntities context = new FinancialReportingEntities())
            {
                var teamData = await context.Database.SqlQuery<Sales_SalesTeamPerformanceRow>(
                    "p_Report_SalesLeader_SalesTeamPerformance @iRptYear, @iRptQuarter, @uidBusinessType, @uidSalesLeader",
                    new SqlParameter("iRptYear", year),
                    new SqlParameter("iRptQuarter", quarter),
                    new SqlParameter("uidBusinessType", uidBusinessType),
                    new SqlParameter("uidSalesLeader", uidSalesLeader)
                    ).ToListAsync();

                return Json(teamData);
            }
        }



Javascript FILE:
if (typeof FR == 'undefined')
    FR = {};

FR.LeadershipDashboard = function () {
    var leadshipViewModel;
    var dashboardParametersStream = new Rx.Subject();

    var kendoCharts = [];
    var kendoGrids = [];

    function initPage() {
        setupViewModel();

        // Create waterfall charts
        createQtdChart();
        createYtdChart();

        // Create orders gauges
        createQtdGauge();
        createYtdGauge();

        // Create detail grids
        createQtdGrid();
        createYtdGrid();

        // Create Sales Team Performance grid
        createSalesTeamGrid();

        // Create pie charts
        createIndustryPie();
        createProductPie();

        // Subscribe to changes on the parameters stream
        dashboardParametersStream.debounceTime(1000).subscribe(
            function () {
                //// Refresh charts
                //var chart = $("#salesQTD").getKendoChart();
                //chart.dataSource.read();
                ////chart = $("#salesYTD").getKendoChart();
                ////chart.dataSource.read();

                kendo.ui.progress($(".chart-loading"), true);

                kendoCharts.forEach(function (chart) {
                    chart.dataSource.read();
                });

                kendoGrids.forEach(function (grid) {
                    grid.dataSource.read();
                });

                // Recreate gauges
                createQtdGauge();
                createYtdGauge();
            },
            function (e) {
                console.error("Error refreshing dashboard!");
            }
        );
    }

    function setupViewModel() {

        //leadership - dashboard
        leadshipViewModel = kendo.observable({
            year: {
                selected: new Date().getFullYear(),
                changed: function (e) {
                    var yearSelected = this.get('year.selected');
                    console.log(currentParams());
                    this.refreshDashboard();
                }
            },
            quarter: {
                selected: Math.ceil((new Date().getMonth() + 1) / 3),
                changed: function (e) {
                    var quarterSelected = this.get('quarter.selected');
                    console.log(currentParams());
                    this.refreshDashboard();
                }
            },
            vertical: {
                selected: 'f9f61bf1-be39-4e13-b2b4-597524feaa9e',   // set initial selection to Injection, because Injection
                changed: function (e) {
                    var verticalSelected = this.get('vertical.selected');
                    console.log(currentParams());
                    this.refreshDashboard();
                }
            },
            leader: {
                selected: '46a95426-66f7-e511-9f78-5207580696bd',   // set initial selection to Bob Strickly (alphabetically first)
                changed: function (e) {
                    var leaderSelected = this.get('leader.selected');
                    console.log(currentParams());
                    this.refreshDashboard();
                }
            },

            // functions
            refreshDashboard: function () {
                // Set hfm charts and customer charts as busy
                kendo.ui.progress($(".chart-loading"), true);

                dashboardParametersStream.next();
            }
        });

        kendo.bind($("#leadership-dashboard"), leadshipViewModel);
    }
function createSalesTeamGrid() {
        var salesTeamDataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    type: "POST",
                    url: $.kendoPageUrls.url.Sales_GetSalesTeamData,
                    contentType: "application/json",
                    dataType: 'json',
                    data: ytdParams
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read") {
                        return kendo.stringify(options.models || [options]);
                    }
                    else
                        return kendo.stringify(options.models || options);
                }
            },
            schema: {
                model: {
                    fields: {
                        vcSalesperson: { type: "string" },
                        dAOP: { type: "number" },
                        dTotalInvoice: { type: "number" },
                        dTotalBookings: { type: "number" },
                        dTotalOrders: { type: "number" },
                        dGrossSales: { type: "number" },
                        dDiscount: { type: "number" },
                        dNetSales: { type: "number" },
                        dFullMfgMARGIN: { type: "number" },
                        DiscountPercent: { type: "number" },
                        dFMM: { type: "number" },
                    }
                }
            },
            requestEnd: function (e) {
                // Start the progress indicator
                kendo.ui.progress($("#salesTeamPerformance"), false);
            }
        });

        var salesTeamGrid = $('#salesTeamPerformance').kendoGrid({
            toolbar: ["excel"],
            excel: {
                fileName: "SalesTeam.xlsx",
                allPages: true
            },
            dataSource: salesTeamDataSource,
            scrollable: false,
            columns: [
                {
                    field: "vcSalesperson",
                    title: "Salesperson"
                },
                {
                    field: "dAOP",
                    title: "AOP",
                    //format: "{0:C0}",
                    template: "#= kendo.toString(dAOP / 1000, 'c0') #",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dTotalInvoice",
                    title: "Total Invoice",
                    //format: "{0:C0}",
                    template: "#= kendo.toString(dTotalInvoice / 1000, 'c0') #",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dTotalBookings",
                    title: "Total Bookings",
                    //format: "{0:C0}",
                    template: "#= kendo.toString(dTotalBookings / 1000, 'c0') #",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dTotalOrders",
                    title: "Total Orders",
                    format: "{0:n0}",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dGrossSales",
                    title: "Gross Sales",
                    //format: "{0:C0}",
                    template: "#= kendo.toString(dGrossSales / 1000, 'c0') #",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dDiscount",
                    title: "Discount",
                    //format: "{0:C0}",
                    template: "#= kendo.toString(dDiscount / 1000, 'c0') #",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dNetSales",
                    title: "Net Sales",
                    //format: "{0:C0}",
                    template: "#= kendo.toString(dNetSales / 1000, 'c0') #",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dFullMfgMARGIN",
                    title: "Full Mfg Margin",
                    //format: "{0:C0}",
                    template: "#= kendo.toString(dFullMfgMARGIN / 1000, 'c0') #",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "DiscountPercent",
                    title: "Discount %",
                    format: "{0:P2}",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
                {
                    field: "dFMM",
                    title: "Full Mfg Margin %",
                    format: "{0:P2}",
                    attributes: {
                        style: "text-align: right;"
                    }
                },
            ]
        }).data().kendoGrid;

        kendoGrids.push(salesTeamGrid);
    }
function currentParams() {
        return {
            year: leadshipViewModel.get('year.selected'),
            quarter: leadshipViewModel.get('quarter.selected'),
            uidBusinessType: leadshipViewModel.get('vertical.selected'),
            uidSalesLeader: leadshipViewModel.get('leader.selected')
        }
    }

    function ytdParams() {
        return {
            year: leadshipViewModel.get('year.selected'),
            quarter: 5,
            uidBusinessType: leadshipViewModel.get('vertical.selected'),
            uidSalesLeader: leadshipViewModel.get('leader.selected')
        }
    }

    return {
        load: initPage,
        currentParams: currentParams
    }
}();




Please help. Thank you in advance

Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: MVC- Review the following URL and make sure it is spelled correctly

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15077
  • View blog
  • Posts: 60,210
  • Joined: 12-June 08

Re: MVC- Review the following URL and make sure it is spelled correctly

Posted 19 September 2018 - 11:07 AM

I would put a breakpoint here:

var teamData = await context.Database.SqlQuery<Sales_SalesTeamPerformanceRow>(


and see what sort of data you are getting out. Maybe something null is having an issue with converting to json.

It may help to throw a try/catch around there to see what the exception is.
Was This Post Helpful? 1
  • +
  • -

#3 nico123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 16-October 13

Re: MVC- Review the following URL and make sure it is spelled correctly

Posted 19 September 2018 - 11:47 AM

View Postmodi123_1, on 19 September 2018 - 11:07 AM, said:

I would put a breakpoint here:

var teamData = await context.Database.SqlQuery<Sales_SalesTeamPerformanceRow>(


and see what sort of data you are getting out. Maybe something null is having an issue with converting to json.

It may help to throw a try/catch around there to see what the exception is.


Thank you so much!!! It was because I was getting some null values from the stored procedure. I am so happy I wrote on this forum. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15077
  • View blog
  • Posts: 60,210
  • Joined: 12-June 08

Re: MVC- Review the following URL and make sure it is spelled correctly

Posted 19 September 2018 - 11:54 AM

No problem. I may have been there a few times in my life. ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1