protected void ButtonSubmitClaim_Click(object sender, EventArgs e)
    {
        // First, if there's an upload that the user hasn't processed, process it first.

        if (this.Upload.UploadedFiles.Count > 0)
        {
            ProcessUpload();
        }

        // If args were invalid, abort

        if (!Page.IsValid)
        {
            return;
        }

        // Set bank details

        _currentUser.BankName     = this.TextBank.Text.Trim();
        _currentUser.BankClearing = Formatting.CleanNumber(this.TextBankClearing.Text.Trim());
        _currentUser.BankAccount  = Formatting.CleanNumber(this.TextAccount.Text.Trim());

        // Read the form data

        int temporaryId = Int32.Parse(this.TemporaryDocumentIdentity.Text);

        int          organizationId = Int32.Parse(this.DropOrganizations.SelectedValue);
        Organization organization   = Organization.FromIdentity(organizationId);

        Int64            amountCents = (Int64)(Double.Parse(this.TextAmount.Text, new CultureInfo("sv-SE")) * 100);
        FinancialAccount account     = this.DropBudgets.SelectedFinancialAccount;
        DateTime         created     = DateTime.Now;
        DateTime         expenseDate = (DateTime)this.DatePicker.SelectedDate;
        string           description = this.TextDescription.Text;
        int claimId = 0;

        if (this.RadioNewClaim.Checked)
        {
            // Create the expense claim record

            ExpenseClaim newClaim = ExpenseClaim.Create(_currentUser,
                                                        organization, account, expenseDate,
                                                        description, amountCents);
            claimId = newClaim.Identity;

            // Move documents to the new expense claim

            Documents.ForObject(new TemporaryIdentity(temporaryId)).SetForeignObjectForAll(newClaim);
        }
        else
        {
            // This was a pre-approved claim: modify the existing claim and transaction

            ExpenseClaim         claim       = ExpenseClaim.FromIdentity(Int32.Parse(this.DropPreattested.SelectedValue));
            FinancialTransaction transaction = claim.FinancialTransaction;
            claimId = claim.Identity;

            claim.Claimed = true;

            // If claimed amount exceeds attested amount, unattest

            if (amountCents > claim.AmountCents)
            {
                claim.Deattest(_currentUser);
            }

            // Change amount and date

            claim.SetAmountCents(amountCents, _currentUser);
            claim.ExpenseDate = expenseDate;

            // Move documents to the expense claim

            Documents.ForObject(new TemporaryIdentity(temporaryId)).SetForeignObjectForAll(claim);
        }

        // Create the event for PirateBot-Mono to send off mails

        Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ExpenseCreated,
                                                    _currentUser.Identity, organizationId, Geography.RootIdentity, _currentUser.Identity,
                                                    claimId, string.Empty);

        Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Your expense claim has been submitted.');", true);

        // Clear the text fields

        this.TextDescription.Text           = string.Empty;
        this.TextAmount.Text                = "0,00"; // TODO: LOCALIZE BY CULTURE
        this.TemporaryDocumentIdentity.Text = "0";

        PopulateGrid();
        PopulatePreattested();
    }
Exemple #2
0
    protected void ButtonSaveChanges_Click(object sender, EventArgs e)
    {
        // If the values in the controls are not valid, abort:

        if (!Page.IsValid)
        {
            return;
        }

        // Move on and parse values.

        double           newAmount      = Double.Parse(this.TextAmount.Text, new CultureInfo("sv-SE"));
        FinancialAccount newAccount     = this.DropAccounts.SelectedFinancialAccount;
        string           newDescription = this.TextDescription.Text;
        DateTime         newDate        = (DateTime)this.DateExpense.SelectedDate;

        if (newDescription != _expenseClaim.Description)
        {
            _expenseClaim.Description = newDescription;
            // Nothing invalidated because description updated

            // Should it?
        }

        if (newAccount.Identity != _expenseClaim.BudgetId)
        {
            if (_expenseClaim.Attested)
            {
                _expenseClaim.Attested = false;
            }

            if (_expenseClaim.BudgetYear == 0)
            {
                _expenseClaim.BudgetYear = _expenseClaim.CreatedDateTime.Year;
            }

            _expenseClaim.SetBudget(newAccount, _currentUser);
        }

        if (newAmount != (double)_expenseClaim.Amount)
        {
            if (_expenseClaim.Attested)
            {
                if (newAmount > _expenseClaim.PreApprovedAmount && newAmount > (double)_expenseClaim.Amount)
                {
                    _expenseClaim.Attested = false;
                }
            }

            _expenseClaim.SetAmountCents((Int64)newAmount * 100, _currentUser);
        }

        if (newDate != _expenseClaim.ExpenseDate)
        {
            if (_expenseClaim.Validated)
            {
                _expenseClaim.Validated = false;
            }

            _expenseClaim.ExpenseDate = newDate;
        }

        // The financial transaction is now updated in ExpenseClaim.

        // Close and rebind

        ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
    }