Committing first work on Attest Costs

This commit is contained in:
Rick Falkvinge
2013-02-04 11:29:43 +00:00
parent 0e518eeb0f
commit 3da0004e92
14 changed files with 265 additions and 5 deletions
+6
View File
@@ -61,5 +61,11 @@ namespace Swarmops.Logic.Financial
}
#endregion
public FinancialAccount FinancialAccount
{
get { return FinancialAccount.FromIdentity(this.FinancialAccountId); }
}
}
}
+37
View File
@@ -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<CashAdvances,CashAdvance,BasicCashAdvance>
{
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;
}
}
}
}
+1 -1
View File
@@ -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));
}
+1
View File
@@ -65,6 +65,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Financial\CashAdvance.cs" />
<Compile Include="Financial\CashAdvances.cs" />
<Compile Include="Financial\ImportedBankData.cs" />
<Compile Include="Financial\YearlyReport.cs" />
<Compile Include="Security\Accesses.cs" />
+6 -2
View File
@@ -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);
@@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<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_PageTitle" xml:space="preserve">
<value>Attest Costs</value>
</data>
<data name="RequestCashAdvance_Amount" xml:space="preserve">
<value>Advance amount (in {0})</value>
<comment>{0} is the currency.</comment>
Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

+1 -1
View File
@@ -159,7 +159,7 @@
<telerik:RadMenuItem runat="server" Text="XYZ View Liquidity Forecast" Permission="All" UserLevel="2" GlobalResourceKey="Menu5_Financial_ViewLiquidityForecast" />
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="2" />
<telerik:RadMenuItem runat="server" Text="XYZ Manage Budget" Permission="All" UserLevel="2" GlobalResourceKey="Menu5_Financial_ManageBudget" />
<telerik:RadMenuItem runat="server" Text="XYZ Attest Costs" Permission="All" UserLevel="2" GlobalResourceKey="Menu5_Financial_AttestCosts" />
<telerik:RadMenuItem runat="server" Text="XYZ Attest Costs" NavigateUrl="~/Pages/v5/Finance/AttestCosts.aspx" ImageUrl="~/Images/PageIcons/iconshock-stamped-paper-16px.png" Permission="All" UserLevel="2" GlobalResourceKey="Menu5_Financial_AttestCosts" />
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="2" />
<telerik:RadMenuItem runat="server" Text="XYZ Send Invoice" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_SendInvoice" />
<telerik:RadMenuItem runat="server" Text="XYZ Received Invoice" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_ReceivedInvoice" />
+29
View File
@@ -0,0 +1,29 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AttestCosts.aspx.cs" Inherits="Pages_v5_Finance_AttestCosts" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<script src="https://hostedscripts.falkvinge.net/easyui/jquery.easyui.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/default/datagrid.css"/>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<h2><asp:Label runat="server" ID="LabelAttestCostsHeader" Text="Attest Costs XYZ" /></h2>
<table id="dg" class="easyui-datagrid" style="width:680px;height:400px"
data-options="rownumbers:false,singleSelect:false,fit:false,loading:false,selectOnCheck:true,checkOnSelect:true,url:'Json-AttestableCosts.aspx'"
idField="itemId">
<thead>
<tr>
<th data-options="field:'check',checkbox:true"></th>
<th data-options="field:'item',width:60">Item</th>
<th data-options="field:'beneficiary',width:120,sortable:true">Beneficiary</th>
<th data-options="field:'description',width:160">Description</th>
<th data-options="field:'budgetName',width:160,sortable:true">Budget</th>
<th data-options="field:'amountRequested',width:80,align:'right',sortable:true,order:'asc'">Requested</th>
<th data-options="field:'wontAttest',width:66,align:'center'">Action</th>
</tr>
</thead>
</table>
<asp:Button runat="server" ID="ButtonAttest" Text="Clickme"/>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
</asp:Content>
@@ -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;
}
}
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-AttestableCosts.aspx.cs" Inherits="Pages_v5_Finance_Json_AttestableCosts" %>
@@ -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<int, bool> _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<AttestableItem>
{
// empty class, we just want the name definition
}
private Dictionary<int, bool> 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<int, bool> result = new Dictionary<int, bool>();
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));
}
}
}
+1 -1
View File
@@ -85,7 +85,7 @@
url="Json-BalanceSheetData.aspx"
rownumbers="false"
animate="true"
fit="true"
fitColumns="true"
idField="id" treeField="name">
<thead>
<tr>