本文整理汇总了C#中Rock.Model.FinancialTransactionService类的典型用法代码示例。如果您正苦于以下问题:C# FinancialTransactionService类的具体用法?C# FinancialTransactionService怎么用?C# FinancialTransactionService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FinancialTransactionService类属于Rock.Model命名空间,在下文中一共展示了FinancialTransactionService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowDetail
/// <summary>
/// Shows the detail.
/// </summary>
/// <param name="itemKey">The item key.</param>
/// <param name="itemKeyValue">The item key value.</param>
public void ShowDetail( string itemKey, int itemKeyValue )
{
if ( !itemKey.Equals( "transactionId" ) && !!itemKey.Equals( "batchfk" ) )
{
return;
}
FinancialTransaction transaction = null;
if ( !itemKeyValue.Equals( 0 ) )
{
transaction = new FinancialTransactionService( new RockContext() ).Get( itemKeyValue );
}
else
{
transaction = new FinancialTransaction { Id = 0 };
}
hfIdTransValue.Value = transaction.Id.ToString();
hfBatchId.Value = PageParameter( "financialBatchId" );
if ( !readOnly )
{
lbEdit.Visible = true;
if ( transaction.Id > 0 )
{
ShowSummary( transaction );
}
else
{
BindDropdowns();
ShowEdit( transaction );
}
gTransactionDetails.Actions.ShowAdd = true;
gTransactionDetails.IsDeleteEnabled = true;
pnlImageUpload.Visible = true;
}
else
{
lbEdit.Visible = false;
ShowSummary( transaction );
gTransactionDetails.Actions.ShowAdd = false;
gTransactionDetails.IsDeleteEnabled = false;
pnlImageUpload.Visible = false;
}
lbSave.Visible = !readOnly;
LoadAccountDropDown();
BindTransactionDetailGrid( transaction );
BindDefinedTypeDropdown( ddlTransactionImageType, new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_IMAGE_TYPE ), "Transaction Image Type" );
LoadRelatedImages( transaction.Id );
}
示例2: RaisePostBackEvent
public void RaisePostBackEvent( string eventArgument )
{
if ( _batch != null )
{
if ( eventArgument == "MoveTransactions" &&
_ddlMove != null &&
_ddlMove.SelectedValue != null &&
!String.IsNullOrWhiteSpace( _ddlMove.SelectedValue ) )
{
var txnsSelected = new List<int>();
gTransactions.SelectedKeys.ToList().ForEach( b => txnsSelected.Add( b.ToString().AsInteger() ) );
if ( txnsSelected.Any() )
{
var rockContext = new RockContext();
var batchService = new FinancialBatchService( rockContext );
var newBatch = batchService.Get( _ddlMove.SelectedValue.AsInteger() );
var oldBatch = batchService.Get( _batch.Id );
if ( newBatch != null && newBatch.Status == BatchStatus.Open )
{
var txnService = new FinancialTransactionService( rockContext );
var txnsToUpdate = txnService.Queryable()
.Where( t => txnsSelected.Contains( t.Id ) )
.ToList();
foreach ( var txn in txnsToUpdate )
{
txn.BatchId = newBatch.Id;
oldBatch.ControlAmount -= txn.TotalAmount;
newBatch.ControlAmount += txn.TotalAmount;
}
rockContext.SaveChanges();
var pageRef = new Rock.Web.PageReference( RockPage.PageId );
pageRef.Parameters = new Dictionary<string, string>();
pageRef.Parameters.Add( "batchid", newBatch.Id.ToString() );
string newBatchLink = string.Format( "<a href='{0}'>{1}</a>",
pageRef.BuildUrl(), newBatch.Name );
RockPage.UpdateBlocks( "~/Blocks/Finance/BatchDetail.ascx" );
nbResult.Text = string.Format( "{0} transactions were moved to the '{1}' batch.",
txnsToUpdate.Count().ToString( "N0" ), newBatchLink );
nbResult.NotificationBoxType = NotificationBoxType.Success;
nbResult.Visible = true;
}
else
{
nbResult.Text = string.Format( "The selected batch does not exist, or is no longer open." );
nbResult.NotificationBoxType = NotificationBoxType.Danger;
nbResult.Visible = true;
}
}
else
{
nbResult.Text = string.Format( "There were not any transactions selected." );
nbResult.NotificationBoxType = NotificationBoxType.Warning;
nbResult.Visible = true;
}
}
_ddlMove.SelectedIndex = 0;
}
BindGrid();
}
示例3: ShowReadonlyDetails
/// <summary>
/// Shows the financial batch summary.
/// </summary>
/// <param name="batch">The financial batch.</param>
private void ShowReadonlyDetails( FinancialBatch batch )
{
SetEditMode( false );
if ( batch != null )
{
hfBatchId.SetValue( batch.Id );
SetHeadingInfo( batch, batch.Name );
string campusName = string.Empty;
if ( batch.CampusId.HasValue )
{
var campus = CampusCache.Read( batch.CampusId.Value );
if ( campus != null )
{
campusName = campus.ToString();
}
}
var rockContext = new RockContext();
var financialTransactionService = new FinancialTransactionService( rockContext );
var batchTransactions = financialTransactionService.Queryable().Where( a => a.BatchId.HasValue && a.BatchId.Value == batch.Id );
var financialTransactionDetailService = new FinancialTransactionDetailService( rockContext );
var qryTransactionDetails = financialTransactionDetailService.Queryable().Where( a => a.Transaction.BatchId == batch.Id );
decimal txnTotal = qryTransactionDetails.Select( a => (decimal?)a.Amount ).Sum() ?? 0;
decimal variance = txnTotal - batch.ControlAmount;
string amountFormat = string.Format(
"{0} / {1} / " + ( variance == 0.0M ? "{2}" : "<span class='label label-danger'>{2}</span>" ),
txnTotal.FormatAsCurrency(),
batch.ControlAmount.FormatAsCurrency(),
variance.FormatAsCurrency() );
lDetails.Text = new DescriptionList()
.Add( "Date Range", new DateRange( batch.BatchStartDateTime, batch.BatchEndDateTime ).ToString( "g" ) )
.Add( "Transaction / Control / Variance", amountFormat )
.Add( "Accounting Code", batch.AccountingSystemCode )
.Add( "Notes", batch.Note )
.Html;
// Account Summary
gAccounts.DataSource = qryTransactionDetails
.GroupBy( d => new
{
AccountId = d.AccountId,
AccountName = d.Account.Name
} )
.Select( s => new
{
Id = s.Key.AccountId,
Name = s.Key.AccountName,
Amount = s.Sum( a => (decimal?)a.Amount ) ?? 0.0M
} )
.OrderBy( s => s.Name )
.ToList();
gAccounts.DataBind();
// Currency Summary
gCurrencyTypes.DataSource = batchTransactions
.GroupBy( c => new
{
CurrencyTypeValueId = c.FinancialPaymentDetailId.HasValue ? c.FinancialPaymentDetail.CurrencyTypeValueId : 0,
} )
.Select( s => new
{
CurrencyTypeValueId = s.Key.CurrencyTypeValueId,
Amount = s.Sum( a => (decimal?)a.TransactionDetails.Sum( t => t.Amount ) ) ?? 0.0M
} )
.ToList()
.Select( s => new
{
Id = s.CurrencyTypeValueId,
Name = DefinedValueCache.GetName( s.CurrencyTypeValueId ),
Amount = s.Amount
} ).OrderBy( a => a.Name ).ToList();
gCurrencyTypes.DataBind();
}
}
示例4: BindGrid
/// <summary>
/// Binds the grid.
/// </summary>
private void BindGrid( bool isExporting = false )
{
_currencyTypes = new Dictionary<int,string>();
_creditCardTypes = new Dictionary<int,string>();
// If configured for a registration and registration is null, return
int registrationEntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Registration ) ).Id;
if ( ContextTypesRequired.Any( e => e.Id == registrationEntityTypeId ) && _registration == null )
{
return;
}
// If configured for a person and person is null, return
int personEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
if ( ContextTypesRequired.Any( e => e.Id == personEntityTypeId ) && _person == null )
{
return;
}
// If configured for a batch and batch is null, return
int batchEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialBatch" ).Id;
if ( ContextTypesRequired.Any( e => e.Id == batchEntityTypeId ) && _batch == null )
{
return;
}
// If configured for a batch and batch is null, return
int scheduledTxnEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialScheduledTransaction" ).Id;
if ( ContextTypesRequired.Any( e => e.Id == scheduledTxnEntityTypeId ) && _scheduledTxn == null )
{
return;
}
// Qry
var rockContext = new RockContext();
var qry = new FinancialTransactionService( rockContext ).Queryable();
// Transaction Types
var transactionTypeValueIdList = GetAttributeValue( "TransactionTypes" ).SplitDelimitedValues().AsGuidList().Select( a => DefinedValueCache.Read( a ) ).Where( a => a != null ).Select( a => a.Id ).ToList();
if ( transactionTypeValueIdList.Any() )
{
qry = qry.Where( t => transactionTypeValueIdList.Contains( t.TransactionTypeValueId ) );
}
// Set up the selection filter
if ( _batch != null )
{
// If transactions are for a batch, the filter is hidden so only check the batch id
qry = qry.Where( t => t.BatchId.HasValue && t.BatchId.Value == _batch.Id );
// If the batch is closed, do not allow any editing of the transactions
if ( _batch.Status != BatchStatus.Closed && _canEdit )
{
gTransactions.IsDeleteEnabled = _canEdit;
}
else
{
gTransactions.IsDeleteEnabled = false;
}
}
else if ( _scheduledTxn != null )
{
// If transactions are for a batch, the filter is hidden so only check the batch id
qry = qry.Where( t => t.ScheduledTransactionId.HasValue && t.ScheduledTransactionId.Value == _scheduledTxn.Id );
gTransactions.IsDeleteEnabled = false;
}
else if ( _registration != null )
{
qry = qry
.Where( t => t.TransactionDetails
.Any( d =>
d.EntityTypeId.HasValue &&
d.EntityTypeId.Value == registrationEntityTypeId &&
d.EntityId.HasValue &&
d.EntityId.Value == _registration.Id ) );
gTransactions.IsDeleteEnabled = false;
}
else // Person
{
// otherwise set the selection based on filter settings
if ( _person != null )
{
// get the transactions for the person or all the members in the person's giving group (Family)
qry = qry.Where( t => t.AuthorizedPersonAlias.Person.GivingId == _person.GivingId );
}
// Date Range
var drp = new DateRangePicker();
drp.DelimitedValues = gfTransactions.GetUserPreference( "Date Range" );
if ( drp.LowerValue.HasValue )
{
qry = qry.Where( t => t.TransactionDateTime >= drp.LowerValue.Value );
}
//.........这里部分代码省略.........
示例5: gTransactions_Delete
/// <summary>
/// Handles the Delete event of the gTransactions control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param>
protected void gTransactions_Delete( object sender, Rock.Web.UI.Controls.RowEventArgs e )
{
var rockContext = new RockContext();
var transactionService = new FinancialTransactionService( rockContext );
var transaction = transactionService.Get( e.RowKeyId );
if ( transaction != null )
{
string errorMessage;
if ( !transactionService.CanDelete( transaction, out errorMessage ) )
{
mdGridWarning.Show( errorMessage, ModalAlertType.Information );
return;
}
// prevent deleting a Transaction that is in closed batch
if (transaction.Batch != null )
{
if ( transaction.Batch.Status == BatchStatus.Closed )
{
mdGridWarning.Show( string.Format( "This {0} is assigned to a closed {1}", FinancialTransaction.FriendlyTypeName, FinancialBatch.FriendlyTypeName ), ModalAlertType.Information );
return;
}
}
if ( transaction.BatchId.HasValue )
{
string caption = ( transaction.AuthorizedPersonAlias != null && transaction.AuthorizedPersonAlias.Person != null ) ?
transaction.AuthorizedPersonAlias.Person.FullName :
string.Format( "Transaction: {0}", transaction.Id );
HistoryService.SaveChanges(
rockContext,
typeof( FinancialBatch ),
Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(),
transaction.BatchId.Value,
new List<string> { "Deleted transaction" },
caption,
typeof( FinancialTransaction ),
transaction.Id,
false
);
}
transactionService.Delete( transaction );
rockContext.SaveChanges();
RockPage.UpdateBlocks( "~/Blocks/Finance/BatchDetail.ascx" );
}
BindGrid();
}
示例6: lbSaveAccount_Click
/// <summary>
/// Handles the Click event of the lbSaveAccount control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void lbSaveAccount_Click( object sender, EventArgs e )
{
if ( string.IsNullOrWhiteSpace( TransactionCode ) )
{
nbSaveAccount.Text = "Sorry, the account information cannot be saved as there's not a valid transaction code to reference";
nbSaveAccount.Visible = true;
return;
}
using ( var rockContext = new RockContext() )
{
if ( phCreateLogin.Visible )
{
if ( string.IsNullOrWhiteSpace( txtUserName.Text ) || string.IsNullOrWhiteSpace( txtPassword.Text ) )
{
nbSaveAccount.Title = "Missing Informaton";
nbSaveAccount.Text = "A username and password are required when saving an account";
nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
nbSaveAccount.Visible = true;
return;
}
if ( new UserLoginService( rockContext ).GetByUserName( txtUserName.Text ) != null )
{
nbSaveAccount.Title = "Invalid Username";
nbSaveAccount.Text = "The selected Username is already being used. Please select a different Username";
nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
nbSaveAccount.Visible = true;
return;
}
if ( !UserLoginService.IsPasswordValid( txtPassword.Text ) )
{
nbSaveAccount.Title = string.Empty;
nbSaveAccount.Text = UserLoginService.FriendlyPasswordRules();
nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
nbSaveAccount.Visible = true;
return;
}
if ( txtPasswordConfirm.Text != txtPassword.Text )
{
nbSaveAccount.Title = "Invalid Password";
nbSaveAccount.Text = "The password and password confirmation do not match";
nbSaveAccount.NotificationBoxType = NotificationBoxType.Danger;
nbSaveAccount.Visible = true;
return;
}
}
if ( !string.IsNullOrWhiteSpace( txtSaveAccount.Text ) )
{
bool isACHTxn = hfPaymentTab.Value == "ACH";
var financialGateway = isACHTxn ? _achGateway : _ccGateway;
var gateway = isACHTxn ? _achGatewayComponent : _ccGatewayComponent;
if ( gateway != null )
{
var ccCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) );
var achCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) );
string errorMessage = string.Empty;
var person = GetPerson( false );
string referenceNumber = string.Empty;
FinancialPaymentDetail paymentDetail = null;
int? currencyTypeValueId = isACHTxn ? achCurrencyType.Id : ccCurrencyType.Id;
if ( string.IsNullOrWhiteSpace( ScheduleId ) )
{
var transaction = new FinancialTransactionService( rockContext ).GetByTransactionCode( TransactionCode );
if ( transaction != null && transaction.AuthorizedPersonAlias != null )
{
if ( transaction.FinancialGateway != null )
{
transaction.FinancialGateway.LoadAttributes( rockContext );
}
referenceNumber = gateway.GetReferenceNumber( transaction, out errorMessage );
paymentDetail = transaction.FinancialPaymentDetail;
}
}
else
{
var scheduledTransaction = new FinancialScheduledTransactionService( rockContext ).GetByScheduleId( ScheduleId );
if ( scheduledTransaction != null )
{
if ( scheduledTransaction.FinancialGateway != null )
{
scheduledTransaction.FinancialGateway.LoadAttributes( rockContext );
}
referenceNumber = gateway.GetReferenceNumber( scheduledTransaction, out errorMessage );
paymentDetail = scheduledTransaction.FinancialPaymentDetail;
}
}
//.........这里部分代码省略.........
示例7: ProcessConfirmation
/// <summary>
/// Processes the confirmation.
/// </summary>
/// <param name="errorMessage">The error message.</param>
/// <returns></returns>
private bool ProcessConfirmation( out string errorMessage )
{
var rockContext = new RockContext();
if ( string.IsNullOrWhiteSpace( TransactionCode ) )
{
var transactionGuid = hfTransactionGuid.Value.AsGuid();
bool isACHTxn = hfPaymentTab.Value == "ACH";
var financialGateway = isACHTxn ? _achGateway : _ccGateway;
var gateway = isACHTxn ? _achGatewayComponent : _ccGatewayComponent;
if ( gateway == null )
{
errorMessage = "There was a problem creating the payment gateway information";
return false;
}
// only create/update the person if they are giving as a person. If they are giving as a Business, the person record already exists
Person person = GetPerson( !phGiveAsOption.Visible || tglGiveAsOption.Checked );
if ( person == null )
{
errorMessage = "There was a problem creating the person information";
return false;
}
if ( !person.PrimaryAliasId.HasValue )
{
errorMessage = "There was a problem creating the person's primary alias";
return false;
}
Person BusinessOrPerson = GetPersonOrBusiness( person );
PaymentInfo paymentInfo = GetTxnPaymentInfo( BusinessOrPerson, out errorMessage );
if ( paymentInfo == null )
{
return false;
}
PaymentSchedule schedule = GetSchedule();
FinancialPaymentDetail paymentDetail = null;
if ( schedule != null )
{
schedule.PersonId = person.Id;
var scheduledTransactionAlreadyExists = new FinancialScheduledTransactionService( rockContext ).Queryable().FirstOrDefault( a => a.Guid == transactionGuid );
if ( scheduledTransactionAlreadyExists != null )
{
// hopefully shouldn't happen, but just in case the scheduledtransaction already went thru, show the success screen
ShowSuccess( gateway, person, paymentInfo, schedule, scheduledTransactionAlreadyExists.FinancialPaymentDetail, rockContext );
return true;
}
var scheduledTransaction = gateway.AddScheduledPayment( financialGateway, schedule, paymentInfo, out errorMessage );
if ( scheduledTransaction == null )
{
return false;
}
// manually assign the Guid that we generated at the beginning of the transaction UI entry to help make duplicate scheduled transactions impossible
scheduledTransaction.Guid = transactionGuid;
SaveScheduledTransaction( financialGateway, gateway, BusinessOrPerson, paymentInfo, schedule, scheduledTransaction, rockContext );
paymentDetail = scheduledTransaction.FinancialPaymentDetail.Clone( false );
}
else
{
var transactionAlreadyExists = new FinancialTransactionService( rockContext ).Queryable().FirstOrDefault( a => a.Guid == transactionGuid );
if ( transactionAlreadyExists != null )
{
// hopefully shouldn't happen, but just in case the transaction already went thru, show the success screen
ShowSuccess( gateway, person, paymentInfo, null, transactionAlreadyExists.FinancialPaymentDetail, rockContext );
return true;
}
var transaction = gateway.Charge( financialGateway, paymentInfo, out errorMessage );
if ( transaction == null )
{
return false;
}
// manually assign the Guid that we generated at the beginning of the transaction UI entry to help make duplicate transactions impossible
transaction.Guid = transactionGuid;
SaveTransaction( financialGateway, gateway, BusinessOrPerson, paymentInfo, transaction, rockContext );
paymentDetail = transaction.FinancialPaymentDetail.Clone( false );
}
ShowSuccess( gateway, person, paymentInfo, schedule, paymentDetail, rockContext );
return true;
}
else
{
pnlDupWarning.Visible = true;
//.........这里部分代码省略.........
示例8: MapContribution
/// <summary>
/// Maps the contribution.
/// </summary>
/// <param name="tableData">The table data.</param>
/// <param name="selectedColumns">The selected columns.</param>
private void MapContribution( IQueryable<Row> tableData, List<string> selectedColumns = null )
{
var lookupContext = new RockContext();
int transactionEntityTypeId = EntityTypeCache.Read( "Rock.Model.FinancialTransaction" ).Id;
var transactionTypeContributionId = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION ), lookupContext ).Id;
var currencyTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_CURRENCY_TYPE ) );
int currencyTypeACH = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ) ).Id;
int currencyTypeCash = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CASH ) ) ).Id;
int currencyTypeCheck = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CHECK ) ) ).Id;
int currencyTypeCreditCard = currencyTypes.DefinedValues.FirstOrDefault( dv => dv.Guid.Equals( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ) ).Id;
int? currencyTypeNonCash = currencyTypes.DefinedValues.Where( dv => dv.Value.Equals( "Non-Cash" ) ).Select( dv => (int?)dv.Id ).FirstOrDefault();
if ( currencyTypeNonCash == null )
{
var newTenderNonCash = new DefinedValue();
newTenderNonCash.Value = "Non-Cash";
newTenderNonCash.Description = "Non-Cash";
newTenderNonCash.DefinedTypeId = currencyTypes.Id;
lookupContext.DefinedValues.Add( newTenderNonCash );
lookupContext.SaveChanges();
currencyTypeNonCash = newTenderNonCash.Id;
}
var creditCardTypes = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_CREDIT_CARD_TYPE ) ).DefinedValues;
int sourceTypeOnsite = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_ONSITE_COLLECTION ), lookupContext ).Id;
int sourceTypeWebsite = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_WEBSITE ), lookupContext ).Id;
int sourceTypeKiosk = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.FINANCIAL_SOURCE_TYPE_KIOSK ), lookupContext ).Id;
var refundReasons = DefinedTypeCache.Read( new Guid( Rock.SystemGuid.DefinedType.FINANCIAL_TRANSACTION_REFUND_REASON ), lookupContext ).DefinedValues;
var accountList = new FinancialAccountService( lookupContext ).Queryable().AsNoTracking().ToList();
int? defaultBatchId = null;
if ( ImportedBatches.ContainsKey( 0 ) )
{
defaultBatchId = ImportedBatches[0];
}
// Get all imported contributions
var importedContributions = new FinancialTransactionService( lookupContext ).Queryable().AsNoTracking()
.Where( c => c.ForeignId != null )
.ToDictionary( t => (int)t.ForeignId, t => (int?)t.Id );
// List for batching new contributions
var newTransactions = new List<FinancialTransaction>();
int completed = 0;
int totalRows = tableData.Count();
int percentage = ( totalRows - 1 ) / 100 + 1;
ReportProgress( 0, string.Format( "Verifying contribution import ({0:N0} found, {1:N0} already exist).", totalRows, importedContributions.Count ) );
foreach ( var row in tableData.Where( r => r != null ) )
{
int? individualId = row["Individual_ID"] as int?;
int? householdId = row["Household_ID"] as int?;
int? contributionId = row["ContributionID"] as int?;
if ( contributionId != null && !importedContributions.ContainsKey( (int)contributionId ) )
{
var transaction = new FinancialTransaction();
transaction.CreatedByPersonAliasId = ImportPersonAliasId;
transaction.ModifiedByPersonAliasId = ImportPersonAliasId;
transaction.TransactionTypeValueId = transactionTypeContributionId;
transaction.ForeignKey = contributionId.ToString();
transaction.ForeignId = contributionId;
int? giverAliasId = null;
var personKeys = GetPersonKeys( individualId, householdId );
if ( personKeys != null && personKeys.PersonAliasId > 0 )
{
giverAliasId = personKeys.PersonAliasId;
transaction.CreatedByPersonAliasId = giverAliasId;
transaction.AuthorizedPersonAliasId = giverAliasId;
transaction.ProcessedByPersonAliasId = giverAliasId;
}
string summary = row["Memo"] as string;
if ( summary != null )
{
transaction.Summary = summary;
}
int? batchId = row["BatchID"] as int?;
if ( batchId != null && ImportedBatches.Any( b => b.Key.Equals( batchId ) ) )
{
transaction.BatchId = ImportedBatches.FirstOrDefault( b => b.Key.Equals( batchId ) ).Value;
}
else
{
// use the default batch for any non-matching transactions
transaction.BatchId = defaultBatchId;
}
DateTime? receivedDate = row["Received_Date"] as DateTime?;
//.........这里部分代码省略.........
示例9: GetTransaction
/// <summary>
/// Gets the transaction.
/// </summary>
/// <param name="transactionId">The transaction identifier.</param>
/// <param name="rockContext">The rock context.</param>
/// <returns></returns>
private FinancialTransaction GetTransaction( int transactionId, RockContext rockContext = null )
{
rockContext = rockContext ?? new RockContext();
var txn = new FinancialTransactionService( rockContext )
.Queryable( "AuthorizedPerson,TransactionTypeValue,SourceTypeValue,GatewayEntityType,CurrencyTypeValue,TransactionDetails,Images.TransactionImageTypeValue,ScheduledTransaction,ProcessedByPersonAlias.Person" )
.Where( t => t.Id == transactionId )
.FirstOrDefault();
return txn;
}
示例10: lbSave_Click
/// <summary>
/// Handles the Click event of the lbSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void lbSave_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
var txnService = new FinancialTransactionService( rockContext );
var txnDetailService = new FinancialTransactionDetailService( rockContext );
var txnImageService = new FinancialTransactionImageService( rockContext );
var binaryFileService = new BinaryFileService( rockContext );
FinancialTransaction txn = null;
int? txnId = hfTransactionId.Value.AsIntegerOrNull();
int? batchId = hfBatchId.Value.AsIntegerOrNull();
if ( txnId.HasValue )
{
txn = txnService.Get( txnId.Value );
}
if ( txn == null && batchId.HasValue )
{
txn = new FinancialTransaction();
txnService.Add( txn );
txn.BatchId = batchId.Value;
}
if ( txn != null )
{
txn.AuthorizedPersonId = ppAuthorizedPerson.PersonId;
txn.TransactionDateTime = dtTransactionDateTime.SelectedDateTime;
txn.TransactionTypeValueId = ddlTransactionType.SelectedValue.AsInteger();
txn.SourceTypeValueId = ddlSourceType.SelectedValueAsInt();
Guid? gatewayGuid = cpPaymentGateway.SelectedValueAsGuid();
if ( gatewayGuid.HasValue )
{
var gatewayEntity = EntityTypeCache.Read( gatewayGuid.Value );
if ( gatewayEntity != null )
{
txn.GatewayEntityTypeId = gatewayEntity.Id;
}
else
{
txn.GatewayEntityTypeId = null;
}
}
else
{
txn.GatewayEntityTypeId = null;
}
txn.TransactionCode = tbTransactionCode.Text;
txn.CurrencyTypeValueId = ddlCurrencyType.SelectedValueAsInt();
txn.CreditCardTypeValueId = ddlCreditCardType.SelectedValueAsInt();
txn.Summary = tbSummary.Text;
if ( !Page.IsValid || !txn.IsValid )
{
return;
}
foreach ( var txnDetail in TransactionDetailsState )
{
if ( !txnDetail.IsValid )
{
return;
}
}
foreach ( var txnImage in TransactionImagesState )
{
if ( !txnImage.IsValid )
{
return;
}
}
rockContext.WrapTransaction( () =>
{
// Save the transaction
rockContext.SaveChanges();
// Delete any transaction details that were removed
var txnDetailsInDB = txnDetailService.Queryable().Where( a => a.TransactionId.Equals( txn.Id ) ).ToList();
var deletedDetails = from txnDetail in txnDetailsInDB
where !TransactionDetailsState.Select( d => d.Guid ).Contains( txnDetail.Guid )
select txnDetail;
deletedDetails.ToList().ForEach( txnDetail =>
{
txnDetailService.Delete( txnDetail );
} );
rockContext.SaveChanges();
// Save Transaction Details
foreach ( var editorTxnDetail in TransactionDetailsState )
//.........这里部分代码省略.........
示例11: GetExpression
/// <summary>
/// Gets the expression.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <param name="serviceInstance">The service instance.</param>
/// <param name="parameterExpression">The parameter expression.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override Expression GetExpression( Type entityType, IService serviceInstance, ParameterExpression parameterExpression, string selection )
{
var values = selection.Split( '|' );
ComparisonType comparisonType = values[0].ConvertToEnum<ComparisonType>( ComparisonType.EqualTo );
decimal? amountValue = values[1].AsDecimalOrNull();
var qry = new FinancialTransactionService( (RockContext)serviceInstance.Context ).Queryable();
var totalAmountEqualQuery = qry.Where( p => p.TransactionDetails.Sum(a => a.Amount) == amountValue );
BinaryExpression compareEqualExpression = FilterExpressionExtractor.Extract<Rock.Model.FinancialTransaction>( totalAmountEqualQuery, parameterExpression, "p" ) as BinaryExpression;
BinaryExpression result = FilterExpressionExtractor.AlterComparisonType( comparisonType, compareEqualExpression, null );
return result;
}
示例12: GetExpression
/// <summary>
/// Gets the expression.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="entityIdProperty">The entity identifier property.</param>
/// <param name="selection">The selection.</param>
/// <returns></returns>
public override Expression GetExpression( RockContext context, MemberExpression entityIdProperty, string selection )
{
var totalAmountQuery = new FinancialTransactionService( context ).Queryable()
.Select( p => p.TransactionDetails.Sum( a => a.Amount ) );
var selectTotalAmountExpression = SelectExpressionExtractor.Extract( totalAmountQuery, entityIdProperty, "p" );
return selectTotalAmountExpression;
}
示例13: BindPaymentsGrid
/// <summary>
/// Binds the payments grid.
/// </summary>
private void BindPaymentsGrid()
{
int? instanceId = hfRegistrationInstanceId.Value.AsIntegerOrNull();
if ( instanceId.HasValue )
{
using ( var rockContext = new RockContext() )
{
var currencyTypes = new Dictionary<int, string>();
var creditCardTypes = new Dictionary<int, string>();
// If configured for a registration and registration is null, return
int registrationEntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.Registration ) ).Id;
// Get all the registrations for this instance
PaymentRegistrations = new RegistrationService( rockContext )
.Queryable( "PersonAlias.Person,Registrants.PersonAlias.Person" ).AsNoTracking()
.Where( r =>
r.RegistrationInstanceId == instanceId.Value &&
!r.IsTemporary )
.ToList();
// Get the Registration Ids
var registrationIds = PaymentRegistrations
.Select( r => r.Id )
.ToList();
// Get all the transactions relate to these registrations
var qry = new FinancialTransactionService( rockContext )
.Queryable().AsNoTracking()
.Where( t => t.TransactionDetails
.Any( d =>
d.EntityTypeId.HasValue &&
d.EntityTypeId.Value == registrationEntityTypeId &&
d.EntityId.HasValue &&
registrationIds.Contains( d.EntityId.Value ) ) );
// Date Range
var drp = new DateRangePicker();
drp.DelimitedValues = fPayments.GetUserPreference( "Date Range" );
if ( drp.LowerValue.HasValue )
{
qry = qry.Where( t => t.TransactionDateTime >= drp.LowerValue.Value );
}
if ( drp.UpperValue.HasValue )
{
DateTime upperDate = drp.UpperValue.Value.Date.AddDays( 1 );
qry = qry.Where( t => t.TransactionDateTime < upperDate );
}
SortProperty sortProperty = gPayments.SortProperty;
if ( sortProperty != null )
{
if ( sortProperty.Property == "TotalAmount" )
{
if ( sortProperty.Direction == SortDirection.Ascending )
{
qry = qry.OrderBy( t => t.TransactionDetails.Sum( d => (decimal?)d.Amount ) ?? 0.00M );
}
else
{
qry = qry.OrderByDescending( t => t.TransactionDetails.Sum( d => (decimal?)d.Amount ) ?? 0.0M );
}
}
else
{
qry = qry.Sort( sortProperty );
}
}
else
{
qry = qry.OrderByDescending( t => t.TransactionDateTime ).ThenByDescending( t => t.Id );
}
gPayments.SetLinqDataSource( qry.AsNoTracking() );
gPayments.DataBind();
}
}
}
示例14: lbSave_Click
/// <summary>
/// Handles the Click event of the lbSave control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
protected void lbSave_Click( object sender, EventArgs e )
{
var rockContext = new RockContext();
var txnService = new FinancialTransactionService( rockContext );
var txnDetailService = new FinancialTransactionDetailService( rockContext );
var txnImageService = new FinancialTransactionImageService( rockContext );
var binaryFileService = new BinaryFileService( rockContext );
FinancialTransaction txn = null;
int? txnId = hfTransactionId.Value.AsIntegerOrNull();
int? batchId = hfBatchId.Value.AsIntegerOrNull();
if ( txnId.HasValue )
{
txn = txnService.Get( txnId.Value );
}
if ( txn == null )
{
txn = new FinancialTransaction();
txnService.Add( txn );
txn.BatchId = batchId;
}
if ( txn != null )
{
if ( ppAuthorizedPerson.PersonId.HasValue )
{
txn.AuthorizedPersonAliasId = ppAuthorizedPerson.PersonAliasId;
}
txn.TransactionDateTime = dtTransactionDateTime.SelectedDateTime;
txn.TransactionTypeValueId = ddlTransactionType.SelectedValue.AsInteger();
txn.SourceTypeValueId = ddlSourceType.SelectedValueAsInt();
Guid? gatewayGuid = cpPaymentGateway.SelectedValueAsGuid();
if ( gatewayGuid.HasValue )
{
var gatewayEntity = EntityTypeCache.Read( gatewayGuid.Value );
if ( gatewayEntity != null )
{
txn.GatewayEntityTypeId = gatewayEntity.Id;
}
else
{
txn.GatewayEntityTypeId = null;
}
}
else
{
txn.GatewayEntityTypeId = null;
}
txn.TransactionCode = tbTransactionCode.Text;
txn.CurrencyTypeValueId = ddlCurrencyType.SelectedValueAsInt();
txn.CreditCardTypeValueId = ddlCreditCardType.SelectedValueAsInt();
txn.Summary = tbSummary.Text;
if ( !Page.IsValid || !txn.IsValid )
{
return;
}
foreach ( var txnDetail in TransactionDetailsState )
{
if ( !txnDetail.IsValid )
{
return;
}
}
rockContext.WrapTransaction( () =>
{
// Save the transaction
rockContext.SaveChanges();
// Delete any transaction details that were removed
var txnDetailsInDB = txnDetailService.Queryable().Where( a => a.TransactionId.Equals( txn.Id ) ).ToList();
var deletedDetails = from txnDetail in txnDetailsInDB
where !TransactionDetailsState.Select( d => d.Guid ).Contains( txnDetail.Guid )
select txnDetail;
deletedDetails.ToList().ForEach( txnDetail =>
{
txnDetailService.Delete( txnDetail );
} );
rockContext.SaveChanges();
// Save Transaction Details
foreach ( var editorTxnDetail in TransactionDetailsState )
{
// Add or Update the activity type
var txnDetail = txn.TransactionDetails.FirstOrDefault( d => d.Guid.Equals( editorTxnDetail.Guid ) );
if ( txnDetail == null )
//.........这里部分代码省略.........
示例15: ProcessPayments
/// <summary>
/// Processes the payments.
/// </summary>
/// <param name="gateway">The gateway.</param>
/// <param name="batchNamePrefix">The batch name prefix.</param>
/// <param name="payments">The payments.</param>
/// <param name="batchUrlFormat">The batch URL format.</param>
/// <returns></returns>
public static string ProcessPayments( FinancialGateway gateway, string batchNamePrefix, List<Payment> payments, string batchUrlFormat = "" )
{
int totalPayments = 0;
int totalAlreadyDownloaded = 0;
int totalNoScheduledTransaction = 0;
int totalAdded = 0;
var batches = new List<FinancialBatch>();
var batchSummary = new Dictionary<Guid, List<Payment>>();
var initialControlAmounts = new Dictionary<Guid, decimal>();
var allBatchChanges = new Dictionary<Guid, List<string>>();
var allTxnChanges = new Dictionary<Guid, List<string>>();
var txnPersonNames = new Dictionary<Guid, string>();
using ( var rockContext = new RockContext() )
{
var accountService = new FinancialAccountService( rockContext );
var txnService = new FinancialTransactionService( rockContext );
var batchService = new FinancialBatchService( rockContext );
var scheduledTxnService = new FinancialScheduledTransactionService( rockContext );
var contributionTxnType = DefinedValueCache.Read( Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION.AsGuid() );
var defaultAccount = accountService.Queryable()
.Where( a =>
a.IsActive &&
!a.ParentAccountId.HasValue &&
( !a.StartDate.HasValue || a.StartDate.Value <= RockDateTime.Now ) &&
( !a.EndDate.HasValue || a.EndDate.Value >= RockDateTime.Now )
)
.OrderBy( a => a.Order )
.FirstOrDefault();
var batchTxnChanges = new Dictionary<Guid, List<string>>();
var batchBatchChanges = new Dictionary<Guid, List<string>>();
foreach ( var payment in payments.Where( p => p.Amount > 0.0M ) )
{
totalPayments++;
// Only consider transactions that have not already been added
if ( txnService.GetByTransactionCode( payment.TransactionCode ) == null )
{
var scheduledTransaction = scheduledTxnService.GetByScheduleId( payment.GatewayScheduleId );
if ( scheduledTransaction != null )
{
scheduledTransaction.IsActive = payment.ScheduleActive;
var txnChanges = new List<string>();
var transaction = new FinancialTransaction();
transaction.FinancialPaymentDetail = new FinancialPaymentDetail();
transaction.Guid = Guid.NewGuid();
allTxnChanges.Add( transaction.Guid, txnChanges );
txnChanges.Add( "Created Transaction (Downloaded from Gateway)" );
transaction.TransactionCode = payment.TransactionCode;
History.EvaluateChange( txnChanges, "Transaction Code", string.Empty, transaction.TransactionCode );
transaction.TransactionDateTime = payment.TransactionDateTime;
History.EvaluateChange( txnChanges, "Date/Time", null, transaction.TransactionDateTime );
transaction.ScheduledTransactionId = scheduledTransaction.Id;
transaction.AuthorizedPersonAliasId = scheduledTransaction.AuthorizedPersonAliasId;
History.EvaluateChange( txnChanges, "Person", string.Empty, scheduledTransaction.AuthorizedPersonAlias.Person.FullName );
txnPersonNames.Add( transaction.Guid, scheduledTransaction.AuthorizedPersonAlias.Person.FullName );
transaction.FinancialGatewayId = gateway.Id;
History.EvaluateChange( txnChanges, "Gateway", string.Empty, gateway.Name );
transaction.TransactionTypeValueId = contributionTxnType.Id;
History.EvaluateChange( txnChanges, "Type", string.Empty, contributionTxnType.Value );
var currencyTypeValue = payment.CurrencyTypeValue;
var creditCardTypevalue = payment.CreditCardTypeValue;
if ( scheduledTransaction.FinancialPaymentDetail != null )
{
if ( currencyTypeValue == null && scheduledTransaction.FinancialPaymentDetail.CurrencyTypeValueId.HasValue )
{
currencyTypeValue = DefinedValueCache.Read( scheduledTransaction.FinancialPaymentDetail.CurrencyTypeValueId.Value );
}
if ( creditCardTypevalue == null && scheduledTransaction.FinancialPaymentDetail.CreditCardTypeValueId.HasValue )
{
creditCardTypevalue = DefinedValueCache.Read( scheduledTransaction.FinancialPaymentDetail.CreditCardTypeValueId.Value );
}
transaction.FinancialPaymentDetail.AccountNumberMasked = scheduledTransaction.FinancialPaymentDetail.AccountNumberMasked;
//.........这里部分代码省略.........