private void DisplayResults() { RockContext rockContext = new RockContext(); var statementYear = PageParameter(PageParameterKey.StatementYear).AsIntegerOrNull() ?? RockDateTime.Now.Year; FinancialTransactionDetailService financialTransactionDetailService = new FinancialTransactionDetailService(rockContext); Person targetPerson = CurrentPerson; var personGuid = PageParameter(PageParameterKey.PersonGuid).AsGuidOrNull(); if (personGuid.HasValue) { // if "AllowPersonQueryString is False", only use the PersonGuid if it is a Guid of one of the current person's businesses var isCurrentPersonsBusiness = targetPerson != null && targetPerson.GetBusinesses().Any(b => b.Guid == personGuid.Value); if (GetAttributeValue(AttributeKey.AllowPersonQueryString).AsBoolean() || isCurrentPersonsBusiness) { var person = new PersonService(rockContext).Get(personGuid.Value); if (person != null) { targetPerson = person; } } } FinancialStatementGeneratorOptions financialStatementGeneratorOptions = new FinancialStatementGeneratorOptions(); var startDate = new DateTime(statementYear, 1, 1); financialStatementGeneratorOptions.StartDate = startDate; financialStatementGeneratorOptions.EndDate = startDate.AddYears(1); financialStatementGeneratorOptions.RenderMedium = "Html"; var financialStatementTemplateGuid = this.GetAttributeValue(AttributeKey.FinancialStatementTemplate).AsGuidOrNull() ?? Rock.SystemGuid.FinancialStatementTemplate.ROCK_DEFAULT.AsGuid(); financialStatementGeneratorOptions.FinancialStatementTemplateId = new FinancialStatementTemplateService(rockContext).GetId(financialStatementTemplateGuid); FinancialStatementGeneratorRecipient financialStatementGeneratorRecipient = new FinancialStatementGeneratorRecipient(); if (targetPerson.GivingGroupId.HasValue) { financialStatementGeneratorRecipient.GroupId = targetPerson.GivingGroupId.Value; } else { financialStatementGeneratorRecipient.GroupId = targetPerson.PrimaryFamilyId ?? 0; financialStatementGeneratorRecipient.PersonId = targetPerson.Id; } FinancialStatementGeneratorRecipientRequest financialStatementGeneratorRecipientRequest = new FinancialStatementGeneratorRecipientRequest(financialStatementGeneratorOptions) { FinancialStatementGeneratorRecipient = financialStatementGeneratorRecipient }; var result = FinancialStatementGeneratorHelper.GetStatementGeneratorRecipientResult(financialStatementGeneratorRecipientRequest, this.CurrentPerson); Response.Write(result.Html); Response.End(); }
/// <summary> /// Copies the base properties from a source FinancialStatementGeneratorOptions object /// </summary> /// <param name="source">The source.</param> public void CopyPropertiesFrom(FinancialStatementGeneratorOptions source) { this.DataViewId = source.DataViewId; this.EnablePageCountPredetermination = source.EnablePageCountPredetermination; this.EndDate = source.EndDate; this.ExcludeInActiveIndividuals = source.ExcludeInActiveIndividuals; this.FinancialStatementTemplateId = source.FinancialStatementTemplateId; this.IncludeBusinesses = source.IncludeBusinesses; this.IndividualSaveOptions = source.IndividualSaveOptions; this.PersonId = source.PersonId; this.RenderMedium = source.RenderMedium; this.ReportConfigurationList = source.ReportConfigurationList; this.StartDate = source.StartDate; }
public HttpResponseMessage RenderGivingStatement( int personId, [FromUri] int?year = null, [FromUri] int?templateDefinedValueId = null, [FromUri] int?financialStatementTemplateId = null, [FromUri] bool hideRefundedTransactions = true) { if (templateDefinedValueId.HasValue) { // if they specified templateDefinedValueId, they are wanting the obsolete version of api/GivingStatement. So call the obsolete version of it #pragma warning disable CS0618 var legacyHtml = StatementGeneratorFinancialTransactionsController.GetGivingStatementHTML(personId, year, templateDefinedValueId, hideRefundedTransactions, this.GetPerson()); #pragma warning restore CS0618 // Render the statement as HTML and send back to the user var legacyResponse = new HttpResponseMessage(); legacyResponse.Content = new StringContent(legacyHtml); legacyResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return(legacyResponse); } // Assume the current year if no year is specified var currentYear = RockDateTime.Now.Year; year = year ?? currentYear; var isCurrentYear = year == currentYear; var startDate = new DateTime(year.Value, 1, 1); var endDate = isCurrentYear ? RockDateTime.Now : new DateTime(year.Value + 1, 1, 1); // Declare the necessary services var rockContext = new RockContext(); var personService = new PersonService(rockContext); // Get the family ID var person = personService.Get(personId); if (person == null) { throw new FinancialGivingStatementException(string.Format("The person with ID {0} could not be found", personId)); } if (!person.PrimaryFamilyId.HasValue) { throw new FinancialGivingStatementException(string.Format("The person with ID {0} does not have a primary family ID", personId)); } // Build the options for the generator var options = new FinancialStatementGeneratorOptions { EndDate = endDate, FinancialStatementTemplateId = financialStatementTemplateId, StartDate = startDate, }; var financialStatementGeneratorRecipientRequest = new FinancialStatementGeneratorRecipientRequest(options); if (person.GivingGroupId.HasValue) { // If person has a GivingGroupId get the combined statement for the GivingGroup financialStatementGeneratorRecipientRequest.FinancialStatementGeneratorRecipient = new FinancialStatementGeneratorRecipient { GroupId = person.GivingGroupId.Value, PersonId = null }; } else { // If person gives individually ( GivingGroupId is null) get the individual statement for the person // and specify Group as the Primary Family so we know which Family to use for the address. financialStatementGeneratorRecipientRequest.FinancialStatementGeneratorRecipient = new FinancialStatementGeneratorRecipient { GroupId = person.PrimaryFamilyId.Value, PersonId = person.Id }; } // Get the generator result FinancialStatementGeneratorRecipientResult result = FinancialStatementGeneratorHelper.GetStatementGeneratorRecipientResult(financialStatementGeneratorRecipientRequest, this.GetPerson()); // Render the statement as HTML and send back to the user var response = new HttpResponseMessage(); response.Content = new StringContent(result.Html); response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return(response); }