Billing: Fix error when no deliveries exist in season

This commit is contained in:
2024-08-14 10:45:03 +02:00
parent 367c3ac357
commit 48970de652

View File

@ -157,13 +157,15 @@ namespace Elwig.Helpers.Billing {
lastMgNr = mgnr; lastMgNr = mgnr;
} }
await AppDbContext.ExecuteBatch(cnx, $""" await AppDbContext.ExecuteBatch(cnx, $"UPDATE delivery_part_bucket SET value = 0 WHERE year = {Year}");
UPDATE delivery_part_bucket SET value = 0 WHERE year = {Year}; if (inserts.Count > 0) {
INSERT INTO delivery_part_bucket (year, did, dpnr, bktnr, discr, value) await AppDbContext.ExecuteBatch(cnx, $"""
VALUES {string.Join(",\n ", inserts.Select(i => $"({Year}, {i.Item1}, {i.Item2}, {i.Item3}, '{i.Item4}', {i.Item5})"))} INSERT INTO delivery_part_bucket (year, did, dpnr, bktnr, discr, value)
ON CONFLICT DO UPDATE VALUES {string.Join(",\n ", inserts.Select(i => $"({Year}, {i.Item1}, {i.Item2}, {i.Item3}, '{i.Item4}', {i.Item5})"))}
SET discr = excluded.discr, value = value + excluded.value; ON CONFLICT DO UPDATE
"""); SET discr = excluded.discr, value = value + excluded.value;
""");
}
if (!avoidUnderDlvrs) { if (!avoidUnderDlvrs) {
if (ownCnx) await cnx.DisposeAsync(); if (ownCnx) await cnx.DisposeAsync();