From 6c56303502f945dcf57a5db1c5d6bb7bcc32d79d Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 6 Jan 2018 22:39:00 +0100 Subject: [PATCH] More on Expensify, committing work-in-progress --- .../Pages.Financial.designer.cs | 2 +- Site/App_GlobalResources/Pages.Financial.resx | 2 +- Site/Pages/v5/Financial/FileExpenseClaim.aspx | 50 ++++++++++--- .../v5/Financial/FileExpenseClaim.aspx.cs | 74 ++++++++++++++++++- .../FileExpenseClaim.aspx.designer.cs | 18 ++--- 5 files changed, 124 insertions(+), 22 deletions(-) diff --git a/Site/App_GlobalResources/Pages.Financial.designer.cs b/Site/App_GlobalResources/Pages.Financial.designer.cs index 052ced59..afb8be42 100644 --- a/Site/App_GlobalResources/Pages.Financial.designer.cs +++ b/Site/App_GlobalResources/Pages.Financial.designer.cs @@ -898,7 +898,7 @@ namespace Resources.Pages { } /// - /// Looks up a localized string similar to Based on the organization's settings, the "Default CSV" profile in Expensify should be good to go.. + /// Looks up a localized string similar to Based on the organization's settings, the "Default CSV" export profile in Expensify should be sufficient for Swarmops.. /// internal static string FileExpenseClaim_Expensify_InstructionsNothingAdvanced { get { diff --git a/Site/App_GlobalResources/Pages.Financial.resx b/Site/App_GlobalResources/Pages.Financial.resx index 3c199db9..c3389cf2 100644 --- a/Site/App_GlobalResources/Pages.Financial.resx +++ b/Site/App_GlobalResources/Pages.Financial.resx @@ -678,7 +678,7 @@ {0} is the organization name. - Based on the organization's settings, the "Default CSV" profile in Expensify should be good to go. + Based on the organization's settings, the "Default CSV" export profile in Expensify should be sufficient for Swarmops. Upload Expensify Report For Reimbursement diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx b/Site/Pages/v5/Financial/FileExpenseClaim.aspx index c3647ef0..bd2bc27d 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx @@ -85,6 +85,26 @@ } var vatEnable = <%= this.CurrentOrganization.VatEnabled? "true" : "false" %>; + var expensifyProcessingHalfway = false; + + function onExpensifyUpload() { + $('#divExpensifyProcessing').fadeIn(); + $('#divExpensifyProgress').progressbar({ value: 0, max: 100 }); + $('#divExpensifyProgressFake').progressbar({ value: 0, max: 100 }); + $('#divExpensifyProgressFake').progressbar({ value: 100 }); // this guy is swapped in on completion + $('#divExpensifyResults').slideUp(); + expensifyProcessingHalfway = false; + + $.ajax({ + type: "POST", + url: "/Pages/v5/Ledgers/UploadBankFiles.aspx/InitializeProcessing", + data: "{'guid': '<%= this.UploadFile.GuidString %>', 'accountIdString':'" + $('#<%= this.DropAccounts.ClientID %>').val() + "'}", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: function (msg) { + setTimeout('updateProgressProcessing();', 1000); + } + }); } @@ -136,24 +156,34 @@
-

+ + +
+

+

-

-
+ -
- - -
- +
+ +
+
diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs index 4f3392e0..22497932 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs @@ -1,11 +1,17 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Threading; using System.Web; +using System.Web.Services; using Swarmops.Interface.Support; +using Swarmops.Logic.Cache; using Swarmops.Logic.Financial; using Swarmops.Logic.Security; +using Swarmops.Logic.Structure; using Swarmops.Logic.Support; +using Swarmops.Logic.Swarm; +using Swarmops.Site.Pages.Ledgers; namespace Swarmops.Frontend.Pages.v5.Financial { @@ -145,7 +151,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial this.LabelExpensifyCsv.Text = Resources.Pages.Financial.FileExpenseClaim_Expensify_CsvUploadDescription; this.LabelExpensifyInstructions1.Text = Resources.Pages.Financial.FileExpenseClaim_Expensify_InstructionsBasic; - this.ButtonExpensifyUpload.Text = Resources.Global.Global_Upload; if (CurrentOrganization.VatEnabled) { @@ -160,6 +165,73 @@ namespace Swarmops.Frontend.Pages.v5.Financial } + [WebMethod(true)] + public static void InitializeExpensifyProcessing(string guid) + { + // Start an async thread that does all the work, then return + + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + Thread initThread = new Thread(ProcessExpensifyUploadThread); + + ProcessThreadArguments args = new ProcessThreadArguments + { + Guid = guid, + Organization = authData.CurrentOrganization, + CurrentUser = authData.CurrentUser + }; + + initThread.Start(args); + } + + + private class ProcessThreadArguments + { + public string Guid { get; set; } + public Organization Organization { get; set; } + public Person CurrentUser { get; set; } + } + + public class ReportedImportResults + { + public string Category { get; set; } + public string Html { get; set; } + } + + + private static void ProcessExpensifyUploadThread(object args) + { + string guid = ((ProcessThreadArguments) args).Guid; + Person currentUser = ((ProcessThreadArguments) args).CurrentUser; + Organization organization = ((ProcessThreadArguments) args).Organization; + + Documents documents = Documents.RecentFromDescription(guid); + GuidCache.Set(guid + "-Progress", 1); // to make sure results aren't repeated from last file + GuidCache.Set(guid + "-Result", UploadBankFiles.ImportResultsCategory.Bad); + // default - this is what happens if exception + + if (documents.Count != 1) + { + return; // abort + } + + Document uploadedDoc = documents[0]; + } + + + private enum ExpensifyColumns + { + Unknown = 0, + AmountCents, + Description, + CategoryCustom, + CategoryStandard, + VatCents, + ReceiptUrl + } + + + protected void ButtonRequest_Click (object sender, EventArgs e) { // The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here. diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs index e843da06..79db9c53 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.designer.cs @@ -219,6 +219,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::System.Web.UI.WebControls.Label LabelBankAccount; + /// + /// LabelProcessingComplete control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label LabelProcessingComplete; + /// /// LabelExpensifyUploadHeader control. /// @@ -264,15 +273,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial { /// protected global::Swarmops.Controls.Base.FileUpload UploadExpensify; - /// - /// ButtonExpensifyUpload control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Button ButtonExpensifyUpload; - /// /// LabelExpensifyCsv control. ///