コード例 #1
0
        public PersonServedBySalesmanWithTotalTrxAmountAdded_Header CreateSalesmanReport_PeopleServedBySalesman(string userId)
        {
            userId.IsNullOrWhiteSpaceThrowException("Not logged in");


            int      noOfDaysSalesmanKeepsPerson = GetNoOfDaysSalesmanKeepsPerson();
            int      minimumAmountOfSaleRequired = GetMinimumRuppeeAmountRequiredToKeepPerson();
            DateTime beginDate = DateTime.Now.AddDays(-1 * noOfDaysSalesmanKeepsPerson);
            DateTime endDate   = DateTime.Now;



            Person salesmanPerson = PersonBiz.GetPersonForUserId(userId);

            salesmanPerson.IsNullThrowException("Salesman not found.");


            PersonServedBySalesmanWithTotalTrxAmountAdded_Header header = new PersonServedBySalesmanWithTotalTrxAmountAdded_Header(userId, salesmanPerson, beginDate, endDate, minimumAmountOfSaleRequired);

            header.Detail = ListPeopleBoughtOrSoldCashFromSalesman(header);
            return(header);
        }
コード例 #2
0
        /// <summary>
        /// this returns a grouped list with amounts summed of people that the salesman has serviced.
        /// </summary>
        /// <param name="salesmanId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        private List <PersonServedBySalesmanWithTotalTrxAmountAdded> ListPeopleBoughtOrSoldCashFromSalesman(PersonServedBySalesmanWithTotalTrxAmountAdded_Header header)
        {
            List <PersonServedBySalesman> listOfPeopleWhoSoldOrBoughtCashFromSalesman = getListOfPeopleOwnedBySalesmanFor(header.SalesmanPersonId, header.BeginDate, header.EndDate);

            //now group the people and add up their amounts. Note, we do not diffrentiate between Reciepts and payments. We want to see the
            //maximum transaction amount

            if (listOfPeopleWhoSoldOrBoughtCashFromSalesman.IsNullOrEmpty())
            {
                return(null);
            }

            //var query = (from t in Transactions
            //             group t by new { t.MaterialID, t.ProductID }
            //                 into grp
            //                 select new
            //                 {
            //                     grp.Key.MaterialID,
            //                     grp.Key.ProductID,
            //                     Quantity = grp.Sum(t => t.Quantity)
            //                 }).ToList();
            //https://stackoverflow.com/questions/847066/group-by-multiple-columns

            List <PersonServedBySalesmanWithTotalTrxAmountAdded> peopleWhoBoughtOrSoldCashToSalesman = (from p in listOfPeopleWhoSoldOrBoughtCashFromSalesman
                                                                                                        group p by p.PersonId
                                                                                                        into grp
                                                                                                        select new PersonServedBySalesmanWithTotalTrxAmountAdded
            {
                PersonId = grp.Key,
                Amount = grp.Sum(t => t.Amount),
                FirstDate = grp.Min(t => t.Date),
                LastDate = grp.Max(t => t.Date),
            })
                                                                                                       .ToList();

            if (peopleWhoBoughtOrSoldCashToSalesman.IsNullOrEmpty())
            {
                return(null);
            }

            foreach (PersonServedBySalesmanWithTotalTrxAmountAdded personAdded in peopleWhoBoughtOrSoldCashToSalesman)
            {
                PersonServedBySalesman personServedBySalesman = listOfPeopleWhoSoldOrBoughtCashFromSalesman.FirstOrDefault(x => x.PersonId == personAdded.PersonId);

                personServedBySalesman.IsNullThrowException("person Served By Salesman cannot be null");
                personServedBySalesman.Person.IsNullThrowException("person cannot be null");
                personAdded.Person = personServedBySalesman.Person;
            }

            return(peopleWhoBoughtOrSoldCashToSalesman);
        }