Exemple #1
0
        private BundleHeader CreateBundle(DateTime CreatedOn, decimal?BundleTotal, decimal?TotalCash, decimal?TotalChecks, string RefId, int?RefIdType)
        {
            // create a touchpoint bundle
            BundleHeader bh = new BundleHeader
            {
                ChurchId           = 1,
                CreatedBy          = 1,
                CreatedDate        = CreatedOn,
                RecordStatus       = false,
                BundleStatusId     = BundleStatusCode.OpenForDataEntry,
                ContributionDate   = CreatedOn,
                BundleHeaderTypeId = BundleTypeCode.Online,
                DepositDate        = null,
                BundleTotal        = BundleTotal,
                TotalCash          = TotalCash,
                TotalChecks        = TotalChecks,
                ReferenceId        = RefId,
                ReferenceIdType    = RefIdType
            };

            db.BundleHeaders.InsertOnSubmit(bh);
            db.SubmitChanges();
            return(bh);
        }
Exemple #2
0
        private static int?BatchProcessFbcStark2(string text, DateTime date, int?fundid)
        {
            var          prevdt = DateTime.MinValue;
            BundleHeader bh     = null;
            var          sr     = new StringReader(text);
            string       line   = "";

            do
            {
                line = sr.ReadLine();
                if (line == null)
                {
                    return(null);
                }
            } while (!line.StartsWith("Batch ID"));
            var sep = ',';

            if (line.StartsWith("Batch ID\t"))
            {
                sep = '\t';
            }

            for (; ;)
            {
                line = sr.ReadLine();
                if (line == null)
                {
                    break;
                }

                var csv = line.Split(sep);
                var bd  = new BundleDetail
                {
                    CreatedBy   = Util.UserId,
                    CreatedDate = DateTime.Now,
                };
                var qf = from f in DbUtil.Db.ContributionFunds
                         where f.FundStatusId == 1
                         orderby f.FundId
                         select f.FundId;

                bd.Contribution = new Contribution
                {
                    CreatedBy            = Util.UserId,
                    CreatedDate          = DateTime.Now,
                    ContributionDate     = date,
                    FundId               = fundid ?? qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash,
                };

                var s  = csv[3];
                var m  = s.Substring(0, 2).ToInt();
                var d  = s.Substring(2, 2).ToInt();
                var y  = s.Substring(4, 2).ToInt() + 2000;
                var dt = new DateTime(y, m, d);

                if (dt != prevdt)
                {
                    if (bh != null)
                    {
                        BatchImportContributions.FinishBundle(bh);
                    }

                    bh     = BatchImportContributions.GetBundleHeader(dt, DateTime.Now);
                    prevdt = dt;
                }

                var rt = csv[7];
                var ac = csv[8];
                var ck = csv[9];
                bd.Contribution.ContributionAmount = csv[10].GetAmount();

                bd.Contribution.CheckNo = ck;
                var eac = Util.Encrypt(rt + "|" + ac);
                var q   = from kc in DbUtil.Db.CardIdentifiers
                          where kc.Id == eac
                          select kc.PeopleId;
                var pid = q.SingleOrDefault();
                if (pid != null)
                {
                    bd.Contribution.PeopleId = pid;
                }

                bd.Contribution.BankAccount = eac;
                bh.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Exemple #3
0
        public void DeleteContributionWithTagsTest()
        {
            using (var db = CMSDataContext.Create(DatabaseFixture.Host))
            {
                var bundle = new BundleHeader
                {
                    ChurchId           = 1,
                    CreatedBy          = 1,
                    CreatedDate        = DateTime.Now,
                    RecordStatus       = false,
                    BundleStatusId     = BundleStatusCode.OpenForDataEntry,
                    ContributionDate   = DateTime.Now,
                    BundleHeaderTypeId = BundleTypeCode.Online,
                    DepositDate        = null,
                    BundleTotal        = 0,
                    TotalCash          = 0,
                    TotalChecks        = 0
                };

                db.BundleHeaders.InsertOnSubmit(bundle);
                db.SubmitChanges();

                var contribution = new Contribution
                {
                    PeopleId             = 1,
                    ContributionDate     = DateTime.Now,
                    ContributionAmount   = 50,
                    ContributionTypeId   = ContributionTypeCode.Online,
                    ContributionStatusId = ContributionStatusCode.Recorded,
                    CreatedDate          = DateTime.Now,
                    FundId = 1
                };

                db.Contributions.InsertOnSubmit(contribution);
                db.SubmitChanges();

                BundleDetail bd = new BundleDetail
                {
                    BundleHeaderId = bundle.BundleHeaderId,
                    ContributionId = contribution.ContributionId,
                    CreatedBy      = 1,
                    CreatedDate    = DateTime.Now
                };
                db.BundleDetails.InsertOnSubmit(bd);
                bundle.BundleDetails.Add(bd);

                var tag = new ContributionTag
                {
                    ContributionId = contribution.ContributionId,
                    TagName        = "Tag Test"
                };

                db.ContributionTags.InsertOnSubmit(tag);
                db.SubmitChanges();

                var model = new PostBundleModel(db, bundle.BundleHeaderId);
                model.editid = contribution.ContributionId;
                model.DeleteContribution();

                db.ContributionTags.SingleOrDefault(t => t.ContributionId == contribution.ContributionId).ShouldBeNull();
                db.Contributions.SingleOrDefault(c => c.ContributionId == contribution.ContributionId).ShouldBeNull();

                // cleanup
                db.BundleDetails.DeleteOnSubmit(bd);
                db.BundleHeaders.DeleteOnSubmit(bundle);
                db.SubmitChanges();
            }
        }
Exemple #4
0
        public static int?RunImport(CsvReader csv, DateTime date, int?fundid)
        {
            var          prevbundle = -1;
            var          curbundle  = 0;
            BundleHeader bh         = null;

            var fieldCount = csv.FieldCount;
            var cols       = csv.GetFieldHeaders();

            while (csv.ReadNextRecord())
            {
                var bd = new BundleDetail
                {
                    CreatedBy   = Util.UserId,
                    CreatedDate = DateTime.Now
                };
                var qf = from f in DbUtil.Db.ContributionFunds
                         where f.FundStatusId == 1
                         orderby f.FundId
                         select f.FundId;

                bd.Contribution = new Contribution
                {
                    CreatedBy            = Util.UserId,
                    CreatedDate          = DateTime.Now,
                    ContributionDate     = date,
                    FundId               = fundid ?? qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash
                };
                string ac = null, rt = null, ck = null;
                for (var c = 1; c < fieldCount; c++)
                {
                    switch (cols[c])
                    {
                    case "DEPOSIT NUMBER":
                        curbundle = csv[c].ToInt();
                        if (curbundle != prevbundle)
                        {
                            if (bh != null)
                            {
                                BatchImportContributions.FinishBundle(bh);
                            }
                            bh         = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                            prevbundle = curbundle;
                        }
                        break;

                    case "AMOUNT":
                        bd.Contribution.ContributionAmount = csv[c].GetAmount();
                        break;

                    case "CHECK NUMBER":
                        ck = csv[c];
                        break;

                    case "ROUTING NUMBER":
                        rt = csv[c];
                        break;

                    case "ACCOUNT NUMBER":
                        ac = csv[c];
                        break;
                    }
                }
                if (!ck.HasValue())
                {
                    if (ac.Contains(' '))
                    {
                        var a = ac.SplitStr(" ", 2);
                        ck = a[0];
                        ac = a[1];
                    }
                }

                var eac = Util.Encrypt(rt + "|" + ac);
                var q   = from kc in DbUtil.Db.CardIdentifiers
                          where kc.Id == eac
                          select kc.PeopleId;
                var pid = q.SingleOrDefault();
                if (pid != null)
                {
                    bd.Contribution.PeopleId = pid;
                }
                bd.Contribution.BankAccount = eac;
                bd.Contribution.CheckNo     = ck;
                bh.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Exemple #5
0
        public ActionResult Upload(string data)
        {
            CheckScanAuthentication authentication = new CheckScanAuthentication();

            authentication.authenticate();

            if (authentication.hasError())
            {
                return(CheckScanMessage.createLoginErrorReturn(authentication));
            }

            User user = authentication.getUser();

            if (!user.InRole("Finance"))
            {
                return(CheckScanMessage.createErrorReturn("Finance role is required for check scanning"));
            }

            CheckInMessage message = CheckInMessage.createFromString(data);

            List <CheckScanEntry> entries = JsonConvert.DeserializeObject <List <CheckScanEntry> >(message.data);

            BundleHeader header;

            if (message.id == 0)
            {
                header = new BundleHeader
                {
                    BundleHeaderTypeId = 1,
                    BundleStatusId     = BundleStatusCode.Open,
                    CreatedBy          = user.UserId,
                    ContributionDate   = DateTime.Now,
                    CreatedDate        = DateTime.Now,
                    FundId             = CurrentDatabase.Setting("DefaultFundId", "1").ToInt(),
                    RecordStatus       = false,
                    TotalCash          = 0,
                    TotalChecks        = 0,
                    TotalEnvelopes     = 0,
                    BundleTotal        = 0
                };

                CurrentDatabase.BundleHeaders.InsertOnSubmit(header);
                CurrentDatabase.SubmitChanges();
            }
            else
            {
                header = (from h in CurrentDatabase.BundleHeaders
                          where h.BundleHeaderId == message.id
                          select h).FirstOrDefault();
            }

            CheckScanMessage response = new CheckScanMessage();

            if (header != null)
            {
                foreach (CheckScanEntry entry in entries)
                {
                    Other other = new Other();
                    other.Created = DateTime.Now;
                    other.UserID  = user.UserId;

                    if (entry.front.Length > 0)
                    {
                        other.First = Convert.FromBase64String(entry.front);
                    }

                    if (entry.back.Length > 0)
                    {
                        other.Second = Convert.FromBase64String(entry.back);
                    }
                    CurrentImageDatabase.Others.InsertOnSubmit(other);
                    CurrentImageDatabase.SubmitChanges();

                    var detail = new BundleDetail
                    {
                        BundleHeaderId = header.BundleHeaderId,
                        CreatedBy      = user.UserId,
                        CreatedDate    = DateTime.Now
                    };

                    string bankAccount = entry.routing.Length > 0 && entry.account.Length > 0 ? Util.Encrypt(entry.routing + "|" + entry.account) : "";

                    detail.Contribution = new Contribution
                    {
                        CreatedBy            = user.UserId,
                        CreatedDate          = detail.CreatedDate,
                        FundId               = header.FundId ?? 0,
                        PeopleId             = FindPerson(CurrentDatabase, entry.routing, entry.account),
                        ContributionDate     = header.ContributionDate,
                        ContributionAmount   = decimal.Parse(entry.amount),
                        ContributionStatusId = 0,
                        ContributionTypeId   = 1,
                        ContributionDesc     = entry.notes,
                        CheckNo              = entry.number,
                        BankAccount          = bankAccount,
                        ImageID              = other.Id
                    };

                    header.BundleDetails.Add(detail);

                    CurrentDatabase.SubmitChanges();
                }

                response.setSuccess();
                response.id = header.BundleHeaderId;
            }
            else
            {
                response.setError(1, "Invalid Bundle ID");
            }

            return(response);
        }
Exemple #6
0
        public static int?BatchProcessBankOfNorthGeorgia(string text, DateTime date, int?fundid)
        {
            BundleHeader bh   = null;
            var          sr   = new StringReader(text);
            string       line = "";

            do
            {
                line = sr.ReadLine();
                if (line == null)
                {
                    return(null);
                }
            } while (!line.Contains("Item ID"));
            var sep = ',';

            if (line.Contains("Item ID\t"))
            {
                sep = '\t';
            }

            for (; ;)
            {
                line = sr.ReadLine();
                if (line == null)
                {
                    break;
                }
                line = line.TrimStart();
                var csv = line.Split(sep);
                if (!csv[6].HasValue())
                {
                    continue;
                }

                if (csv[21] == "VDP")
                {
                    if (bh != null)
                    {
                        FinishBundle(bh);
                    }
                    bh = GetBundleHeader(date, DateTime.Now);
                    continue;
                }

                var bd = new BundleDetail
                {
                    CreatedBy   = Util.UserId,
                    CreatedDate = DateTime.Now,
                };
                var qf = from f in DbUtil.Db.ContributionFunds
                         where f.FundStatusId == 1
                         orderby f.FundId
                         select f.FundId;

                bd.Contribution = new Contribution
                {
                    CreatedBy            = Util.UserId,
                    CreatedDate          = DateTime.Now,
                    ContributionDate     = date,
                    FundId               = fundid ?? qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash,
                };


                string ck, rt, ac;
                rt = csv[14];
                ac = csv[20];
                ck = csv[17];
                bd.Contribution.ContributionAmount = csv[9].GetAmount();

                bd.Contribution.CheckNo = ck;
                var eac = Util.Encrypt(rt + "|" + ac);
                var q   = from kc in DbUtil.Db.CardIdentifiers
                          where kc.Id == eac
                          select kc.PeopleId;
                var pid = q.SingleOrDefault();
                if (pid != null)
                {
                    bd.Contribution.PeopleId = pid;
                }
                bd.Contribution.BankAccount = eac;
                bh.BundleDetails.Add(bd);
            }
            FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Exemple #7
0
        private void UploadPledges(UploadPeopleRun rt, ExcelPackage pkg)
        {
            //var db = DbUtil.Create(Host);
            var data = FetchPledgeData(pkg.Workbook.Worksheets["Pledges"]).ToList();

            rt.Count       = data.Count;
            rt.Description = $"Uploading Pledges {(Testing ? "in testing mode" : "for real")}";
            rt.Processed   = 0;
            Db2.SubmitChanges();

            var weeks = (from g in data
                         group g by g.Date.Sunday() into weeklypledges
                         select weeklypledges).ToList();
            BundleHeader bh = null;
            var          c  = Db2.Content("OrphanedPledges", "---", ContentTypeCode.TypeText);

            c.Body = "";
            Db2.SubmitChanges();
            foreach (var week in weeks)
            {
                FinishBundle(Db2, bh);
                //if (!Testing)
                //{
                //    Db2.Dispose();
                //    db = DbUtil.Create(Host);
                //}
                bh = new BundleHeader
                {
                    BundleHeaderTypeId = BundleTypeCode.Pledge,
                    BundleStatusId     = BundleStatusCode.Closed,
                    CreatedBy          = Util.UserId,
                    CreatedDate        = DateTime.Today,
                    ContributionDate   = week.Key,
                };
                foreach (var pledge in week)
                {
                    var pid = GetPeopleId(pledge);
                    var f   = new ContributionFund {
                        FundId = 0
                    };
                    if (!Testing)
                    {
                        if (!pid.HasValue)
                        {
                            if (IgnoreMissingGifts)
                            {
                                c       = Db2.Content("OrphanedPledges");
                                c.Body += $"{pledge.IndividualId} {pledge.Date:d} {pledge.Amount:C}\n";
                                Db2.SubmitChanges();
                                continue;
                            }
                            else
                            {
                                throw new Exception($"peopleid not found from individualid {pledge.IndividualId}");
                            }
                        }

                        f = Db2.FetchOrCreateFund(pledge.FundId, pledge.FundName ?? pledge.FundDescription);
                        f.FundPledgeFlag = true;
                    }
                    var bd = new BundleDetail();
                    bd.CreatedBy    = Util.UserId;
                    bd.CreatedDate  = DateTime.Now;
                    bd.Contribution = new Contribution
                    {
                        CreatedBy            = Util.UserId,
                        CreatedDate          = DateTime.Now,
                        ContributionDate     = pledge.Date,
                        FundId               = f.FundId,
                        ContributionStatusId = 0,
                        ContributionTypeId   = ContributionTypeCode.Pledge,
                        ContributionAmount   = pledge.Amount,
                        PeopleId             = pid
                    };
                    bh.BundleDetails.Add(bd);
                    rt.Processed++;
                    Db2.SubmitChanges();
                }
            }
            FinishBundle(Db2, bh);
            //if (!Testing)
            //{
            //    DbUtil.Db.Dispose();
            //}
        }
        private static int?BatchProcessDiscoverCrosspoint(string text, DateTime date, int?fundid)
        {
            var          db     = DbUtil.Db;
            var          prevdt = DateTime.MinValue;
            BundleHeader bh     = null;
            var          sr     = new StringReader(text);

            for (; ;)
            {
                var line = sr.ReadLine();
                if (line == null)
                {
                    break;
                }
                var csv = line.Split(',');
                var bd  = new BundleDetail
                {
                    CreatedBy   = db.UserId,
                    CreatedDate = DateTime.Now,
                };
                var qf = from f in db.ContributionFunds
                         where f.FundStatusId == 1
                         orderby f.FundId
                         select f.FundId;

                bd.Contribution = new Contribution
                {
                    CreatedBy            = db.UserId,
                    CreatedDate          = DateTime.Now,
                    ContributionDate     = date,
                    FundId               = fundid ?? qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash,
                };

                var dt = csv[2].ToDate().Value;

                if (dt != prevdt)
                {
                    if (bh != null)
                    {
                        BatchImportContributions.FinishBundle(bh);
                    }
                    bh     = BatchImportContributions.GetBundleHeader(dt, DateTime.Now);
                    prevdt = dt;
                }
                bd.Contribution.ContributionAmount = csv[1].ToDecimal();

                var ck = csv[3];
                var rt = csv[4];
                var ac = csv[0];

                bd.Contribution.CheckNo = ck;
                var eac = Util.Encrypt(rt + "|" + ac);
                var q   = from kc in db.CardIdentifiers
                          where kc.Id == eac
                          select kc.PeopleId;
                var pid = q.SingleOrDefault();
                if (pid != null)
                {
                    bd.Contribution.PeopleId = pid;
                }
                bd.Contribution.BankAccount = eac;
                bh.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Exemple #9
0
        public static int?BatchProcessFbcStark(string text, DateTime date, int?fundid)
        {
            var          prevdt = DateTime.MinValue;
            BundleHeader bh     = null;
            var          sr     = new StringReader(text);

            for (; ;)
            {
                var line = sr.ReadLine();
                if (line == null)
                {
                    break;
                }
                var csv = line.Split(',');
                var bd  = new BundleDetail
                {
                    CreatedBy   = Util.UserId,
                    CreatedDate = DateTime.Now,
                };
                var qf = from f in DbUtil.Db.ContributionFunds
                         where f.FundStatusId == 1
                         orderby f.FundId
                         select f.FundId;

                bd.Contribution = new Contribution
                {
                    CreatedBy            = Util.UserId,
                    CreatedDate          = DateTime.Now,
                    ContributionDate     = date,
                    FundId               = fundid ?? qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash,
                };

                var dtint = csv[3].ToLong();
                var y     = (int)(dtint % 10000);
                var m     = (int)(dtint / 1000000);
                var d     = (int)(dtint / 10000) % 100;
                var dt    = new DateTime(y, m, d);

                if (dt != prevdt)
                {
                    if (bh != null)
                    {
                        FinishBundle(bh);
                    }
                    bh     = GetBundleHeader(dt, DateTime.Now);
                    prevdt = dt;
                }
                bd.Contribution.ContributionAmount = csv[5].GetAmount() / 100;

                string ck, rt, ac;
                ck = csv[4];
                rt = csv[6];
                ac = csv[7];

                bd.Contribution.CheckNo = ck;
                var eac = Util.Encrypt(rt + "|" + ac);
                var q   = from kc in DbUtil.Db.CardIdentifiers
                          where kc.Id == eac
                          select kc.PeopleId;
                var pid = q.SingleOrDefault();
                if (pid != null)
                {
                    bd.Contribution.PeopleId = pid;
                }
                bd.Contribution.BankAccount = eac;
                bh.BundleDetails.Add(bd);
            }
            FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
        public static int?BatchProcessStewardshipTechnology(CsvReader csv, DateTime date, int?fundid)
        {
            var fundList = (from f in DbUtil.Db.ContributionFunds
                            select new
            {
                f.FundId,
                f.FundName
            }).ToList();

            var          cols      = csv.GetFieldHeaders();
            BundleHeader bh        = null;
            var          firstfund = FirstFundId();

            var list = new List <depositRecord>();

            csv.ReadNextRecord();
            while (csv.ReadNextRecord())
            {
                list.Add(new depositRecord()
                {
                    date    = csv[1].ToDate(),
                    account = csv[6],
                    amount  = csv[2],
                    checkno = csv[0],
                    type    = csv[3],
                });
            }
            DateTime?prevbatch = null;

            foreach (var r in list.OrderBy(rr => rr.date))
            {
                if (r.date != prevbatch)
                {
                    if (bh != null)
                    {
                        FinishBundle(bh);
                    }
                    bh             = GetBundleHeader(r.date ?? date, DateTime.Now, BundleTypeCode.Online);
                    bh.DepositDate = r.date;
                    prevbatch      = r.date;
                }

                BundleDetail bd;

                var fid = (from f in fundList
                           where f.FundName == r.type
                           select f.FundId).SingleOrDefault();
                if (fid > 0)
                {
                    bd = AddContributionDetail(r.date ?? date, fid, r.amount, r.checkno, "", r.account);
                }
                else
                {
                    bd = AddContributionDetail(r.date ?? date, fundid ?? firstfund, r.amount, r.checkno, "", r.account);
                    bd.Contribution.ContributionDesc = "Used default fund (fund requested: {0})".Fmt(r.type);
                }
                bh.BundleDetails.Add(bd);
            }
            FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
        private static int?BatchProcess(CsvReader csv, DateTime date, int?fundid)
        {
            BundleHeader bh   = null;
            var          fid  = fundid ?? BatchImportContributions.FirstFundId();
            var          now  = DateTime.Now;
            var          list = new List <Record>();

            // for parsing account and checkno
            var regex = new Regex(Patterns, RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);

            csv.Read();
            csv.ReadHeader();
            csv.Read(); // read header;
            var newBundle = true;

            while (csv.Read())
            {
                if (csv[4] == "Bank On Us")
                {
                    csv.Read(); // read the next row past the header row
                    newBundle = true;
                }

                var rec = new Record
                {
                    Dt        = csv[1].PadLeft(8, '0').ToDate(),
                    Amount    = csv[5],
                    Routing   = csv[3],
                    AccCk     = csv[4],
                    NewBundle = newBundle,
                };
                // Parse out account and checkno
                var m = regex.Match(rec.AccCk);
                if (!m.Success)
                {
                    throw new Exception($@"account **""{rec.AccCk}""**, does not match known patterns, contact support with this information.

No Contributions have been imported from this batch.");
                }
                rec.Account = m.Groups["ac"].Value;
                rec.CheckNo = m.Groups["ck"].Value;
                list.Add(rec);
                newBundle = false;
            }
            foreach (var rec in list)
            {
                if (!rec.HasAmount || !rec.Dt.HasValue)
                {
                    continue;
                }

                if (rec.NewBundle)
                {
                    if (bh != null)
                    {
                        BatchImportContributions.FinishBundle(bh);
                    }
                    bh = BatchImportContributions.GetBundleHeader(date, now);
                }
                if (bh == null)
                {
                    throw new Exception($@"Unexpected error: header row not found, aborting");
                }

                var bd = BatchImportContributions.AddContributionDetail(rec.Dt.Value, fid, rec.Amount, rec.CheckNo, rec.Routing, rec.Account);
                bd.Contribution.PostingDate = now;

                bh.BundleDetails.Add(bd);
            }

            BatchImportContributions.FinishBundle(bh);

            return(bh?.BundleHeaderId ?? 0);
        }
Exemple #12
0
        private Contribution ResolvePayment(Payment payment, ContributionFund fund, int?PersonId, BundleHeader bundle)
        {
            // find/create a touchpoint contribution from a pushpay payment
            Contribution contribution;
            var          result = ContributionWithPayment(payment);

            if (result.Any())
            {
                contribution = result.Single();
            }
            else
            {
                contribution = new Contribution
                {
                    PeopleId             = PersonId,
                    ContributionDate     = payment.CreatedOn.ToLocalTime(),
                    ContributionAmount   = payment.Amount.Amount,
                    ContributionTypeId   = (fund.NonTaxDeductible == true) ? ContributionTypeCode.NonTaxDed : ContributionTypeCode.Online,
                    ContributionStatusId = (payment.Amount.Amount >= 0) ? ContributionStatusCode.Recorded : ContributionStatusCode.Reversed,
                    Origin      = ContributionOriginCode.PushPay,
                    CreatedDate = DateTime.Now,
                    FundId      = fund.FundId,

                    MetaInfo = PushPayTransactionNum + payment.TransactionId
                };
                db.Contributions.InsertOnSubmit(contribution);
                db.SubmitChanges();

                // assign contribution to bundle
                BundleDetail bd = new BundleDetail
                {
                    BundleHeaderId = bundle.BundleHeaderId,
                    ContributionId = contribution.ContributionId,
                    CreatedBy      = 0,
                    CreatedDate    = DateTime.Now
                };
                db.BundleDetails.InsertOnSubmit(bd);
                db.SubmitChanges();
            }
            return(contribution);
        }
Exemple #13
0
        private void UploadGifts(UploadPeopleRun rt, ExcelPackage pkg)
        {
            var db   = DbUtil.Create(Host);
            var data = FetchContributionData(pkg.Workbook.Worksheets["Gift Data"]).ToList();

            rt.Count       = data.Count;
            rt.Description = $"Uploading Gifts {(Testing ? "in testing mode" : "for real")}";
            rt.Processed   = 0;
            Db2.SubmitChanges();

            var weeks = (from g in data
                         group g by g.Date.Sunday() into weeklygifts
                         select weeklygifts).ToList();
            BundleHeader bh = null;
            var          c  = db.Content("OrphanedGifts", "---", ContentTypeCode.TypeText);

            c.Body = "";
            db.SubmitChanges();
            foreach (var week in weeks)
            {
                FinishBundle(db, bh);
                if (!Testing)
                {
                    db.Dispose();
                    db = DbUtil.Create(Host);
                }
                bh = new BundleHeader
                {
                    BundleHeaderTypeId = BundleTypeCode.ChecksAndCash,
                    BundleStatusId     = BundleStatusCode.Closed,
                    CreatedBy          = Util.UserId,
                    CreatedDate        = DateTime.Today,
                    ContributionDate   = week.Key,
                };
                foreach (var gift in week)
                {
                    var pid = GetPeopleId(gift);
                    if (!Testing)
                    {
                        if (!pid.HasValue)
                        {
                            if (IgnoreMissingGifts)
                            {
                                c       = db.Content("OrphanedGifts");
                                c.Body += $"{gift.IndividualId} {gift.Date:d} {gift.Amount:C}\n";
                                db.SubmitChanges();
                                continue;
                            }
                            else
                            {
                                throw new Exception($"peopleid not found from individualid {gift.IndividualId}");
                            }
                        }
                    }
                    if (!Testing)
                    {
                        db.FetchOrCreateFund(gift.FundId, gift.FundName ?? gift.FundDescription);
                    }
                    var bd = new BundleDetail();
                    bd.CreatedBy    = Util.UserId;
                    bd.CreatedDate  = DateTime.Now;
                    bd.Contribution = new Contribution
                    {
                        CreatedBy            = Util.UserId,
                        CreatedDate          = DateTime.Now,
                        ContributionDate     = gift.Date,
                        FundId               = gift.FundId,
                        ContributionStatusId = 0,
                        ContributionTypeId   = ContributionTypeCode.CheckCash,
                        ContributionAmount   = gift.Amount,
                        CheckNo              = gift.CheckNo,
                        PeopleId             = pid
                    };
                    bh.BundleDetails.Add(bd);
                    rt.Processed++;
                    Db2.SubmitChanges();
                }
            }
            FinishBundle(db, bh);
            if (!Testing)
            {
                db.Dispose();
            }
        }
Exemple #14
0
        private static int?BatchProcessMagTek(string lines, DateTime date)
        {
            var now = DateTime.Now;
            var bh  = new BundleHeader
            {
                BundleHeaderTypeId = BundleTypeCode.ChecksAndCash,
                BundleStatusId     = BundleStatusCode.Open,
                ContributionDate   = date,
                CreatedBy          = Util.UserId,
                CreatedDate        = now,
                FundId             = DbUtil.Db.Setting("DefaultFundId", "1").ToInt()
            };

            DbUtil.Db.BundleHeaders.InsertOnSubmit(bh);

            var re = new Regex(
                @"(T(?<rt>[\d?]+)T(?<ac>[\d ?]*)U\s*(?<ck>[\d?]+))|
(CT(?<rt>[\d?]+)A(?<ac>[\d ?]*)C(?<ck>[\d?]+)M)",
                RegexOptions.IgnoreCase);
            var m = re.Match(lines);

            while (m.Success)
            {
                var rt = m.Groups["rt"].Value;
                var ac = m.Groups["ac"].Value;
                var ck = m.Groups["ck"].Value;
                var bd = new BundleDetail
                {
                    CreatedBy   = Util.UserId,
                    CreatedDate = now,
                };
                bh.BundleDetails.Add(bd);
                var qf = from f in DbUtil.Db.ContributionFunds
                         where f.FundStatusId == 1
                         orderby f.FundId
                         select f.FundId;

                bd.Contribution = new Contribution
                {
                    CreatedBy            = Util.UserId,
                    CreatedDate          = now,
                    ContributionDate     = date,
                    FundId               = qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash,
                };
                bd.Contribution.ContributionDesc = ck;
                var eac = Util.Encrypt(rt + "," + ac);
                var q   = from kc in DbUtil.Db.CardIdentifiers
                          where kc.Id == eac
                          select kc.PeopleId;
                var pid = q.SingleOrDefault();
                if (pid != null)
                {
                    bd.Contribution.PeopleId = pid;
                }

                bd.Contribution.BankAccount      = eac;
                bd.Contribution.ContributionDesc = ck;

                m = m.NextMatch();
            }
            bh.TotalChecks    = 0;
            bh.TotalCash      = 0;
            bh.TotalEnvelopes = 0;
            DbUtil.Db.SubmitChanges();
            return(bh.BundleHeaderId);
        }
        private static int?BatchProcessOakbrookChurch(CsvReader csv, DateTime date, int?fundid)
        {
            var cols = csv.GetFieldHeaders();

            BundleHeader bh = null;

            var qf = from f in DbUtil.Db.ContributionFunds
                     where f.FundStatusId == 1
                     orderby f.FundId
                     select f.FundId;

            while (csv.ReadNextRecord())
            {
                if (csv[16] == "Credit")
                {
                    if (bh != null)
                    {
                        BatchImportContributions.FinishBundle(bh);
                    }
                    bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                    continue;
                }
                if (bh == null)
                {
                    bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                }

                var bd = new BundleDetail
                {
                    CreatedBy   = Util.UserId,
                    CreatedDate = DateTime.Now,
                };

                bd.Contribution = new Contribution
                {
                    CreatedBy            = Util.UserId,
                    CreatedDate          = DateTime.Now,
                    ContributionDate     = date,
                    FundId               = fundid ?? qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash,
                };


                string ck, rt, ac;
                rt = csv[11];
                ac = csv[13];
                ck = csv[14];
                bd.Contribution.ContributionAmount = csv[15].GetAmount();

                bd.Contribution.CheckNo = ck;
                var eac = Util.Encrypt(rt + "|" + ac);
                var q   = from kc in DbUtil.Db.CardIdentifiers
                          where kc.Id == eac
                          select kc.PeopleId;
                var pid = q.SingleOrDefault();
                if (pid != null)
                {
                    bd.Contribution.PeopleId = pid;
                }
                bd.Contribution.BankAccount = eac;
                bh.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Exemple #16
0
        private void UploadPledges(UploadPeopleRun rt, ExcelPackage pkg)
        {
            var data = FetchPledgeData(pkg.Workbook.Worksheets["Pledges"]).ToList();

            rt.Count       = data.Count;
            rt.Description = $"Uploading Pledges {(Testing ? "in testing mode" : "for real")}";
            rt.Processed   = 0;
            ProgressDbContext.SubmitChanges();

            var weeks = (from g in data
                         group g by g.Date.Sunday()
                         into weeklypledges
                         select weeklypledges).ToList();
            BundleHeader bh = null;

            foreach (var week in weeks)
            {
                FinishBundle(JobDbContext, bh);

                bh = new BundleHeader
                {
                    BundleHeaderTypeId = BundleTypeCode.Pledge,
                    BundleStatusId     = BundleStatusCode.Closed,
                    CreatedBy          = Util.UserId,
                    CreatedDate        = DateTime.Today,
                    ContributionDate   = week.Key
                };
                foreach (var pledge in week)
                {
                    var pid = GetPeopleId(pledge);
                    var f   = new ContributionFund {
                        FundId = 0
                    };
                    if (!Testing)
                    {
                        if (!pid.HasValue)
                        {
                            if (IgnoreMissingGifts)
                            {
                                _orphanedPledges.Append($"{pledge.IndividualId} {pledge.Date:d} {pledge.Amount:C}\n");
                                continue;
                            }

                            throw new Exception($"peopleid not found from individualid {pledge.IndividualId}");
                        }

                        f = ProgressDbContext.FetchOrCreateFund(pledge.FundId,
                                                                pledge.FundName ?? pledge.FundDescription);
                        f.FundPledgeFlag = true;
                    }

                    var bd = new BundleDetail
                    {
                        CreatedBy    = Util.UserId,
                        CreatedDate  = DateTime.Now,
                        Contribution = new Contribution
                        {
                            CreatedBy            = Util.UserId,
                            CreatedDate          = DateTime.Now,
                            ContributionDate     = pledge.Date,
                            FundId               = f.FundId,
                            ContributionStatusId = 0,
                            ContributionTypeId   = ContributionTypeCode.Pledge,
                            ContributionAmount   = pledge.Amount,
                            PeopleId             = pid,
                            CheckNo              = pledge.CheckNo,
                            ContributionDesc     = pledge.GiftDescription
                        }
                    };
                    bh.BundleDetails.Add(bd);

                    // save orphaned pledges
                    if (!Testing)
                    {
                        var currentOrphans = JobDbContext.Content("OrphanedPledges", "---", ContentTypeCode.TypeText);
                        currentOrphans.Body = _orphanedPledges.ToString();
                        JobDbContext.SubmitChanges();
                    }

                    rt.Processed++;
                    ProgressDbContext.SubmitChanges();
                }
            }

            FinishBundle(JobDbContext, bh);
        }
Exemple #17
0
        private void UploadPledges(UploadPeopleRun rt, ExcelPackage pkg)
        {
            var db   = DbUtil.Create(host);
            var data = FetchPledgeData(pkg.Workbook.Worksheets["Pledges"]).ToList();

            rt.Count       = data.Count;
            rt.Description = $"Uploading Pledges {(Testing ? "in testing mode" : "for real")}";
            rt.Processed   = 0;
            db2.SubmitChanges();

            var weeks = (from g in data
                         group g by g.Date.Sunday() into weeklypledges
                         select weeklypledges).ToList();
            BundleHeader bh = null;

            foreach (var week in weeks)
            {
                FinishBundle(db, bh);
                if (!Testing)
                {
                    db.Dispose();
                    db = DbUtil.Create(host);
                }
                bh = new BundleHeader
                {
                    BundleHeaderTypeId = BundleTypeCode.Pledge,
                    BundleStatusId     = BundleStatusCode.Closed,
                    CreatedBy          = Util.UserId,
                    CreatedDate        = DateTime.Today,
                    ContributionDate   = week.Key,
                };
                foreach (var pledge in week)
                {
                    var pid = GetPeopleId(pledge.IndividualId);
                    if (!pid.HasValue)
                    {
                        throw new Exception($"peopleid not found from individualid {pledge.IndividualId}");
                    }
                    if (!Testing)
                    {
                        var f = db.FetchOrCreateFund(pledge.FundId, pledge.FundName ?? pledge.FundDescription);
                        f.FundPledgeFlag = true;
                    }
                    var bd = new BundleDetail();
                    bd.CreatedBy    = Util.UserId;
                    bd.CreatedDate  = DateTime.Now;
                    bd.Contribution = new Contribution
                    {
                        CreatedBy            = Util.UserId,
                        CreatedDate          = DateTime.Now,
                        ContributionDate     = pledge.Date,
                        FundId               = pledge.FundId,
                        ContributionStatusId = 0,
                        ContributionTypeId   = ContributionTypeCode.Pledge,
                        ContributionAmount   = pledge.Amount,
                        PeopleId             = pid
                    };
                    bh.BundleDetails.Add(bd);
                    rt.Processed++;
                    db2.SubmitChanges();
                }
            }
            FinishBundle(db, bh);
            if (!Testing)
            {
                db.Dispose();
            }
        }