From d2fbad1d0e57c341e770cc3a3e365893ae3b27b8 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 10 Feb 2013 12:26:49 +0000 Subject: [PATCH] Loc on attests, some minor renames --- Logic/DataObjects/ExpensesDataObject.cs | 4 +- Logic/Financial/ExpenseClaims.cs | 21 +++- .../App_GlobalResources/Pages.Financial.resx | 67 +++++++++++ Site5/Pages/v5/Financial/AttestCosts.aspx.cs | 109 +++++++++++------- .../v5/Financial/Json-AttestableCosts.aspx.cs | 5 + 5 files changed, 159 insertions(+), 47 deletions(-) diff --git a/Logic/DataObjects/ExpensesDataObject.cs b/Logic/DataObjects/ExpensesDataObject.cs index 82cdb9e5..9acbdca4 100644 --- a/Logic/DataObjects/ExpensesDataObject.cs +++ b/Logic/DataObjects/ExpensesDataObject.cs @@ -23,7 +23,7 @@ namespace Swarmops.Logic.DataObjects #endif public static ExpenseClaim[] SelectOpenByClaimer (int personId) { - return ExpenseClaims.FromClaimingPerson (Person.FromIdentity(personId)).AllOpen.ToArray(); + return ExpenseClaims.FromClaimingPerson (Person.FromIdentity(personId)).WhereOpen.ToArray(); } #if !__MonoCS__ @@ -55,7 +55,7 @@ namespace Swarmops.Logic.DataObjects #endif public static ExpenseClaim[] SelectUnapprovedByOrganization (int organizationId) { - return ExpenseClaims.FromOrganization (Organization.FromIdentity(organizationId)).AllUnapproved.ToArray(); + return ExpenseClaims.FromOrganization (Organization.FromIdentity(organizationId)).WhereUnapproved.ToArray(); } diff --git a/Logic/Financial/ExpenseClaims.cs b/Logic/Financial/ExpenseClaims.cs index 758925b1..a9ce9746 100644 --- a/Logic/Financial/ExpenseClaims.cs +++ b/Logic/Financial/ExpenseClaims.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Swarmops.Basic.Types; using Swarmops.Database; using Swarmops.Logic.Swarm; @@ -10,7 +11,7 @@ namespace Swarmops.Logic.Financial { public class ExpenseClaims : PluralBase { - public ExpenseClaims AllOpen + public ExpenseClaims WhereOpen { get { @@ -27,7 +28,7 @@ namespace Swarmops.Logic.Financial } } - public ExpenseClaims AllApproved + public ExpenseClaims WhereApproved { get { @@ -44,7 +45,7 @@ namespace Swarmops.Logic.Financial } } - public ExpenseClaims AllUnapproved + public ExpenseClaims WhereUnapproved { get { @@ -61,6 +62,20 @@ namespace Swarmops.Logic.Financial } } + + public ExpenseClaims WhereUnattested + { + get + { + ExpenseClaims result = new ExpenseClaims(); + result.AddRange(this.Where(expenseClaim => expenseClaim.Attested == false)); + + return result; + } + } + + + public static ExpenseClaims FromClaimingPersonAndOrganization (Person person, Organization organization) { return diff --git a/Site5/App_GlobalResources/Pages.Financial.resx b/Site5/App_GlobalResources/Pages.Financial.resx index cae6c3f9..a6d08fda 100644 --- a/Site5/App_GlobalResources/Pages.Financial.resx +++ b/Site5/App_GlobalResources/Pages.Financial.resx @@ -117,12 +117,79 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Cash Advance #{0} for {1} has been attested for {3:N2}. + Status message. + + + Cash Advance #{0} for {1} was UN-attested. It will not be paid out unless attested again. + When somebody undoes a previous attestation. + + + Expense Claim #{0} from {1} for {2} {3:N2} has been attested. + {2} is the currency. + + + Expense Claim #{0} from {1} was DE-attested. It will not be paid out unless attested again. + When somebody undoes a previous attestation. + + + Action + Yes / No buttons. Keep short! + + + Beneficiary + The receiver of money. + + + Budget + + + Description + + + Docs + Button to see underlying documentation. Keep short! + + + Item + Could also be translated to "Type". Will list"cash advance", "invoice", etc. + + + Requested + Header for the requested amount. + + + Costs waiting for your attestation + This is where you attest costs that other people are requesting from your budgets. Nothing is paid before you have attested it. + + Invoice #{0} from {1} for {2} {3:N2} has been attested. + {2} is the currency. + + + Invoice #{0} from {1} was UN-attested. It will not be paid unless attested again. + When somebody undoes a previous attestation. + Attest Costs + + Conference #{0}, arranged by {1}, has been attested for {3:N2}. + + + Conference #{0} by {1} was UN-attested. It will not be greenlighted unless attested again. + When somebody undoes a previous attestation. + + + Salary #{0} for {1} was attested for {3:N2}. + + + Salary #{0} for {1} was DE-attested. It will not be paid out unless attested again. + When somebody undoes a previous attestation. + Advance amount (in {0}) {0} is the currency. diff --git a/Site5/Pages/v5/Financial/AttestCosts.aspx.cs b/Site5/Pages/v5/Financial/AttestCosts.aspx.cs index eddca932..2b065627 100644 --- a/Site5/Pages/v5/Financial/AttestCosts.aspx.cs +++ b/Site5/Pages/v5/Financial/AttestCosts.aspx.cs @@ -36,13 +36,48 @@ namespace Swarmops.Frontend.Pages.v5.Financial { this.PageTitle = Resources.Pages.Financial.AttestCosts_PageTitle; this.InfoBoxLiteral = Resources.Pages.Financial.AttestCosts_Info; + this.LabelAttestCostsHeader.Text = Resources.Pages.Financial.AttestCosts_Header_CostsAwaitingAttestation; + this.LabelGridHeaderAction.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Action; + this.LabelGridHeaderBeneficiary.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Beneficiary; + this.LabelGridHeaderBudget.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Budget; + this.LabelGridHeaderDescription.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Description; + this.LabelGridHeaderDocs.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Docs; + this.LabelGridHeaderItem.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Item; + this.LabelGridHeaderRequested.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Requested; } + private enum AttestationMode + { + Unknown = 0, + Attestation, + Deattestation + }; + [WebMethod] public static string Attest (string identifier) { identifier = HttpUtility.UrlDecode(identifier); + string result = HandleAttestationDeattestation(identifier, AttestationMode.Attestation); + + return HttpUtility.UrlEncode(result).Replace("+", "%20"); + } + + [WebMethod] + public static string Deattest(string identifier) + { + identifier = HttpUtility.UrlDecode(identifier); + + string result = HandleAttestationDeattestation(identifier, AttestationMode.Deattestation); + + return HttpUtility.UrlEncode(result).Replace("+", "%20"); + } + + + private static string HandleAttestationDeattestation (string identifier, AttestationMode mode) + { + // Find various credentials + string identity = HttpContext.Current.User.Identity.Name; string[] identityTokens = identity.Split(','); @@ -55,11 +90,18 @@ namespace Swarmops.Frontend.Pages.v5.Financial Person currentUser = Person.FromIdentity(currentUserId); Organization currentOrganization = Organization.FromIdentity(currentOrganizationId); + IAttestable attestableItem = null; + string attestedTemplate = string.Empty; + string deattestedTemplate = string.Empty; + char costType = identifier[0]; int itemId = Int32.Parse(identifier.Substring(1)); + Int64 amountCents; string beneficiary = string.Empty; string result = string.Empty; + // Find the item we are attesting or deattesting + switch(costType) { case 'A': // Case advance @@ -73,55 +115,38 @@ namespace Swarmops.Frontend.Pages.v5.Financial throw new SecurityAccessDeniedException("Called without attestation privileges"); } - result = "XYZ Cash Advance"; - advance.Attest(currentUser); + attestableItem = advance; + attestedTemplate = Resources.Pages.Financial.AttestCosts_AdvanceAttested; + deattestedTemplate = Resources.Pages.Financial.AttestCosts_AdvanceDeattested; + beneficiary = advance.Person.Name; + amountCents = advance.AmountCents; + break; + default: + throw new InvalidOperationException("Unknown Cost Type in HandleAttestationDeattestation: \"" + identifier + "\""); } - return HttpUtility.UrlEncode(result); - } + // Finally, attest or deattest - [WebMethod] - public static string Deattest(string identifier) - { - identifier = HttpUtility.UrlDecode(identifier); - - string identity = HttpContext.Current.User.Identity.Name; - string[] identityTokens = identity.Split(','); - - string userIdentityString = identityTokens[0]; - string organizationIdentityString = identityTokens[1]; - - int currentUserId = Convert.ToInt32(userIdentityString); - int currentOrganizationId = Convert.ToInt32(organizationIdentityString); - - Person currentUser = Person.FromIdentity(currentUserId); - Organization currentOrganization = Organization.FromIdentity(currentOrganizationId); - - char costType = identifier[0]; - int itemId = Int32.Parse(identifier.Substring(1)); - string beneficiary = string.Empty; - string result = string.Empty; - - switch (costType) + if (mode == AttestationMode.Attestation) { - case 'A': // Case advance - CashAdvance advance = CashAdvance.FromIdentity(itemId); - if (advance.OrganizationId != currentOrganizationId) - { - throw new InvalidOperationException("Called to attest out-of-org line item"); - } - if (advance.FinancialAccount.OwnerPersonId != currentUserId && advance.FinancialAccount.OwnerPersonId != Person.NobodyId) - { - throw new SecurityAccessDeniedException("Called without attestation privileges"); - } - - result = "XYZ Cash Advance for " + beneficiary; - advance.Deattest(currentUser); - break; + attestableItem.Attest(currentUser); + result = string.Format(attestedTemplate, itemId, beneficiary, currentOrganization.Currency.Code, + amountCents/100.0); + } + else if (mode == AttestationMode.Deattestation) + { + attestableItem.Deattest(currentUser); + result = string.Format(deattestedTemplate, itemId, beneficiary, currentOrganization.Currency.Code, + amountCents / 100.0); + } + else + { + throw new InvalidOperationException("Unknown Attestation Mode: " + mode.ToString()); } - return HttpUtility.UrlEncode(result).Replace("+", "%20"); + return result; } + } } \ No newline at end of file diff --git a/Site5/Pages/v5/Financial/Json-AttestableCosts.aspx.cs b/Site5/Pages/v5/Financial/Json-AttestableCosts.aspx.cs index af8cd4f9..71760f65 100644 --- a/Site5/Pages/v5/Financial/Json-AttestableCosts.aspx.cs +++ b/Site5/Pages/v5/Financial/Json-AttestableCosts.aspx.cs @@ -146,4 +146,9 @@ public partial class Pages_v5_Finance_Json_AttestableCosts : System.Web.UI.Page } + private void PopulateExpenses() + { + ExpenseClaims expenses = ExpenseClaims.ForOrganization(_currentOrganization).WhereUnattested; + } + } \ No newline at end of file