From 3da0004e92ab7b3b7b641cca4808673daae4f179 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 4 Feb 2013 11:29:43 +0000 Subject: [PATCH] Committing first work on Attest Costs --- Logic/Financial/CashAdvance.cs | 6 + Logic/Financial/CashAdvances.cs | 37 +++++ Logic/Financial/Salaries.cs | 2 +- Logic/Logic.csproj | 1 + Logic/Support/SingularFactory.cs | 8 +- Site5/App_GlobalResources/Pages.Finance.resx | 6 + .../iconshock-stamped-paper-16px.png | Bin 0 -> 880 bytes .../iconshock-stamped-paper-40px.png | Bin 0 -> 3274 bytes Site5/Master-v5.master | 2 +- Site5/Pages/v5/Finance/AttestCosts.aspx | 29 ++++ Site5/Pages/v5/Finance/AttestCosts.aspx.cs | 33 ++++ .../v5/Finance/Json-AttestableCosts.aspx | 1 + .../v5/Finance/Json-AttestableCosts.aspx.cs | 143 ++++++++++++++++++ Site5/Pages/v5/Ledgers/BalanceSheet.aspx | 2 +- 14 files changed, 265 insertions(+), 5 deletions(-) create mode 100644 Logic/Financial/CashAdvances.cs create mode 100644 Site5/Images/PageIcons/iconshock-stamped-paper-16px.png create mode 100644 Site5/Images/PageIcons/iconshock-stamped-paper-40px.png create mode 100644 Site5/Pages/v5/Finance/AttestCosts.aspx create mode 100644 Site5/Pages/v5/Finance/AttestCosts.aspx.cs create mode 100644 Site5/Pages/v5/Finance/Json-AttestableCosts.aspx create mode 100644 Site5/Pages/v5/Finance/Json-AttestableCosts.aspx.cs diff --git a/Logic/Financial/CashAdvance.cs b/Logic/Financial/CashAdvance.cs index 6f79e7db..3d8ad673 100644 --- a/Logic/Financial/CashAdvance.cs +++ b/Logic/Financial/CashAdvance.cs @@ -61,5 +61,11 @@ namespace Swarmops.Logic.Financial } #endregion + + + public FinancialAccount FinancialAccount + { + get { return FinancialAccount.FromIdentity(this.FinancialAccountId); } + } } } diff --git a/Logic/Financial/CashAdvances.cs b/Logic/Financial/CashAdvances.cs new file mode 100644 index 00000000..79e7e73e --- /dev/null +++ b/Logic/Financial/CashAdvances.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Swarmops.Basic.Types.Financial; +using Swarmops.Database; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; + +namespace Swarmops.Logic.Financial +{ + public class CashAdvances: PluralBase + { + static public CashAdvances ForOrganization(Organization organization) + { + return ForOrganization(organization, false); + } + + static public CashAdvances ForOrganization(Organization organization, bool includeClosed) + { + return FromArray(PirateDb.GetDatabaseForReading().GetCashAdvances(organization, + includeClosed ? DatabaseCondition.None : DatabaseCondition.OpenTrue)); + } + + public CashAdvances WhereUnattested + { + get + { + CashAdvances result = new CashAdvances(); + result.AddRange(this.Where(cashAdvance => cashAdvance.Attested == false)); + + return result; + } + } + + } +} diff --git a/Logic/Financial/Salaries.cs b/Logic/Financial/Salaries.cs index d6d37292..c876f2a3 100644 --- a/Logic/Financial/Salaries.cs +++ b/Logic/Financial/Salaries.cs @@ -17,7 +17,7 @@ namespace Swarmops.Logic.Financial static public Salaries ForOrganization(Organization organization, bool includeClosed) { - return FromArray (PirateDb.GetDatabaseForWriting().GetSalaries(organization, + return FromArray (PirateDb.GetDatabaseForReading().GetSalaries(organization, includeClosed? DatabaseCondition.None : DatabaseCondition.OpenTrue)); } diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 9186b9f1..04820ad7 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -65,6 +65,7 @@ + diff --git a/Logic/Support/SingularFactory.cs b/Logic/Support/SingularFactory.cs index bf37e633..62bbe8c3 100644 --- a/Logic/Support/SingularFactory.cs +++ b/Logic/Support/SingularFactory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using Swarmops.Basic.Types.Financial; using Swarmops.Logic.Communications; using Swarmops.Logic.Financial; using Swarmops.Logic.Swarm; @@ -37,7 +38,10 @@ namespace Swarmops.Logic.Support // ----------- FINANCIAL CLASSES ---------- case "Swarmops.Basic.Types.BasicExpenseClaim": - return ExpenseClaim.FromBasic((BasicExpenseClaim) basic); + return ExpenseClaim.FromBasic((BasicExpenseClaim)basic); + + case "Swarmops.Basic.Types.Financial.BasicCashAdvance": + return CashAdvance.FromBasic((BasicCashAdvance)basic); case "Swarmops.Basic.Types.BasicInboundInvoice": return InboundInvoice.FromBasic((BasicInboundInvoice) basic); @@ -97,7 +101,7 @@ namespace Swarmops.Logic.Support return MotionAmendment.FromBasic((BasicMotionAmendment)basic); - // ------------ PIRATE CLASSES ------------ + // ------------ PARLEY/ACTIVISM CLASSES ------------ case "Swarmops.Basic.Types.BasicExternalActivity": return ExternalActivity.FromBasic((BasicExternalActivity) basic); diff --git a/Site5/App_GlobalResources/Pages.Finance.resx b/Site5/App_GlobalResources/Pages.Finance.resx index 7e00fc2d..cae6c3f9 100644 --- a/Site5/App_GlobalResources/Pages.Finance.resx +++ b/Site5/App_GlobalResources/Pages.Finance.resx @@ -117,6 +117,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + This is where you attest costs that other people are requesting from your budgets. Nothing is paid before you have attested it. + + + Attest Costs + Advance amount (in {0}) {0} is the currency. diff --git a/Site5/Images/PageIcons/iconshock-stamped-paper-16px.png b/Site5/Images/PageIcons/iconshock-stamped-paper-16px.png new file mode 100644 index 0000000000000000000000000000000000000000..5cd87b1cf9728709b98f3ea5fb652a72d4e4203d GIT binary patch literal 880 zcmV-$1CRWPP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*Y+ z2n-V03S=Ar00QtyL_t(I%XN}nY*Td@hoArH=T4!Yu54p;9mQ2vGI40M$`og&F_{K0 zfJCRvcwq=C7kWWrV!SloNkYI2mT@By5{F}ny6IEZ0?D3YyOS~bTkEA{c8ckx{K;|qPiVSr!EPsI*MW=S1i-k z*4_YU3J3?+P?t6;wH5MZgX^~!aJp5r%uO!O++b+%1pt(00M)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%ei@5-i{n|A#lF{Hr=iqCKmwTlm<5AI@Yb=>V z^!RwM<2ZEp_0ZkhXIk2F!i#xCqb{!NEV|@4ylMnZ>q(1LwiPE1Bd;9Ago?^+C4Ber z;rj^c?>zC7Z3cK3kd|$`w(Ufvlu>C}?w8kZY-{W2PVIjFxmlq6(Q7k ztrm+Hl%}VL8kNdg$Cj%T@kBNfjgUwr$>g%Mv}R2*lOf_oMKYBpkxr9HWk|NPQ1=_` z*|EbI9f*Vb_8ocZmDeuX_sYu?zwJm7umA^efw@lwJh7d-Zk_CJYx4>d6D={%Tiw^) zy)ow6m&tnLe7`gwHL5`}ogvrTN7w2BdRDEXyT2c4+3b1#d6OSLB;FdExc(=PJo4zW z4n)7eGcA8|{q<+JMxz@{wS2xR%@3HM(H>7EThpyM+1lBOz%Wsm-g(#7e_Xfh6We7z z?_9WkLni6iol*t89c{TYvZ>U?mSvd(qho*f%rAenZ@GZ~2Oe9?vmq+{5&!@I07*qo IM6N<$f`*4ZPyhe` literal 0 HcmV?d00001 diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index 7a3ef186..96470870 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -159,7 +159,7 @@ - + diff --git a/Site5/Pages/v5/Finance/AttestCosts.aspx b/Site5/Pages/v5/Finance/AttestCosts.aspx new file mode 100644 index 00000000..786e949b --- /dev/null +++ b/Site5/Pages/v5/Finance/AttestCosts.aspx @@ -0,0 +1,29 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AttestCosts.aspx.cs" Inherits="Pages_v5_Finance_AttestCosts" %> + + + + + + + +

+ + + + + + + + + + + + +
ItemBeneficiaryDescriptionBudgetRequestedAction
+ +
+ + + diff --git a/Site5/Pages/v5/Finance/AttestCosts.aspx.cs b/Site5/Pages/v5/Finance/AttestCosts.aspx.cs new file mode 100644 index 00000000..fe093689 --- /dev/null +++ b/Site5/Pages/v5/Finance/AttestCosts.aspx.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +public partial class Pages_v5_Finance_AttestCosts : PageV5Base +{ + protected void Page_Load(object sender, EventArgs e) + { + if (!this.CurrentOrganization.IsEconomyEnabled) + { + Response.Redirect("/Pages/v5/Finance/EconomyNotEnabled.aspx", true); + return; + } + + this.PageIcon = "iconshock-stamped-paper"; + + if (!Page.IsPostBack) + { + Localize(); + } + } + + + private void Localize() + { + this.PageTitle = Resources.Pages.Finance.AttestCosts_PageTitle; + this.InfoBoxLiteral = Resources.Pages.Finance.AttestCosts_Info; + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Finance/Json-AttestableCosts.aspx b/Site5/Pages/v5/Finance/Json-AttestableCosts.aspx new file mode 100644 index 00000000..094be3b6 --- /dev/null +++ b/Site5/Pages/v5/Finance/Json-AttestableCosts.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-AttestableCosts.aspx.cs" Inherits="Pages_v5_Finance_Json_AttestableCosts" %> diff --git a/Site5/Pages/v5/Finance/Json-AttestableCosts.aspx.cs b/Site5/Pages/v5/Finance/Json-AttestableCosts.aspx.cs new file mode 100644 index 00000000..cba90400 --- /dev/null +++ b/Site5/Pages/v5/Finance/Json-AttestableCosts.aspx.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using Swarmops.Basic.Interfaces; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Security; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Swarm; + +public partial class Pages_v5_Finance_Json_AttestableCosts : System.Web.UI.Page +{ + protected void Page_Load(object sender, EventArgs e) + { + // Current authentication + + 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); + + _currentUser = Person.FromIdentity(currentUserId); + Authority authority = _currentUser.GetAuthority(); + _currentOrganization = Organization.FromIdentity(currentOrganizationId); + + Response.ContentType = "application/json"; + + _attestationRights = GetAttestationRights(); + + // TODO: Set language for localization + + // Get all attestable items + + _items = new AttestableItems(); + + PopulateCashAdvances(); + + // Format as JSON and return + + string json = FormatAsJson(); + Response.Output.WriteLine(json); + Response.End(); + } + + private string FormatAsJson() + { + StringBuilder result = new StringBuilder(16384); + + result.Append("{\"rows\":["); + + foreach (AttestableItem item in _items) + { + result.Append("{"); + result.AppendFormat( + "\"item\":\"{0}\",\"beneficiary\":\"{1}\",\"description\":\"{2}\",\"budgetName\":\"{3}\",\"amountRequested\":\"{4:N2}\",\"itemId\":\"{5}\"", + item.IdentityDisplay, item.Beneficiary, item.Description, item.BudgetName, + item.AmountRequestedCents/100.0, item.Identity); + result.Append("},"); + } + + result.Remove(result.Length - 1, 1); // remove last comma + + result.Append("]}"); + + return result.ToString(); + } + + private Dictionary _attestationRights; + private Person _currentUser; + private Organization _currentOrganization; + private AttestableItems _items; + + protected class AttestableItem + { + public AttestableItem(string identity, string beneficiary, Int64 amountCents, FinancialAccount account, string description, string identityDisplay, IHasIdentity item) + { + this.IdentityDisplay = identityDisplay; + this.Identity = identity; + this.Beneficiary = beneficiary; + this.AmountRequestedCents = amountCents; + this.Budget = account; + this.Description = description; + this.Item = item; + } + + public FinancialAccount Budget { get; private set; } + public string BudgetName { get { return this.Budget.Name; } } + public string Identity { get; private set; } + public string Beneficiary { get; private set; } + public Int64 AmountRequestedCents { get; private set; } + public string Description { get; private set; } + public string IdentityDisplay { get; private set; } + public IHasIdentity Item { get; private set; } + } + + protected class AttestableItems : List + { + // empty class, we just want the name definition + } + + + + private Dictionary GetAttestationRights() + { + // Right now, this function is quite primitive. At some point in the future, it needs to take into + // account that a budget may have several attesters. Right now, it just loops over all accounts and + // checks the owner. + + Dictionary result = new Dictionary(); + FinancialAccounts accounts = FinancialAccounts.ForOrganization(_currentOrganization); + + foreach (FinancialAccount account in accounts) + { + if (account.OwnerPersonId == _currentUser.Identity) + { + result[account.Identity] = true; + } + } + + return result; + } + + + private void PopulateCashAdvances() + { + CashAdvances advances = CashAdvances.ForOrganization(_currentOrganization).WhereUnattested; + + foreach (CashAdvance advance in advances) + { + _items.Add(new AttestableItem("A" + advance.Identity.ToString(CultureInfo.InvariantCulture), "Beneficiary", advance.AmountCents, advance.FinancialAccount, "Description", "Advance", advance)); + } + } + + +} \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/BalanceSheet.aspx b/Site5/Pages/v5/Ledgers/BalanceSheet.aspx index e9da46ae..3447801d 100644 --- a/Site5/Pages/v5/Ledgers/BalanceSheet.aspx +++ b/Site5/Pages/v5/Ledgers/BalanceSheet.aspx @@ -85,7 +85,7 @@ url="Json-BalanceSheetData.aspx" rownumbers="false" animate="true" - fit="true" + fitColumns="true" idField="id" treeField="name">