Edit Organization switches work, roughly

This commit is contained in:
Rick Falkvinge
2014-11-18 20:37:21 +01:00
parent f01db6e925
commit 967f8e72fc
6 changed files with 320 additions and 18 deletions
+2 -2
View File
@@ -534,7 +534,7 @@ namespace Swarmops
//PirateWeb.Utility.Special.Sweden.SupportDatabase.CloseDelayWarnings();
NewsletterChecker.Run();
// NewsletterChecker.Run();
}
@@ -1155,7 +1155,7 @@ namespace Swarmops
private static void RunForumCheck()
{
SwedishForumMemberCheck.Run();
// SwedishForumMemberCheck.Run();
}
private static void RunRepaidTest()
-1
View File
@@ -59,7 +59,6 @@
<Reference Include="System.Data" />
<Reference Include="System.Security" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
@@ -100,11 +100,13 @@ namespace Swarmops.Logic.Financial
public FinancialAccount AssetsBitcoinCold
{
get { return this[OrganizationFinancialAccountType.AssetsBitcoinCold]; }
set { this[OrganizationFinancialAccountType.AssetsBitcoinCold] = value; }
}
public FinancialAccount AssetsBitcoinHot
{
get { return this[OrganizationFinancialAccountType.AssetsBitcoinHot]; }
set { this[OrganizationFinancialAccountType.AssetsBitcoinHot] = value; }
}
public FinancialAccount AssetsOutboundInvoices
@@ -120,11 +122,13 @@ namespace Swarmops.Logic.Financial
public FinancialAccount AssetsPaypal
{
get { return this[OrganizationFinancialAccountType.AssetsPaypal]; }
set { this[OrganizationFinancialAccountType.AssetsPaypal] = value; }
}
public FinancialAccount AssetsVatInbound
{
get { return this[OrganizationFinancialAccountType.AssetsVatInbound]; }
set { this[OrganizationFinancialAccountType.AssetsVatInbound] = value; }
}
public FinancialAccount CostsBankFees
@@ -140,6 +144,7 @@ namespace Swarmops.Logic.Financial
public FinancialAccount CostsCurrencyFluctuations
{
get { return this[OrganizationFinancialAccountType.CostsCurrencyFluctuations]; }
set { this[OrganizationFinancialAccountType.CostsCurrencyFluctuations] = value; }
}
public FinancialAccount CostsInfrastructure
@@ -185,6 +190,7 @@ namespace Swarmops.Logic.Financial
public FinancialAccount DebtsVatOutbound
{
get { return this[OrganizationFinancialAccountType.DebtsVatOutbound]; }
set { this[OrganizationFinancialAccountType.DebtsVatOutbound] = value; }
}
public FinancialAccount DebtsEarmarkedVirtualBanking
@@ -205,6 +211,7 @@ namespace Swarmops.Logic.Financial
public FinancialAccount IncomeCurrencyFluctuations
{
get { return this[OrganizationFinancialAccountType.IncomeCurrencyFluctuations]; }
set { this[OrganizationFinancialAccountType.IncomeCurrencyFluctuations] = value; }
}
public FinancialAccount IncomeDonations
+4 -4
View File
@@ -225,8 +225,8 @@ namespace Swarmops.Logic.Structure
// FinancialAccount.Create(this, "Bitcoin Holdings (Hot)", FinancialAccountType.Asset, null);
//FinancialAccounts[OrganizationFinancialAccountType.AssetsBitcoinCold] =
// FinancialAccount.Create(this, "Bitcoin Cold Storage", FinancialAccountType.Asset, null);
FinancialAccounts[OrganizationFinancialAccountType.AssetsVatInbound] =
FinancialAccount.Create(this, "Inbound Value Added Tax", FinancialAccountType.Asset, null);
//FinancialAccounts[OrganizationFinancialAccountType.AssetsVatInbound] =
// FinancialAccount.Create(this, "Inbound Value Added Tax", FinancialAccountType.Asset, null);
FinancialAccounts[OrganizationFinancialAccountType.CostsAllocatedFunds] =
FinancialAccount.Create(this, "Allocated funds", FinancialAccountType.Cost, null);
FinancialAccounts[OrganizationFinancialAccountType.CostsBankFees] =
@@ -247,8 +247,8 @@ namespace Swarmops.Logic.Structure
FinancialAccount.Create(this, "Salaries Due", FinancialAccountType.Debt, null);
FinancialAccounts[OrganizationFinancialAccountType.DebtsTax] =
FinancialAccount.Create(this, "Taxes Due", FinancialAccountType.Debt, null);
FinancialAccounts[OrganizationFinancialAccountType.DebtsVatOutbound] =
FinancialAccount.Create(this, "Outbound Value Added Tax", FinancialAccountType.Debt, null);
//FinancialAccounts[OrganizationFinancialAccountType.DebtsVatOutbound] =
// FinancialAccount.Create(this, "Outbound Value Added Tax", FinancialAccountType.Debt, null);
FinancialAccounts[OrganizationFinancialAccountType.IncomeDonations] =
FinancialAccount.Create(this, "Donations", FinancialAccountType.Income, null);
+67 -7
View File
@@ -11,14 +11,74 @@
$('.EditCheck').switchbutton({
checkedLabel: '<%=Resources.Global.Global_On.ToUpperInvariant() %>',
uncheckedLabel: '<%=Resources.Global.Global_Off.ToUpperInvariant() %>',
}).change(function() {
}).change(function () {
if (suppressSwitchResponse) {
return;
}
$('#divUseAccountPlan').slideDown().fadeIn();
var jsonData = {};
jsonData.switchName = $(this).attr("rel");
jsonData.switchValue = $(this).prop('checked');
$.ajax({
type: "POST",
url: "EditOrganization.aspx/SwitchToggled",
data: $.toJSON(jsonData),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg.d.Success) {
alertify.log(msg.d.DisplayMessage);
} else {
// do nothing
}
},
error: function (msg) {
// TODO: Reset switch, protest server unreachable
}
});
});
// Ask for initial data
$.ajax({
type: "POST",
url: "EditOrganization.aspx/GetInitialData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
initializeSettings(msg.d);
},
error: function (msg) {
// TODO: try again? bail out?
alert("The server did not respond with the organization's current settings.");
}
});
});
function initializeSettings(orgSettings) {
console.log(orgSettings);
suppressSwitchResponse = true;
$("#CheckEnableBitcoinCold").prop("checked", orgSettings.AccountBitcoinCold).change();
$("#CheckEnableBitcoinHot").prop("checked", orgSettings.AccountBitcoinHot).change();
$("#CheckEnablePaypal").prop("checked", orgSettings.AccountPaypal).change();
$("#CheckEnableForex").prop("checked", orgSettings.AccountsForex).change();
$("#CheckEnableVat").prop("checked", orgSettings.AccountsVat).change();
suppressSwitchResponse = false;
}
var suppressSwitchResponse = false;
</script>
<style>
<style type="text/css">
.IconEdit {
cursor: pointer;
}
@@ -38,12 +98,12 @@
<div title="<img src='/Images/Icons/iconshock-switch-red-64px.png' />">
<h2>Accounting Features</h2>
<div class="entryFields">
<label for="CheckAccountBitcoinCold"><asp:Literal ID="LiteralLabelBitcoinColdShort" runat="server" Text="Bitcoin Cold"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Active" class="EditCheck" id="CheckEnableBitcoinCold"/></div><br/>
<label for="CheckAccountBitcoinHot"><asp:Literal ID="LiteralLabelBitcoinHotShort" runat="server" Text="Bitcoin Hot"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Active" class="EditCheck" id="CheckboxEnableBitcoinHot"/></div><br/>
<label for="CheckEnableBitcoinCold"><asp:Literal ID="LiteralLabelBitcoinColdShort" runat="server" Text="Bitcoin Cold"/></label><div class="CheckboxContainer"><input type="checkbox" rel="BitcoinCold" class="EditCheck" id="CheckEnableBitcoinCold"/></div><br/>
<label for="CheckEnableBitcoinHot"><asp:Literal ID="LiteralLabelBitcoinHotShort" runat="server" Text="Bitcoin Hot"/></label><div class="CheckboxContainer"><input type="checkbox" rel="BitcoinHot" class="EditCheck" id="CheckEnableBitcoinHot"/></div><br/>
<asp:TextBox runat="server" ID="TextDaysCashReserves" CssClass="alignRight" Text="60-90" />&#8203;<br/>
<label for="CheckAccountPaypal"><asp:Literal ID="Literal1" runat="server" Text="Paypal"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Active" class="EditCheck" id="CheckboxEnablePaypal"/></div><br/>
<label for="CheckAccountForeign"><asp:Literal ID="Literal2" runat="server" Text="Forex Profit/Loss"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Active" class="EditCheck" id="CheckboxEnableForeignProfitLoss"/></div><br/>
<label for="CheckAccountVat"><asp:Literal ID="Literal3" runat="server" Text="VAT In/Out"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Active" class="EditCheck" id="CheckboxEnableVat"/></div><br/>
<label for="CheckEnablePaypal"><asp:Literal ID="Literal1" runat="server" Text="Paypal"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Paypal" class="EditCheck" id="CheckEnablePaypal"/></div><br/>
<label for="CheckEnableForex"><asp:Literal ID="Literal2" runat="server" Text="Forex Profit/Loss"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Forex" class="EditCheck" id="CheckEnableForex"/></div><br/>
<label for="CheckEnableVat"><asp:Literal ID="Literal3" runat="server" Text="VAT In/Out"/></label><div class="CheckboxContainer"><input type="checkbox" rel="Vat" class="EditCheck" id="CheckEnableVat"/></div><br/>
</div>
<div class="entryLabels">
Enable bitcoin coldwallet tracking?<br/>
+240 -4
View File
@@ -5,7 +5,10 @@ using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Basic.Enums;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
namespace Swarmops.Frontend.Pages.v5.Admin
{
@@ -26,7 +29,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin
this.EasyUIControlsUsed = EasyUIControl.Tabs;
this.IncludedControlsUsed = IncludedControl.FileUpload | IncludedControl.SwitchButton;
this.IncludedControlsUsed = IncludedControl.FileUpload | IncludedControl.SwitchButton | IncludedControl.JsonParameters;
}
private void Localize()
@@ -96,11 +99,234 @@ namespace Swarmops.Frontend.Pages.v5.Admin
}
[WebMethod]
public static CallResult FlickSwitch(string switchName, bool switchOn)
public static InitialOrgData GetInitialData()
{
// TODO
InitialOrgData result = new InitialOrgData();
AuthenticationData authData = GetAuthenticationDataAndCulture();
Organization org = authData.CurrentOrganization;
return new CallResult();
if (org == null || authData.CurrentUser == null)
{
return result; // just... don't
}
result.AccountBitcoinCold = (org.FinancialAccounts.AssetsBitcoinCold != null);
result.AccountBitcoinHot = (org.FinancialAccounts.AssetsBitcoinHot != null);
result.AccountPaypal = (org.FinancialAccounts.AssetsPaypal != null);
result.AccountsForex = (org.FinancialAccounts.IncomeCurrencyFluctuations != null);
result.AccountsVat = (org.FinancialAccounts.AssetsVatInbound != null);
// TODO: Add all the other fields
return result;
}
[WebMethod]
public static CallResult SwitchToggled(string switchName, bool switchValue)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
if (authData.CurrentOrganization == null || authData.CurrentUser == null)
{
return null; // just don't... don't anything, actually
}
CallResult result = new CallResult();
result.Success = true;
FinancialAccounts workAccounts = new FinancialAccounts();
switch (switchName)
{
case "BitcoinCold":
FinancialAccount coldAccount = authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold;
if (coldAccount == null)
{
coldAccount = FinancialAccount.Create(authData.CurrentOrganization, "Bitcoin Assets Cold",
FinancialAccountType.Asset, null);
FinancialAccount.Create(authData.CurrentOrganization, "Cold Address 1",
FinancialAccountType.Asset, coldAccount);
FinancialAccount.Create(authData.CurrentOrganization, "Cold Address 2 (rename these)",
FinancialAccountType.Asset, coldAccount);
FinancialAccount.Create(authData.CurrentOrganization, "Cold Address... etc",
FinancialAccountType.Asset, coldAccount);
authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold = coldAccount;
result.DisplayMessage =
"Bitcoin cold accounts were created. Edit names and addresses in Account Plan."; // LOC
}
else
{
workAccounts.Add(coldAccount);
}
break;
case "BitcoinHot":
FinancialAccount hotAccount = authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot;
if (hotAccount == null)
{
authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot =
FinancialAccount.Create(authData.CurrentOrganization, "Bitcoin Wallet Hot",
FinancialAccountType.Asset, null);
result.DisplayMessage =
"Bitcoin hotwallet account was created. Upload its wallet file in Account Plan.";
}
else
{
workAccounts.Add(hotAccount);
}
break;
case "Forex":
FinancialAccount forexGain =
authData.CurrentOrganization.FinancialAccounts.IncomeCurrencyFluctuations;
FinancialAccount forexLoss =
authData.CurrentOrganization.FinancialAccounts.CostsCurrencyFluctuations;
if (forexGain == null)
{
if (forexLoss != null)
{
throw new InvalidOperationException();
}
authData.CurrentOrganization.FinancialAccounts.IncomeCurrencyFluctuations = FinancialAccount.Create(authData.CurrentOrganization, "Forex holding gains",
FinancialAccountType.Income, null);
authData.CurrentOrganization.FinancialAccounts.CostsCurrencyFluctuations = FinancialAccount.Create(authData.CurrentOrganization, "Forex holding losses",
FinancialAccountType.Cost, null);
result.DisplayMessage =
"Forex gain/loss accounts were created and will be used to account for currency fluctuations.";
}
else
{
if (forexLoss == null)
{
throw new InvalidOperationException();
}
workAccounts.Add(forexGain);
workAccounts.Add(forexLoss);
}
break;
case "Vat":
FinancialAccount vatInbound = authData.CurrentOrganization.FinancialAccounts.AssetsVatInbound;
FinancialAccount vatOutbound = authData.CurrentOrganization.FinancialAccounts.DebtsVatOutbound;
if (vatInbound == null)
{
if (vatOutbound != null)
{
throw new InvalidOperationException();
}
authData.CurrentOrganization.FinancialAccounts.AssetsVatInbound = FinancialAccount.Create(authData.CurrentOrganization, "Inbound VAT",
FinancialAccountType.Asset, null);
authData.CurrentOrganization.FinancialAccounts.DebtsVatOutbound = FinancialAccount.Create(authData.CurrentOrganization, "Outbound VAT",
FinancialAccountType.Debt, null);
result.DisplayMessage = "Inbound and outbound VAT accounts were created.";
}
else
{
if (vatOutbound == null)
{
throw new InvalidOperationException();
}
workAccounts.Add(vatInbound);
workAccounts.Add(vatOutbound);
}
break;
case "Paypal":
FinancialAccount assetsPaypal = authData.CurrentOrganization.FinancialAccounts.AssetsPaypal;
if (assetsPaypal == null)
{
authData.CurrentOrganization.FinancialAccounts.AssetsPaypal =
FinancialAccount.Create(authData.CurrentOrganization, "Paypal account",
FinancialAccountType.Asset, null);
result.DisplayMessage = "An account was created for Paypal account tracking.";
}
else
{
workAccounts.Add(assetsPaypal);
}
break;
default:
throw new NotImplementedException();
}
if (workAccounts.Count > 0 && String.IsNullOrEmpty(result.DisplayMessage))
{
if (switchValue) // switch has been turned on
{
// accounts can always be re-enabled. This is not a create, it is a re-enable.
foreach (FinancialAccount account in workAccounts)
{
account.Active = true;
}
if (workAccounts.Count > 1)
{
result.DisplayMessage = "The accounts were re-enabled.";
}
else
{
result.DisplayMessage = "The account was re-enabled.";
}
}
else // switch is being set to off position
{
// if the accounts are currently enabled, we must first check there aren't
// any transactions in them before disabling
bool transactionsOnAccount = false;
foreach (FinancialAccount account in workAccounts)
{
if (account.GetLastRows(5).Count > 0)
{
transactionsOnAccount = true;
}
}
if (transactionsOnAccount)
{
if (workAccounts.Count > 1)
{
result.DisplayMessage = "Can't disable these accounts: there are transactions";
}
else
{
result.DisplayMessage = "Can't disable this account: there are transactions";
}
result.Success = false;
}
else
{
// Disable accounts
foreach (FinancialAccount account in workAccounts)
{
account.Active = false;
}
if (workAccounts.Count > 1)
{
result.DisplayMessage = "The accounts were disabled.";
}
else
{
result.DisplayMessage = "The account was disabled.";
}
}
}
}
return result;
}
@@ -111,6 +337,16 @@ namespace Swarmops.Frontend.Pages.v5.Admin
public string DisplayMessage { get; set; }
public string RequiredOn { get; set; }
}
public class InitialOrgData
{
public bool AccountsVat;
public bool AccountPaypal;
public bool AccountBitcoinCold;
public bool AccountsForex;
public bool AccountBitcoinHot;
}
}
}