Example #1
0
        public List <ReportRow> LARCANews(string smoFin, string buFin, string regionId)
        {
            var permisos = new List <LARCA20_UsersRoles>();
            var lista    = new List <ReportRow>();
            var toplvl2  = new ApplicationDataBLL().TraerTopLvl2();

            var lista22       = new LARCA2.Data.Services.UserOwnerDAL();
            var permisostodos = lista22.Todos();

            if (smoFin.Length > 0)
            {
                var items = SmoScopeDAL.Todos().Where(s => s.MasterSMO.DataFin == smoFin && s.clone != true && s.historic != true).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]);
                int cant  = 0;
                foreach (var item in items) //.Take(toplvl2))
                {
                    cant++;
                    var volumenSmo = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.MasterSMODetail.DataFin == smoFin && s.historic == false).Sum(s => s.Volumen));
                    var volumen    = SmoDetailDAL.Todos().Where(s => s.MasterSMODetail.DataFin == smoFin && s.historic == false && s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key).Sum(s => s.Volumen);
                    var row        = new ReportRow();
                    row.SMO     = item.ToList()[0].MasterSMO.DataFin;
                    row.RBU     = "TOTAL";
                    row.CUT     = new RCClassificationBLL().Traer(item.Key).Description;
                    row.Details = new List <ReportRow>();
                    row.VOLUME  = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString();
                    row.PROBLEM = "View Details Below";
                    row.GAP     = Math.Round(volumen * 100 / volumenSmo, 2).ToString() + " %";

                    var     toplvl3 = new ApplicationDataBLL().TraerTopLvl3();
                    decimal vol     = 0;
                    int     i       = 1;
                    foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3)) //.Take(toplvl3))
                    {
                        var detailRow = new ReportRow
                        {
                            SMO         = subitem.MasterSMO.DataFin,
                            RBU         = subitem.MasterBU.DataFin,
                            CUT         = subitem.MasterLvl.Description,
                            VOLUME      = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(),
                            PROBLEM     = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news),
                            WHY1        = subitem.Why1,
                            WHY2        = subitem.Why2,
                            WHY3        = subitem.Why3,
                            ACTIONPLAN  = subitem.ActionPlan,
                            LEVEL4      = "",
                            RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty,
                            GAP         = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %"
                        };

                        try
                        {
                            detailRow.LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty;
                        }
                        catch (Exception)
                        {
                            detailRow.LEVEL4 = "";
                        }

                        var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner);
                        if (user.Id > 0)
                        {
                            detailRow.GAPANALYSIS = user.user_name;
                        }
                        else
                        {
                            detailRow.GAPANALYSIS = "";
                        }

                        //////
                        Boolean paso = false;
                        if (i == 1)
                        {
                            i++;
                            vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                            row.Details.Add(detailRow);
                            paso = true;
                        }
                        else
                        {
                            if (vol * 100 / volumen <= 80)
                            {
                                i++;
                                vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                                row.Details.Add(detailRow);
                                paso = true;
                            }
                        }

                        if (paso)
                        {
                            // Chequeo de clones
                            var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false);
                            if (clones.Count() > 0)
                            {
                                foreach (var clon in clones)
                                {
                                    var detail = new ReportRow
                                    {
                                        SMO         = string.Empty,
                                        RBU         = string.Empty,
                                        CUT         = string.Empty,
                                        VOLUME      = string.Empty,
                                        PROBLEM     = clon.Problem,
                                        WHY1        = clon.Why1,
                                        WHY2        = clon.Why2,
                                        WHY3        = clon.Why3,
                                        ACTIONPLAN  = clon.ActionPlan,
                                        RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty,
                                        //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty,
                                        LEVEL4 = "",
                                        GAP    = string.Empty
                                    };

                                    try
                                    {
                                        detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty;
                                    }
                                    catch (Exception)
                                    {
                                        detail.LEVEL4 = "";
                                    }

                                    user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner);
                                    if (user.Id > 0)
                                    {
                                        detail.GAPANALYSIS = user.user_name;
                                    }
                                    else
                                    {
                                        detail.GAPANALYSIS = "";
                                    }

                                    row.Details.Add(detail);
                                }
                            }
                        }
                    }
                    lista.Add(row);
                }
            }
            else
            if (buFin.Length > 0)
            {
                var items = SmoScopeDAL.Todos().Where(s => s.MasterBU.DataFin == buFin && s.historic == false && s.clone != true).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]);
                int cant  = 0;
                foreach (var item in items)     //.Take(toplvl2))
                {
                    cant++;
                    var volumenBU = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.MasterBUDetail.DataFin == buFin && s.historic == false).Sum(s => s.Volumen));
                    var volumen   = SmoDetailDAL.Todos().Where(s => s.MasterBUDetail.DataFin == buFin && s.historic == false && s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key).Sum(s => s.Volumen);
                    var row       = new ReportRow();
                    row.SMO     = "TOTAL";
                    row.RBU     = item.ToList()[0].MasterBU.DataFin;
                    row.CUT     = new RCClassificationBLL().Traer(item.Key).Description;
                    row.Details = new List <ReportRow>();
                    row.VOLUME  = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString();
                    row.PROBLEM = "View Details Below";
                    row.GAP     = Math.Round(volumen * 100 / volumenBU, 2).ToString() + " %";


                    decimal vol = 0;
                    int     i   = 1;

                    var toplvl3 = new ApplicationDataBLL().TraerTopLvl3();
                    foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3))
                    {
                        string SMOt         = subitem.MasterSMO.DataFin;
                        string RBUt         = subitem.MasterBU.DataFin;
                        string CUTt         = subitem.MasterLvl.Description;
                        string VOLUMEt      = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString();
                        string PROBLEMt     = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news);
                        string WHY1t        = subitem.Why1;
                        string WHY2t        = subitem.Why2;
                        string WHY3t        = subitem.Why3;
                        string ACTIONPLANt  = subitem.ActionPlan;
                        string RESPONSIBLEt = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty;
                        string LEVEL4t      = "";
                        string GAPANALYSIS;
                        try
                        {
                            LEVEL4t = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty;
                        }
                        catch (Exception)
                        {
                            LEVEL4t = "";
                        }

                        var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner);
                        if (user.Id > 0)
                        {
                            GAPANALYSIS = user.user_name;
                        }
                        else
                        {
                            GAPANALYSIS = "";
                        }

                        string GAPt = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %";


                        var detailRow = new ReportRow
                        {
                            SMO         = SMOt,
                            RBU         = RBUt,
                            CUT         = CUTt,
                            VOLUME      = VOLUMEt,
                            PROBLEM     = PROBLEMt,
                            WHY1        = WHY1t,
                            WHY2        = WHY2t,
                            WHY3        = WHY3t,
                            ACTIONPLAN  = ACTIONPLANt,
                            RESPONSIBLE = RESPONSIBLEt,
                            LEVEL4      = LEVEL4t,
                            GAP         = GAPt,
                            GAPANALYSIS = GAPANALYSIS

                                          /*
                                           * SMO = subitem.MasterSMO.DataFin,
                                           * RBU = subitem.MasterBU.DataFin,
                                           * CUT = subitem.MasterLvl.Description,
                                           * VOLUME = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(),
                                           * PROBLEM = CheckProblem(subitem.Problem, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner),
                                           * WHY1 = subitem.Why1,
                                           * WHY2 = subitem.Why2,
                                           * WHY3 = subitem.Why3,
                                           * ACTIONPLAN = subitem.ActionPlan,
                                           * RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Name.ToString() : string.Empty,
                                           * LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty,
                                           * GAP = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %"
                                           */
                        };
                        Boolean paso = false;
                        if (i == 1)
                        {
                            i++;
                            vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                            row.Details.Add(detailRow);
                            paso = true;
                        }
                        else
                        {
                            if (vol * 100 / volumen <= 80)
                            {
                                i++;
                                vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                                row.Details.Add(detailRow);

                                paso = true;
                            }
                        }

                        if (paso)
                        {
                            // Chequeo de clones
                            var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false);
                            if (clones.Count() > 0)
                            {
                                foreach (var clon in clones)
                                {
                                    var detail = new ReportRow
                                    {
                                        SMO         = string.Empty,
                                        RBU         = string.Empty,
                                        CUT         = string.Empty,
                                        VOLUME      = string.Empty,
                                        PROBLEM     = clon.Problem,
                                        WHY1        = clon.Why1,
                                        WHY2        = clon.Why2,
                                        WHY3        = clon.Why3,
                                        ACTIONPLAN  = clon.ActionPlan,
                                        RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty,
                                        //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty,
                                        LEVEL4 = "",
                                        GAP    = string.Empty
                                    };

                                    try
                                    {
                                        detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty;
                                    }
                                    catch (Exception)
                                    {
                                        detail.LEVEL4 = "";
                                    }

                                    user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner);
                                    if (user.Id > 0)
                                    {
                                        detail.GAPANALYSIS = user.user_name;
                                    }
                                    else
                                    {
                                        detail.GAPANALYSIS = "";
                                    }

                                    row.Details.Add(detail);
                                }
                            }
                        }
                    }


                    lista.Add(row);
                }
            }
            else
            {
                if (regionId == "1")
                {
                    var items = SmoScopeDAL.Todos().Where(p => p.clone != true && p.historic == false).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]);
                    int cant  = 0;
                    foreach (var item in items)     //.Take(toplvl2))
                    {
                        cant++;
                        var volumenTotal = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.historic == false).Sum(s => s.Volumen));
                        var volumen      = SmoDetailDAL.Todos().Where(s => s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key && s.historic == false).Sum(s => s.Volumen);
                        var row          = new ReportRow();
                        row.SMO     = "TOTAL";
                        row.RBU     = "TOTAL";
                        row.CUT     = new RCClassificationBLL().Traer(item.Key).Description;
                        row.Details = new List <ReportRow>();
                        row.VOLUME  = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString();
                        row.PROBLEM = "View Details Below";
                        row.GAP     = Math.Round(volumen * 100 / volumenTotal, 2).ToString() + " %";

                        decimal vol     = 0;
                        int     i       = 1;
                        var     toplvl3 = new ApplicationDataBLL().TraerTopLvl3();
                        foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3))
                        {
                            var detailRow = new ReportRow
                            {
                                SMO         = subitem.MasterSMO.DataFin,
                                RBU         = subitem.MasterBU.DataFin,
                                CUT         = subitem.MasterLvl.Description,
                                VOLUME      = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(),
                                PROBLEM     = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news),
                                WHY1        = subitem.Why1,
                                WHY2        = subitem.Why2,
                                WHY3        = subitem.Why3,
                                ACTIONPLAN  = subitem.ActionPlan,
                                RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty,
                                //LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty,
                                LEVEL4 = "",
                                GAP    = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %"
                            };

                            try
                            {
                                detailRow.LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty;
                            }
                            catch (Exception)
                            {
                                detailRow.LEVEL4 = "";
                            }

                            var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner);
                            if (user.Id > 0)
                            {
                                detailRow.GAPANALYSIS = user.user_name;
                            }
                            else
                            {
                                detailRow.GAPANALYSIS = "";
                            }

                            Boolean paso = false;
                            if (i == 1)
                            {
                                i++;
                                vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                                row.Details.Add(detailRow);
                                paso = true;
                            }
                            else
                            {
                                if (vol * 100 / volumen <= 80)
                                {
                                    i++;
                                    vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                                    row.Details.Add(detailRow);
                                    paso = true;
                                }
                            }

                            if (paso)
                            {
                                // Chequeo de clones
                                var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false);
                                if (clones.Count() > 0)
                                {
                                    foreach (var clon in clones)
                                    {
                                        var detail = new ReportRow
                                        {
                                            SMO         = string.Empty,
                                            RBU         = string.Empty,
                                            CUT         = string.Empty,
                                            VOLUME      = string.Empty,
                                            PROBLEM     = clon.Problem,
                                            WHY1        = clon.Why1,
                                            WHY2        = clon.Why2,
                                            WHY3        = clon.Why3,
                                            ACTIONPLAN  = clon.ActionPlan,
                                            RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty,
                                            //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty,
                                            LEVEL4 = "",
                                            GAP    = string.Empty
                                        };
                                        try
                                        {
                                            detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty;
                                        }
                                        catch (Exception)
                                        {
                                            detail.LEVEL4 = "";
                                        }



                                        user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner);
                                        if (user.Id > 0)
                                        {
                                            detail.GAPANALYSIS = user.user_name;
                                        }
                                        else
                                        {
                                            detail.GAPANALYSIS = "";
                                        }

                                        row.Details.Add(detail);
                                    }
                                }
                            }
                        }
                        lista.Add(row);
                    }
                }
                else
                if (regionId == "2")
                {
                    var items = SmoScopeDAL.TodosConExclusiones().Where(p => p.clone != true && p.historic == false).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]);
                    int cant  = 0;
                    foreach (var item in items)         //.Take(toplvl2))
                    {
                        cant++;
                        var volumenTotal = Convert.ToDecimal(SmoDetailDAL.Todos().Where(s => s.historic == false).Sum(s => s.Volumen));
                        var volumen      = SmoDetailDAL.Todos().Where(s => s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[0] + "." + s.MasterLvl2Detail.Code.Split(Convert.ToChar("."))[1] == item.Key && s.historic == false).Sum(s => s.Volumen);
                        var row          = new ReportRow();
                        row.SMO     = "TOTAL";
                        row.RBU     = "TOTAL";
                        row.CUT     = new RCClassificationBLL().Traer(item.Key).Description;
                        row.Details = new List <ReportRow>();
                        row.VOLUME  = (Math.Round(decimal.Parse(volumen.ToString()), 2)).ToString();
                        row.PROBLEM = "View Details Below";
                        row.GAP     = Math.Round(volumen * 100 / volumenTotal, 2).ToString() + " %";

                        decimal vol     = 0;
                        int     i       = 1;
                        var     toplvl3 = new ApplicationDataBLL().TraerTopLvl3();
                        foreach (var subitem in item.ToList().OrderByDescending(s => s.Volumen).Take(toplvl3))
                        {
                            var detailRow = new ReportRow
                            {
                                SMO         = subitem.MasterSMO.DataFin,
                                RBU         = subitem.MasterBU.DataFin,
                                CUT         = subitem.MasterLvl.Description,
                                VOLUME      = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2)).ToString(),
                                PROBLEM     = CheckProblem(subitem.Problem, subitem.ActionPlan, subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner, subitem.partial, subitem.top_news),
                                WHY1        = subitem.Why1,
                                WHY2        = subitem.Why2,
                                WHY3        = subitem.Why3,
                                ACTIONPLAN  = subitem.ActionPlan,
                                RESPONSIBLE = subitem.ResponsableSmo != null ? subitem.ResponsableSmo.Responsable_user.user_name : string.Empty,
                                //LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty,
                                LEVEL4 = "",
                                GAP    = Math.Round(Convert.ToDecimal(subitem.Volumen) * 100 / volumen, 2).ToString() + " %"
                            };

                            try
                            {
                                detailRow.LEVEL4 = subitem.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(subitem.Level4)).name : string.Empty;
                            }
                            catch (Exception)
                            {
                                detailRow.LEVEL4 = "";
                            }

                            var user = new UserOwnerBLL().UserPermisoCheck(subitem.RefIdBU, subitem.RefIdSMO, subitem.RefIdOwner);
                            if (user.Id > 0)
                            {
                                detailRow.GAPANALYSIS = user.user_name;
                            }
                            else
                            {
                                detailRow.GAPANALYSIS = "";
                            }

                            Boolean paso = false;
                            if (i == 1)
                            {
                                i++;
                                vol = (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                                row.Details.Add(detailRow);
                                paso = true;
                            }
                            else
                            {
                                if (vol * 100 / volumen <= 80)
                                {
                                    i++;
                                    vol += (Math.Round(decimal.Parse(subitem.Volumen.ToString()), 2));
                                    row.Details.Add(detailRow);
                                    paso = true;
                                }
                            }

                            if (paso)
                            {
                                // Chequeo de clones
                                var clones = new SMOScopeBLL().Todos().Where(s => s.RefIdSMO == subitem.RefIdSMO && s.RefIdBU == subitem.RefIdBU && s.RefIdOwner == subitem.RefIdOwner && s.RefIdRC == subitem.RefIdRC && s.SmoScopeID != subitem.SmoScopeID && s.clone == true && s.historic == false);
                                if (clones.Count() > 0)
                                {
                                    foreach (var clon in clones)
                                    {
                                        var detail = new ReportRow
                                        {
                                            SMO         = string.Empty,
                                            RBU         = string.Empty,
                                            CUT         = string.Empty,
                                            VOLUME      = string.Empty,
                                            PROBLEM     = clon.Problem,
                                            WHY1        = clon.Why1,
                                            WHY2        = clon.Why2,
                                            WHY3        = clon.Why3,
                                            ACTIONPLAN  = clon.ActionPlan,
                                            RESPONSIBLE = clon.ResponsableSmo != null ? clon.ResponsableSmo.Responsable_user.user_name : string.Empty,
                                            //LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty,
                                            LEVEL4 = "",
                                            GAP    = string.Empty
                                        };
                                        try
                                        {
                                            detail.LEVEL4 = clon.Level4 != null ? new Level4BLL().Traer(Convert.ToInt64(clon.Level4)).name : string.Empty;
                                        }
                                        catch (Exception)
                                        {
                                            detail.LEVEL4 = "";
                                        }

                                        user = new UserOwnerBLL().UserPermisoCheck(clon.RefIdBU, clon.RefIdSMO, clon.RefIdOwner);
                                        if (user.Id > 0)
                                        {
                                            detail.GAPANALYSIS = user.user_name;
                                        }
                                        else
                                        {
                                            detail.GAPANALYSIS = "";
                                        }



                                        row.Details.Add(detail);
                                    }
                                }
                            }
                        }
                        lista.Add(row);
                    }
                }
            }
            return(lista.OrderByDescending(i => Convert.ToDecimal(i.VOLUME)).Take(toplvl2).ToList());
        }
Example #2
0
        /// <summary>
        /// Metodo que se encarga de enviar los PRIMEROS REMINDERS por email
        /// </summary>
        public List <string> EnviarPrimerosRemiders()
        {
            // General Reminders

            /* LARCA2.Data.Services.SmoScopeDAL analisis = new LARCA2.Data.Services.SmoScopeDAL();
             * //var lista_analisis = analisis.Todos();
             *
             * var lista_final_aux = analisis.Todos().OrderByDescending(z => z.SmoScopeID).ToList();
             * var lista_final = lista_final_aux.ToList();
             * lista_final.Clear();
             *
             * foreach (var item in lista_final_aux)
             * {
             *   if (!lista_final.Exists(x => x.RefIdRC == item.RefIdRC && x.RefIdSMO == item.RefIdSMO && x.RefIdBU == item.RefIdBU && x.RefIdOwner == item.RefIdOwner))
             *   {
             *       lista_final.Add(item);
             *   }
             * }*/

            List <string> return_list = new List <string>();

            LARCA2.Business.Services.ApplicationDataBLL repo = new LARCA2.Business.Services.ApplicationDataBLL();
            DateTime siev = DateTime.Now.AddDays(-repo.Todos().First().SmoDays.Value);


            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result            = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result_test       = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result_aux_smo    = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>       result_aux_bu     = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScope>();
            List <LARCA2.Data.DatabaseModels.LARCA20_SmoScopeDetail> lista_tops_level2 = new List <LARCA2.Data.DatabaseModels.LARCA20_SmoScopeDetail>();

            //result = result.Where(x => x.deleted == false && x.date >= siev).ToList();
            LARCA2.Business.Services.MasterDataBLL smo_list = new LARCA2.Business.Services.MasterDataBLL();
            LARCA2.Business.Services.MasterDataBLL bu_list  = new LARCA2.Business.Services.MasterDataBLL();
            var toplvl3 = new LARCA2.Business.Services.ApplicationDataBLL().TraerTopLvl3();
            var toplvl2 = new LARCA2.Business.Services.ApplicationDataBLL().TraerTopLvl2();

            decimal volumen;
            decimal vol;

            LARCA2.Business.Services.SMOScopeBLL smoscopebll = new LARCA2.Business.Services.SMOScopeBLL();

            LARCA2.Data.Services.SmoScopeDAL SmoScopeDAL = new LARCA2.Data.Services.SmoScopeDAL();

            foreach (var smo_var in smo_list.Todos().Where(x => x.Data == "SMO").ToList())
            {
                result_aux_smo.AddRange(SmoScopeDAL.Todos().Where(x => x.date >= siev && x.RefIdSMO == smo_var.id && x.clone != true).ToList());
            }

            var result_aux_s = result_aux_smo.GroupBy(p => p.RefIdSMO).ToList();


            var tops_smo = smoscopebll.traer_tops_level2(1);

            foreach (var item in result_aux_s)
            {
                var result_aux = item.Where(i => i.RefIdSMO == item.Key).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]).ToList();

                foreach (var subitem in result_aux)
                {
                    if (tops_smo.Exists(p => p.level == subitem.Key.ToString() && p.smo == item.Key))
                    {
                        volumen = tops_smo.SingleOrDefault(t => t.level == subitem.Key.ToString() && t.smo == item.Key).volumen;



                        vol = 0;
                        int cant = 0;
                        foreach (var item_list in subitem.OrderByDescending(p => p.Volumen).ToList())
                        {
                            cant++;
                            if (cant == 1)
                            {
                                result_test.Add(item_list);
                                vol = vol + Convert.ToDecimal(item_list.Volumen);
                            }

                            else
                            {
                                if ((vol * 100 / volumen <= 80))
                                {
                                    result_test.Add(item_list);
                                    vol = vol + Convert.ToDecimal(item_list.Volumen);
                                }
                            }
                        }
                        result.AddRange(result_test.OrderByDescending(s => s.Volumen).Take(toplvl3).ToList());
                        result_test.Clear();
                    }
                }
            }



            foreach (var bu_var in smo_list.Todos().Where(x => x.Data == "BU").ToList())
            {
                result_aux_bu.AddRange(SmoScopeDAL.Todos().Where(x => x.date >= siev && x.RefIdBU == bu_var.id && x.clone != true).ToList().ToList());
            }

            var result_aux_b = result_aux_bu.GroupBy(p => p.MasterBU.DataFin).ToList();


            var tops_bu = smoscopebll.traer_tops_level2(2);

            foreach (var item in result_aux_b)
            {
                var result_aux = item.Where(i => i.MasterBU.DataFin == item.Key.ToString()).GroupBy(p => p.MasterLvl.Code.Split(Convert.ToChar("."))[0] + "." + p.MasterLvl.Code.Split(Convert.ToChar("."))[1]).ToList();

                foreach (var subitem in result_aux)
                {
                    if (tops_bu.Exists(p => p.level == subitem.Key.ToString() && p.bu == item.Key.ToString()))
                    {
                        //volumen = tops_bu.SingleOrDefault(t => t.level == subitem.Key.ToString() && t.bu == item.Key.ToString()).volumen;
                        volumen = tops_bu.FirstOrDefault(t => t.level == subitem.Key.ToString() && t.bu == item.Key.ToString()).volumen;



                        vol = 0;
                        int cant = 0;
                        foreach (var item_list in subitem.OrderByDescending(p => p.Volumen).ToList())
                        {
                            cant++;
                            if (cant == 1)
                            {
                                result_test.Add(item_list);
                                vol = vol + Convert.ToDecimal(item_list.Volumen);
                            }

                            else
                            {
                                if ((vol * 100 / volumen <= 80))
                                {
                                    result_test.Add(item_list);
                                    vol = vol + Convert.ToDecimal(item_list.Volumen);
                                }
                            }
                        }
                        result.AddRange(result_test.OrderByDescending(s => s.Volumen).Take(toplvl3).ToList());
                        result_test.Clear();
                    }
                }
            }


            var lista_analisis = result.ToList();

            lista_analisis.Clear();

            foreach (var item in result.ToList())
            {
                if (!lista_analisis.Exists(x => x.RefIdBU == item.RefIdBU && x.RefIdSMO == item.RefIdSMO && x.RefIdRC == item.RefIdRC))
                {
                    lista_analisis.Add(item);
                }
            }

            foreach (var item in lista_analisis)
            {
                if ((item.Problem == "" || item.Problem == null) || (item.ActionPlan == "" || item.ActionPlan == null))
                {
                    LARCA2.Data.Services.UserOwnerDAL permisos = new LARCA2.Data.Services.UserOwnerDAL();
                    var permisos_lista2 = permisos.Todos().Where(x => x.IdOwner == item.RefIdOwner && x.IdSmo == item.RefIdSMO && x.IdBU == item.RefIdBU && x.deleted != true);

                    var    fs      = new FileStream(HttpContext.Current.Server.MapPath("~/AlertTemplates/FirstReminders.htm"), FileMode.Open);
                    var    sr      = new StreamReader(fs);
                    string subject = "LARCA - FIRST REMINDER - PENDING ANALYSIS";
                    var    body    = sr.ReadToEnd();
                    sr.Close();
                    fs.Close();

                    if (permisos_lista2.Count() > 0)
                    {
                        var to = permisos_lista2.First().LARCA20_Users.user_name + "@pg.com";
                        return_list.Add(permisos_lista2.First().LARCA20_Users.user_name + " - " + item.MasterBU.DataFin + " - " + item.MasterSMO.DataFin + " - " + item.MasterLvl.Description);
                        body = body.Replace("[owner]", permisos_lista2.First().LARCA20_Users.user_name);
                        string texto = item.MasterBU.DataFin + " - " + item.MasterSMO.DataFin + " - " + item.MasterLvl.Description;
                        body = body.Replace("[action_plan]", texto);
                        Send(subject, body, to, null);
                    }
                }
            }

            return(return_list);
        }