public IActionResult GetSubscriptionYears() { var dto = new SubscriptionYearsDTO(); var startofYear = options.GetFirstDayOfYear(DateTimeOffset.Now); int year = startofYear.Year; dto.SubscriptionYears = new List <string>(); for (int i = year + options.SubscriptionYearFrom; i < year + options.SubscriptionYearTo; ++i) { dto.SubscriptionYears.Add(options.GetSubscriptionYear(i)); } dto.CurrentSubscriptionYear = options.GetCurrentSubscriptionYear(); return(SuccessResult(dto)); }
private static int CalculateSubscription(this Member m, QParaOptions options) { int amountDue = 0; if (m.ShouldMakePayments()) { var year = options.GetFirstDayOfYear(DateTimeOffset.Now).Year; var currentYear = options.GetSubscriptionYear(year); switch (m.SubscriptionType) { case SubscriptionType.Unknown: case SubscriptionType.Standard: amountDue = m.PaymentMethod == PaymentMethod.Regular ? 8 : 10; break; case SubscriptionType.Concession: amountDue = m.PaymentMethod == PaymentMethod.Regular ? 4 : 5; break; } if (m.MemberCount > 1) { amountDue *= m.MemberCount; } } return(amountDue); }
private void UpdatePaymentStatus(IIncludableQueryable <Member, ICollection <Change> > members, QParaOptions options, ILogger log) { this.ChangeTracker.AutoDetectChangesEnabled = false; var selectedMembers = members .Where(x => x.SubscriptionPeriod != SubscriptionPeriod.Life && (x.SubscriptionType == SubscriptionType.Standard || x.SubscriptionType == SubscriptionType.Concession)) ; var notSelectedMembers = members.Except(selectedMembers).Where(x => !x.GetIsPaid(options) /*!x.IsPaid*/); foreach (var m in notSelectedMembers.ToArray()) { if (m.AmountDue != 0 || m.AmountReceived != 0) { m.AmountDue = m.AmountReceived = 0; log.Information($"{m.FirstName} {m.LastName} due and received amounts reset (to 0)"); //SaveChanges(); } } var subscriptionYear = options.GetSubscriptionYear(DateTimeOffset.UtcNow); foreach (var m in selectedMembers.ToArray()) { m.UpdatePaymentRecords(options, true); //SaveChanges(); } ChangeTracker.DetectChanges(); SaveChanges(); this.ChangeTracker.AutoDetectChangesEnabled = true; }
public static void UpdatePaymentRecords(this Member m, QParaOptions options, bool writeChanges) { if (m.ShouldMakePayments()) { var amountDue = m.CalculateSubscription(options); if (m.AmountDue != amountDue) { if (writeChanges) { m.Changes.Add(new Change { Member = m, Date = DateTimeOffset.Now, MadeBy = "System", Description = $"Amount Due changed from £{m.AmountDue} to £{amountDue}" }); } m.AmountDue = amountDue; } var subscriptionYear = options.GetSubscriptionYear(DateTimeOffset.UtcNow); var amountReceived = m.Payments.Where(x => x.SubscriptionYear == subscriptionYear).Sum(x => x.AmountReceived); var isWaived = m.Payments.Where(x => x.SubscriptionYear == subscriptionYear).Any(x => x.IsPaid); if (m.AmountReceived != amountReceived) { if (writeChanges) { m.Changes.Add(new Change { Member = m, Date = DateTimeOffset.Now, MadeBy = "System", Description = $"Amount Received changed from £{m.AmountReceived} to £{amountReceived}" }); } m.AmountReceived = amountReceived; } if (isWaived) { m.PaymentIsOutstanding = false; } else { m.PaymentIsOutstanding = m.AmountReceived < m.AmountDue; } //if (m.AmountReceived < m.AmountDue) //{ // m.PaymentIsOutstanding = true; //} } else { m.PaymentIsOutstanding = false; } }