Files
elwig/Elwig/Documents/DeliveryConfirmation.cs

35 lines
1.5 KiB
C#

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 Season Season;
public IEnumerable<DeliveryPart> Deliveries;
public string? Text = App.Client.TextDeliveryConfirmation;
public Dictionary<string, (string, int, int, int, int)> MemberBuckets;
public DeliveryConfirmation(AppDbContext ctx, int year, Member m, IEnumerable<DeliveryPart>? deliveries = null) :
base($"Anlieferungsbestätigung {year}", m) {
Season = ctx.Seasons.Find(year) ?? throw new ArgumentException("invalid season");
ShowDateAndLocation = true;
UseBillingAddress = true;
IncludeSender = true;
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) = ({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();
MemberBuckets = ctx.GetMemberBuckets(Season.Year, m.MgNr).GetAwaiter().GetResult();
}
}
}