Loc on attests, some minor renames
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<ExpenseClaims,ExpenseClaim,BasicExpenseClaim>
|
||||
{
|
||||
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
|
||||
|
||||
@@ -117,12 +117,79 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="AttestCosts_AdvanceAttested" xml:space="preserve">
|
||||
<value>Cash Advance #{0} for {1} has been attested for {3:N2}.</value>
|
||||
<comment>Status message.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_AdvanceDeattested" xml:space="preserve">
|
||||
<value>Cash Advance #{0} 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_ExpenseAttested" xml:space="preserve">
|
||||
<value>Expense Claim #{0} from {1} for {2} {3:N2} has been attested.</value>
|
||||
<comment>{2} is the currency.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_ExpenseDeattested" xml:space="preserve">
|
||||
<value>Expense Claim #{0} from {1} was DE-attested. It will not be paid out unless attested again.</value>
|
||||
<comment>When somebody undoes a previous attestation.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_GridHeader_Action" xml:space="preserve">
|
||||
<value>Action</value>
|
||||
<comment>Yes / No buttons. Keep short!</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_GridHeader_Beneficiary" xml:space="preserve">
|
||||
<value>Beneficiary</value>
|
||||
<comment>The receiver of money.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_GridHeader_Budget" xml:space="preserve">
|
||||
<value>Budget</value>
|
||||
</data>
|
||||
<data name="AttestCosts_GridHeader_Description" xml:space="preserve">
|
||||
<value>Description</value>
|
||||
</data>
|
||||
<data name="AttestCosts_GridHeader_Docs" xml:space="preserve">
|
||||
<value>Docs</value>
|
||||
<comment>Button to see underlying documentation. Keep short!</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_GridHeader_Item" xml:space="preserve">
|
||||
<value>Item</value>
|
||||
<comment>Could also be translated to "Type". Will list"cash advance", "invoice", etc.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_GridHeader_Requested" xml:space="preserve">
|
||||
<value>Requested</value>
|
||||
<comment>Header for the requested amount.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_Header_CostsAwaitingAttestation" xml:space="preserve">
|
||||
<value>Costs waiting for your attestation</value>
|
||||
</data>
|
||||
<data name="AttestCosts_Info" xml:space="preserve">
|
||||
<value>This is where you attest costs that other people are requesting from your budgets. Nothing is paid before you have attested it.</value>
|
||||
</data>
|
||||
<data name="AttestCosts_InvoiceAttested" xml:space="preserve">
|
||||
<value>Invoice #{0} from {1} for {2} {3:N2} has been attested.</value>
|
||||
<comment>{2} is the currency.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_InvoiceDeattested" xml:space="preserve">
|
||||
<value>Invoice #{0} from {1} was UN-attested. It will not be paid unless attested again.</value>
|
||||
<comment>When somebody undoes a previous attestation.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_PageTitle" xml:space="preserve">
|
||||
<value>Attest Costs</value>
|
||||
</data>
|
||||
<data name="AttestCosts_ParleyAttested" xml:space="preserve">
|
||||
<value>Conference #{0}, arranged by {1}, has been attested for {3:N2}.</value>
|
||||
</data>
|
||||
<data name="AttestCosts_ParleyDeattested" xml:space="preserve">
|
||||
<value>Conference #{0} by {1} was UN-attested. It will not be greenlighted unless attested again.</value>
|
||||
<comment>When somebody undoes a previous attestation.</comment>
|
||||
</data>
|
||||
<data name="AttestCosts_SalaryAttested" xml:space="preserve">
|
||||
<value>Salary #{0} for {1} was attested for {3:N2}.</value>
|
||||
</data>
|
||||
<data name="AttestCosts_SalaryDeattested" xml:space="preserve">
|
||||
<value>Salary #{0} for {1} was DE-attested. It will not be paid out unless attested again.</value>
|
||||
<comment>When somebody undoes a previous attestation.</comment>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_Amount" xml:space="preserve">
|
||||
<value>Advance amount (in {0})</value>
|
||||
<comment>{0} is the currency.</comment>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user