Denying attestation should work

This commit is contained in:
Rick Falkvinge
2015-04-05 20:22:42 +02:00
parent e3d6f40fb2
commit 74d2f90d3d
12 changed files with 178 additions and 50 deletions
+8 -4
View File
@@ -159,6 +159,9 @@ namespace Swarmops.Logic.Communications
}
public static OutboundComm CreateNotificationAttestationNeeded (FinancialAccount budget, Person concernedPerson,
string supplier, double amountRequested, string purpose, NotificationResource notification)
{
@@ -166,7 +169,7 @@ namespace Swarmops.Logic.Communications
payload.Strings[NotificationString.CurrencyCode] = budget.Organization.Currency.DisplayCode;
payload.Strings[NotificationString.OrganizationName] = budget.Organization.Name;
payload.Strings[NotificationString.BudgetAmountFloat] =
amountRequested.ToString (CultureInfo.InvariantCulture);
amountRequested.ToString ("N2");
payload.Strings[NotificationString.RequestPurpose] = purpose;
payload.Strings[NotificationString.Description] = purpose;
payload.Strings[NotificationString.Supplier] = supplier;
@@ -201,7 +204,7 @@ namespace Swarmops.Logic.Communications
payload.Strings[NotificationString.CurrencyCode] = organization.Currency.DisplayCode;
payload.Strings[NotificationString.OrganizationName] = organization.Name;
payload.Strings[NotificationString.BudgetAmountFloat] =
amountRequested.ToString (CultureInfo.InvariantCulture);
amountRequested.ToString("N2");
OutboundComm comm = OutboundComm.Create (null, null, organization, CommResolverClass.Unknown, null,
CommTransmitterClass.CommsTransmitterMail,
@@ -222,16 +225,17 @@ namespace Swarmops.Logic.Communications
public static OutboundComm CreateNotificationOfFinancialValidation (FinancialAccount budget,
Person concernedPerson, double amountRequested, string purpose, NotificationResource notification)
Person concernedPerson, double amountRequested, string purpose, NotificationResource notification, string reasonGiven="")
{
NotificationPayload payload = new NotificationPayload (notification.ToString());
payload.Strings[NotificationString.CurrencyCode] = budget.Organization.Currency.DisplayCode;
payload.Strings[NotificationString.OrganizationName] = budget.Organization.Name;
payload.Strings[NotificationString.BudgetAmountFloat] =
amountRequested.ToString (CultureInfo.InvariantCulture);
amountRequested.ToString("N2");
payload.Strings[NotificationString.RequestPurpose] = purpose;
payload.Strings[NotificationString.BudgetName] = budget.Name;
payload.Strings[NotificationString.ConcernedPersonName] = concernedPerson.Canonical;
payload.Strings[NotificationString.EmbeddedPreformattedText] = reasonGiven;
OutboundComm comm = OutboundComm.Create (null, null, budget.Organization, CommResolverClass.Unknown, null,
CommTransmitterClass.CommsTransmitterMail,
+15 -2
View File
@@ -62,7 +62,7 @@ namespace Swarmops.Logic.Financial
public void Attest (Person attester)
{
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Attestation,
FinancialDependencyType.CashAdvance, Identity, DateTime.Now, attester.Identity, AmountCents/100.0);
FinancialDependencyType.CashAdvance, Identity, DateTime.UtcNow, attester.Identity, AmountCents/100.0);
SwarmDb.GetDatabaseForWriting().SetCashAdvanceAttested (Identity, true, attester.Identity);
OutboundComm.CreateNotificationOfFinancialValidation (Budget, Person, AmountCents/100.0, Description,
@@ -72,13 +72,25 @@ namespace Swarmops.Logic.Financial
public void Deattest (Person deattester)
{
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Deattestation,
FinancialDependencyType.CashAdvance, Identity, DateTime.Now, deattester.Identity, AmountCents/100.0);
FinancialDependencyType.CashAdvance, Identity, DateTime.UtcNow, deattester.Identity, AmountCents/100.0);
SwarmDb.GetDatabaseForWriting().SetCashAdvanceAttested (Identity, false, Person.NobodyId);
OutboundComm.CreateNotificationOfFinancialValidation (Budget, Person, AmountCents/100.0, Description,
NotificationResource.CashAdvance_Deattested);
}
public void DenyAttestation (Person denyingPerson, string reason)
{
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation(FinancialValidationType.Kill,
FinancialDependencyType.CashAdvance, Identity, DateTime.UtcNow, denyingPerson.Identity, AmountCents / 100.0);
OutboundComm.CreateNotificationOfFinancialValidation(Budget, Person, AmountCents / 100.0, Description,
NotificationResource.CashAdvance_Denied, reason);
Attested = false;
Open = false;
}
#endregion
public Person Person
@@ -198,6 +210,7 @@ namespace Swarmops.Logic.Financial
public void SetAmountCents(Int64 newAmount, Person settingPerson)
{
SwarmDb.GetDatabaseForWriting().SetCashAdvanceAmountCents (this.Identity, newAmount);
base.AmountCents = newAmount;
}
}
}
+27 -11
View File
@@ -292,7 +292,7 @@ namespace Swarmops.Logic.Financial
SwarmDb.GetDatabaseForWriting().SetExpenseClaimValidated (Identity, true);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Validation,
FinancialDependencyType.ExpenseClaim, Identity,
DateTime.Now, validator.Identity, (double) Amount);
DateTime.UtcNow, validator.Identity, (double) Amount);
base.Validated = true;
OutboundComm.CreateNotificationOfFinancialValidation (Budget, Claimer, AmountCents/100.0, Description,
@@ -304,7 +304,7 @@ namespace Swarmops.Logic.Financial
SwarmDb.GetDatabaseForWriting().SetExpenseClaimValidated (Identity, false);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Devalidation,
FinancialDependencyType.ExpenseClaim, Identity,
DateTime.Now, devalidator.Identity, (double) Amount);
DateTime.UtcNow, devalidator.Identity, (double) Amount);
base.Validated = false;
OutboundComm.CreateNotificationOfFinancialValidation (Budget, Claimer, AmountCents/100.0, Description,
@@ -317,11 +317,10 @@ namespace Swarmops.Logic.Financial
public void Attest (Person attester)
{
SwarmDb.GetDatabaseForWriting().SetExpenseClaimAttested (Identity, true);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Attestation,
Attested = true;
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation(FinancialValidationType.Attestation,
FinancialDependencyType.ExpenseClaim, Identity,
DateTime.Now, attester.Identity, (double) Amount);
base.Attested = true;
DateTime.UtcNow, attester.Identity, (double) Amount);
OutboundComm.CreateNotificationOfFinancialValidation (Budget, Claimer, AmountCents/100.0, Description,
NotificationResource.ExpenseClaim_Attested);
@@ -329,16 +328,27 @@ namespace Swarmops.Logic.Financial
public void Deattest (Person deattester)
{
SwarmDb.GetDatabaseForWriting().SetExpenseClaimAttested (Identity, false);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Deattestation,
Attested = false;
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation(FinancialValidationType.Deattestation,
FinancialDependencyType.ExpenseClaim, Identity,
DateTime.Now, deattester.Identity, (double) Amount);
base.Attested = false;
DateTime.UtcNow, deattester.Identity, (double) Amount);
OutboundComm.CreateNotificationOfFinancialValidation (Budget, Claimer, AmountCents/100.0, Description,
NotificationResource.ExpenseClaim_Deattested);
}
public void DenyAttestation (Person denyingPerson, string reason)
{
Attested = false;
Open = false;
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation(FinancialValidationType.Kill,
FinancialDependencyType.ExpenseClaim, Identity,
DateTime.UtcNow, denyingPerson.Identity, (double)Amount);
OutboundComm.CreateNotificationOfFinancialValidation(Budget, Claimer, AmountCents / 100.0, Description,
NotificationResource.ExpenseClaim_Denied, reason);
}
#endregion
public FinancialAccount Budget
@@ -378,6 +388,12 @@ namespace Swarmops.Logic.Financial
base.AmountCents = amountCents;
SwarmDb.GetDatabaseForWriting().SetExpenseClaimAmount (Identity, amountCents);
UpdateFinancialTransaction (settingPerson);
if (Validated)
{
// Reset validation, since amount was changed
Devalidate (settingPerson);
}
}
@@ -402,7 +418,7 @@ namespace Swarmops.Logic.Financial
// Mark transaction as invalid in description
FinancialTransaction.Description = "Expense Claim #" + Identity + " (killed/zeroed)";
FinancialTransaction.Description = "[strikeout]Expense Claim #" + Identity;
}
+2
View File
@@ -7,5 +7,7 @@ namespace Swarmops.Logic.Financial
FinancialAccount Budget { get; }
void Attest (Person attester);
void Deattest (Person deattester);
void DenyAttestation(Person denyingPerson, string reason);
}
}
+11 -2
View File
@@ -115,7 +115,7 @@ namespace Swarmops.Logic.Financial
SwarmDb.GetDatabaseForWriting().SetInboundInvoiceAttested (Identity, true);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Attestation,
FinancialDependencyType.InboundInvoice, Identity,
DateTime.Now, attester.Identity, (double) Amount);
DateTime.UtcNow, attester.Identity, (double) Amount);
base.Attested = true;
}
@@ -124,10 +124,19 @@ namespace Swarmops.Logic.Financial
SwarmDb.GetDatabaseForWriting().SetInboundInvoiceAttested (Identity, false);
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation (FinancialValidationType.Deattestation,
FinancialDependencyType.InboundInvoice, Identity,
DateTime.Now, deattester.Identity, (double) Amount);
DateTime.UtcNow, deattester.Identity, (double) Amount);
base.Attested = false;
}
public void DenyAttestation (Person denyingPerson, string reason)
{
SwarmDb.GetDatabaseForWriting().CreateFinancialValidation(FinancialValidationType.Kill,
FinancialDependencyType.InboundInvoice, Identity,
DateTime.UtcNow, denyingPerson.Identity, (double)Amount);
Attested = false;
Open = false;
}
#endregion
public FinancialAccount Budget
+8
View File
@@ -138,6 +138,14 @@ namespace Swarmops.Logic.Financial
SwarmDb.GetDatabaseForWriting().SetSalaryAttested (Identity, false);
}
public void DenyAttestation (Person denyingPerson, string reason)
{
// Denying a salary payout is not to be taken lightly. This needs to be a larger feature. Until
// then, it's not implemented at all.
throw new NotImplementedException();
}
#endregion
public FinancialAccount Budget // needed for IAttestable
@@ -98,6 +98,27 @@ namespace Swarmops.Logic.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat] concerning [RequestPurpose] has been denied. The text below was given as reason for denying it:
///
///[EmbeddedPreformattedText]
///.
/// </summary>
internal static string CashAdvance_Denied_Body {
get {
return ResourceManager.GetString("CashAdvance_Denied_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to [[OrganizationName]] Cash Advance DENIED: [CurrencyCode] [BudgetAmountFloat].
/// </summary>
internal static string CashAdvance_Denied_Subject {
get {
return ResourceManager.GetString("CashAdvance_Denied_Subject", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Your request for a cash advance with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat], concerning [RequestPurpose], has been marked as paid out by the organization&apos;s accountants.
///
@@ -197,7 +218,10 @@ namespace Swarmops.Logic.Resources {
}
/// <summary>
/// Looks up a localized string similar to Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat] concerning [RequestPurpose] has been denied. Expect more communications to follow on what you need to do to file a proper expense claim..
/// Looks up a localized string similar to Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat] concerning [RequestPurpose] has been denied. The text below was given as reason for denying it:
///
///[EmbeddedPreformattedText]
///.
/// </summary>
internal static string ExpenseClaim_Denied_Body {
get {
@@ -131,6 +131,15 @@ Expect more communication from the budget owner to follow on the matter.</value>
<data name="CashAdvance_Deattested_Subject" xml:space="preserve">
<value>[OrganizationName] Cash Advance DE-attested: [CurrencyCode] [BudgetAmountFloat]</value>
</data>
<data name="CashAdvance_Denied_Body" xml:space="preserve">
<value>Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat] concerning [RequestPurpose] has been denied. The text below was given as reason for denying it:
[EmbeddedPreformattedText]
</value>
</data>
<data name="CashAdvance_Denied_Subject" xml:space="preserve">
<value>[[OrganizationName]] Cash Advance DENIED: [CurrencyCode] [BudgetAmountFloat]</value>
</data>
<data name="CashAdvance_PaidOut_Body" xml:space="preserve">
<value>Your request for a cash advance with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat], concerning [RequestPurpose], has been marked as paid out by the organization's accountants.
@@ -176,7 +185,10 @@ Expect more communication from the budget owner to follow on the matter.</value>
<value>[[OrganizationName]] Expense Claim DE-attested: [CurrencyCode] [BudgetAmountFloat]</value>
</data>
<data name="ExpenseClaim_Denied_Body" xml:space="preserve">
<value>Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat] concerning [RequestPurpose] has been denied. Expect more communications to follow on what you need to do to file a proper expense claim.</value>
<value>Your expense claim with [OrganizationName] for [CurrencyCode] [BudgetAmountFloat] concerning [RequestPurpose] has been denied. The text below was given as reason for denying it:
[EmbeddedPreformattedText]
</value>
<comment>This is sent to the claimer.</comment>
</data>
<data name="ExpenseClaim_Denied_Subject" xml:space="preserve">
+7
View File
@@ -193,6 +193,13 @@ namespace Swarmops.Logic.Swarm
// this.BudgetId = this.Budget.ParentIdentity;
}
public void DenyAttestation (Person denyingPerson, string denyReason)
{
// Re-implement if and when parleys are resurrected
throw new NotImplementedException();
}
#endregion
public FinancialAccount Budget
+4
View File
@@ -667,4 +667,8 @@
<value>Swarmops does not understand your currency amount. (One thousand money and zero cents are written like "{0:N2}".) Try again?</value>
<comment>The {0:N2} is just fed with the number 1000.00 in culture-specific format.</comment>
</data>
<data name="Global_NoReasonGiven" xml:space="preserve">
<value>No reason was specified.</value>
<comment>As inter-activist communication when denying resources, et cetera</comment>
</data>
</root>
+31 -1
View File
@@ -294,6 +294,35 @@
budgetRemainingLookup.attestabilityInitialized = true;
}
function onDenyRecord() {
var reason = $('#<%=this.TextDenyReason.ClientID%>').val();
// hide yes/no icons, show denied icon, but set it to "loading" icon until completed
$('#IconApproval' + recordId).hide();
$('#IconDenial' + recordId).hide();
$('#IconDenied' + recordId).attr('src', '/Images/Abstract/ajaxloader-48x36px.gif');
<%= this.DialogDeny.ClientID %>_close();
SwarmopsJS.ajaxCall(
"/Pages/v5/Financial/AttestCosts.aspx/DenyItem",
{ recordId: recordId, reason: reason },
$.proxy(function(result) {
if (result.Success) {
$(this).attr("src", "/Images/Icons/iconshock-red-cross-circled-128x96px.png");
$(this).fadeIn(); // was visible already, but this will create an effect as it changes image
} else {
// Failure can happen for many reasons, all bad, so we're just reloading the
// entire grid to cover our bases
alertify.error(result.DisplayMessage);
recheckBudgets();
$('#TableAttestableCosts').datagrid('reload');
}
}, $('#IconDenied' + recordId)));
}
function onRebudgetRecord() {
var newAccountId = <%=this.DropBudgetsRebudget.ClientID%>_val();
if (newAccountId == 0) {
@@ -333,7 +362,8 @@
if (!result.Success) {
alertify.error(result.DisplayMessage);
} else {
// Succeeded, attested for new amount. Since amount was changed, reload grid
// Succeeded, attested for new amount. Since amount was changed, reload grid and budgets
recheckBudgets();
$('#TableAttestableCosts').datagrid('reload');
<%= this.DialogDeny.ClientID %>_close();
}
+27 -28
View File
@@ -130,7 +130,24 @@ namespace Swarmops.Frontend.Pages.v5.Financial
throw new NotImplementedException("Unknown record type");
}
}
[WebMethod]
public static void DenyItem (string recordId, string reason)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
IPayable payable = PayableFromRecordId (recordId);
FinancialAccount budget = payable.Budget;
if (budget.OrganizationId != authData.CurrentOrganization.Identity ||
budget.OwnerPersonId != authData.CurrentUser.Identity)
{
throw new UnauthorizedAccessException();
}
payable.DenyAttestation (authData.CurrentUser, reason);
}
[WebMethod]
public static void RebudgetItem (string recordId, int newAccountId)
@@ -233,28 +250,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
};
}
[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]
public static BudgetRemainder[] GetRemainingBudgets()
@@ -371,7 +367,10 @@ namespace Swarmops.Frontend.Pages.v5.Financial
Int64 deltaCentsYear = account.GetDeltaCents(new DateTime(year, 1, 1),
new DateTime(year + 1, 1, 1));
Int64 budgetYear = account.GetBudgetCents(year);
return -(budgetYear - deltaCentsYear);
Dictionary<int, Int64> adjustments = GetAccountingAdjustments (account.Organization);
return -(budgetYear - deltaCentsYear) + (adjustments.ContainsKey(account.Identity)? adjustments[account.Identity]: 0);
}
public class BudgetRemainder
@@ -403,15 +402,15 @@ namespace Swarmops.Frontend.Pages.v5.Financial
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
IAttestable attestableItem = null;
string attestedTemplate = string.Empty;
string deattestedTemplate = string.Empty;
IAttestable attestableItem;
string attestedTemplate;
string deattestedTemplate;
char costType = identifier[0];
int itemId = Int32.Parse (identifier.Substring (1));
Int64 amountCents;
string beneficiary = string.Empty;
string result = string.Empty;
string beneficiary;
string result;
// Find the item we are attesting or deattesting