public static AjaxCallResult ExpensifyRecordsetCommit(string masterGuid)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            // Commit all expenses in the recordset

            try
            {
                List <ExpensifyRecord> recordList = (List <ExpensifyRecord>)GuidCache.Get("ExpensifyData-" + masterGuid);
                string expensifyRaw = (string)GuidCache.Get("ExpensifyRaw-" + masterGuid);

                ExpenseClaimGroup expenseClaimGroup = ExpenseClaimGroup.Create(authData.CurrentOrganization,
                                                                               authData.CurrentUser, ExpenseClaimGroupType.Expensify, expensifyRaw);

                foreach (ExpensifyRecord record in recordList)
                {
                    FinancialAccount budget = FinancialAccount.FromIdentity(record.BudgetId);

                    ExpenseClaim claim = ExpenseClaim.Create(authData.CurrentUser, authData.CurrentOrganization, budget,
                                                             record.Timestamp, record.CategoryCustom + " / " + record.Description, record.AmountCents,
                                                             record.VatCents,
                                                             expenseClaimGroup);

                    record.Documents.SetForeignObjectForAll(claim);

                    // TODO: Log
                }

                if (recordList.Count > 1)
                {
                    return(new AjaxCallResult
                    {
                        Success = true,
                        DisplayMessage =
                            String.Format(Resources.Pages.Financial.FileExpenseClaim_Expensify_SuccessSeveral,
                                          recordList.Count)
                    });
                }

                return(new AjaxCallResult
                {
                    Success = true,
                    DisplayMessage = Resources.Pages.Financial.FileExpenseClaim_Expensify_SuccessOne
                });
            }
            catch (Exception exc)
            {
                return(new AjaxCallResult
                {
                    Success = false,
                    DisplayMessage = exc.ToString()
                });
            }
        }
Esempio n. 2
0
    private string ProcessExpenseClaim()
    {
        int year = DateTime.Today.Year;
        FinancialAccount account     = FinancialAccount.FromIdentity(Int32.Parse(this.DropBudgets.SelectedValue));
        string           expenseName = this.TextDescription.Text;
        Person           claimer     = this.ComboClaimPerson.SelectedPerson;
        Int64            amountCents = (Int64)(Double.Parse(this.TextAmount.Text, NumberStyles.Float, new CultureInfo("sv-SE")) * 100);

        // Create the expense claim record

        ExpenseClaim newClaim = ExpenseClaim.Create(claimer, Organization.PPSE, account, DateTime.Today, expenseName, amountCents);

        newClaim.Claimed = false;
        newClaim.Attest(_currentUser);

        return("The claim was created and pre-attested. " + claimer.Canonical +
               " has it in the list of approved expenses.");
    }
Esempio n. 3
0
        protected void ButtonRequest_Click(object sender, EventArgs e)
        {
            // The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here.
            // People who choose to disable JavaScript and then submit bad input almost deserve to be hurt.

            Int64 amountCents = (Int64)(this.CurrencyAmount.Value * 100.0);

            string description = this.TextPurpose.Text;

            FinancialAccount budget = FinancialAccount.FromIdentity(Int32.Parse(Request.Form["DropBudgets"]));

            // sanity check

            if (budget.Organization.Identity != CurrentOrganization.Identity)
            {
                throw new InvalidOperationException("Budget-organization mismatch; won't file expense claim");
            }

            // Store bank details for current user

            CurrentUser.BankName     = this.TextBank.Text;
            CurrentUser.BankClearing = this.TextClearing.Text;
            CurrentUser.BankAccount  = this.TextAccount.Text;

            // Get documents; check that documents have been uploaded

            Documents documents = Documents.RecentFromDescription(this.FileUpload.GuidString);

            if (documents.Count == 0)
            {
                throw new InvalidOperationException("No documents uploaded");
            }

            ExpenseClaim claim = ExpenseClaim.Create(CurrentUser, CurrentOrganization, budget, DateTime.UtcNow,
                                                     description, amountCents);

            foreach (int tagSetId in this._tagSetIds)
            {
                string selectedTagString =
                    Request.Form["DropTags" + tagSetId.ToString(CultureInfo.InvariantCulture)];

                if (!String.IsNullOrEmpty(selectedTagString))
                {
                    int selectedTagType = Int32.Parse(selectedTagString);
                    if (selectedTagType != 0)
                    {
                        claim.FinancialTransaction.CreateTag(
                            FinancialTransactionTagType.FromIdentity(selectedTagType),
                            CurrentUser);
                    }
                }
            }

            documents.SetForeignObjectForAll(claim);

            string successMessage = string.Format(Resources.Pages.Financial.FileExpenseClaim_SuccessMessagePartOne,
                                                  CurrentOrganization.Currency.Code,
                                                  amountCents / 100.0,
                                                  budget.Name);

            if (budget.OwnerPersonId != CurrentUser.Identity)
            {
                successMessage += "<br/><br/>" + Resources.Pages.Financial.FileExpenseClaim_SuccessMessagePartTwo +
                                  "<br/>";
            }
            else
            {
                successMessage += "<br/><br/>" +
                                  Resources.Pages.Financial.FileExpenseClaim_SuccessMessagePartTwoOwnBudget +
                                  "<br/>";
                claim.Attest(CurrentUser);
            }

            Response.AppendCookie(new HttpCookie("DashboardMessage", HttpUtility.UrlEncode(successMessage)));

            // Redirect to dashboard

            Response.Redirect("/", true);
        }
Esempio n. 4
0
    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();
    }
Esempio n. 5
0
    protected void ButtonSubmitClaim_Click(object sender, EventArgs e)
    {
        // First, if there's an upload that the user hasn't processed, process it first.

        // If args were invalid, abort

        if (!Page.IsValid)
        {
            return;
        }

        // Set bank details, if applicable

        if (!this.CheckImpersonate.Checked)
        {
            _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

        Person advancePerson = Person.FromIdentity(_currentUser.Identity);

        if (this.CheckImpersonate.Checked && this.ComboPersonImpersonated.SelectedPerson != null)
        {
            advancePerson = Person.FromIdentity(this.ComboPersonImpersonated.SelectedPerson.Identity);
        }

        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;
        int              budgetYear     = created.Year;
        DateTime         expenseDate    = DateTime.Today;
        string           description    = this.TextDescription.Text;

        // Create the POSITIVE transaction and claim

        ExpenseClaim newClaim = ExpenseClaim.Create(advancePerson,
                                                    organization, account, expenseDate, description, amountCents);

        newClaim.KeepSeparate = true; // assures separate payout
        newClaim.Validated    = true; // no validation: no receipts (yet)

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

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

        // Create the NEGATIVE transaction and claim

        newClaim = ExpenseClaim.Create(advancePerson,
                                       organization, account, expenseDate, description, -amountCents);

        // This claim is automatically validated, attested

        newClaim.Attested  = true;
        newClaim.Validated = true;

        Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Your cash request has been submitted. Note that this is a LOAN from the organization until the corresponding expenses have been documented.');", true);

        // Clear the text fields

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