diff --git a/Elwig/Helpers/Billing/Billing.cs b/Elwig/Helpers/Billing/Billing.cs index ad82fee..3f2021c 100644 --- a/Elwig/Helpers/Billing/Billing.cs +++ b/Elwig/Helpers/Billing/Billing.cs @@ -43,6 +43,7 @@ namespace Elwig.Helpers.Billing { } public async Task CalculateBins() { + var forcedAttr = Context.WineAttributes.Where(a => !a.FillLowerBins).Select(a => a.AttrId).ToArray(); using var cnx = await AppDbContext.ConnectAsync(); var memberOblRig = await GetMemberRightsObligations(cnx, Year); var inserts = new List<(int, int, int, int, int, int, int)>(); @@ -84,7 +85,7 @@ namespace Elwig.Helpers.Billing { int w = weight; int[] b = new int[4]; - foreach (var p in Utils.Permutate(attributes)) { + foreach (var p in Utils.Permutate(attributes, attributes.Intersect(forcedAttr))) { var c = p.Count(); var key = sortid + string.Join("", p); if (rights.ContainsKey(key)) { diff --git a/Elwig/Helpers/Utils.cs b/Elwig/Helpers/Utils.cs index a2470c3..a5dcd06 100644 --- a/Elwig/Helpers/Utils.cs +++ b/Elwig/Helpers/Utils.cs @@ -327,13 +327,14 @@ namespace Elwig.Helpers { } } - public static IEnumerable> Permutate(IEnumerable input) { - List> output = new(); + public static IEnumerable> Permutate(IEnumerable input, IEnumerable? forced = null) { + HashSet> output = new(); for (int i = 0; i < Math.Pow(2, input.Count()); i++) { List t = new(); for (int j = 0; j < 30; j++) { - if ((i & (1 << j)) != 0) { - t.Add(input.ElementAt(j)); + var e = input.ElementAtOrDefault(j); + if (e != null && ((forced?.Contains(e) ?? false) || (i & (1 << j)) != 0)) { + t.Add(e); } } output.Add(t);