Add account api for setting/getting reconcile info.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3380 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-01-03 12:53:59 +00:00
parent 1ed54b681d
commit db755ed7a7
7 changed files with 427 additions and 32 deletions

View File

@ -1529,7 +1529,297 @@ xaccAccountTypesCompatible (int parent_type, int child_type)
/********************************************************************\ /********************************************************************\
\********************************************************************/ \********************************************************************/
static kvp_frame *
xaccAccountGetReconcileInfo (Account *account)
{
kvp_value *value;
if (!account)
return NULL;
value = kvp_frame_get_slot (xaccAccountGetSlots (account), "reconcile-info");
if (!value)
return NULL;
return kvp_value_get_frame (value);
}
/********************************************************************\
\********************************************************************/
static void
xaccAccountMakeReconcileInfo (Account *account)
{
kvp_frame *slots;
if (!account)
return;
if (xaccAccountGetReconcileInfo (account))
return;
slots = xaccAccountGetSlots (account);
if (!slots)
return;
xaccAccountBeginEdit (account);
{
kvp_frame *frame;
kvp_value *value;
check_open (account);
frame = kvp_frame_new ();
value = kvp_value_new_frame (frame);
kvp_frame_set_slot (slots, "reconcile-info", value);
kvp_value_delete (value);
kvp_frame_delete (frame);
mark_account (account);
}
xaccAccountCommitEdit (account);
}
/********************************************************************\
\********************************************************************/
gboolean
xaccAccountGetReconcileLastDate (Account *account, time_t *last_date)
{
kvp_frame *recn_info;
kvp_value *value;
if (!account)
return FALSE;
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
return FALSE;
value = kvp_frame_get_slot (recn_info, "last-date");
if (!value)
return FALSE;
if (kvp_value_get_type (value) == KVP_TYPE_GINT64)
{
if (last_date)
*last_date = kvp_value_get_gint64 (value);
return TRUE;
}
return FALSE;
}
/********************************************************************\
\********************************************************************/
void
xaccAccountSetReconcileLastDate (Account *account, time_t last_date)
{
kvp_frame *recn_info;
if (!account)
return;
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
{
xaccAccountMakeReconcileInfo (account);
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
{
PERR ("Couldn't make reconcile info");
return;
}
}
xaccAccountBeginEdit (account);
{
kvp_value *value;
check_open (account);
value = kvp_value_new_gint64 (last_date);
kvp_frame_set_slot (recn_info, "last-date", value);
kvp_value_delete (value);
mark_account (account);
}
xaccAccountCommitEdit (account);
}
/********************************************************************\
\********************************************************************/
gboolean
xaccAccountGetReconcilePostponeDate (Account *account,
time_t *postpone_date)
{
kvp_frame *recn_info;
kvp_value *value;
if (!account)
return FALSE;
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
return FALSE;
value = kvp_frame_get_slot (recn_info, "postpone-date");
if (!value)
return FALSE;
if (kvp_value_get_type (value) == KVP_TYPE_GINT64)
{
if (postpone_date)
*postpone_date = kvp_value_get_gint64 (value);
return TRUE;
}
return FALSE;
}
/********************************************************************\
\********************************************************************/
void
xaccAccountSetReconcilePostponeDate (Account *account,
time_t postpone_date)
{
kvp_frame *recn_info;
if (!account)
return;
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
{
xaccAccountMakeReconcileInfo (account);
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
{
PERR ("Couldn't make reconcile info");
return;
}
}
xaccAccountBeginEdit (account);
{
kvp_value *value;
check_open (account);
value = kvp_value_new_gint64 (postpone_date);
kvp_frame_set_slot (recn_info, "postpone-date", value);
kvp_value_delete (value);
mark_account (account);
}
xaccAccountCommitEdit (account);
}
/********************************************************************\
\********************************************************************/
gboolean
xaccAccountGetReconcilePostponeBalance (Account *account,
gnc_numeric *balance)
{
kvp_frame *recn_info;
kvp_value *value;
if (!account)
return FALSE;
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
return FALSE;
value = kvp_frame_get_slot (recn_info, "postpone-balance");
if (!value)
return FALSE;
if (kvp_value_get_type (value) == KVP_TYPE_GINT64)
{
if (balance)
*balance = kvp_value_get_numeric (value);
return TRUE;
}
return FALSE;
}
/********************************************************************\
\********************************************************************/
void
xaccAccountSetReconcilePostponeBalance (Account *account,
gnc_numeric balance)
{
kvp_frame *recn_info;
if (!account)
return;
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
{
xaccAccountMakeReconcileInfo (account);
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
{
PERR ("Couldn't make reconcile info");
return;
}
}
xaccAccountBeginEdit (account);
{
kvp_value *value;
check_open (account);
value = kvp_value_new_numeric (balance);
kvp_frame_set_slot (recn_info, "postpone-balance", value);
kvp_value_delete (value);
mark_account (account);
}
xaccAccountCommitEdit (account);
}
/********************************************************************\
\********************************************************************/
void
xaccAccountClearReconcilePostpone (Account *account)
{
kvp_frame *recn_info;
if (!account)
return;
recn_info = xaccAccountGetReconcileInfo (account);
if (!recn_info)
return;
xaccAccountBeginEdit (account);
{
check_open (account);
kvp_frame_set_slot (recn_info, "postpone-date", NULL);
kvp_frame_set_slot (recn_info, "postpone-balance", NULL);
mark_account (account);
}
xaccAccountCommitEdit (account);
}
/********************************************************************\
\********************************************************************/
void void
xaccAccountSetPriceSrc(Account *acc, const char *src) { xaccAccountSetPriceSrc(Account *acc, const char *src) {

View File

@ -277,6 +277,25 @@ void xaccClearMark (Account *account, short val);
void xaccClearMarkDown (Account *account, short val); void xaccClearMarkDown (Account *account, short val);
void xaccClearMarkDownGr (AccountGroup *group, short val); void xaccClearMarkDownGr (AccountGroup *group, short val);
/* The following functions get and set reconciliation information */
gboolean xaccAccountGetReconcileLastDate (Account *account,
time_t *last_date);
void xaccAccountSetReconcileLastDate (Account *account,
time_t last_date);
gboolean xaccAccountGetReconcilePostponeDate (Account *account,
time_t *postpone_date);
void xaccAccountSetReconcilePostponeDate (Account *account,
time_t postpone_date);
gboolean xaccAccountGetReconcilePostponeBalance (Account *account,
gnc_numeric *balance);
void xaccAccountSetReconcilePostponeBalance (Account *account,
gnc_numeric balance);
void xaccAccountClearReconcilePostpone (Account *account);
/* The xaccAccountSetPriceSrc() and xaccAccountGetPriceSrc() routines /* The xaccAccountSetPriceSrc() and xaccAccountGetPriceSrc() routines
are used to get and set a string that identifies the current source are used to get and set a string that identifies the current source
for investment pricing info. Currently supported values include for investment pricing info. Currently supported values include

View File

@ -66,6 +66,26 @@ Use: This string holds the old Price Source code used by earlier versions
is fully supported. The new version of Finance::Quote uses a different is fully supported. The new version of Finance::Quote uses a different
scheme to identify sources for price quotes. scheme to identify sources for price quotes.
Name: reconcile-info
Type: frame
Entities: Account
Use: store reconcile information about accounts
Name: reconcile-info/last-date
Type: frame
Entities: Account
Use: store the statement date of the last reconciliation
Name: reconcile-info/postpone-date
Type: gint64
Entities: Account
Use: store the ending statement date of a postponed reconciliation
Name: reconcile-info/postpone-balance
Type: numeric
Entities: Account
Use: store the ending balance of a postponed reconciliation
Name: tax-related Name: tax-related
Type: gint64 Type: gint64
Entities: Account Entities: Account

View File

@ -146,6 +146,7 @@ gnc_reconcile_list_init(GNCReconcileList *list)
list->current_split = NULL; list->current_split = NULL;
list->no_toggle = FALSE; list->no_toggle = FALSE;
list->always_unselect = FALSE; list->always_unselect = FALSE;
list->first_fill = TRUE;
list->query = NULL; list->query = NULL;
while (titles[list->num_columns] != NULL) while (titles[list->num_columns] != NULL)
@ -268,7 +269,6 @@ gnc_reconcile_list_toggle(GNCReconcileList *list)
Split *split, *current; Split *split, *current;
gboolean reconciled; gboolean reconciled;
const char *recn_str; const char *recn_str;
char recn;
gint row; gint row;
g_assert(IS_GNC_RECONCILE_LIST(list)); g_assert(IS_GNC_RECONCILE_LIST(list));
@ -294,9 +294,8 @@ gnc_reconcile_list_toggle(GNCReconcileList *list)
g_hash_table_remove(list->reconciled, split); g_hash_table_remove(list->reconciled, split);
} }
recn = xaccSplitGetReconcile(split); recn_str = reconciled ? gnc_get_reconcile_str (YREC) : "";
recn = reconciled ? YREC : recn;
recn_str = gnc_get_reconcile_str(recn);
gtk_clist_set_text(GTK_CLIST(list), row, 4, recn_str); gtk_clist_set_text(GTK_CLIST(list), row, 4, recn_str);
gnc_reconcile_list_set_row_style(list, row, reconciled); gnc_reconcile_list_set_row_style(list, row, reconciled);
@ -547,14 +546,50 @@ gnc_reconcile_list_commit(GNCReconcileList *list, time_t date)
for (i = 0; i < list->num_splits; i++) for (i = 0; i < list->num_splits; i++)
{ {
char recn;
split = gtk_clist_get_row_data (clist, i); split = gtk_clist_get_row_data (clist, i);
if (g_hash_table_lookup(list->reconciled, split) != NULL) recn = g_hash_table_lookup (list->reconciled, split) ? YREC : NREC;
{
xaccSplitSetReconcile(split, YREC); xaccSplitSetReconcile (split, recn);
if (recn == YREC)
xaccSplitSetDateReconciledSecs (split, date); xaccSplitSetDateReconciledSecs (split, date);
} }
} }
/********************************************************************\
* gnc_reconcile_list_commit *
* postpone the reconcile information in the list by setting *
* reconciled splits to cleared status *
* *
* Args: list - list to commit *
* Returns: nothing *
\********************************************************************/
void
gnc_reconcile_list_postpone (GNCReconcileList *list)
{
GtkCList *clist = GTK_CLIST(list);
Split *split;
int i;
g_return_if_fail(list != NULL);
g_return_if_fail(IS_GNC_RECONCILE_LIST(list));
if (list->reconciled == NULL)
return;
for (i = 0; i < list->num_splits; i++)
{
char recn;
split = gtk_clist_get_row_data (clist, i);
recn = g_hash_table_lookup (list->reconciled, split) ? CREC : NREC;
xaccSplitSetReconcile (split, recn);
}
} }
@ -678,12 +713,11 @@ gnc_reconcile_list_fill(GNCReconcileList *list)
strings[2] = xaccTransGetDescription(trans); strings[2] = xaccTransGetDescription(trans);
strings[3] = xaccPrintAmount(gnc_numeric_abs (amount), print_info); strings[3] = xaccPrintAmount(gnc_numeric_abs (amount), print_info);
if (list->first_fill && recn == CREC)
g_hash_table_insert (list->reconciled, split, split);
reconciled = g_hash_table_lookup(list->reconciled, split) != NULL; reconciled = g_hash_table_lookup(list->reconciled, split) != NULL;
recn = reconciled ? YREC : recn; strings[4] = reconciled ? gnc_get_reconcile_str (YREC) : "";
if (recn == NREC)
strings[4] = "";
else
strings[4] = gnc_get_reconcile_str(recn);
row = gtk_clist_append(GTK_CLIST(list), (gchar **) strings); row = gtk_clist_append(GTK_CLIST(list), (gchar **) strings);
gtk_clist_set_row_data(GTK_CLIST(list), row, split); gtk_clist_set_row_data(GTK_CLIST(list), row, split);
@ -692,4 +726,6 @@ gnc_reconcile_list_fill(GNCReconcileList *list)
list->num_splits++; list->num_splits++;
} }
list->first_fill = FALSE;
} }

View File

@ -61,6 +61,7 @@ struct _GNCReconcileList
gboolean no_toggle; gboolean no_toggle;
gboolean always_unselect; gboolean always_unselect;
gboolean first_fill;
GHashTable *reconciled; GHashTable *reconciled;
@ -102,6 +103,8 @@ gnc_numeric gnc_reconcile_list_reconciled_balance(GNCReconcileList *list);
void gnc_reconcile_list_commit (GNCReconcileList *list, time_t date); void gnc_reconcile_list_commit (GNCReconcileList *list, time_t date);
void gnc_reconcile_list_postpone (GNCReconcileList *list);
void gnc_reconcile_list_unselect_all(GNCReconcileList *list); void gnc_reconcile_list_unselect_all(GNCReconcileList *list);
gboolean gnc_reconcile_list_changed(GNCReconcileList *list); gboolean gnc_reconcile_list_changed(GNCReconcileList *list);

View File

@ -32,6 +32,7 @@
#include <gnome.h> #include <gnome.h>
#include <stdio.h> #include <stdio.h>
#include <time.h>
#include "AccWindow.h" #include "AccWindow.h"
#include "MainWindow.h" #include "MainWindow.h"
@ -1273,6 +1274,28 @@ gnc_recn_create_tool_bar(RecnWindow *recnData)
return toolbar; return toolbar;
} }
static void
gnc_get_reconcile_info (Account *account,
gnc_numeric *new_ending,
time_t *statement_date)
{
if (xaccAccountGetReconcileLastDate (account, statement_date))
{
struct tm *tm;
tm = localtime (statement_date);
tm->tm_mon++;
tm->tm_isdst = -1;
*statement_date = mktime (tm);
}
xaccAccountGetReconcilePostponeDate (account, statement_date);
xaccAccountGetReconcilePostponeBalance (account, new_ending);
}
static gboolean static gboolean
find_by_account (gpointer find_data, gpointer user_data) find_by_account (gpointer find_data, gpointer user_data)
{ {
@ -1373,15 +1396,16 @@ recnWindow (GtkWidget *parent, Account *account)
/* The last time reconciliation was attempted during the current /* The last time reconciliation was attempted during the current
* execution of gnucash, the date was stored. Use that date if * execution of gnucash, the date was stored. Use that date if
* possible. This helps with balancing multiple accounts for * possible. This helps with balancing multiple accounts for which
* which statements are issued at the same time, like multiple * statements are issued at the same time, like multiple bank
* bank accounts on a single statement. * accounts on a single statement. */
*/
if (!last_statement_date) if (!last_statement_date)
statement_date = time (NULL); statement_date = time (NULL);
else else
statement_date = last_statement_date; statement_date = last_statement_date;
gnc_get_reconcile_info (account, &new_ending, &statement_date);
/* Popup a little window to prompt the user to enter the /* Popup a little window to prompt the user to enter the
* ending balance for his/her bank statement */ * ending balance for his/her bank statement */
if (!startRecnWindow (parent, account, &new_ending, &statement_date)) if (!startRecnWindow (parent, account, &new_ending, &statement_date))
@ -1750,6 +1774,9 @@ recnFinishCB (GtkWidget *w, gpointer data)
account = recn_get_account (recnData); account = recn_get_account (recnData);
xaccAccountClearReconcilePostpone (account);
xaccAccountSetReconcileLastDate (account, date);
if (auto_payment && if (auto_payment &&
(xaccAccountGetType (account) == CREDIT) && (xaccAccountGetType (account) == CREDIT) &&
(gnc_numeric_negative_p (recnData->new_ending))) (gnc_numeric_negative_p (recnData->new_ending)))