Пример #1
0
 public AccrualLoan()
 {
     this.Amount            = (decimal)(new Random().Next(30, 70));
     this.ExpiryDate        = DateUtilities.GetFirstDayOfNextMonth().AddDays((double)(new Random().Next(4, 19)));
     this.CollectionRecords = new List <CollectionRecord>();
     this.RefNumber         = StringUtilities.GenerateKey(7).ToUpper();
 }
Пример #2
0
        public void TriggerMonthlyBilling(Guid userId)
        {
            var today = DateTime.Today;

            var endOfMonth = DateUtilities.GetLastDayOfCurrentMonth();

            if (today.Date != endOfMonth.Date)
            {
                // TODO:
                return;
            }

            var orginalMemberships = _identityRepository.GetUserByFilter(null).ToList().Where(m => m.UserType == Common.Enum.Enum.UserType.Membership);

            var memberships = ObjectMapper.Mapper.Map <IEnumerable <UserModel> >(orginalMemberships);

            foreach (var ms in memberships)
            {
                var hasAlready = ms.AccrualLoans.Any(m => m.Type == Common.Enum.Enum.AccrualLoanType.Invoice && m.CreatedAt.Year == today.Year && m.CreatedAt.Month == today.Month);

                if (hasAlready)
                {
                    // TODO:
                    continue;
                }

                var orginalMembership = orginalMemberships.FirstOrDefault(m => m.Id == ms.Id);

                var rnd                = new Random();
                var generatedAmount    = (decimal)rnd.Next(30, 70);
                var generatedDelayDays = rnd.Next(3, 17);

                orginalMembership.AccrualLoans.Add(new AccrualLoan()
                {
                    Amount            = generatedAmount,
                    ExpiryDate        = DateUtilities.GetFirstDayOfNextMonth().AddDays(generatedDelayDays),
                    CreatedById       = userId,
                    CreatedAt         = today.Date,
                    CollectionRecords = new List <CollectionRecord>()
                    {
                        /* */
                    }
                });


                _identityRepository.UpdateUser(orginalMembership);
            }
        }