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."); }
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); }
protected void ButtonAttest_Click(object sender, EventArgs e) { List <string> identityStrings = new List <string>(); foreach (string indexString in this.GridAttestables.SelectedIndexes) { int index = Int32.Parse(indexString); string itemIdentityString = (string)this.GridAttestables.MasterTableView.DataKeyValues[index]["Identity"]; int itemIdentity = Int32.Parse(itemIdentityString.Substring(1)); // Mark items as attested switch (itemIdentityString[0]) { case 'E': ExpenseClaim claim = ExpenseClaim.FromIdentity(itemIdentity); if (attestationRights.ContainsKey(claim.BudgetId)) { claim.Attest(_currentUser); Activizr.Logic.Support.PWEvents.CreateEvent( EventSource.PirateWeb, EventType.ExpenseAttested, _currentUser.Identity, claim.OrganizationId, 0, claim.ClaimingPersonId, claim.Identity, string.Empty); } break; case 'I': InboundInvoice invoice = InboundInvoice.FromIdentity(itemIdentity); if (attestationRights.ContainsKey(invoice.BudgetId)) { invoice.Attest(_currentUser); Activizr.Logic.Support.PWEvents.CreateEvent( EventSource.PirateWeb, EventType.InboundInvoiceAttested, _currentUser.Identity, invoice.OrganizationId, 0, 0, invoice.Identity, string.Empty); } break; case 'S': Salary salary = Salary.FromIdentity(itemIdentity); // Mark as attested bool mayAttest = false; if (attestationRights.ContainsKey(salary.PayrollItem.BudgetId) && salary.PayrollItem.PersonId != _currentUser.Identity) { mayAttest = true; } if (salary.PayrollItem.ReportsToPersonId == _currentUser.Identity) { mayAttest = true; } if (mayAttest) { salary.Attest(_currentUser); Activizr.Logic.Support.PWEvents.CreateEvent( EventSource.PirateWeb, EventType.SalaryAttested, _currentUser.Identity, salary.PayrollItem.OrganizationId, 0, 0, salary.Identity, string.Empty); } break; case 'P': Parley parley = Parley.FromIdentity(itemIdentity); if (attestationRights.ContainsKey(parley.BudgetId)) { parley.Attest(_currentUser); } break; } } this.GridAttestables.Rebind(); }