Models: Add Entities/ folder

This commit is contained in:
2023-11-10 13:48:25 +01:00
parent 2f98df87a0
commit 32f229b0a5
63 changed files with 63 additions and 68 deletions

View File

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("AT_gem"), PrimaryKey("Gkz")]
public class AT_Gem {
[Column("gkz")]
public int Gkz { get; private set; }
[Column("name")]
public string Name { get; private set; }
[InverseProperty("Gem")]
public virtual ISet<AT_Kg> Kgs { get; private set; }
[InverseProperty("AtGem")]
public virtual WbGem? WbGem { get; private set; }
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("AT_kg"), PrimaryKey("KgNr")]
public class AT_Kg {
[Column("kgnr")]
public int KgNr { get; private set; }
[Column("gkz")]
public int Gkz { get; private set; }
[Column("name")]
public string Name { get; private set; }
[ForeignKey("Gkz")]
public virtual AT_Gem Gem { get; private set; }
[InverseProperty("AtKg")]
public virtual WbKg WbKg { get; private set; }
}
}

View File

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("AT_ort"), PrimaryKey("Okz")]
public class AT_Ort {
[Column("okz")]
public int Okz { get; private set; }
[Column("gkz")]
public int Gkz { get; private set; }
[Column("kgnr")]
public int? KgNr { get; private set; }
[Column("name")]
public string Name { get; private set; }
[ForeignKey("Gkz")]
public virtual AT_Gem Gem { get; private set; }
[ForeignKey("KgNr")]
public virtual AT_Kg? Kg { get; private set; }
}
}

View File

@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("AT_plz"), PrimaryKey("Plz")]
public class AT_Plz {
[Column("plz")]
public int Plz { get; private set; }
[Column("ort")]
public string Ort { get; private set; }
[Column("blnr")]
public int BlNr { get; private set; }
[Column("type")]
public string Type { get; private set; }
[Column("internal")]
public bool IsInternal { get; private set; }
[Column("addressable")]
public bool IsAddressable { get; private set; }
[Column("po_box")]
public bool IsPoBox { get; private set; }
[InverseProperty("AtPlz")]
public virtual ISet<AT_PlzDest> Orte { get; private set; }
}
}

View File

@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("AT_plz_dest"), PrimaryKey("Id"), Index("Plz", "Okz", IsUnique = true)]
public class AT_PlzDest {
[Column("plz")]
public int Plz { get; private set; }
[Column("okz")]
public int Okz { get; private set; }
[Column("country")]
public int CountryNum { get; private set; }
[Column("id")]
public string Id { get; private set; }
[Column("dest")]
public string Dest { get; private set; }
[ForeignKey("Plz")]
public virtual AT_Plz AtPlz { get; private set; }
[ForeignKey("Okz")]
public virtual AT_Ort Ort { get; private set; }
[ForeignKey("CountryNum")]
public virtual Country Country { get; private set; }
}
}

View File

@ -0,0 +1,65 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Elwig.Models.Entities {
[Table("area_commitment"), PrimaryKey("FbNr")]
public class AreaCom {
[Column("fbnr")]
public int FbNr { get; set; }
[Column("mgnr")]
public int MgNr { get; set; }
[Column("vtrgid")]
public string VtrgId { get; set; }
[Column("cultid")]
public string CultId { get; set; }
[Column("area")]
public int Area { get; set; }
[Column("kgnr")]
public int KgNr { get; set; }
[Column("gstnr")]
public string GstNr { get; set; }
[Column("rdnr")]
public int? RdNr { get; set; }
[Column("year_from")]
public int YearFrom { get; set; }
[Column("year_to")]
public int? YearTo { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
[ForeignKey("VtrgId")]
public virtual AreaComType AreaComType { get; private set; }
[ForeignKey("CultId")]
public virtual WineCult WineCult { get; private set; }
[ForeignKey("KgNr")]
public virtual WbKg Kg { get; private set; }
[ForeignKey("KgNr, RdNr")]
public virtual WbRd? Rd { get; private set; }
public int SearchScore(IEnumerable<string> keywords) {
var list = new string?[] {
WineCult.Name, Kg.AtKg.Name, Rd.Name, GstNr, Comment,
}.ToList();
return Utils.GetSearchScore(list, keywords);
}
}
}

View File

@ -0,0 +1,57 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("area_commitment_type"), PrimaryKey("VtrgId"), Index("SortId", "AttrId", "Discriminator", IsUnique = true)]
public class AreaComType {
[Column("vtrgid")]
public string VtrgId { get; set; }
[Column("sortid")]
public string SortId { get; set; }
[Column("attrid")]
public string? AttrId { get; set; }
[Column("disc")]
public string? Discriminator { get; set; }
[Column("min_kg_per_ha")]
public int? MinKgPerHa { get; set; }
[Column("penalty_per_kg")]
public long? PenaltyPerKgValue { get; set; }
[NotMapped]
public decimal? PenaltyPerKg {
get => PenaltyPerKgValue != null ? Utils.DecFromDb(PenaltyPerKgValue.Value, 4) : null;
set => PenaltyPerKgValue = value != null ? Utils.DecToDb(value.Value, 4) : null;
}
[Column("penalty_amount")]
public long? PenaltyAmoutValue { get; set; }
[NotMapped]
public decimal? PenaltyAmount {
get => PenaltyAmoutValue != null ? Utils.DecFromDb(PenaltyAmoutValue.Value, 4) : null;
set => PenaltyAmoutValue = value != null ? Utils.DecToDb(value.Value, 4) : null;
}
[Column("penalty_none")]
public long? PenaltyNoneValue { get; set; }
[NotMapped]
public decimal? PenaltyNone {
get => PenaltyNoneValue != null ? Utils.DecFromDb(PenaltyNoneValue.Value, 4) : null;
set => PenaltyNoneValue = value != null ? Utils.DecToDb(value.Value, 4) : null;
}
[ForeignKey("SortId")]
public virtual WineVar WineVar { get; private set; }
[ForeignKey("AttrId")]
public virtual WineAttr? WineAttr { get; private set; }
[NotMapped]
public string DisplayName => WineVar.Name + (WineAttr != null ? $" {WineAttr.Name}" : "") + (Discriminator != null ? $" ({Discriminator})" : "");
}
}

View File

@ -0,0 +1,32 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("member_billing_address"), PrimaryKey("MgNr")]
public class BillingAddr : IAddress {
[Column("mgnr")]
public int MgNr { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("country")]
public int CountryNum { get; set; }
[Column("postal_dest")]
public string PostalDestId { get; set; }
[Column("address")]
public string Address { get; set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
[ForeignKey("CountryNum")]
public virtual Country Country { get; private set; }
[ForeignKey("CountryNum, PostalDestId")]
public virtual PostalDest PostalDest { get; private set; }
}
}

View File

@ -0,0 +1,42 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("branch"), PrimaryKey("ZwstId"), Index("Name", IsUnique = true)]
public class Branch {
[Column("zwstid")]
public string ZwstId { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("country")]
public int? CountryNum { get; set; }
[Column("postal_dest")]
public string? PostalDestId { get; set; }
[Column("address")]
public string? Address { get; set; }
[ForeignKey("CountryNum")]
public virtual Country? Country { get; private set; }
[ForeignKey("CountryNum, PostalDestId")]
public virtual PostalDest? PostalDest { get; private set; }
[Column("phone_nr")]
public string? PhoneNr { get; set; }
[Column("fax_nr")]
public string? FaxNr { get; set; }
[Column("mobile_nr")]
public string? MobileNr { get; set; }
[InverseProperty("Branch")]
public virtual ISet<Member> Members { get; private set; }
}
}

View File

@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("client_parameter"), PrimaryKey("Param")]
public class ClientParam {
[Column("param")]
public string Param { get; set; }
[Column("value")]
public string? Value { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("country"), PrimaryKey("Num"), Index("Alpha2", IsUnique = true), Index("Alpha3", IsUnique = true)]
public class Country {
[Column("num")]
public int Num { get; private set; }
[Column("alpha2")]
public string Alpha2 { get; private set; }
[Column("alpha3")]
public string Alpha3 { get; private set; }
[Column("name")]
public string Name { get; private set; }
[Column("is_visible")]
public bool IsVisible { get; private set; }
}
}

View File

@ -0,0 +1,105 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("credit"), PrimaryKey("Year", "TgNr"), Index("Year", "AvNr", "MgNr", IsUnique = true)]
public class Credit {
[Column("year")]
public int Year { get; set; }
[Column("tgnr")]
public int TgNr { get; set; }
[NotMapped]
public string TgId => $"{Year}/{TgNr:000}";
[Column("mgnr")]
public int MgNr { get; set; }
[Column("avnr")]
public int AvNr { get; set; }
[Column("net_amount")]
public long NetAmountValue { get; set; }
[NotMapped]
public decimal NetAmount {
get => Utils.DecFromDb(NetAmountValue, 2);
set => NetAmountValue = Utils.DecToDb(value, 2);
}
[Column("prev_net_amount")]
public long? PrevNetAmountValue { get; set; }
[NotMapped]
public decimal? PrevNetAmount {
get => PrevNetAmountValue != null ? Utils.DecFromDb(PrevNetAmountValue.Value, 2) : null;
set => PrevNetAmountValue = value != null ? Utils.DecToDb(value.Value, 2) : null;
}
[Column("vat")]
public double VatValue { get; set; }
[NotMapped]
public decimal Vat {
get => (decimal)VatValue;
set => VatValue = (double)value;
}
[Column("vat_amount")]
public long VatAmountValue { get; private set; }
[NotMapped]
public decimal VatAmount {
get => Utils.DecFromDb(VatAmountValue, 2);
}
[Column("gross_amount")]
public long GrossAmountValue { get; private set; }
[NotMapped]
public decimal GrossAmount {
get => Utils.DecFromDb(GrossAmountValue, 2);
}
[Column("modifiers")]
public long? ModifiersValue { get; set; }
[NotMapped]
public decimal? Modifiers {
get => ModifiersValue != null ? Utils.DecFromDb(ModifiersValue.Value, 2) : null;
set => ModifiersValue = value != null ? Utils.DecToDb(value.Value, 2) : null;
}
[Column("prev_modifiers")]
public long? PrevModifiersValue { get; set; }
[NotMapped]
public decimal? PrevModifiers {
get => PrevModifiersValue != null ? Utils.DecFromDb(PrevModifiersValue.Value, 2) : null;
set => PrevModifiersValue = value != null ? Utils.DecToDb(value.Value, 2) : null;
}
[Column("amount")]
public long AmountValue { get; private set; }
[NotMapped]
public decimal Amount {
get => Utils.DecFromDb(AmountValue, 2);
}
[Column("ctime")]
public long CTime { get; private set; }
[NotMapped]
public DateTime CreatedTimestamp => DateTimeOffset.FromUnixTimeSeconds(CTime).LocalDateTime;
[Column("mtime")]
public long MTime { get; private set; }
[NotMapped]
public DateTime ModifiedTimestamp => DateTimeOffset.FromUnixTimeSeconds(CTime).LocalDateTime;
[ForeignKey("Year, AvNr, MgNr")]
public virtual PaymentMember Payment { get; private set; }
[ForeignKey("Year, AvNr")]
public virtual PaymentVar Variant { get; private set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
}
}

View File

@ -0,0 +1,23 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("currency"), PrimaryKey("Code")]
public class Currency {
[Column("code")]
public string Code { get; private set; }
[Column("name")]
public string Name { get; private set; }
[Column("symbol")]
public string? Symbol { get; private set; }
[Column("one_euro")]
public long? OneEuroValue { get; private set; }
[NotMapped]
public decimal? OneEuro => OneEuroValue != null ? Utils.DecFromDb(OneEuroValue.Value, 6) : null;
}
}

View File

@ -0,0 +1,95 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("delivery"), PrimaryKey("Year", "DId"), Index("DateString", "ZwstId", "LNr", IsUnique = true), Index("LsNr", IsUnique = true)]
public class Delivery {
[Column("year")]
public int Year { get; set; }
[Column("did")]
public int DId { get; set; }
[Column("date")]
public string DateString { get; set; }
[NotMapped]
public DateOnly Date {
get => DateOnly.ParseExact(DateString, "yyyy-MM-dd");
set => DateString = value.ToString("yyyy-MM-dd");
}
[Column("time")]
public string? TimeString { get; set; }
[NotMapped]
public TimeOnly? Time {
get => (TimeString == null) ? null : TimeOnly.ParseExact(TimeString, "HH:mm:ss");
set => TimeString = value?.ToString("HH:mm:ss");
}
[NotMapped]
public DateTime DateTime {
get => Date.ToDateTime(Time ?? TimeOnly.MinValue);
set {
Date = DateOnly.FromDateTime(value);
Time = TimeOnly.FromDateTime(value);
}
}
[Column("zwstid")]
public string ZwstId { get; set; }
[ForeignKey("ZwstId")]
public virtual Branch Branch { get; private set; }
[Column("lnr")]
public int LNr { get; set; }
[Column("lsnr")]
public string LsNr { get; set; }
[Column("mgnr")]
public int MgNr { get; set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("Year")]
public virtual Season Season { get; private set; }
[InverseProperty("Delivery")]
public virtual ISet<DeliveryPart> Parts { get; private set; }
public int Weight => Parts.Select(p => p.Weight).Sum();
public IEnumerable<string> SortIds => Parts
.GroupBy(p => p.SortId)
.OrderByDescending(g => g.Select(p => p.Weight).Sum())
.Select(g => g.Select(p => p.SortId).First());
public string SortIdString => string.Join(", ", SortIds);
public double Kmw => Utils.AggregateDeliveryPartsKmw(Parts);
public double Oe => Utils.KmwToOe(Kmw);
public int SearchScore(IEnumerable<string> keywords) {
var list = new string?[] {
LsNr, Time?.ToString("HH:mm"),
Member.FamilyName, Member.MiddleName, Member.GivenName, Member.BillingAddress?.Name,
Comment
}.ToList();
list.AddRange(Parts.Select(p => p.Comment).Distinct());
return Utils.GetSearchScore(list, keywords);
}
}
}

View File

@ -0,0 +1,120 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Elwig.Models.Entities {
[Table("delivery_part"), PrimaryKey("Year", "DId", "DPNr")]
public class DeliveryPart {
[Column("year")]
public int Year { get; set; }
[Column("did")]
public int DId { get; set; }
[ForeignKey("Year, DId")]
public virtual Delivery Delivery { get; private set; }
[Column("dpnr")]
public int DPNr { get; set; }
[Column("sortid")]
public string SortId { get; set; }
[ForeignKey("SortId")]
public virtual WineVar Variant { get; private set; }
[Column("attrid")]
public string? AttrId { get; set; }
[ForeignKey("AttrId")]
public virtual WineAttr? Attribute { get; private set; }
[Column("weight")]
public int Weight { get; set; }
[Column("kmw")]
public double Kmw { get; set; }
[NotMapped]
public double Oe {
get => Utils.KmwToOe(Kmw);
set => Kmw = Utils.OeToKmw(value);
}
[Column("qualid")]
public string QualId { get; set; }
[ForeignKey("QualId")]
public virtual WineQualLevel Quality { get; private set; }
[Column("hkid")]
public string HkId { get; set; }
[ForeignKey("HkId")]
public virtual WineOrigin Origin { get; private set; }
[Column("kgnr")]
public int? KgNr { get; set; }
[ForeignKey("KgNr")]
public virtual WbKg? Kg { get; private set; }
[Column("rdnr")]
public int? RdNr { get; set; }
[ForeignKey("KgNr, RdNr")]
public virtual WbRd? Rd { get; private set; }
[Column("gerebelt")]
public bool IsGerebelt { get; set; }
[Column("manual_weighing")]
public bool ManualWeighing { get; set; }
[Column("spl_check")]
public bool SplCheck { get; set; }
[Column("hand_picked")]
public bool? IsHandPicked { get; set; }
[Column("lesewagen")]
public bool? IsLesewagen { get; set; }
[Column("gebunden")]
public bool? IsGebunden { get; set; }
[Column("temperature")]
public double? Temperature { get; set; }
[Column("acid")]
public double? Acid { get; set; }
[Column("scale_id")]
public string? ScaleId { get; set; }
[Column("weighing_id")]
public string? WeighingId { get; set; }
[Column("weighing_reason")]
public string? WeighingReason { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[InverseProperty("Part")]
public virtual ISet<DeliveryPartModifier> PartModifiers { get; private set; }
[NotMapped]
public IEnumerable<Modifier> Modifiers => PartModifiers.Select(m => m.Modifier).OrderBy(m => m.Ordering);
[InverseProperty("DeliveryPart")]
public virtual PaymentDeliveryPart? Payment { get; private set; }
[NotMapped]
public string OriginString => Origin.OriginString + "\n" + (Kg?.Gl != null ? $" / {Kg.Gl.Name}" : "") + (Kg != null ? $" / {Kg.AtKg.Gem.Name} / KG {Kg.AtKg.Name}" : "") + (Rd != null ? $" / Ried {Rd.Name}" : "");
[InverseProperty("Part")]
public virtual ISet<DeliveryPartBucket> Buckets { get; private set; }
}
}

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("delivery_part_bucket"), PrimaryKey("Year", "DId", "DPNr", "BktNr")]
public class DeliveryPartBucket {
[Column("year")]
public int Year { get; set; }
[Column("did")]
public int DId { get; set; }
[Column("dpnr")]
public int DPNr { get; set; }
[Column("bktnr")]
public int BktNr { get; set; }
[Column("discr")]
public string Discr { get; set; }
[Column("value")]
public int Value { get; set; }
[ForeignKey("Year, DId, DPNr")]
public virtual DeliveryPart Part { get; private set; }
}
}

View File

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("delivery_part_modifier"), PrimaryKey("Year", "DId", "DPNr", "ModId")]
public class DeliveryPartModifier {
[Column("year")]
public int Year { get; set; }
[Column("did")]
public int DId { get; set; }
[Column("dpnr")]
public int DPNr { get; set; }
[ForeignKey("Year, DId, DPNr")]
public virtual DeliveryPart Part { get; private set; }
[Column("modid")]
public string ModId { get; set; }
[ForeignKey("Year, ModId")]
public virtual Modifier Modifier { get; private set; }
}
}

View File

@ -0,0 +1,191 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Elwig.Models.Entities {
[Table("member"), PrimaryKey("MgNr")]
public class Member : IAddress {
[Column("mgnr")]
public int MgNr { get; set; }
[Column("predecessor_mgnr")]
public int? PredecessorMgNr { get; set; }
[Column("prefix")]
public string? Prefix { get; set; }
[Column("given_name")]
public string GivenName { get; set; }
[Column("middle_names")]
public string? MiddleName { get; set; }
[NotMapped]
public string[] MiddleNames {
get { return (MiddleName != null) ? MiddleName.Split(" ") : Array.Empty<string>(); }
set { MiddleName = (value.Length > 0) ? string.Join(" ", value) : null; }
}
[Column("family_name")]
public string FamilyName { get; set; }
[Column("suffix")]
public string? Suffix { get; set; }
public string Name =>
(Prefix != null ? Prefix + " " : "") +
GivenName + " " +
(MiddleName != null ? MiddleName + " " : "") +
FamilyName +
(Suffix != null ? " " + Suffix : "");
public string ShortName => GivenName + " " + FamilyName;
public string AdministrativeName => AdministrativeName1 + " " + AdministrativeName2;
public string AdministrativeName1 => FamilyName.ToUpper();
public string AdministrativeName2 =>
(Prefix != null ? Prefix + " " : "") +
GivenName +
(MiddleName != null ? " " + MiddleName : "") +
(Suffix != null ? " " + Suffix : "");
[Column("birthday")]
public string? Birthday { get; set; }
[Column("entry_date")]
public string? EntryDateString { get; set; }
[NotMapped]
public DateOnly? EntryDate {
get {
return EntryDateString != null ? DateOnly.ParseExact(EntryDateString, "yyyy-MM-dd") : null;
}
set {
EntryDateString = value?.ToString("yyyy-MM-dd");
}
}
[Column("exit_date")]
public string? ExitDateString { get; set; }
[NotMapped]
public DateOnly? ExitDate {
get {
return ExitDateString != null ? DateOnly.ParseExact(ExitDateString, "yyyy-MM-dd") : null;
}
set {
ExitDateString = value?.ToString("yyyy-MM-dd");
}
}
[Column("business_shares")]
public int BusinessShares { get; set; }
[Column("accounting_nr")]
public string? AccountingNr { get; set; }
[Column("zwstid")]
public string? ZwstId { get; set; }
[Column("lfbis_nr")]
public string? LfbisNr { get; set; }
[Column("ustid_nr")]
public string? UstIdNr { get; set; }
[Column("volllieferant")]
public bool IsVollLieferant { get; set; }
[Column("buchführend")]
public bool IsBuchführend { get; set; }
[Column("organic")]
public bool IsOrganic { get; set; }
[Column("funktionär")]
public bool IsFunktionär { get; set; }
[Column("active")]
public bool IsActive { get; set; }
[Column("deceased")]
public bool IsDeceased { get; set; }
[Column("iban")]
public string? Iban { get; set; }
[Column("bic")]
public string? Bic { get; set; }
[Column("country")]
public int CountryNum { get; set; }
[Column("postal_dest")]
public string PostalDestId { get; set; }
[Column("address")]
public string Address { get; set; }
[Column("default_kgnr")]
public int? DefaultKgNr { get; set; }
[Column("contact_postal")]
public bool ContactViaPost { get; set; }
[Column("contact_email")]
public bool ContactViaEmail { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("PredecessorMgNr")]
public virtual Member? Predecessor { get; private set; }
[ForeignKey("CountryNum")]
public virtual Country Country { get; private set; }
[ForeignKey("CountryNum, PostalDestId")]
public virtual PostalDest PostalDest { get; private set; }
[ForeignKey("DefaultKgNr")]
public virtual AT_Kg? DefaultKg { get; private set; }
[ForeignKey("ZwstId")]
public virtual Branch? Branch { get; private set; }
[InverseProperty("Member")]
public virtual ISet<AreaCom> AreaCommitments { get; private set; }
[NotMapped]
public IEnumerable<AreaCom> ActiveAreaCommitments => AreaCommitments
.Where(c => c.YearFrom <= Utils.CurrentNextSeason && (c.YearTo ?? int.MaxValue) >= Utils.CurrentNextSeason);
[InverseProperty("Member")]
public virtual BillingAddr? BillingAddress { get; private set; }
[InverseProperty("Member")]
public virtual ISet<Delivery> Deliveries { get; private set; }
[InverseProperty("Member")]
public virtual ISet<MemberTelNr> TelephoneNumbers { get; private set; }
[InverseProperty("member")]
public virtual ISet<MemberEmailAddr> EmailAddresses { get; private set; }
public string FullAddress => $"{Address}, {PostalDest.AtPlz.Plz} {PostalDest.AtPlz.Ort.Name}";
public int SearchScore(IEnumerable<string> keywords) {
return Utils.GetSearchScore(new string?[] {
MgNr.ToString(),
FamilyName, MiddleName, GivenName,
BillingAddress?.Name,
Comment,
}, keywords);
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("member_email_address"), PrimaryKey("MgNr", "Nr")]
public class MemberEmailAddr {
[Column("mgnr")]
public int MgNr { get; set; }
[Column("nr")]
public int Nr { get; set; }
[Column("address")]
public string Address { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
}
}

View File

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("member_telephone_number"), PrimaryKey("MgNr", "Nr")]
public class MemberTelNr {
[Column("mgnr")]
public int MgNr { get; set; }
[Column("nr")]
public int Nr { get; set; }
[Column("type")]
public string Type { get; set; }
[Column("number")]
public string Number { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
}
}

View File

@ -0,0 +1,58 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Elwig.Models.Entities {
[Table("modifier"), PrimaryKey("Year", "ModId")]
public class Modifier {
[Column("year")]
public int Year { get; set; }
[Column("modid")]
public string ModId { get; set; }
[Column("ordering")]
public int Ordering { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("abs")]
public long? AbsValue { get; set; }
[NotMapped]
public decimal? Abs {
get => AbsValue != null ? Season.DecFromDb(AbsValue.Value) : null;
set => AbsValue = value != null ? Season.DecToDb(value.Value) : null;
}
[Column("rel")]
public double? RelValue { get; set; }
[NotMapped]
public decimal? Rel {
get => (decimal?)RelValue;
set => RelValue = (double?)value;
}
[Column("standard")]
public bool IsStandard { get; set; }
[Column("quick_select")]
public bool IsQuickSelect { get; set; }
[ForeignKey("Year")]
public virtual Season Season { get; private set; }
public string ValueStr =>
(Abs != null) ? $"{Utils.GetSign(Abs.Value)}{Math.Abs(Abs.Value).ToString("0." + string.Concat(Enumerable.Repeat('0', Season.Precision)))}\u00a0{Season.Currency.Symbol}/kg" :
(Rel != null) ? $"{Utils.GetSign(Rel.Value)}{(Math.Abs(Rel.Value) < 0.1m ? "\u2007" : "")}{Math.Abs(Rel.Value):0.00##\u00a0%}" :
"";
public override string ToString() {
return Name;
}
}
}

View File

@ -0,0 +1,49 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("payment_delivery_part"), PrimaryKey("Year", "DId", "DPNr", "AvNr")]
public class PaymentDeliveryPart {
[Column("year")]
public int Year { get; set; }
[Column("did")]
public int DId { get; set; }
[Column("dpnr")]
public int DPNr { get; set; }
[Column("avnr")]
public int AvNr { get; set; }
[Column("mod_abs")]
public long ModAbsValue { get; set; }
[NotMapped]
public decimal ModAbs {
get => Variant.Season.DecFromDb(ModAbsValue);
set => ModAbsValue = Variant.Season.DecToDb(value);
}
[Column("mod_rel")]
public double ModRelValue { get; set; }
[NotMapped]
public decimal ModRel {
get => (decimal)ModRelValue;
set => ModRelValue = (double)value;
}
[Column("amount")]
public long? AmountValue { get; set; }
[NotMapped]
public decimal? Amount {
get => AmountValue != null ? Variant.Season.DecFromDb(AmountValue.Value) : null;
set => AmountValue = value != null ? Variant.Season.DecToDb(value.Value) : null;
}
[ForeignKey("Year, AvNr")]
public virtual PaymentVar Variant { get; private set; }
[ForeignKey("Year, DId, DPNr")]
public virtual DeliveryPart DeliveryPart { get; private set; }
}
}

View File

@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("payment_delivery_part_bucket"), PrimaryKey("Year", "DId", "DPNr", "BktNr", "AvNr")]
public class PaymentDeliveryPartBucket {
[Column("year")]
public int Year { get; set; }
[Column("did")]
public int DId { get; set; }
[Column("dpnr")]
public int DPNr { get; set; }
[Column("bktnr")]
public int BktNr { get; set; }
[Column("avnr")]
public int AvNr { get; set; }
[Column("price")]
public long PriceValue { get; set; }
[NotMapped]
public decimal Price {
get => Variant.Season.DecFromDb(PriceValue);
set => PriceValue = Variant.Season.DecToDb(value);
}
[Column("amount")]
public long AmountValue { get; set; }
[NotMapped]
public decimal Amount {
get => Variant.Season.DecFromDb(AmountValue);
set => AmountValue = Variant.Season.DecToDb(value);
}
[ForeignKey("Year, AvNr")]
public virtual PaymentVar Variant { get; private set; }
[ForeignKey("Year, DId, DPNr")]
public virtual DeliveryPart DeliveryPart { get; private set; }
}
}

View File

@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("payment_member"), PrimaryKey("Year", "AvNr", "MgNr")]
public class PaymentMember {
[Column("year")]
public int Year { get; set; }
[Column("avnr")]
public int AvNr { get; set; }
[Column("mgnr")]
public int MgNr { get; set; }
[Column("amount")]
public long AmountValue { get; set; }
[NotMapped]
public decimal Amount {
get => Variant.Season.DecFromDb(AmountValue);
set => AmountValue = Variant.Season.DecToDb(value);
}
[ForeignKey("Year, AvNr")]
public virtual PaymentVar Variant { get; private set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
[InverseProperty("Payment")]
public virtual Credit? Credit { get; private set; }
}
}

View File

@ -0,0 +1,57 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("payment_variant"), PrimaryKey("Year", "AvNr")]
public class PaymentVar {
[Column("year")]
public int Year { get; set; }
[Column("avnr")]
public int AvNr { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("date")]
public string DateString { get; set; }
[NotMapped]
public DateOnly Date {
get => DateOnly.ParseExact(DateString, "yyyy-MM-dd");
set => DateString = value.ToString("yyyy-MM-dd");
}
[Column("transfer_date")]
public string? TransferDateString { get; set; }
[NotMapped]
public DateOnly? TransferDate {
get => TransferDateString != null ? DateOnly.ParseExact(TransferDateString, "yyyy-MM-dd") : null;
set => TransferDateString = value?.ToString("yyyy-MM-dd");
}
[Column("test_variant")]
public bool TestVariant { get; set; }
[Column("calc_time")]
public int? CalcTime { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[Column("data")]
public string Data { get; set; }
[ForeignKey("Year")]
public virtual Season Season { get; private set; }
[InverseProperty("Variant")]
public virtual ISet<PaymentMember> MemberPayments { get; private set; }
[InverseProperty("Variant")]
public virtual ISet<Credit> Credits { get; private set; }
}
}

View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("postal_dest"), PrimaryKey("CountryNum", "Id")]
public class PostalDest {
[Column("country")]
public int CountryNum { get; private set; }
[Column("id")]
public string Id { get; private set; }
[ForeignKey("CountryNum")]
public virtual Country Country { get; private set; }
[ForeignKey("Id")]
public virtual AT_PlzDest? AtPlz { get; private set; }
}
}

View File

@ -0,0 +1,96 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("season"), PrimaryKey("Year")]
public class Season {
[Column("year")]
public int Year { get; set; }
[Column("currency")]
public string CurrencyCode { get; set; }
[Column("precision")]
public byte Precision { get; set; }
[Column("max_kg_per_ha")]
public int MaxKgPerHa { get; set; }
[Column("vat_normal")]
public double VatNormal { get; set; }
[Column("vat_flatrate")]
public double VatFlatrate { get; set; }
[Column("min_kg_per_bs")]
public int MinKgPerBusinessShare { get; set; }
[Column("max_kg_per_bs")]
public int MaxKgPerBusinessShare { get; set; }
[Column("penalty_per_kg")]
public long? PenaltyPerKgValue { get; set; }
[NotMapped]
public decimal? PenaltyPerKg {
get => PenaltyPerKgValue != null ? DecFromDb(PenaltyPerKgValue.Value) : null;
set => PenaltyPerKgValue = value != null ? DecToDb(value.Value) : null;
}
[Column("penalty_amount")]
public long? PenaltyAmoutValue { get; set; }
[NotMapped]
public decimal? PenaltyAmount {
get => PenaltyAmoutValue != null ? DecFromDb(PenaltyAmoutValue.Value) : null;
set => PenaltyAmoutValue = value != null ? DecToDb(value.Value) : null;
}
[Column("penalty_none")]
public long? PenaltyNoneValue { get; set; }
[NotMapped]
public decimal? PenaltyNone {
get => PenaltyNoneValue != null ? DecFromDb(PenaltyNoneValue.Value) : null;
set => PenaltyNoneValue = value != null ? DecToDb(value.Value) : null;
}
[Column("start_date")]
public string? StartDateString { get; set; }
[NotMapped]
public DateOnly? StartDate {
get => StartDateString != null ? DateOnly.ParseExact(StartDateString, "yyyy-MM-dd") : null;
set => StartDateString = value?.ToString("yyyy-MM-dd");
}
[Column("end_date")]
public string? EndDateString { get; set; }
[NotMapped]
public DateOnly? EndDate {
get => EndDateString != null ? DateOnly.ParseExact(EndDateString, "yyyy-MM-dd") : null;
set => EndDateString = value?.ToString("yyyy-MM-dd");
}
[ForeignKey("CurrencyCode")]
public virtual Currency Currency { get; private set; }
[InverseProperty("Season")]
public virtual ISet<Modifier> Modifiers { get; private set; }
[InverseProperty("Season")]
public virtual ISet<PaymentVar> PaymentVariants { get; private set; }
[InverseProperty("Season")]
public virtual ISet<Delivery> Deliveries { get; private set; }
public decimal DecFromDb(long value) {
return Utils.DecFromDb(value, Precision);
}
public long DecToDb(decimal value) {
return Utils.DecToDb(value, Precision);
}
}
}

View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("wb_gem"), PrimaryKey("Gkz")]
public class WbGem {
[Column("gkz")]
public int Gkz { get; private set; }
[Column("hkid")]
public string HkId { get; private set; }
[ForeignKey("Gkz")]
public virtual AT_Gem AtGem { get; private set; }
[ForeignKey("HkId")]
public virtual WineOrigin Origin { get; private set; }
}
}

View File

@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("wb_gl"), PrimaryKey("GlNr")]
public class WbGl {
[Column("glnr")]
public int GlNr { get; private set; }
[Column("name")]
public string Name { get; private set; }
[InverseProperty("Gl")]
public virtual ISet<WbKg> Kgs { get; private set; }
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("wb_kg"), PrimaryKey("KgNr")]
public class WbKg {
[Column("kgnr")]
public int KgNr { get; set; }
[Column("glnr")]
public int? GlNr { get; set; }
[ForeignKey("KgNr")]
public virtual AT_Kg AtKg { get; private set; }
[ForeignKey("GlNr")]
public virtual WbGl Gl { get; private set; }
[InverseProperty("Kg")]
public virtual ISet<WbRd> Rds { get; private set; }
[NotMapped]
public WbGem Gem => AtKg.Gem.WbGem;
[NotMapped]
public WineOrigin Origin => Gem.Origin;
}
}

View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("wb_rd"), PrimaryKey("KgNr", "RdNr")]
public class WbRd {
[Column("kgnr")]
public int KgNr { get; set; }
[Column("rdnr")]
public int RdNr { get; set; }
[Column("name")]
public string Name { get; set; }
[ForeignKey("KgNr")]
public virtual WbKg Kg { get; private set; }
}
}

View File

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("wine_attribute"), PrimaryKey("AttrId"), Index("Name", IsUnique = true)]
public class WineAttr {
[Column("attrid")]
public string AttrId { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("active")]
public bool IsActive { get; set; }
[Column("max_kg_per_ha")]
public int? MaxKgPerHa { get; set; }
[Column("strict")]
public bool IsStrict { get; set; }
[Column("fill_lower")]
public int FillLower { get; set; }
public override string ToString() {
return Name;
}
}
}

View File

@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("wine_cultivation"), PrimaryKey("CultId"), Index("Name", IsUnique = true)]
public class WineCult {
[Column("cultid")]
public string CultId { get; set; }
[Column("name")]
public string Name { get; set; }
[Column("description")]
public string? Description { get; set; }
}
}

View File

@ -0,0 +1,47 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using IndexAttribute = Microsoft.EntityFrameworkCore.IndexAttribute;
namespace Elwig.Models.Entities {
[Table("wine_origin"), PrimaryKey("HkId"), Index("Name", IsUnique = true)]
public class WineOrigin {
[Column("hkid")]
public string HkId { get; private set; }
[Column("parent_hkid")]
public string? ParentHkId { get; private set; }
[ForeignKey("ParentHkId")]
public virtual WineOrigin? Parent { get; private set; }
[Column("name")]
public string Name { get; private set; }
[Column("blnr")]
public int? BlNr { get; private set; }
[InverseProperty("Origin")]
public virtual ISet<WbGem> Gems { get; private set; }
[InverseProperty("Parent")]
public virtual ISet<WineOrigin> Children { get; private set; }
public int Level => (Parent?.Level + 1) ?? 0;
public string HkIdLevel => $"{new string(' ', Level * 2)}{HkId}";
public int TotalChildNum => 1 + Children.Select(c => c.TotalChildNum).Sum();
private int SortKey1 => (Parent?.SortKey1 ?? 0) | (TotalChildNum << ((3 - Level) * 8));
public int SortKey => SortKey1 | ((Level < 3) ? (-1 >>> (Level * 8 + 8)) : 0);
public override string ToString() {
return Name;
}
public string OriginString => (Parent != null ? $"{Parent.OriginString} / " : "") + Name;
}
}

View File

@ -0,0 +1,45 @@
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("wine_quality_level"), PrimaryKey("QualId")]
public class WineQualLevel : IEquatable<WineQualLevel> {
[Column("qualid")]
public string QualId { get; private set; }
[Column("origin_level")]
public int? OriginLevel { get; private set; }
[Column("predicate")]
public bool IsPredicate { get; private set; }
[Column("min_kmw")]
public double? MinKmw { get; private set; }
[NotMapped]
public double? MinOe => MinKmw != null ? Utils.KmwToOe((double)MinKmw) : null;
[Column("name")]
public string Name { get; private set; }
public string MinKmwStr => (MinKmw == null) ? "" : $"(mind. {MinKmw:#.0}°)";
public override bool Equals(object? obj) {
return Equals(obj as WineQualLevel);
}
public bool Equals(WineQualLevel? obj) {
return QualId == obj?.QualId;
}
public static bool operator ==(WineQualLevel? q1, WineQualLevel? q2) {
return q1?.Equals(q2) ?? Equals(q1, q2);
}
public static bool operator !=(WineQualLevel? q1, WineQualLevel? q2) {
return !(q1?.Equals(q2) ?? Equals(q1, q2));
}
}
}

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("wine_variety"), PrimaryKey("SortId")]
public class WineVar {
[Column("sortid")]
public string SortId { get; private set; }
[Column("type")]
public string Type { get; private set; }
[Column("name")]
public string Name { get; private set; }
[Column("comment")]
public string? Comment { get; private set; }
public string CommentFormat => (Comment != null) ? $" ({Comment})" : "";
public bool IsRed => Type == "R";
public bool IsWhite => Type == "W";
public override string ToString() {
return Name;
}
}
}