protected void ButtonCreate_Click(object sender, EventArgs e) // TODO { // 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. double amount = Double.Parse(this.TextAmount.Text, NumberStyles.Number); // parses in current culture - intentional Int64 amountCents = (Int64)amount * 100; string description = this.TextPurpose.Text; DateTime dueDate = DateTime.Parse(this.TextDueDate.Text); FinancialAccount budget = FinancialAccount.FromIdentity(Int32.Parse(this.Request.Form["DropBudgets"])); // sanity check if (budget.Organization.Identity != CurrentOrganization.Identity) { throw new InvalidOperationException("Budget-organization mismatch; won't file expense claim"); } // 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"); } InboundInvoice invoice = InboundInvoice.Create(CurrentOrganization, dueDate, amountCents, budget, this.TextSupplier.Text, this.TextPurpose.Text, this.TextAccount.Text, string.Empty, this.TextReference.Text, CurrentUser); foreach (int tagSetId in _tagSetIds) { string selectedTagString = this.Request.Form["DropTags" + tagSetId.ToString(CultureInfo.InvariantCulture)]; if (!String.IsNullOrEmpty(selectedTagString)) { int selectedTagType = Int32.Parse(selectedTagString); if (selectedTagType != 0) { invoice.FinancialTransaction.CreateTag( FinancialTransactionTagType.FromIdentity(selectedTagType), CurrentUser); } } } documents.SetForeignObjectForAll(invoice); // Display success message this.LiteralSuccess.Text = HttpUtility.UrlEncode(String.Format(Resources.Pages.Financial.CreateInboundInvoice_SuccessMessage, invoice.Identity)).Replace("+", "%20"); // Reset all fields for next invoice this.FileUpload.Reset(); this.TextSupplier.Text = String.Empty; this.TextAccount.Text = String.Empty; this.TextPurpose.Text = String.Empty; this.TextReference.Text = String.Empty; this.TextAmount.Text = 0.ToString("N2"); this.TextDueDate.Text = DateTime.Today.AddDays(30).ToShortDateString(); // Use current culture // the easyUI combo fields should reset automatically on form submission unless we explicitly reconstruct this.TextSupplier.Focus(); }
protected void ButtonCreate_Click(object sender, EventArgs e) // TODO { // 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 = this.CurrencyAmount.Cents; Int64 amountVatCents = this.CurrencyVat.Cents; string description = this.TextPurpose.Text; DateTime dueDate = DateTime.Parse(this.TextDueDate.Text); FinancialAccount budget = this.ComboBudgets.SelectedAccount; // sanity check if (budget.Organization.Identity != CurrentOrganization.Identity) { throw new InvalidOperationException("Budget-organization mismatch; won't file expense claim"); } // 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"); } InboundInvoice invoice = InboundInvoice.Create(CurrentOrganization, dueDate, amountCents, amountVatCents, budget, this.TextSupplier.Text, this.TextPurpose.Text, this.TextAccount.Text, string.Empty, this.TextReference.Text, CurrentUser); 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) { invoice.FinancialTransaction.CreateTag( FinancialTransactionTagType.FromIdentity(selectedTagType), CurrentUser); } } } documents.SetForeignObjectForAll(invoice); // If amounts were in a different currency, record the native values for proper payment if (this.CurrencyAmount.NonPresentationCurrencyUsed) { Money currencyEntered = this.CurrencyAmount.NonPresentationCurrencyAmount; invoice.NativeCurrencyAmount = currencyEntered; } // Display success message this._invoiceId = invoice.OrganizationSequenceId; // a property returns the localized string // Reset all fields for next invoice this.FileUpload.Reset(); this.TextSupplier.Text = String.Empty; this.TextAccount.Text = String.Empty; this.TextPurpose.Text = String.Empty; this.TextReference.Text = String.Empty; this.CurrencyAmount.Cents = 0; this.CurrencyVat.Cents = 0; this.TextDueDate.Text = DateTime.Today.AddDays(30).ToShortDateString(); // Use current culture // the easyUI combo fields should reset automatically on form submission unless we explicitly reconstruct this.TextSupplier.Focus(); }
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; } // Read the form data string supplier = this.TextSupplier.Text; string bankAccount = this.TextAccount.Text; int temporaryId = Int32.Parse(this.TemporaryDocumentIdentity.Text); int organizationId = Int32.Parse(this.DropOrganizations.SelectedValue); Organization org = Organization.FromIdentity(organizationId); Int64 amountCents = (Int64)(Double.Parse(this.TextAmount.Text, new CultureInfo("sv-SE")) * 100); FinancialAccount budget = this.DropBudgets.SelectedFinancialAccount; DateTime dueDate = (DateTime)this.DatePicker.SelectedDate; string ocr = string.Empty; string invoiceNumber = string.Empty; if (this.DropReferenceType.SelectedValue == "OCR") { ocr = this.TextReference.Text; } else { invoiceNumber = this.TextReference.Text; } // Create the invoice record InboundInvoice newInvoice = InboundInvoice.Create(org, dueDate, amountCents, budget, supplier, bankAccount, ocr, invoiceNumber, _currentUser); // Move documents to the new invoice Documents.ForObject(new TemporaryIdentity(temporaryId)).SetForeignObjectForAll(newInvoice); // Create the event for PirateBot-Mono to send off mails Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.InboundInvoiceReceived, _currentUser.Identity, organizationId, 1, _currentUser.Identity, newInvoice.Identity, string.Empty); Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('The invoice was registered.');", true); // Clear the text fields this.TextSupplier.Text = string.Empty; this.TextAccount.Text = string.Empty; this.TextReference.Text = string.Empty; this.DropReferenceType.SelectedIndex = 0; this.TemporaryDocumentIdentity.Text = "0"; this.TextAmount.Text = "0,00"; // TODO: LOCALIZE BY CULTURE // PopulateGrid(); }