private double CalculateAgendaGroupDiscount(double agendaFee, Group group, AgendaResponseCount count) { double total = 0; if (group.Primary.Event.StartPage.GroupDiscount.GroupSizeOption == GroupDiscount_GroupSizeOption.SizeOrMore) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total += agendaFee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * count.count; } else { total += group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * count.count; } } else if (group.Primary.Event.StartPage.GroupDiscount.AddtionalRegOption == GroupDiscount_AdditionalRegOption.All) { for (int i = 1; i <= count.count; i++) { if (i % group.Primary.Event.StartPage.GroupDiscount.GroupSize == 0) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total += agendaFee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * group.Primary.Event.StartPage.GroupDiscount.GroupSize; } else { total += group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * group.Primary.Event.StartPage.GroupDiscount.GroupSize; } } } } else if (group.Primary.Event.StartPage.GroupDiscount.AddtionalRegOption == GroupDiscount_AdditionalRegOption.AnyAdditional) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total += agendaFee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * (count.count - group.Primary.Event.StartPage.GroupDiscount.GroupSize); } else { total += group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * (count.count - group.Primary.Event.StartPage.GroupDiscount.GroupSize); } } else if (group.Primary.Event.StartPage.GroupDiscount.AddtionalRegOption == GroupDiscount_AdditionalRegOption.Additional) { for (int i = 1; i <= count.count; i++) { if ((i > group.Primary.Event.StartPage.GroupDiscount.GroupSize) && (i <= group.Primary.Event.StartPage.GroupDiscount.NumberOfAdditionalReg.Value + count.count)) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total += agendaFee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0; } else { total += group.Primary.Event.StartPage.GroupDiscount.DiscountAmount; } } } } return total; }
private double CalculateGroupDiscount(Group group) { double total = 0; total += this.CalculateSingleReg(group.Primary); foreach (Registrant reg in group.Secondaries) { total += this.CalculateSingleReg(reg); } List<Registrant> regs = new List<Registrant>(); regs.Add(group.Primary); foreach (Registrant reg in group.Secondaries) { regs.Add(reg); } List<EventFeeResponse> regEventFeeResponses = new List<EventFeeResponse>(); List<AgendaResponse> regAgendaResponses = new List<AgendaResponse>(); foreach (Registrant reg in regs) { if (reg.EventFee_Response != null) { regEventFeeResponses.Add(reg.EventFee_Response); } foreach (CustomFieldResponse resp in reg.CustomField_Responses) { if (resp is AgendaResponse) { AgendaResponse response = resp as AgendaResponse; switch (response.AgendaItem.Type) { case FormData.CustomFieldType.AlwaysSelected: case FormData.CustomFieldType.CheckBox: case FormData.CustomFieldType.RadioButton: case FormData.CustomFieldType.Dropdown: case FormData.CustomFieldType.Contribution: case FormData.CustomFieldType.FileUpload: regAgendaResponses.Add(response); break; default: break; } } } } List<EventFeeResponseCount> eventFeeResponseCount = new List<EventFeeResponseCount>(); List<AgendaResponseCount> agendaResponseCount = new List<AgendaResponseCount>(); foreach (EventFeeResponse resp in regEventFeeResponses) { if (eventFeeResponseCount.Exists(e => e.EventFee_Response.RegType == resp.RegType)) { eventFeeResponseCount.Find(e => e.EventFee_Response.RegType == resp.RegType).count += 1; } else if ((group.Primary.Event.StartPage.GroupDiscount != null) && group.Primary.Event.StartPage.GroupDiscount.ApplyToRegTypes.Count != 0) { if (group.Primary.Event.StartPage.GroupDiscount.ApplyToRegTypes.Exists(r => r == resp.RegType)) { EventFeeResponseCount responseCount = new EventFeeResponseCount(); responseCount.EventFee_Response = resp; responseCount.count = 1; eventFeeResponseCount.Add(responseCount); } } else { EventFeeResponseCount responseCount = new EventFeeResponseCount(); responseCount.EventFee_Response = resp; responseCount.count = 1; eventFeeResponseCount.Add(responseCount); } } foreach (AgendaResponse resp in regAgendaResponses) { if (agendaResponseCount.Exists(a => a.Agenda_Response.AgendaItem == resp.AgendaItem)) { agendaResponseCount.Find(a => a.Agenda_Response.AgendaItem == resp.AgendaItem).count += 1; } else if ((group.Primary.Event.StartPage.GroupDiscount != null) && group.Primary.Event.StartPage.GroupDiscount.ApplyToAgendaItems.Count != 0) { if (group.Primary.Event.StartPage.GroupDiscount.ApplyToAgendaItems.Exists(a => a == resp.AgendaItem)) { AgendaResponseCount responseCount = new AgendaResponseCount(); responseCount.Agenda_Response = resp; responseCount.count = 1; agendaResponseCount.Add(responseCount); } } else { AgendaResponseCount responseCount = new AgendaResponseCount(); responseCount.Agenda_Response = resp; responseCount.count = 1; agendaResponseCount.Add(responseCount); } } foreach (EventFeeResponseCount count in eventFeeResponseCount) { if ((group.Primary.Event.StartPage.GroupDiscount != null) && (count.count >= group.Primary.Event.StartPage.GroupDiscount.GroupSize) && (group.Primary.Event.StartPage.GroupDiscount.ShowAndApply)) { if (group.Primary.Event.StartPage.GroupDiscount.GroupSizeOption == GroupDiscount_GroupSizeOption.SizeOrMore) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * count.count; count.EventFee_Response.Fee -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * count.count; } else { total -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * count.count; count.EventFee_Response.Fee -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * count.count; } } else if (group.Primary.Event.StartPage.GroupDiscount.AddtionalRegOption == GroupDiscount_AdditionalRegOption.All) { for (int i = 1; i <= count.count; i++) { if (i % group.Primary.Event.StartPage.GroupDiscount.GroupSize == 0) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * group.Primary.Event.StartPage.GroupDiscount.GroupSize; count.EventFee_Response.Fee -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * group.Primary.Event.StartPage.GroupDiscount.GroupSize; } else { total -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * group.Primary.Event.StartPage.GroupDiscount.GroupSize; count.EventFee_Response.Fee -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * group.Primary.Event.StartPage.GroupDiscount.GroupSize; } } } } else if (group.Primary.Event.StartPage.GroupDiscount.AddtionalRegOption == GroupDiscount_AdditionalRegOption.AnyAdditional) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * (count.count - group.Primary.Event.StartPage.GroupDiscount.GroupSize); count.EventFee_Response.Fee -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0 * (count.count - group.Primary.Event.StartPage.GroupDiscount.GroupSize); } else { total -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * (count.count - group.Primary.Event.StartPage.GroupDiscount.GroupSize); count.EventFee_Response.Fee -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount * (count.count - group.Primary.Event.StartPage.GroupDiscount.GroupSize); } } else if (group.Primary.Event.StartPage.GroupDiscount.AddtionalRegOption == GroupDiscount_AdditionalRegOption.Additional) { for (int i = 1; i <= count.count; i++) { if ((i > group.Primary.Event.StartPage.GroupDiscount.GroupSize) && (i <= group.Primary.Event.StartPage.GroupDiscount.NumberOfAdditionalReg.Value)) { if (group.Primary.Event.StartPage.GroupDiscount.GroupDiscountType == GroupDiscount_DiscountType.Percent) { total -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0; count.EventFee_Response.Fee -= count.EventFee_Response.Fee * group.Primary.Event.StartPage.GroupDiscount.DiscountAmount / 100.0; } else { total -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount; count.EventFee_Response.Fee -= group.Primary.Event.StartPage.GroupDiscount.DiscountAmount; } } } } } } foreach (AgendaResponseCount count in agendaResponseCount) { if ((group.Primary.Event.StartPage.GroupDiscount != null) && (count.count >= group.Primary.Event.StartPage.GroupDiscount.GroupSize) && (group.Primary.Event.StartPage.GroupDiscount.ShowAndApply)) { switch(count.Agenda_Response.AgendaItem.Type) { case FormData.CustomFieldType.AlwaysSelected: AgendaResponse_AlwaysSelected respAlways = count.Agenda_Response as AgendaResponse_AlwaysSelected; respAlways.Fee = total -= this.CalculateAgendaGroupDiscount(respAlways.Fee, group, count); break; case FormData.CustomFieldType.CheckBox: AgendaResponse_Checkbox respCheck = count.Agenda_Response as AgendaResponse_Checkbox; respCheck.Fee = total -= this.CalculateAgendaGroupDiscount(respCheck.Fee, group, count); break; case FormData.CustomFieldType.RadioButton: AgendaResponse_MultipleChoice_RadioButton respRadio = count.Agenda_Response as AgendaResponse_MultipleChoice_RadioButton; respRadio.Fee = total -= this.CalculateAgendaGroupDiscount(respRadio.Fee, group, count); break; case FormData.CustomFieldType.Dropdown: AgendaResponse_MultipleChoice_DropDown respDrop = count.Agenda_Response as AgendaResponse_MultipleChoice_DropDown; respDrop.Fee = total -= this.CalculateAgendaGroupDiscount(respDrop.Fee, group, count); break; case FormData.CustomFieldType.Contribution: AgendaResponse_Contribution respContri = count.Agenda_Response as AgendaResponse_Contribution; respContri.ContributionAmount = total -= this.CalculateAgendaGroupDiscount(respContri.ContributionAmount, group, count); break; case FormData.CustomFieldType.FileUpload: AgendaResponse_FileUpload respFile = count.Agenda_Response as AgendaResponse_FileUpload; respFile.Fee = total -= this.CalculateAgendaGroupDiscount(respFile.Fee, group, count); break; default: break; } } } return total; }