using Elwig.Helpers; using Elwig.Models; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; using System.Linq; namespace Elwig.Documents { public class DeliveryConfirmation : BusinessDocument { public int Year; public IEnumerable Deliveries; public string? Text = App.Client.TextDeliveryConfirmation; public Dictionary MemberBins; public DeliveryConfirmation(AppDbContext ctx, int year, Member m, IEnumerable? deliveries = null) : base($"Anlieferungsbestätigung {year}", m) { Year = year; ShowDateAndLocation = true; UseBillingAddress = true; IncludeSender = true; DocumentId = $"Anl.-Best. {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 """) .ToList(); MemberBins = ctx.GetMemberBins(Year, m.MgNr).GetAwaiter().GetResult(); } } }