Beispiel #1
0
    private FinancialAccounts GetRootLevelResultAccounts()
    {
        Organization org = this.CurrentOrganization;

        if (org == null && Page.IsPostBack)
        {
            // If we're being called from Page_Init to create controls just to catch events, then this.CurrentOrganization won't be set.
            // We need to create it temporarily from a hidden field:

            org = Organization.FromIdentity(Int32.Parse(Request["ctl00$PlaceHolderMain$HiddenInitOrganizationId"]));
        }

        FinancialAccount  yearlyResult = org.FinancialAccounts.CostsYearlyResult;
        FinancialAccounts allAccounts  = FinancialAccounts.ForOrganization(org, FinancialAccountType.Result);

        // Select root accounts

        FinancialAccounts accounts = new FinancialAccounts();

        foreach (FinancialAccount account in allAccounts)
        {
            if (account.ParentFinancialAccountId == 0 && account.Identity != yearlyResult.Identity)
            {
                accounts.Add(account);
            }
        }

        return(accounts);
    }
    protected void PopulateGrid()
    {
        FinancialAccounts      allAccounts     = FinancialAccounts.ForOrganization(Organization.PPSE);
        Dictionary <int, bool> accountIsParent = new Dictionary <int, bool>();

        FinancialAccounts resultAccounts = new FinancialAccounts();

        foreach (FinancialAccount account in allAccounts)
        {
            if (account.AccountType == FinancialAccountType.Income ||
                account.AccountType == FinancialAccountType.Cost)
            {
                resultAccounts.Add(account);

                if (account.ParentIdentity != 0)
                {
                }
            }
        }

        // Add expansion headers


        this.GridBudgetAccounts.DataSource = resultAccounts;

        PopulateLookups(resultAccounts);
    }
Beispiel #3
0
    protected void PopulateGrid()
    {
        FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE);

        FinancialAccounts volatileAccounts = new FinancialAccounts();

        foreach (FinancialAccount account in allAccounts)
        {
            if (account.AccountType == FinancialAccountType.Cost ||
                account.AccountType == FinancialAccountType.Income)
            {
                volatileAccounts.Add(account);
            }
        }

        this.GridBudgetAccounts.DataSource = volatileAccounts;

        PopulateLookups(volatileAccounts);
    }
Beispiel #4
0
    protected void PopulateGrid()
    {
        FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE);

        FinancialAccounts balanceAccounts = new FinancialAccounts();

        foreach (FinancialAccount account in allAccounts)
        {
            if (account.AccountType == FinancialAccountType.Asset ||
                account.AccountType == FinancialAccountType.Debt)
            {
                balanceAccounts.Add(account);
            }
        }

        // Add main headers

        this.GridBudgetAccounts.DataSource = balanceAccounts;

        PopulateLookups(balanceAccounts);
    }
    private void PopulateLedger()
    {
        FinancialAccounts accounts = new FinancialAccounts();

        if (this.RadioAllAccounts.Checked)
        {
            accounts =
                FinancialAccounts.ForOrganization(
                    Organization.FromIdentity(Int32.Parse(this.DropOrganizations.SelectedValue)));
        }
        else if (this.RadioAccountGroup.Checked)
        {
            accounts =
                FinancialAccounts.ForOrganization(
                    Organization.FromIdentity(Int32.Parse(this.DropOrganizations.SelectedValue)), (FinancialAccountType)Int32.Parse(this.DropAccountGroups.SelectedValue));
        }
        else if (this.RadioSpecificAccount.Checked)
        {
            accounts.Add(this.DropAccounts.SelectedFinancialAccount);
        }

        Ledger.Accounts = accounts;

        Ledger.DateStart = (DateTime)this.DateStart.SelectedDate;
        Ledger.DateEnd   = (DateTime)this.DateEnd.SelectedDate;

        Ledger.MaxAmount = 1.0e12m; // catches all transactions -- if not, PW is kind of outscaled

        if (this.RadioCreditingTransactions.Checked)
        {
            Ledger.MaxAmount = 0.0m;
        }
        else if (this.RadioCreditingTransactionsLarge.Checked)
        {
            Ledger.MaxAmount = -1000.0m;
        }

        Ledger.Populate();
    }
Beispiel #6
0
        public static AjaxInputCallResult SwitchToggled(string cookie, bool newValue)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            if (authData.CurrentOrganization == null || authData.CurrentUser == null)
            {
                return(null); // just don't... don't anything, actually
            }

            AjaxInputCallResult result = new AjaxInputCallResult();

            result.Success  = true;
            result.NewValue = newValue? "true": "false";

            bool bitcoinNative = (authData.CurrentOrganization.Currency.Code == "BTC");

            FinancialAccounts workAccounts = new FinancialAccounts();

            switch (cookie)
            {
            case "BitcoinCold":

                FinancialAccount coldAccount = authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold;
                if (coldAccount == null)
                {
                    coldAccount = FinancialAccount.Create(authData.CurrentOrganization, "[LOC]Asset_BitcoinCold",
                                                          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 Connected Accounts.";     // 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, "[LOC]Asset_BitcoinHot",
                                                FinancialAccountType.Asset, null);

                    result.DisplayMessage =
                        "Bitcoin HD hotwallet was created along with an account for the hotwallet.";
                }
                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, "[LOC]Income_ForexGains",
                                                FinancialAccountType.Income, null);
                    authData.CurrentOrganization.FinancialAccounts.CostsCurrencyFluctuations =
                        FinancialAccount.Create(authData.CurrentOrganization, "[LOC]Cost_ForexLosses",
                                                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();
                    }

                    if (!bitcoinNative && newValue == false &&
                        ((authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold != null &&
                          authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold.Active) ||
                         (authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot != null &&
                          authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.Active)))
                    {
                        // bitcoin is active, and we're not bitcoin native, so we're not turning off forex

                        result.Success        = false;
                        result.NewValue       = "true";
                        result.DisplayMessage =
                            "Cannot disable forex: bitcoin accounts are active in a non-bitcoin-native organization.";
                    }
                    else
                    {
                        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, "[LOC]Asset_InboundVat",
                                                FinancialAccountType.Asset, null);
                    authData.CurrentOrganization.FinancialAccounts.DebtsVatOutbound =
                        FinancialAccount.Create(authData.CurrentOrganization, "[LOC]Debt_OutboundVat",
                                                FinancialAccountType.Debt, null);

                    result.DisplayMessage = "Inbound and outbound VAT accounts were created.";
                }
                else
                {
                    if (vatOutbound == null)
                    {
                        throw new InvalidOperationException();
                    }

                    // If the VAT Inbound/Outbound already exist, but subaccounts don't:

                    if (authData.CurrentOrganization.FinancialAccounts.AssetsVatInboundUnreported == null)
                    {
                        // create unreported/reported VAT inbound/outbound - four accounts total

                        authData.CurrentOrganization.FinancialAccounts.AssetsVatInboundUnreported =
                            FinancialAccount.Create(authData.CurrentOrganization, "[LOC]Asset_InboundVatUnreported",
                                                    FinancialAccountType.Asset,
                                                    authData.CurrentOrganization.FinancialAccounts.AssetsVatInbound);
                        authData.CurrentOrganization.FinancialAccounts.DebtsVatOutboundUnreported =
                            FinancialAccount.Create(authData.CurrentOrganization, "[LOC]Debt_OutboundVatUnreported",
                                                    FinancialAccountType.Debt,
                                                    authData.CurrentOrganization.FinancialAccounts.DebtsVatOutbound);

                        authData.CurrentOrganization.FinancialAccounts.AssetsVatInboundReported =
                            FinancialAccount.Create(authData.CurrentOrganization, "[LOC]Asset_InboundVatReported",
                                                    FinancialAccountType.Asset,
                                                    authData.CurrentOrganization.FinancialAccounts.AssetsVatInbound);
                        authData.CurrentOrganization.FinancialAccounts.DebtsVatOutboundReported =
                            FinancialAccount.Create(authData.CurrentOrganization, "[LOC]Debt_OutboundVatReported",
                                                    FinancialAccountType.Debt,
                                                    authData.CurrentOrganization.FinancialAccounts.DebtsVatOutbound);
                    }
                    else     // the accounts exist, need to be re-enabled or disabled, as per the switch direction
                    {
                        workAccounts.Add(authData.CurrentOrganization.FinancialAccounts.AssetsVatInboundReported);
                        workAccounts.Add(authData.CurrentOrganization.FinancialAccounts.AssetsVatInboundUnreported);
                        workAccounts.Add(authData.CurrentOrganization.FinancialAccounts.DebtsVatOutboundReported);
                        workAccounts.Add(authData.CurrentOrganization.FinancialAccounts.DebtsVatOutboundUnreported);
                    }

                    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, "[LOC]Asset_Paypal",
                                                FinancialAccountType.Asset, null);

                    result.DisplayMessage = "An account was created for Paypal account tracking.";
                }
                else
                {
                    workAccounts.Add(assetsPaypal);
                }
                break;

            case "ParticipantFinancials":
                authData.CurrentOrganization.ParticipantFinancialsEnabled = newValue;
                break;

            case "AskPartipantStreet":
                authData.CurrentOrganization.Parameters.AskParticipantStreet = newValue;
                break;

            default:
                throw new NotImplementedException();
            }

            if (workAccounts.Count > 0 && String.IsNullOrEmpty(result.DisplayMessage))
            {
                if (newValue) // 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;
                        result.NewValue = "true";
                    }
                    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);
        }
    protected void PopulateGrid ()
    {
        FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE);

        FinancialAccounts balanceAccounts = new FinancialAccounts();
        foreach (FinancialAccount account in allAccounts)
        {
            if (account.AccountType == FinancialAccountType.Asset ||
                account.AccountType == FinancialAccountType.Debt)
            {
                balanceAccounts.Add(account);
            }
        }

        // Add main headers

        this.GridBudgetAccounts.DataSource = balanceAccounts;

        PopulateLookups(balanceAccounts);
    }
    private void PopulateLedger()
    {
        FinancialAccounts accounts = new FinancialAccounts();

        if (this.RadioAllAccounts.Checked)
        {
            accounts =
                FinancialAccounts.ForOrganization(
                    Organization.FromIdentity(Int32.Parse(this.DropOrganizations.SelectedValue)));
        }
        else if (this.RadioAccountGroup.Checked)
        {
            accounts =
                FinancialAccounts.ForOrganization(
                    Organization.FromIdentity(Int32.Parse(this.DropOrganizations.SelectedValue)), (FinancialAccountType) Int32.Parse(this.DropAccountGroups.SelectedValue));
        }
        else if (this.RadioSpecificAccount.Checked)
        {
            accounts.Add(this.DropAccounts.SelectedFinancialAccount);
        }

        Ledger.Accounts = accounts;

        Ledger.DateStart = (DateTime)this.DateStart.SelectedDate;
        Ledger.DateEnd = (DateTime)this.DateEnd.SelectedDate;

        Ledger.MaxAmount = 1.0e12m; // catches all transactions -- if not, PW is kind of outscaled

        if (this.RadioCreditingTransactions.Checked)
        {
            Ledger.MaxAmount = 0.0m;
        }
        else if (this.RadioCreditingTransactionsLarge.Checked)
        {
            Ledger.MaxAmount = -1000.0m;
        }

        Ledger.Populate();
    }
Beispiel #9
0
        private void PopulateOrderedList(FinancialAccounts orderedList, int renderNodeId)
        {
            foreach (FinancialAccount account in _treeMap[renderNodeId])
            {
                orderedList.Add(account);

                if (_treeMap.ContainsKey(account.Identity))
                {
                    PopulateOrderedList(orderedList, account.Identity); // recursive call
                }
            }
        }
Beispiel #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FinancialAccounts allOwned = new FinancialAccounts();

            Memberships memberships = this.person.GetMemberships();

            int orgOwned = 0;
            bool multipleOrgs = false;

            foreach (Membership membership in memberships)
            {
                FinancialAccounts orgAccounts = FinancialAccounts.ForOrganization(membership.Organization);
                foreach (FinancialAccount account in orgAccounts)
                {
                    if (account.OwnerPersonId == this.person.Identity)
                    {
                        allOwned.Add(account);

                        if (orgOwned == 0 || orgOwned == membership.OrganizationId)
                        {
                            orgOwned = membership.OrganizationId;
                        }
                        else
                        {
                            multipleOrgs = true;
                        }
                    }
                }
            }

            if (allOwned.Count > 0)
            {

                string literal =
                    "<span style=\"line-height:150%\"><table border=\"0\" cellspacing=\"0\" width=\"100%\">";

                int year = DateTime.Today.Year;
                DateTime now = DateTime.Now;
                DateTime jan1 = new DateTime(year, 1, 1);
                bool budgetFound = false;

                foreach (FinancialAccount account in allOwned)
                {
                    double budget = -account.GetBudget(year);
                    decimal spent = account.GetDelta(jan1, now);
                    decimal remaining = (decimal) budget - spent;

                    if (budget == 0.0 && spent == 0.0m)
                    {
                        continue; // not interesting
                    }

                    budgetFound = true;
                    literal += "<tr><td>";

                    if (multipleOrgs)
                    {
                        literal += Server.HtmlEncode(account.Organization.NameShort) + " - ";
                    }

                    literal += "<a href=\"/Pages/v4/Financial/ManageBudget.aspx?AccountId=" + account.Identity + "\">" + Server.HtmlEncode(account.Name) + "</a>&nbsp;</td><td align=\"right\">";

                    literal += Server.HtmlEncode(remaining.ToString("N2"));

                    literal += "</td><td>&nbsp;of&nbsp;</td><td align=\"right\">";

                    literal += Server.HtmlEncode(budget.ToString("N2"));

                    literal += "</td><td align=\"right\">&nbsp;(";

                    if (budget != 0.0)
                    {
                        literal += (remaining/(decimal) budget).ToString("P0");
                    }
                    else
                    {
                        literal += "--%";
                    }

                    literal += " left)</td><tr>\r\n";

                }

                if (!budgetFound)
                {
                    literal += "<tr><td>No budget allocated to you (yet?) for " + year.ToString() + ".</td></tr>\r\n";
                }

                literal +=
                    "<tr><td>&nbsp;</td></tr><tr><td colspan=\"5\" align=\"right\"><a href=\"/Pages/v4/Financial/AllocateFunds.aspx\">Allocate funds...</a></td></tr>\r\n";

                literal += "</table></span>";

                this.LiteralBudgetData.Text = literal;
            }
            else
            {
                this.LiteralBudgetData.Text = "You own no budgets.";
            }
        }
Beispiel #11
0
    protected void PopulateGrid ()
    {
        FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE);

        FinancialAccounts volatileAccounts = new FinancialAccounts();
        foreach (FinancialAccount account in allAccounts)
        {
            if (account.AccountType == FinancialAccountType.Cost ||
                account.AccountType == FinancialAccountType.Income)
            {
                volatileAccounts.Add(account);
            }
        }

        this.GridBudgetAccounts.DataSource = volatileAccounts;

        PopulateLookups(volatileAccounts);
    }
    private FinancialAccounts GetRootLevelResultAccounts()
    {
        Organization org = this.CurrentOrganization;

        if (org == null && Page.IsPostBack)
        {
            // If we're being called from Page_Init to create controls just to catch events, then this.CurrentOrganization won't be set.
            // We need to create it temporarily from a hidden field:

            org = Organization.FromIdentity(Int32.Parse(Request["ctl00$PlaceHolderMain$HiddenInitOrganizationId"]));
        }

        FinancialAccount yearlyResult = org.FinancialAccounts.CostsYearlyResult;
        FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(org, FinancialAccountType.Result);

        // Select root accounts

        FinancialAccounts accounts = new FinancialAccounts();

        foreach (FinancialAccount account in allAccounts)
        {
            if (account.ParentFinancialAccountId == 0 && account.Identity != yearlyResult.Identity)
            {
                accounts.Add(account);
            }
        }

        return accounts;
    }
        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;

            bool bitcoinNative = (authData.CurrentOrganization.Currency.Code == "BTC");

            FinancialAccounts workAccounts = new FinancialAccounts();

            switch (switchName)
            {
            case "BitcoinCold":

                if (switchValue && !bitcoinNative)
                {
                    result.RequireForex = true;
                }

                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":
                if (switchValue && !bitcoinNative)
                {
                    result.RequireForex = true;
                }

                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();
                    }

                    if (!bitcoinNative && switchValue == false &&
                        ((authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold != null &&
                          authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinCold.Active) ||
                         (authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot != null &&
                          authData.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.Active)))
                    {
                        // bitcoin is active, and we're not bitcoin native, so we're not turning off forex

                        result.Success        = false;
                        result.DisplayMessage =
                            "Cannot disable forex: bitcoin accounts are active in a non-bitcoin-native organization.";
                        result.RequireForex = true;
                    }
                    else
                    {
                        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);
        }
    protected void PopulateGrid ()
    {
        FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE);
        Dictionary<int, bool> accountIsParent = new Dictionary<int, bool>();

        FinancialAccounts resultAccounts = new FinancialAccounts();
        foreach (FinancialAccount account in allAccounts)
        {
            if (account.AccountType == FinancialAccountType.Income ||
                account.AccountType == FinancialAccountType.Cost)
            {
                resultAccounts.Add(account);

                if (account.ParentIdentity != 0)
                {
                    
                }
            }
        }

        // Add expansion headers


        this.GridBudgetAccounts.DataSource = resultAccounts;

        PopulateLookups(resultAccounts);
    }
Beispiel #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            FinancialAccounts allOwned = new FinancialAccounts();

            Memberships memberships = this.person.GetMemberships();

            int  orgOwned     = 0;
            bool multipleOrgs = false;

            foreach (Membership membership in memberships)
            {
                FinancialAccounts orgAccounts = FinancialAccounts.ForOrganization(membership.Organization);
                foreach (FinancialAccount account in orgAccounts)
                {
                    if (account.OwnerPersonId == this.person.Identity)
                    {
                        allOwned.Add(account);

                        if (orgOwned == 0 || orgOwned == membership.OrganizationId)
                        {
                            orgOwned = membership.OrganizationId;
                        }
                        else
                        {
                            multipleOrgs = true;
                        }
                    }
                }
            }

            if (allOwned.Count > 0)
            {
                string literal =
                    "<span style=\"line-height:150%\"><table border=\"0\" cellspacing=\"0\" width=\"100%\">";

                int      year        = DateTime.Today.Year;
                DateTime now         = DateTime.Now;
                DateTime jan1        = new DateTime(year, 1, 1);
                bool     budgetFound = false;

                foreach (FinancialAccount account in allOwned)
                {
                    double  budget    = -account.GetBudget(year);
                    decimal spent     = account.GetDelta(jan1, now);
                    decimal remaining = (decimal)budget - spent;

                    if (budget == 0.0 && spent == 0.0m)
                    {
                        continue; // not interesting
                    }

                    budgetFound = true;
                    literal    += "<tr><td>";

                    if (multipleOrgs)
                    {
                        literal += Server.HtmlEncode(account.Organization.NameShort) + " - ";
                    }

                    literal += "<a href=\"/Pages/v4/Financial/ManageBudget.aspx?AccountId=" + account.Identity + "\">" + Server.HtmlEncode(account.Name) + "</a>&nbsp;</td><td align=\"right\">";

                    literal += Server.HtmlEncode(remaining.ToString("N2"));

                    literal += "</td><td>&nbsp;of&nbsp;</td><td align=\"right\">";

                    literal += Server.HtmlEncode(budget.ToString("N2"));

                    literal += "</td><td align=\"right\">&nbsp;(";

                    if (budget != 0.0)
                    {
                        literal += (remaining / (decimal)budget).ToString("P0");
                    }
                    else
                    {
                        literal += "--%";
                    }

                    literal += " left)</td><tr>\r\n";
                }

                if (!budgetFound)
                {
                    literal += "<tr><td>No budget allocated to you (yet?) for " + year.ToString() + ".</td></tr>\r\n";
                }

                literal +=
                    "<tr><td>&nbsp;</td></tr><tr><td colspan=\"5\" align=\"right\"><a href=\"/Pages/v4/Financial/AllocateFunds.aspx\">Allocate funds...</a></td></tr>\r\n";

                literal += "</table></span>";

                this.LiteralBudgetData.Text = literal;
            }
            else
            {
                this.LiteralBudgetData.Text = "You own no budgets.";
            }
        }