Billing: Fix error when no deliveries exist in season
This commit is contained in:
		@@ -157,13 +157,15 @@ namespace Elwig.Helpers.Billing {
 | 
			
		||||
                lastMgNr = mgnr;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            await AppDbContext.ExecuteBatch(cnx, $"""
 | 
			
		||||
                UPDATE delivery_part_bucket SET value = 0 WHERE year = {Year};
 | 
			
		||||
                INSERT INTO delivery_part_bucket (year, did, dpnr, bktnr, discr, value)
 | 
			
		||||
                VALUES {string.Join(",\n       ", inserts.Select(i => $"({Year}, {i.Item1}, {i.Item2}, {i.Item3}, '{i.Item4}', {i.Item5})"))}
 | 
			
		||||
                ON CONFLICT DO UPDATE
 | 
			
		||||
                SET discr = excluded.discr, value = value + excluded.value;
 | 
			
		||||
                """);
 | 
			
		||||
            await AppDbContext.ExecuteBatch(cnx, $"UPDATE delivery_part_bucket SET value = 0 WHERE year = {Year}");
 | 
			
		||||
            if (inserts.Count > 0) {
 | 
			
		||||
                await AppDbContext.ExecuteBatch(cnx, $"""
 | 
			
		||||
                    INSERT INTO delivery_part_bucket (year, did, dpnr, bktnr, discr, value)
 | 
			
		||||
                    VALUES {string.Join(",\n       ", inserts.Select(i => $"({Year}, {i.Item1}, {i.Item2}, {i.Item3}, '{i.Item4}', {i.Item5})"))}
 | 
			
		||||
                    ON CONFLICT DO UPDATE
 | 
			
		||||
                    SET discr = excluded.discr, value = value + excluded.value;
 | 
			
		||||
                    """);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!avoidUnderDlvrs) {
 | 
			
		||||
                if (ownCnx) await cnx.DisposeAsync();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user