Financial year handling

Yves-Eric Martin yemartin at yve.net
Thu Sep 29 23:01:48 EDT 2005


Hi all,

I posted the message below to gnucash-devel about 2 weeks ago, but it 
did not spark any reply there. Maybe I should have brought the matter on 
the gnucash-user list first? Anyway, here it is:



Hi all,


I would like to help address the issue mentioned in the FAQ
http://gnomesupport.org/wiki/index.php/GnuCashFaq#Q:_The_fiscal_year_is_July_1-June_30.2C_how_can_I_change_that.3F

For businesses, the financial year is paramount, and not being
able to set it renders the "Current Financial Year Start" and
the likes totally useless.

Having seen quite a few requests for that feature in the list
archives, but only workarounds and no mention of anything
being done about it, I went ahead and, following the FAQ
pointer, made some changes in date-utilities.scm, to make it
easy to set the financial year starting month and day by
simply editing at the top of the file:

     ;; fin-year-start format: mm dd
     (define fin-year-start '(07 01))

 From there, "get-start-cur-fin-year" and cousins now return
the right value. See patch file attached.

While this makes it easy to set a global financial year,
it is of course far from a complete solution. We need a
way to set this per file, through the UI (maybe in the
"Book options" dialog accessed by File->Properties?), and
then date-utilities.scm should use the value from the UI
instead of the hardcoded fin-year-start... While it does
not sound like there should be much to do (but I may be
totally out to lunch here...), I am afraid this is way
above my head and I cannot take this any further myself.
Could anyone pick things up from here?

PS: "End Current/Previous Financial Year" options should
be called "Current/Previous Financial Year End" for
consistency with their "Start" counterpart.


Cheers,


-- 
Yves-Eric Martin
-------------- next part --------------
--- date-utilities.scm.ORIG	2005-09-18 01:30:40.000000000 +0900
+++ date-utilities.scm	2005-09-18 03:05:34.000000000 +0900
@@ -1,6 +1,7 @@
 ;; date-utilities.scm -- date utility functions.
 ;; Bryan Larsen (blarsen at ada-works.com)
 ;; Revised by Christopher Browne
+;; Improvement to financial year support by Yves-Eric Martin
 ;;
 ;; This program is free software; you can redistribute it and/or    
 ;; modify it under the terms of the GNU General Public License as   
@@ -19,6 +20,14 @@
 ;; 59 Temple Place - Suite 330        Fax:    +1-617-542-2652
 ;; Boston, MA  02111-1307,  USA       gnu at gnu.org
 
+
+;; fin-year-start format: mm dd
+(define fin-year-start '(07 01))
+
+
+(define fin-year-start-month (- (car fin-year-start) 1)) ;; jan == 0
+(define fin-year-start-day (cadr fin-year-start))
+
 (define gnc:reldate-list '())
 
 (define (gnc:timepair->secs tp)
@@ -435,13 +444,13 @@
 ;; FIXME:: Replace with option when it becomes available
 (define (gnc:get-start-cur-fin-year)
   (let ((now (localtime (current-time))))
-    (if (< (tm:mon now) 6)
+    (if (or (< (tm:mon now) fin-year-start-month) (and (= (tm:mon now) fin-year-start-month) (< (tm:mday now) fin-year-start-day) ))
 	(begin
 	  (set-tm:sec now 0)
 	  (set-tm:min now 0)
 	  (set-tm:hour now 0)
-	  (set-tm:mday now 1)
-	  (set-tm:mon now 6)
+	  (set-tm:mday now fin-year-start-day)
+	  (set-tm:mon now fin-year-start-month)
 	  (set-tm:year now (- (tm:year now) 1))
           (set-tm:isdst now -1)
 	  (gnc:date->timepair now))
@@ -449,20 +458,20 @@
 	  (set-tm:sec now 0)
 	  (set-tm:min now 0)
 	  (set-tm:hour now 0)
-	  (set-tm:mday now 1)
-	  (set-tm:mon now 6)
+	  (set-tm:mday now fin-year-start-day)
+	  (set-tm:mon now fin-year-start-month)
           (set-tm:isdst now -1)
 	  (gnc:date->timepair now)))))
 
 (define (gnc:get-start-prev-fin-year)
   (let ((now (localtime (current-time))))
-    (if (< (tm:mon now) 6)
+    (if (or (< (tm:mon now) fin-year-start-month) (and (= (tm:mon now) fin-year-start-month) (< (tm:mday now) fin-year-start-day) ))
 	(begin
 	  (set-tm:sec now 0)
 	  (set-tm:min now 0)
 	  (set-tm:hour now 0)
-	  (set-tm:mday now 1)
-	  (set-tm:mon now 6)
+	  (set-tm:mday now fin-year-start-day)
+	  (set-tm:mon now fin-year-start-month)
 	  (set-tm:year now (- (tm:year now) 2))
           (set-tm:isdst now -1)
 	  (gnc:date->timepair now))
@@ -470,53 +479,42 @@
 	  (set-tm:sec now 0)
 	  (set-tm:min now 0)
 	  (set-tm:hour now 0)
-	  (set-tm:mday now 1)
-	  (set-tm:mon now 6)
+	  (set-tm:mday now fin-year-start-day)
+	  (set-tm:mon now fin-year-start-month)
 	  (set-tm:year now (- (tm:year now) 1))
           (set-tm:isdst now -1)
 	  (gnc:date->timepair now)))))
 
-(define (gnc:get-end-prev-fin-year)
+(define (gnc:get-start-next-fin-year)
   (let ((now (localtime (current-time))))
-    (if (< (tm:mon now) 6)
+    (if (or (< (tm:mon now) fin-year-start-month) (and (= (tm:mon now) fin-year-start-month) (< (tm:mday now) fin-year-start-day) ))
 	(begin
-	  (set-tm:sec now 59)
-	  (set-tm:min now 59)
-	  (set-tm:hour now 23)
-	  (set-tm:mday now 30)
-	  (set-tm:mon now 5)
-	  (set-tm:year now (- (tm:year now) 1))
+	  (set-tm:sec now 0)
+	  (set-tm:min now 0)
+	  (set-tm:hour now 0)
+	  (set-tm:mday now fin-year-start-day)
+	  (set-tm:mon now fin-year-start-month)
           (set-tm:isdst now -1)
 	  (gnc:date->timepair now))
 	(begin
-	  (set-tm:sec now 59)
-	  (set-tm:min now 59)
-	  (set-tm:hour now 23)
-	  (set-tm:mday now 30)
-	  (set-tm:mon now 5)
+	  (set-tm:sec now 0)
+	  (set-tm:min now 0)
+	  (set-tm:hour now 0)
+	  (set-tm:mday now fin-year-start-day)
+	  (set-tm:mon now fin-year-start-month)
+	  (set-tm:year now (+ (tm:year now) 1))
           (set-tm:isdst now -1)
 	  (gnc:date->timepair now)))))
 
+(define (gnc:get-end-prev-fin-year)
+  (let ((now (gnc:get-start-cur-fin-year)))
+      (gnc:secs->timepair (- (gnc:timepair->secs now) 1))
+      ))
+
 (define (gnc:get-end-cur-fin-year)
-  (let ((now (localtime (current-time))))
-    (if (< (tm:mon now) 6)
-	(begin
-	  (set-tm:sec now 59)
-	  (set-tm:min now 59)
-	  (set-tm:hour now 23)
-	  (set-tm:mday now 30)
-	  (set-tm:mon now 5)
-          (set-tm:isdst now -1)
-	  (gnc:date->timepair now))
-	(begin
-	  (set-tm:sec now 59)
-	  (set-tm:min now 59)
-	  (set-tm:hour now 23)
-	  (set-tm:mday now 30)
-	  (set-tm:mon now 5)
-	  (set-tm:year now (+ (tm:year now) 1))
-          (set-tm:isdst now -1)
-	  (gnc:date->timepair now)))))
+  (let ((now (gnc:get-start-next-fin-year)))
+      (gnc:secs->timepair (- (gnc:timepair->secs now) 1))
+      ))
 
 (define (gnc:get-start-this-month)
   (let ((now (localtime (current-time))))


More information about the gnucash-user mailing list