From 66906069aa0270f9486f15281506df757c64af01 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 13 Feb 2018 12:02:35 +0100 Subject: [PATCH] Work on Expensify reports: some errors detected --- .../Pages.Financial.designer.cs | 36 ++++++++++++++ Site/App_GlobalResources/Pages.Financial.resx | 13 +++++ Site/Pages/v5/Financial/FileExpenseClaim.aspx | 49 ++++++++++++++++--- .../v5/Financial/FileExpenseClaim.aspx.cs | 32 ++++++++++-- 4 files changed, 120 insertions(+), 10 deletions(-) diff --git a/Site/App_GlobalResources/Pages.Financial.designer.cs b/Site/App_GlobalResources/Pages.Financial.designer.cs index c9c38830..3962ea9b 100644 --- a/Site/App_GlobalResources/Pages.Financial.designer.cs +++ b/Site/App_GlobalResources/Pages.Financial.designer.cs @@ -879,6 +879,24 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to <p><strong>ERROR: Unable to parse the Expensify CSV.</strong> If this is a CSV file from Expensify, then Swarmops needs the columns "Timestamp", "Amount", "Merchant", "Comment", "Category", "MCC", "Original Currency", and "Original Amount" to be present in the file. If the organization reports VAT, then a further column called "VAT" is required.</p><p>Unable to proceed with this file.</p>. + /// + internal static string FileExpenseClaim_Expensify_Error_BadFile { + get { + return ResourceManager.GetString("FileExpenseClaim_Expensify_Error_BadFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to <p><strong>ERROR: The Expensify CSV file doesn't have a VAT field.</strong> Since this organization reports Value Added Tax (VAT) to authorities, this must be specified on a per-expense basis. Please enable VAT in Expensify and create a new CSV export profile that exports this under the column header "VAT". If your team has already created such a CSV profile, you may just need to select it when exporting to CSV.</p><p>Unable to process this file.</p>. + /// + internal static string FileExpenseClaim_Expensify_Error_NeedsVat { + get { + return ResourceManager.GetString("FileExpenseClaim_Expensify_Error_NeedsVat", resourceCulture); + } + } + /// /// Looks up a localized string similar to If you have many expense reports, you can gather them with Expensify and upload an Expensify CSV report here (which you obtain from at Expensify under Reports, Export, as CSV). Swarmops will use Expensify to fetch all the individual receipts and log them as separate expense claims for proper accounting.. /// @@ -915,6 +933,24 @@ namespace Resources.Pages { } } + /// + /// Looks up a localized string similar to myself. + /// + internal static string FileExpenseClaim_ForWhom_DefaultMyself { + get { + return ResourceManager.GetString("FileExpenseClaim_ForWhom_DefaultMyself", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This is an expense claim from whom?. + /// + internal static string FileExpenseClaim_ForWhom_Prompt { + get { + return ResourceManager.GetString("FileExpenseClaim_ForWhom_Prompt", resourceCulture); + } + } + /// /// Looks up a localized string similar to Your Bank Details. /// diff --git a/Site/App_GlobalResources/Pages.Financial.resx b/Site/App_GlobalResources/Pages.Financial.resx index 3d456b48..129af430 100644 --- a/Site/App_GlobalResources/Pages.Financial.resx +++ b/Site/App_GlobalResources/Pages.Financial.resx @@ -686,4 +686,17 @@ Upload Expensify Report For Reimbursement + + <p><strong>ERROR: Unable to parse the Expensify CSV.</strong> If this is a CSV file from Expensify, then Swarmops needs the columns "Timestamp", "Amount", "Merchant", "Comment", "Category", "MCC", "Original Currency", and "Original Amount" to be present in the file. If the organization reports VAT, then a further column called "VAT" is required.</p><p>Unable to proceed with this file.</p> + Do not translate the Expensify column field names. + + + <p><strong>ERROR: The Expensify CSV file doesn't have a VAT field.</strong> Since this organization reports Value Added Tax (VAT) to authorities, this must be specified on a per-expense basis. Please enable VAT in Expensify and create a new CSV export profile that exports this under the column header "VAT". If your team has already created such a CSV profile, you may just need to select it when exporting to CSV.</p><p>Unable to process this file.</p> + + + myself + + + This is an expense claim from whom? + \ No newline at end of file diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx b/Site/Pages/v5/Financial/FileExpenseClaim.aspx index c2f2d7a8..bd86695c 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx @@ -110,10 +110,48 @@ } function onExpensifyProgressComplete() { - <%=this.ProgressExpensify.ClientID%>_hide(); - <%=this.ProgressExpensifyFake.ClientID%>_show(); - $('#divUploadExpensify').hide(); - $('#divExpensifyUploadAnotherHeader').show(); + // Get results + + $('#divExpensifyUploadHeader').hide(); // this should be hidden at this time regardless of result + + SwarmopsJS.ajaxCall('/Pages/v5/Financial/FileExpenseClaim.aspx/GetExpensifyResults', + { guidFiles: '<%=this.UploadExpensify.GuidString%>'}, + function(result) { + if (result.Success) { + + // Make a neat transition to success view + + $('#divExpensifyResultsBad').hide(); + $('#divExpensifyResultsGood').show(); + <%=this.ProgressExpensify.ClientID%>_hide(); + <%=this.ProgressExpensifyFake.ClientID%>_show(); + $('#divUploadExpensify').hide(); + $('#divExpensifyUploadAnotherHeader').show(); + $('#divExpensifyResults').slideDown(); + + } else { + + // Make a brutal transition to failure view + + $('#divUploadExpensify').show(); // re-show + <%=this.ProgressExpensify.ClientID%>_hide(); + + if (result.ErrorType == "ERR_NEEDSVAT") { + $('#divExpensifyResultsBad').show(); + $('#divExpensifyResultsGood').hide(); + $('#divExpensifyResults').show(); + $('#divExpensifyUploadAnotherHeader').show(); + $('#divExpensifyResultsBadText').innerHTML(result.DisplayMessage); + } + + } + + // Regardless of whether result is good or bad, reset the upload control + + <%=this.UploadExpensify.ClientID%>_clear(); + }) + + } @@ -173,12 +211,11 @@ diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs index 5fd2edca..9f6f0717 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs @@ -222,7 +222,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial Documents documents = Documents.RecentFromDescription(guidFiles); progress.Set(1); - GuidCache.Set(guidProgress + "-UploadResult", UploadBankFiles.ImportResultsCategory.Bad); // default - this is what happens if exception if (documents.Count != 1) @@ -300,8 +299,16 @@ namespace Swarmops.Frontend.Pages.v5.Financial // Set progress to complete // Abort - GuidCache.Set(guidProgress, 100); // terminate progress bar - throw new BarfException(); + GuidCache.Set("Results-" + guidFiles, new AjaxCallExpensifyUploadResult + { + Success = false, + ErrorType = "ERR_NEEDSVAT", + DisplayMessage = Resources.Pages.Financial.FileExpenseClaim_Expensify_Error_NeedsVat + }); + + progress.Set(100); // terminate progress bar, causes retrieval of result + + return; // terminates thread } List recordList = new List(); @@ -468,6 +475,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial } + [WebMethod] + public static AjaxCallExpensifyUploadResult GetExpensifyUploadResult(string guid) + { + // This may throw and it's okay + + return (AjaxCallExpensifyUploadResult) GuidCache.Get("Results-" + guid); + } + + public class BarfException: Exception {} @@ -637,6 +653,14 @@ namespace Swarmops.Frontend.Pages.v5.Financial { get { return JavascriptEscape(Resources.Pages.Financial.FileExpenseClaim_ValidationError_Documents); } } - } + + + public class AjaxCallExpensifyUploadResult: AjaxCallResult + { + public string ErrorType { get; set; } + // Todo: the whole damn data structure + } + + } \ No newline at end of file