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 00000000..5cd87b1c Binary files /dev/null and b/Site5/Images/PageIcons/iconshock-stamped-paper-16px.png differ diff --git a/Site5/Images/PageIcons/iconshock-stamped-paper-40px.png b/Site5/Images/PageIcons/iconshock-stamped-paper-40px.png new file mode 100644 index 00000000..ec69b0ab Binary files /dev/null and b/Site5/Images/PageIcons/iconshock-stamped-paper-40px.png differ 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">