Billing: Add feature to calculate member/delivery bins
This commit is contained in:
41
Elwig/Helpers/Billing/BillingVariant.cs
Normal file
41
Elwig/Helpers/Billing/BillingVariant.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class BillingVariant : Billing {
|
||||
|
||||
private readonly int AvNr;
|
||||
|
||||
public BillingVariant(int year, int avnr) : base(year) {
|
||||
AvNr = avnr;
|
||||
}
|
||||
|
||||
protected async Task DeleteInDb() {
|
||||
using var cnx = await AppDbContext.ConnectAsync();
|
||||
using (var cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = $"DELETE FROM payment_delivery_part WHERE (year, avnr) = ({Year}, {AvNr})";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
using (var cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = $"DELETE FROM payment_member WHERE (year, avnr) = ({Year}, {AvNr})";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CalculatePrices() {
|
||||
await DeleteInDb();
|
||||
var tasks = new List<Task>();
|
||||
foreach (var mgnr in Context.Members.Select(m => m.MgNr)) {
|
||||
tasks.Add(Task.Run(() => CalculateMemberPrices(mgnr)));
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
protected async Task CalculateMemberPrices(int mgnr) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user