Work on Expensify upload

This commit is contained in:
Rick Falkvinge
2018-02-15 13:07:00 +01:00
parent b74881706a
commit 44374cdd1b
5 changed files with 56 additions and 6 deletions
+9
View File
@@ -888,6 +888,15 @@ namespace Resources.Pages {
}
}
/// <summary>
/// Looks up a localized string similar to &lt;p&gt;&lt;strong&gt;ERROR: The Expensify CSV file is missing required data fields.&lt;/strong&gt; The file appears to be missing at least one of the required fields of Expensify&apos;s default CSV profile. Refer to the technical documentation and compare with the file you tried to upload. (It is a more probable cause of error, of course, that you tried to upload the completely wrong file &amp;ndash; maybe a photograph instead of an Expensify CSV &amp;ndash; and that this is the cause for the missing expected data.)&lt;/p&gt;&lt;p&gt;Unable to pro [rest of string was truncated]&quot;;.
/// </summary>
internal static string FileExpenseClaim_Expensify_Error_InvalidCsv {
get {
return ResourceManager.GetString("FileExpenseClaim_Expensify_Error_InvalidCsv", 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>
@@ -703,4 +703,7 @@
<data name="FileExpenseClaim_ForWhom_Prompt" xml:space="preserve">
<value>This is an expense claim from whom?</value>
</data>
<data name="FileExpenseClaim_Expensify_Error_InvalidCsv" xml:space="preserve">
<value>&lt;p&gt;&lt;strong&gt;ERROR: The Expensify CSV file is missing required data fields.&lt;/strong&gt; The file appears to be missing at least one of the required fields of Expensify's default CSV profile. Refer to the technical documentation and compare with the file you tried to upload. (It is a more probable cause of error, of course, that you tried to upload the completely wrong file &amp;ndash; maybe a photograph instead of an Expensify CSV &amp;ndash; and that this is the cause for the missing expected data.)&lt;/p&gt;&lt;p&gt;Unable to process this file.&lt;/p&gt;</value>
</data>
</root>
+2
View File
@@ -20,9 +20,11 @@
function <%=this.ClientID%>_reset() {
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 0 });
<%=this.ClientID%>_lastProgress = 0;
}
function <%=this.ClientID%>_begin() {
<%=this.ClientID%>_lastProgress = 0;
$('#Div_<%=this.ClientID %>_ProgressBar').progressbar({ value: 0, max: 100 });
<%=this.ClientID%>_nextPollTimer = setTimeout(function() { <%= this.ClientID%>_progressFallbackPoll(); }, 2500);
progressUpdateCallback_<%=this.GuidToken%>(1); // Initializes a small piece of bar
@@ -113,7 +113,7 @@
$('#divExpensifyUploadHeader').hide(); // this should be hidden at this time regardless of result
SwarmopsJS.ajaxCall('/Pages/v5/Financial/FileExpenseClaim.aspx/GetExpensifyUploadResult',
{ guid: '<%=this.UploadExpensify.GuidString%>'},
{ guid: '<%=this.UploadExpensify.GuidString%>' },
function(result) {
if (result.Success) {
@@ -122,17 +122,23 @@
$('#divExpensifyResultsBad').hide();
$('#divExpensifyResultsGood').show();
<%=this.ProgressExpensify.ClientID%>_hide();
<%=this.ProgressExpensify.ClientID%>_reset();
<%=this.ProgressExpensifyFake.ClientID%>_show();
$('#divUploadExpensify').hide();
$('#divExpensifyUploadAnotherHeader').show();
$('#divExpensifyResults').slideDown();
// Display processed data
} else {
// Make a brutal transition to failure view
<%=this.ProgressExpensify.ClientID%>_fadeOut();
<%=this.ProgressExpensify.ClientID%>_hide(); // both fadeOut + hide necessary
<%=this.ProgressExpensify.ClientID%>_reset();
<%=this.ProgressExpensifyFake.ClientID%>_hide();
$('#divExpensifyResultsBad').show();
@@ -148,7 +154,7 @@
// Regardless of whether result is good or bad, reset the upload control
<%=this.UploadExpensify.ClientID%>_clear();
})
});
}
@@ -292,6 +292,40 @@ namespace Swarmops.Frontend.Pages.v5.Financial
}
}
ExpensifyColumns[] requiredData =
{
ExpensifyColumns.AmountFloat,
ExpensifyColumns.CategoryCustom,
ExpensifyColumns.CategoryStandard,
ExpensifyColumns.Comment,
ExpensifyColumns.Merchant,
ExpensifyColumns.OriginalCurrency,
ExpensifyColumns.OriginalCurrencyAmountFloat,
ExpensifyColumns.ReceiptUrl,
ExpensifyColumns.Timestamp
};
foreach (ExpensifyColumns requiredColumn in requiredData)
{
if (!fieldMap.ContainsKey(requiredColumn))
{
// Abort as invalid file
GuidCache.Set("Results-" + guidFiles, new AjaxCallExpensifyUploadResult
{
Success = false,
ErrorType = "ERR_INVALIDCSV",
DisplayMessage = Resources.Pages.Financial.FileExpenseClaim_Expensify_Error_InvalidCsv
});
progress.Set(100); // terminate progress bar, causes retrieval of result
documents[0].Delete(); // prevents further processing
return; // terminates thread
}
}
// TODO: Much more general-case error conditions if not all fields are filled
bool vatEnabled = organization.VatEnabled;
@@ -299,10 +333,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial
if (vatEnabled && !fieldMap.ContainsKey(ExpensifyColumns.VatFloat))
{
// Error: Organization needs a VAT field
// TODO
// Set result to bad
// Set progress to complete
// Abort
GuidCache.Set("Results-" + guidFiles, new AjaxCallExpensifyUploadResult
{