Commit changes - moves and renames can sometimes screw up the repo

This commit is contained in:
Rick Falkvinge
2013-02-05 19:54:50 +00:00
parent 791ff351c4
commit 64dd5e80c0
11 changed files with 518 additions and 189 deletions
+2 -2
View File
@@ -152,14 +152,14 @@
<telerik:RadMenuItem runat="server" Text="XYZ Financial" Permission="CanSeeSelf" UserLevel="1" GlobalResourceKey="Menu5_Financial">
<Items>
<telerik:RadMenuItem runat="server" Text="XYZ Claim Refund For Expense" ImageUrl="~/Images/PageIcons/iconshock-moneyback-16px.png" Permission="All" UserLevel="1" GlobalResourceKey="Menu5_Financial_ClaimExpense" />
<telerik:RadMenuItem runat="server" Text="XYZ Request Cash Advance" NavigateUrl="~/Pages/v5/Finance/RequestCashAdvance.aspx" ImageUrl="~/Images/PageIcons/iconshock-walletmoney-16px.png" Permission="All" UserLevel="1" GlobalResourceKey="Menu5_Financial_RequestCashAdvance" />
<telerik:RadMenuItem runat="server" Text="XYZ Request Cash Advance" NavigateUrl="~/Pages/v5/Financial/RequestCashAdvance.aspx" ImageUrl="~/Images/PageIcons/iconshock-walletmoney-16px.png" Permission="All" UserLevel="1" GlobalResourceKey="Menu5_Financial_RequestCashAdvance" />
<telerik:RadMenuItem runat="server" Text="XYZ Create Purchase Order" Permission="All" UserLevel="2" GlobalResourceKey="Menu5_Financial_CreatePurchaseOrder" />
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="1" />
<telerik:RadMenuItem runat="server" Text="XYZ View Budget, Actuals" ImageUrl="~/Images/PageIcons/iconshock-scales-16px.png" Permission="All" UserLevel="1" GlobalResourceKey="Menu5_Financial_ViewBudgetActuals" />
<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" 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" Text="XYZ Attest Costs" NavigateUrl="~/Pages/v5/Financial/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" />
@@ -1 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ExpensableBudgetsTree.aspx.cs" Inherits="Pages_v5_Finance_Json_ExpensableBudgetsTree" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ExpensableBudgetsTree.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Finance.Json_ExpensableBudgetsTree" %>
@@ -10,96 +10,101 @@ using Swarmops.Logic.Swarm;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
public partial class Pages_v5_Finance_Json_ExpensableBudgetsTree : System.Web.UI.Page
namespace Swarmops.Frontend.Pages.v5.Finance
{
protected void Page_Load(object sender, EventArgs e)
public partial class Json_ExpensableBudgetsTree : System.Web.UI.Page
{
// 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);
Person currentUser = Person.FromIdentity(currentUserId);
Authority authority = currentUser.GetAuthority();
Organization currentOrganization = Organization.FromIdentity(currentOrganizationId);
Response.ContentType = "application/json";
// Is this stuff in cache already?
string cacheKey = "ExpensableAccounts-Json-" + currentOrganizationId.ToString((CultureInfo.InvariantCulture));
string accountsJson =
(string) Cache[cacheKey];
if (accountsJson != null)
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);
Person currentUser = Person.FromIdentity(currentUserId);
Authority authority = currentUser.GetAuthority();
Organization currentOrganization = Organization.FromIdentity(currentOrganizationId);
Response.ContentType = "application/json";
// Is this stuff in cache already?
string cacheKey = "ExpensableAccounts-Json-" +
currentOrganizationId.ToString((CultureInfo.InvariantCulture));
string accountsJson =
(string) Cache[cacheKey];
if (accountsJson != null)
{
Response.Output.WriteLine(accountsJson);
Response.End();
return;
}
// Not in cache. Construct.
// Get accounts
FinancialAccounts accounts = currentOrganization.FinancialAccounts.ExpensableAccounts;
// Build tree (there should be a template for this)
Dictionary<int, List<FinancialAccount>> treeMap = new Dictionary<int, List<FinancialAccount>>();
foreach (FinancialAccount account in accounts)
{
if (!treeMap.ContainsKey(account.ParentIdentity))
{
treeMap[account.ParentIdentity] = new List<FinancialAccount>();
}
treeMap[account.ParentIdentity].Add(account);
}
int renderRootNodeId = 0;
if (treeMap[0].Count == 1)
{
// assume there's a master root like "Costs"; bypass it
renderRootNodeId = treeMap[0][0].Identity;
}
accountsJson = RecurseTreeMap(treeMap, renderRootNodeId);
Cache.Insert(cacheKey, accountsJson, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
// cache lasts for five minutes, no sliding expiration
Response.Output.WriteLine(accountsJson);
Response.End();
return;
}
// Not in cache. Construct.
// Get accounts
FinancialAccounts accounts = currentOrganization.FinancialAccounts.ExpensableAccounts;
// Build tree (there should be a template for this)
Dictionary<int, List<FinancialAccount>> treeMap = new Dictionary<int, List<FinancialAccount>>();
foreach (FinancialAccount account in accounts)
private string RecurseTreeMap(Dictionary<int, List<FinancialAccount>> treeMap, int node)
{
if (!treeMap.ContainsKey(account.ParentIdentity))
List<string> elements = new List<string>();
foreach (FinancialAccount account in treeMap[node])
{
treeMap[account.ParentIdentity] = new List<FinancialAccount>();
string element = string.Format("\"id\":{0},\"text\":\"{1}\"", account.Identity,
account.Name.Replace("\"", "'"));
if (treeMap.ContainsKey(account.Identity))
{
element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, account.Identity);
}
elements.Add("{" + element + "}");
}
treeMap[account.ParentIdentity].Add(account);
return "[" + String.Join(",", elements.ToArray()) + "]";
}
int renderRootNodeId = 0;
if (treeMap[0].Count == 1)
{
// assume there's a master root like "Costs"; bypass it
renderRootNodeId = treeMap[0][0].Identity;
}
accountsJson = RecurseTreeMap (treeMap, renderRootNodeId);
Cache.Insert(cacheKey, accountsJson, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero); // cache lasts for five minutes, no sliding expiration
Response.Output.WriteLine(accountsJson);
Response.End();
}
private string RecurseTreeMap (Dictionary<int, List<FinancialAccount>> treeMap, int node)
{
List<string> elements = new List<string>();
foreach (FinancialAccount account in treeMap[node])
{
string element = string.Format("\"id\":{0},\"text\":\"{1}\"", account.Identity,
account.Name.Replace("\"", "'"));
if (treeMap.ContainsKey(account.Identity))
{
element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, account.Identity);
}
elements.Add("{" + element + "}");
}
return "[" + String.Join(",", elements.ToArray()) + "]";
}
}
@@ -1,4 +1,4 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="RequestCashAdvance.aspx.cs" Inherits="Pages_v5_Finance_RequestCashAdvance" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="RequestCashAdvance.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Finance.RequestCashAdvance" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<script src="https://hostedscripts.falkvinge.net/easyui/jquery.easyui.min.js" type="text/javascript"></script>
@@ -7,106 +7,113 @@ using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Logic.Financial;
public partial class Pages_v5_Finance_RequestCashAdvance : PageV5Base
namespace Swarmops.Frontend.Pages.v5.Finance
{
protected void Page_Load(object sender, EventArgs e)
public partial class RequestCashAdvance : PageV5Base
{
if (!this.CurrentOrganization.IsEconomyEnabled)
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
return;
if (!this.CurrentOrganization.IsEconomyEnabled)
{
Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
return;
}
this.PageTitle = Resources.Pages.Finance.RequestCashAdvance_PageTitle;
this.PageIcon = "iconshock-walletmoney";
this.InfoBoxLiteral = Resources.Pages.Finance.RequestCashAdvance_Info;
if (!Page.IsPostBack)
{
// Prime bank details
this.TextBank.Text = this.CurrentUser.BankName;
this.TextClearing.Text = this.CurrentUser.BankClearing;
this.TextAccount.Text = this.CurrentUser.BankAccount;
this.TextAmount.Text = 0.ToString("N2");
this.TextAmount.Focus();
Localize();
}
}
this.PageTitle = Resources.Pages.Finance.RequestCashAdvance_PageTitle;
this.PageIcon = "iconshock-walletmoney";
this.InfoBoxLiteral = Resources.Pages.Finance.RequestCashAdvance_Info;
if (!Page.IsPostBack)
private void Localize()
{
// Prime bank details
this.LabelAmount.Text = string.Format(Resources.Pages.Finance.RequestCashAdvance_Amount,
CurrentOrganization.Currency.Code);
this.LabelPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_Purpose;
this.LabelBudget.Text = Resources.Pages.Finance.RequestCashAdvance_Budget;
this.LabelHeaderBankDetails.Text = Resources.Pages.Finance.RequestCashAdvance_HeaderBankDetails;
this.LabelBankName.Text = Resources.Pages.Finance.RequestCashAdvance_BankName;
this.LabelBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_BankClearing;
this.LabelBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_BankAccount;
this.TextBank.Text = this.CurrentUser.BankName;
this.TextClearing.Text = this.CurrentUser.BankClearing;
this.TextAccount.Text = this.CurrentUser.BankAccount;
this.TextAmount.Text = 0.ToString("N2");
this.TextAmount.Focus();
Localize();
}
}
private void Localize()
{
this.LabelAmount.Text = string.Format(Resources.Pages.Finance.RequestCashAdvance_Amount,
CurrentOrganization.Currency.Code);
this.LabelPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_Purpose;
this.LabelBudget.Text = Resources.Pages.Finance.RequestCashAdvance_Budget;
this.LabelHeaderBankDetails.Text = Resources.Pages.Finance.RequestCashAdvance_HeaderBankDetails;
this.LabelBankName.Text = Resources.Pages.Finance.RequestCashAdvance_BankName;
this.LabelBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_BankClearing;
this.LabelBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_BankAccount;
this.LiteralErrorAmount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Amount;
this.LiteralErrorPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Purpose;
this.LiteralErrorBudget.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Budget;
this.LiteralErrorBankName.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankName;
this.LiteralErrorBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankClearing;
this.LiteralErrorBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankAccount;
}
protected void ButtonRequest_Click(object sender, EventArgs e)
{
// The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here.
double amount = Double.Parse(this.TextAmount.Text, NumberStyles.Number); // parses in current culture - intentional
Int64 amountCents = (Int64) amount*100;
string description = this.TextPurpose.Text;
FinancialAccount budget = FinancialAccount.FromIdentity(Int32.Parse(this.Request.Form["DropBudgets"]));
// sanity check
if (budget.Organization.Identity != CurrentOrganization.Identity)
{
throw new InvalidOperationException("Budget-organization mismatch; won't file cash advance");
this.LiteralErrorAmount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Amount;
this.LiteralErrorPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Purpose;
this.LiteralErrorBudget.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Budget;
this.LiteralErrorBankName.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankName;
this.LiteralErrorBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankClearing;
this.LiteralErrorBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankAccount;
}
// Store bank details for current user
CurrentUser.BankName = this.TextBank.Text;
CurrentUser.BankClearing = this.TextClearing.Text;
CurrentUser.BankAccount = this.TextAccount.Text;
// Create cash advance
CashAdvance cashAdvance = CashAdvance.Create(CurrentOrganization, CurrentUser, CurrentUser, amountCents, budget,
description);
// Create success message
string successMessage = string.Format(Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartOne,
HttpUtility.HtmlEncode(CurrentUser.Name),
HttpUtility.HtmlEncode(description), CurrentOrganization.Currency.Code,
(double) (amountCents/100.0));
if (budget.OwnerPersonId != CurrentUser.Identity)
protected void ButtonRequest_Click(object sender, EventArgs e)
{
successMessage += "<br/><br/>" + Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwo + "<br/>";
// The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here.
double amount = Double.Parse(this.TextAmount.Text, NumberStyles.Number);
// parses in current culture - intentional
Int64 amountCents = (Int64) amount*100;
string description = this.TextPurpose.Text;
FinancialAccount budget = FinancialAccount.FromIdentity(Int32.Parse(this.Request.Form["DropBudgets"]));
// sanity check
if (budget.Organization.Identity != CurrentOrganization.Identity)
{
throw new InvalidOperationException("Budget-organization mismatch; won't file cash advance");
}
// Store bank details for current user
CurrentUser.BankName = this.TextBank.Text;
CurrentUser.BankClearing = this.TextClearing.Text;
CurrentUser.BankAccount = this.TextAccount.Text;
// Create cash advance
CashAdvance cashAdvance = CashAdvance.Create(CurrentOrganization, CurrentUser, CurrentUser, amountCents,
budget,
description);
// Create success message
string successMessage = string.Format(Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartOne,
HttpUtility.HtmlEncode(CurrentUser.Name),
HttpUtility.HtmlEncode(description), CurrentOrganization.Currency.Code,
(double) (amountCents/100.0));
if (budget.OwnerPersonId != CurrentUser.Identity)
{
successMessage += "<br/><br/>" + Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwo +
"<br/>";
}
else
{
successMessage += "<br/><br/>" +
Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwoOwnBudget +
"<br/>";
// TODO: Auto-attest
}
Response.AppendCookie(new HttpCookie("DashboardMessage", HttpUtility.UrlEncode(successMessage)));
// Redirect to dashboard
Response.Redirect("/", true);
}
else
{
successMessage += "<br/><br/>" + Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwoOwnBudget +
"<br/>";
// TODO: Auto-attest
}
Response.AppendCookie(new HttpCookie("DashboardMessage", HttpUtility.UrlEncode(successMessage)));
// Redirect to dashboard
Response.Redirect("/", true);
}
}
+4 -3
View File
@@ -1,4 +1,4 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AttestCosts.aspx.cs" Inherits="Pages_v5_Finance_AttestCosts" %>
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AttestCosts.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.AttestCosts" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<script src="https://hostedscripts.falkvinge.net/easyui/jquery.easyui.min.js" type="text/javascript"></script>
@@ -15,9 +15,10 @@
<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:'description',width:140">Description</th>
<th data-options="field:'budgetName',width:140,sortable:true">Budget</th>
<th data-options="field:'amountRequested',width:80,align:'right',sortable:true,order:'asc'">Requested</th>
<th data-options="field:'dox',width:40,align:'right'">Docs</th>
<th data-options="field:'wontAttest',width:66,align:'center'">Action</th>
</tr>
</thead>
+18 -15
View File
@@ -6,28 +6,31 @@ using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Pages_v5_Finance_AttestCosts : PageV5Base
namespace Swarmops.Frontend.Pages.v5.Financial
{
protected void Page_Load(object sender, EventArgs e)
public partial class AttestCosts : PageV5Base
{
if (!this.CurrentOrganization.IsEconomyEnabled)
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
return;
if (!this.CurrentOrganization.IsEconomyEnabled)
{
Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
return;
}
this.PageIcon = "iconshock-stamped-paper";
if (!Page.IsPostBack)
{
Localize();
}
}
this.PageIcon = "iconshock-stamped-paper";
if (!Page.IsPostBack)
private void Localize()
{
Localize();
this.PageTitle = Resources.Pages.Finance.AttestCosts_PageTitle;
this.InfoBoxLiteral = Resources.Pages.Finance.AttestCosts_Info;
}
}
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-ExpensableBudgetsTree.aspx.cs" Inherits="Pages_v5_Finance_Json_ExpensableBudgetsTree" %>
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
public partial class Pages_v5_Finance_Json_ExpensableBudgetsTree : 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);
Person currentUser = Person.FromIdentity(currentUserId);
Authority authority = currentUser.GetAuthority();
Organization currentOrganization = Organization.FromIdentity(currentOrganizationId);
Response.ContentType = "application/json";
// Is this stuff in cache already?
string cacheKey = "ExpensableAccounts-Json-" + currentOrganizationId.ToString((CultureInfo.InvariantCulture));
string accountsJson =
(string) Cache[cacheKey];
if (accountsJson != null)
{
Response.Output.WriteLine(accountsJson);
Response.End();
return;
}
// Not in cache. Construct.
// Get accounts
FinancialAccounts accounts = currentOrganization.FinancialAccounts.ExpensableAccounts;
// Build tree (there should be a template for this)
Dictionary<int, List<FinancialAccount>> treeMap = new Dictionary<int, List<FinancialAccount>>();
foreach (FinancialAccount account in accounts)
{
if (!treeMap.ContainsKey(account.ParentIdentity))
{
treeMap[account.ParentIdentity] = new List<FinancialAccount>();
}
treeMap[account.ParentIdentity].Add(account);
}
int renderRootNodeId = 0;
if (treeMap[0].Count == 1)
{
// assume there's a master root like "Costs"; bypass it
renderRootNodeId = treeMap[0][0].Identity;
}
accountsJson = RecurseTreeMap (treeMap, renderRootNodeId);
Cache.Insert(cacheKey, accountsJson, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero); // cache lasts for five minutes, no sliding expiration
Response.Output.WriteLine(accountsJson);
Response.End();
}
private string RecurseTreeMap (Dictionary<int, List<FinancialAccount>> treeMap, int node)
{
List<string> elements = new List<string>();
foreach (FinancialAccount account in treeMap[node])
{
string element = string.Format("\"id\":{0},\"text\":\"{1}\"", account.Identity,
account.Name.Replace("\"", "'"));
if (treeMap.ContainsKey(account.Identity))
{
element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, account.Identity);
}
elements.Add("{" + element + "}");
}
return "[" + String.Join(",", elements.ToArray()) + "]";
}
}
@@ -0,0 +1,95 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="RequestCashAdvance.aspx.cs" Inherits="Pages_v5_Finance_RequestCashAdvance" %>
<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/tree.css"/>
<link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css">
<script type="text/javascript">
$(document).ready(function () {
$('#DropBudgets').combotree({
animate: true
}); // Is this init call even necessary?
$('input.combo-text').click(function () {
$('span.combo-arrow').click();
});
});
function validateFields() {
var isValid = true;
isValid = validateTextField('#<%=this.TextAccount.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankAccount" />") && isValid;
isValid = validateTextField('#<%=this.TextClearing.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankClearing" />") && isValid;
isValid = validateTextField('#<%=this.TextBank.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankName" />") && isValid;
if ($('#DropBudgets').combotree('tree').tree('getSelected') == null) {
isValid = false;
alertify.error("<asp:Literal runat="server" ID="LiteralErrorBudget" />");
}
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorPurpose" />") && isValid;
$.ajax({
type: "POST",
url: "/Automation/FieldValidation.asmx/IsAmountValid",
data: "{'amount': '" + escape($('#<%=this.TextAmount.ClientID %>').val()) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false, // blocks until function returns - race conditions otherwise
success: function (msg) {
if (msg.d != true) {
isValid = false;
alertify.error("<asp:Literal runat="server" ID="LiteralErrorAmount" />");
$('#<%=this.TextAmount.ClientID %>').focus();
}
}
});
return isValid;
}
function validateTextField (fieldId, message) {
if ($(fieldId).val().length == 0) {
alertify.error(message);
$(fieldId).focus();
return false;
}
return true;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<div class="entryFields">
<asp:TextBox runat="server" ID="TextAmount" CssClass="alignRight" />&nbsp;<br/>
<asp:TextBox runat="server" ID="TextPurpose" />&nbsp;<br/>
<select class="easyui-combotree" url="Json-ExpensableBudgetsTree.aspx" name="DropBudgets" id="DropBudgets" animate="true" style="width:300px"></select>&nbsp;<br/>
&nbsp;<br/><!-- placeholder for label-side H2 -->
<asp:TextBox runat="server" ID="TextBank" />&nbsp;<br/>
<asp:TextBox runat="server" ID="TextClearing" />&nbsp;<br/>
<asp:TextBox runat="server" ID="TextAccount" />&nbsp;<br/>
<asp:Button ID="ButtonRequest" runat="server" CssClass="buttonAccentColor" OnClientClick="return validateFields();" OnClick="ButtonRequest_Click" Text="Request"/>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelAmount" /><br/>
<asp:Label runat="server" ID="LabelPurpose" /><br/>
<asp:Label runat="server" ID="LabelBudget" /><br/>
<h2><asp:Label runat="server" ID="LabelHeaderBankDetails" /></h2>
<asp:Label runat="server" ID="LabelBankName" /><br/>
<asp:Label runat="server" ID="LabelBankClearing" /><br/>
<asp:Label runat="server" ID="LabelBankAccount" />
</div>
<div style="clear:both"></div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
</asp:Content>
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Logic.Financial;
public partial class Pages_v5_Finance_RequestCashAdvance : PageV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.CurrentOrganization.IsEconomyEnabled)
{
Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
return;
}
this.PageTitle = Resources.Pages.Finance.RequestCashAdvance_PageTitle;
this.PageIcon = "iconshock-walletmoney";
this.InfoBoxLiteral = Resources.Pages.Finance.RequestCashAdvance_Info;
if (!Page.IsPostBack)
{
// Prime bank details
this.TextBank.Text = this.CurrentUser.BankName;
this.TextClearing.Text = this.CurrentUser.BankClearing;
this.TextAccount.Text = this.CurrentUser.BankAccount;
this.TextAmount.Text = 0.ToString("N2");
this.TextAmount.Focus();
Localize();
}
}
private void Localize()
{
this.LabelAmount.Text = string.Format(Resources.Pages.Finance.RequestCashAdvance_Amount,
CurrentOrganization.Currency.Code);
this.LabelPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_Purpose;
this.LabelBudget.Text = Resources.Pages.Finance.RequestCashAdvance_Budget;
this.LabelHeaderBankDetails.Text = Resources.Pages.Finance.RequestCashAdvance_HeaderBankDetails;
this.LabelBankName.Text = Resources.Pages.Finance.RequestCashAdvance_BankName;
this.LabelBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_BankClearing;
this.LabelBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_BankAccount;
this.LiteralErrorAmount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Amount;
this.LiteralErrorPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Purpose;
this.LiteralErrorBudget.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Budget;
this.LiteralErrorBankName.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankName;
this.LiteralErrorBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankClearing;
this.LiteralErrorBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankAccount;
}
protected void ButtonRequest_Click(object sender, EventArgs e)
{
// The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here.
double amount = Double.Parse(this.TextAmount.Text, NumberStyles.Number); // parses in current culture - intentional
Int64 amountCents = (Int64) amount*100;
string description = this.TextPurpose.Text;
FinancialAccount budget = FinancialAccount.FromIdentity(Int32.Parse(this.Request.Form["DropBudgets"]));
// sanity check
if (budget.Organization.Identity != CurrentOrganization.Identity)
{
throw new InvalidOperationException("Budget-organization mismatch; won't file cash advance");
}
// Store bank details for current user
CurrentUser.BankName = this.TextBank.Text;
CurrentUser.BankClearing = this.TextClearing.Text;
CurrentUser.BankAccount = this.TextAccount.Text;
// Create cash advance
CashAdvance cashAdvance = CashAdvance.Create(CurrentOrganization, CurrentUser, CurrentUser, amountCents, budget,
description);
// Create success message
string successMessage = string.Format(Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartOne,
HttpUtility.HtmlEncode(CurrentUser.Name),
HttpUtility.HtmlEncode(description), CurrentOrganization.Currency.Code,
(double) (amountCents/100.0));
if (budget.OwnerPersonId != CurrentUser.Identity)
{
successMessage += "<br/><br/>" + Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwo + "<br/>";
}
else
{
successMessage += "<br/><br/>" + Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwoOwnBudget +
"<br/>";
// TODO: Auto-attest
}
Response.AppendCookie(new HttpCookie("DashboardMessage", HttpUtility.UrlEncode(successMessage)));
// Redirect to dashboard
Response.Redirect("/", true);
}
}