> On Nov 1, 2019, at 9:36 AM, Fross, Michael <mich...@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



_______________________________________________
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
If you are using Nabble or Gmane, please see 
https://wiki.gnucash.org/wiki/Mailing_Lists for more information.
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.

Reply via email to