Work on Expensify reports: some errors detected

This commit is contained in:
Rick Falkvinge
2018-02-13 12:02:35 +01:00
parent 1edaf018f3
commit 66906069aa
4 changed files with 120 additions and 10 deletions
+36
View File
@@ -879,6 +879,24 @@ namespace Resources.Pages {
}
}
/// <summary>
/// Looks up a localized string similar to &lt;p&gt;&lt;strong&gt;ERROR: Unable to parse the Expensify CSV.&lt;/strong&gt; If this is a CSV file from Expensify, then Swarmops needs the columns &quot;Timestamp&quot;, &quot;Amount&quot;, &quot;Merchant&quot;, &quot;Comment&quot;, &quot;Category&quot;, &quot;MCC&quot;, &quot;Original Currency&quot;, and &quot;Original Amount&quot; to be present in the file. If the organization reports VAT, then a further column called &quot;VAT&quot; is required.&lt;/p&gt;&lt;p&gt;Unable to proceed with this file.&lt;/p&gt;.
/// </summary>
internal static string FileExpenseClaim_Expensify_Error_BadFile {
get {
return ResourceManager.GetString("FileExpenseClaim_Expensify_Error_BadFile", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;p&gt;&lt;strong&gt;ERROR: The Expensify CSV file doesn&apos;t have a VAT field.&lt;/strong&gt; 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 &quot;VAT&quot;. If your team has already created such a CSV profile, you may just need to select it when exporting to CSV.&lt;/p&gt;&lt;p&gt;Unable to process this file.&lt;/p&gt;.
/// </summary>
internal static string FileExpenseClaim_Expensify_Error_NeedsVat {
get {
return ResourceManager.GetString("FileExpenseClaim_Expensify_Error_NeedsVat", resourceCulture);
}
}
/// <summary>
/// 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..
/// </summary>
@@ -915,6 +933,24 @@ namespace Resources.Pages {
}
}
/// <summary>
/// Looks up a localized string similar to myself.
/// </summary>
internal static string FileExpenseClaim_ForWhom_DefaultMyself {
get {
return ResourceManager.GetString("FileExpenseClaim_ForWhom_DefaultMyself", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This is an expense claim from whom?.
/// </summary>
internal static string FileExpenseClaim_ForWhom_Prompt {
get {
return ResourceManager.GetString("FileExpenseClaim_ForWhom_Prompt", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Your Bank Details.
/// </summary>
@@ -686,4 +686,17 @@
<data name="FileExpenseClaim_Title_Expensify" xml:space="preserve">
<value>Upload Expensify Report For Reimbursement</value>
</data>
<data name="FileExpenseClaim_Expensify_Error_BadFile" xml:space="preserve">
<value>&lt;p&gt;&lt;strong&gt;ERROR: Unable to parse the Expensify CSV.&lt;/strong&gt; 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.&lt;/p&gt;&lt;p&gt;Unable to proceed with this file.&lt;/p&gt;</value>
<comment>Do not translate the Expensify column field names.</comment>
</data>
<data name="FileExpenseClaim_Expensify_Error_NeedsVat" xml:space="preserve">
<value>&lt;p&gt;&lt;strong&gt;ERROR: The Expensify CSV file doesn't have a VAT field.&lt;/strong&gt; 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.&lt;/p&gt;&lt;p&gt;Unable to process this file.&lt;/p&gt;</value>
</data>
<data name="FileExpenseClaim_ForWhom_DefaultMyself" xml:space="preserve">
<value>myself</value>
</data>
<data name="FileExpenseClaim_ForWhom_Prompt" xml:space="preserve">
<value>This is an expense claim from whom?</value>
</data>
</root>
+43 -6
View File
@@ -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 @@
<div id="divExpensifyResults" style="display:none; margin-bottom:10px">
<h2><asp:Label ID="LabelProcessingComplete" runat="server" /></h2>
<div id="divExpensifyProgressFake" style="width:100%"></div>
<div id="divExpensifyResultsGood" style="display:none">Good results go here<div id="DivUploadResultsGoodText"></div></div>
<div id="divExpensifyResultsBad" style="display:none">
<div style="float:left;margin-right:10px"><img src="/Images/Icons/iconshock-cross-96px.png" /></div><div id="DivUploadResultsBadText"></div>
<div style="float:left;margin-right:10px"><img src="/Images/Icons/iconshock-cross-96px.png" /></div><div id="DivExpensifyResultsBadText"></div>
</div>
</div>
@@ -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<ExpensifyRecord> recordList = new List<ExpensifyRecord>();
@@ -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
}
}