Work on account automation profiles

This commit is contained in:
Rick Falkvinge
2018-04-15 16:20:52 +02:00
parent ca5ba0da4c
commit fd7fa680ad
8 changed files with 274 additions and 79 deletions
+11 -1
View File
@@ -432,6 +432,16 @@ namespace Swarmops.Common.Enums
OrgSignupLastPage,
OrgApplicationCompleteMail,
OrgParticipationAcceptedMail,
OrgApplicationQualifyingScore
OrgApplicationQualifyingScore,
/// <summary>
/// Profile identifier for asset tracking automation
/// </summary>
AutomationProfileId,
/// <summary>
/// If custom automation, the XML for it, in string format
/// </summary>
AutomationProfileCustomXml
}
}
+21
View File
@@ -646,5 +646,26 @@ namespace Swarmops.Logic.Financial
return result;
}
public int AutomationProfileId
{
get { return ObjectOptionalData.ForObject(this).GetOptionalDataInt(ObjectOptionalDataType.AutomationProfileId); }
set { ObjectOptionalData.ForObject(this).SetOptionalDataInt(ObjectOptionalDataType.AutomationProfileId, value); }
}
public string AutomationProfileCustomXml
{
get
{
return
ObjectOptionalData.ForObject(this)
.GetOptionalDataString(ObjectOptionalDataType.AutomationProfileCustomXml);
}
set
{
ObjectOptionalData.ForObject(this).SetOptionalDataString(ObjectOptionalDataType.AutomationProfileCustomXml, value);
}
}
}
}
+1 -1
View File
@@ -160,7 +160,7 @@ namespace Resources.Pages {
}
/// <summary>
/// Looks up a localized string similar to File upload profile.
/// Looks up a localized string similar to Automation Profile.
/// </summary>
internal static string AccountPlan_Edit_FileUploadProfile {
get {
+1 -1
View File
@@ -431,7 +431,7 @@
<value>Expensable</value>
</data>
<data name="AccountPlan_Edit_FileUploadProfile" xml:space="preserve">
<value>File upload profile</value>
<value>Automation Profile</value>
</data>
<data name="AccountPlan_Edit_Header" xml:space="preserve">
<value>Editing Account</value>
+64 -47
View File
@@ -1,9 +1,5 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.AccountPlan" Codebehind="AccountPlan.aspx.cs" CodeFile="AccountPlan.aspx.cs" %>
<%@ Import Namespace="Swarmops.Logic.Financial" %>
<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="ComboPeople" Src="~/Controls/v5/Swarm/ComboPeople.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="TextCurrency" Src="~/Controls/v5/Financial/CurrencyTextBox.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="ModalDialog" Src="~/Controls/v5/Base/ModalDialog.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<script src="/Scripts/jquery.switchButton.js" language="javascript" type="text/javascript"></script>
@@ -397,55 +393,47 @@
}, 100);
}
$.ajax({
type: "POST",
url: "/Pages/v5/Ledgers/AccountPlan.aspx/GetAccountData",
data: "{'accountId': '" + escape(accountId) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
SwarmopsJS.ajaxCall(
"/Pages/v5/Ledgers/AccountPlan.aspx/GetAccountData",
{ accountId: accountId },
function(data) {
suppressSwitchChangeAction = true;
$("#CheckAccountActive").prop("checked", msg.d.Active).change();
$("#CheckAccountExpensable").prop("checked", msg.d.Expensable).change();
$("#CheckAccountAdministrative").prop("checked", msg.d.Administrative).change();
$("#CheckAccountActive").prop("checked", data.Active).change();
$("#CheckAccountExpensable").prop("checked", data.Expensable).change();
$("#CheckAccountAdministrative").prop("checked", data.Administrative).change();
suppressSwitchChangeAction = false;
modalAccountName = msg.d.AccountName;
$('#TextAccountName').val(msg.d.AccountName).css('background-color', '#FFF');
modalAccountName = data.AccountName;
$('#TextAccountName').val(data.AccountName).css('background-color', '#FFF');
modalAccountBudget = msg.d.Budget;
$('#TextAccountBudget').val(msg.d.Budget).css('background-color', '#FFF');
modalAccountBudget = data.Budget;
$('#TextAccountBudget').val(data.Budget).css('background-color', '#FFF');
modalAccountInitialBalance = msg.d.InitialBalance;
$('#<%=CurrencyInitialBalance.ClientID%>_TextInput').val(msg.d.InitialBalance).css('background-color', '#FFF');
modalAccountInitialBalance = data.InitialBalance;
$('#<%=CurrencyInitialBalance.ClientID%>_TextInput').val(data.InitialBalance).css('background-color', '#FFF');
$('#SpanTextCurrency').text(msg.d.CurrencyCode);
$('#SpanEditBalance').text(msg.d.Balance);
parentAccountName = msg.d.ParentAccountName;
setAccountTreeId(msg.d.ParentAccountId);
$('#SpanTextCurrency').text(data.CurrencyCode);
$('#SpanEditBalance').text(data.Balance);
parentAccountName = data.ParentAccountName;
setAccountTreeId(data.ParentAccountId);
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.textbox-text').css('background-color', '#FFF');
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.textbox-text').css('background-image', "url('" + msg.d.AccountOwnerAvatarUrl + "')");
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.textbox-text').attr('placeholder', msg.d.AccountOwnerName);
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.textbox-text').css('background-image', "url('" + data.AccountOwnerAvatarUrl + "')");
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.textbox-text').attr('placeholder', data.AccountOwnerName);
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.textbox-text').val('');
}
});
});
}
function updateInactiveCount()
{
$.ajax({
type: "POST",
url: "/Pages/v5/Ledgers/AccountPlan.aspx/GetInactiveAccountCount",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$("#SpanInactiveCount").text(msg.d);
}
});
SwarmopsJS.ajaxCall (
"/Pages/v5/Ledgers/AccountPlan.aspx/GetInactiveAccountCount",
{},
function(msg) {
$("#SpanInactiveCount").text(msg);
});
}
function modalShow() {
@@ -625,11 +613,24 @@
<label for="CheckAccountExpensable"><asp:Literal ID="LiteralLabelExpensableShort" runat="server"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Expensable" class="EditCheck" id="CheckAccountExpensable"/></div><br/>
<label for="CheckAccountAdministrative"><asp:Literal ID="LiteralLabelAdministrativeShort" runat="server"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Administrative" class="EditCheck" id="CheckAccountAdministrative"/></div>
&nbsp;<br/></div>
<div id="DivEditInitControls"><Swarmops5:TextCurrency ID="CurrencyInitialBalance" runat="server" /></div>
<div id="DivEditAssetControls">
&nbsp;<br/>&nbsp;<br/>&nbsp;<br/><!--
<asp:DropDownList runat="server" ID="DropAccountUploadFormats"/>
<div class="stacked-input-control"><input type="text" id="TextAutomationPaymentTag" readonly="readonly"/></div>-->
<div class="DivEditInitControls"><Swarmops5:TextCurrency ID="CurrencyInitialBalance" runat="server" />
<div class="DivEditForexControls"><Swarmops5:TextCurrency ID="CurrencyInitialBalanceForex" runat="server" /></div></div>
<div class="DivEditAssetControls">
<div class="stacked-input-control"></div><!-- space for headline -->
<Swarmops5:AjaxToggleSlider ID="ToggleAssetAutomation" runat="server"/>
<div class="DivEditAutomationControls">
<Swarmops5:AjaxDropDown ID="DropAccountAutomationProfile" runat="server"/>
<div class="DivAutomationProfileCustom">
<Swarmops5:AjaxTextBox ID="TextCustomAutomationProfile" runat="server"/>
</div>
<div class="DivAutomaticRetrieval">
<Swarmops5:AjaxToggleSlider ID="ToggleAutoRetrieval" runat="server"/>
<div class="DivAutomaticRetrievalCredentials">
<Swarmops5:AjaxTextBox ID="TextRetrievalLogin" runat="server"/>
<Swarmops5:AjaxTextBox ID="TextRetrievalPassword" runat="server"/>
</div>
</div>
</div>
</div>
</div>
<div class="entryLabels"><asp:Literal ID="LiteralLabelAccountName" runat="server"/><br/>
@@ -641,10 +642,26 @@
<asp:Literal ID="LiteralLabelActiveLong" runat="server"/><br/>
<asp:Literal ID="LiteralLabelExpensableLong" runat="server"/><br/>
<asp:Literal ID="LiteralLabelAdministrativeLong" runat="server"/><br/></div>
<div id="DivEditInitLabels"><asp:Literal ID="LiteralLabelInitialAmount" runat="server"/></div>
<div id="DivEditAssetLabels"><h2><asp:Literal ID="LiteralLabelHeaderAutomation" runat="server"/></h2>
<!--<asp:Literal ID="LiteralLabelFileUploadProfile" runat="server"/>-->TODO<br/>
<span id="SpanUploadParameterName">TODO</span></div>
<div id="DivEditInitLabels"><asp:Literal ID="LiteralLabelInitialAmount" runat="server"/>
<div class="DivEditForexControls">Initial Balance (<span class="SpanAccountCurrencyCode">XXX</span>)</div>
</div>
<div class="DivEditAssetControls">
<h2><asp:Label ID="LabelHeaderAutomation" runat="server"/></h2>
Enable account automation<br/>
<div class="DivEditAutomationControls">
<asp:Label runat="server" ID="LabelFileUploadProfile"/><br/>
<div class="DivAutomationProfileCustom">
Custom Profile XML<br/>
</div>
<div class="DivAutomaticRetrieval">
Automatic Retrieval<br />
<div class="DivAutomaticRetrievalCredentials">
Autoretrieval Username<br/>
Autoretrieval Password<br />
</div>
</div>
</div>
</div>
</div>
</DialogCode>
</Swarmops5:ModalDialog>
+115 -23
View File
@@ -77,8 +77,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
this.LiteralLabelBudgetBalance.Text = Resources.Pages.Ledgers.AccountPlan_Edit_BudgetBalance;
this.LiteralLabelExpensableLong.Text = Resources.Pages.Ledgers.AccountPlan_Edit_ExpensableLong;
this.LiteralLabelExpensableShort.Text = Resources.Pages.Ledgers.AccountPlan_Edit_ExpensableShort;
this.LiteralLabelFileUploadProfile.Text = Resources.Pages.Ledgers.AccountPlan_Edit_FileUploadProfile;
this.LiteralLabelHeaderAutomation.Text = Resources.Pages.Ledgers.AccountPlan_Edit_HeaderAutomation;
this.LabelFileUploadProfile.Text = Resources.Pages.Ledgers.AccountPlan_Edit_FileUploadProfile;
this.LabelHeaderAutomation.Text = Resources.Pages.Ledgers.AccountPlan_Edit_HeaderAutomation;
this.LiteralLabelHeaderConfiguration.Text = Resources.Pages.Ledgers.AccountPlan_Edit_HeaderConfiguration;
this.LiteralLabelHeaderDailyOperations.Text =
Resources.Pages.Ledgers.AccountPlan_Edit_HeaderDailyOperations;
@@ -104,7 +104,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
[WebMethod]
public static JsonAccountData GetAccountData (int accountId)
public static AjaxCallAccountData GetAccountData (int accountId)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
@@ -118,7 +118,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
FinancialAccounts accountTree = account.ThisAndBelow();
int year = DateTime.Today.Year;
JsonAccountData result = new JsonAccountData();
AjaxCallAccountData result = new AjaxCallAccountData();
if (account.ParentIdentity == 0)
{
@@ -276,9 +276,16 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
return false;
}
// TODO SECURITY: Verify that authdata.AuthenticatedPerson can see personId, or this can be exploited to enumerate all people
Person newOwner = Person.FromIdentity(newOwnerId);
account.Owner = Person.FromIdentity (newOwnerId);
// Verify that authdata.AuthenticatedPerson can see personId, or this can be exploited to enumerate all people
if (!authData.Authority.CanSeePerson(newOwner))
{
throw new ArgumentException("No such person identity");
}
account.Owner = newOwner;
return true;
}
@@ -287,6 +294,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
{
try
{
const string initialBalanceTransactionTitle = "Initial Balances";
AuthenticationData authData = GetAuthenticationDataAndCulture();
FinancialAccount account = FinancialAccount.FromIdentity (accountId);
@@ -314,7 +323,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
foreach (FinancialAccountRow row in testRows)
{
if (row.Transaction.Description == "Initial Balances")
if (row.Transaction.Description == initialBalanceTransactionTitle)
{
initialBalancesTransaction = row.Transaction;
break;
@@ -326,7 +335,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
// create transaction
initialBalancesTransaction = FinancialTransaction.Create (authData.CurrentOrganization.Identity,
new DateTime (authData.CurrentOrganization.FirstFiscalYear - 1, 12, 31), "Initial Balances");
new DateTime (authData.CurrentOrganization.FirstFiscalYear - 1, 12, 31), initialBalanceTransactionTitle);
}
Dictionary<int, Int64> recalcBase = initialBalancesTransaction.GetRecalculationBase();
@@ -358,6 +367,85 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
}
}
[WebMethod]
public static ChangeAccountDataResult SetAccountInitialBalanceForex(int accountId, string newInitialBalanceString)
{
try
{
const string initialBalanceTransactionTitle = "Initial Balances";
AuthenticationData authData = GetAuthenticationDataAndCulture();
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
if (!PrepareAccountChange(account, authData, false) || authData.CurrentOrganization.Parameters.FiscalBooksClosedUntilYear >= authData.CurrentOrganization.FirstFiscalYear)
{
return new ChangeAccountDataResult
{
Result = ChangeAccountDataOperationsResult.NoPermission
};
}
Int64 desiredInitialBalanceCents = Formatting.ParseDoubleStringAsCents(newInitialBalanceString);
Int64 currentInitialBalanceCents = account.GetDeltaCents(new DateTime(1900, 1, 1),
new DateTime(authData.CurrentOrganization.FirstFiscalYear, 1, 1));
Int64 deltaCents = desiredInitialBalanceCents - currentInitialBalanceCents;
// Find or create "Initial Balances" transaction
FinancialAccountRows testRows = FinancialAccountRows.ForOrganization(authData.CurrentOrganization,
new DateTime(1900, 1, 1), new DateTime(authData.CurrentOrganization.FirstFiscalYear, 1, 1));
FinancialTransaction initialBalancesTransaction = null;
foreach (FinancialAccountRow row in testRows)
{
if (row.Transaction.Description == initialBalanceTransactionTitle)
{
initialBalancesTransaction = row.Transaction;
break;
}
}
if (initialBalancesTransaction == null)
{
// create transaction
initialBalancesTransaction = FinancialTransaction.Create(authData.CurrentOrganization.Identity,
new DateTime(authData.CurrentOrganization.FirstFiscalYear - 1, 12, 31), initialBalanceTransactionTitle);
}
Dictionary<int, Int64> recalcBase = initialBalancesTransaction.GetRecalculationBase();
int equityAccountId = authData.CurrentOrganization.FinancialAccounts.DebtsEquity.Identity;
if (!recalcBase.ContainsKey(accountId))
{
recalcBase[accountId] = 0;
}
if (!recalcBase.ContainsKey(equityAccountId))
{
recalcBase[equityAccountId] = 0;
}
recalcBase[accountId] += deltaCents;
recalcBase[equityAccountId] -= deltaCents;
initialBalancesTransaction.RecalculateTransaction(recalcBase, authData.CurrentUser);
return new ChangeAccountDataResult
{
Result = ChangeAccountDataOperationsResult.Changed,
NewData = (desiredInitialBalanceCents / 100.0).ToString("N2", CultureInfo.CurrentCulture)
};
}
catch (Exception weirdException)
{
SupportFunctions.LogException("AccountPlan-SetInitBalance", weirdException);
throw;
}
}
[WebMethod]
public static ChangeAccountDataResult SetAccountBudget (int accountId, string budget)
{
@@ -464,6 +552,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
}
[Serializable]
public class ChangeAccountDataResult
{
public ChangeAccountDataOperationsResult Result { set; get; }
@@ -471,22 +560,25 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
}
public struct JsonAccountData
[Serializable]
public class AjaxCallAccountData: AjaxCallResult
{
public string AccountName;
public string AccountOwnerAvatarUrl;
public string AccountOwnerName;
public bool Active;
public bool Administrative;
public string InitialBalance;
public string Balance;
public string Budget;
public string ClosedYear;
public string CurrencyCode;
public bool Expensable;
public bool Open;
public int ParentAccountId;
public string ParentAccountName;
public string AccountName { get; set; }
public string AccountOwnerAvatarUrl { get; set; }
public string AccountOwnerName { get; set; }
public bool Active { get; set; }
public bool Administrative { get; set; }
public int AutomationProfileId { get; set; }
public string AutomationProfileCustomXml { get; set; }
public string InitialBalance { get; set; }
public string Balance { get; set; }
public string Budget { get; set; }
public string ClosedYear { get; set; }
public string CurrencyCode { get; set; }
public bool Expensable { get; set; }
public bool Open { get; set; }
public int ParentAccountId { get; set; }
public string ParentAccountName { get; set; }
}
}
}
+60 -6
View File
@@ -166,13 +166,67 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers {
protected global::Swarmops.Frontend.Controls.Financial.CurrencyTextBox CurrencyInitialBalance;
/// <summary>
/// DropAccountUploadFormats control.
/// CurrencyInitialBalanceForex control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DropDownList DropAccountUploadFormats;
protected global::Swarmops.Frontend.Controls.Financial.CurrencyTextBox CurrencyInitialBalanceForex;
/// <summary>
/// ToggleAssetAutomation control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.AjaxToggleSlider ToggleAssetAutomation;
/// <summary>
/// DropAccountAutomationProfile control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.AjaxDropDown DropAccountAutomationProfile;
/// <summary>
/// TextCustomAutomationProfile control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.AjaxTextBox TextCustomAutomationProfile;
/// <summary>
/// ToggleAutoRetrieval control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.AjaxToggleSlider ToggleAutoRetrieval;
/// <summary>
/// TextRetrievalLogin control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.AjaxTextBox TextRetrievalLogin;
/// <summary>
/// TextRetrievalPassword control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.AjaxTextBox TextRetrievalPassword;
/// <summary>
/// LiteralLabelAccountName control.
@@ -265,22 +319,22 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers {
protected global::System.Web.UI.WebControls.Literal LiteralLabelInitialAmount;
/// <summary>
/// LiteralLabelHeaderAutomation control.
/// LabelHeaderAutomation control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal LiteralLabelHeaderAutomation;
protected global::System.Web.UI.WebControls.Label LabelHeaderAutomation;
/// <summary>
/// LiteralLabelFileUploadProfile control.
/// LabelFileUploadProfile control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal LiteralLabelFileUploadProfile;
protected global::System.Web.UI.WebControls.Label LabelFileUploadProfile;
/// <summary>
/// LabelSidebarOptions control.
+1
View File
@@ -45,6 +45,7 @@
<add tagPrefix="Swarmops5" tagName="IncludedScripts" src="~/Controls/v5/Meta/IncludedScripts.ascx" />
<add tagPrefix="Swarmops5" tagName="ModalDialog" src="~/Controls/v5/Base/ModalDialog.ascx" />
<add tagPrefix="Swarmops5" tagName="MainMenu" src="~/Controls/v5/Base/MainMenu.ascx" />
<add tagPrefix="Swarmops5" tagName="TextCurrency" src="~/Controls/v5/Financial/CurrencyTextBox.ascx" />
<add tagPrefix="Swarmops5" tagName="TreePositions" src="~/Controls/v5/Swarm/TreePositions.ascx" />
<add tagPrefix="Swarmops5" tagName="ProgressBar" src="~/Controls/v5/Base/ProgressBar.ascx" />
<add tagPrefix="Swarmops5" tagName="ProgressBarFake" src="~/Controls/v5/Base/ProgressBarFake.ascx" />