[#20] MemberAdminWindow: Add MemberBusinessSharesAdminWindow to manage member shares
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows;
|
||||
|
||||
namespace Elwig.Services {
|
||||
public static class AreaComService {
|
||||
@@ -115,7 +114,7 @@ namespace Elwig.Services {
|
||||
using var ctx = new AppDbContext();
|
||||
var c = new AreaComContract {
|
||||
FbNr = oldFbNr ?? newFbNr,
|
||||
Comment = string.IsNullOrEmpty(vm.Comment) ? null : vm.Comment,
|
||||
Comment = string.IsNullOrWhiteSpace(vm.Comment) ? null : vm.Comment,
|
||||
KgNr = vm.Kg!.KgNr,
|
||||
RdNr = vm.Rd?.RdNr,
|
||||
};
|
||||
|
||||
@@ -8,7 +8,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Elwig.Documents;
|
||||
using Elwig.Helpers.Export;
|
||||
using Elwig.Models.Dtos;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using LinqKit;
|
||||
using System.Windows.Controls;
|
||||
|
||||
@@ -6,7 +6,6 @@ using Elwig.Models.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using Elwig.ViewModels;
|
||||
using LinqKit;
|
||||
@@ -23,15 +22,6 @@ namespace Elwig.Services {
|
||||
FromFilters, FromToday, FromSeason, FromSeasonAndBranch, Selected,
|
||||
};
|
||||
|
||||
public static async Task<Member?> GetMemberAsync(int mgnr) {
|
||||
using var ctx = new AppDbContext();
|
||||
return await ctx.FetchMembers(mgnr).SingleOrDefaultAsync();
|
||||
}
|
||||
|
||||
public static Member? GetMember(int mgnr) {
|
||||
return GetMemberAsync(mgnr).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public static void ClearInputs(this DeliveryAdminViewModel vm) {
|
||||
}
|
||||
|
||||
@@ -486,7 +476,7 @@ namespace Elwig.Services {
|
||||
if (partNew && timeIsDefault) {
|
||||
newTimeString = DateTime.Now.ToString("HH:mm:ss");
|
||||
} else if (partNew || timeHasChanged) {
|
||||
newTimeString = string.IsNullOrEmpty(vm.Time) ? null : vm.Time + ":00";
|
||||
newTimeString = string.IsNullOrWhiteSpace(vm.Time) ? null : vm.Time + ":00";
|
||||
}
|
||||
|
||||
var d = new Delivery {
|
||||
@@ -498,7 +488,7 @@ namespace Elwig.Services {
|
||||
ZwstId = vm.Branch!.ZwstId,
|
||||
LsNr = newLsNr ?? vm.LsNr!,
|
||||
MgNr = vm.MgNr!.Value,
|
||||
Comment = string.IsNullOrEmpty(vm.Comment) ? null : vm.Comment,
|
||||
Comment = string.IsNullOrWhiteSpace(vm.Comment) ? null : vm.Comment,
|
||||
};
|
||||
|
||||
p = new DeliveryPart {
|
||||
@@ -521,7 +511,7 @@ namespace Elwig.Services {
|
||||
Unloading = vm.Unloading,
|
||||
Temperature = vm.Temperature,
|
||||
Acid = vm.Acid,
|
||||
Comment = string.IsNullOrEmpty(vm.PartComment) ? null : vm.PartComment,
|
||||
Comment = string.IsNullOrWhiteSpace(vm.PartComment) ? null : vm.PartComment,
|
||||
|
||||
Weight = vm.Weight!.Value,
|
||||
IsManualWeighing = vm.IsManualWeighing,
|
||||
|
||||
@@ -48,6 +48,19 @@ namespace Elwig.Services {
|
||||
}
|
||||
}
|
||||
|
||||
public static bool? AskContinueYesNo(string title, string text) {
|
||||
if (NextContinue != null) {
|
||||
var r = NextContinue(title, text);
|
||||
NextContinue = null;
|
||||
return r;
|
||||
} else if (Override != null) {
|
||||
return Override("continue", title, text) != null;
|
||||
} else {
|
||||
var r = MessageBox.Show(text, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
|
||||
return r == MessageBoxResult.Yes ? true : r == MessageBoxResult.No ? false : null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AskConfirmation(string title, string text) {
|
||||
if (NextConfirmation != null) {
|
||||
var r = NextConfirmation(title, text);
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
using Elwig.Models.Entities;
|
||||
using Elwig.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Services {
|
||||
public static class MemberBusinessSharesService {
|
||||
|
||||
public static async Task InitInputs(this MemberBusinessSharesViewModel vm) {
|
||||
using var ctx = new AppDbContext();
|
||||
vm.DateNoticeString = $"{Utils.Today:dd.MM.yyyy}";
|
||||
vm.ValuePerShare = (await ctx.Seasons.OrderBy(s => s.Year).LastOrDefaultAsync())?.BusinessShareValue;
|
||||
}
|
||||
|
||||
public static void ClearInputs(this MemberBusinessSharesViewModel vm) {
|
||||
|
||||
}
|
||||
|
||||
public static void FillInputs(this MemberBusinessSharesViewModel vm, MemberHistory h) {
|
||||
var mgnr = vm.FilterMember.MgNr;
|
||||
vm.DateNotice = h.DateNotice;
|
||||
vm.DateEffective = h.DateEffective;
|
||||
vm.Reason = h.Reason + (h.Reason == MemberHistory.REASON_TRANSFER ? $"_{(h.ToMgNr == mgnr ? "from" : "to")}" : "");
|
||||
vm.Shares = h.Shares;
|
||||
vm.MemberHasSigned = h.MemberHasSigned;
|
||||
vm.ValuePerShare = h.ValuePerShare;
|
||||
vm.OtherMgNr = h.FromMgNr != null && h.FromMgNr != mgnr ? h.FromMgNr : h.ToMgNr != null && h.ToMgNr != mgnr ? h.ToMgNr : null;
|
||||
vm.DeductYear = h.DeductYear ?? h.DateNotice.Year;
|
||||
vm.Deduct = h.DeductYear != null;
|
||||
vm.Comment = h.Comment;
|
||||
}
|
||||
|
||||
public static async Task<int> UpdateMemberHistory(this MemberBusinessSharesViewModel vm, int? oldHistNr, bool enableTriggers) {
|
||||
return await Task.Run(async () => {
|
||||
using var ctx = new AppDbContext();
|
||||
var tx = await ctx.Database.BeginTransactionAsync();
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE client_parameter SET value = {(enableTriggers ? "1" : "0")} WHERE param = 'ENABLE_MEMBER_HISTORY_TRIGGERS'");
|
||||
|
||||
var h = new MemberHistory {
|
||||
HistNr = oldHistNr ?? await ctx.NextHistNr(),
|
||||
FromMgNr =
|
||||
vm.Reason == $"{MemberHistory.REASON_TRANSFER}_from" ? vm.OtherMgNr :
|
||||
vm.Reason == MemberHistory.REASON_PURCHASE || vm.Reason == MemberHistory.REASON_PRESCRIPTION ? null :
|
||||
vm.FilterMember.MgNr,
|
||||
FromType =
|
||||
vm.Reason == MemberHistory.REASON_PAYOUT ? BusinessShareType.Dormant :
|
||||
vm.Reason == MemberHistory.REASON_PURCHASE || vm.Reason == MemberHistory.REASON_PRESCRIPTION ? null :
|
||||
BusinessShareType.Normal,
|
||||
ToMgNr =
|
||||
vm.Reason == MemberHistory.REASON_PAYOUT || vm.Reason == MemberHistory.REASON_EXCLUSION ? null :
|
||||
vm.Reason == $"{MemberHistory.REASON_TRANSFER}_to" ? vm.OtherMgNr :
|
||||
vm.FilterMember.MgNr,
|
||||
ToType =
|
||||
vm.Reason == MemberHistory.REASON_PAYOUT || vm.Reason == MemberHistory.REASON_EXCLUSION ? null :
|
||||
vm.Reason == MemberHistory.REASON_RETIREMENT || vm.Reason == MemberHistory.REASON_DECEASED ? BusinessShareType.Dormant :
|
||||
BusinessShareType.Normal,
|
||||
DateNoticeString = $"{vm.DateNotice:yyyy-MM-dd}",
|
||||
DateEffectiveString = $"{vm.DateEffective:yyyy-MM-dd}",
|
||||
Reason = vm.Reason?.Split("_")[0] ?? MemberHistory.REASON_CONVERT,
|
||||
Source = "manual",
|
||||
Shares = vm.Shares ?? 0,
|
||||
MemberHasSigned = vm.MemberHasSigned,
|
||||
ValuePerShare = vm.ValuePerShare,
|
||||
CurrencyCode = vm.ValuePerShare != null ? "EUR" : null,
|
||||
DeductYear = vm.Deduct ? vm.DeductYear : null,
|
||||
Comment = string.IsNullOrWhiteSpace(vm.Comment) ? null : vm.Comment.Trim(),
|
||||
};
|
||||
|
||||
if (oldHistNr != null) {
|
||||
ctx.Update(h);
|
||||
} else {
|
||||
ctx.Add(h);
|
||||
}
|
||||
|
||||
await ctx.SaveChangesAsync();
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE client_parameter SET value = '1' WHERE param = 'ENABLE_MEMBER_HISTORY_TRIGGERS'");
|
||||
await tx.CommitAsync();
|
||||
|
||||
return h.HistNr;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static async Task DeleteMemberHistory(int histnr, bool enableTriggers) {
|
||||
await Task.Run(async () => {
|
||||
using var ctx = new AppDbContext();
|
||||
var tx = await ctx.Database.BeginTransactionAsync();
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE client_parameter SET value = {(enableTriggers ? "1" : "0")} WHERE param = 'ENABLE_MEMBER_HISTORY_TRIGGERS'");
|
||||
await ctx.MemberHistory.Where(h => h.HistNr == histnr).ExecuteDeleteAsync();
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE client_parameter SET value = '1' WHERE param = 'ENABLE_MEMBER_HISTORY_TRIGGERS'");
|
||||
await tx.CommitAsync();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -501,7 +501,10 @@ namespace Elwig.Services {
|
||||
var history2 = await query.IgnoreAutoIncludes()
|
||||
.SelectMany(m => m.HistoryTo)
|
||||
.ToListAsync();
|
||||
var history = history1.Union(history2).DistinctBy(h => h.HistNr).OrderBy(h => h.HistNr).ToList();
|
||||
var history = history1.Union(history2)
|
||||
.DistinctBy(h => h.HistNr)
|
||||
.OrderBy(h => h.DateNotice).ThenBy(h => h.HistNr)
|
||||
.ToList();
|
||||
var areaComs = await query
|
||||
.SelectMany(m => m.AreaCommitments)
|
||||
.Select(c => c.Contract).Distinct()
|
||||
@@ -541,33 +544,33 @@ namespace Elwig.Services {
|
||||
Name = vm.Name!,
|
||||
Suffix = vm.IsJuridicalPerson || string.IsNullOrWhiteSpace(vm.Suffix) ? null : vm.Suffix,
|
||||
ForTheAttentionOf = !vm.IsJuridicalPerson || string.IsNullOrWhiteSpace(vm.ForTheAttentionOf) ? null : vm.ForTheAttentionOf,
|
||||
Birthday = string.IsNullOrEmpty(vm.Birthday) ? null : string.Join("-", vm.Birthday!.Split(".").Reverse()),
|
||||
Birthday = string.IsNullOrWhiteSpace(vm.Birthday) ? null : string.Join("-", vm.Birthday!.Split(".").Reverse()),
|
||||
IsDeceased = vm.IsDeceased,
|
||||
CountryNum = 40, // Austria AT AUT
|
||||
PostalDestId = vm.Ort!.Id,
|
||||
Address = vm.Address!,
|
||||
|
||||
Iban = string.IsNullOrEmpty(vm.Iban) ? null : vm.Iban?.Replace(" ", ""),
|
||||
Bic = string.IsNullOrEmpty(vm.Bic) ? null : vm.Bic,
|
||||
Iban = string.IsNullOrWhiteSpace(vm.Iban) ? null : vm.Iban?.Replace(" ", ""),
|
||||
Bic = string.IsNullOrWhiteSpace(vm.Bic) ? null : vm.Bic,
|
||||
|
||||
UstIdNr = string.IsNullOrEmpty(vm.UstIdNr) ? null : vm.UstIdNr,
|
||||
LfbisNr = string.IsNullOrEmpty(vm.LfbisNr) ? null : vm.LfbisNr,
|
||||
UstIdNr = string.IsNullOrWhiteSpace(vm.UstIdNr) ? null : vm.UstIdNr,
|
||||
LfbisNr = string.IsNullOrWhiteSpace(vm.LfbisNr) ? null : vm.LfbisNr,
|
||||
IsBuchführend = vm.IsBuchführend,
|
||||
IsOrganic = vm.IsOrganic,
|
||||
|
||||
EntryDateString = string.IsNullOrEmpty(vm.EntryDate) ? null : string.Join("-", vm.EntryDate.Split(".").Reverse()),
|
||||
ExitDateString = string.IsNullOrEmpty(vm.ExitDate) ? null : string.Join("-", vm.ExitDate.Split(".").Reverse()),
|
||||
EntryDateString = string.IsNullOrWhiteSpace(vm.EntryDate) ? null : string.Join("-", vm.EntryDate.Split(".").Reverse()),
|
||||
ExitDateString = string.IsNullOrWhiteSpace(vm.ExitDate) ? null : string.Join("-", vm.ExitDate.Split(".").Reverse()),
|
||||
Shares = App.Client.HasRedWhite ? 0 : vm.BusinessShares1 ?? 0,
|
||||
SharesRed = App.Client.HasRedWhite ? vm.BusinessShares1 ?? 0 : 0,
|
||||
SharesWhite = App.Client.HasRedWhite ? vm.BusinessShares2 ?? 0 : 0,
|
||||
SharesDormant = App.Client.HasRedWhite ? vm.BusinessShares3 ?? 0 : vm.BusinessShares2 ?? 0,
|
||||
AccountingNr = string.IsNullOrEmpty(vm.AccountingNr) ? null : vm.AccountingNr,
|
||||
AccountingNr = string.IsNullOrWhiteSpace(vm.AccountingNr) ? null : vm.AccountingNr,
|
||||
IsActive = vm.IsActive,
|
||||
IsVollLieferant = vm.IsVollLieferant,
|
||||
IsFunktionär = vm.IsFunktionär,
|
||||
ZwstId = vm.Branch?.ZwstId,
|
||||
DefaultKgNr = vm.DefaultKg?.KgNr,
|
||||
Comment = string.IsNullOrEmpty(vm.Comment) ? null : vm.Comment,
|
||||
Comment = string.IsNullOrWhiteSpace(vm.Comment) ? null : vm.Comment,
|
||||
ContactViaPost = vm.ContactViaPost,
|
||||
ContactViaEmail = vm.ContactViaEmail,
|
||||
};
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace Elwig.Services {
|
||||
TransferDate = vm.TransferDate,
|
||||
TestVariant = vm.SelectedPaymentVariant?.TestVariant ?? true,
|
||||
CalcTimeUnix = vm.SelectedPaymentVariant?.CalcTimeUnix,
|
||||
Comment = string.IsNullOrEmpty(vm.Comment) ? null : vm.Comment,
|
||||
Comment = string.IsNullOrWhiteSpace(vm.Comment) ? null : vm.Comment,
|
||||
Data = JsonSerializer.Serialize(d.Data),
|
||||
};
|
||||
avnr = v.AvNr;
|
||||
|
||||
@@ -33,7 +33,10 @@ namespace Elwig.Services {
|
||||
var history2 = await query.IgnoreAutoIncludes()
|
||||
.SelectMany(m => m.HistoryTo)
|
||||
.ToListAsync();
|
||||
var history = history1.Union(history2).DistinctBy(h => h.HistNr).OrderBy(h => h.HistNr).ToList();
|
||||
var history = history1.Union(history2)
|
||||
.DistinctBy(h => h.HistNr)
|
||||
.OrderBy(h => h.DateNotice).ThenBy(h => h.HistNr)
|
||||
.ToList();
|
||||
var areaComs = await query
|
||||
.SelectMany(m => m.AreaCommitments)
|
||||
.Select(c => c.Contract).Distinct()
|
||||
|
||||
Reference in New Issue
Block a user