From a665f7484e392149e25ab8583462dddf0f22f1eb Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Fri, 3 Apr 2015 18:34:17 +0200 Subject: [PATCH] Work on Attestation incl. Db0016 --- Database/Configuration.cs | 2 +- Database/Database-CashAdvances.cs | 27 +++++-- Database/Schemata/revisions.txt | 3 +- Database/Schemata/upgrade-0016.sql | 10 +++ Logic/Financial/CashAdvance.cs | 12 +++ Site5/App_Code/PageV5Base.cs | 5 ++ .../App_GlobalResources/Pages.Financial.resx | 11 ++- Site5/Automation/Formatting.aspx.cs | 16 +++- Site5/Pages/v5/Financial/AttestCosts.aspx | 39 +++++++++- Site5/Pages/v5/Financial/AttestCosts.aspx.cs | 75 +++++++++++++++++-- Site5/Swarmops-v5.js | 34 +++++++++ 11 files changed, 216 insertions(+), 18 deletions(-) create mode 100644 Database/Schemata/upgrade-0016.sql diff --git a/Database/Configuration.cs b/Database/Configuration.cs index 6cb58a95..3524304f 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -14,7 +14,7 @@ namespace Swarmops.Database /// public static int DbVersionExpected { - get { return 15; } + get { return 16; } } diff --git a/Database/Database-CashAdvances.cs b/Database/Database-CashAdvances.cs index a30d8619..521980f1 100644 --- a/Database/Database-CashAdvances.cs +++ b/Database/Database-CashAdvances.cs @@ -124,24 +124,41 @@ namespace Swarmops.Database } - public void SetCashAdvanceOpen (int cashAdvanceId, bool open) + public void SetCashAdvanceBudget(int cashAdvanceId, int budgetId) { using (DbConnection connection = GetMySqlDbConnection()) { connection.Open(); - DbCommand command = GetDbCommand ("SetCashAdvanceOpen", connection); + DbCommand command = GetDbCommand("SetCashAdvanceBudget", connection); command.CommandType = CommandType.StoredProcedure; - AddParameterWithName (command, "cashAdvanceId", cashAdvanceId); - AddParameterWithName (command, "open", open); + AddParameterWithName(command, "cashAdvanceId", cashAdvanceId); + AddParameterWithName(command, "budgetId", budgetId); command.ExecuteNonQuery(); } } - public void SetCashAdvanceAttested (int cashAdvanceId, bool attested, int attestedByPersonId) + public void SetCashAdvanceOpen(int cashAdvanceId, bool open) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetCashAdvanceOpen", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "cashAdvanceId", cashAdvanceId); + AddParameterWithName(command, "open", open); + + command.ExecuteNonQuery(); + } + } + + + public void SetCashAdvanceAttested(int cashAdvanceId, bool attested, int attestedByPersonId) { using (DbConnection connection = GetMySqlDbConnection()) { diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index 153e38d6..21343236 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -12,4 +12,5 @@ 0012 - Renamed "Roles" to "Positions" to clarify terminology [RF] 0013 - Added PositionTitles for organizational culture flexibility [RF] 0014 - Forgot one storedproc in Db0012; renamed CreateAssignedRole [RF] -0015 - Merged PositionsStandard and PositionsAdditional into one table [RF] \ No newline at end of file +0015 - Merged PositionsStandard and PositionsAdditional into one table [RF] +0016 - Added SetCashAdvanceBudget procedure [RF] \ No newline at end of file diff --git a/Database/Schemata/upgrade-0016.sql b/Database/Schemata/upgrade-0016.sql new file mode 100644 index 00000000..177754d9 --- /dev/null +++ b/Database/Schemata/upgrade-0016.sql @@ -0,0 +1,10 @@ +CREATE PROCEDURE `SetCashAdvanceBudget`( + IN cashAdvanceId INTEGER, + IN budgetId INTEGER +) +BEGIN + + UPDATE CashAdvances SET CashAdvances.FinancialAccountId=budgetId + WHERE CashAdvances.CashAdvanceId=cashAdvanceId; + +END diff --git a/Logic/Financial/CashAdvance.cs b/Logic/Financial/CashAdvance.cs index 9f87e573..4ea1d6ce 100644 --- a/Logic/Financial/CashAdvance.cs +++ b/Logic/Financial/CashAdvance.cs @@ -164,6 +164,18 @@ namespace Swarmops.Logic.Financial public FinancialAccount Budget { get { return FinancialAccount.FromIdentity (BudgetId); } + set + { + if (BudgetId != value.Identity) + { + if (this.Open) // requirement + { + SwarmDb.GetDatabaseForWriting().SetCashAdvanceBudget (this.Identity, value.Identity); + base.BudgetId = value.Identity; + } + } + + } } public Organization Organization diff --git a/Site5/App_Code/PageV5Base.cs b/Site5/App_Code/PageV5Base.cs index efe3e5c3..e3e2e0d7 100644 --- a/Site5/App_Code/PageV5Base.cs +++ b/Site5/App_Code/PageV5Base.cs @@ -168,6 +168,11 @@ public class PageV5Base : Page { this.IncludedControlsUsed |= control; } + + public string JavascriptEscape (string input) + { + return System.Uri.EscapeDataString (input).Replace ("'", "%27"); // makes it safe to embed in single quotes client-side + } } diff --git a/Site5/App_GlobalResources/Pages.Financial.resx b/Site5/App_GlobalResources/Pages.Financial.resx index 7b962f02..ac60cae7 100644 --- a/Site5/App_GlobalResources/Pages.Financial.resx +++ b/Site5/App_GlobalResources/Pages.Financial.resx @@ -125,6 +125,15 @@ Cash Advance #{0:N0} for {1} was UN-attested. It will not be paid out unless attested again. When somebody undoes a previous attestation. + + Sorry, you cannot rebudget a salary payout. + + + That doesn't seem to be a valid amount. Please retry? + + + Please select a budget to retarget the charge for. + Expense Claim #{0:N0} from {1} for {2} {3:N2} has been attested. {2} is the currency. @@ -219,7 +228,7 @@ There are not enough funds remaining in the budget to attest this cost. - There are not enough funds to attest this. You can attest up to {0} {1:N2} more for {2} in this budget. + There are not enough funds to attest this. You can attest up to {0} {1:N2} more in this budget for the year {2}. The {0} is the currency and the {1} is the remaining budget. The {2} is the current year. diff --git a/Site5/Automation/Formatting.aspx.cs b/Site5/Automation/Formatting.aspx.cs index a1b715d0..2f216829 100644 --- a/Site5/Automation/Formatting.aspx.cs +++ b/Site5/Automation/Formatting.aspx.cs @@ -21,10 +21,22 @@ namespace Swarmops.Frontend.Automation /// The integer to format. /// The formatted integer for display. [WebMethod] - public static string FormatInteger (int input) + public static string FormatInteger(int input) { GetAuthenticationDataAndCulture(); - return input.ToString ("N0"); + return input.ToString("N0"); + } + + /// + /// Returns a culturally-formatted double with thousands separators and two decimals. + /// + /// The double to format. + /// The formatted double for display. + [WebMethod] + public static string FormatCurrency(double input) + { + GetAuthenticationDataAndCulture(); + return input.ToString("N2"); } } diff --git a/Site5/Pages/v5/Financial/AttestCosts.aspx b/Site5/Pages/v5/Financial/AttestCosts.aspx index 934c3e62..a918bb55 100644 --- a/Site5/Pages/v5/Financial/AttestCosts.aspx +++ b/Site5/Pages/v5/Financial/AttestCosts.aspx @@ -20,7 +20,7 @@ '/Images/Abstract/ajaxloader-medium.gif', '/Images/Icons/iconshock-balloon-yes-128x96px-hot.png', '/Images/Icons/iconshock-balloon-yes-128x96px-disabled.png', - '/Images/Icons/iconshock-balloon-yes-128x96px-disabled-hot.png', + '/Images/Icons/iconshock-balloon-yes-128x96px-hot-disabled.png', '/Images/Icons/iconshock-balloon-no-128x96px-hot.png', '/Images/Icons/iconshock-green-tick-128x96px.png', '/Images/Icons/iconshock-red-cross-128x96px.png', @@ -98,8 +98,14 @@ }); $(".LocalIconDenial").click(function() { - if ($(this).attr("rel") != "loading" && $("#IconDenial" + $(this).attr("baseid")) != "loading") { + if ($(this).attr("rel") != "loading" && $("#IconApproval" + $(this).attr("baseid")) != "loading") { + recordId = $(this).attr("baseid"); + var amountRequested = $("#IconApproval" + recordId).attr('amount'); + accountId = $("#IconApproval" + recordId).attr('accountid'); $('div.radioOption').hide(); + $('input:radio[name="ModalOptions"]').prop('checked', false); + SwarmopsJS.formatCurrency(amountRequested, function (data) { $('#<%=this.TextDifferentAmount.ClientID%>_Input').val(data); }); + $('<%=this.TextDenyReason.ClientID%>').val(''); // empty reason <%=this.DialogDeny.ClientID%>_open(); } }); @@ -288,6 +294,33 @@ budgetRemainingLookup.attestabilityInitialized = true; } + function onRebudgetRecord() { + var newAccountId = <%=this.DropBudgetsRebudget.ClientID%>_val(); + if (newAccountId == 0) { + alertify.error(decodeURIComponent('')); + return; + } + if (recordId[0] == 'S') // Salary - cannot rebudget + { + alertify.error(decodeURIComponent('')); + } + + + // We have a valid budget, and there are no more fail conditions, so close the modal, issue the change, and when + // returned, reload the grid data + + <%= this.DialogDeny.ClientID %>_close(); + SwarmopsJS.ajaxCall( + "/Pages/v5/Financial/AttestCosts.aspx/RebudgetItem", + { recordId: recordId, newAccountId: newAccountId }, + function(data) { + // this is when the change is completed + $('#TableAttestableCosts').datagrid('reload'); + }); + } + + var recordId = ''; + var accountId = 0; var budgetRemainingLookup = {}; @@ -362,7 +395,7 @@

- ​
+ ​