protected void ValidatorAccountNoClearing_ServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = true; if (Formatting.CleanNumber(this.TextAccount.Text.Trim()).StartsWith(Formatting.CleanNumber(this.TextBankClearing.Text.Trim()))) { args.IsValid = false; } }
protected void ValidatorAccountNumbersOnly_ServerValidate(object source, ServerValidateEventArgs args) { args.IsValid = true; if (Formatting.CleanNumber(this.TextAccount.Text.Trim()).Length != this.TextAccount.Text.Trim().Length) { args.IsValid = false; } }
protected void ButtonGo_Click(object sender, EventArgs e) { Person candidate = Person.FromIdentity((int)ViewState[this.ClientID + "SelectedCandidate"]); Election.September2010.SetCandidateDocumented(Organization.PPSE, candidate); candidate.PersonalNumber = Formatting.CleanNumber(this.TextPersonalNumber.Text); candidate.Phone = Formatting.CleanNumber(this.TextPhone.Text); PWEvents.CreateEvent(EventSource.PirateWeb, EventType.CandidateDocumentationReceived, _currentUser.Identity, Organization.PPSEid, 1, candidate.Identity, Election.September2010.Identity, string.Empty); this.TextPersonalNumber.Text = string.Empty; this.TextPhone.Text = string.Empty; this.LabelBallots.Text = string.Empty; this.ComboCandidate.Text = string.Empty; this.LabelCandidateName.Text = "---"; Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('" + HttpUtility.HtmlEncode(candidate.Canonical + " är klarerad att gå till val.").Replace("'", "''") + "');", true); }
protected void ButtonSaveChanges_Click(object sender, EventArgs e) { // Check for dirty fields, one by one int currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name); Person currentUser = Person.FromIdentity(currentUserId); AuditedPerson aperson = AuditedPerson.FromPerson(Person, currentUser, "PersonBasicDetails"); if (this.TextName.Text != Person.Name) { if (!string.IsNullOrEmpty(aperson.PartyEmail)) { msgAskAboutPPAddress.Visible = true; //Show "alert" panel divMessage.InnerHtml = Server.HtmlEncode( this.GetLocalResourceObject("Interface.Controls.EditPerson.MsgAskForChangeMail").ToString()).Replace("[", "<").Replace("]", ">"); /*"[br/][br/] * [span style='font-size:1.1em;font-weight: bold']You changed your name.[/span][br/][br/] * Do you want yor party mail address @piratpartiet.se[br/] * to be changed as well?[br/] * [br/]"*/ } aperson.Name = this.TextName.Text; // causes a database op } if (this.TextStreet.Text != Person.Street) { aperson.Street = this.TextStreet.Text; // causes a database op } if (this.TextCity.Text != Person.CityName) { aperson.City = this.TextCity.Text; // causes two dbops } Cities cities = Cities.FromPostalCode(this.TextPostalCode.Text.Replace(" ", ""), this.DropCountries.SelectedValue); int personGeography = person.GeographyId; if (this.TextPostalCode.Text != Person.PostalCode) { aperson.PostalCode = this.TextPostalCode.Text; // causes two dbops } if (this.DropCountries.SelectedValue != Person.Country.Code) { aperson.Country = Country.FromCode(this.DropCountries.SelectedValue); // causes two dbops } Person tempPerson = Person.FromIdentity(this.Person.Identity); //important that this is after country, city and postcode, since they might resolve wrongly if (this.DropDownMunicipalities.SelectedValue != tempPerson.GeographyId.ToString()) { aperson.Geography = Geography.FromIdentity(int.Parse(this.DropDownMunicipalities.SelectedValue)); // causes two dbops } this.LabelEmailMessage.Text = ""; this.LabelEmailMessage.CssClass = ""; if (this.TextEmail.Text != Person.Email) { if (Formatting.ValidateEmailFormat(this.TextEmail.Text)) { aperson.Email = this.TextEmail.Text; // causes dbop if (aperson.MailUnreachable) { aperson.MailUnreachable = false; this.LabelEmailMessage.Text = string.Empty; } } else { this.TextEmail.CssClass = "DirtyInput"; this.LabelEmailMessage.Text = "Invalid Email Not Saved"; this.LabelEmailMessage.CssClass = "ErrorMessage"; this.TextEmail.Focus(); } } if (this.TextPhone.Text != Person.Phone) { string phone = Formatting.CleanNumber(this.TextPhone.Text); this.TextPhone.Text = phone; aperson.Phone = phone; // causes dbop } this.LabelBirthdateMessage.Text = ""; this.LabelBirthdateMessage.CssClass = ""; DateTime birthdate = DateTime.MinValue; if (DateTime.TryParse(this.TextBirthdate.Text, out birthdate)) { if (birthdate != Person.Birthdate) { aperson.Birthdate = birthdate; // causes dbop } this.TextBirthdate.CssClass = string.Empty; this.LabelBirthdateMessage.Text = string.Empty; } else { this.TextBirthdate.CssClass = "DirtyInput"; this.LabelBirthdateMessage.Text = "Invalid Date Not Saved"; this.LabelBirthdateMessage.CssClass = "ErrorMessage"; this.TextBirthdate.Focus(); } PersonGender gender = (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue); if (gender != Person.Gender) { aperson.Gender = gender; // causes dbop } string currentHandle = this.TextHandle.Text; try { currentHandle = Person.Handle; if (currentHandle == null) { currentHandle = string.Empty; } this.LabelHandleMessage.Text = string.Empty; this.TextHandle.CssClass = string.Empty; if (this.TextHandle.Text != currentHandle) { try { aperson.Handle = this.TextHandle.Text; } catch (HandleException exh) { this.TextHandle.CssClass = "DirtyInput"; if (exh.ErrorType == HandleErrorType.HandleNotFound) { this.LabelHandleMessage.Text = "Not Found"; } else if (exh.ErrorType == HandleErrorType.HandleOccupied) { this.LabelHandleMessage.Text = "Already in use, contact [email protected] if it is yours."; } else { this.LabelHandleMessage.Text = "Invalid Handle"; } this.LabelHandleMessage.CssClass = "ErrorMessage"; this.TextHandle.Focus(); } } } catch (Exception ex) { currentHandle = ""; this.TextHandle.Text = "Connection Error"; this.TextHandle.ToolTip = ex.Message; this.TextHandle.Enabled = false; } if (this.TextPersonalNumber.Text != Person.PersonalNumber) { aperson.PersonalNumber = this.TextPersonalNumber.Text; } this.LabelBankAccountMessage.CssClass = this.LabelBankNameMessage.CssClass = string.Empty; this.TextBankAccount.CssClass = this.TextBankName.CssClass = string.Empty; if (this.TextBankAccount.Text != Person.BankAccount || this.TextBankName.Text != Person.BankName || this.TextBankClearing.Text != Person.BankClearing) { // If we are saving the bank account, the name and account must either be both present // or both empty. if (this.TextBankName.Text.Trim() == string.Empty && this.TextBankAccount.Text.Trim() == string.Empty) { aperson.BankAccount = aperson.BankName = string.Empty; } else if (this.TextBankName.Text.Trim().Length > 1 && this.TextBankAccount.Text.Trim().Length > 4) { aperson.BankAccount = Formatting.CleanNumber(this.TextBankAccount.Text.Trim()); // causes dbops aperson.BankClearing = Formatting.CleanNumber(this.TextBankClearing.Text.Trim()); aperson.BankName = this.TextBankName.Text.Trim(); } else { // If we get here, only one of the fields have been set. this.TextBankName.CssClass = "DirtyInput"; this.TextBankAccount.CssClass = "DirtyInput"; this.LabelBankNameMessage.Text = "Must specify bank AND account"; this.LabelBankAccountMessage.Text = "Must specify bank AND account"; this.LabelBankNameMessage.CssClass = "ErrorMessage"; this.LabelBankAccountMessage.CssClass = "ErrorMessage"; if (this.TextBankAccount.Text.Trim().Length > 4) { this.TextBankName.Focus(); } else { this.TextBankAccount.Focus(); } } } if (this.TextPersonalNumber.Text != Person.PersonalNumber) { // TODO: Check for validity //aperson.PersonalNumber = this.TextPersonalNumber.Text.Trim(); } if (DataChanged != null) { DataChanged(this, new EventArgs()); } }
private string GetAccountOcr(Payout payout) { return(Formatting.CleanNumber(payout.Account) + "#41#"); }
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(); }
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 }
public static PaymentTransferInfo FromObject(IHasIdentity financialObject, Money amountToPay = null) { if (financialObject is ExpenseClaim) { ExpenseClaim claim = financialObject as ExpenseClaim; if (amountToPay == null) { return(FromObject(claim.Claimer, new Money(claim.AmountCents, claim.Organization.Currency))); } else { return(FromObject(claim.Claimer, amountToPay)); } } if (financialObject is CashAdvance) { CashAdvance advance = financialObject as CashAdvance; if (amountToPay == null) { return(FromObject(advance.Person, new Money(advance.AmountCents, advance.Organization.Currency))); } else { return(FromObject(advance.Person, amountToPay)); } } if (financialObject is Salary) { Salary salary = financialObject as Salary; return(FromObject(salary.PayrollItem.Person, new Money(salary.NetSalaryCents, salary.PayrollItem.Organization.Currency))); } if (financialObject is InboundInvoice) { // TODO: Create Supplier object, read from that instead InboundInvoice invoice = financialObject as InboundInvoice; PaymentTransferInfo result = new PaymentTransferInfo(); // For now, do a switch on the pay-to-account string, before the payment targets are implemented // on invoices and expense claims: result.LocalizedPaymentInformation = new Dictionary <string, string>(); if (invoice.PayToAccount.StartsWith("IBAN")) { result.TargetType = PaymentTargetType.InternationalBankTransfer; result.LocalizedPaymentInformation[ Logic_Financial_PaymentTransferInfo.PaymentTargetField_Iban] = invoice.PayToAccount.Substring(5); // this should have bic too but we don't have that information before payment targets // are properly implemented } else if (invoice.PayToAccount.StartsWith("SEBG")) { result.TargetType = PaymentTargetType.DomesticBankGiro; // for now result.LocalizedPaymentInformation[ Logic_Financial_PaymentTransferInfo.PaymentTargetField_GiroNumber] = invoice.PayToAccount.Substring(5); // Check for SEBG OCR availability if (invoice.InvoiceReference.Length > 2 && Formatting.CheckLuhnChecksum(invoice.InvoiceReference) && Formatting.CheckLuhnChecksum(invoice.PayToAccount)) { result.OcrAvailable = true; result.OcrData = new string[3]; result.OcrData[0] = invoice.InvoiceReference + " #"; result.OcrData[1] = string.Format("{0} {1:00} {2} >", // three spaces between the cents and the checksum invoice.AmountCents / 100, invoice.AmountCents % 100, Formatting.GetLuhnChecksum(invoice.AmountCents.ToString(CultureInfo.InvariantCulture))); result.OcrData[2] = Formatting.CleanNumber(invoice.PayToAccount) + "#41#"; } } else { // Assume domestic giro in lack of other information result.TargetType = PaymentTargetType.DomesticBankGiro; result.LocalizedPaymentInformation[ Logic_Financial_PaymentTransferInfo.PaymentTargetField_GiroNumber] = invoice.PayToAccount; // the whole string, as opposed to case above } result.LocalizedPaymentMethodName = Logic_Financial_PaymentTransferInfo.ResourceManager.GetString("PaymentTargetType_" + result.TargetType.ToString()); if (invoice.HasNativeCurrency) { result.Currency = invoice.NativeCurrencyAmount.Currency; result.CurrencyAmount = result.Currency.Code + " " + (invoice.NativeCurrencyAmount.Cents / 100.0).ToString("N2"); } else { result.Currency = invoice.Organization.Currency; result.CurrencyAmount = result.Currency.Code + " " + (invoice.AmountCents / 100.0).ToString("N2"); } result.Country = null; // TODO: Set to Supplier's PaymentTarget country result.Recipient = invoice.Supplier; return(result); } if (financialObject is Person) { Person person = financialObject as Person; // For now, assume the bank/clearing/account triplet // TODO: Implement payment targets on teh Person object PaymentTransferInfo result = new PaymentTransferInfo(); result.TargetType = PaymentTargetType.DomesticBankTransfer; // We must know the amount at this point if (amountToPay == null) { throw new ArgumentNullException("amountToPay", @"Cannot determine payment transfer information without knowing origin currency"); } if (string.IsNullOrEmpty(person.BankName) || string.IsNullOrEmpty(person.BankClearing) || string.IsNullOrEmpty(person.BankAccount)) { throw new NotImplementedException("Cannot provide payment transfer information for Person #" + person.Identity.ToString()); } result.TargetType = PaymentTargetType.DomesticBankTransfer; result.Country = person.CountryId == 0? null: person.Country; result.Currency = amountToPay.Currency; // TODO: The currency will need to come from the payment method instead result.CurrencyAmount = result.Currency.Code + " " + (amountToPay.ToCurrency(result.Currency).Cents / 100.0).ToString("N2"); result.LocalizedPaymentMethodName = Logic_Financial_PaymentTransferInfo.ResourceManager.GetString("PaymentTargetType_" + result.TargetType.ToString()); result.Recipient = person.Canonical; result.LocalizedPaymentInformation = new Dictionary <string, string>(); result.LocalizedPaymentInformation[ Logic_Financial_PaymentTransferInfo.PaymentTargetField_ClearingCode] = person.BankName + " " + person.BankClearing; result.LocalizedPaymentInformation[ Logic_Financial_PaymentTransferInfo.PaymentTargetField_AccountNumber] = person.BankAccount; return(result); } throw new NotImplementedException("Unknown payment information"); }