Example #1
0
        /// <summary>
        /// Binds the transaction details.
        /// </summary>
        private void BindAccounts()
        {
            var accounts = TransactionDetailsState.ToList();

            gAccountsEdit.DataSource = accounts;
            gAccountsEdit.DataBind();
        }
Example #2
0
        /// <summary>
        /// Shows the account dialog.
        /// </summary>
        /// <param name="guid">The unique identifier.</param>
        private void ShowAccountDialog(Guid guid)
        {
            hfAccountGuid.Value = guid.ToString();

            var txnDetail = TransactionDetailsState.Where(d => d.Guid.Equals(guid)).FirstOrDefault();

            if (txnDetail != null)
            {
                apAccount.SetValue(txnDetail.AccountId);
                tbAccountAmount.Text  = txnDetail.Amount.ToString("N2");
                tbAccountSummary.Text = txnDetail.Summary;

                if (txnDetail.Attributes == null)
                {
                    txnDetail.LoadAttributes();
                }
            }
            else
            {
                apAccount.SetValue(null);
                tbAccountAmount.Text  = string.Empty;
                tbAccountSummary.Text = string.Empty;

                txnDetail = new FinancialScheduledTransactionDetail();
                txnDetail.LoadAttributes();
            }

            phAccountAttributeEdits.Controls.Clear();
            Helper.AddEditControls(txnDetail, phAccountAttributeEdits, true, mdAccount.ValidationGroup);

            ShowDialog("ACCOUNT");
        }
Example #3
0
        /// <summary>
        /// Handles the SaveClick event of the mdAccount 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 mdAccount_SaveClick(object sender, EventArgs e)
        {
            Guid?guid = hfAccountGuid.Value.AsGuidOrNull();

            if (guid.HasValue)
            {
                var txnDetail = TransactionDetailsState.Where(t => t.Guid.Equals(guid.Value)).FirstOrDefault();
                if (txnDetail == null)
                {
                    txnDetail = new FinancialScheduledTransactionDetail();
                    TransactionDetailsState.Add(txnDetail);
                }
                txnDetail.AccountId = apAccount.SelectedValue.AsInteger();
                txnDetail.Amount    = tbAccountAmount.Text.AsDecimal();
                txnDetail.Summary   = tbAccountSummary.Text;

                txnDetail.LoadAttributes();
                Rock.Attribute.Helper.GetEditValues(phAccountAttributeEdits, txnDetail);
                foreach (var attributeValue in txnDetail.AttributeValues)
                {
                    txnDetail.SetAttributeValue(attributeValue.Key, attributeValue.Value.Value);
                }

                BindAccounts();
            }

            HideDialog();
        }
Example #4
0
        /// <summary>
        /// Handles the SaveClick event of the mdAccount 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 mdAccount_SaveClick(object sender, EventArgs e)
        {
            Guid?guid = hfAccountGuid.Value.AsGuidOrNull();

            if (guid.HasValue)
            {
                var financialTransactionDetail = TransactionDetailsState.Where(t => t.Guid.Equals(guid.Value)).FirstOrDefault();
                if (financialTransactionDetail == null)
                {
                    financialTransactionDetail = new FinancialScheduledTransactionDetail();
                    TransactionDetailsState.Add(financialTransactionDetail);
                }

                financialTransactionDetail.AccountId = apAccount.SelectedValue.AsInteger();
                var feeCoverageAmount = tbAccountFeeCoverageAmount.Value;
                financialTransactionDetail.Amount            = (tbAccountAmountMinusFeeCoverageAmount.Value ?? 0.0M) + (feeCoverageAmount ?? 0.00M);
                financialTransactionDetail.FeeCoverageAmount = feeCoverageAmount;
                financialTransactionDetail.Summary           = tbAccountSummary.Text;

                financialTransactionDetail.LoadAttributes();
                Rock.Attribute.Helper.GetEditValues(phAccountAttributeEdits, financialTransactionDetail);
                foreach (var attributeValue in financialTransactionDetail.AttributeValues)
                {
                    financialTransactionDetail.SetAttributeValue(attributeValue.Key, attributeValue.Value.Value);
                }

                BindAccounts();
            }

            HideDialog();
        }
Example #5
0
        /// <summary>
        /// Shows the edit details.
        /// </summary>
        /// <param name="txn">The TXN.</param>
        private void ShowEditDetails(FinancialTransaction txn, RockContext rockContext)
        {
            this.Page.ClientScript.RegisterStartupScript(
                this.GetType(),
                "StartupScript", @"Sys.Application.add_load(function () {

                // if the person picker is empty then open it for quick entry
                var personPicker = $('.js-authorizedperson');
                var currentPerson = personPicker.find('.picker-selectedperson').html();
                if (currentPerson != null && currentPerson.length == 0) {
                    $(personPicker).find('a.picker-label').trigger('click');
                }

            });", true);

            if (txn != null)
            {
                BindDropdowns(rockContext);

                hfTransactionId.Value = txn.Id.ToString();

                SetHeadingInfo(txn);

                SetEditMode(true);

                if (txn.AuthorizedPersonAlias != null)
                {
                    ppAuthorizedPerson.SetValue(txn.AuthorizedPersonAlias.Person);
                }
                else
                {
                    ppAuthorizedPerson.SetValue(null);
                }
                dtTransactionDateTime.SelectedDateTime = txn.TransactionDateTime;
                ddlTransactionType.SetValue(txn.TransactionTypeValueId);
                ddlSourceType.SetValue(txn.SourceTypeValueId);
                cpPaymentGateway.SetValue(txn.GatewayEntityType != null ? txn.GatewayEntityType.Guid.ToString().ToUpper() : string.Empty);
                tbTransactionCode.Text = txn.TransactionCode;
                ddlCurrencyType.SetValue(txn.CurrencyTypeValueId);
                ddlCreditCardType.SetValue(txn.CreditCardTypeValueId);
                SetCreditCardVisibility();

                TransactionDetailsState = txn.TransactionDetails.ToList();
                TransactionImagesState  = txn.Images.OrderBy(i => i.Order).Select(i => i.BinaryFileId).ToList();

                if (TransactionDetailsState.Count() == 1)
                {
                    UseSimpleAccountMode = true;
                }
                else
                {
                    UseSimpleAccountMode = false;
                }
                BindAccounts();

                tbSummary.Text = txn.Summary;

                BindImages();
            }
        }
Example #6
0
 /// <summary>
 /// Handles the Click event of the lbShowMore 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 lbShowMore_Click(object sender, EventArgs e)
 {
     if (TransactionDetailsState.Count() == 1)
     {
         TransactionDetailsState.First().Amount = tbSingleAccountAmount.Text.AsDecimal();
         UseSimpleAccountMode = false;
         BindAccounts();
     }
 }
Example #7
0
        /// <summary>
        /// Handles the DeleteClick event of the gAccountsEdit 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 gAccountsEdit_DeleteClick(object sender, RowEventArgs e)
        {
            Guid?guid = e.RowKeyValue.ToString().AsGuidOrNull();

            if (guid.HasValue)
            {
                var txnDetail = TransactionDetailsState.Where(t => t.Guid.Equals(guid.Value)).FirstOrDefault();
                if (txnDetail != null)
                {
                    TransactionDetailsState.Remove(txnDetail);
                }

                BindAccounts();
            }
        }
Example #8
0
        /// <summary>
        /// Handles the SaveClick event of the mdAccount 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 mdAccount_SaveClick(object sender, EventArgs e)
        {
            Guid?guid = hfAccountGuid.Value.AsGuidOrNull();

            if (guid.HasValue)
            {
                var txnDetail = TransactionDetailsState.Where(t => t.Guid.Equals(guid.Value)).FirstOrDefault();
                if (txnDetail == null)
                {
                    txnDetail = new FinancialTransactionDetail();
                    TransactionDetailsState.Add(txnDetail);
                }
                txnDetail.AccountId = ddlAccount.SelectedValue.AsInteger();
                txnDetail.Amount    = tbAccountAmount.Text.AsDecimal();
                txnDetail.Summary   = tbAccountSummary.Text;

                BindAccounts();
            }

            HideDialog();
        }
Example #9
0
        /// <summary>
        /// Binds the transaction details.
        /// </summary>
        private void BindAccounts()
        {
            if (UseSimpleAccountMode && TransactionDetailsState.Count() == 1)
            {
                var txnDetail = TransactionDetailsState.First();
                tbSingleAccountAmount.Label = AccountName(txnDetail.AccountId);
                tbSingleAccountAmount.Text  = txnDetail.Amount.ToString("N2");
            }
            else
            {
                var accounts = TransactionDetailsState.ToList();
                accounts.Add(new FinancialTransactionDetail
                {
                    AccountId = int.MinValue,
                    Amount    = TransactionDetailsState.Sum(d => (decimal?)d.Amount) ?? 0.0M
                });

                gAccountsEdit.DataSource = accounts;
                gAccountsEdit.DataBind();
            }
        }
Example #10
0
        /// <summary>
        /// Shows the account dialog.
        /// </summary>
        /// <param name="guid">The unique identifier.</param>
        private void ShowAccountDialog(Guid guid)
        {
            hfAccountGuid.Value = guid.ToString();

            var txnDetail = TransactionDetailsState.Where(d => d.Guid.Equals(guid)).FirstOrDefault();

            if (txnDetail != null)
            {
                ddlAccount.SetValue(txnDetail.AccountId);
                tbAccountAmount.Text  = txnDetail.Amount.ToString("N2");
                tbAccountSummary.Text = txnDetail.Summary;
            }
            else
            {
                ddlAccount.SelectedIndex = -1;
                tbAccountSummary.Text    = string.Empty;
                tbAccountSummary.Text    = string.Empty;
            }

            ShowDialog("ACCOUNT");

            _focusControl = tbAccountAmount;
        }
Example #11
0
        protected void lbSaveAccounts_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var txn = GetTransaction(rockContext);
                {
                    decimal totalAmount = TransactionDetailsState.Select(d => d.Amount).ToList().Sum();
                    if (txn.TotalAmount != totalAmount)
                    {
                        nbError.Title   = "Incorrect Amount";
                        nbError.Text    = string.Format("<p>When updating account allocations, the total amount needs to remain the same as the original amount ({0}).</p>", txn.TotalAmount.FormatAsCurrency());
                        nbError.Visible = true;
                        return;
                    }

                    var txnDetailService = new FinancialScheduledTransactionDetailService(rockContext);
                    var accountService   = new FinancialAccountService(rockContext);

                    // Delete any transaction details that were removed
                    var txnDetailsInDB = txnDetailService.Queryable().Where(a => a.ScheduledTransactionId.Equals(txn.Id)).ToList();
                    var deletedDetails = from txnDetail in txnDetailsInDB
                                         where !TransactionDetailsState.Select(d => d.Guid).Contains(txnDetail.Guid)
                                         select txnDetail;

                    bool accountChanges = deletedDetails.Any();

                    deletedDetails.ToList().ForEach(txnDetail =>
                    {
                        txnDetailService.Delete(txnDetail);
                    });

                    var changeSummary = new StringBuilder();

                    // Save Transaction Details
                    foreach (var editorTxnDetail in TransactionDetailsState)
                    {
                        editorTxnDetail.Account = accountService.Get(editorTxnDetail.AccountId);

                        // Add or Update the activity type
                        var txnDetail = txn.ScheduledTransactionDetails.FirstOrDefault(d => d.Guid.Equals(editorTxnDetail.Guid));
                        if (txnDetail == null)
                        {
                            accountChanges = true;
                            txnDetail      = new FinancialScheduledTransactionDetail();
                            txnDetail.Guid = editorTxnDetail.Guid;
                            txn.ScheduledTransactionDetails.Add(txnDetail);
                        }
                        else
                        {
                            if (txnDetail.AccountId != editorTxnDetail.AccountId ||
                                txnDetail.Amount != editorTxnDetail.Amount ||
                                txnDetail.Summary != editorTxnDetail.Summary)
                            {
                                accountChanges = true;
                            }
                        }

                        changeSummary.AppendFormat("{0}: {1}", editorTxnDetail.Account != null ? editorTxnDetail.Account.Name : "?", editorTxnDetail.Amount.FormatAsCurrency());
                        changeSummary.AppendLine();

                        txnDetail.AccountId = editorTxnDetail.AccountId;
                        txnDetail.Amount    = editorTxnDetail.Amount;
                        txnDetail.Summary   = editorTxnDetail.Summary;
                    }

                    if (accountChanges)
                    {
                        // save changes
                        rockContext.SaveChanges();

                        // Add a note about the change
                        var noteType = NoteTypeCache.Read(Rock.SystemGuid.NoteType.SCHEDULED_TRANSACTION_NOTE.AsGuid());
                        if (noteType != null)
                        {
                            var noteService = new NoteService(rockContext);
                            var note        = new Note();
                            note.NoteTypeId = noteType.Id;
                            note.EntityId   = txn.Id;
                            note.Caption    = "Updated Transaction";
                            note.Text       = changeSummary.ToString();
                            noteService.Add(note);
                        }
                        rockContext.SaveChanges();
                    }

                    ShowView(txn);
                }
            }
        }
Example #12
0
        /// <summary>
        /// Handles the Click event of the btnSaveAccounts 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 btnSaveAccounts_Click(object sender, EventArgs e)
        {
            using (var rockContext = new RockContext())
            {
                var financialScheduledTransaction = GetTransaction(rockContext);

                decimal totalAmount = TransactionDetailsState.Select(d => d.Amount).ToList().Sum();
                if (financialScheduledTransaction.TotalAmount != totalAmount)
                {
                    nbError.Title   = "Incorrect Amount";
                    nbError.Text    = string.Format("<p>When updating account allocations, the total amount needs to remain the same as the original amount ({0}).</p>", financialScheduledTransaction.TotalAmount.FormatAsCurrency());
                    nbError.Visible = true;
                    return;
                }

                var txnDetailService = new FinancialScheduledTransactionDetailService(rockContext);
                var accountService   = new FinancialAccountService(rockContext);

                // Delete any transaction details that were removed
                var txnDetailsInDB = txnDetailService.Queryable().Where(a => a.ScheduledTransactionId.Equals(financialScheduledTransaction.Id)).ToList();
                var deletedDetails = from txnDetail in txnDetailsInDB
                                     where !TransactionDetailsState.Select(d => d.Guid).Contains(txnDetail.Guid)
                                     select txnDetail;

                bool accountChanges = deletedDetails.Any();

                deletedDetails.ToList().ForEach(txnDetail =>
                {
                    txnDetailService.Delete(txnDetail);
                });

                // Save Transaction Details
                foreach (var editorTxnDetail in TransactionDetailsState)
                {
                    editorTxnDetail.Account = accountService.Get(editorTxnDetail.AccountId);

                    // Add or Update the activity type
                    var financialTransactionDetail = financialScheduledTransaction.ScheduledTransactionDetails.FirstOrDefault(d => d.Guid.Equals(editorTxnDetail.Guid));
                    if (financialTransactionDetail == null)
                    {
                        accountChanges                  = true;
                        financialTransactionDetail      = new FinancialScheduledTransactionDetail();
                        financialTransactionDetail.Guid = editorTxnDetail.Guid;
                        financialScheduledTransaction.ScheduledTransactionDetails.Add(financialTransactionDetail);
                    }
                    else
                    {
                        if (financialTransactionDetail.AccountId != editorTxnDetail.AccountId ||
                            financialTransactionDetail.Amount != editorTxnDetail.Amount ||
                            financialTransactionDetail.Summary != editorTxnDetail.Summary)
                        {
                            accountChanges = true;
                        }
                    }

                    financialTransactionDetail.AccountId = editorTxnDetail.AccountId;
                    financialTransactionDetail.Amount    = editorTxnDetail.Amount;
                    financialTransactionDetail.Summary   = editorTxnDetail.Summary;
                }

                if (accountChanges)
                {
                    // save changes
                    rockContext.SaveChanges();
                }

                ShowView(financialScheduledTransaction);
            }
        }
Example #13
0
        /// <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)
                        {
                            txnDetail      = new FinancialTransactionDetail();
                            txnDetail.Guid = editorTxnDetail.Guid;
                            txn.TransactionDetails.Add(txnDetail);
                        }
                        txnDetail.AccountId = editorTxnDetail.AccountId;
                        txnDetail.Amount    = UseSimpleAccountMode ? tbSingleAccountAmount.Text.AsDecimal() : editorTxnDetail.Amount;
                        txnDetail.Summary   = editorTxnDetail.Summary;
                    }
                    rockContext.SaveChanges();

                    // Delete any transaction images that were removed
                    var orphanedBinaryFileIds = new List <int>();
                    var txnImagesInDB         = txnImageService.Queryable().Where(a => a.TransactionId.Equals(txn.Id)).ToList();
                    foreach (var txnImage in txnImagesInDB.Where(i => !TransactionImagesState.Contains(i.BinaryFileId)))
                    {
                        orphanedBinaryFileIds.Add(txnImage.BinaryFileId);
                        txnImageService.Delete(txnImage);
                    }

                    // Save Transaction Images
                    int imageOrder = 0;
                    foreach (var binaryFileId in TransactionImagesState)
                    {
                        // Add or Update the activity type
                        var txnImage = txnImagesInDB.FirstOrDefault(i => i.BinaryFileId == binaryFileId);
                        if (txnImage == null)
                        {
                            txnImage = new FinancialTransactionImage();
                            txnImage.TransactionId = txn.Id;
                            txn.Images.Add(txnImage);
                        }
                        txnImage.BinaryFileId = binaryFileId;
                        txnImage.Order        = imageOrder;
                        imageOrder++;
                    }
                    rockContext.SaveChanges();

                    // Make sure updated binary files are not temporary
                    foreach (var binaryFile in binaryFileService.Queryable().Where(f => TransactionImagesState.Contains(f.Id)))
                    {
                        binaryFile.IsTemporary = false;
                    }

                    // Delete any orphaned images
                    foreach (var binaryFile in binaryFileService.Queryable().Where(f => orphanedBinaryFileIds.Contains(f.Id)))
                    {
                        binaryFileService.Delete(binaryFile);
                    }

                    rockContext.SaveChanges();
                });

                // Save selected options to session state in order to prefill values for next added txn
                Session["NewTxnDefault_BatchId"]             = txn.BatchId;
                Session["NewTxnDefault_TransactionDateTime"] = txn.TransactionDateTime;
                Session["NewTxnDefault_TransactionType"]     = txn.TransactionTypeValueId;
                Session["NewTxnDefault_SourceType"]          = txn.SourceTypeValueId;
                Session["NewTxnDefault_CurrencyType"]        = txn.CurrencyTypeValueId;
                Session["NewTxnDefault_CreditCardType"]      = txn.CreditCardTypeValueId;
                if (TransactionDetailsState.Count() == 1)
                {
                    Session["NewTxnDefault_Account"] = TransactionDetailsState.First().AccountId;
                }
                else
                {
                    Session.Remove("NewTxnDefault_Account");
                }

                // Requery the batch to support EF navigation properties
                var savedTxn = GetTransaction(txn.Id);
                ShowReadOnlyDetails(savedTxn);
            }
        }