/// <summary> /// Copies the base properties from a source FinancialStatementGeneratorRecipientResult object /// </summary> /// <param name="source">The source.</param> public void CopyPropertiesFrom(FinancialStatementGeneratorRecipientResult source) { this.ContributionTotal = source.ContributionTotal; this.FooterHtmlFragment = source.FooterHtmlFragment; this.Html = source.Html; this.OptedOut = source.OptedOut; this.PledgeTotal = source.PledgeTotal; this.Recipient = source.Recipient; }
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); }