From 0341cb1726ff5ae7be352aea155cc53b0767efe8 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 4 Mar 2018 13:18:23 +0100 Subject: [PATCH] Trying adding footer to Expensify --- Site/Pages/v5/Financial/FileExpenseClaim.aspx | 22 +++++++++--- .../v5/Financial/FileExpenseClaim.aspx.cs | 34 +++++++++++++++++-- 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx b/Site/Pages/v5/Financial/FileExpenseClaim.aspx index 811071c5..49d72b88 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx @@ -54,7 +54,7 @@ function(result) { if (result.Success) { - displayExpensifyDataGrid(result.DataUpdate); + displayExpensifyDataGrid(result.DataUpdate, result.FooterUpdate); if (result.Guid.length > 1) // there's a new record { @@ -79,7 +79,7 @@ if (result.Success) { // A record has been deleted. It is possible that a new one is displayed. - displayExpensifyDataGrid(result.DataUpdate); + displayExpensifyDataGrid(result.DataUpdate, result.FooterUpdate); if (result.Guid.length > 1) // there's a new record { @@ -198,9 +198,21 @@ } - function displayExpensifyDataGrid(data) { + function displayExpensifyDataGrid(rows, footer) { - $('#expensifyDataGrid').datagrid('loadData', data); + var gridData = { + rows: rows, + footer: footer + }; + + $('#expensifyDataGrid').datagrid('loadData', gridData); + + $('#expensifyDataGrid').datagrid('mergeCells', { + index: 1, + field: 'BudgetText', + colspan: 3, + type: 'footer' + }); // Bind to enable document viewing @@ -287,7 +299,7 @@ $('#divDocumentsHidden').html(result.Documents); - displayExpensifyDataGrid(result.Data); + displayExpensifyDataGrid(result.Data, result.Footer); } else { diff --git a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs index 670c32f1..942f9abf 100644 --- a/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs +++ b/Site/Pages/v5/Financial/FileExpenseClaim.aspx.cs @@ -536,6 +536,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial { Success = true, Data = FormatExpensifyOutputRecords(recordList), + Footer = FormatExpensifyFooter(recordList), Documents = documentsAll }; @@ -596,6 +597,31 @@ namespace Swarmops.Frontend.Pages.v5.Financial } + private static ExpensifyOutputRecord[] FormatExpensifyFooter(List recordList) + { + Int64 amountCentsTotal =0; + Int64 vatCentsTotal =0; + + foreach (ExpensifyRecord record in recordList) + { + amountCentsTotal += record.AmountCents; + vatCentsTotal += record.VatCents; + } + + ExpensifyOutputRecord newRecord = new ExpensifyOutputRecord + { + Amount = "" + amountCentsTotal.ToString("N2") + "", + AmountVat = "" + amountCentsTotal.ToString("N2") + "", + BudgetText = "" + Resources.Global.Global_Total + "" + }; + + List listResult = new List(); + listResult.Add(newRecord); + + return listResult.ToArray(); + } + + [WebMethod] public static AjaxCallExpensifyRecordResult ExpensifyRecordProceed(string masterGuid, string recordGuid, string amountString, string amountVatString, int budgetId, string description) @@ -649,7 +675,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial Guid = recordList[index].Guid, ExistNext = (index < recordList.Count - 1 ? true : false), Success = true, - DataUpdate = FormatExpensifyOutputRecords(recordList) + DataUpdate = FormatExpensifyOutputRecords(recordList), + FooterUpdate = FormatExpensifyFooter (recordList) }; } @@ -687,7 +714,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial Guid = recordList[index].Guid, ExistNext = (index < recordList.Count - 1 ? true : false), Success = true, - DataUpdate = FormatExpensifyOutputRecords(recordList) + DataUpdate = FormatExpensifyOutputRecords(recordList), + FooterUpdate = FormatExpensifyFooter(recordList) }; } @@ -937,6 +965,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial { public string ErrorType { get; set; } public ExpensifyOutputRecord[] Data { get; set; } + public ExpensifyOutputRecord[] Footer { get; set; } public string Documents { get; set; } } @@ -951,6 +980,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial public bool ExistNext { get; set; } public ExpensifyOutputRecord[] DataUpdate { get; set; } + public ExpensifyOutputRecord[] FooterUpdate { get; set; } public bool CanCommit { get; set; } }