diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index d957217f..9694ba06 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -654,6 +654,17 @@ namespace Swarmops.Logic.Financial set { ObjectOptionalData.ForObject(this).SetOptionalDataInt(ObjectOptionalDataType.AutomationProfileId, value); } } + public FinancialAccountAutomationProfile AutomationProfile + { + get + { + return (AutomationProfileId == 0 + ? null + : FinancialAccountAutomationProfile.FromIdentity(AutomationProfileId)); + } + set { AutomationProfileId = (value == null ? 0 : value.Identity); } + } + public string AutomationProfileCustomXml { get diff --git a/Logic/Financial/FinancialAccountAutomationProfile.cs b/Logic/Financial/FinancialAccountAutomationProfile.cs index 081db0e1..e1a3012b 100644 --- a/Logic/Financial/FinancialAccountAutomationProfile.cs +++ b/Logic/Financial/FinancialAccountAutomationProfile.cs @@ -13,9 +13,88 @@ namespace Swarmops.Logic.Financial [Serializable] public class FinancialAccountAutomationProfile: IHasIdentity { + public static FinancialAccountAutomationProfile FromIdentity(int financialAccountAutomationProfileId) + { + if (financialAccountAutomationProfileId >= 100) + { + // Database ID, not hard ID + + throw new NotImplementedException(); + } + + FinancialAccountAutomationProfileHardIds hardId = + (FinancialAccountAutomationProfileHardIds) financialAccountAutomationProfileId; + + switch (hardId) + { + case FinancialAccountAutomationProfileHardIds.Unknown: + throw new ArgumentException("Null Profile"); + + case FinancialAccountAutomationProfileHardIds.Custom: + throw new NotImplementedException("Custom profiles not implemented"); + + case FinancialAccountAutomationProfileHardIds.BankPaypal: + return new FinancialAccountAutomationProfile + { + CanManualUpload = true, + CanAutoRetrieve = false, + Name = "Swedish SEB CSV", + Country = null, // global + Currency = null, // whatever the presentation currency is + BankDataProfile = ExternalBankDataProfile.FromIdentity(ExternalBankDataProfile.PaypalId) + }; + + case FinancialAccountAutomationProfileHardIds.BankSwedenSeb: + return new FinancialAccountAutomationProfile + { + CanManualUpload = true, + CanAutoRetrieve = false, + Name = "Swedish SEB CSV", + Country = Structure.Country.FromCode("SE"), + Currency = Financial.Currency.FromCode("SEK"), + BankDataProfile = ExternalBankDataProfile.FromIdentity(ExternalBankDataProfile.SESebId) + }; + + case FinancialAccountAutomationProfileHardIds.BankGermanyPostbank: + return new FinancialAccountAutomationProfile + { + CanManualUpload = true, + CanAutoRetrieve = false, + Name = "Deutsche Postbank CSV", + Country = Structure.Country.FromCode("DE"), + Currency = Financial.Currency.FromCode("EUR"), + BankDataProfile = ExternalBankDataProfile.FromIdentity(ExternalBankDataProfile.DEPostbankId) + }; + + case FinancialAccountAutomationProfileHardIds.BankCzechFio: + return new FinancialAccountAutomationProfile + { + CanManualUpload = true, + CanAutoRetrieve = false, + Name = "Ceská Fio CSV", + Country = Structure.Country.FromCode("CZ"), + Currency = Financial.Currency.FromCode("CZK"), + BankDataProfile = ExternalBankDataProfile.FromIdentity(ExternalBankDataProfile.CZFioId) + }; + + default: + return new FinancialAccountAutomationProfile + { + // Some other, non-upload automation + + CanManualUpload = false, + CanAutoRetrieve = false, + Name = "Unspecified" + }; + } + } + + + public int FinancialAccountAutomationProfileId { get; set; } public string Name { get; set; } - public bool CanRetrieve { get; set; } + public bool CanAutoRetrieve { get; set; } + public bool CanManualUpload { get; set; } [XmlIgnore] public Country Country diff --git a/Site/Pages/v5/Ledgers/UploadBankFiles.aspx b/Site/Pages/v5/Ledgers/UploadBankFiles.aspx index b57149df..dd64dbd2 100644 --- a/Site/Pages/v5/Ledgers/UploadBankFiles.aspx +++ b/Site/Pages/v5/Ledgers/UploadBankFiles.aspx @@ -26,16 +26,14 @@ if (selectedAccountId != 0) { $('#<%=this.UploadFile.ClientID %>_ButtonUploadVisible').fadeIn(); - $.ajax({ - type: "POST", - url: "/Pages/v5/Ledgers/UploadBankFiles.aspx/GetAccountUploadInstructions", - data: "{'guid': '<%= this.UploadFile.GuidString %>', 'accountIdString':'" + $('#<%= this.DropAccounts.ClientID %>').val() + "'}", - contentType: "application/json; charset=utf-8", - dataType: "json", - success: function (msg) { - $('#SpanInstructions').text(msg.d); - } - }); + SwarmopsJS.ajaxCall( + "/Pages/v5/Ledgers/UploadBankFiles.aspx/GetAutomationProfileName", + { + guid: guid, accountId: selectedAccountId + }, + function(result) { + $('#SpanInstructions').text(result.DisplayMessage); + }); } else { $('#<%=this.UploadFile.ClientID %>_ButtonUploadVisible').fadeOut(); } @@ -144,6 +142,8 @@ var progressReceived = false; + var guid = '<%=this.UploadFile.GuidString%>'; + var halfway = false; var currentYear = <%=DateTime.Today.Year %>; diff --git a/Site/Pages/v5/Ledgers/UploadBankFiles.aspx.cs b/Site/Pages/v5/Ledgers/UploadBankFiles.aspx.cs index a9e2fc58..bf986a07 100644 --- a/Site/Pages/v5/Ledgers/UploadBankFiles.aspx.cs +++ b/Site/Pages/v5/Ledgers/UploadBankFiles.aspx.cs @@ -188,7 +188,10 @@ namespace Swarmops.Site.Pages.Ledgers { if (account.AccountType == FinancialAccountType.Asset) { - this.DropAccounts.Items.Add (new ListItem (account.Name, account.Identity.ToString())); + if (account.AutomationProfile.CanManualUpload) + { + this.DropAccounts.Items.Add(new ListItem(account.Name, account.Identity.ToString())); + } } } } @@ -234,27 +237,38 @@ namespace Swarmops.Site.Pages.Ledgers } [WebMethod] - public static string GetAccountUploadInstructions (string guid, string accountIdString) + public static AjaxCallResult GetAutomationProfileName (string guid, string accountIdString) { int accountId = Int32.Parse (accountIdString); + FinancialAccount account = FinancialAccount.FromIdentity(accountId); - // HACK HACK RELENTLESS HACK TODO + AuthenticationData authData = GetAuthenticationDataAndCulture(); - switch (accountId) + if ( + !authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.BookkeepingDetails, + AccessType.Write))) { - case 0: - return string.Empty; - case 1: - case 29: - return "(Instruct Stock-SE-SEB)"; - case 2: - return "(Instruct Stock-Global-Paypal)"; - case 150: - return "(Instruct Stock-DE-Postbank)"; - default: - throw new NotImplementedException(); - + throw new UnauthorizedAccessException(); } + + FinancialAccountAutomationProfile profile = + FinancialAccountAutomationProfile.FromIdentity(account.AutomationProfileId); + + if (profile == null) + { + return new AjaxCallResult + { + Success = true, + DisplayMessage = string.Empty + }; + } + + return new AjaxCallResult + { + Success = true, + DisplayMessage = profile.Name + " (" + profile.Currency.DisplayCode + ")" + }; + } [WebMethod]