FinishBundle() статический приватный Метод

static private FinishBundle ( CmsData.BundleHeader bh ) : void
bh CmsData.BundleHeader
Результат void
Пример #1
0
        private static int?BatchProcessTeaysValley(CsvReader csv, DateTime date, int?fundid)
        {
            var fundList = (from f in DbUtil.Db.ContributionFunds
                            orderby f.FundId
                            select f.FundId).ToList();

            var          cols      = csv.GetFieldHeaders();
            BundleHeader bh        = null;
            var          firstfund = BatchImportContributions.FirstFundId();
            var          fund      = fundid ?? firstfund;

            while (csv.ReadNextRecord())
            {
                var dt     = csv[0].ToDate();
                var amount = csv[2];
                if (!amount.HasValue() || !dt.HasValue)
                {
                    continue;
                }

                var fid     = csv[1].ToInt2() ?? fund;
                var account = csv[3];
                var checkno = csv[4];

                if (!fundList.Contains(fid))
                {
                    fid = firstfund;
                }

                if (bh == null)
                {
                    bh = BatchImportContributions.GetBundleHeader(dt.Value, DateTime.Now);
                }

                var bd = BatchImportContributions.AddContributionDetail(date, fid, amount, checkno, "", account);

                bh.BundleDetails.Add(bd);
            }

            BatchImportContributions.FinishBundle(bh);

            return(bh.BundleHeaderId);
        }
Пример #2
0
        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>();

            csv.Read();
            csv.ReadHeader();
            while (csv.Read())
            {
                var rec = new Record
                {
                    ItemType = csv["ItemTypeName"],
                    Amount   = csv["Amount"],
                    Dt       = csv["CapturedDate"].ToDate(),
                    Account  = csv["Account"],
                    Routing  = csv["RoutingNumber"],
                    CheckNo  = csv["TranCode"],
                };
                if (rec.ItemType == "CK")
                {
                    list.Add(rec);
                }
            }
            bh = BatchImportContributions.GetBundleHeader(date, now);
            foreach (var rec in list)
            {
                if (!rec.HasAmount || !rec.Dt.HasValue)
                {
                    continue;
                }

                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);
        }
Пример #3
0
        private static int?BatchProcessJackHenry(CsvReader csv, DateTime date, int?fundid)
        {
            BundleHeader bh        = null;
            var          firstfund = BatchImportContributions.FirstFundId();
            var          fund      = fundid ?? firstfund;

            var list = new List <DepositRecord>();
            var r    = 2;

            while (csv.ReadNextRecord())
            {
                var peopleid = csv[6].ToInt();
                list.Add(new DepositRecord()
                {
                    PeopleId = peopleid,
                    Amount   = csv[9],
                    CheckNo  = csv[10],
                    Row      = r++,
                    Valid    = DbUtil.Db.People.Any(pp => pp.PeopleId == peopleid),
                });
            }
            if (list.Any(vv => vv.Valid == false))
            {
                throw new Exception("The following rows had peopleids that were not found<br>\n" +
                                    string.Join(",", (list.Where(vv => vv.Valid == false).Select(vv => vv.Row)).ToArray()));
            }
            foreach (var i in list)
            {
                if (bh == null)
                {
                    bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                }

                var bd = BatchImportContributions.AddContributionDetail(date, fund, i.Amount, i.CheckNo, i.Routing, i.PeopleId);
                bh.BundleDetails.Add(bd);
            }
            if (bh == null)
            {
                return(null);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Пример #4
0
        private static int?Import(CsvReader csv, DateTime date, int?fundid)
        {
            BundleHeader bh  = null;
            var          fid = fundid ?? BatchImportContributions.FirstFundId();

            var list = new List <DepositRecord>();

            csv.Read();
            csv.ReadHeader();
            while (csv.Read())
            {
                list.Add(new DepositRecord()
                {
                    Batch   = csv[0],
                    Account = csv[4],
                    CheckNo = csv[5],
                    Amount  = csv[7],
                });
            }
            var q = from r in list
                    select r;
            var prevbatch = "";

            foreach (var r in q)
            {
                if (r.Batch != prevbatch)
                {
                    if (bh == null)
                    {
                        bh = BatchImportContributions.GetBundleHeader(r.Batch.ToDate() ?? date, DateTime.Now);
                    }
                    prevbatch = r.Batch;
                }
                var bd = BatchImportContributions.AddContributionDetail(date, fid, r.Amount, r.CheckNo, r.Routing, r.Account);
                bh.BundleDetails.Add(bd);
            }
            if (bh == null)
            {
                return(null);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Пример #5
0
        public static int?BatchProcessSilverdale(CsvReader csv, DateTime date, int?fundid)
        {
            var          cols      = csv.GetFieldHeaders();
            BundleHeader bh        = null;
            var          firstfund = BatchImportContributions.FirstFundId();
            var          fund      = fundid ?? firstfund;

            while (csv.ReadNextRecord())
            {
                var excludecol = csv[12] == "Virtual Credit Item";
                var routing    = csv[18];
                var account    = csv[19];
                var amount     = csv[20];
                var checkno    = csv[24];
                if (!checkno.HasValue() && account.Count(c => c == ' ') == 1)
                {
                    var a = account.Split(' ');
                    account = a[1];
                    checkno = a[0];
                }

                if (excludecol)
                {
                    if (bh != null)
                    {
                        BatchImportContributions.FinishBundle(bh);
                    }
                    bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                    continue;
                }
                if (bh == null)
                {
                    bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                }

                var bd = BatchImportContributions.AddContributionDetail(date, fund, amount, checkno, routing, account);
                bh.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
Пример #6
0
        private static int?Import(CsvReader csv, DateTime date, int?fundid)
        {
            BundleHeader bundleHeader = null;
            var          fid          = fundid ?? BatchImportContributions.FirstFundId();

            csv.Read();
            csv.ReadHeader();
            while (csv.Read())
            {
                var batchDate = csv["Date"].ToDate();
                var amount    = csv["Amount"];

                //var paymentMethod = csv["Payment Method"];
                var method = csv["Method"];
                //var payerName = csv["Payer Name"];
                var email    = csv["Email address"];
                var phone    = csv["Mobile Number"];
                var fundText = "";
                if (csv.Context.HeaderRecord.Contains("Giving Type Label"))
                {
                    fundText = csv["Giving Type Label"];
                }

                ContributionFund f = null;
                if (fundText.HasValue())
                {
                    f = DbUtil.Db.FetchOrCreateFund(fundText);
                }

                if (bundleHeader == null)
                {
                    bundleHeader = BatchImportContributions.GetBundleHeader(batchDate ?? DateTime.Today, DateTime.Now);
                }

                var bd = BatchImportContributions.AddContributionDetail(date, f?.FundId ?? fid, amount, method, null, $"{email}|{phone}");
                bundleHeader.BundleDetails.Add(bd);
            }

            BatchImportContributions.FinishBundle(bundleHeader);
            return(bundleHeader.BundleHeaderId);
        }
Пример #7
0
        private static int?Import(CsvReader csv, DateTime date, int?fundid)
        {
            BundleHeader bundleHeader = null;
            var          fid          = fundid ?? BatchImportContributions.FirstFundId();

            var details = new List <BundleDetail>();

            while (csv.ReadNextRecord())
            {
                var batchDate = csv[0].ToDate();
                var amount    = csv[14];
                var type      = csv[13];
                if (!amount.HasValue() || !batchDate.HasValue || type == "Credit")
                {
                    continue;
                }

                var routingNumber = csv[17];
                var accountNumber = csv[16];
                var checkNumber   = csv[15];

                if (bundleHeader == null)
                {
                    bundleHeader = BatchImportContributions.GetBundleHeader(batchDate.Value, DateTime.Now);
                }

                details.Add(BatchImportContributions.AddContributionDetail(date, fid, amount, checkNumber, routingNumber, accountNumber));
            }

            details.Reverse();
            foreach (var bd in details)
            {
                bundleHeader.BundleDetails.Add(bd);
            }

            BatchImportContributions.FinishBundle(bundleHeader);

            return(bundleHeader.BundleHeaderId);
        }
        private static int?BatchProcessFbcFayetteville(CsvReader csv, DateTime date, int?fundid)
        {
            var          cols         = csv.GetFieldHeaders();
            BundleHeader bundleHeader = null;
            var          firstfund    = BatchImportContributions.FirstFundId(); //TODO: use default fund id based on DBSetting w/ default to 1 if not set
            var          fund         = fundid ?? firstfund;

            while (csv.ReadNextRecord())
            {
                var isHeaderRow = csv[0].StartsWith("Date");

                if (isHeaderRow)
                {
                    continue;
                }

                var contributionDate = csv[0].Trim();
                var memberNumber     = csv[1].Trim();
                var memberName       = csv[2].Trim();
                var amount           = csv[3].Trim();
                var checkNumber      = csv[4].Trim();

                if (bundleHeader == null)
                {
                    bundleHeader = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                }

                var bundleDetails = BatchImportContributions.AddContributionDetail(date, fund, amount, checkNumber, "", int.Parse(memberNumber));
                bundleHeader.BundleDetails.Add(bundleDetails);
            }

            if (bundleHeader == null)
            {
                return(null);
            }

            BatchImportContributions.FinishBundle(bundleHeader);
            return(bundleHeader.BundleHeaderId);
        }
Пример #9
0
        private static int?BatchProcess(CsvReader csv, DateTime date, int?fundid)
        {
            BundleHeader bh  = null;
            var          fid = fundid ?? BatchImportContributions.FirstFundId();
            var          now = DateTime.Now;

            csv.Read();
            csv.ReadHeader();
            csv.Read(); // skip first row which is the total row

            while (csv.Read())
            {
                var amount  = csv[0];
                var routing = csv[1];
                var checkno = csv[2];
                var account = csv[3];
                var dt      = csv[4].ToDate();

                if (!amount.HasValue() || !dt.HasValue)
                {
                    continue;
                }

                if (bh == null)
                {
                    bh = BatchImportContributions.GetBundleHeader(date, now);
                }

                var bd = BatchImportContributions.AddContributionDetail(dt.Value, fid, amount, checkno, routing, account);
                bd.Contribution.PostingDate = now;

                bh.BundleDetails.Add(bd);
            }

            BatchImportContributions.FinishBundle(bh);

            return(bh?.BundleHeaderId ?? 0);
        }
        private static int?Import(CsvReader csv, int?fundid, DateTime date)
        {
            csv.Configuration.HasHeaderRecord = false;
            csv.Configuration.Delimiter       = "\t";
            var bundleHeader = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
            var fid          = fundid ?? BatchImportContributions.FirstFundId();

            var list = new List <DepositRecord>();
            var n    = 0;

            // this is a peculiar file, no headers and all rows are included twice.

            while (csv.Read())
            {
                if (csv[3] == "C") // C is the marker beginning each section
                {
                    continue;      // skip over C records
                }
                var r = new DepositRecord()
                {
                    Row = n++, Valid = true
                };
                r.Account = csv[5];
                r.Amount  = (csv[7].ToDecimal() / 100).ToString();
                r.CheckNo = csv[8];
                r.Routing = csv[9];
                list.Add(r);
            }
            for (var i = 0; i < n / 2; i++)
            {
                var r  = list[i];
                var bd = BatchImportContributions.AddContributionDetail(date, fid, r.Amount, r.CheckNo, r.Routing, r.Account);
                bundleHeader.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bundleHeader);
            return(bundleHeader.BundleHeaderId);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
0
        private static int?BatchProcessRegions(CsvReader csv, DateTime date, int?fundid)
        {
            var db         = DbUtil.Db;
            var userId     = db.UserId;
            var prevbundle = -1;
            var curbundle  = 0;

            var bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);

            Regex re = new Regex(
                @"(?<g1>d(?<rt>.*?)d\sc(?<ac>.*?)(?:c|\s)(?<ck>.*?))$
		|(?<g2>d(?<rt>.*?)d(?<ck>.*?)(?:c|\s)(?<ac>.*?)c[\s!]*)$
		|(?<g3>d(?<rt>.*?)d(?<ac>.*?)c(?<ck>.*?$))
		|(?<g4>c(?<ck>.*?)c\s*d(?<rt>.*?)d(?<ac>.*?)c\s*$)
		"        , RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
            int fieldCount = csv.FieldCount;
            var cols       = csv.GetFieldHeaders();

            while (csv.ReadNextRecord())
            {
                if (!csv[12].Contains("Check"))
                {
                    continue;
                }

                var bd = new CmsData.BundleDetail
                {
                    CreatedBy   = 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            = userId,
                    CreatedDate          = DateTime.Now,
                    ContributionDate     = date,
                    FundId               = fundid ?? qf.First(),
                    ContributionStatusId = 0,
                    ContributionTypeId   = ContributionTypeCode.CheckCash,
                };
                string ac = null, rt = null;
                for (var c = 1; c < fieldCount; c++)
                {
                    switch (cols[c].ToLower())
                    {
                    case "deposit number":
                        curbundle = csv[c].ToInt();
                        if (prevbundle == -1)
                        {
                            prevbundle = curbundle;
                        }
                        if (curbundle != prevbundle)
                        {
                            if (curbundle == 3143)
                            {
                                foreach (var i in bh.BundleDetails)
                                {
                                    Debug.WriteLine(i.Contribution.ContributionDesc);
                                    Debug.WriteLine(i.Contribution.BankAccount);
                                }
                            }

                            BatchImportContributions.FinishBundle(bh);
                            bh         = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                            prevbundle = curbundle;
                        }
                        break;

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

                    case "micr":
                        var m = re.Match(csv[c]);
                        rt = m.Groups["rt"].Value;
                        ac = m.Groups["ac"].Value;
                        bd.Contribution.CheckNo = m.Groups["ck"].Value.Truncate(20);
                        break;
                    }
                }
                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);
        }
Пример #14
0
        private static int?BatchProcessSunTrust(CsvReader csv, DateTime date, int?fundid)
        {
            var prevbundle = -1;
            var curbundle  = 0;

            var bh = BatchImportContributions.GetBundleHeader(date, DateTime.Now);

            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, sn = null;
                for (var c = 1; c < fieldCount; c++)
                {
                    switch (cols[c].ToLower())
                    {
                    case "deposit_id":
                        curbundle = csv[c].ToInt();
                        if (curbundle != prevbundle)
                        {
                            if (curbundle == 3143)
                            {
                                foreach (var i in bh.BundleDetails)
                                {
                                    Debug.WriteLine(i.Contribution.ContributionDesc);
                                    Debug.WriteLine(i.Contribution.BankAccount);
                                }
                            }

                            BatchImportContributions.FinishBundle(bh);
                            bh         = BatchImportContributions.GetBundleHeader(date, DateTime.Now);
                            prevbundle = curbundle;
                        }
                        break;

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

                    case "tran_code":
                        ck = csv[c];
                        break;

                    case "serial_number":
                        sn = csv[c];
                        break;

                    case "routing_transit":
                        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];
                    }
                }
                bd.Contribution.ContributionDesc = string.Join(" ", sn, 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);
        }
Пример #15
0
        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);
        }
Пример #16
0
        private static int?Import(CsvReader csv, DateTime date)
        {
            var bundleHeader = BatchImportContributions.GetBundleHeader(date, DateTime.Now);

            var list = new List <DepositRecord>();
            var n    = 0;

            csv.Read();
            csv.ReadHeader();
            while (csv.Read())
            {
                var r = new DepositRecord()
                {
                    Row = ++n, Valid = true
                };
                r.Date     = csv["Date"].ToDate();
                r.PeopleId = csv["PeopleId"].ToInt();
                r.CheckNo  = csv["Check#"];
                var typ = csv["Type"];
                r.FundId      = csv["Fund"].ToInt2();
                r.Amount      = csv["Amount"];
                r.Description = csv["Notes"];
                if (!r.Date.HasValue)
                {
                    r.AddError("Missing Date");
                }
                if (!r.FundId.HasValue)
                {
                    r.AddError("Missing Fund");
                }
                if (r.PeopleId == 0)
                {
                    r.AddError("Missing PeopleId");
                }
                if (0 == DbUtil.Db.Connection.ExecuteScalar <int>(
                        "SELECT IIF(EXISTS(SELECT NULL FROM dbo.People WHERE PeopleId = @pid), 1, 0)", new { pid = r.PeopleId }))
                {
                    r.AddError("Cannot Find Person");
                }
                if (0 == DbUtil.Db.Connection.ExecuteScalar <int>(
                        "SELECT IIF(EXISTS(SELECT NULL FROM dbo.ContributionFund WHERE FundId = @fid), 1, 0)", new { fid = r.FundId }))
                {
                    r.AddError("Cannot Find Fund");
                }

                switch (typ)
                {
                case "PL":
                    r.TypeId = ContributionTypeCode.Pledge;
                    break;

                case "NT":
                    r.TypeId = ContributionTypeCode.NonTaxDed;
                    break;

                case "GK":
                    r.TypeId = ContributionTypeCode.GiftInKind;
                    break;

                case "SK":
                    r.TypeId = ContributionTypeCode.Stock;
                    break;

                case "CN":
                    r.TypeId = ContributionTypeCode.CheckCash;
                    break;

                default:
                    r.AddError("missing/unknown type");
                    break;
                }
                list.Add(r);
            }
            if (list.Any(vv => vv.Valid == false))
            {
                throw new Exception("The following errors were found<br>\n" +
                                    string.Join("<br>\n", list.Where(vv => vv.Valid == false).Select(vv => vv.RowError()).ToArray()));
            }
            foreach (var r in list)
            {
                if (!r.Date.HasValue || !r.FundId.HasValue)
                {
                    continue;
                }
                var bd = BatchImportContributions.AddContributionDetail(r.Date.Value, r.FundId.Value, r.Amount, r.PeopleId);
                var c  = bd.Contribution;
                c.ContributionDesc = r.Description;
                c.CheckNo          = r.CheckNo;
                bundleHeader.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bundleHeader);
            return(bundleHeader.BundleHeaderId);
        }
Пример #17
0
        private static int?BatchProcessBankOfNorthGeorgia(string text, DateTime date, int?fundid)
        {
            BundleHeader bh   = null;
            var          sr   = new StringReader(text);
            var          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)
                    {
                        BatchImportContributions.FinishBundle(bh);
                    }
                    bh = BatchImportContributions.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,
                };


                var rt = csv[14];
                var ac = csv[20];
                var 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);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }
        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);
        }
Пример #19
0
        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);
        }
        private 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 = BatchImportContributions.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)
                    {
                        BatchImportContributions.FinishBundle(bh);
                    }

                    bh             = BatchImportContributions.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 = BatchImportContributions.AddContributionDetail(r.Date ?? date, fid, r.Amount, r.CheckNo, "", r.Account);
                }
                else
                {
                    bd = BatchImportContributions.AddContributionDetail(r.Date ?? date, fundid ?? firstfund, r.Amount, r.CheckNo, "", r.Account);
                    bd.Contribution.ContributionDesc = $"Used default fund (fund requested: {r.Type})";
                }
                bh.BundleDetails.Add(bd);
            }
            BatchImportContributions.FinishBundle(bh);
            return(bh.BundleHeaderId);
        }