Exemplo n.º 1
0
        private dynamic GetDataByType(string NTSType, int?cad)
        {
            int _year = cad == null? 0:(int)cad;
            List <StrawmanDBLibray.Entities.WRK_NTS_VIEW_DATA>      data  = (List <StrawmanDBLibray.Entities.WRK_NTS_VIEW_DATA>)GetSessionData(NTSTables.WRK_NTS_VIEW_DATA);
            List <StrawmanDBLibray.Entities.v_WRK_FRANCHISE_MASTER> mster = (List <StrawmanDBLibray.Entities.v_WRK_FRANCHISE_MASTER>)Helpers.StrawmanDBLibrayData.Get(StrawmanDBLibray.Classes.StrawmanDataTables.v_WRK_FRANCHISE_MASTER, true);
            var q = data.Where(m => m.YEAR_PERIOD == Helpers.PeriodUtil.Year - _year && m.MONTH_PERIOD == Helpers.PeriodUtil.Month && m.BRAND < 9000 && m.MARKET < 9000 && m.TYPE == NTSType).AsEnumerable()
                    .Join(mster.Where(m => m.TYPE == Classes.StrawmanViews.MARKET).AsEnumerable()
                          , d => new { _channel = d.CHANNEL, _market = d.MARKET, _brand = d.BRAND }, m => new { _channel = m.CHANNEL, _market = m.MARKET, _brand = (decimal?)m.BRAND }, (d, m) => new { d = d, m = m })
                    .AsEnumerable()
                    .Select(p => new Models.MarketViewChannelModels {
                col1 = (decimal?)p.d.AMOUNT * p.m.CFG, col2 = 0, col3 = 0, col4 = 0, col5 = 0, col6 = 0, vid = (decimal)p.m.FRANCHISE_ID, vparent = p.m.PARENT_ID
            })
                    .AsEnumerable();
            var fdata = new MarketViewFranchiseController().GetFormatedData(q, Classes.StrawmanColumns.NTS);

            //List<StrawmanDBLibray.Entities.v_WRK_NTS_DATA_FRANCHISE> data = (List<StrawmanDBLibray.Entities.v_WRK_NTS_DATA_FRANCHISE>)GetSessionData(NTSTables.v_WRK_NTS_DATA_FRANCHISE);
            return(fdata
                   .Select(p => new Models.StrawmanViewSTDModel
            {
                vid = p.vid,
                vorder = p.vorder,
                vparent = p.vparent,
                col1 = p.col1
            })
                   .ToList());
        }
Exemplo n.º 2
0
        private List <Models.ChartByChannelModels> GetChartByChannelData(string type)
        {
            var typ = ((List <StrawmanDBLibray.Entities.WRK_VIEWS_VARIABLES>)Helpers.StrawmanDBLibrayData.Get(StrawmanDBLibray.Classes.StrawmanDataTables.WRK_VIEWS_VARIABLES))
                      .Where(m => m.VIEW == "CHART BY CONFIG" && m.NAME == type).Select(m => m.VALUE).FirstOrDefault();

            if (typ == null)
            {
                return(null);
            }

            var grp  = (List <StrawmanDBLibray.Entities.GROUP_MASTER>)Helpers.StrawmanDBLibrayData.Get(StrawmanDBLibray.Classes.StrawmanDataTables.GROUP_MASTER);
            var grpd = grp.Join(((List <StrawmanDBLibray.Entities.GROUP_CONFIG>)Helpers.StrawmanDBLibrayData.Get(StrawmanDBLibray.Classes.StrawmanDataTables.GROUP_CONFIG))
                                .Where(m => m.TYPE_ID == int.Parse(typ)).AsEnumerable(),
                                m => new { _id = m.ID }, c => new { _id = (decimal)c.GROUP_ID },
                                (m, c) => new
            {
                order  = c.ID,
                id     = c.BRAND,
                name   = m.NAME,
                source = c.SOURCE,
                brand  = c.BRAND,
                market = c.MARKET
            });

            if (grpd == null)
            {
                return(null);
            }

            MarketViewFranchiseController mfranchise = new MarketViewFranchiseController();
            BrandViewFranchiseController  bfranchise = new BrandViewFranchiseController();

            MarketViewChannelController mchannel = new MarketViewChannelController();
            BrandViewChannelController  bchannel = new BrandViewChannelController();

            MarketViewController mstrawm = new MarketViewController();
            BrandViewController  bstrawm = new BrandViewController();

            string vtype = Classes.StrawmanViews.MAT;

            var f_data_market_MAT = mfranchise.GetMarketViewData(vtype);
            var f_data_brand_MAT  = bfranchise.GetBrandViewData(vtype);

            var c_data_market_MAT = mchannel.GetMarketViewData(vtype);
            var c_data_brand_MAT  = bchannel.GetBrandViewData(vtype);

            var s_data_market_MAT = (List <Models.StrawmanViewSTDModel>)mstrawm.GetMarketViewData(StrawmanDBLibray.Classes.StrawmanDataTables.WRK_MARKET_MAT);
            var s_data_brand_MAT  = (List <Models.StrawmanViewSTDModel>)bstrawm.GetBrandViewData(StrawmanDBLibray.Classes.StrawmanDataTables.WRK_BRAND_MAT);

            var fdata_MAT = GetCalcChartData(f_data_market_MAT, f_data_brand_MAT);

            var cdata_MAT = GetCalcChartData(c_data_market_MAT, c_data_brand_MAT);

            var sdata_MAT = GetCalcChartData(s_data_market_MAT, s_data_brand_MAT, "STRAWMAN");

            vtype = Classes.StrawmanViews.YTD;
            var f_data_market_YTD = mfranchise.GetMarketViewData(vtype);
            var f_data_brand_YTD  = bfranchise.GetBrandViewData(vtype);

            var c_data_market_YTD = mchannel.GetMarketViewData(vtype);
            var c_data_brand_YTD  = bchannel.GetBrandViewData(vtype);

            var fdata_YTD = GetCalcChartData(f_data_market_YTD, f_data_brand_YTD);
            var cdata_YTD = GetCalcChartData(c_data_market_YTD, c_data_brand_YTD);

            vtype = Classes.StrawmanViews.MONTH;
            var f_data_market_LM = mfranchise.GetMarketViewData(vtype);
            var f_data_brand_LM  = bfranchise.GetBrandViewData(vtype);

            var c_data_market_LM = mchannel.GetMarketViewData(vtype);
            var c_data_brand_LM  = bchannel.GetBrandViewData(vtype);

            var fdata_LM = GetCalcChartData(f_data_market_LM, f_data_brand_LM);
            var cdata_LM = GetCalcChartData(c_data_market_LM, c_data_brand_LM);

            vtype = Classes.StrawmanViews.BOY;
            var f_data_market_BOY = mfranchise.GetMarketViewData(vtype);
            var f_data_brand_BOY  = bfranchise.GetBrandViewData(vtype);

            var c_data_market_BOY = mchannel.GetMarketViewData(vtype);
            var c_data_brand_BOY  = bchannel.GetBrandViewData(vtype);


            vtype = Classes.StrawmanViews.TOTAL;
            var f_data_market_PBP = mfranchise.GetMarketViewData(vtype).Join(f_data_market_BOY, t => new{ _id = t.vid }, b => new{ _id = b.vid }, (t, b) => new Models.MarketViewChannelModels
            {
                vid  = t.vid,
                col1 = t.col3,
                col2 = b._le
            }).ToList();
            var f_data_brand_PBP = bfranchise.GetBrandViewData(vtype).Join(f_data_brand_BOY, t => new { _id = t.vid }, b => new { _id = b.vid }, (t, b) => new Models.MarketViewChannelModels
            {
                vid  = t.vid,
                col1 = t.col3,
                col2 = b._le
            }).ToList();

            var c_data_market_PBP = mchannel.GetMarketViewData(vtype).Join(c_data_market_BOY, t => new { _id = t.vid }, b => new { _id = b.vid }, (t, b) => new Models.StrawmanViewSTDModel
            {
                vid  = t.vid,
                col1 = t.col3,
                col2 = b._le
            }).ToList();
            var c_data_brand_PBP = bchannel.GetBrandViewData(vtype).Join(c_data_brand_BOY, t => new { _id = t.vid }, b => new { _id = b.vid }, (t, b) => new Models.StrawmanViewSTDModel
            {
                vid  = t.vid,
                col1 = t.col3,
                col2 = b._le
            }).ToList();

            var fdata_PBP = GetCalcChartData(f_data_market_PBP, f_data_brand_PBP);
            var cdata_PBP = GetCalcChartData(c_data_market_PBP, c_data_brand_PBP);

            return(grpd.Select(p => new Models.ChartByChannelModels
            {
                channel_name = p.name,
                vid = (decimal)p.id,
                mat_market_size = p.source == "FRANCHISE"? fdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().market_size: p.source == "STRAWMAN"? sdata_MAT.Where(m => m.brand == p.brand && m.market == p.market).FirstOrDefault().market_size: cdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().market_size,
                mat_market_share_l = p.source == "FRANCHISE" ? fdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().market_share_l : cdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().market_share_l,
                mat_market_share_p = p.source == "FRANCHISE" ? fdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().market_share_p : cdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().market_share_p,
                ytd_market_share_l = p.source == "FRANCHISE" ? fdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().market_share_l : cdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().market_share_l,
                ytd_market_share_p = p.source == "FRANCHISE" ? fdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().market_share_p : cdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().market_share_p,
                lm_market_share_l = p.source == "FRANCHISE" ? fdata_LM.Where(m => m.vid == p.id).FirstOrDefault().market_share_l : cdata_LM.Where(m => m.vid == p.id).FirstOrDefault().market_share_l,
                lm_market_share_p = p.source == "FRANCHISE" ? fdata_LM.Where(m => m.vid == p.id).FirstOrDefault().market_share_p : cdata_LM.Where(m => m.vid == p.id).FirstOrDefault().market_share_p,
                mat_grouth_c = p.source == "FRANCHISE" ? fdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().grouth_c : cdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().grouth_c,
                mat_grouth_jj = p.source == "FRANCHISE" ? fdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj : cdata_MAT.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj,
                ytd_grouth_c = p.source == "FRANCHISE" ? fdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().grouth_c : cdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().grouth_c,
                ytd_grouth_jj = p.source == "FRANCHISE" ? fdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj : cdata_YTD.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj,
                lm_grouth_c = p.source == "FRANCHISE" ? fdata_LM.Where(m => m.vid == p.id).FirstOrDefault().grouth_c : cdata_LM.Where(m => m.vid == p.id).FirstOrDefault().grouth_c,
                lm_grouth_jj = p.source == "FRANCHISE" ? fdata_LM.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj : cdata_LM.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj,
                pbp_market_size = p.source == "FRANCHISE" ? (double)fdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().market_size : (double)cdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().market_size,
                pbp_grouth_c = p.source == "FRANCHISE" ? fdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().grouth_c : cdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().grouth_c,
                pbp_grouth_jj = p.source == "FRANCHISE" ? fdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj : cdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().grouth_jj,
                pbp_share_p = p.source == "FRANCHISE" ? fdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().market_share_p: cdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().market_share_p,
                pbp_share_l = p.source == "FRANCHISE" ? fdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().market_share_l : cdata_PBP.Where(m => m.vid == p.id).FirstOrDefault().market_share_l,
            }).ToList());
        }