Custom dates for archive providers.

Discussions relating to plugin development, and the Jiwa API.

Custom dates for archive providers.

Postby pricerc » Wed Mar 03, 2021 6:41 pm

There an outstanding request (https://service.jiwa.com.au/browse/DEV-8612) for 'other' dates for the archiving tool.

Having just been testing this for a client, adding new date filters for a provider is quite easy, except that the values are coded in SQL, which gets added into some other SQL before being executed.

The 'default' "Two year" filter looks like this:
Code: Select all
SELECT DATEADD(year,-2,GETDATE())


Which gives you two years prior to the date of execution. But what if you want to archive whole financial years, and you're already months into the year?

Well, since Jiwa kindly has a table of financial years - the GL_Config table, it should be easy enough to use that.
Code: Select all
SELECT MAX([YearStartingDate])
  FROM [dbo].[GL_Config]
  WHERE DATEDIFF(year, [YearStartingDate], GETDATE()) > 5
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Re: Custom dates for archive providers.

Postby DannyC » Fri Mar 05, 2021 11:34 am

I use variation of this SQL to get the financial year start date from nn years ago.

Code: Select all
SELECT DATEADD(year,-7,DATEADD(mm,DATEDIFF(mm,0,GETDATE()) + 7 - MONTH(GETDATE())-CASE WHEN 7 > MONTH(GETDATE()) THEN 12 ELSE 0 END,0))
User avatar
DannyC
Senpai
Senpai
 
Posts: 636
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 30

Re: Custom dates for archive providers.

Postby pricerc » Fri Mar 05, 2021 1:30 pm

DannyC wrote:I use variation of this SQL to get the financial year start date from nn years ago.

Code: Select all
SELECT DATEADD(year,-7,DATEADD(mm,DATEDIFF(mm,0,GETDATE()) + 7 - MONTH(GETDATE())-CASE WHEN 7 > MONTH(GETDATE()) THEN 12 ELSE 0 END,0))


I've got a whole SQL function for doing those, which is great if you don't have ready access to a table with the data, or don't want to hit the table for some reason.

But for the archiving, if you take a look at the stored procedure, it's just using the query to populate a cutoff variable prior to running the queries to do the actual work, so hitting the table isn't an issue, and so using it makes for nice, simple query with no date maths, and it doesn't matter what month you start your financial year (we have customers who start in April and January), it will still work.

The only bit I haven't confirmed is whether I should be using the YearEndingDate for the archiving. Depends on whether it's using a < or a <=.
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 6 guests

cron