Billing: fix calculation
This commit is contained in:
@ -1,35 +1,34 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Documents {
|
||||
public class DeliveryConfirmation : BusinessDocument {
|
||||
|
||||
public int Year;
|
||||
public Season Season;
|
||||
public IEnumerable<DeliveryPart> Deliveries;
|
||||
public string? Text = App.Client.TextDeliveryConfirmation;
|
||||
public Dictionary<string, (string, int, int, int, int)> MemberBins;
|
||||
|
||||
public DeliveryConfirmation(AppDbContext ctx, int year, Member m, IEnumerable<DeliveryPart>? deliveries = null) :
|
||||
base($"Anlieferungsbestätigung {year}", m) {
|
||||
Year = year;
|
||||
Season = ctx.Seasons.Find(year) ?? throw new ArgumentException("invalid season");
|
||||
ShowDateAndLocation = true;
|
||||
UseBillingAddress = true;
|
||||
IncludeSender = true;
|
||||
DocumentId = $"Anl.-Best. {Year}/{m.MgNr}";
|
||||
DocumentId = $"Anl.-Best. {Season.Year}/{m.MgNr}";
|
||||
Deliveries = deliveries ?? ctx.DeliveryParts.FromSqlRaw($"""
|
||||
SELECT p.*
|
||||
FROM v_delivery v
|
||||
JOIN delivery_part p ON (p.year, p.did, p.dpnr) = (v.year, v.did, v.dpnr)
|
||||
WHERE (v.year, v.mgnr) = ({Year}, {m.MgNr})
|
||||
ORDER BY v.sortid, v.abgewertet ASC,
|
||||
COALESCE(LENGTH(v.attributes), 0) ASC, attribute_prio DESC, COALESCE(v.attributes, '~'),
|
||||
v.kmw DESC, v.lsnr, v.dpnr
|
||||
WHERE (v.year, v.mgnr) = ({Season.Year}, {m.MgNr})
|
||||
ORDER BY v.sortid, v.abgewertet ASC, v.attribute_prio DESC, COALESCE(v.attrid, '~'), v.kmw DESC, v.lsnr, v.dpnr
|
||||
""")
|
||||
.ToList();
|
||||
MemberBins = ctx.GetMemberBins(Year, m.MgNr).GetAwaiter().GetResult();
|
||||
MemberBins = ctx.GetMemberBins(Season.Year, m.MgNr).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user