Question

Photo of Ken Roach

0

How select transactions in date range (not for statementYear) in ContributionStatementLava.ascx.cs?

In New Zealand our financial year goes from 1/4/(statementYear-1) - 31/3/(statementYear).

How can I select transactions in this date range, not for the statementYear, in ContributionStatementLava.ascx.cs?  (Accessed from the Home > Give > Giving History > Available Contribution Statements).  

I tried this, but it doesn't work:

            var statementYear = RockDateTime.Now.Year;

            if ( Request["StatementYear"] != null ) 
            { 
                Int32.TryParse( Request["StatementYear"].ToString(), out statementYear ); 
            } 

     var statementStartDate_s = "1/4/" + (statementYear-1).ToString(); 
     var statementStartDate_d = convert(datetime,convert(varchar(10),myStatementStartDate_s, 103 ) )
     var statementEndDate_s = "31/3/" + statementYear.ToString(); 
     var statementEndDate_d = convert(datetime,convert(varchar(10),myStatementEndDate_s, 103 ) )

...

            // get the transactions for the person or all the members in the person's giving group (Family)

            var qry = financialTransactionDetailService.Queryable().AsNoTracking()

                        .Where( t => t.Transaction.AuthorizedPersonAliasId.HasValue && personAliasIds.Contains( t.Transaction.AuthorizedPersonAliasId.Value ) );

            qry = qry.Where( t => t.Transaction.TransactionDateTime >= statementStartDate_d && 

      <.Transaction.TransactionDateTime <= statementEndDate_d );

    

But this isn't working.

Have also tried the format  var myStatementEndDate_d = convert(varchar,myStatementEndDate_s, 103 )

I use 103 because our dates are in format dd/MM/yyyy.



  • Photo of Ken Roach

    0

     // set up the start and end dates

         string sStatementStartDate = "01/04/" + (statementYear-1).ToString(); 

         DateTime dStatementStartDate = Convert.ToDateTime( sStatementStartDate );

         string sStatementEndDate = "31/03/" + statementYear.ToString();

         DateTime dStatementEndDate = Convert.ToDateTime( sStatementEndDate );

         var mergeFields = new Dictionary<string, object>();

                mergeFields.Add( "StatementStartDate", sStatementStartDate );

                mergeFields.Add( "StatementEndDate", sStatementEndDate );

                qry = qry.Where( t => t.Transaction.TransactionDateTime >= dStatementStartDate && t.Transaction.TransactionDateTime <= dStatementEndDate );