Exemplo n.º 1
0
 public List <TeamMembers> Get()
 {
     return(repo.Get());
 }
Exemplo n.º 2
0
        public void Post([FromBody] List <FinancialResults> results)
        {
            Debug.WriteLine("RESULT SIZE " + results.Count);
            // repo.add(results);

            if (results.Count != 0)
            {
                List <int> empIds = repo.getTimeReportedEmpIdForQuarter(results[0].Year, results[0].Quarter, results[0].AccountId);
                foreach (FinancialResults result in results)
                {
                    empIds.Remove(result.EmpId);

                    //repo.saveData(result);
                }

                foreach (int empId in empIds)
                {
                    TeamMembers member = teamRepo.Get(empId);
                    if (member != null)
                    {
                        FinancialResults tempResult = new FinancialResults();
                        tempResult.EmpId       = empId;
                        tempResult.EmpName     = member.MemberName;
                        tempResult.AccountId   = results[0].AccountId;
                        tempResult.AccountName = results[0].AccountName;
                        tempResult.Month       = results[0].Month;
                        tempResult.Quarter     = results[0].Quarter;
                        tempResult.Year        = results[0].Year;
                        Console.WriteLine(tempResult.EmpName);
                        //  repo.saveData(tempResult);
                    }
                }
            }

            //Calculate Financial Summary
            double expectedHours        = 0;
            double actualHours          = 0;
            double coveredBillableHours = 0;

            foreach (FinancialResults result in results)
            {
                if (result.BillableType == Constants.FULLTIMEBILLABLE)
                {
                    // The below commented code compares individual allocation with its billable hours

                    //expectedHours += result.AllocatedHours;

                    //double tempActualHours = 0;
                    //if (result.AllocatedHours < result.BillableHours)
                    //{
                    //    tempActualHours = result.AllocatedHours;
                    //}
                    //else
                    //{
                    //    tempActualHours = result.BillableHours;
                    //}
                    //actualHours += tempActualHours;

                    expectedHours        += result.AllocatedHours;
                    actualHours          += result.BillableHours;
                    coveredBillableHours += result.BillableHours;
                }
            }

            if (results.Count != 0)
            {
                if (actualHours > expectedHours)
                {
                    // actualHours = expectedHours;
                }

                string strDate = "01/" + results[0].Month + "/" + results[0].Year;

                //String strDate = "01/12/2014";
                DateTime dateTime = new DateTime(results[0].Year, results[0].Month, 1);
                //DateTime dateTime = DateTime.ParseExact(strDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                dateTime = dateTime.AddMonths(-1);


                FinancialSummary summary = summaryRepo.getSelectedMonthSummary(dateTime.Year, results[0].AccountId, results[0].Quarter);

                FinancialSummary savingSummary = new FinancialSummary();
                savingSummary.Month       = results[0].Month;
                savingSummary.Year        = results[0].Year;
                savingSummary.Quarter     = results[0].Quarter;
                savingSummary.AccountId   = results[0].AccountId;
                savingSummary.AccountName = results[0].AccountName;
                savingSummary.MonthName   = getMonth(results[0].Month);

                if (summary != null)
                {
                    double finalAllocatedHours       = expectedHours + summary.ExpectedHours;
                    double finalActualHours          = actualHours + summary.ActualHours;
                    double finalCoveredBillableHours = coveredBillableHours + summary.coveredBillableHours;
                    finalActualHours = finalCoveredBillableHours;
                    if (finalCoveredBillableHours > finalAllocatedHours)
                    {
                        finalActualHours = finalAllocatedHours;
                    }

                    savingSummary.ExpectedHours        = finalAllocatedHours;
                    savingSummary.ActualHours          = finalActualHours;
                    savingSummary.coveredBillableHours = finalCoveredBillableHours;
                }
                else
                {
                    savingSummary.ExpectedHours = expectedHours;
                    Debug.WriteLine("Saving Summary " + expectedHours);
                    savingSummary.ActualHours          = actualHours;
                    savingSummary.coveredBillableHours = coveredBillableHours;
                }

                summaryRepo.add(savingSummary);
            }
        }
        public bool sendTeamSatisfactionSurveyEmails(SurveyEmail surveyEmailData)
        {
            if (surveyEmailData != null)
            {
                string subject = " " + surveyEmailData.Account.AccountName + " Team satisfaction - " + surveyEmailData.Year + " : Q" + surveyEmailData.Quarter + " ";
                string body    = "<html><body>"
                                 + "<h4>Hi Team,</h4><br>"
                                 + "<div>It is once again, that time of the quarter where you are tasked with filling out the team satisfaction survey for " + surveyEmailData.Year + " : Q" + surveyEmailData.Quarter + " . "
                                 + "<br> Please be kind enough to complete this task before " + surveyEmailData.DeadLine + " .</ div>"
                                 + "<br><br> You may find the form here: <a href=" + appSettingsRepo.getEmailBodyLink() + "" + surveyEmailData.Account.Id + "/" + surveyEmailData.Year + "/" + surveyEmailData.Quarter + " >" + appSettingsRepo.getEmailBodyLink() + "" + surveyEmailData.Account.Id + "/" + surveyEmailData.Year + "/" + surveyEmailData.Quarter + " </a>"
                                 + "<br><br>Thank you<br>Regards,<br><b>Project Dashbaord Team</b>"
                                 + "<br>-This is an auto generated email-"
                                 + "</body></html>";


                var coreCount = Environment.ProcessorCount;
                var itemCount = surveyEmailData.ValidEmployees.Count;
                //var itemCount = 10;
                var batchSize = itemCount / coreCount;

                var pending = coreCount;
                using (var mre = new ManualResetEvent(false))
                {
                    for (int batchCount = 0; batchCount < coreCount; batchCount++)
                    {
                        var lower = batchCount * batchSize;
                        var upper = (batchCount == coreCount - 1) ? itemCount : lower + batchSize;
                        ThreadPool.QueueUserWorkItem(st =>
                        {
                            //foreach (int employee in surveyEmailData.ValidEmployees)
                            for (int i = lower; i < upper; i++)
                            {
                                TeamMembers member = teamMemberRepo.Get(surveyEmailData.ValidEmployees[i]);
                                string email       = member.MemberName + "@99x.lk";
                                SendEmail(email, subject, body);
                            }
                            if (Interlocked.Decrement(ref pending) == 0)
                            {
                                mre.Set();
                            }
                        });
                    }
                    mre.WaitOne();
                    return(true);
                }
            }
            else
            {
                return(false);
            }



            //<a href="http://*****:*****@99x.lk";
            //        //string email = "ishanm" + "@99x.lk";
            //        SendEmail(email, subject, body);
            //    }
            //    return true;
            //}
            //else {
            //    return false;
            //}
        }
Exemplo n.º 4
0
        public int add(List <FinancialExpandedResults> results)
        {
            int datarows = 0;
            //String strDate = "5/" + results[0].Month + "/" + results[0].Year+ "";
            //DateTime dateTime = DateTime.ParseExact(strDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            //dateTime = dateTime.AddMonths(-1);
            List <int> empDataInAccount      = new List <int>();
            List <int> usingEmpDataInAccount = new List <int>();

            if (results.Count != 0)
            {
                empDataInAccount      = empRepo.getDistinctEmpIdsForAccounts(results[0].AccountId, results[0].Year, results[0].Quarter);
                usingEmpDataInAccount = empRepo.getDistinctEmpIdsForAccounts(results[0].AccountId, results[0].Year, results[0].Quarter);
            }

            foreach (FinancialExpandedResults result in results)
            {
                if (empDataInAccount.Count != 0)
                {
                    foreach (int data in empDataInAccount)
                    {
                        if (data == result.EmpId)
                        {
                            usingEmpDataInAccount.Remove(data);
                        }
                    }
                }
                //Check the above method



                // This Add Statement Is Not Completed.....
                int tempMonth    = result.Month;
                int pastMaxMonth = getEmployeeTimeReportMaxMonth(result.AccountId, result.Year, result.Quarter, result.EmpId);
                if (pastMaxMonth != 0)
                {
                    int currentMonth = result.Month;

                    int monthDifference = currentMonth - pastMaxMonth;

                    if (monthDifference > 1)
                    {
                        monthDifference = monthDifference - 1;
                        for (int i = (pastMaxMonth + 1); i <= (monthDifference + pastMaxMonth); i++)
                        {
                            result.Month = i;
                            Console.WriteLine(result.EmpName);
                            saveData(result);
                        }
                    }
                }
                else
                {
                    int pastMonth    = 0;
                    int currentMonth = result.Month;
                    if (result.Quarter == 1)
                    {
                        pastMonth = 1;
                    }
                    else
                    {
                        pastMonth = 7;
                    }

                    int minMonthForQuarter = getAccountTimeReportMinMonthForQuarter(result.AccountId, result.Year, result.Quarter);
                    if (minMonthForQuarter == 0)
                    {
                        pastMonth = currentMonth;
                    }
                    else
                    {
                        pastMonth = minMonthForQuarter;
                    }

                    for (int i = pastMonth; i < currentMonth; i++)
                    {
                        FinancialExpandedResults tempResult = result;
                        tempResult.Month = i;
                        Console.WriteLine(tempResult.EmpName);
                        saveData(tempResult);
                    }
                }



                double considerableHours = 0;

                double extraOrLag = result.BillableHours - result.AllocatedHours;

                if (result.BillableHours >= result.AllocatedHours)
                {
                    considerableHours = result.AllocatedHours;
                }
                else
                {
                    considerableHours = result.BillableHours;
                }

                Debug.WriteLine("BillableType " + result.BillableType);
                Console.WriteLine(result.EmpName);
                result.Month = tempMonth;
                datarows     = this._db.Execute(@"INSERT FinancialResults([EmpId],[EmpName],[AccountId],[AccountName],[Year],[Month],[Quarter],[BillableType],[AllocatedHours],[BillableHours],[TotalReportedHours],[ConsiderableHours],[ExtraOrLag],[CumAllocatedHours],[CumBillableHours],[CumTotalReportedHours],[CumConsiderableHours]) values (@EmpId,@EmpName,@AccountId,@AccountName,@Year,@Month,@Quarter,@BillableType,@AllocatedHours,@BillableHours,@TotalReportedHours,@ConsiderableHours,@ExtraOrLag,@CumAllocatedHours,@CumBillableHours,@CumTotalReportedHours,@CumConsiderableHours)",
                                                new { EmpId = result.EmpId, EmpName = result.EmpName, AccountId = result.AccountId, AccountName = result.AccountName, Year = result.Year, Month = result.Month, Quarter = result.Quarter, BillableType = result.BillableType, AllocatedHours = result.AllocatedHours, BillableHours = result.BillableHours, TotalReportedHours = result.TotalReportedHours, ConsiderableHours = considerableHours, ExtraOrLag = extraOrLag, CumAllocatedHours = result.CumAllocatedHours, CumBillableHours = result.CumBillableHours, CumTotalReportedHours = result.CumTotalReportedHours, CumConsiderableHours = result.CumConsiderableHours });
            }

            if (usingEmpDataInAccount.Count != 0 && results.Count != 0)
            {
                foreach (int data in usingEmpDataInAccount)
                {
                    FinancialExpandedResults tempFinancialResult = new FinancialExpandedResults();
                    tempFinancialResult.EmpId = data;
                    TeamMembers employee = teamRepo.Get(data);
                    tempFinancialResult.EmpName     = employee.MemberName;
                    tempFinancialResult.Year        = results[0].Year;
                    tempFinancialResult.Month       = results[0].Month;
                    tempFinancialResult.Quarter     = results[0].Quarter;
                    tempFinancialResult.AccountId   = results[0].AccountId;
                    tempFinancialResult.AccountName = results[0].AccountName;
                    saveData(tempFinancialResult);
                }
            }

            return(datarows);
        }