Example #1
0
        public void CreateTask(int forPeopleId, Person p, string description)
        {
            var t = p.AddTaskAbout(db, forPeopleId, description);

            db.SubmitChanges();
            db.Email(db.Setting("AdminMail", "*****@*****.**"), db.LoadPersonById(forPeopleId),
                     "TASK: " + description,
                     Task.TaskLink(db, description, t.Id) + "<br/>" + p.Name);
        }
Example #2
0
        // List of api functions to call from Python

        public void CreateTask(int forPeopleId, Person p, string description)
        {
            DbUtil.LogActivity("Adding Task about: {0}".Fmt(p.Name));
            var t = p.AddTaskAbout(Db, forPeopleId, description);

            Db.SubmitChanges();
            Db.Email(DbUtil.SystemEmailAddress, DbUtil.Db.LoadPersonById(forPeopleId),
                     "TASK: " + description,
                     Task.TaskLink(Db, description, t.Id) + "<br/>" + p.Name);
        }
Example #3
0
        public int DoGiving(CMSDataContext db)
        {
            var total = (from a in db.RecurringAmounts
                         where a.PeopleId == PeopleId
                         where a.ContributionFund.FundStatusId == 1
                         where a.ContributionFund.OnlineSort != null
                         select a.Amt).Sum();

            if (!total.HasValue || total == 0)
                return 0;

            var paymentInfo = db.PaymentInfos.Single(x => x.PeopleId == PeopleId);
            var preferredType = paymentInfo.PreferredGivingType;

            var gw = GetGateway(db, paymentInfo);

            var orgid = (from o in db.Organizations
                             where o.RegistrationTypeId == RegistrationTypeCode.ManageGiving
                             select o.OrganizationId).FirstOrDefault();

            var t = new Transaction
            {
                TransactionDate = DateTime.Now,
                TransactionId = "started",
                First = Person.FirstName,
                MiddleInitial = Person.MiddleName.Truncate(1) ?? "",
                Last = Person.LastName,
                Suffix = Person.SuffixCode,
                Amt = total,
                Description = "Recurring Giving",
                Testing = false,
                TransactionGateway = gw.GatewayType,
                Financeonly = true,
                PaymentType = preferredType,
                LastFourCC = preferredType == PaymentType.CreditCard ? paymentInfo.MaskedCard.Last(4) : null,
                LastFourACH = preferredType == PaymentType.Ach ? paymentInfo.MaskedAccount.Last(4) : null,
                OrgId = orgid,
            };

            db.Transactions.InsertOnSubmit(t);
            db.SubmitChanges();

            var ret = gw.PayWithVault(PeopleId, total ?? 0, "Recurring Giving", t.Id, preferredType);

            t.Message = ret.Message;
            t.AuthCode = ret.AuthCode;
            t.Approved = ret.Approved;
            t.TransactionId = ret.TransactionId;

            var gift = db.Setting("NameForPayment", "gift");
            var church = db.Setting("NameOfChurch", db.CmsHost);
            var q = from a in db.RecurringAmounts
                    where a.PeopleId == PeopleId
                    select a;
            var tot = q.Where(aa => aa.ContributionFund.FundStatusId == 1).Sum(aa => aa.Amt);
            t.TransactionPeople.Add(new TransactionPerson
            {
                PeopleId = Person.PeopleId,
                Amt = tot,
            });
            var notify = db.RecurringGivingNotifyPersons();
            var from = Util.TryGetMailAddress(notify[0].EmailAddress);
            if (ret.Approved)
            {
                foreach (var a in q)
                {
                    if (a.ContributionFund.FundStatusId == 1 && a.ContributionFund.OnlineSort != null && a.Amt > 0)
                        Person.PostUnattendedContribution(db, a.Amt ?? 0, a.FundId, "Recurring Giving", tranid: t.Id);
                }

                NextDate = FindNextDate(Util.Now.Date.AddDays(1));
                db.SubmitChanges();
                if (tot > 0)
                {
                    var msg = db.Content("RecurringGiftNotice") ?? new Content
                              { Title = $"Recurring {gift} for {{church}}",
                                Body = "Your gift of {total} was processed this morning." };
                    var subject = msg.Title.Replace("{church}", church);
                    var body = msg.Body.Replace("{total}", $"${tot:N2}");
                    var m = new EmailReplacements(db, body, from);
                    body = m.DoReplacements(db, Person);
                    db.EmailFinanceInformation(from, Person, null, subject, body);
                }
            }
            else
            {
                db.SubmitChanges();
                var msg = db.Content("RecurringGiftFailedNotice") ?? new Content
                          { Title = $"Recurring {gift} for {{church}} did not succeed",
                            Body = @"Your payment of {total} failed to process this morning.<br>
            The message was '{message}'.
            Please contact the Finance office at the church." };
                var subject = msg.Title.Replace("{church}", church);
                var body = msg.Body.Replace("{total}", $"${tot:N2}")
                    .Replace("{message}", ret.Message);
                var m = new EmailReplacements(db, body, from);
                body = m.DoReplacements(db, Person);

                db.Email(from, Person, null, subject, body, false);
                foreach (var p in db.RecurringGivingNotifyPersons())
                    db.EmailFinanceInformation(from, p, null,
                        $"Recurring Giving Failed on {db.CmsHost}",
                        $"<a href='{db.CmsHost}/Transactions/{t.Id}'>message: {ret.Message}, tranid:{t.Id}</a>");
            }
            return 1;
        }
Example #4
0
        public int DoGiving(CMSDataContext db)
        {
            var q = (from a in db.RecurringAmounts
                     where a.PeopleId == PeopleId
                     where a.ContributionFund.FundStatusId == 1
                     where a.ContributionFund.OnlineSort != null
                     where a.Amt > 0
                     select new GivingConfirmation.FundItem()
            {
                Amt = a.Amt.Value,
                Desc = a.ContributionFund.FundName,
                Fundid = a.FundId
            }).ToList();
            var total = q.Sum(vv => vv.Amt);

            if (total == 0)
            {
                return(0);
            }

            var paymentInfo   = db.PaymentInfos.Single(x => x.PeopleId == PeopleId);
            var preferredType = paymentInfo.PreferredGivingType ?? paymentInfo.PreferredPaymentType;

            var gw = GetGateway(db, paymentInfo);

            var orgid = (from o in db.Organizations
                         where o.RegistrationTypeId == RegistrationTypeCode.ManageGiving
                         select o.OrganizationId).FirstOrDefault();

            var t = new Transaction
            {
                TransactionDate    = DateTime.Now,
                TransactionId      = "started",
                First              = Person.FirstName,
                MiddleInitial      = Person.MiddleName.Truncate(1) ?? "",
                Last               = Person.LastName,
                Suffix             = Person.SuffixCode,
                Amt                = total,
                Description        = "Recurring Giving",
                Testing            = false,
                TransactionGateway = gw.GatewayType,
                Financeonly        = true,
                PaymentType        = preferredType,
                LastFourCC         = preferredType == PaymentType.CreditCard ? paymentInfo.MaskedCard.Last(4) : null,
                LastFourACH        = preferredType == PaymentType.Ach ? paymentInfo.MaskedAccount.Last(4) : null,
                OrgId              = orgid,
                LoginPeopleId      = Person.PeopleId,
            };

            var vaultid = gw.VaultId(PeopleId);

            if (!vaultid.HasValue())
            {
                t.Message  = "Missing VaultId";
                t.Approved = false;
            }
            db.Transactions.InsertOnSubmit(t);
            db.SubmitChanges();
            if (!vaultid.HasValue())
            {
                return(0);
            }

            var ret = gw.PayWithVault(PeopleId, total, "Recurring Giving", t.Id, preferredType);

            t.Message       = ret.Message;
            t.AuthCode      = ret.AuthCode;
            t.Approved      = ret.Approved;
            t.TransactionId = ret.TransactionId;

            var gift   = db.Setting("NameForPayment", "gift");
            var church = db.Setting("NameOfChurch", db.CmsHost);
            var notify = db.RecurringGivingNotifyPersons();
            var staff  = notify[0];
            var from   = Util.TryGetMailAddress(staff.EmailAddress);

            if (ret.Approved)
            {
                NextDate = FindNextDate(Util.Now.Date.AddDays(1));
                db.SubmitChanges();
                var msg = db.Content("RecurringGiftNotice") ?? new Content
                {
                    Title = $"Recurring {gift} for {{church}}",
                    Body  = $"Your gift of {total:C} was processed this morning."
                };
                var body    = GivingConfirmation.PostAndBuild(db, staff, Person, msg.Body, orgid, q, t, "Recurring Giving");
                var subject = msg.Title.Replace("{church}", church);
                var m       = new EmailReplacements(db, body, from);
                body = m.DoReplacements(db, Person);
                db.EmailFinanceInformation(from, Person, null, subject, body);
            }
            else
            {
                t.TransactionPeople.Add(new TransactionPerson
                {
                    PeopleId = Person.PeopleId,
                    Amt      = t.Amt,
                    OrgId    = orgid,
                });
                db.SubmitChanges();
                var msg = db.Content("RecurringGiftFailedNotice") ?? new Content
                {
                    Title = $"Recurring {gift} for {{church}} did not succeed",
                    Body  = @"Your payment of {total} failed to process this morning.<br>
The message was '{message}'.
Please contact the Finance office at the church."
                };
                var subject = msg.Title.Replace("{church}", church);
                var body    = msg.Body.Replace("{total}", $"${total:N2}")
                              .Replace("{message}", ret.Message);
                var m = new EmailReplacements(db, body, from);
                body = m.DoReplacements(db, Person);

                db.Email(from, Person, null, subject, body, false);
                foreach (var p in db.RecurringGivingNotifyPersons())
                {
                    db.EmailFinanceInformation(from, p, null,
                                               $"Recurring Giving Failed on {db.CmsHost}",
                                               $"<a href='{db.CmsHost}/Transactions/{t.Id}'>message: {ret.Message}, tranid:{t.Id}</a>");
                }
            }
            return(1);
        }
Example #5
0
        public static Person Add(CMSDataContext Db, bool SendNotices, Family fam, int position, Tag tag, string firstname, string nickname, string lastname, string dob, int MarriedCode, int gender, int originId, int? EntryPointId, bool testing = false)
        {
            var p = new Person();
            p.CreatedDate = Util.Now;
            p.CreatedBy = Util.UserId;
            Db.People.InsertOnSubmit(p);
            p.PositionInFamilyId = position;
            p.AddressTypeId = 10;

            if (Util.HasValue(firstname))
                p.FirstName = firstname.Trim().ToProper().Truncate(25);
            else
                p.FirstName = "";

            if (Util.HasValue(nickname))
                p.NickName = nickname.Trim().ToProper().Truncate(15);

            if (Util.HasValue(lastname))
                p.LastName = lastname.Trim().ToProper().Truncate(30);
            else
                p.LastName = "?";

            p.GenderId = gender;
            if (p.GenderId == 99)
                p.GenderId = 0;
            p.MaritalStatusId = MarriedCode;

            DateTime dt;
            if (Util.BirthDateValid(dob, out dt))
            {
                if (dt.Year == Util.SignalNoYear)
                {
                    p.BirthDay = dt.Day;
                    p.BirthMonth = dt.Month;
                    p.BirthYear = null;
                }
                else
                {
                    while (dt.Year < 1900)
                        dt = dt.AddYears(100);
                    if (dt > Util.Now)
                        dt = dt.AddYears(-100);
                    p.BirthDay = dt.Day;
                    p.BirthMonth = dt.Month;
                    p.BirthYear = dt.Year;
                }
                if (p.GetAge() < 18 && MarriedCode == 0)
                    p.MaritalStatusId = MaritalStatusCode.Single;
            }
                // I think this else statement is no longer necessary
            else if (DateTime.TryParse(dob, out dt))
            {
                p.BirthDay = dt.Day;
                p.BirthMonth = dt.Month;
                if (Regex.IsMatch(dob, @"\d+[-/]\d+[-/]\d+"))
                {
                    p.BirthYear = dt.Year;
                    while (p.BirthYear < 1900)
                        p.BirthYear += 100;
                    if (p.GetAge() < 18 && MarriedCode == 0)
                        p.MaritalStatusId = MaritalStatusCode.Single;
                }
            }

            p.MemberStatusId = MemberStatusCode.JustAdded;
            if (fam == null)
            {
                fam = new Family();
                Db.Families.InsertOnSubmit(fam);
                p.Family = fam;
            }
            else
                fam.People.Add(p);

            if (tag != null)
                tag.PersonTags.Add(new TagPerson { Person = p });

            p.OriginId = originId;
            p.EntryPointId = EntryPointId;
            p.FixTitle();
            if(Db.Setting("ElectronicStatementDefault", "false").Equal("true"))
                p.ElectronicStatement = true;
            if (!testing)
                Db.SubmitChanges();
            if (SendNotices)
            {
                if (Util.UserPeopleId.HasValue
                    && Util.UserPeopleId.Value != Db.NewPeopleManagerId
                    && HttpContext.Current.User.IsInRole("Access")
                    && !HttpContext.Current.User.IsInRole("OrgMembersOnly")
                    && !HttpContext.Current.User.IsInRole("OrgLeadersOnly"))
                    Task.AddNewPerson(Db, p.PeopleId);
                else
                {
                    var np = Db.GetNewPeopleManagers();
                    if (np != null)
                        Db.Email(Util.SysFromEmail, np,
                            $"Just Added Person on {Db.Host}",
                            $"<a href='{Db.ServerLink("/Person2/" + p.PeopleId)}'>{p.Name}</a>");
                }
            }
            return p;
        }
Example #6
0
        public static Person Add(CMSDataContext Db, bool SendNotices, Family fam, int position, Tag tag, string firstname, string nickname, string lastname, string dob, int MarriedCode, int gender, int originId, int? EntryPointId, bool testing = false)
        {
            var p = new Person();
            p.CreatedDate = Util.Now;
            p.CreatedBy = Util.UserId;
            Db.People.InsertOnSubmit(p);
            p.PositionInFamilyId = position;
            p.AddressTypeId = 10;

            if (firstname.HasValue())
                p.FirstName = firstname.Trim().ToProper().Truncate(25);
            else
                p.FirstName = "";

            if (nickname.HasValue())
                p.NickName = nickname.Trim().ToProper().Truncate(15);

            if (lastname.HasValue())
                p.LastName = lastname.Trim().ToProper().Truncate(30);
            else
                p.LastName = "?";

            p.GenderId = gender;
            if (p.GenderId == 99)
                p.GenderId = 0;
            p.MaritalStatusId = MarriedCode;

            DateTime dt;
            if (Util.DateValid(dob, out dt))
            {
                while (dt.Year < 1900)
                    dt = dt.AddYears(100);
                if (dt > Util.Now)
                    dt = dt.AddYears(-100);
                p.BirthDay = dt.Day;
                p.BirthMonth = dt.Month;
                p.BirthYear = dt.Year;
                if (p.GetAge() < 18 && MarriedCode == 0)
                    p.MaritalStatusId = MaritalStatusCode.Single;
            }
            else if (DateTime.TryParse(dob, out dt))
            {
                p.BirthDay = dt.Day;
                p.BirthMonth = dt.Month;
                if (Regex.IsMatch(dob, @"\d+[-/]\d+[-/]\d+"))
                {
                    p.BirthYear = dt.Year;
                    while (p.BirthYear < 1900)
                        p.BirthYear += 100;
                    if (p.GetAge() < 18 && MarriedCode == 0)
                        p.MaritalStatusId = MaritalStatusCode.Single;
                }
            }

            p.MemberStatusId = MemberStatusCode.JustAdded;
            if (fam == null)
            {
                fam = new Family();
                Db.Families.InsertOnSubmit(fam);
                p.Family = fam;
            }
            else
                fam.People.Add(p);

            var PrimaryCount = fam.People.Where(c => c.PositionInFamilyId == PositionInFamily.PrimaryAdult).Count();
            if (PrimaryCount > 2 && p.PositionInFamilyId == PositionInFamily.PrimaryAdult)
                p.PositionInFamilyId = PositionInFamily.SecondaryAdult;

            if (tag != null)
                tag.PersonTags.Add(new TagPerson { Person = p });

            p.OriginId = originId;
            p.EntryPointId = EntryPointId;
            p.FixTitle();
            if (!testing)
                Db.SubmitChanges();
            if (SendNotices)
            {
                if (Util.UserPeopleId.HasValue
                        && Util.UserPeopleId.Value != Db.NewPeopleManagerId
                        && HttpContext.Current.User.IsInRole("Access")
                        && !HttpContext.Current.User.IsInRole("OrgMembersOnly")
                        && !HttpContext.Current.User.IsInRole("OrgLeadersOnly"))
                    Task.AddNewPerson(p.PeopleId);
                else
                    Db.Email(Util.SysFromEmail, Db.GetNewPeopleManagers(),
                            "Just Added Person on " + Db.Host, "{0} ({1})".Fmt(p.Name, p.PeopleId));
            }
            return p;
        }
Example #7
0
        public int DoGiving(CMSDataContext db)
        {
            var total = (from a in db.RecurringAmounts
                         where a.PeopleId == PeopleId
                         where a.ContributionFund.FundStatusId == 1
                         where a.ContributionFund.OnlineSort != null
                         select a.Amt).Sum();

            if (!total.HasValue || total == 0)
            {
                return(0);
            }

            var paymentInfo   = db.PaymentInfos.Single(x => x.PeopleId == PeopleId);
            var preferredType = paymentInfo.PreferredGivingType;

            var gw = GetGateway(db, paymentInfo);

            var t = new Transaction
            {
                TransactionDate    = DateTime.Now,
                TransactionId      = "started",
                First              = Person.FirstName,
                MiddleInitial      = Person.MiddleName.Truncate(1) ?? "",
                Last               = Person.LastName,
                Suffix             = Person.SuffixCode,
                Amt                = total,
                Description        = "Recurring Giving",
                Testing            = false,
                TransactionGateway = gw.GatewayType,
                Financeonly        = true,
                PaymentType        = preferredType,
                LastFourCC         = preferredType == PaymentType.CreditCard ? paymentInfo.MaskedCard.Last(4) : null,
                LastFourACH        = preferredType == PaymentType.Ach ? paymentInfo.MaskedAccount.Last(4) : null
            };

            db.Transactions.InsertOnSubmit(t);
            db.SubmitChanges();

            var ret = gw.PayWithVault(PeopleId, total ?? 0, "Recurring Giving", t.Id, preferredType);

            t.Message       = ret.Message;
            t.AuthCode      = ret.AuthCode;
            t.Approved      = ret.Approved;
            t.TransactionId = ret.TransactionId;

            var gift   = db.Setting("NameForPayment", "gift");
            var church = db.Setting("NameOfChurch", db.CmsHost);
            var q      = from a in db.RecurringAmounts
                         where a.PeopleId == PeopleId
                         select a;
            var tot = q.Where(aa => aa.ContributionFund.FundStatusId == 1).Sum(aa => aa.Amt);

            t.TransactionPeople.Add(new TransactionPerson
            {
                PeopleId = Person.PeopleId,
                Amt      = tot,
            });
            var notify = db.RecurringGivingNotifyPersons();
            var from   = Util.TryGetMailAddress(notify[0].EmailAddress);

            if (ret.Approved)
            {
                foreach (var a in q)
                {
                    if (a.ContributionFund.FundStatusId == 1 && a.ContributionFund.OnlineSort != null && a.Amt > 0)
                    {
                        Person.PostUnattendedContribution(db, a.Amt ?? 0, a.FundId, "Recurring Giving", tranid: t.Id);
                    }
                }

                NextDate = FindNextDate(Util.Now.Date.AddDays(1));
                db.SubmitChanges();
                if (tot > 0)
                {
                    var msg = db.Content("RecurringGiftNotice") ?? new Content
                    {
                        Title = $"Recurring {gift} for {{church}}",
                        Body  = "Your gift of {total} was processed this morning."
                    };
                    var subject = msg.Title.Replace("{church}", church);
                    var body    = msg.Body.Replace("{total}", $"${tot:N2}");
                    var m       = new EmailReplacements(db, body, from);
                    body = m.DoReplacements(db, Person);
                    db.EmailFinanceInformation(from, Person, null, subject, body);
                }
            }
            else
            {
                db.SubmitChanges();
                var msg = db.Content("RecurringGiftFailedNotice") ?? new Content
                {
                    Title = $"Recurring {gift} for {{church}} did not succeed",
                    Body  = @"Your payment of {total} failed to process this morning.<br>
The message was '{message}'.
Please contact the Finance office at the church."
                };
                var subject = msg.Title.Replace("{church}", church);
                var body    = msg.Body.Replace("{total}", $"${tot:N2}")
                              .Replace("{message}", ret.Message);
                var m = new EmailReplacements(db, body, from);
                body = m.DoReplacements(db, Person);

                db.Email(from, Person, null, subject, body, false);
                foreach (var p in db.RecurringGivingNotifyPersons())
                {
                    db.EmailFinanceInformation(from, p, null,
                                               $"Recurring Giving Failed on {db.CmsHost}",
                                               $"<a href='{db.CmsHost}/Transactions/{t.Id}'>message: {ret.Message}, tranid:{t.Id}</a>");
                }
            }
            return(1);
        }