Exemple #1
0
        public void Should_Show_Closed_Funds()
        {
            var fund = new ContributionFund
            {
                FundId         = RandomNumber(500, 1000),
                CreatedBy      = 1,
                CreatedDate    = DateTime.Now,
                FundName       = RandomString(),
                FundStatusId   = 2,
                FundTypeId     = 1,
                FundPledgeFlag = false
            };

            db.ContributionFunds.InsertOnSubmit(fund);
            db.SubmitChanges();

            username = RandomString();
            password = RandomString();
            var user = CreateUser(username, password, roles: new string[] { "Access", "Edit", "Admin", "Finance" });

            Login();

            Open($"{rootUrl}Funds/");

            Find(xpath: "//a[contains(@href, '/Funds?status=2')]").Click();
            PageSource.ShouldContain(fund.FundName);

            db.ContributionFunds.DeleteOnSubmit(fund);
            db.SubmitChanges();
        }
Exemple #2
0
        public static ContributionFund CreateSaveFund(CMSDataContext db, bool isPledge)
        {
            int    fundId;
            Random random       = new Random();
            bool   fundIdExists = false;

            do
            {
                fundId       = random.Next(1000);
                fundIdExists = db.ContributionFunds.Any(f => f.FundId == fundId);
            } while (fundIdExists);

            var fund = new ContributionFund
            {
                FundId         = fundId,
                FundName       = DatabaseTestBase.RandomString(),
                FundPledgeFlag = isPledge,
                CreatedBy      = 1,
                CreatedDate    = DateTime.Now
            };

            db.ContributionFunds.InsertOnSubmit(fund);
            db.SubmitChanges();
            return(fund);
        }
Exemple #3
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);
        }
Exemple #4
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 #5
0
        private ContributionFund ResolveFund(Fund fund)
        {
            // take a pushpay fund and find or create a touchpoint fund
            IQueryable <ContributionFund> funds = db.ContributionFunds.AsQueryable();

            var result = from f in funds
                         where f.FundName == fund.Name
                         where f.FundStatusId > 0
                         orderby f.FundStatusId
                         orderby f.FundId descending
                         select f;

            if (result.Any())
            {
                int id = result.Select(f => f.FundId).First();
                return(db.ContributionFunds.SingleOrDefault(f => f.FundId == id));
            }
            else
            {
                var max_id = from fn in funds
                             orderby fn.FundId descending
                             select fn.FundId + 1;
                int fund_id = max_id.FirstOrDefault();

                ContributionFund f = new ContributionFund
                {
                    FundId           = fund_id,
                    FundName         = fund.Name,
                    FundStatusId     = 1,
                    CreatedDate      = DateTime.Now.Date,
                    CreatedBy        = 1,
                    FundDescription  = fund.Name,
                    NonTaxDeductible = !fund.taxDeductible
                };
                db.ContributionFunds.InsertOnSubmit(f);
                db.SubmitChanges();
                return(f);
            }
        }
Exemple #6
0
        private async Task <ActionResult> OneTimeProcess(string paymentToken)
        {
            var oid = CmsData.API.APIContribution.OneTimeGiftOrgId(CurrentDatabase);

            if (oid == null)
            {
                return(View("OnePageGiving/NotConfigured"));
            }

            var     merchantHandler = GetMerchantHandle(oid.Value);
            Payment payment         = await _pushpayPayment.GetPayment(paymentToken, merchantHandler);

            if (_resolver.TransactionAlreadyImported(payment))
            {
                ViewBag.Message = "Payment already processed";
                return(View("~/Views/Shared/PageError.cshtml"));
            }

            // determine the batch to put the payment in
            BundleHeader bundle;

            if (payment.Settlement?.Key.HasValue() == true)
            {
                bundle = await _resolver.ResolveSettlement(payment.Settlement);
            }
            else
            {
                // create a new bundle for each payment not part of a PushPay batch or settlement
                bundle = _resolver.CreateBundle(payment.CreatedOn.ToLocalTime(), payment.Amount.Amount, null, null, payment.TransactionId, BundleReferenceIdTypeCode.PushPayStandaloneTransaction);
            }
            ContributionFund fund = _resolver.ResolveFund(payment.Fund);
            int?pid = _resolver.ResolvePersonId(payment.Payer);

            _resolver.ResolvePayment(payment, fund, pid, bundle);
            _resolver.ResolveTransaction(payment, pid.Value, oid.Value, "Online Giving");

            ViewBag.Message = "Thank you, your transaction is complete for Online Giving.";
            return(View());
        }
Exemple #7
0
        public ActionResult Create(string fundid)
        {
            var id = fundid.ToInt();

            if (id == 0)
            {
                return(Json(new { error = "expected an integer (account number)" }));
            }

            var f = CurrentDatabase.ContributionFunds.SingleOrDefault(ff => ff.FundId == id);

            if (f != null)
            {
                return(Json(new { error = $"fund already exists: {f.FundName} ({fundid})" }));
            }

            try
            {
                f = new ContributionFund
                {
                    FundName         = "new fund",
                    FundId           = id,
                    CreatedBy        = Util.UserId1,
                    CreatedDate      = Util.Now,
                    FundStatusId     = 1,
                    FundTypeId       = 1,
                    FundPledgeFlag   = false,
                    NonTaxDeductible = false
                };
                CurrentDatabase.ContributionFunds.InsertOnSubmit(f);
                CurrentDatabase.SubmitChanges();
                return(Json(new { edit = "/Fund/Edit/" + id }));
            }
            catch (Exception ex)
            {
                return(Json(new { error = ex.Message }));
            }
        }
Exemple #8
0
 private async Task <ActionResult> OneTimeProcess(Payment payment, int orgId)
 {
     if (payment != null && !_resolver.TransactionAlreadyImported(payment))
     {
         // determine the batch to put the payment in
         BundleHeader bundle;
         if (payment.Settlement?.Key.HasValue() == true)
         {
             bundle = await _resolver.ResolveSettlement(payment.Settlement);
         }
         else
         {
             // create a new bundle for each payment not part of a PushPay batch or settlement
             bundle = _resolver.CreateBundle(payment.CreatedOn.ToLocalTime(), payment.Amount.Amount, null, null, payment.TransactionId, BundleReferenceIdTypeCode.PushPayStandaloneTransaction);
         }
         int?PersonId                  = _resolver.ResolvePersonId(payment.Payer);
         ContributionFund fund         = _resolver.ResolveFund(payment.Fund);
         Contribution     contribution = _resolver.ResolvePayment(payment, fund, PersonId, bundle);
         Transaction      transaction  = _resolver.ResolveTransaction(payment, PersonId.Value, orgId, "Online Giving");
     }
     ViewBag.Message = "Thank you, your transaction is complete for Online Giving.";
     return(View());
 }
Exemple #9
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 #10
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();
            //}
        }
Exemple #11
0
        private async Task <int> RunInternal()
        {
            int Count         = 0;
            var organizations = await pushpay.GetOrganizations();

            foreach (Organization org in organizations)
            {
                try
                {
                    int  OnPaymentPage        = 0;
                    bool HasPaymentsToProcess = true;

                    Init(org.Key);

                    while (HasPaymentsToProcess)
                    {
                        PaymentList payments = await pushpay.GetPaymentsForOrganizationSince(org.Key, StartDate, OnPaymentPage);

                        int PaymentPages = (payments.TotalPages.HasValue ? (int)payments.TotalPages : 1);

                        foreach (Payment payment in payments.Items)
                        {
                            var merchantKey = payment.Recipient.Key;
                            if (!TransactionAlreadyImported(payment))
                            {
                                // determine the batch to put the payment in
                                BundleHeader bundle;
                                if (payment.Batch?.Key.HasValue() == true)
                                {
                                    bundle = await ResolveBatch(payment.Batch, merchantKey);
                                }
                                else if (payment.Settlement?.Key.HasValue() == true)
                                {
                                    bundle = await ResolveSettlement(payment.Settlement);
                                }
                                else
                                {
                                    if (ImportUnreconciled)
                                    {
                                        // create a new bundle for each payment not part of a PushPay batch or settlement
                                        bundle = CreateBundle(payment.CreatedOn.ToLocalTime(), payment.Amount.Amount, null, null, payment.TransactionId, BundleReferenceIdTypeCode.PushPayStandaloneTransaction);
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }

                                Console.WriteLine("Importing payment " + payment.TransactionId);

                                // resolve the payer, fund, and payment
                                int?PersonId                  = ResolvePersonId(payment.Payer);
                                ContributionFund fund         = ResolveFund(payment.Fund);
                                Contribution     contribution = ResolvePayment(payment, fund, PersonId, bundle);

                                // mark this payment as imported
                                RecordImportProgress(org, bundle, contribution, payment);
                                Count++;
                            }
                        }
                        // done with this page of payments, see if there's more
                        if (PaymentPages > OnPaymentPage + 1)
                        {
                            OnPaymentPage++;
                        }
                        else
                        {
                            HasPaymentsToProcess = false;
                        }
                    }
                }
                catch (Exception e)
                {
                    string timestamp = DateTime.UtcNow.ToString("yyyy-dd-MM-HH-mm-ss-fff");
                    string exception = $"{org.Key}\n{e.ToString()}";
                    File.WriteAllText($"PushPay{timestamp}-{db.Host}.txt", exception);
                }
            }
            return(Count);
        }