Patch to allow reconciling sub-accounts

Paul Campbell kemitix@users.sourceforge.net
Sun, 24 Jun 2001 15:48:35 +0100


--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Very impressed with the new 1.6.0 release.  Well done everyone involved.

I'd like to offer a small patch.  To explain why I saw a need to this
let me explain briefly how I wanted to structure my bank account
details.

I wanted to be able to create sub-accounts within my normal bank
account to represent putting money aside for various items.
Particularly annual fees.  I then wanted to pay for these items
directly out of one of these sub-accounts.  This is fine until it
comes to reconciling my bank statement.

The only problem left that I haven't figured out yet is reconciling
transfers *between* the parent account and it's sub-accounts.  The
transaction appears on both sides and needs to be checked of
individually, leaving room for human error if only one side is picked.

The patch modifies the configure.in file, so remember to run autoconf
after applying it.  To enable this feature pass
--enable-reconcile-children to the ./configure script.

Comments, suggestions, etc... welcome.

-- 
Paul Campbell (Sourceforge) <kemitix@users.sourceforge.net>
http://www.kemitix.uklinux.net   SETI@Home Units: 179
jupiter: 2:40pm up 41 days, 6:21, 7 users, load average: 1.24, 1.47, 1.43
'You are knee deep and goin' in'

--2fHTh5uZTiUOsy+g
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="gnucash-1.6.0-reconcile-children.patch"

# This is a patch for gnucash-1.6.0 to update it to gnucash-1.6.0-reconcile-children
# 
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'patch' program with this file as input.
#
#### End of Preamble ####

#### Patch data follows ####
diff -c 'gnucash-1.6.0/config.h.in' 'gnucash-1.6.0-reconcile-children/config.h.in'
Index: ./config.h.in
*** ./config.h.in	Mon Jun 11 01:05:30 2001
--- ./config.h.in	Sun Jun 24 00:40:51 2001
***************
*** 236,238 ****
--- 236,240 ----
  /* is sizeof(long_long) >= sizeof(gint64) */
  #undef GUILE_LONG_LONG_OK
  
+ /* Define if reconciliation is to include sub-accounts */
+ #undef WITH_RECONCILE_CHILDREN
diff -c 'gnucash-1.6.0/configure.in' 'gnucash-1.6.0-reconcile-children/configure.in'
Index: ./configure.in
*** ./configure.in	Mon Jun 11 02:21:47 2001
--- ./configure.in	Sun Jun 24 00:06:27 2001
***************
*** 482,487 ****
--- 482,504 ----
  
  AC_SUBST(GTK_XIM_FLAGS)
  
+ ### --------------------------------------------------------------------------
+ ### RECONCILE_CHILDREN
+ AC_ARG_ENABLE( reconcile-children,
+   [  --enable-reconcile-children  include sub-accounts in reconciliation [default=no]],
+   if test $enableval = no;then
+     WITH_RECONCILE_CHILDREN=0
+   else
+     WITH_RECONCILE_CHILDREN=1
+   fi,
+   WITH_RECONCILE_CHILDREN=0 )
+ 
+ if test ${WITH_RECONCILE_CHILDREN} = 0; then
+   AC_MSG_WARN([Compiling WITHOUT including sub-accounts in reconciliation])
+ else
+   AC_MSG_WARN([Compiling WITH sub-accounts included in reconciliation])
+   AC_DEFINE(WITH_RECONCILE_CHILDREN)
+ fi
  
  ### --------------------------------------------------------------------------
  ### popt
diff -c 'gnucash-1.6.0/src/engine/Account.c' 'gnucash-1.6.0-reconcile-children/src/engine/Account.c'
Index: ./src/engine/Account.c
*** ./src/engine/Account.c	Fri Jun  1 23:45:53 2001
--- ./src/engine/Account.c	Sun Jun 24 15:19:18 2001
***************
*** 1452,1458 ****
  double
  DxaccAccountGetReconciledBalance (Account *acc)
  {
!   return gnc_numeric_to_double(xaccAccountGetReconciledBalance(acc));
  }
  
  double
--- 1452,1458 ----
  double
  DxaccAccountGetReconciledBalance (Account *acc)
  {
!   return gnc_numeric_to_double(xaccAccountGetReconciledBalance(acc, FALSE));
  }
  
  double
***************
*** 1487,1496 ****
  }
  
  gnc_numeric
! xaccAccountGetReconciledBalance (Account *acc)
  {
     if (!acc) return gnc_numeric_zero();
!    return acc->reconciled_balance;
  }
  
  gnc_numeric
--- 1487,1515 ----
  }
  
  gnc_numeric
! xaccAccountGetReconciledBalance (Account *acc, gboolean include_children)
  {
+    AccountGroup * account_group;
+    GList * children_list;
+    GList * node;
+    gnc_numeric balance;
+    gnc_numeric child_balance;
+    Account * child_account;
+ 
     if (!acc) return gnc_numeric_zero();
!    balance = acc->reconciled_balance;
!    if(include_children)
!    {
!       account_group = xaccAccountGetChildren(acc);
!       children_list = xaccGroupGetAccountList(account_group);
!       for(node = children_list; node; node = node->next)
!       {
! 	 child_account = node->data;
! 	 child_balance = xaccAccountGetReconciledBalance(child_account, include_children);
!          balance = gnc_numeric_add_fixed(balance, child_balance);
!       }
!    }
!    return balance;
  }
  
  gnc_numeric
diff -c 'gnucash-1.6.0/src/engine/Account.h' 'gnucash-1.6.0-reconcile-children/src/engine/Account.h'
Index: ./src/engine/Account.h
*** ./src/engine/Account.h	Fri Jun  1 23:45:56 2001
--- ./src/engine/Account.h	Sun Jun 24 11:48:42 2001
***************
*** 244,250 ****
  
  gnc_numeric     xaccAccountGetBalance (Account *account);
  gnc_numeric     xaccAccountGetClearedBalance (Account *account);
! gnc_numeric     xaccAccountGetReconciledBalance (Account *account);
  gnc_numeric     xaccAccountGetShareBalance (Account *account);
  gnc_numeric     xaccAccountGetShareClearedBalance (Account *account);
  gnc_numeric     xaccAccountGetShareReconciledBalance (Account *account);
--- 244,250 ----
  
  gnc_numeric     xaccAccountGetBalance (Account *account);
  gnc_numeric     xaccAccountGetClearedBalance (Account *account);
! gnc_numeric     xaccAccountGetReconciledBalance (Account *account, gboolean include_children);
  gnc_numeric     xaccAccountGetShareBalance (Account *account);
  gnc_numeric     xaccAccountGetShareClearedBalance (Account *account);
  gnc_numeric     xaccAccountGetShareReconciledBalance (Account *account);
diff -c 'gnucash-1.6.0/src/gnome/reconcile-list.c' 'gnucash-1.6.0-reconcile-children/src/gnome/reconcile-list.c'
Index: ./src/gnome/reconcile-list.c
*** ./src/gnome/reconcile-list.c	Sun Jun 10 00:43:31 2001
--- ./src/gnome/reconcile-list.c	Sun Jun 24 09:42:11 2001
***************
*** 113,118 ****
--- 113,123 ----
  
    /* match the account */
    xaccQueryAddSingleAccountMatch(list->query, account, QUERY_OR);
+   
+ #ifdef WITH_RECONCILE_CHILDREN
+   /* match child accounts */
+   xaccQueryAddSinglesChildrenAccountMatch( list->query, account, QUERY_OR );
+ #endif
  
    if (type == RECLIST_CREDIT)
      DxaccQueryAddAmountMatch(list->query, 0.0, AMT_SGN_MATCH_CREDIT,
diff -c 'gnucash-1.6.0/src/gnome/window-reconcile.c' 'gnucash-1.6.0-reconcile-children/src/gnome/window-reconcile.c'
Index: ./src/gnome/window-reconcile.c
*** ./src/gnome/window-reconcile.c	Fri Jun  1 23:46:02 2001
--- ./src/gnome/window-reconcile.c	Sun Jun 24 11:47:23 2001
***************
*** 207,213 ****
    }
    else
    {
!     starting = xaccAccountGetReconciledBalance(account);
      print_info = gnc_account_value_print_info (account, TRUE);
    }
  
--- 207,217 ----
    }
    else
    {
! #ifdef WITH_RECONCILE_CHILDREN
!     starting = xaccAccountGetReconciledBalance(account, TRUE);
! #else
!     starting = xaccAccountGetReconciledBalance(account, FALSE);
! #endif
      print_info = gnc_account_value_print_info (account, TRUE);
    }
  
***************
*** 397,403 ****
    }
    else
    {
!     ending = xaccAccountGetReconciledBalance(account);
      print_info = gnc_account_value_print_info (account, TRUE);
    }
  
--- 401,411 ----
    }
    else
    {
! #ifdef WITH_RECONCILE_CHILDREN
!     ending = xaccAccountGetReconciledBalance(account, TRUE);
! #else
!     ending = xaccAccountGetReconciledBalance(account, FALSE);
! #endif
      print_info = gnc_account_value_print_info (account, TRUE);
    }
  
diff -c 'gnucash-1.6.0/src/gnome/window-register.c' 'gnucash-1.6.0-reconcile-children/src/gnome/window-register.c'
Index: ./src/gnome/window-register.c
*** ./src/gnome/window-register.c	Sun Jun  3 01:24:33 2001
--- ./src/gnome/window-register.c	Sun Jun 24 11:44:38 2001
***************
*** 2331,2337 ****
  
    if (regData->reconciled_label != NULL)
    {
!     amount = xaccAccountGetReconciledBalance (leader);
      if (reverse)
        amount = gnc_numeric_neg (amount);
  
--- 2331,2341 ----
  
    if (regData->reconciled_label != NULL)
    {
! #ifdef WITH_RECONCILE_CHILDREN
!     amount = xaccAccountGetReconciledBalance (leader, TRUE);
! #else
!     amount = xaccAccountGetReconciledBalance (leader, FALSE);
! #endif
      if (reverse)
        amount = gnc_numeric_neg (amount);
  
diff -c 'gnucash-1.6.0/src/guile/gnc.gwp' 'gnucash-1.6.0-reconcile-children/src/guile/gnc.gwp'
Index: ./src/guile/gnc.gwp
*** ./src/guile/gnc.gwp	Sat Jun  2 22:15:34 2001
--- ./src/guile/gnc.gwp	Sun Jun 24 15:32:00 2001
***************
*** 1456,1462 ****
     'gnc:account-get-reconciled-balance
     '<gnc:numeric>
     "xaccAccountGetReconciledBalance"
!    '((<gnc:Account*> a))
     "Undocumented.")
  
    (gw:wrap-function
--- 1456,1462 ----
     'gnc:account-get-reconciled-balance
     '<gnc:numeric>
     "xaccAccountGetReconciledBalance"
!    '((<gnc:Account*> a) (<gnc:gboolean> include_children))
     "Undocumented.")
  
    (gw:wrap-function
#### End of Patch data ####

#### ApplyPatch data follows ####
# Data version        : 1.0
# Date generated      : Sun Jun 24 15:32:21 2001
# Generated by        : makepatch 2.00
# Recurse directories : Yes
# p 'config.h.in' 6164 993339651 0100644
# p 'configure.in' 17832 993337587 0100644
# p 'src/engine/Account.c' 61328 993392358 0100644
# p 'src/engine/Account.h' 17934 993379722 0100644
# p 'src/gnome/reconcile-list.c' 21263 993372131 0100644
# p 'src/gnome/window-reconcile.c' 61796 993379643 0100644
# p 'src/gnome/window-register.c' 93988 993379478 0100644
# p 'src/guile/gnc.gwp' 99252 993393120 0100644
#### End of ApplyPatch data ####

#### End of Patch kit [created: Sun Jun 24 15:32:21 2001] ####
#### Checksum: 272 8958 35853 ####

--2fHTh5uZTiUOsy+g--