/// <summary> /// Handles the Delete event of the grdFinancialBatch 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 rGridBatch_Delete(object sender, RowEventArgs e) { var FinancialBatchService = new Rock.Model.FinancialBatchService(); Rock.Model.FinancialBatch FinancialBatch = FinancialBatchService.Get((int)rGridBatch.DataKeys[e.RowIndex]["id"]); if (FinancialBatch != null) { FinancialBatchService.Delete(FinancialBatch, CurrentPersonId); FinancialBatchService.Save(FinancialBatch, CurrentPersonId); } BindGrid(); }
/// <summary> /// Handles the Click event of the btnSaveFinancialBatch 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 btnSaveFinancialBatch_Click(object sender, EventArgs e) { using (new Rock.Data.UnitOfWorkScope()) { var financialBatchService = new Rock.Model.FinancialBatchService(); Rock.Model.FinancialBatch financialBatch = null; int financialBatchId = 0; if (!string.IsNullOrEmpty(hfIdValue.Value)) { financialBatchId = Int32.Parse(hfIdValue.Value); } if (financialBatchId == 0) { financialBatch = new Rock.Model.FinancialBatch(); financialBatch.CreatedByPersonId = CurrentPersonId.Value; financialBatchService.Add(financialBatch, CurrentPersonId); } else { financialBatch = financialBatchService.Get(financialBatchId); } financialBatch.Name = tbName.Text; financialBatch.BatchStartDateTime = dtBatchDate.LowerValue; financialBatch.BatchEndDateTime = dtBatchDate.UpperValue; financialBatch.CampusId = cpCampus.SelectedCampusId; financialBatch.Status = (BatchStatus)ddlStatus.SelectedIndex; decimal fcontrolamt = 0; decimal.TryParse(tbControlAmount.Text, out fcontrolamt); financialBatch.ControlAmount = fcontrolamt; financialBatchService.Save(financialBatch, CurrentPersonId); } BindGrid(); NavigateToParentPage(); }
/// <summary> /// Handles the Delete event of the grdFinancialBatch 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 rGridBatch_Delete( object sender, RowEventArgs e ) { var FinancialBatchService = new Rock.Model.FinancialBatchService(); Rock.Model.FinancialBatch FinancialBatch = FinancialBatchService.Get( (int)rGridBatch.DataKeys[e.RowIndex]["id"] ); if ( FinancialBatch != null ) { FinancialBatchService.Delete( FinancialBatch, CurrentPersonId ); FinancialBatchService.Save( FinancialBatch, CurrentPersonId ); } BindGrid(); }
/// <summary> /// Processes the confirmation. /// </summary> /// <param name="errorMessage">The error message.</param> /// <returns></returns> private bool ProcessConfirmation( out string errorMessage ) { if ( string.IsNullOrWhiteSpace( TransactionCode ) ) { GatewayComponent gateway = hfPaymentTab.Value == "ACH" ? _achGateway : _ccGateway; if ( gateway == null ) { errorMessage = "There was a problem creating the payment gateway information"; return false; } Person person = GetPerson( true ); if ( person == null ) { errorMessage = "There was a problem creating the person information"; return false; } PaymentInfo paymentInfo = GetPaymentInfo(); if ( paymentInfo == null ) { errorMessage = "There was a problem creating the payment information"; return false; } else { paymentInfo.FirstName = person.FirstName; paymentInfo.LastName = person.LastName; } if ( paymentInfo.CreditCardTypeValue != null ) { CreditCardTypeValueId = paymentInfo.CreditCardTypeValue.Id; } PaymentSchedule schedule = GetSchedule(); if ( schedule != null ) { schedule.PersonId = person.Id; var scheduledTransaction = gateway.AddScheduledPayment( schedule, paymentInfo, out errorMessage ); if ( scheduledTransaction != null ) { scheduledTransaction.TransactionFrequencyValueId = schedule.TransactionFrequencyValue.Id; scheduledTransaction.AuthorizedPersonId = person.Id; scheduledTransaction.GatewayEntityTypeId = EntityTypeCache.Read( gateway.TypeGuid ).Id; foreach ( var account in SelectedAccounts.Where( a => a.Amount > 0 ) ) { var transactionDetail = new FinancialScheduledTransactionDetail(); transactionDetail.Amount = account.Amount; transactionDetail.AccountId = account.Id; scheduledTransaction.ScheduledTransactionDetails.Add( transactionDetail ); } var transactionService = new FinancialScheduledTransactionService(); transactionService.Add( scheduledTransaction, CurrentPersonId ); transactionService.Save( scheduledTransaction, CurrentPersonId ); ScheduleId = scheduledTransaction.GatewayScheduleId; TransactionCode = scheduledTransaction.TransactionCode; } else { return false; } } else { var transaction = gateway.Charge( paymentInfo, out errorMessage ); if ( transaction != null ) { transaction.TransactionDateTime = DateTime.Now; transaction.AuthorizedPersonId = person.Id; transaction.GatewayEntityTypeId = gateway.TypeId; transaction.Amount = paymentInfo.Amount; transaction.TransactionTypeValueId = DefinedValueCache.Read(new Guid(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION)).Id; transaction.CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id; transaction.CreditCardTypeValueId = CreditCardTypeValueId; Guid sourceGuid = Guid.Empty; if (Guid.TryParse(GetAttributeValue("Source"), out sourceGuid)) { transaction.SourceTypeValueId = DefinedValueCache.Read(sourceGuid).Id; } foreach ( var account in SelectedAccounts.Where( a => a.Amount > 0 ) ) { var transactionDetail = new FinancialTransactionDetail(); transactionDetail.Amount = account.Amount; transactionDetail.AccountId = account.Id; transaction.TransactionDetails.Add( transactionDetail ); } // Get the batch name string ccSuffix = string.Empty; if ( paymentInfo.CreditCardTypeValue != null ) { ccSuffix = paymentInfo.CreditCardTypeValue.GetAttributeValue( "BatchNameSuffix" ); } if ( string.IsNullOrWhiteSpace( ccSuffix ) ) { ccSuffix = paymentInfo.CurrencyTypeValue.Name; } string batchName = GetAttributeValue( "BatchNamePrefix" ).Trim() + " " + ccSuffix; using ( new UnitOfWorkScope() ) { var batchService = new FinancialBatchService(); var batch = batchService.Queryable() .Where( b => b.Status == BatchStatus.Open && b.BatchStartDateTime <= transaction.TransactionDateTime && b.BatchEndDateTime > transaction.TransactionDateTime && b.Name == batchName ) .FirstOrDefault(); if ( batch == null ) { batch = new FinancialBatch(); batch.Name = batchName; batch.Status = BatchStatus.Open; batch.BatchStartDateTime = transaction.TransactionDateTime.Value.Date.Add( gateway.BatchTimeOffset ); if ( batch.BatchStartDateTime > transaction.TransactionDateTime ) { batch.BatchStartDateTime.Value.AddDays( -1 ); } batch.BatchEndDateTime = batch.BatchStartDateTime.Value.AddDays( 1 ).AddMilliseconds( -1 ); batch.CreatedByPersonId = person.Id; batchService.Add( batch, CurrentPersonId ); batchService.Save( batch, CurrentPersonId ); batch = batchService.Get( batch.Id ); } batch.ControlAmount += transaction.Amount; batchService.Save( batch, CurrentPersonId ); var transactionService = new FinancialTransactionService(); transaction.BatchId = batch.Id; transactionService.Add( transaction, CurrentPersonId ); transactionService.Save( transaction, CurrentPersonId ); } TransactionCode = transaction.TransactionCode; } else { return false; } } tdTransactionCode.Description = TransactionCode; tdTransactionCode.Visible = !string.IsNullOrWhiteSpace( TransactionCode ); tdScheduleId.Description = ScheduleId; tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId ); // If there was a transaction code returned and this was not already created from a previous saved account, // show the option to save the account. if ( !( paymentInfo is ReferencePaymentInfo ) && !string.IsNullOrWhiteSpace( TransactionCode ) ) { cbSaveAccount.Visible = true; pnlSaveAccount.Visible = true; txtSaveAccount.Visible = true; // If current person does not have a login, have them create a username and password phCreateLogin.Visible = !new UserLoginService().GetByPersonId( person.Id ).Any(); } else { pnlSaveAccount.Visible = false; } return true; } else { pnlDupWarning.Visible = true; errorMessage = string.Empty; return false; } }
/// <summary> /// Handles the Click event of the btnSaveFinancialBatch 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 btnSaveFinancialBatch_Click( object sender, EventArgs e ) { using ( new Rock.Data.UnitOfWorkScope() ) { var financialBatchService = new FinancialBatchService(); FinancialBatch financialBatch = null; int financialBatchId = 0; if ( !string.IsNullOrEmpty( hfBatchId.Value ) ) { financialBatchId = int.Parse( hfBatchId.Value ); } if ( financialBatchId == 0 ) { financialBatch = new Rock.Model.FinancialBatch(); financialBatch.CreatedByPersonId = CurrentPersonId.Value; financialBatchService.Add( financialBatch, CurrentPersonId ); } else { financialBatch = financialBatchService.Get( financialBatchId ); } financialBatch.Name = tbName.Text; financialBatch.BatchStartDateTime = dtBatchDate.LowerValue; financialBatch.BatchEndDateTime = dtBatchDate.UpperValue; financialBatch.CampusId = cpCampus.SelectedCampusId; financialBatch.Status = (BatchStatus) ddlStatus.SelectedIndex; decimal fcontrolamt = 0; decimal.TryParse( tbControlAmount.Text, out fcontrolamt ); financialBatch.ControlAmount = fcontrolamt; if ( !financialBatch.IsValid ) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction( () => { financialBatchService.Save( financialBatch, CurrentPersonId ); hfBatchId.SetValue( financialBatch.Id ); } ); } var savedFinancialBatch = new FinancialBatchService().Get( hfBatchId.ValueAsInt() ); ShowReadOnly( savedFinancialBatch ); }