Work on Attestation incl. Db0016

This commit is contained in:
Rick Falkvinge
2015-04-03 18:34:17 +02:00
parent 986588cc05
commit a665f7484e
11 changed files with 216 additions and 18 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Database
/// </summary>
public static int DbVersionExpected
{
get { return 15; }
get { return 16; }
}
+22 -5
View File
@@ -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())
{
+2 -1
View File
@@ -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]
0015 - Merged PositionsStandard and PositionsAdditional into one table [RF]
0016 - Added SetCashAdvanceBudget procedure [RF]
+10
View File
@@ -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
+12
View File
@@ -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
+5
View File
@@ -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
}
}
+10 -1
View File
@@ -125,6 +125,15 @@
<value>Cash Advance #{0:N0} for {1} was UN-attested. It will not be paid out unless attested again.</value>
<comment>When somebody undoes a previous attestation.</comment>
</data>
<data name="AttestCosts_Error_CantRebudgetSalary" xml:space="preserve">
<value>Sorry, you cannot rebudget a salary payout.</value>
</data>
<data name="AttestCosts_Error_InvalidAmountRetry" xml:space="preserve">
<value>That doesn't seem to be a valid amount. Please retry?</value>
</data>
<data name="AttestCosts_Error_PleaseSelectBudget" xml:space="preserve">
<value>Please select a budget to retarget the charge for.</value>
</data>
<data name="AttestCosts_ExpenseAttested" xml:space="preserve">
<value>Expense Claim #{0:N0} from {1} for {2} {3:N2} has been attested.</value>
<comment>{2} is the currency.</comment>
@@ -219,7 +228,7 @@
<value>There are not enough funds remaining in the budget to attest this cost.</value>
</data>
<data name="AttestCosts_OutOfBudgetPrecise" xml:space="preserve">
<value>There are not enough funds to attest this. You can attest up to {0} {1:N2} more for {2} in this budget.</value>
<value>There are not enough funds to attest this. You can attest up to {0} {1:N2} more in this budget for the year {2}.</value>
<comment>The {0} is the currency and the {1} is the remaining budget. The {2} is the current year.</comment>
</data>
<data name="AttestCosts_PageTitle" xml:space="preserve">
+14 -2
View File
@@ -21,10 +21,22 @@ namespace Swarmops.Frontend.Automation
/// <param name="input">The integer to format.</param>
/// <returns>The formatted integer for display.</returns>
[WebMethod]
public static string FormatInteger (int input)
public static string FormatInteger(int input)
{
GetAuthenticationDataAndCulture();
return input.ToString ("N0");
return input.ToString("N0");
}
/// <summary>
/// Returns a culturally-formatted double with thousands separators and two decimals.
/// </summary>
/// <param name="input">The double to format.</param>
/// <returns>The formatted double for display.</returns>
[WebMethod]
public static string FormatCurrency(double input)
{
GetAuthenticationDataAndCulture();
return input.ToString("N2");
}
}
+36 -3
View File
@@ -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('<asp:Literal ID="LiteralPleaseSelectBudget" runat="server" />'));
return;
}
if (recordId[0] == 'S') // Salary - cannot rebudget
{
alertify.error(decodeURIComponent('<asp:Literal ID="LiteralCannotRebudgetSalary" runat="server" />'));
}
// 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 = {};
</script>
@@ -362,7 +395,7 @@
<p><input type="radio" id="RadioRebudget" name="ModalOptions" value="Rebudget" /><label for="RadioRebudget"><asp:Label runat="server" ID="LabelRadioRebudget" Text="This record should be charging a different budget. XYZ" /></label></p>
<div id="radioOptionRebudget" class="radioOption">
<div class="entryFields">
<Swarmops5:ComboBudgets ID="DropBudgetBalance" runat="server" ListType="Expensable" />&#8203;<br/>
<Swarmops5:ComboBudgets ID="DropBudgetsRebudget" runat="server" ListType="Expensable" />&#8203;<br/>
<input type="button" value='<asp:Literal ID="LiteralButtonRebudget" runat="server" Text="RebudgetXYZ" />' class="buttonAccentColor" onclick="onRebudgetRecord(); return false;" id="buttonExecuteRebudget"/>
</div>
<div class="entryLabels">
+70 -5
View File
@@ -89,23 +89,83 @@ namespace Swarmops.Frontend.Pages.v5.Financial
this.LabelGridHeaderItem.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Item;
this.LabelGridHeaderRequested.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Requested;
this.LiteralErrorInsufficientBudget.Text =
System.Uri.EscapeDataString (Resources.Pages.Financial.AttestCosts_OutOfBudget);
this.LiteralErrorInsufficientBudget.Text = JavascriptEscape (Resources.Pages.Financial.AttestCosts_OutOfBudget);
this.LabelDescribeDeny.Text = Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionDeny;
this.LabelDescribeDifferentAmount.Text = Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionAmount;
this.LabelDescribeDifferentAmount.Text = String.Format (Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionAmount, CurrentOrganization.Currency.DisplayCode);
this.LabelDescribeRebudget.Text = Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionRebudget;
this.LabelRadioAmount.Text = Resources.Pages.Financial.AttestCosts_Modal_RadioOptionAmount;
this.LabelRadioDeny.Text = Resources.Pages.Financial.AttestCosts_Modal_RadioOptionDeny;
this.LabelRadioRebudget.Text = Resources.Pages.Financial.AttestCosts_Modal_RadioOptionRebudget;
this.LiteralButtonAmount.Text = Resources.Pages.Financial.AttestCosts_Modal_ButtonAmount;
this.LiteralButtonAmount.Text = Resources.Pages.Financial.AttestCosts_Modal_ButtonAmount; // these may be flagged red by Resharper. That's Resharper being wrong.
this.LiteralButtonDeny.Text = Resources.Pages.Financial.AttestCosts_Modal_ButtonDeny;
this.LiteralButtonRebudget.Text = Resources.Pages.Financial.AttestCosts_Modal_ButtonRebudget;
this.LabelModalDenyHeader.Text = Resources.Pages.Financial.AttestCosts_Modal_Header;
this.LabelWhatProblem.Text = Resources.Pages.Financial.AttestCosts_Modal_WhatIsProblem;
this.LiteralPleaseSelectBudget.Text = JavascriptEscape (Resources.Pages.Financial.AttestCosts_Error_PleaseSelectBudget);
this.LiteralCannotRebudgetSalary.Text =
JavascriptEscape (Resources.Pages.Financial.AttestCosts_Error_CantRebudgetSalary);
}
[WebMethod]
public static void RebudgetItem (string recordId, int newAccountId)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
char recordType = recordId[0];
int itemId = Int32.Parse (recordId.Substring (1));
FinancialAccount newAccount = FinancialAccount.FromIdentity(itemId);
switch (recordType)
{
case 'E': // Expense claim
ExpenseClaim claim = ExpenseClaim.FromIdentity (itemId);
if (claim.Budget.OrganizationId != authData.CurrentOrganization.Identity ||
claim.Budget.OwnerPersonId != authData.CurrentUser.Identity ||
newAccount.OrganizationId != authData.CurrentOrganization.Identity)
{
throw new UnauthorizedAccessException();
}
claim.SetBudget (newAccount, authData.CurrentUser);
break;
case 'A': // Cash advance
CashAdvance advance = CashAdvance.FromIdentity (itemId);
if (advance.Budget.OrganizationId != authData.CurrentOrganization.Identity ||
advance.Budget.OwnerPersonId != authData.CurrentUser.Identity ||
newAccount.OrganizationId != authData.CurrentOrganization.Identity)
{
throw new UnauthorizedAccessException();
}
advance.Budget = newAccount; // no accounting changes
}
}
[WebMethod]
public static string GetOverdraftMessage (int accountId)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
FinancialAccount account = FinancialAccount.FromIdentity (accountId);
if (account.OrganizationId != authData.CurrentOrganization.Identity)
{
throw new UnauthorizedAccessException();
}
if (authData.CurrentUser.Identity != account.OwnerPersonId)
{
throw new UnauthorizedAccessException();
}
int year = DateTime.UtcNow.Year;
Int64 budgetRemainingCents = GetBudgetRemaining (account, year);
return String.Format (Resources.Pages.Financial.AttestCosts_OutOfBudgetPrecise,
authData.CurrentOrganization.Currency.DisplayCode, budgetRemainingCents/100.0, year);
}
[WebMethod]
@@ -213,8 +273,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial
return result;
}
private static Int64 GetBudgetRemaining (FinancialAccount account, int year)
private static Int64 GetBudgetRemaining (FinancialAccount account, int year = -1)
{
if (year == -1)
{
year = DateTime.UtcNow.Year;
}
Int64 deltaCentsYear = account.GetDeltaCents(new DateTime(year, 1, 1),
new DateTime(year + 1, 1, 1));
Int64 budgetYear = account.GetBudgetCents(year);
+34
View File
@@ -36,6 +36,40 @@
}
publicSymbols.formatCurrency = formatCurrency;
function formatCurrency(number, callbackSuccess, callbackError) {
if (callbackSuccess === undefined) {
alert("FormatCurrency() called without callbackSuccess parameter. This is not allowed.");
return ("[Undefined]");
}
var jsonData = {};
jsonData.input = number;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '/Automation/Formatting.aspx/FormatCurrency',
dataType: 'json',
data: $.toJSON(jsonData),
success: function (data) {
callbackSuccess(data.d);
},
error: function () {
if (callbackError !== undefined) {
callbackError();
} else {
alertify.error("AJAX error calling SwarmopsJS.FormatCurrency. Are the server and network still available?"); // TODO: Loc - how?
callbackSuccess("[Undefined]");
}
}
});
}
publicSymbols.ajaxCall = ajaxCall;
function ajaxCall(url, params, successFunction, errorFunction) {
$.ajax({