Пример #1
0
        private string ConfirmTransaction(OnlineRegModel m, string TransactionID, ExtraDatum ed = null)
        {
            m.ParseSettings();
            if (m.List.Count == 0)
                return "error: unexpected, no registrants found in confirmation";
            string confirm = "Confirm";
            var managingsubs = m.ManagingSubscriptions();
            var choosingslots = m.ChoosingSlots();
            var t = m.Transaction;
            if (t == null && !managingsubs && !choosingslots)
            {
                var pf = PaymentForm.CreatePaymentForm(m);
                if (ed != null)
                    pf.DatumId = ed.Id;
                t = pf.CreateTransaction(DbUtil.Db);
                m.TranId = t.Id;
                if (ed != null)
                {
                    m.History.Add("ConfirmTransaction");
                    ed.Completed = true;
                    ed.Data = Util.Serialize<OnlineRegModel>(m);
                    DbUtil.Db.SubmitChanges();
                }
            }
            if (t != null)
                ViewData["message"] = t.Message;

            if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.CreateAccount)
            {
                m.List[0].CreateAccount();
                ViewData["CreatedAccount"] = true;
                confirm = "ConfirmAccount";
            }
            else if (m.OnlineGiving())
            {
                var p = m.List[0];
                if (p.IsNew)
                    p.AddPerson(null, p.org.EntryPointId ?? 0);

                var staff = DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId)[0];
                var text = p.setting.Body.Replace("{church}", DbUtil.Db.Setting("NameOfChurch", "church"), ignoreCase:true);
                text = text.Replace("{amt}", (t.Amt ?? 0).ToString("N2"));
                text = text.Replace("{date}", DateTime.Today.ToShortDateString());
                text = text.Replace("{tranid}", t.Id.ToString());
                text = text.Replace("{name}", p.person.Name);
                text = text.Replace("{account}", "");
                text = text.Replace("{email}", p.person.EmailAddress);
                text = text.Replace("{phone}", p.person.HomePhone.FmtFone());
                text = text.Replace("{contact}", staff.Name);
                text = text.Replace("{contactemail}", staff.EmailAddress);
                text = text.Replace("{contactphone}", p.org.PhoneNumber.FmtFone());
                var re = new Regex(@"(?<b>.*?)<!--ITEM\sROW\sSTART-->(?<row>.*?)\s*<!--ITEM\sROW\sEND-->(?<e>.*)", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                var match = re.Match(text);
                var b = match.Groups["b"].Value;
                var row = match.Groups["row"].Value.Replace("{funditem}", "{0}").Replace("{itemamt}", "{1:N2}");
                var e = match.Groups["e"].Value;
                var sb = new StringBuilder(b);

                var desc = "{0}; {1}; {2}".Fmt(
                        p.person.Name,
                        p.person.PrimaryAddress,
                        p.person.PrimaryZip);
                foreach (var g in p.FundItemsChosen())
                {
                    if (g.amt > 0)
                    {
                        sb.AppendFormat(row, g.desc, g.amt);
                        p.person.PostUnattendedContribution(DbUtil.Db,
                                                            g.amt,
                                                            g.fundid,
                                                            desc);
                    }
                }
                t.Financeonly = true;
                if (t.Donate > 0)
                {
                    var fundname = DbUtil.Db.ContributionFunds.Single(ff => ff.FundId == p.setting.DonationFundId).FundName;
                    sb.AppendFormat(row, fundname, t.Donate);
                    t.Fund = p.setting.DonationFund();
                    p.person.PostUnattendedContribution(DbUtil.Db,
                        t.Donate.Value,
                        p.setting.DonationFundId,
                        desc);
                }
                sb.Append(e);
                if (!t.TransactionId.HasValue())
                {
                    t.TransactionId = TransactionID;
                    if (m.testing == true && !t.TransactionId.Contains("(testing)"))
                        t.TransactionId += "(testing)";
                }
                var contributionemail = (from ex in p.person.PeopleExtras
                                         where ex.Field == "ContributionEmail"
                                         select ex.Data).SingleOrDefault();
                if (contributionemail.HasValue())
                    contributionemail = contributionemail.Trim();
                if (!Util.ValidEmail(contributionemail))
                    contributionemail = p.person.FromEmail;

                Util.SendMsg(Util.SysFromEmail, Util.Host, Util.TryGetMailAddress(DbUtil.Db.StaffEmailForOrg(p.org.OrganizationId)),
                    p.setting.Subject, sb.ToString(),
                    Util.EmailAddressListFromString(contributionemail), 0, p.PeopleId);
                DbUtil.Db.Email(contributionemail, DbUtil.Db.StaffPeopleForOrg(p.org.OrganizationId),
                    "online giving contribution received",
                    "see contribution records for {0} ({1})".Fmt(p.person.Name, p.PeopleId));
                if (p.CreatingAccount == true)
                    p.CreateAccount();
            }
            else if (managingsubs)
            {
                m.ConfirmManageSubscriptions();
                m.URL = null;
                ViewData["ManagingSubscriptions"] = true;
                ViewData["CreatedAccount"] = m.List[0].CreatingAccount;
                confirm = "ConfirmAccount";
            }
            else if (choosingslots)
            {
                m.ConfirmPickSlots();
                m.URL = null;
                ViewData["ManagingVolunteer"] = true;
                ViewData["CreatedAccount"] = m.List[0].CreatingAccount;
                confirm = "ConfirmAccount";
            }
            else if (m.OnlinePledge())
            {
                m.ConfirmManagePledge();
                ViewData["ManagingPledge"] = true;
                ViewData["CreatedAccount"] = m.List[0].CreatingAccount;
                confirm = "ConfirmAccount";
            }
            else if (m.ManageGiving())
            {
                m.ConfirmManageGiving();
                ViewData["ManagingGiving"] = true;
                ViewData["CreatedAccount"] = m.List[0].CreatingAccount;
                confirm = "ConfirmAccount";
            }
            else if (t.TransactionGateway.ToLower() == "serviceu")
            {
                t.TransactionId = TransactionID;
                if (m.testing == true && !t.TransactionId.Contains("(testing)"))
                    t.TransactionId += "(testing)";
                t.Message = "Transaction Completed";
                t.Approved = true;
                m.EnrollAndConfirm();
                if (m.List.Any(pp => pp.PeopleId == null))
                {
                    LogOutOfOnlineReg();
                    return "error: no person";
                }
                m.UseCoupon(t.TransactionId, t.Amt ?? 0);
            }
            else
            {
                if (!t.TransactionId.HasValue())
                {
                    t.TransactionId = TransactionID;
                    if (m.testing == true && !t.TransactionId.Contains("(testing)"))
                        t.TransactionId += "(testing)";
                }
                m.EnrollAndConfirm();
                if (m.List.Any(pp => pp.PeopleId == null))
                {
                    LogOutOfOnlineReg();
                    return "error: no person";
                }
                m.UseCoupon(t.TransactionId, t.Amt ?? 0);
            }
            if (m.IsCreateAccount() || m.ManagingSubscriptions())
                ViewData["email"] = m.List[0].person.EmailAddress;
            else
                ViewData["email"] = m.List[0].email;

            if(m.masterorgid.HasValue && m.orgid.HasValue && !m.settings[m.orgid.Value].Subject.HasValue())
                ViewData["orgname"] = m.masterorg.OrganizationName;
            else
                ViewData["orgname"] = m.org != null ? m.org.OrganizationName : m.masterorg.OrganizationName;

            LogOutOfOnlineReg();
            return confirm;
        }
Пример #2
0
 private ActionResult ErrorResult(OnlineRegModel m, Exception ex, string errorDisplay)
 {
     var d = new ExtraDatum { Stamp = Util.Now };
     d.Data = Util.Serialize<OnlineRegModel>(m);
     DbUtil.Db.ExtraDatas.InsertOnSubmit(d);
     DbUtil.Db.SubmitChanges();
     var ex2 = new Exception("{0}, {2}".Fmt(errorDisplay, d.Id, Util.ServerLink("/OnlineReg/RegPeople/") + d.Id), ex);
     ErrorSignal.FromCurrentContext().Raise(ex2);
     TempData["error"] = errorDisplay;
     return Content("/Error/");
 }
Пример #3
0
        public static int? BatchProcessServiceU(CsvReader csv, DateTime date)
        {
            var cols = csv.GetFieldHeaders();
            var now = DateTime.Now;

            var bh = GetBundleHeader(date, now);

            while (csv.ReadNextRecord())
            {
                string ac = null, oth = null, first = null, last = null, addr = null, name = null, email = null;
                var dt = date;
                for (var c = 1; c < csv.FieldCount; c++)
                {
                    var col = cols[c].Trim();
                    switch (col)
                    {
                        case "Date Entered":
                            dt = csv[c].ToDate() ?? date;
                            break;
                        case "ProfileID":
                            ac = csv[c];
                            break;
                        case "First Name":
                            first = csv[c];
                            break;
                        case "Last Name":
                            last = csv[c];
                            break;
                        case "Full Name":
                            name = csv[c];
                            break;
                        case "Address":
                            addr = csv[c];
                            break;
                        case "Email Address":
                            email = csv[c];
                            break;
                        case "Designation for &quot;Other&quot;":
                            oth = csv[c];
                            break;
                    }
                }
                if (ac.ToInt() == 0)
                    ac = email;
                var eac = Util.Encrypt(ac);
                var q = from kc in DbUtil.Db.CardIdentifiers
                        where kc.Id == eac
                        select kc.PeopleId;
                var pid = q.SingleOrDefault();
                string bankac = null;
                ExtraDatum ed = null;
                if (pid == null)
                {
                    bankac = eac;
                    string person;
                    if (last.HasValue())
                        person = "{1}, {0}; {2}".Fmt(first, last, addr);
                    else
                        person = "{0}; {1}".Fmt(name, addr);
                    ed = new ExtraDatum { Data = person, Stamp = Util.Now };
                }
                CmsData.BundleDetail bd = null;
                var defaultfundid = DbUtil.Db.Setting("DefaultFundId", "1").ToInt();
                for (var c = 0; c < csv.FieldCount; c++)
                {
                    var col = cols[c].Trim();
                    if (col != "Amount" && !col.Contains("Comment") && csv[c].StartsWith("$") && csv[c].GetAmount() > 0)
                    {
                        var fundid = FindFund(col);
                        bd = CreateContribution(date, fundid ?? defaultfundid);
                        bd.Contribution.ContributionAmount = csv[c].GetAmount();
                        if (col == "Other")
                            col = oth;
                        if (!fundid.HasValue)
                            bd.Contribution.ContributionDesc = col;
                        if (ac.HasValue())
                            bd.Contribution.BankAccount = bankac;
                        bd.Contribution.PeopleId = pid;
                        bh.BundleDetails.Add(bd);
                        if (ed != null)
                            bd.Contribution.ExtraDatum = ed;
                    }
                }
            }
            FinishBundle(bh);
            return bh.BundleHeaderId;
        }
Пример #4
0
        public ActionResult CompleteRegistration(OnlineRegModel m)
        {
            m.History.Add("CompleteRegistration");

            if(m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.SpecialJavascript )
            {
                SpecialRegModel.ParseResults( m.orgid ?? 0, m.UserPeopleId ?? 0, Request.Form );
                return View( "SpecialRegistrationResults" );
            }

            if (m.AskDonation() && !m.donor.HasValue && m.donation > 0)
            {
                SetHeaders(m);
                ModelState.AddModelError("donation",
                     "Please indicate a donor or clear the donation amount");
                return View("AskDonation", m);
            }

            if (m.List.Count == 0)
                return Content("Can't find any registrants");

            RemmoveLastRegistrantIfEmpty(m);

            var d = new ExtraDatum { Stamp = Util.Now };
            d.Data = Util.Serialize<OnlineRegModel>(m);
            DbUtil.Db.ExtraDatas.InsertOnSubmit(d);
            DbUtil.Db.SubmitChanges();
            DbUtil.LogActivity("Online Registration: {0} ({1})".Fmt(m.Header, d.Id));

            if (m.PayAmount() == 0 && (m.donation ?? 0) == 0 && !m.Terms.HasValue())
                return RedirectToAction("Confirm",
                     new
                     {
                         id = d.Id,
                         TransactionID = "zero due",
                     });

            var terms = Util.PickFirst(m.Terms, "");
            if (terms.HasValue())
                ViewData["Terms"] = terms;

            SetHeaders(m);
            if (m.PayAmount() == 0 && m.Terms.HasValue())
            {
                return View("Terms", new PaymentModel
                     {
                         Terms = m.Terms,
                         _URL = m.URL,
                         _timeout = INT_timeout,
                         PostbackURL = Util.ServerLink("/OnlineReg/Confirm/" + d.Id),
                     });
            }

            ViewBag.timeout = INT_timeout;
            ViewBag.Url = m.URL;

            var om =
                 DbUtil.Db.OrganizationMembers.SingleOrDefault(
                      mm => mm.OrganizationId == m.orgid && mm.PeopleId == m.List[0].PeopleId);
            m.ParseSettings();

            if (om != null && m.settings[m.orgid.Value].AllowReRegister == false)
            {
                return Content("You are already registered it appears");
            }

            var pf = PaymentForm.CreatePaymentForm(m);
            pf.DatumId = d.Id;
            pf.FormId = Guid.NewGuid();
            if (OnlineRegModel.GetTransactionGateway() == "serviceu")
                return View("Payment", pf);
            return View("ProcessPayment", pf);
        }