scheduled transactions

Mike Talbot mike.talbot@zepler.org
Fri, 2 Feb 2001 22:00:35 +0000


Hello,

Just a few thoughts on the scheduled transactions front: why not have the 
transaction frequency specified as a function, so the scheduled transaction 
would look something like this:

typedef int (*FreqFunc) (int);

struct ScheduledTransaction 
{
	int 		due_date;
	FreqFunc 	freq_func;
	int		n_pmts;		/* number of payments left (decrement each time a scheduled 
					 * transaction is entered, or -1 not to use n_pmts)
					 * scheduled transaction stops when n_pmts reaches 0.
					 */
	int		end_date;	/* date after which scheduled transaction stops, 
					 * or -1 to not use it
					 */
					/* if n_pmts and end_date are both -1, scheduled transaction
					 * continues forever (or until stopped manually)
					 */
	...
	/* transaction details */
	...
}

The FreqFunc would calculate the next due_date from the current due_date.  
e.g.

int daily(int current_due_date)
{
	return current_due_date + 1;
}

Every day (or every time gnucash runs), for each scheduled transaction a 
check is made to see if today's date >= due_date, if so the transaction is 
entered into the register (maybe asking the user for confirmation first) and 
due_date and n_pmts are updated:

due_date = freq_func(due_date);
if (n_pmts > 0)
{
	n_pmts--;
}


I think this would create a much more flexable system: a number of 'standard' 
frequency functions can be defined (along the lines of Joshua's 
FrequencyEnum), but there is then scope for a 'user defined' function(s) 
(presumably written in scheme) so users can create the most complicated 
scheduled transactions they can dream of!

I'm not familiar with the gnucash code, so I don't know how complicated this 
would be to implement.  However from a UI point of view, I think the 
scheduled transactions should have a drop-down list of available frequency 
functions, consisting of built-in functions & user defined scheme functions 
(defined in a file(s) somewhere perhaps).

I know most users probably won't want to learn & write scheme functions, but 
a library of functions could be built up & shared easily...

Any thoughts?