public static void AddMoveHistory(RockContext rockContext, Location location, Attendance attendeeAttendance, bool isSubroom)
        {
            var moveSummary = string.Format("{0}</span> at <span class=\"field-name\">{1}", location.Name, Rock.RockDateTime.Now);

            if (isSubroom)
            {
                moveSummary += string.Format("</span> (a subroom of <span class=\"field-name\">{0})", location.ParentLocation.Name);
            }

            var changes = new History.HistoryChangeList();

            changes.AddCustom("Entry", History.HistoryChangeType.Record.ToString(), moveSummary.Truncate(250));
            changes.First().Caption             = "Moved To Location";
            changes.First().RelatedEntityTypeId = locationEntityTypeId;
            changes.First().RelatedEntityId     = location.Id;
            changes.First().RelatedData         = GetHostInfo();

            HistoryService.SaveChanges(
                rockContext,
                typeof(Rock.Model.Person),
                CategoryCache.Get(4).Guid,
                attendeeAttendance.PersonAlias.PersonId,
                changes,
                true
                );
        }
        public static void AddWithParentHistory(RockContext rockContext, Person person)
        {
            var summary = string.Format("</span> to be with Parent at <span class=\"field-name\">{0}", Rock.RockDateTime.Now);

            var changes = new History.HistoryChangeList();

            changes.AddCustom("Moved", History.HistoryChangeType.Record.ToString(), summary.Truncate(250));
            changes.First().Caption     = "Moved be with Parent";
            changes.First().RelatedData = GetHostInfo();

            HistoryService.SaveChanges(
                rockContext,
                typeof(Rock.Model.Person),
                CategoryCache.Get(4).Guid,
                person.Id,
                changes,
                true
                );
            AttendanceCache.SetWithParent(person.Id);
        }
        /// <summary>
        /// Handles the Delete event of the gTransactionEntities control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gTransactionEntities_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            var service     = new FinancialTransactionDetailService(rockContext);
            var detail      = service.Get(e.RowKeyId);

            if (detail == null)
            {
                return;
            }
            else
            {
                var changes  = new History.HistoryChangeList();
                var typeName = detail.EntityType.FriendlyName;
                var name     = GetEntityName(detail.EntityTypeId, detail.EntityId, rockContext);

                History.EvaluateChange(changes, "Entity Type Id", detail.EntityTypeId, null);
                History.EvaluateChange(changes, "Entity Id", detail.EntityId, null);

                detail.EntityTypeId = null;
                detail.EntityId     = null;

                changes.AddCustom("Removed", "Removed", string.Format("Removed transaction detail association to {0} {1}", typeName, name));

                HistoryService.SaveChanges(
                    rockContext,
                    typeof(FinancialTransaction),
                    Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(),
                    detail.TransactionId,
                    changes
                    );

                rockContext.SaveChanges();
            }

            BindGrid();
        }
Beispiel #4
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            var personGuid = GetAttributeValue(action, "Person", true).AsGuidOrNull();

            if (personGuid == null)
            {
                errorMessages.Add("Person Add History requires a valid person");
                return(false);
            }

            var categoryGuid = GetAttributeValue(action, "Category").AsGuid();
            var category     = new CategoryService(rockContext).Get(categoryGuid);

            if (category == null)
            {
                errorMessages.Add("Person Add History requires a valid category");
                return(false);
            }

            PersonAliasService personAliasService = new PersonAliasService(rockContext);
            var personAlias = personAliasService.Get(personGuid.Value);

            if (personAlias != null)
            {
                var person               = personAlias.Person;
                var entityTypeId         = EntityTypeCache.GetId(typeof(Rock.Model.Person));
                var workflowEntityTypeId = EntityTypeCache.GetId(typeof(Rock.Model.Workflow));
                var mergeFields          = GetMergeFields(action);
                var caption              = GetAttributeValue(action, "Caption").ResolveMergeFields(mergeFields);
                var summary              = GetAttributeValue(action, "Summary").ResolveMergeFields(mergeFields);
                var verb = GetAttributeValue(action, "Verb").ResolveMergeFields(mergeFields);


                var personChanges = new History.HistoryChangeList();

                personChanges.AddCustom(verb, History.HistoryChangeType.Record.ToString(), summary.Truncate(250));
                personChanges.First().Caption = caption;

                if (action?.Activity?.Workflow != null && action.Activity.WorkflowId != 0)
                {
                    personChanges.First().RelatedEntityTypeId = workflowEntityTypeId;
                    personChanges.First().RelatedEntityId     = action.Activity.WorkflowId;
                }

                HistoryService.SaveChanges(
                    rockContext,
                    typeof(Rock.Model.Person),
                    category.Guid,
                    person.Id,
                    personChanges,
                    true
                    );

                return(true);
            }
            else
            {
                errorMessages.Add("Person Add History requires a valid person");
                return(false);
            }
        }
Beispiel #5
0
        private void SaveTransaction(FinancialGateway financialGateway, GatewayComponent gateway, Person person, PaymentInfo paymentInfo, FinancialTransaction transaction, RockContext rockContext)
        {
            transaction.AuthorizedPersonAliasId = person.PrimaryAliasId;
            if (RockTransactionEntry != null)
            {
                RockCheckBox cbGiveAnonymouslyControl = (( RockCheckBox )(RockTransactionEntry.FindControl("cbGiveAnonymously")));
                if (cbGiveAnonymouslyControl != null)
                {
                    transaction.ShowAsAnonymous = cbGiveAnonymouslyControl.Checked;
                }
            }
            transaction.TransactionDateTime = RockDateTime.Now;
            transaction.FinancialGatewayId  = financialGateway.Id;

            var txnType = DefinedValueCache.Get(this.GetAttributeValue("TransactionType").AsGuidOrNull() ?? Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid());

            transaction.TransactionTypeValueId = txnType.Id;

            transaction.Summary = paymentInfo.Comment1;

            if (transaction.FinancialPaymentDetail == null)
            {
                transaction.FinancialPaymentDetail = new FinancialPaymentDetail();
            }
            transaction.FinancialPaymentDetail.SetFromPaymentInfo(paymentInfo, gateway, rockContext);

            Guid sourceGuid = Guid.Empty;

            if (Guid.TryParse(GetAttributeValue("Source"), out sourceGuid))
            {
                var source = DefinedValueCache.Get(sourceGuid);
                if (source != null)
                {
                    transaction.SourceTypeValueId = source.Id;
                }
            }

            var transactionEntity = this.GetTransactionEntity();

            foreach (var account in GetSelectedAccounts().Where(a => a.Amount > 0))
            {
                var transactionDetail = new FinancialTransactionDetail();
                transactionDetail.Amount    = account.Amount;
                transactionDetail.AccountId = account.Id;
                if (transactionEntity != null)
                {
                    transactionDetail.EntityTypeId = transactionEntity.TypeId;
                    transactionDetail.EntityId     = transactionEntity.Id;
                }

                transaction.TransactionDetails.Add(transactionDetail);
            }

            var batchService = new FinancialBatchService(rockContext);

            // Get the batch
            var batch = batchService.Get(
                GetAttributeValue("BatchNamePrefix"),
                paymentInfo.CurrencyTypeValue,
                paymentInfo.CreditCardTypeValue,
                transaction.TransactionDateTime.Value,
                financialGateway.GetBatchTimeOffset());

            var batchChanges = new History.HistoryChangeList();

            if (batch.Id == 0)
            {
                batchChanges.AddCustom("Add", "Record", "Generated the batch");
                History.EvaluateChange(batchChanges, "Batch Name", string.Empty, batch.Name);
                History.EvaluateChange(batchChanges, "Status", null, batch.Status);
                History.EvaluateChange(batchChanges, "Start Date/Time", null, batch.BatchStartDateTime);
                History.EvaluateChange(batchChanges, "End Date/Time", null, batch.BatchEndDateTime);
            }

            decimal newControlAmount = batch.ControlAmount + transaction.TotalAmount;

            History.EvaluateChange(batchChanges, "Control Amount", batch.ControlAmount.FormatAsCurrency(), newControlAmount.FormatAsCurrency());
            batch.ControlAmount = newControlAmount;

            transaction.BatchId = batch.Id;
            transaction.LoadAttributes(rockContext);

            var allowedTransactionAttributes = GetAttributeValue("AllowedTransactionAttributesFromURL").Split(',').AsGuidList().Select(x => AttributeCache.Get(x).Key);

            foreach (KeyValuePair <string, AttributeValueCache> attr in transaction.AttributeValues)
            {
                if (PageParameters().ContainsKey("Attribute_" + attr.Key) && allowedTransactionAttributes.Contains(attr.Key))
                {
                    attr.Value.Value = Server.UrlDecode(PageParameter("Attribute_" + attr.Key));
                }
            }

            batch.Transactions.Add(transaction);

            rockContext.SaveChanges();
            transaction.SaveAttributeValues();

            HistoryService.SaveChanges(
                rockContext,
                typeof(FinancialBatch),
                Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(),
                batch.Id,
                batchChanges
                );

            SendReceipt(transaction.Id);

            TransactionCode = transaction.TransactionCode;
        }