[GNC] Scheduled Transaction Calculations

John Ralls jralls at ceridwen.us
Fri Nov 1 15:34:28 EDT 2019



> On Nov 1, 2019, at 9:36 AM, Fross, Michael <michael at fross.org> wrote:
> 
> Hello all,
> 
> I have a scheduled transaction that I pay monthly which is a fixed amount
> per day.  I'd love to be able to have is automatically entrer based on the
> number of days per month.  I pay on the 1st (or the first business day
> after that) so basically I'd like to use the following formula:
> 
> Amount = NumDaysInPreviousMonth * AmountPerDay
> 
> I looked through the guide
> <https://wiki.gnucash.org/wiki/Scheduled_Transactions> and didn't see
> anything.  It references fin.scm (link throws a 404 by the way) but I
> didn't see anything here that calculated the number of days in the previous
> month (but perhaps I missed it in the SCM code.)
> 
> This seems like a simple use case, am I missing something? Perhaps I'll
> need to write a function in fin.scm that can return the number of days in a
> provided month.  No idea how to use scheme, but I'm sure I can figure it
> out.
> 
> Thoughts?

I fixed the link.

The closest functions in GnuCash would be gnc:get-start-prev-month and gnc:get-end-prev-month. They return time64 so you'd divide the difference by 86400 (the number of seconds in a day) after adding in 1 second to compensate for gnc:get-start-prev-month's returning the first second of the month rather than the last second of the month before.

You could try adding this to fin.scm:

(load-from-path "gnucash/app-utils")
(define (gnc:days-in-prev-month) (/ ( + 1 (- (gnc:get-end-prev-month) (gnc:get-start-prev-month)))) 86400))

Then use 
  days-in-prev-month() * AmountPerDay
in your scheduled transaction. Replace "AmountPerDay" with the actual numeric amount or the Since Last Run dialog will ask for the amount every month.

I've never actually tried doing anything like that, but it might work.

Regards,
John Ralls





More information about the gnucash-user mailing list