Example #1
0
        void btnAddPledge_Click(object sender, EventArgs e)
        {
            int fundId = Int32.Parse(ddlFunds.SelectedValue);
            PledgeCollection pledges = new PledgeCollection();

            pledges.LoadByPersonAndFundId(person.PersonID, fundId);
            if (pledges.Count > 0)
            {
                lblError.Text = string.Format("<br />Error: {0} already has a {1:c} pledge for the {2} fund.", person.NickName, pledges[0].Amount, pledges[0].Fund.FundName);
            }
            else
            {
                lblError.Text = string.Empty;
                Fund fund = new Fund(fundId);

                DateTime startDate = DateTime.Today;
                if (DateTime.Today > fund.EndDate || DateTime.Today < fund.StartDate)
                {
                    startDate = fund.StartDate;
                }

                new Arena.DataLayer.Contributions.PledgeData().SavePledge(
                    -1,
                    person.PersonID,
                    fund.FundId,
                    startDate,
                    fund.EndDate,
                    0,
                    CurrentUser.Identity.Name);
            }

            ShowList();
        }
Example #2
0
        /// <summary>
        /// Update button was clicked to save pledge information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            // Create person object based on the person that is selected
            Person person = new Person(GetSelectedPersonId());

            // Load a pledge collection object to determine if person already has a pledge against the fund selected
            PledgeCollection pledges = new PledgeCollection();

            pledges.LoadByPersonAndFundId(GetSelectedPersonId(), Convert.ToInt32(ddlFund.SelectedValue));

            DataLayer.PledgeData pledgeData = new DataLayer.PledgeData(-1);

            if (pledges.Count > 0)
            {
                lblUpdated.Text = "";
                lblError.Text   = string.Format("Error: {0} already has a {1:c} pledge for the {2} fund.", Utilities.PersonLink(person, Convert.ToInt32(PersonDetailPageSetting)), pledges[0].Amount, pledges[0].Fund.FundName);
            }
            else
            {
                // Create pledge data object and save to database
                pledgeData.PersonID        = GetSelectedPersonId();
                pledgeData.CampusLUID      = Convert.ToInt32(ddlCampus.SelectedValue);
                pledgeData.FundID          = Convert.ToInt32(ddlFund.SelectedValue);
                pledgeData.StartDate       = tbStartDate.SelectedDate;
                pledgeData.EndDate         = tbEndDate.SelectedDate;
                pledgeData.FrequencyAmount = Convert.ToDecimal(tbFrequencyAmt.Text);
                pledgeData.FrequencyCount  = Convert.ToInt32(tbFrequencyCount.Text);
                pledgeData.TotalAmount     = Convert.ToDecimal(tbAmount.Text);
                pledgeData.SavePledge(CurrentUser.Identity.Name);

                // Clear any errors being displayed, display a confirmation text that the pledge was stored, and reset the form appropriately
                lblError.Text       = "";
                lblUpdated.Text     = string.Format(@"Added {0:c} pledge to the <span style=""font-weight:bold;"">{1}</span> fund for {2}", pledgeData.TotalAmount, ddlFund.SelectedItem.Text, Utilities.PersonLink(person, Convert.ToInt32(PersonDetailPageSetting)));
                tbFrequencyAmt.Text = tbFrequencyCount.Text = tbAmount.Text = "";
                dgPeople.Visible    = false;
                tbName.Text         = "";
                tbName.Focus();
            }
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            PledgeCollection pledges = new PledgeCollection();

            pledges.LoadByPersonAndFundId(GetSelectedPersonId(), Convert.ToInt32(ddlFund.SelectedValue));
            if (pledges.Count > 0)
            {
                Person person = new Person(GetSelectedPersonId());
                lblError.Text = string.Format("Error: {0} already has a {1:c} pledge for the {2} fund.", Utilities.PersonLink(person, Convert.ToInt32(PersonDetailPageSetting)), pledges[0].Amount, pledges[0].Fund.FundName);
            }
            else if (dtbStartDate.SelectedDate > dtbEndDate.SelectedDate)
            {
                lblError.Text = "Start Date must be less than or equal to End Date";
            }
            else
            {
                Pledge pledge = new Pledge();
                pledge.PersonId        = GetSelectedPersonId();
                pledge.FundId          = Convert.ToInt32(ddlFund.SelectedValue);
                pledge.PledgeBeginDate = dtbStartDate.SelectedDate;
                pledge.PledgeEndDate   = dtbEndDate.SelectedDate;
                pledge.Amount          = Convert.ToDecimal(tbAmount.Text);
                //   pledge.Save(CurrentUser.Identity.Name);

                // Create custom pledge object
                DataLayer.PledgeData pledgeData = new DataLayer.PledgeData(_pledgeId);
                pledgeData.PersonID        = GetSelectedPersonId();
                pledgeData.CampusLUID      = Convert.ToInt32(ddlCampus.SelectedValue);
                pledgeData.FundID          = Convert.ToInt32(ddlFund.SelectedValue);
                pledgeData.StartDate       = dtbStartDate.SelectedDate;
                pledgeData.EndDate         = dtbEndDate.SelectedDate;
                pledgeData.FrequencyAmount = Convert.ToDecimal(tbFrequencyAmt.Text);
                pledgeData.FrequencyCount  = Convert.ToInt32(tbFrequencyCount.Text);
                pledgeData.TotalAmount     = Convert.ToDecimal(tbAmount.Text);
                pledgeData.SavePledge(CurrentUser.Identity.Name);


                if (cbCreateRepeatingPayment.Checked)
                {
                    CurrentPerson.Settings["PledgeQuickEntry_CreateRepeatingPayment"] = cbCreateRepeatingPayment.Checked.ToString();

                    //Create ACH Repeating Payment
                    string comment = string.Format("F{0}:{1} ", pledge.FundId.ToString(), tbPaymentAmount.Text);

                    try
                    {
                        RepeatingPayment repeatingPayment = null;
                        if (_achGatewayAcct.AuthorizeACH(TransactionType.Repeating, tbAccountNumber.Text.Trim(), tbRoutingNumber.Text.Trim(),
                                                         rblAccountType.Items[0].Selected, pledge.PersonId, pledge.Person.FirstName, pledge.Person.FirstName,
                                                         pledge.Person.LastName, pledge.Person.Addresses.PrimaryAddress().Address.StreetLine1, pledge.Person.Addresses.PrimaryAddress().Address.City,
                                                         pledge.Person.Addresses.PrimaryAddress().Address.State, pledge.Person.Addresses.PrimaryAddress().Address.PostalCode,
                                                         "", "", Convert.ToDecimal(tbPaymentAmount.Text), comment, dtbStartDate.SelectedDate,
                                                         (PaymentFrequency)Enum.Parse(typeof(PaymentFrequency), ddlFrequency.SelectedValue), Convert.ToInt32(tbNumOfPayments.Text)))
                        {
                            repeatingPayment = _achGatewayAcct.RepeatingPayment;
                        }


                        if (repeatingPayment != null)
                        {
                            //Save Repeating Payment
                            repeatingPayment.Title          = "Pledge for " + pledge.Fund.FundName;
                            repeatingPayment.AccountNumber  = MaskAccountNumber(tbAccountNumber.Text.Trim());
                            repeatingPayment.OrganizationID = CurrentOrganization.OrganizationID;
                            repeatingPayment.RepeatingPaymentFunds.Clear();

                            RepeatingPaymentFund rpf = new RepeatingPaymentFund();
                            rpf.Amount = Convert.ToDecimal(tbPaymentAmount.Text);
                            rpf.FundID = pledge.FundId;
                            repeatingPayment.RepeatingPaymentFunds.Add(rpf);
                            repeatingPayment.Save(CurrentUser.Identity.Name);

                            try
                            {
                                OnlineGivingContribution ogcEmail = new OnlineGivingContribution();
                                ogcEmail.Send(CurrentOrganization, repeatingPayment);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else
                        {
                            string error = ParseError("Authorization of your information failed for the following reason(s):", _achGatewayAcct.Messages);
                            throw new ArenaApplicationException(error);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ArenaApplicationException("Error occurred during Authorization", ex);
                    }
                }
                RedirectToPledge(pledge.PledgeId);
            }

            ddlCampus.Focus();
        }