|
@@ -1,5 +1,6 @@
|
|
using InABox.Core;
|
|
using InABox.Core;
|
|
using InABox.Core.Postable;
|
|
using InABox.Core.Postable;
|
|
|
|
+using InABox.DynamicGrid;
|
|
using Microsoft.Web.WebView2.Wpf;
|
|
using Microsoft.Web.WebView2.Wpf;
|
|
using MYOB.AccountRight.SDK;
|
|
using MYOB.AccountRight.SDK;
|
|
using MYOB.AccountRight.SDK.Contracts;
|
|
using MYOB.AccountRight.SDK.Contracts;
|
|
@@ -138,7 +139,11 @@ public abstract class MYOBPosterEngine<TPostable, TSettings> :
|
|
where TPostable : Entity, IPostable, IRemotable, IPersistent, new()
|
|
where TPostable : Entity, IPostable, IRemotable, IPersistent, new()
|
|
where TSettings : MYOBPosterSettings, new()
|
|
where TSettings : MYOBPosterSettings, new()
|
|
{
|
|
{
|
|
- private MYOBGlobalPosterSettings GetGlobalSettings() => (this as IGlobalSettingsPosterEngine<IMYOBPoster<TPostable, TSettings>, MYOBGlobalPosterSettings>).GetGlobalSettings();
|
|
|
|
|
|
+ private MYOBGlobalPosterSettings GetGlobalSettings() =>
|
|
|
|
+ (this as IGlobalSettingsPosterEngine<IMYOBPoster<TPostable, TSettings>, MYOBGlobalPosterSettings>).GetGlobalSettings();
|
|
|
|
+
|
|
|
|
+ private void SaveGlobalSettings(MYOBGlobalPosterSettings settings) =>
|
|
|
|
+ (this as IGlobalSettingsPosterEngine<IMYOBPoster<TPostable, TSettings>, MYOBGlobalPosterSettings>).SaveGlobalSettings(settings);
|
|
|
|
|
|
public override bool BeforePost(IDataModel<TPostable> model)
|
|
public override bool BeforePost(IDataModel<TPostable> model)
|
|
{
|
|
{
|
|
@@ -151,24 +156,57 @@ public abstract class MYOBPosterEngine<TPostable, TSettings> :
|
|
var data = MYOBPosterEngine.GetConnectionData();
|
|
var data = MYOBPosterEngine.GetConnectionData();
|
|
|
|
|
|
var globalSettings = GetGlobalSettings();
|
|
var globalSettings = GetGlobalSettings();
|
|
- var companyFileID = globalSettings.GetCompanyFileID();
|
|
|
|
- if(data.CompanyFile is null || data.CompanyFile.Id != companyFileID)
|
|
|
|
|
|
+ if(data.CompanyFile is null || data.CompanyFile.Id != globalSettings.CompanyFile.ID)
|
|
{
|
|
{
|
|
CompanyFile? file;
|
|
CompanyFile? file;
|
|
- if(companyFileID == Guid.Empty)
|
|
|
|
|
|
+ if(globalSettings.CompanyFile.ID == Guid.Empty)
|
|
{
|
|
{
|
|
file = MYOBCompanyFileSelectionDialog.SelectCompanyFile();
|
|
file = MYOBCompanyFileSelectionDialog.SelectCompanyFile();
|
|
if(file is null)
|
|
if(file is null)
|
|
{
|
|
{
|
|
throw new PostCancelledException();
|
|
throw new PostCancelledException();
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ globalSettings.CompanyFile.ID = file.Id;
|
|
|
|
+ globalSettings.CompanyFile.Name = file.Name;
|
|
|
|
+
|
|
|
|
+ SaveGlobalSettings(globalSettings);
|
|
|
|
+ globalSettings.CommitChanges();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if(globalSettings.CompanyFileUserID.IsNullOrWhiteSpace())
|
|
if(globalSettings.CompanyFileUserID.IsNullOrWhiteSpace())
|
|
{
|
|
{
|
|
- throw new PostFailedMessageException("CompanyFile credentials have not been set.");
|
|
|
|
|
|
+ var credentials = new MYOBCompanyFileCredentials
|
|
|
|
+ {
|
|
|
|
+ UserID = globalSettings.CompanyFileUserID,
|
|
|
|
+ Password = globalSettings.CompanyFilePassword,
|
|
|
|
+ };
|
|
|
|
+ if (DynamicGridUtils.EditObject(credentials, customiseGrid: grid =>
|
|
|
|
+ {
|
|
|
|
+ grid.OnValidate += (grid, items, errors) =>
|
|
|
|
+ {
|
|
|
|
+ if(items.Any(x => x.UserID.IsNullOrWhiteSpace()))
|
|
|
|
+ {
|
|
|
|
+ errors.Add("[UserID] cannot be blank");
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }))
|
|
|
|
+ {
|
|
|
|
+ globalSettings.CompanyFileUserID = credentials.UserID;
|
|
|
|
+ globalSettings.CompanyFilePassword = credentials.Password;
|
|
|
|
+
|
|
|
|
+ SaveGlobalSettings(globalSettings);
|
|
|
|
+ globalSettings.CommitChanges();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ throw new PostCancelledException();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- var companyFile = data.CompanyFileService.GetRange().FirstOrDefault(x => x.Id == companyFileID);
|
|
|
|
|
|
+
|
|
|
|
+ var companyFile = data.CompanyFileService.GetRange().FirstOrDefault(x => x.Id == globalSettings.CompanyFile.ID);
|
|
var fileCredentials = new CompanyFileCredentials(globalSettings.CompanyFileUserID, globalSettings.CompanyFilePassword);
|
|
var fileCredentials = new CompanyFileCredentials(globalSettings.CompanyFileUserID, globalSettings.CompanyFilePassword);
|
|
data.CompanyFile = companyFile;
|
|
data.CompanyFile = companyFile;
|
|
data.CompanyFileCredentials = fileCredentials;
|
|
data.CompanyFileCredentials = fileCredentials;
|