Re: [GNC] Scheduled Transaction Calculations

2019-11-02 Thread John Ralls



> On Nov 2, 2019, at 7:08 AM, Fred Bone  wrote:
> 
> On 01 November 2019 at 12:34, John Ralls said:
> 
> [...]
>> 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))
> 
> This will produce a non-integer result if
> (a) prev month includes daylight-saving-time shift
> or
> (b) prev month includes a leap second.
> 
> (While I'm not familiar with Scheme, if the potential non-integer result 
> isn't an issue -- i.e. if it gets auto-rounded to nearest integer -- then 
> there was no point in adding the odd second).
> 

Time in GnuCash is UTC internally so there are no daylight-time changes. A leap 
second might be an issue, though a rather rare one.

See https://www.gnu.org/software/guile/manual/html_node/Exactness.html. Without 
adding the second back in the result of the division for October was 
2678399/86400. One could instead use 
  (round (/ (- (gnc:get-end-prev-month) (gnc:get-start-prev-month 86400))
which would resolve the leap-second problem.

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.


Re: [GNC] Scheduled Transaction Calculations

2019-11-02 Thread Fred Bone
On 01 November 2019 at 12:34, John Ralls said:

[...]
> 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))

This will produce a non-integer result if
(a) prev month includes daylight-saving-time shift
or
(b) prev month includes a leap second.

(While I'm not familiar with Scheme, if the potential non-integer result 
isn't an issue -- i.e. if it gets auto-rounded to nearest integer -- then 
there was no point in adding the odd second).


___
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.


Re: [GNC] Scheduled Transaction Calculations

2019-11-01 Thread John Ralls
Glad (and a little surprised) that it worked. The naming problem makes sense in 
retrospect. It's standard for scheme but the expression parser has to deal with 
normal arithmetic notation so it would see the hyphens as minus signs and each 
fragment (days, in, prev, and month) as separate tokens.

I'm at a loss about the load-from-path issue, though I know that it's fiddly.

Regards,
John Ralls



> On Nov 1, 2019, at 4:35 PM, Fross, Michael  wrote:
> 
> Hi John,
> 
> I got it to work, but one challenge remains.  The load-from-path seems to 
> crash Gnucash.  But copying the app-utils.scm to the fin.scm folder solves 
> the problem, but it's sloppy.
> 
> I'll need to play around with it.
> 
> Secondly, I it didn't like the name "days-in-prev-mon"  But I shortened it 
> and took out the dashes and that seems ok.  Here is what I inserted in 
> fin.scm:
> 
> ;; Return number of days in the previous month
> (load-from-path "C:\Program Files 
> (x86)\gnucash\share\gnucash\scm\gnucash\app-utils")
> (define (gnc:numdayslastmon)
>(/
>   (+ 1 
>  (- (gnc:get-end-prev-month) (gnc:get-start-prev-month))) 86400)
> )
> 
> 
> Thanks again for your help!
> 
> Michael
> 
> On Fri, Nov 1, 2019 at 3:25 PM Fross, Michael  wrote:
> Thanks John.  I'll give is a shot and report back.
> 
> Michael
> 
> On Fri, Nov 1, 2019 at 2:34 PM John Ralls  wrote:
> 
> 
> > On Nov 1, 2019, at 9:36 AM, Fross, Michael  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
> >  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.


Re: [GNC] Scheduled Transaction Calculations

2019-11-01 Thread Fross, Michael
Hi John,

I got it to work, but one challenge remains.  The load-from-path seems to
crash Gnucash.  But copying the app-utils.scm to the fin.scm folder solves
the problem, but it's sloppy.

I'll need to play around with it.

Secondly, I it didn't like the name "days-in-prev-mon"  But I shortened it
and took out the dashes and that seems ok.  Here is what I inserted in
fin.scm:

;; Return number of days in the previous month
(load-from-path "C:\Program Files
(x86)\gnucash\share\gnucash\scm\gnucash\app-utils")
(define (gnc:numdayslastmon)
   (/
  (+ 1
 (- (gnc:get-end-prev-month) (gnc:get-start-prev-month))) 86400)
)


Thanks again for your help!

Michael

On Fri, Nov 1, 2019 at 3:25 PM Fross, Michael  wrote:

> Thanks John.  I'll give is a shot and report back.
>
> Michael
>
> On Fri, Nov 1, 2019 at 2:34 PM John Ralls  wrote:
>
>>
>>
>> > On Nov 1, 2019, at 9:36 AM, Fross, Michael  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
>> >  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.


Re: [GNC] Scheduled Transaction Calculations

2019-11-01 Thread Fross, Michael
Thanks John.  I'll give is a shot and report back.

Michael

On Fri, Nov 1, 2019 at 2:34 PM John Ralls  wrote:

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


Re: [GNC] Scheduled Transaction Calculations

2019-11-01 Thread John Ralls



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


[GNC] Scheduled Transaction Calculations

2019-11-01 Thread Fross, Michael
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
 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?

Thank you.

Michael
___
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.