mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Associate last check number with accounts. Use that in register
Num auto-fill. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3390 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -2769,6 +2769,26 @@ xaccSRSaveRegEntry (SplitRegister *reg, gboolean do_commit)
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static void
|
||||
sr_set_last_num (SplitRegister *reg, Transaction *trans, const char *num)
|
||||
{
|
||||
SRInfo *info = xaccSRGetInfo (reg);
|
||||
Split *blank_split = xaccSplitLookup(&info->blank_split_guid);
|
||||
Transaction *blank_trans = xaccSplitGetParent (blank_split);
|
||||
Account *account;
|
||||
|
||||
if (trans != blank_trans)
|
||||
return;
|
||||
|
||||
account = sr_get_default_account (reg);
|
||||
if (!account)
|
||||
return;
|
||||
|
||||
xaccAccountSetLastNum (account, reg->numCell->cell.value);
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static void
|
||||
xaccSRSaveChangedCells (SplitRegister *reg, Transaction *trans, Split *split)
|
||||
{
|
||||
@@ -2780,7 +2800,8 @@ xaccSRSaveChangedCells (SplitRegister *reg, Transaction *trans, Split *split)
|
||||
changed |= xaccSplitRegisterGetConditionalChangeFlag (reg);
|
||||
|
||||
/* copy the contents from the cursor to the split */
|
||||
if (MOD_DATE & changed) {
|
||||
if (MOD_DATE & changed)
|
||||
{
|
||||
Timespec ts;
|
||||
|
||||
/* commit any pending changes */
|
||||
@@ -2793,33 +2814,40 @@ xaccSRSaveChangedCells (SplitRegister *reg, Transaction *trans, Split *split)
|
||||
xaccTransSetDateTS (trans, &ts);
|
||||
}
|
||||
|
||||
if (MOD_NUM & changed) {
|
||||
if (MOD_NUM & changed)
|
||||
{
|
||||
DEBUG ("MOD_NUM: %s\n", reg->numCell->cell.value);
|
||||
xaccTransSetNum (trans, reg->numCell->cell.value);
|
||||
xaccSetNumCellLastNum(reg->numCell, reg->numCell->cell.value);
|
||||
if (xaccSetNumCellLastNum (reg->numCell, reg->numCell->cell.value))
|
||||
sr_set_last_num (reg, trans, reg->numCell->cell.value);
|
||||
}
|
||||
|
||||
if (MOD_DESC & changed) {
|
||||
if (MOD_DESC & changed)
|
||||
{
|
||||
DEBUG ("MOD_DESC: %s", reg->descCell->cell.value);
|
||||
xaccTransSetDescription (trans, reg->descCell->cell.value);
|
||||
}
|
||||
|
||||
if (MOD_NOTES & changed) {
|
||||
if (MOD_NOTES & changed)
|
||||
{
|
||||
DEBUG ("MOD_NOTES: %s", reg->notesCell->cell.value);
|
||||
xaccTransSetNotes (trans, reg->notesCell->cell.value);
|
||||
}
|
||||
|
||||
if (MOD_RECN & changed) {
|
||||
if (MOD_RECN & changed)
|
||||
{
|
||||
DEBUG ("MOD_RECN: %c", xaccRecnCellGetFlag(reg->recnCell));
|
||||
xaccSplitSetReconcile (split, xaccRecnCellGetFlag(reg->recnCell));
|
||||
}
|
||||
|
||||
if (MOD_ACTN & changed) {
|
||||
if (MOD_ACTN & changed)
|
||||
{
|
||||
DEBUG ("MOD_ACTN: %s", reg->actionCell->cell.value);
|
||||
xaccSplitSetAction (split, reg->actionCell->cell.value);
|
||||
}
|
||||
|
||||
if (MOD_MEMO & changed) {
|
||||
if (MOD_MEMO & changed)
|
||||
{
|
||||
DEBUG ("MOD_MEMO: %s", reg->memoCell->cell.value);
|
||||
xaccSplitSetMemo (split, reg->memoCell->cell.value);
|
||||
}
|
||||
@@ -4181,6 +4209,7 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist,
|
||||
gboolean start_primary_color = TRUE;
|
||||
gboolean found_pending = FALSE;
|
||||
gboolean found_divider = FALSE;
|
||||
gboolean has_last_num = FALSE;
|
||||
gboolean multi_line;
|
||||
gboolean dynamic;
|
||||
|
||||
@@ -4292,13 +4321,27 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist,
|
||||
present = mktime (tm);
|
||||
}
|
||||
|
||||
if (info->first_pass)
|
||||
{
|
||||
if (default_account)
|
||||
{
|
||||
const char *last_num = xaccAccountGetLastNum (default_account);
|
||||
|
||||
if (last_num)
|
||||
{
|
||||
xaccSetNumCellLastNum (reg->numCell, last_num);
|
||||
has_last_num = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
table->dividing_row = -1;
|
||||
|
||||
if (multi_line)
|
||||
trans_table = g_hash_table_new (g_direct_hash, g_direct_equal);
|
||||
|
||||
/* populate the table */
|
||||
for(gsplit=slist; gsplit; gsplit=gsplit->next)
|
||||
for (gsplit = slist; gsplit; gsplit = gsplit->next)
|
||||
{
|
||||
split = gsplit->data;
|
||||
trans = xaccSplitGetParent (split);
|
||||
@@ -4337,6 +4380,9 @@ xaccSRLoadRegister (SplitRegister *reg, GList * slist,
|
||||
xaccQuickFillAddCompletion (reg->notesCell,
|
||||
xaccTransGetNotes (trans));
|
||||
|
||||
if (!has_last_num)
|
||||
xaccSetNumCellLastNum (reg->numCell, xaccTransGetNum (trans));
|
||||
|
||||
for (node = xaccTransGetSplitList (trans); node; node = node->next)
|
||||
{
|
||||
Split *s = node->data;
|
||||
@@ -4568,7 +4614,7 @@ xaccSRHasPendingChanges (SplitRegister *reg)
|
||||
SRInfo *info = xaccSRGetInfo(reg);
|
||||
Transaction *pending_trans = xaccTransLookup(&info->pending_trans_guid);
|
||||
guint32 changed;
|
||||
|
||||
|
||||
if (reg == NULL)
|
||||
return FALSE;
|
||||
|
||||
|
||||
@@ -1708,6 +1708,48 @@ xaccAccountClearReconcilePostpone (Account *account)
|
||||
xaccAccountCommitEdit (account);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
const char *
|
||||
xaccAccountGetLastNum (Account *account)
|
||||
{
|
||||
kvp_value *value;
|
||||
|
||||
if (!account)
|
||||
return FALSE;
|
||||
|
||||
value = kvp_frame_get_slot (xaccAccountGetSlots (account), "last-num");
|
||||
if (!value)
|
||||
return FALSE;
|
||||
|
||||
return kvp_value_get_string (value);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
void
|
||||
xaccAccountSetLastNum (Account *account, const char *num)
|
||||
{
|
||||
if (!account)
|
||||
return;
|
||||
|
||||
xaccAccountBeginEdit (account);
|
||||
{
|
||||
kvp_value *value;
|
||||
|
||||
check_open (account);
|
||||
|
||||
value = kvp_value_new_string (num);
|
||||
|
||||
kvp_frame_set_slot (xaccAccountGetSlots (account), "last-num", value);
|
||||
|
||||
kvp_value_delete (value);
|
||||
|
||||
mark_account (account);
|
||||
}
|
||||
xaccAccountCommitEdit (account);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
void
|
||||
|
||||
@@ -295,6 +295,9 @@ void xaccAccountSetReconcilePostponeBalance (Account *account,
|
||||
|
||||
void xaccAccountClearReconcilePostpone (Account *account);
|
||||
|
||||
/* Get and set the last num field of an Account */
|
||||
const char * xaccAccountGetLastNum (Account *account);
|
||||
void xaccAccountSetLastNum (Account *account, const char *num);
|
||||
|
||||
/* The xaccAccountSetPriceSrc() and xaccAccountGetPriceSrc() routines
|
||||
are used to get and set a string that identifies the current source
|
||||
|
||||
@@ -36,10 +36,12 @@ Please put the keys in alphabetical order.
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
Name: split-type
|
||||
Entities: Split
|
||||
Use: xaccSplitGetType, xaccSplitMakeStockSplit
|
||||
Store a string representing the type of split, if not normal.
|
||||
Name: last-num
|
||||
Type: string
|
||||
Entities: Account
|
||||
Use: xaccAccountGetLastNum, xaccAccountSetLastNum
|
||||
Store the last number used in an account's transactions.
|
||||
Used in auto-filling the Num field.
|
||||
|
||||
Name: memo
|
||||
Type: string
|
||||
@@ -91,6 +93,11 @@ Type: numeric
|
||||
Entities: Account
|
||||
Use: store the ending balance of a postponed reconciliation
|
||||
|
||||
Name: split-type
|
||||
Entities: Split
|
||||
Use: xaccSplitGetType, xaccSplitMakeStockSplit
|
||||
Store a string representing the type of split, if not normal.
|
||||
|
||||
Name: tax-related
|
||||
Type: gint64
|
||||
Entities: Account
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
/* static short module = MOD_REGISTER; */
|
||||
|
||||
static void xaccInitNumCell (NumCell *cell);
|
||||
|
||||
|
||||
/* ================================================ */
|
||||
/* Parses the string value and returns true if it is a
|
||||
@@ -197,24 +199,33 @@ setNumCellValue (BasicCell *_cell, const char *str)
|
||||
void
|
||||
xaccSetNumCellValue (NumCell *cell, const char *str)
|
||||
{
|
||||
if (!cell)
|
||||
return;
|
||||
|
||||
setNumCellValue (&cell->cell, str);
|
||||
}
|
||||
|
||||
/* ================================================ */
|
||||
void
|
||||
gboolean
|
||||
xaccSetNumCellLastNum (NumCell *cell, const char *str)
|
||||
{
|
||||
long int number;
|
||||
|
||||
if (!cell)
|
||||
return FALSE;
|
||||
|
||||
if (parse_num (str, &number))
|
||||
{
|
||||
cell->next_num = number + 1;
|
||||
cell->next_num_set = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* ================================================ */
|
||||
void
|
||||
static void
|
||||
xaccInitNumCell (NumCell *cell)
|
||||
{
|
||||
xaccInitBasicCell (&(cell->cell));
|
||||
|
||||
@@ -45,10 +45,9 @@ typedef struct _NumCell
|
||||
} NumCell;
|
||||
|
||||
NumCell * xaccMallocNumCell (void);
|
||||
void xaccInitNumCell (NumCell *);
|
||||
void xaccDestroyNumCell (NumCell *);
|
||||
void xaccDestroyNumCell (NumCell *cell);
|
||||
|
||||
void xaccSetNumCellValue (NumCell *cell, const char *str);
|
||||
void xaccSetNumCellLastNum (NumCell *cell, const char *str);
|
||||
gboolean xaccSetNumCellLastNum (NumCell *cell, const char *str);
|
||||
|
||||
#endif /* __NUM_CELL_H__ */
|
||||
|
||||
Reference in New Issue
Block a user