コード例 #1
0
        public async Task <ActionResult <TargetMatrix> > GetTargetMatrix(string month)
        {
            try
            {
                DateTime selectedMonth = Convert.ToDateTime(month);
                selectedMonth = new DateTime(selectedMonth.Year, selectedMonth.Month, 1);

                var ListofWeeks = GetWeekRange.GetListofWeeks(selectedMonth.Year, selectedMonth.Month);

                //int noOfWeek = GetWeekNumberOfMonth(selectedMonth);

                TargetMatrix targetMatrix = new TargetMatrix()
                {
                    Header = new List <string>(), RowDataTargetMaster = new List <TargetMasterViewModel>()
                };
                targetMatrix.Header.Add("Tele Caller");
                foreach (dynamic item in ListofWeeks)
                {
                    DateTime FromDate = Convert.ToDateTime(item.DateFrom);
                    DateTime ToDate   = Convert.ToDateTime(item.To);
                    targetMatrix.Header.Add(FromDate.Day.ToString() + " - " + ToDate.Day.ToString());
                }
                //for (int i = 1; i <= ListofWeeks.Count(); i++)
                //    targetMatrix.Header.Add("Week " + i);

                Guid currentCompanyId = new Guid(User.Claims.FirstOrDefault(p => p.Type == "CompanyId").Value);
                var  telecallerList   = _context.UserMaster.Include(p => p.TargetMaster).Where(r => r.RoleId == (int)Roles.TeleCaller && r.Status == true && r.CompanyId == currentCompanyId).AsEnumerable();

                foreach (var userMaster in telecallerList)
                {
                    var objTarget = userMaster.TargetMaster.FirstOrDefault(p => p.MonthYear == selectedMonth);
                    if (objTarget == null)
                    {
                        objTarget = new TargetMaster();
                    }

                    targetMatrix.RowDataTargetMaster.Add(new TargetMasterViewModel()
                    {
                        TagetId        = objTarget.TagetId,
                        TelecallerName = userMaster.FirstName,
                        TelecallerId   = userMaster.UserId,
                        TargetWeek1    = objTarget.TargetWeek1,
                        TargetWeek2    = objTarget.TargetWeek2,
                        TargetWeek3    = objTarget.TargetWeek3,
                        TargetWeek4    = objTarget.TargetWeek4,
                        TargetWeek5    = objTarget.TargetWeek5,
                        TargetWeek6    = objTarget.TargetWeek6,
                    });
                }

                GenericMethods.Log(LogType.ActivityLog.ToString(), "GetTargetMatrix: -get tele caller target matrix in admin");
                return(await Task.FromResult(targetMatrix));
            }
            catch (Exception ex)
            {
                GenericMethods.Log(LogType.ErrorLog.ToString(), "GetTargetByMonth: " + ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }
コード例 #2
0
        public async Task <ActionResult <TargetMatrix> > GetTargetVsAchieve(string month)
        {
            try
            {
                DateTime selectedMonth = Convert.ToDateTime(month);
                selectedMonth = new DateTime(selectedMonth.Year, selectedMonth.Month, 1);

                var          ListofWeeks     = GetWeekRange.GetListofWeeks(selectedMonth.Year, selectedMonth.Month);
                TargetMatrix targetVsAchieve = new TargetMatrix()
                {
                    Header = new List <string>(), RowDataTargetMaster = new List <TargetMasterViewModel>()
                };
                targetVsAchieve.Header.Add("Tele Caller");
                foreach (dynamic item in ListofWeeks)
                {
                    DateTime FromDate = Convert.ToDateTime(item.DateFrom);
                    DateTime ToDate   = Convert.ToDateTime(item.To);
                    targetVsAchieve.Header.Add(FromDate.Day.ToString() + " - " + ToDate.Day.ToString());
                }
                targetVsAchieve.Header.Add("Total");

                Guid currentCompanyId = new Guid(User.Claims.FirstOrDefault(p => p.Type == "CompanyId").Value);
                var  telecallerList   = _context.UserMaster.Include(p => p.TargetMaster).Where(r => r.RoleId == (int)Roles.TeleCaller && r.Status == true && r.CompanyId == currentCompanyId).AsNoTracking().AsEnumerable();

                foreach (var userMaster in telecallerList)
                {
                    var objTarget = userMaster.TargetMaster.FirstOrDefault(p => p.MonthYear == selectedMonth);
                    if (objTarget == null)
                    {
                        objTarget = new TargetMaster();
                    }

                    targetVsAchieve.RowDataTargetMaster.Add(new TargetMasterViewModel()
                    {
                        TagetId        = objTarget.TagetId,
                        TelecallerName = userMaster.FirstName,
                        TelecallerId   = userMaster.UserId,
                        TargetWeek1    = objTarget.TargetWeek1,
                        TargetWeek2    = objTarget.TargetWeek2,
                        TargetWeek3    = objTarget.TargetWeek3,
                        TargetWeek4    = objTarget.TargetWeek4,
                        TargetWeek5    = objTarget.TargetWeek5,
                        TargetWeek6    = objTarget.TargetWeek6,
                    });

                    int cntWeek = 0;
                    foreach (dynamic item in ListofWeeks)
                    {
                        cntWeek++;
                        DateTime FromDate = Convert.ToDateTime(item.DateFrom);
                        DateTime ToDate   = Convert.ToDateTime(item.To);

                        //OmniCRMContext con_text = new OmniCRMContext();
                        var TeleCallerLeads = _context.CallTransactionDetail.AsEnumerable().Where(q => Convert.ToDateTime(q.CreatedDate).Date >= FromDate.Date && Convert.ToDateTime(q.CreatedDate).Date <= ToDate.Date &&
                                                                                                  q.OutComeId != (int)Enums.CallOutcome.NoResponse &&
                                                                                                  q.OutComeId != (int)Enums.CallOutcome.None &&
                                                                                                  q.OutComeId != (int)Enums.CallOutcome.Dropped &&
                                                                                                  q.OutComeId != (int)Enums.CallOutcome.Interested &&
                                                                                                  q.CreatedBy == userMaster.UserId).GroupBy(x => x.CallId).Select(r => r.OrderBy(a => a.CallTransactionId).LastOrDefault());

                        var objAchive = targetVsAchieve.RowDataTargetMaster.FirstOrDefault(p => p.TelecallerId == userMaster.UserId);
                        switch (cntWeek)
                        {
                        case 1:
                            objAchive.AchieveWeek1 = TeleCallerLeads.Count();
                            break;

                        case 2:
                            objAchive.AchieveWeek2 = TeleCallerLeads.Count();
                            break;

                        case 3:
                            objAchive.AchieveWeek3 = TeleCallerLeads.Count();
                            break;

                        case 4:
                            objAchive.AchieveWeek4 = TeleCallerLeads.Count();
                            break;

                        case 5:
                            objAchive.AchieveWeek5 = TeleCallerLeads.Count();
                            break;

                        case 6:
                            objAchive.AchieveWeek6 = TeleCallerLeads.Count();
                            break;

                        default:
                            break;
                        }
                    }
                }

                GenericMethods.Log(LogType.ActivityLog.ToString(), "GetTargetVsAchieve: -get tele caller target vs achievement in admin");
                return(await Task.FromResult(targetVsAchieve));
            }
            catch (Exception ex)
            {
                GenericMethods.Log(LogType.ErrorLog.ToString(), "GetTargetByMonth: " + ex.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }
        }