コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get account

        int financialAccountId = Int32.Parse(Request.QueryString["FinancialAccountId"]);

        _account = FinancialAccount.FromIdentity(financialAccountId);
        int year = DateTime.Today.Year;

        if (!_authority.HasPermission(Permission.CanDoBudget, _account.OrganizationId, -1, Authorization.Flag.ExactOrganization))
        {
            throw new UnauthorizedAccessException("Access Denied");
        }

        this.ComboOwner.Authority = _authority;


        if (!Page.IsPostBack)
        {
            // Populate all data

            this.LabelBudgetYear.Text   = year.ToString();
            this.LabelAccount.Text      = _account.Name;
            this.LabelOrganization.Text = _account.Organization.Name;
            this.TextBudget.Text        = _account.GetBudget(year).ToString(CultureInfo.InvariantCulture);

            if (_account.Owner != null)
            {
                this.ComboOwner.Text = _account.Owner.Name + " (#" + _account.Owner.Identity.ToString() + ")";
            }
        }

        // Page.Title = "Editing Budget: " + _account.Name + ", " + year.ToString();
    }
コード例 #2
0
    protected void Page_Load (object sender, EventArgs e)
    {
        // Get account

        int financialAccountId = Int32.Parse(Request.QueryString["FinancialAccountId"]);
        _account = FinancialAccount.FromIdentity(financialAccountId);
        int year = DateTime.Today.Year;

        if (!_authority.HasPermission(Permission.CanDoBudget, _account.OrganizationId, -1, Authorization.Flag.ExactOrganization))
        {
            throw new UnauthorizedAccessException("Access Denied");
        }

        this.ComboOwner.Authority = _authority;


        if (!Page.IsPostBack)
        {
            // Populate all data

            this.LabelBudgetYear.Text = year.ToString();
            this.LabelAccount.Text = _account.Name;
            this.LabelOrganization.Text = _account.Organization.Name;
            this.TextBudget.Text = _account.GetBudget(year).ToString(CultureInfo.InvariantCulture);

            if (_account.Owner != null)
            {
                this.ComboOwner.Text = _account.Owner.Name + " (#" + _account.Owner.Identity.ToString() + ")";
            }
        }

        // Page.Title = "Editing Budget: " + _account.Name + ", " + year.ToString();
    }
コード例 #3
0
        private BudgetData GetBudgetData(int budgetId, int year)
        {
            FinancialAccount account     = FinancialAccount.FromIdentity(budgetId);
            double           budget      = -account.GetBudget(year);
            Int64            actualCents = account.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1));
            double           actual      = actualCents / 100.0;

            // Get suballocated

            FinancialAccounts accountTree = account.GetTree();

            double budgetTotal     = -accountTree.GetBudgetSum(year);
            Int64  deltaTotalCents = accountTree.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1));
            double deltaTotal      = deltaTotalCents / 100.0;

            BudgetData result = new BudgetData();

            result.AccountName = account.Name;

            if (budgetTotal > 0.0)
            {
                result.PercentActual           = actual / budgetTotal * 100.0;
                result.PercentSuballocated     = (budgetTotal - budget) / budgetTotal * 100.0;
                result.PercentSuballocatedUsed = (deltaTotal - actual) / budgetTotal * 100.0;
            }

            return(result);
        }
コード例 #4
0
    private string ProcessTransferSubBudget()
    {
        int year = DateTime.Today.Year;
        FinancialAccount fromAccount = FinancialAccount.FromIdentity(Int32.Parse(this.DropBudgets.SelectedValue));
        FinancialAccount toAccount   = this.DropSubBudget.SelectedFinancialAccount;
        double           amount      = Double.Parse(this.TextAmount.Text, NumberStyles.Float, new CultureInfo("sv-SE"));
        string           description = this.TextDescription.Text;

        // Transfer the budget

        fromAccount.SetBudget(year, fromAccount.GetBudget(year) + amount); // budgets are negative -- this decreases the budget
        toAccount.SetBudget(year, toAccount.GetBudget(year) - amount);     // budgets are negative -- this increases the budget

        // Set result

        return(amount.ToString("N2") + " was transferred from " + fromAccount.Name + " to " + toAccount.Name + ".");
    }
コード例 #5
0
    private string ProcessCreateSubBudget()
    {
        int year = DateTime.Today.Year;

        FinancialAccount parentAccount = FinancialAccount.FromIdentity(Int32.Parse(this.DropBudgets.SelectedValue));
        string           budgetName    = this.TextDescription.Text;
        Person           owner         = this.ComboBudgetPerson.SelectedPerson;
        double           currentBudget = parentAccount.GetBudget(year);
        double           amount        = Double.Parse(this.TextAmount.Text, NumberStyles.Float, new CultureInfo("sv-SE"));

        FinancialAccount account = FinancialAccount.Create(Organization.PPSEid, budgetName, FinancialAccountType.Cost,
                                                           parentAccount.Identity);

        account.Owner = owner;
        account.SetBudget(year, -amount);                      // cost accounts have a negative budget
        parentAccount.SetBudget(year, currentBudget + amount); // cost accounts have a negative budget -- this will LOWER the budget

        return("The budget " + budgetName + " was created, owned by " + owner.Canonical +
               " and with an initial budget for " + year.ToString() + " of " +
               amount.ToString("N2") + ". Do not forget to instruct " + (owner.IsFemale? "her" : "him") +
               " on the duties associated, such as attesting expenses, etc.");
    }
コード例 #6
0
    protected void ButtonReallocate_Click(object sender, EventArgs e)
    {
        FinancialAccounts children = _account.Children;

        double deltaTotal = 0.0;
        int    budgetAttempt;
        int    budgetTotal = 0;

        // In a first round, verify that all numbers are parsable

        foreach (RepeaterItem repeaterItem in this.RepeaterBudgetTextBoxes.Items)
        {
            HiddenField      hiddenAccountId = (HiddenField)repeaterItem.FindControl("HiddenAccountId");
            FinancialAccount child           = FinancialAccount.FromIdentity(Int32.Parse(hiddenAccountId.Value));

            TextBox box     = (TextBox)repeaterItem.FindControl("TextChildBudget");
            string  boxText = box.Text;
            if (!Int32.TryParse(boxText, NumberStyles.Number, new CultureInfo("sv-SE"), out budgetAttempt))
            {
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "error",
                                                    "alert('The budget for the account \"" + Server.HtmlEncode(child.Name).Replace("'", "''") + "\" does not appear to be a valid number. Please correct this and try again.');",
                                                    true);
                return;
            }

            budgetTotal += budgetAttempt;
        }

        // Verify that the budget is not overrun by suballocations

        if (Math.Abs(budgetTotal) > Math.Abs(_account.GetTree().GetBudgetSum(_year)))
        {
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "error",
                                                "alert('You are trying to overallocate the budget. Please correct this and try again.');",
                                                true);
            return;
        }

        // Then, move on to actually mod the budgets

        foreach (RepeaterItem repeaterItem in this.RepeaterBudgetTextBoxes.Items)
        {
            HiddenField      hiddenAccountId = (HiddenField)repeaterItem.FindControl("HiddenAccountId");
            FinancialAccount child           = FinancialAccount.FromIdentity(Int32.Parse(hiddenAccountId.Value));

            TextBox box       = (TextBox)repeaterItem.FindControl("TextChildBudget");
            string  boxText   = box.Text;
            double  newBudget = (double)Int32.Parse(boxText, NumberStyles.Number, new CultureInfo("sv-SE"));
            double  curBudget = child.GetTree().GetBudgetSum(_year);

            // since we don't know here how much has been suballocated in turn, we need to produce a delta from the child's tree budget total and apply it to the child node

            double delta = newBudget - curBudget;
            child.SetBudget(_year, child.GetBudget(_year) + delta);

            deltaTotal += delta;
        }

        // Last, apply the total delta to the master account

        _account.SetBudget(_year, _account.GetBudget(_year) - deltaTotal);

        // Rewrite controls

        PopulateBudgetData();
    }
コード例 #7
0
    private void PopulateBudgetData()
    {
        Ledger.Accounts = FinancialAccounts.FromSingle(_account);
        int year = Int32.Parse(this.DropYears.SelectedValue);

        Ledger.DateStart = new DateTime(year, 1, 1);
        Ledger.DateEnd   = new DateTime(year, 12, 31);
        Ledger.MaxAmount = 1.0e12m;

        double budget = _account.GetBudget(year);

        Ledger.Populate();

        // Populate predictions

        int monthIterator = 1;

        Int64[] monthlyPredicts = _account.GetBudgetMonthly(year);

        while (monthIterator <= 12)
        {
            TextBox box =
                (TextBox)
                this.Master.FindControl("BodyContent").FindControl("TextPredictMonth" + monthIterator.ToString());

            if (monthlyPredicts.Length == 12)
            {
                box.Text = (monthlyPredicts[monthIterator - 1] / 100).ToString("N0", new CultureInfo("sv-SE"));
            }
            else
            {
                box.Text = string.Empty;
            }

            monthIterator++;
        }

        // Populate actuals

        monthIterator = 1;

        while (monthIterator <= 12 && new DateTime(year, monthIterator, 1).AddMonths(1) < DateTime.Today)
        {
            DateTime start      = new DateTime(year, monthIterator, 1);
            Int64    deltaCents = _account.GetDeltaCents(start, start.AddMonths(1));

            decimal deltaDecimal = -deltaCents / 100.0m;

            TextBox actual = (TextBox)this.Master.FindControl("BodyContent").FindControl("TextActualsMonth" + monthIterator.ToString());
            actual.Text = deltaDecimal.ToString("N0", new CultureInfo(_account.Organization.DefaultCountry.Culture));
            monthIterator++;
        }

        // Clear the non-set actuals fields

        while (monthIterator <= 12)
        {
            TextBox actual = (TextBox)this.Master.FindControl("BodyContent").FindControl("TextActualsMonth" + monthIterator.ToString());
            actual.Text = string.Empty;
            monthIterator++;
        }

        InitSuballocation(true);

        ScriptManager.RegisterStartupScript(this, Page.GetType(), "set_budget_iframe",
                                            "var currWidth = document.getElementById('DivIframeContainer').offsetWidth; document.getElementById('DivIframeContainer').innerHTML='<iframe src=\"BudgetUsageBar.aspx?AccountId=" + _account.Identity.ToString() + "&Year=" + year.ToString() + "&Width=' + currWidth + '\" width=\"100%\" scrolling=\"no\" height=\"100\" frameBorder=\"0\" />';",
                                            true);
    }