Exemple #1
0
        /// <summary>
        /// Gets the payments that have been processed for any scheduled transactions
        /// </summary>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override List <Payment> GetPayments(FinancialGateway financialGateway, DateTime startDate, DateTime endDate, out string errorMessage)
        {
            errorMessage = string.Empty;
            var fakePayments             = new List <Payment>();
            var randomNumberOfPayments   = new Random().Next(1, 1000);
            var rockContext              = new Rock.Data.RockContext();
            var scheduledTransactionList = new FinancialScheduledTransactionService(rockContext).Queryable().ToList();

            var transactionDateTime = startDate;

            for (int paymentNumber = 0; paymentNumber < randomNumberOfPayments; paymentNumber++)
            {
                var scheduledTransaction = scheduledTransactionList.OrderBy(a => a.Guid).FirstOrDefault();
                var fakePayment          = new Payment
                {
                    Amount = scheduledTransaction.TotalAmount,
                    TransactionDateTime = startDate,
                    CreditCardTypeValue = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.FINANCIAL_CREDIT_CARD_TYPE.AsGuid()).DefinedValues.OrderBy(a => Guid.NewGuid()).First(),
                    CurrencyTypeValue   = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()),
                    TransactionCode     = Guid.NewGuid().ToString("N"),
                    GatewayScheduleId   = scheduledTransaction.GatewayScheduleId
                };

                fakePayments.Add(fakePayment);
            }


            return(fakePayments);
        }
Exemple #2
0
        /// <summary>
        /// Gets the payments that have been processed for any scheduled transactions
        /// </summary>
        /// <param name="financialGateway">The financial gateway.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <returns></returns>
        public override List <Payment> GetPayments(FinancialGateway financialGateway, DateTime startDate, DateTime endDate, out string errorMessage)
        {
            errorMessage = string.Empty;
            if (!this.GetAttributeValue(financialGateway, AttributeKey.GenerateFakeGetPayments).AsBoolean())
            {
                return(new List <Payment>());
            }

            var fakePayments             = new List <Payment>();
            var randomNumberOfPayments   = new Random().Next(1, 1000);
            var rockContext              = new Rock.Data.RockContext();
            var scheduledTransactionList = new FinancialScheduledTransactionService(rockContext).Queryable().Where(a => a.FinancialGatewayId == financialGateway.Id).ToList();

            if (!scheduledTransactionList.Any())
            {
                return(fakePayments);
            }

            var transactionDateTime = startDate;

            for (int paymentNumber = 0; paymentNumber < randomNumberOfPayments; paymentNumber++)
            {
                // get a random scheduled Transaction (if any)
                var scheduledTransaction = scheduledTransactionList.OrderBy(a => a.Guid).FirstOrDefault();
                if (scheduledTransaction == null)
                {
                    return(new List <Payment>());
                }

                var fakePayment = new Payment
                {
                    Amount = scheduledTransaction.TotalAmount,
                    TransactionDateTime     = startDate,
                    CreditCardTypeValue     = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.FINANCIAL_CREDIT_CARD_TYPE.AsGuid()).DefinedValues.OrderBy(a => Guid.NewGuid()).First(),
                    CurrencyTypeValue       = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()),
                    TransactionCode         = Guid.NewGuid().ToString("N"),
                    GatewayScheduleId       = scheduledTransaction.GatewayScheduleId,
                    GatewayPersonIdentifier = scheduledTransaction?.FinancialPaymentDetail?.GatewayPersonIdentifier
                };

                fakePayments.Add(fakePayment);
            }


            return(fakePayments);
        }
Exemple #3
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var profiles = new FinancialScheduledTransactionService().Queryable();

            SortProperty sortProperty = rGridGivingProfile.SortProperty;

            if (dtpGivingProfileDate.SelectedDateTime.HasValue)
            {
                profiles = profiles.Where(GivingProfile => GivingProfile.StartDate >= dtpGivingProfileDate.SelectedDateTime);
            }

            if (sortProperty != null)
            {
                rGridGivingProfile.DataSource = profiles.Sort(sortProperty).ToList();
            }
            else
            {
                rGridGivingProfile.DataSource = profiles.OrderBy(b => b.AuthorizedPersonId).ToList();
            }

            rGridGivingProfile.DataBind();
        }
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid(bool isExporting = false)
        {
            int?personId      = null;
            int?givingGroupId = null;

            bool validRequest = false;

            if (TargetPerson != null)
            {
                personId      = TargetPerson.Id;
                givingGroupId = TargetPerson.GivingGroupId;
                validRequest  = true;
            }
            else
            {
                int personEntityTypeId = EntityTypeCache.Read("Rock.Model.Person").Id;
                if (!ContextTypesRequired.Any(e => e.Id == personEntityTypeId))
                {
                    validRequest = true;
                }
            }

            if (validRequest)
            {
                var rockContext = new RockContext();
                var qry         = new FinancialScheduledTransactionService(rockContext)
                                  .Queryable("ScheduledTransactionDetails,FinancialPaymentDetail.CurrencyTypeValue,FinancialPaymentDetail.CreditCardTypeValue")
                                  .AsNoTracking();

                // Valid Accounts
                var accountGuids = GetAttributeValue("Accounts").SplitDelimitedValues().AsGuidList();
                if (accountGuids.Any())
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => accountGuids.Contains(d.Account.Guid)));
                }

                // Amount Range
                var nre = new NumberRangeEditor();
                nre.DelimitedValues = gfSettings.GetUserPreference("Amount");
                if (nre.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) >= nre.LowerValue.Value);
                }

                if (nre.UpperValue.HasValue)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Sum(d => d.Amount) <= nre.UpperValue.Value);
                }

                // Frequency
                int?frequencyTypeId = gfSettings.GetUserPreference("Frequency").AsIntegerOrNull();
                if (frequencyTypeId.HasValue)
                {
                    qry = qry.Where(t => t.TransactionFrequencyValueId == frequencyTypeId.Value);
                }

                // Date Range
                var drp = new DateRangePicker();
                drp.DelimitedValues = gfSettings.GetUserPreference("Created");
                if (drp.LowerValue.HasValue)
                {
                    qry = qry.Where(t => t.CreatedDateTime >= drp.LowerValue.Value);
                }

                if (drp.UpperValue.HasValue)
                {
                    DateTime upperDate = drp.UpperValue.Value.Date.AddDays(1);
                    qry = qry.Where(t => t.CreatedDateTime < upperDate);
                }

                // Account Id
                int accountId = int.MinValue;
                if (int.TryParse(gfSettings.GetUserPreference("Account"), out accountId) && ddlAccount.Visible)
                {
                    qry = qry.Where(t => t.ScheduledTransactionDetails.Any(d => d.AccountId == accountId));
                }

                // Active only (no filter)
                if (string.IsNullOrWhiteSpace(gfSettings.GetUserPreference("Include Inactive")))
                {
                    qry = qry.Where(t => t.IsActive);
                }

                if (givingGroupId.HasValue)
                {
                    //  Person contributes with family
                    qry = qry.Where(t => t.AuthorizedPersonAlias.Person.GivingGroupId == givingGroupId);
                }
                else if (personId.HasValue)
                {
                    // Person contributes individually
                    qry = qry.Where(t => t.AuthorizedPersonAlias.PersonId == personId);
                }

                SortProperty sortProperty = gList.SortProperty;
                if (sortProperty != null)
                {
                    if (sortProperty.Property == "Amount")
                    {
                        if (sortProperty.Direction == SortDirection.Ascending)
                        {
                            qry = qry.OrderBy(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.00M);
                        }
                        else
                        {
                            qry = qry.OrderByDescending(t => t.ScheduledTransactionDetails.Sum(d => (decimal?)d.Amount) ?? 0.0M);
                        }
                    }
                    else
                    {
                        qry = qry.Sort(sortProperty);
                    }
                }
                else
                {
                    qry = qry
                          .OrderBy(t => t.AuthorizedPersonAlias.Person.LastName)
                          .ThenBy(t => t.AuthorizedPersonAlias.Person.NickName)
                          .ThenByDescending(t => t.IsActive)
                          .ThenByDescending(t => t.StartDate);
                }

                _isExporting = isExporting;

                gList.SetLinqDataSource <FinancialScheduledTransaction>(qry);
                gList.DataBind();

                _isExporting = false;
            }
        }