diff --git a/Elwig/Helpers/AppDbUpdater.cs b/Elwig/Helpers/AppDbUpdater.cs index bf02d55..a6606c6 100644 --- a/Elwig/Helpers/AppDbUpdater.cs +++ b/Elwig/Helpers/AppDbUpdater.cs @@ -9,7 +9,7 @@ namespace Elwig.Helpers { public static class AppDbUpdater { // Don't forget to update value in Tests/fetch-resources.bat! - public static readonly int RequiredSchemaVersion = 28; + public static readonly int RequiredSchemaVersion = 29; private static int VersionOffset = 0; diff --git a/Elwig/Models/Entities/DeliverySchedule.cs b/Elwig/Models/Entities/DeliverySchedule.cs index 0bd715c..2545b8b 100644 --- a/Elwig/Models/Entities/DeliverySchedule.cs +++ b/Elwig/Models/Entities/DeliverySchedule.cs @@ -32,6 +32,12 @@ namespace Elwig.Models.Entities { [NotMapped] public string Identifier => $"{Date:dd.MM.} - {ZwstId} - {Description}"; + [Column("attrid")] + public string? AttrId { get; set; } + + [Column("cultid")] + public string? CultId { get; set; } + [Column("max_weight")] public int? MaxWeight { get; set; } [NotMapped] @@ -39,6 +45,9 @@ namespace Elwig.Models.Entities { [NotMapped] public double? Percent => (double)AnnouncedWeight / MaxWeight * 100; + [Column("cancelled")] + public bool IsCancelled { get; set; } + [Column("ancmt_from")] public long? AncmtFromUnix { get; set; } [NotMapped] @@ -61,6 +70,12 @@ namespace Elwig.Models.Entities { [ForeignKey("ZwstId")] public virtual Branch Branch { get; private set; } = null!; + [ForeignKey("AttrId")] + public virtual WineAttr? Attribute { get; private set; } + + [ForeignKey("CultId")] + public virtual WineCult? Cultivation { get; private set; } + [InverseProperty(nameof(DeliveryScheduleWineVar.Schedule))] public virtual ICollection Varieties { get; private set; } = null!; diff --git a/Elwig/Resources/Sql/28-29.sql b/Elwig/Resources/Sql/28-29.sql new file mode 100644 index 0000000..7f29814 --- /dev/null +++ b/Elwig/Resources/Sql/28-29.sql @@ -0,0 +1,23 @@ +-- schema version 28 to 29 + +ALTER TABLE delivery_schedule ADD COLUMN attrid TEXT DEFAULT NULL; +ALTER TABLE delivery_schedule ADD COLUMN cultid TEXT DEFAULT NULL; +ALTER TABLE delivery_schedule ADD COLUMN cancelled INTEGER NOT NULL CHECK (cancelled IN (TRUE, FALSE)) DEFAULT FALSE; +UPDATE delivery_schedule SET cultid = 'B' WHERE UPPER(description) LIKE '%BIO%'; +UPDATE delivery_schedule SET cancelled = TRUE WHERE zwstid = 'M' AND date IN ('2024-09-14', '2024-09-16'); + +PRAGMA writable_schema = ON; + +UPDATE sqlite_schema SET sql = REPLACE(sql, ' +) STRICT', ', + CONSTRAINT fk_delivery_schedule_wine_attribute FOREIGN KEY (attrid) REFERENCES wine_attribute (attrid) + ON UPDATE CASCADE + ON DELETE RESTRICT, + CONSTRAINT fk_delivery_schedule_wine_cultivation FOREIGN KEY (cultid) REFERENCES wine_cultivation (cultid) + ON UPDATE CASCADE + ON DELETE RESTRICT +) STRICT') +WHERE type = 'table' AND name = 'delivery_schedule'; + +PRAGMA schema_version = 2801; +PRAGMA writable_schema = OFF; diff --git a/Elwig/Services/DeliveryScheduleService.cs b/Elwig/Services/DeliveryScheduleService.cs index 97c69ca..07d4dc5 100644 --- a/Elwig/Services/DeliveryScheduleService.cs +++ b/Elwig/Services/DeliveryScheduleService.cs @@ -26,6 +26,7 @@ namespace Elwig.Services { vm.Branch = (Branch?)ControlUtils.GetItemFromSourceWithPk(vm.BranchSource, s.ZwstId); vm.Description = s.Description; vm.MaxWeight = s.MaxWeight; + vm.IsCancelled = s.IsCancelled; vm.MainVarieties.Clear(); foreach (var v in s.Varieties.Where(v => v.Priority == 1)) { vm.MainVarieties.Add((WineVar)ControlUtils.GetItemFromSourceWithPk(vm.MainVarietiesSource, v.SortId)!); @@ -34,6 +35,8 @@ namespace Elwig.Services { foreach (var v in s.Varieties.Where(v => v.Priority != 1)) { vm.OtherVarieties.Add((WineVar)ControlUtils.GetItemFromSourceWithPk(vm.OtherVarietiesSource, v.SortId)!); } + vm.Attribute = ControlUtils.GetItemFromSourceWithPk(vm.AttributeSource, s.AttrId) as WineAttr; + vm.Cultivation = ControlUtils.GetItemFromSourceWithPk(vm.CultivationSource, s.CultId) as WineCult; vm.AncmtFrom = s.AncmtFrom; vm.AncmtTo = s.AncmtTo?.AddSeconds(-1); } @@ -156,7 +159,10 @@ namespace Elwig.Services { DateString = $"{vm.Date:yyyy-MM-dd}", ZwstId = vm.Branch!.ZwstId, Description = vm.Description, + AttrId = vm.Attribute?.AttrId, + CultId = vm.Cultivation?.CultId, MaxWeight = vm.MaxWeight, + IsCancelled = vm.IsCancelled, AncmtFrom = vm.AncmtFrom, AncmtTo = vm.AncmtTo?.AddMinutes(1), }; diff --git a/Elwig/ViewModels/DeliveryScheduleAdminViewModel.cs b/Elwig/ViewModels/DeliveryScheduleAdminViewModel.cs index ee5a39f..25f365c 100644 --- a/Elwig/ViewModels/DeliveryScheduleAdminViewModel.cs +++ b/Elwig/ViewModels/DeliveryScheduleAdminViewModel.cs @@ -47,12 +47,30 @@ namespace Elwig.ViewModels { get => int.TryParse(MaxWeightString, out var w) ? w : null; set => MaxWeightString = $"{value}"; } + [ObservableProperty] + private bool _isCancelled; public ObservableCollection MainVarieties { get; set; } = []; [ObservableProperty] private IEnumerable _mainVarietiesSource = []; public ObservableCollection OtherVarieties { get; set; } = []; [ObservableProperty] private IEnumerable _otherVarietiesSource = []; + [ObservableProperty] + private IEnumerable _attributeSource = []; + [ObservableProperty] + private object? _attributeObj; + public WineAttr? Attribute { + get => AttributeObj as WineAttr; + set => AttributeObj = value ?? AttributeSource.FirstOrDefault(); + } + [ObservableProperty] + private IEnumerable _cultivationSource = []; + [ObservableProperty] + private object? _cultivationObj; + public WineCult? Cultivation { + get => CultivationObj as WineCult; + set => CultivationObj = value ?? CultivationSource.FirstOrDefault(); + } [ObservableProperty] private string _ancmtFromDateString = ""; diff --git a/Elwig/Windows/DeliveryScheduleAdminWindow.xaml b/Elwig/Windows/DeliveryScheduleAdminWindow.xaml index 4acdb6e..514b49b 100644 --- a/Elwig/Windows/DeliveryScheduleAdminWindow.xaml +++ b/Elwig/Windows/DeliveryScheduleAdminWindow.xaml @@ -195,29 +195,34 @@ +