Example #1
0
        /// <summary>
        /// Handles the RowDataBound event of the grdFinancialBatch control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
        protected void rGridBatch_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Rock.Model.FinancialBatch batch = e.Row.DataItem as Rock.Model.FinancialBatch;
            if (batch != null)
            {
                Literal lDateRange       = e.Row.FindControl("lDateRange") as Literal;
                Literal TransactionTotal = e.Row.FindControl("TransactionTotal") as Literal;
                if (TransactionTotal != null)
                {
                    var data     = batch.Transactions.Where(d => d.Amount > 0);
                    var totalSum = data.Sum(d => d.Amount);
                    TransactionTotal.Text = String.Format("{0:C}", totalSum);

                    Literal Variance = e.Row.FindControl("Variance") as Literal;
                    if (Variance != null)
                    {
                        if (batch.ControlAmount > 0)
                        {
                            var variance = Convert.ToDecimal(batch.ControlAmount) - totalSum;
                            Variance.Text = String.Format("{0:C}", variance);
                        }
                    }
                }
                Literal TransactionCount = e.Row.FindControl("TransactionCount") as Literal;
                if (TransactionCount != null)
                {
                    TransactionCount.Text = batch.Transactions.Count.ToString();
                }
            }
        }
Example #2
0
        /// <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 lbSaveFinancialBatch 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 lbSaveFinancialBatch_Click(object sender, EventArgs e)
        {
            var            rockContext           = new RockContext();
            var            financialBatchService = new FinancialBatchService(rockContext);
            FinancialBatch financialBatch        = null;

            int financialBatchId = 0;

            if (!string.IsNullOrEmpty(hfBatchId.Value))
            {
                financialBatchId = int.Parse(hfBatchId.Value);
            }

            if (financialBatchId == 0)
            {
                financialBatch = new Rock.Model.FinancialBatch();
                financialBatchService.Add(financialBatch);
            }
            else
            {
                financialBatch = financialBatchService.Get(financialBatchId);
            }

            financialBatch.Name = tbName.Text;
            financialBatch.BatchStartDateTime = drpBatchDate.LowerValue;
            financialBatch.BatchEndDateTime   = drpBatchDate.UpperValue;
            financialBatch.CampusId           = campCampus.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;
            }

            rockContext.SaveChanges();
            hfBatchId.SetValue(financialBatch.Id);

            foreach (var block in RockPage.RockBlocks.OfType <RockWeb.Blocks.Finance.TransactionList>())
            {
                ((RockWeb.Blocks.Finance.TransactionList)block).RefreshList();
            }

            var savedFinancialBatch = new FinancialBatchService(rockContext).Get(hfBatchId.ValueAsInt());

            ShowSummary(savedFinancialBatch);
        }
Example #4
0
        /// <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);
        }
Example #5
0
        /// <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 );
        }
        /// <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();
        }
Example #7
0
 /// <summary>
 /// Instantiates a new DTO object from the entity
 /// </summary>
 /// <param name="financialBatch"></param>
 public FinancialBatchDto(FinancialBatch financialBatch)
 {
     CopyFromModel(financialBatch);
 }
Example #8
0
 /// <summary>
 /// To the dto.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static FinancialBatchDto ToDto(this FinancialBatch value)
 {
     return(new FinancialBatchDto(value));
 }
Example #9
0
        /// <summary>
        /// Handles the RowDataBound event of the gBatchList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridViewRowEventArgs"/> instance containing the event data.</param>
        protected void gBatchList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Rock.Model.FinancialBatch batch = e.Row.DataItem as Rock.Model.FinancialBatch;
            if (batch != null)
            {
                var startDate = Convert.ToDateTime(e.Row.DataItem.GetPropertyValue("BatchStartDateTime")).ToShortDateString();
                e.Row.Cells[1].Text = startDate;

                Literal transactionTotal = e.Row.FindControl("TransactionTotal") as Literal;
                if (transactionTotal != null)
                {
                    var data     = batch.Transactions.Where(d => d.TotalAmount > 0);
                    var totalSum = data.Sum(d => d.TotalAmount);
                    transactionTotal.Text = string.Format("{0:C}", totalSum);

                    Label variance = e.Row.FindControl("lblVariance") as Label;
                    if (variance != null)
                    {
                        if (batch.ControlAmount > 0)
                        {
                            var varianceAmount = Convert.ToDecimal(batch.ControlAmount) - totalSum;
                            variance.Text = string.Format("{0:C}", varianceAmount);
                            if (varianceAmount != 0)
                            {
                                variance.AddCssClass("text-danger");
                            }
                        }
                    }
                }

                Literal transactionCount = e.Row.FindControl("TransactionCount") as Literal;
                if (transactionCount != null)
                {
                    transactionCount.Text = batch.Transactions.Count.ToString();
                }

                var status = e.Row.DataItem.GetPropertyValue("Status").ToString();
                if (!string.IsNullOrWhiteSpace(status))
                {
                    switch (status.ToUpper())
                    {
                    case "CLOSED":
                        e.Row.Cells[7].Text = "<span class='label label-success'>Closed</span>";
                        break;

                    case "OPEN":
                        e.Row.Cells[7].Text = "<span class='label label-warning'>Open</span>";
                        break;

                    case "PENDING":
                        e.Row.Cells[7].Text = "<span class='label label-default'>Pending</span>";
                        break;
                    }
                }

                // Get any warnings for this row and display them in the Warnings column
                Label warnings    = e.Row.FindControl("lblWarnings") as Label;
                var   warningList = GetWarnings(batch);
                if (warningList != null)
                {
                    foreach (var warning in warningList)
                    {
                        switch (warning.ToUpper())
                        {
                        case "UNTIED":
                            warnings.Text += "<span class='label label-danger'>Untied Transactions</span>";
                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the lbSaveFinancialBatch 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 lbSaveFinancialBatch_Click( object sender, EventArgs e )
        {
            var rockContext = new RockContext();
            var financialBatchService = new FinancialBatchService( rockContext );
            FinancialBatch financialBatch = null;

            int financialBatchId = 0;
            if ( !string.IsNullOrEmpty( hfBatchId.Value ) )
            {
                financialBatchId = int.Parse( hfBatchId.Value );
            }

            if ( financialBatchId == 0 )
            {
                financialBatch = new Rock.Model.FinancialBatch();
                financialBatchService.Add( financialBatch );
            }
            else
            {
                financialBatch = financialBatchService.Get( financialBatchId );
            }

            financialBatch.Name = tbName.Text;
            financialBatch.BatchStartDateTime = drpBatchDate.LowerValue;
            financialBatch.BatchEndDateTime = drpBatchDate.UpperValue;
            financialBatch.CampusId = campCampus.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;
            }

            rockContext.SaveChanges();
            hfBatchId.SetValue( financialBatch.Id );

            foreach ( var block in RockPage.RockBlocks.OfType<RockWeb.Blocks.Finance.TransactionList>() )
            {
                ( (RockWeb.Blocks.Finance.TransactionList)block ).RefreshList();
            }

            var savedFinancialBatch = new FinancialBatchService( rockContext ).Get( hfBatchId.ValueAsInt() );
            ShowSummary( savedFinancialBatch );
        }
Example #11
0
        /// <summary>
        /// Gets the first FinancialBatch matching the specified filter parameters, or creates a new FinancialBatch if one isn't found.
        /// </summary>
        /// <param name="batchName">Name of the batch.</param>
        /// <param name="transactionDate">The transaction date.</param>
        /// <param name="batchTimeOffset">The batch time offset.</param>
        /// <param name="batches">The batches.</param>
        /// <param name="batchWeeklyDayOfWeek">If batching weekly, the day of the week the batch should begin</param>
        /// <returns></returns>
        public FinancialBatch GetByNameAndDate(string batchName, DateTime transactionDate, TimeSpan batchTimeOffset, DayOfWeek?batchWeeklyDayOfWeek, List <FinancialBatch> batches = null)
        {
            FinancialBatch batch = null;

            // If a list of batches was passed, search those first
            if (batches != null)
            {
                batch = batches
                        .Where(b =>
                               b.Status == BatchStatus.Open &&
                               b.BatchStartDateTime <= transactionDate &&
                               b.BatchEndDateTime > transactionDate &&
                               b.Name == batchName)
                        .OrderByDescending(b => b.BatchStartDateTime)
                        .FirstOrDefault();

                if (batch != null)
                {
                    return(batch);
                }
            }

            // If batch was not found in existing list, search database
            batch = Queryable()
                    .Where(b =>
                           b.Status == BatchStatus.Open &&
                           b.BatchStartDateTime <= transactionDate &&
                           b.BatchEndDateTime > transactionDate &&
                           b.Name == batchName)
                    .OrderByDescending(b => b.BatchStartDateTime)
                    .FirstOrDefault();

            // If still no batch, create a new one
            if (batch == null)
            {
                batch        = new FinancialBatch();
                batch.Guid   = Guid.NewGuid();
                batch.Name   = batchName;
                batch.Status = BatchStatus.Open;

                var isWeekly           = batchWeeklyDayOfWeek.HasValue;
                var batchStartDateTime = transactionDate.Date.Add(batchTimeOffset);

                if (isWeekly)
                {
                    var dayOfWeekDifference = batchWeeklyDayOfWeek.Value - batchStartDateTime.DayOfWeek;
                    batchStartDateTime = batchStartDateTime.AddDays(dayOfWeekDifference);

                    if (batchStartDateTime > transactionDate)
                    {
                        batchStartDateTime = batchStartDateTime.AddDays(-7);
                    }

                    batch.BatchEndDateTime = batchStartDateTime.AddDays(7);
                }
                else
                {
                    if (batchStartDateTime > transactionDate)
                    {
                        batchStartDateTime = batchStartDateTime.AddDays(-1);
                    }

                    batch.BatchEndDateTime = batchStartDateTime.AddDays(1);
                }

                batch.BatchStartDateTime = batchStartDateTime;
                batch.ControlAmount      = 0;
                Add(batch);
            }

            // Add the batch to the list
            if (batches != null)
            {
                batches.Add(batch);
            }

            return(batch);
        }
Example #12
0
        /// <summary>
        /// Gets the specified name prefix.
        /// </summary>
        /// <param name="namePrefix">The name prefix.</param>
        /// <param name="currencyType">Type of the currency.</param>
        /// <param name="creditCardType">Type of the credit card.</param>
        /// <param name="transactionDate">The transaction date.</param>
        /// <param name="batchTimeOffset">The batch time offset.</param>
        /// <param name="batches">The batches.</param>
        /// <returns></returns>
        public FinancialBatch Get(string namePrefix, DefinedValueCache currencyType, DefinedValueCache creditCardType,
                                  DateTime transactionDate, TimeSpan batchTimeOffset, List <FinancialBatch> batches = null)
        {
            // Use the credit card type's batch name suffix, or if that doesn't exist, use the currency type value
            string ccSuffix = string.Empty;

            if (creditCardType != null)
            {
                ccSuffix = creditCardType.GetAttributeValue("BatchNameSuffix");
                if (string.IsNullOrWhiteSpace(ccSuffix))
                {
                    ccSuffix = creditCardType.Value;
                }
            }

            if (string.IsNullOrWhiteSpace(ccSuffix) && currencyType != null)
            {
                ccSuffix = currencyType.Value;
            }

            string batchName = namePrefix.Trim() + (string.IsNullOrWhiteSpace(ccSuffix) ? "" : " " + ccSuffix);

            FinancialBatch batch = null;

            // If a list of batches was passed, search those first
            if (batches != null)
            {
                batch = batches
                        .Where(b =>
                               b.Status == BatchStatus.Open &&
                               b.BatchStartDateTime <= transactionDate &&
                               b.BatchEndDateTime > transactionDate &&
                               b.Name == batchName)
                        .OrderByDescending(b => b.BatchStartDateTime)
                        .FirstOrDefault();

                if (batch != null)
                {
                    return(batch);
                }
            }

            // If batch was not found in existing list, search database
            batch = Queryable()
                    .Where(b =>
                           b.Status == BatchStatus.Open &&
                           b.BatchStartDateTime <= transactionDate &&
                           b.BatchEndDateTime > transactionDate &&
                           b.Name == batchName)
                    .OrderByDescending(b => b.BatchStartDateTime)
                    .FirstOrDefault();

            // If still no batch, create a new one
            if (batch == null)
            {
                batch        = new FinancialBatch();
                batch.Guid   = Guid.NewGuid();
                batch.Name   = batchName;
                batch.Status = BatchStatus.Open;

                var batchStartDateTime = transactionDate.Date.Add(batchTimeOffset);
                if (batchStartDateTime > transactionDate)
                {
                    batchStartDateTime = batchStartDateTime.AddDays(-1);
                }
                batch.BatchStartDateTime = batchStartDateTime;
                batch.BatchEndDateTime   = batchStartDateTime.AddDays(1);

                batch.ControlAmount = 0;
                Add(batch);
            }

            // Add the batch to the list
            if (batches != null)
            {
                batches.Add(batch);
            }

            return(batch);
        }