protected void ButtonSetBudget_Click(object sender, EventArgs e)
    {
        if (_authority.HasPermission(Permission.CanDoBudget, _account.OrganizationId, -1, Authorization.Flag.ExactOrganization))
        {
            _account.SetBudget(Int32.Parse(this.LabelBudgetYear.Text), Int32.Parse(this.TextBudget.Text));
        }

        ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
    }
Beispiel #2
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 + ".");
    }
Beispiel #3
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.");
    }
Beispiel #4
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();
    }