Пример #1
0
        /// <summary>
        /// Shows the read only details.
        /// </summary>
        /// <param name="txn">The TXN.</param>
        private void ShowReadOnlyDetails( FinancialTransaction txn )
        {
            SetEditMode( false );

            if ( txn != null && txn.Id > 0 )
            {
                hfTransactionId.Value = txn.Id.ToString();

                SetHeadingInfo( txn );

                string rockUrlRoot = ResolveRockUrl( "/" );

                var detailsLeft = new DescriptionList()
                    .Add( "Person", ( txn.AuthorizedPersonAlias != null && txn.AuthorizedPersonAlias.Person != null ) ? txn.AuthorizedPersonAlias.Person.GetAnchorTag( rockUrlRoot ) : string.Empty )
                    .Add( "Date/Time", txn.TransactionDateTime.HasValue ? txn.TransactionDateTime.Value.ToString( "g" ) : string.Empty );

                if ( txn.Batch != null )
                {
                    var qryParam = new Dictionary<string, string>();
                    qryParam.Add( "BatchId", txn.Batch.Id.ToString() );
                    string url = LinkedPageUrl( "BatchDetailPage", qryParam );
                    detailsLeft.Add( "Batch", !string.IsNullOrWhiteSpace( url ) ?
                        string.Format( "<a href='{0}'>{1}</a>", url, txn.Batch.Name ) :
                        txn.Batch.Name );
                }

                detailsLeft.Add( "Source", txn.SourceTypeValue != null ? txn.SourceTypeValue.Value : string.Empty );

                if ( txn.FinancialGateway != null )
                {
                    detailsLeft.Add( "Payment Gateway", Rock.Financial.GatewayContainer.GetComponentName( txn.FinancialGateway.Name ) );
                }

                detailsLeft.Add( "Transaction Code", txn.TransactionCode );

                if ( txn.ScheduledTransaction != null )
                {
                    var qryParam = new Dictionary<string, string>();
                    qryParam.Add( "ScheduledTransactionId", txn.ScheduledTransaction.Id.ToString() );
                    string url = LinkedPageUrl( "ScheduledTransactionDetailPage", qryParam );
                    detailsLeft.Add( "Scheduled Transaction Id", !string.IsNullOrWhiteSpace( url ) ?
                        string.Format( "<a href='{0}'>{1}</a>", url, txn.ScheduledTransaction.GatewayScheduleId ) :
                        txn.ScheduledTransaction.GatewayScheduleId );
                }

                if ( txn.FinancialPaymentDetail != null )
                {
                    detailsLeft.Add( "Account #", txn.FinancialPaymentDetail.AccountNumberMasked );
                    if ( txn.FinancialPaymentDetail.CurrencyTypeValue != null )
                    {
                        string currencyType = txn.FinancialPaymentDetail.CurrencyTypeValue.Value;
                        if ( txn.FinancialPaymentDetail.CurrencyTypeValue.Guid.Equals( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid() ) )
                        {
                            currencyType += txn.FinancialPaymentDetail.CreditCardTypeValue != null ? ( " - " + txn.FinancialPaymentDetail.CreditCardTypeValue.Value ) : string.Empty;
                        }
                        detailsLeft.Add( "Currency Type", currencyType );
                    }
                }

                var registrationEntityType = EntityTypeCache.Read( typeof( Rock.Model.Registration ) );
                if ( registrationEntityType != null )
                {
                    var registrationIds = txn.TransactionDetails
                        .Where( d => d.EntityTypeId == registrationEntityType.Id )
                        .Select( d => d.EntityId )
                        .Distinct()
                        .ToList();

                    if ( registrationIds.Any() )
                    {
                        var registrationLinks = new List<string>();
                        using ( var rockContext = new RockContext() )
                        {
                            foreach ( var registration in new RegistrationService(rockContext)
                                .Queryable().AsNoTracking()
                                .Where( r =>
                                    r.RegistrationInstance != null &&
                                    r.RegistrationInstance.RegistrationTemplate != null &&
                                    registrationIds.Contains( r.Id ) ) )
                            {
                                var qryParam = new Dictionary<string, string>();
                                qryParam.Add("RegistrationId", registration.Id.ToString() );
                                registrationLinks.Add( string.Format( "<a href='{0}'>{1} - {2}</a>",
                                    LinkedPageUrl( "RegistrationDetailPage", qryParam ),
                                    registration.RegistrationInstance.RegistrationTemplate.Name,
                                    registration.RegistrationInstance.Name ) );
                            }
                        }
                        if ( registrationLinks.Any() )
                        {
                            detailsLeft.Add( "Registration", registrationLinks.AsDelimited( "<br/>" ) );
                        }
                    }
                }

                detailsLeft.Add( "Summary", txn.Summary.ConvertCrLfToHtmlBr() );

                if ( txn.RefundDetails != null )
                {
                    var refundTxt = "Yes";
                    if ( txn.RefundDetails.OriginalTransaction != null )
                    {
                        var qryParam = new Dictionary<string, string>();
                        qryParam.Add( "transactionId", txn.RefundDetails.OriginalTransaction.Id.ToStringSafe() );
                        string url = new PageReference( CurrentPageReference.PageId, 0, qryParam ).BuildUrl();
                        refundTxt = string.Format( "Yes (<a href='{0}'>Original Transaction</a>)", url );
                    }
                    detailsLeft.Add( "Refund", refundTxt );

                    if ( txn.RefundDetails.RefundReasonValue != null )
                    {
                        detailsLeft.Add( "Refund Reason", txn.RefundDetails.RefundReasonValue.Value );
                    }
                    detailsLeft.Add( "Refund Summary", txn.RefundDetails.RefundReasonSummary );
                }
                if ( !string.IsNullOrWhiteSpace(txn.Status) )
                {
                    string status = txn.Status;
                    if ( !string.IsNullOrWhiteSpace( txn.StatusMessage ) )
                    {
                        status += string.Format( "<br/><small>{0}</small>", txn.StatusMessage.ConvertCrLfToHtmlBr() );
                    }
                    detailsLeft.Add( "Status", status );
                }

                var modified = new StringBuilder(); ;
                if ( txn.CreatedByPersonAlias != null && txn.CreatedByPersonAlias.Person != null && txn.CreatedDateTime.HasValue )
                {
                    modified.AppendFormat( "Created by {0} on {1} at {2}<br/>", txn.CreatedByPersonAlias.Person.GetAnchorTag( rockUrlRoot ),
                        txn.CreatedDateTime.Value.ToShortDateString(), txn.CreatedDateTime.Value.ToShortTimeString() );
                }
                if ( txn.ProcessedByPersonAlias != null && txn.ProcessedByPersonAlias.Person != null && txn.ProcessedDateTime.HasValue )
                {
                    modified.AppendFormat( "Processed by {0} on {1} at {2}<br/>", txn.ProcessedByPersonAlias.Person.GetAnchorTag( rockUrlRoot ),
                        txn.ProcessedDateTime.Value.ToShortDateString(), txn.ProcessedDateTime.Value.ToShortTimeString() );
                }
                if ( txn.ModifiedByPersonAlias != null && txn.ModifiedByPersonAlias.Person != null && txn.ModifiedDateTime.HasValue )
                {
                    modified.AppendFormat( "Last Modified by {0} on {1} at {2}<br/>", txn.ModifiedByPersonAlias.Person.GetAnchorTag( rockUrlRoot ),
                        txn.ModifiedDateTime.Value.ToShortDateString(), txn.ModifiedDateTime.Value.ToShortTimeString() );
                }
                detailsLeft.Add( "Updates", modified.ToString() );

                lDetailsLeft.Text = detailsLeft.Html;

                var accounts = txn.TransactionDetails.ToList();
                accounts.Add( new FinancialTransactionDetail
                {
                    AccountId = int.MinValue,
                    Amount = txn.TransactionDetails.Sum( d => (decimal?)d.Amount ) ?? 0.0M
                });
                gAccountsView.DataSource = accounts;
                gAccountsView.DataBind();

                if ( txn.Images.Any() )
                {
                    pnlImages.Visible = true;

                    var primaryImage = txn.Images
                        .OrderBy( i => i.Order )
                        .FirstOrDefault();
                    imgPrimary.ImageUrl = string.Format( "~/GetImage.ashx?id={0}", primaryImage.BinaryFileId );

                    rptrImages.DataSource = txn.Images
                        .Where( i => !i.Id.Equals( primaryImage.Id ) )
                        .OrderBy( i => i.Order )
                        .ToList();
                    rptrImages.DataBind();
                }
                else
                {
                    pnlImages.Visible = false;
                }

                var refunds = txn.Refunds
                    .Where( r =>
                        r.FinancialTransaction != null &&
                        r.FinancialTransaction.TransactionDateTime.HasValue )
                    .OrderBy( r => r.FinancialTransaction.TransactionDateTime.Value )
                    .ToList();
                if ( refunds.Any() )
                {
                    pnlRefunds.Visible = true;
                    gRefunds.DataSource = refunds
                        .Select( r => new
                        {
                            Id = r.FinancialTransaction.Id,
                            TransactionDateTime = r.FinancialTransaction.TransactionDateTime.Value.ToShortDateString() + " " +
                                r.FinancialTransaction.TransactionDateTime.Value.ToShortTimeString(),
                            TransactionCode = r.FinancialTransaction.TransactionCode,
                            TotalAmount = r.FinancialTransaction.TotalAmount
                        } )
                        .ToList();
                    gRefunds.DataBind();
                }
                else
                {
                    pnlRefunds.Visible = false;
                }

                if ( !string.IsNullOrWhiteSpace( txn.TransactionCode ) )
                {
                    using ( var rockContext = new RockContext() )
                    {
                        var relatedTxns = new FinancialTransactionService( rockContext )
                            .Queryable().AsNoTracking()
                            .Where( t =>
                                t.TransactionCode == txn.TransactionCode &&
                                t.AuthorizedPersonAliasId == txn.AuthorizedPersonAliasId &&
                                t.Id != txn.Id &&
                                t.TransactionDateTime.HasValue )
                            .OrderBy( t => t.TransactionDateTime.Value )
                            .ToList();
                        if ( relatedTxns.Any() )
                        {
                            pnlRelated.Visible = true;
                            gRelated.DataSource = relatedTxns
                                .Select( t => new
                                {
                                    Id = t.Id,
                                    TransactionDateTime = t.TransactionDateTime.Value.ToShortDateString() + " " +
                                        t.TransactionDateTime.Value.ToShortTimeString(),
                                    TransactionCode = t.TransactionCode,
                                    TotalAmount = t.TotalAmount
                                } )
                                .ToList();
                            gRelated.DataBind();
                        }
                        else
                        {
                            pnlRelated.Visible = false;
                        }
                    }
                }

                Helper.AddDisplayControls(txn, Helper.GetAttributeCategories(txn, false, false), phAttributes, null, false);
                Helper.AddDisplayControls(txn.FinancialPaymentDetail, Helper.GetAttributeCategories(txn.FinancialPaymentDetail, false, false), phAttributes, null, false);
            }
            else
            {
                nbEditModeMessage.Text = EditModeMessage.NotAuthorizedToEdit( FinancialTransaction.FriendlyTypeName );
            }
        }