diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx b/Site/Pages/v5/Financial/FileExpenseClaim.aspx
index ae9a5540..1be3d4cc 100644
--- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx
+++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx
@@ -17,7 +17,33 @@
$(document).ready(function () {
$('#divTabs').tabs();
-
+
+ $('#buttonModalProceed').click(function() {
+
+ });
+
+ $('#buttonModalDelete').click(function () {
+ <%=this.DialogEditExpenseClaim.ClientID%>_close();
+
+ SwarmopsJS.ajaxCall(
+ '/Pages/v5/Financial/FileExpenseClaim.aspx/ExpensifyRecordDelete',
+ { masterGuid: '<%=this.UploadExpensify.GuidString%>', recordGuid: currentlyEditedRecordGuid },
+ function(result) {
+ if (result.Success) {
+ // A record has been deleted. It is possible that a new one is displayed.
+
+ $('#expensifyDataGrid').datagrid('loadData', result.DataUpdate);
+
+ if (result.Guid.length > 1) // there's a new record
+ {
+ currentlyEditedRecordGuid = result.Guid;
+ displayExpensifyRecord(result);
+ }
+
+ }
+ });
+ });
+
});
@@ -95,30 +121,37 @@
},
function(result) {
if (result.Success) {
- <%=this.CurrencyModalExpensifyAmount.ClientID%>_initialize(result.Amount);
- <%=this.CurrencyModalExpensifyAmountVat.ClientID%>_initialize(result.AmountVat);
- $('#textModalExpensifyDescription').val(result.Description);
- <%=this.DialogEditExpenseClaim.ClientID%>_open();
- $('#imgModalDocument').attr('src', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + result.DocumentId);
- $('#imgModalDocument').attr('data-zoom-image', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + result.DocumentId + '&hq=1');
- $('.zoomContainer').remove();
- $('#imgModalDocument').removeData('elevateZoom');
- $('#imgModalDocument').removeData('zoomImage');
- setTimeout(function () {
- $('#imgModalDocument').elevateZoom({
- zoomType: "lens",
- cursor: "crosshair",
- zoomWindowFadeIn: 200,
- zoomWindowFadeOut: 200,
- lensShape: "round",
- lensSize: 150
- });
- }, 50); // delay this slightly for race condition reasons
+ currentlyEditedRecordGuid = result.Guid;
+ displayExpensifyRecord(result);
}
});
}
+ function displayExpensifyRecord(record) {
+ <%=this.CurrencyModalExpensifyAmount.ClientID%>_initialize(record.Amount);
+ <%=this.CurrencyModalExpensifyAmountVat.ClientID%>_initialize(record.AmountVat);
+ $('#textModalExpensifyDescription').val(record.Description);
+ <%=this.DialogEditExpenseClaim.ClientID%>_open();
+ $('#imgModalDocument').attr('src', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + record.DocumentId);
+ $('#imgModalDocument').attr('data-zoom-image', '/Pages/v5/Support/StreamUpload.aspx?DocId=' + record.DocumentId + '&hq=1');
+ $('.zoomContainer').remove();
+ $('#imgModalDocument').removeData('elevateZoom');
+ $('#imgModalDocument').removeData('zoomImage');
+ setTimeout(function () {
+ $('#imgModalDocument').elevateZoom({
+ zoomType: "lens",
+ cursor: "crosshair",
+ zoomWindowFadeIn: 200,
+ zoomWindowFadeOut: 200,
+ lensShape: "round",
+ lensSize: 150
+ });
+ }, 50); // delay this slightly for race condition reasons
+ }
+
+
var expensifyProcessingHalfway = false;
+ var currentlyEditedRecordGuid = '';
function onExpensifyUpload() {
$('#divExpensifyUploadFile').slideUp();
@@ -348,7 +381,7 @@
-
+
Description
Budget charged
Expense amount
VAT amount of the total
diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs
index 40bfe159..e5ab953f 100644
--- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs
+++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs
@@ -5,6 +5,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
+using System.Security.Principal;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
@@ -514,12 +515,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial
List outputRecords = new List();
- string doxString =
- "
";
-
- string editString =
- "
";
-
string docString =
"";
@@ -527,17 +522,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial
foreach (ExpensifyRecord record in recordList)
{
- outputRecords.Add(new ExpensifyOutputRecord
- {
- Budget = "" + Resources.Global.Global_DropInits_SelectFinancialAccount + "",
- Description = record.CategoryCustom + " / " + record.Description,
- CreatedDateTime = record.Timestamp.ToString("MMM dd"),
- Amount = (record.AmountCents / 100.0).ToString("N2"),
- AmountVat = (record.VatCents / 100.0).ToString("N2"),
- Actions = String.Format(doxString, "D" + record.Documents[0].Identity.ToString(CultureInfo.InvariantCulture)) + String.Format(editString, record.Guid),
- Guid = record.Guid
- });
-
foreach (Document document in record.Documents)
{
documentsAll += String.Format(docString, document.Identity,
@@ -549,7 +533,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
AjaxCallExpensifyUploadResult result = new AjaxCallExpensifyUploadResult
{
Success = true,
- Data = outputRecords.ToArray(),
+ Data = FormatExpensifyOutputRecords(recordList),
Documents = documentsAll
};
@@ -560,6 +544,85 @@ namespace Swarmops.Frontend.Pages.v5.Financial
}
+
+ private static ExpensifyOutputRecord[] FormatExpensifyOutputRecords(List recordList)
+ {
+ List outputRecords = new List();
+
+ const string doxString =
+ "
";
+
+ const string editString =
+ "
";
+
+ foreach (ExpensifyRecord record in recordList)
+ {
+ outputRecords.Add(new ExpensifyOutputRecord
+ {
+ Budget =
+ "" +
+ Resources.Global.Global_DropInits_SelectFinancialAccount + "",
+ Description = record.CategoryCustom + " / " + record.Description,
+ CreatedDateTime = record.Timestamp.ToString("MMM dd"),
+ Amount = (record.AmountCents/100.0).ToString("N2"),
+ AmountVat = (record.VatCents/100.0).ToString("N2"),
+ Actions =
+ String.Format(doxString,
+ "D" + record.Documents[0].Identity.ToString(CultureInfo.InvariantCulture)) +
+ String.Format(editString, record.Guid),
+ Guid = record.Guid
+ });
+ }
+
+ return outputRecords.ToArray();
+ }
+
+
+ [WebMethod]
+ public static AjaxCallExpensifyRecordResult ExpensifyRecordProceed(string masterGuid, string recordGuid,
+ int amountCents, int amountVat, int budgetId, string description)
+ {
+ List recordList = (List)GuidCache.Get("ExpensifyData-" + masterGuid);
+
+ throw new NotImplementedException();
+ }
+
+ public static AjaxCallExpensifyRecordResult ExpensifyRecordDelete(string masterGuid, string recordGuid)
+ {
+ List recordList = (List)GuidCache.Get("ExpensifyData-" + masterGuid);
+ int index = LocateRecordsetIndex(recordList, recordGuid);
+
+ recordList.RemoveAt(index);
+ GuidCache.Set("ExpensifyData-" + masterGuid, recordList);
+
+ if (index >= recordList.Count)
+ {
+ // We deleted the last record, so return a null record
+
+ return new AjaxCallExpensifyRecordResult
+ {
+ Guid = "", // indicates null record
+ DataUpdate = FormatExpensifyOutputRecords(recordList)
+ // TODO: CanCommit
+ };
+ }
+
+ // Display the record next in line
+
+ return new AjaxCallExpensifyRecordResult
+ {
+ Amount = (recordList[index].AmountCents / 100.0).ToString("N2"),
+ AmountVat = (recordList[index].VatCents / 100.0).ToString("N2"),
+ Description = recordList[index].Description,
+ DocumentId = recordList[index].Documents.First().Identity,
+ Guid = recordList[index].Guid,
+ ExistNext = (index < recordList.Count - 1 ? true : false),
+ Success = true,
+ DataUpdate = FormatExpensifyOutputRecords(recordList)
+ };
+
+ }
+
[WebMethod]
public static AjaxCallExpensifyUploadResult GetExpensifyUploadResult(string guid)
{
@@ -573,7 +636,22 @@ namespace Swarmops.Frontend.Pages.v5.Financial
public static AjaxCallExpensifyRecordResult GetExpensifyRecord(string masterGuid, string recordGuid)
{
List recordList = (List) GuidCache.Get("ExpensifyData-" + masterGuid);
+ int index = LocateRecordsetIndex(recordList, recordGuid);
+ return new AjaxCallExpensifyRecordResult
+ {
+ Amount = (recordList[index].AmountCents / 100.0).ToString("N2"),
+ AmountVat = (recordList[index].VatCents / 100.0).ToString("N2"),
+ Description = recordList[index].Description,
+ DocumentId = recordList[index].Documents.First().Identity,
+ Guid = recordGuid,
+ ExistNext = (index < recordList.Count - 1? true: false),
+ Success = true
+ };
+ }
+
+ private static int LocateRecordsetIndex(List recordList, string recordGuid)
+ {
// Linear search for the GUID -- a report should have more than a couple dozen records at most
// so this is not a real need for optimization
@@ -587,19 +665,10 @@ namespace Swarmops.Frontend.Pages.v5.Financial
{
// not found
- return new AjaxCallExpensifyRecordResult {Success = false};
+ throw new ArgumentException("Could not locate record GUID");
}
- return new AjaxCallExpensifyRecordResult
- {
- Amount = (recordList[index].AmountCents / 100.0).ToString("N2"),
- AmountVat = (recordList[index].VatCents / 100.0).ToString("N2"),
- Description = recordList[index].Description,
- DocumentId = recordList[index].Documents.First().Identity,
- Guid = recordGuid,
- ExistNext = (index < recordList.Count - 1? true: false),
- Success = true
- };
+ return index;
}
@@ -807,6 +876,9 @@ namespace Swarmops.Frontend.Pages.v5.Financial
public int DocumentId { get; set; }
public string Guid { get; set; }
public bool ExistNext { get; set; }
+
+ public ExpensifyOutputRecord[] DataUpdate { get; set; }
+ public bool CanCommit { get; set; }
}
}
\ No newline at end of file