Committing Expensify might work

This commit is contained in:
Rick Falkvinge
2018-03-04 19:02:12 +01:00
parent c9eabed403
commit 5fadf90435
4 changed files with 112 additions and 0 deletions
+18
View File
@@ -987,6 +987,24 @@ namespace Resources.Pages {
}
}
/// <summary>
/// Looks up a localized string similar to Claim successfully filed..
/// </summary>
internal static string FileExpenseClaim_Expensify_SuccessOne {
get {
return ResourceManager.GetString("FileExpenseClaim_Expensify_SuccessOne", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Successfully filed {0} claims..
/// </summary>
internal static string FileExpenseClaim_Expensify_SuccessSeveral {
get {
return ResourceManager.GetString("FileExpenseClaim_Expensify_SuccessSeveral", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Upload Another Expensify CSV File?.
/// </summary>
@@ -725,4 +725,10 @@
<value>Ready to submit {0} claims</value>
<comment>The {0} is replaced by a number, 2 or higher</comment>
</data>
<data name="FileExpenseClaim_Expensify_SuccessOne" xml:space="preserve">
<value>Claim successfully filed.</value>
</data>
<data name="FileExpenseClaim_Expensify_SuccessSeveral" xml:space="preserve">
<value>Successfully filed {0} claims.</value>
</data>
</root>
@@ -121,6 +121,24 @@
});
});
$('#buttonExpensifySubmit').click(function() {
SwarmopsJS.ajaxCall (
'/Pages/v5/Financial/FileExpenseClaim.aspx/ExpensifyRecordsetCommit',
{ masterGuid: '<%=this.UploadExpensify.GuidString%>' },
function(result) {
if (result.Success) {
alertify.success(result.DisplayMessage);
$('#divExpensifyResults').slideUp();
$('#divExpensifyUploadAnotherHeader').show();
$('#divExpensifyUploadFile').show();
$('#divExpensifyInstructions').hide();
$('#divUploadExpensify').slideDown();
} else {
alertify.dialog(result.DisplayMessage);
console.log(result.DisplayMessage);
}
});
}); // end of doc.ready
@@ -5,6 +5,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Security.Principal;
using System.Text.RegularExpressions;
using System.Threading;
@@ -21,6 +22,7 @@ using Swarmops.Logic.Support.BackendServices;
using Swarmops.Logic.Swarm;
using Swarmops.Site.Pages.Ledgers;
using CsvHelper;
using Swarmops.Common.Enums;
using Swarmops.Frontend.Automation;
using Formatting = Swarmops.Logic.Support.Formatting;
@@ -259,6 +261,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
csvEntire = reader.ReadToEnd();
}
GuidCache.Set("ExpensifyRaw-" + guidFiles, csvEntire);
string[] csvLines = csvEntire.Split(new char[] {'\r', '\n'});
string[] fieldNames = csvLines[0].Split(',');
@@ -663,6 +667,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
public static AjaxCallExpensifyRecordResult ExpensifyRecordProceed(string masterGuid, string recordGuid,
string amountString, string amountVatString, int budgetId, string description)
{
GetAuthenticationDataAndCulture();
List<ExpensifyRecord> recordList = (List<ExpensifyRecord>)GuidCache.Get("ExpensifyData-" + masterGuid);
int index = LocateRecordsetIndex(recordList, recordGuid);
@@ -724,6 +730,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
[WebMethod]
public static AjaxCallExpensifyRecordResult ExpensifyRecordDelete(string masterGuid, string recordGuid)
{
GetAuthenticationDataAndCulture();
List<ExpensifyRecord> recordList = (List<ExpensifyRecord>)GuidCache.Get("ExpensifyData-" + masterGuid);
int index = LocateRecordsetIndex(recordList, recordGuid);
@@ -763,6 +771,66 @@ namespace Swarmops.Frontend.Pages.v5.Financial
}
[WebMethod]
public static AjaxCallResult ExpensifyRecordsetCommit(string masterGuid)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
// Commit all expenses in the recordset
try
{
List<ExpensifyRecord> recordList = (List<ExpensifyRecord>) GuidCache.Get("ExpensifyData-" + masterGuid);
string expensifyRaw = (string) GuidCache.Get("ExpensifyRaw-" + masterGuid);
ExpenseClaimGroup expenseClaimGroup = ExpenseClaimGroup.Create(authData.CurrentOrganization,
authData.CurrentUser, ExpenseClaimGroupType.Expensify, expensifyRaw);
foreach (ExpensifyRecord record in recordList)
{
FinancialAccount budget = FinancialAccount.FromIdentity(record.BudgetId);
ExpenseClaim claim = ExpenseClaim.Create(authData.CurrentUser, authData.CurrentOrganization, budget,
record.Timestamp, record.CategoryCustom + " / " + record.Description, record.AmountCents,
record.VatCents,
expenseClaimGroup);
record.Documents.SetForeignObjectForAll(claim);
// TODO: Log
}
if (recordList.Count > 1)
{
return new AjaxCallResult
{
Success = true,
DisplayMessage =
String.Format(Resources.Pages.Financial.FileExpenseClaim_Expensify_SuccessSeveral,
recordList.Count)
};
}
return new AjaxCallResult
{
Success = true,
DisplayMessage = Resources.Pages.Financial.FileExpenseClaim_Expensify_SuccessOne
};
}
catch (Exception exc)
{
return new AjaxCallResult
{
Success = false,
DisplayMessage = exc.ToString()
};
}
}
[WebMethod]
public static AjaxCallExpensifyUploadResult GetExpensifyUploadResult(string guid)
{
@@ -775,6 +843,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
[WebMethod]
public static AjaxCallExpensifyRecordResult GetExpensifyRecord(string masterGuid, string recordGuid)
{
GetAuthenticationDataAndCulture();
List<ExpensifyRecord> recordList = (List<ExpensifyRecord>) GuidCache.Get("ExpensifyData-" + masterGuid);
int index = LocateRecordsetIndex(recordList, recordGuid);