Skip to content

Commit

Permalink
Implement a Book Option to give users the choice to use the transacti…
Browse files Browse the repository at this point in the history
…on number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.

The changes made are:

1.  Implement the new book option to select source for 'num' cell:
     libqof/qof/qofbookslots.h - define num source option
     engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
         'SPLIT-ACTION' as a term for sorting queries
     app-utils/business-prefs.scm - define book option for num-field-source
     app-utils/app-utils.scm - define and export book option for num-field-source

2.  Implement functions to get book option setting and to test:
     libqof/qof/qofbook.c & .h - define function to get number source book option
     libqof/qof/test/test-qofbook.c - test function to get number source book option

3.  Implement a notification mechanism for book option changes:
     engine/engine-helpers.c & .h - define functions to register callbacks,
         define function to remove callbacks and
         define function to initiate callbacks on book num-source option changes
     core-utils/gnc-features.c & .h - define feature for num-source
     app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
         include setting of feature flag on initial use
     gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
         function to gnc_book_options_dialog_apply_cb and adjust function to 
         call function gnc_book_option_num_field_source_change_cb when book
         option for num-field-source changes; change name of
         gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb

4.  Implement 'help' button response on Book Option Dialog:
     gnome-utils/gnc-ui.h - define "book-options" section of help manual
     gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
     gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
         to make help button active

5.  Implement utility functions to get/set number/action based on book option:
     engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
         define 'gnc_get_action_num' function
         define 'gnc_set_num_action' function
     engine/engine.i - make get/set num/action functions available to guile &
         allow #f to be used in place of NULL from guile
     engine/Transaction.h - add reference to utility functions in comments to 
         xaccTransSetNum and xaccTransGetNum functions
     engine/Split.h -  add reference to utility functions in comments to 
         xaccSplitSetAction and xaccSplitGetAction functions

6.  Implement register use of num source book option; for General, Income and Search
    Ledgers, since there is no anchor split, always show tran-num in transaction
    cursor, but vary label to correspond to book option:
     register/ledger-core/split-register.h - define TNUM_CELL
         define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
         define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
         add boolean to split_reg structure to hold num source book option
     register/ledger-core/split-register-layout.c -
         add logic to define and set up new ledger/journal cursors with TNUM_CELLs
         add logic to add the new cursors to a layout
         add logic to add TNUM_CELL to a layout
     register/ledger-core/split-register-model.c -
         define function to get TNUM_CELL label
         add logic to recognize ledger/journal cursors with TNUM_CELL
         modify function to get NUM_CELL value based on book option and register
             type
         define function to get TNUM_CELL value
         adjust num help text to reflect book option choice
         define function to get TNUM_CELL help
         modify function to get action help to reflect book option choice
         set up handlers for TNUM_CELL
     register/ledger-core/split-register-model-save.c -
         use 'gnc_set_num_action' function to set num/action for NUM_CELL based
             on book option
         define function to save TNUM_CELL using 'gnc_set_num_action' function
         set save handler for TNUM_CELL
     register/ledger-core/split-register-util.c - 
         modify logic to recognize ledger/journal cursors with tnum_cell
     register/ledger-core/split-register.c -
         define split_register_book_option_changed function
         register split_register_book_option_changed function in register init
         initialize register structure setting to book option
         remove split_register_book_option_changed function in register destroy
         modify gnc_split_register_save_to_scm to handle TNUM_CELL

7.  Enhance transaction copy/duplicate logic to accommodate new book option:
     gnome/gtkbuilder/gnc-plugin-page-register.glade -
         add widgets to handle trans number and/or split action based on book option
     gnome-utils/dialog-dup-trans.c & .h -
         add capability to display and handle 'Num' field according to book option
     gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
     register/ledger-core/split-register.c -
         modify gnc_split_register_duplicate_current to accomodate book option
         setting
     register/ledger-core/Makefile.am - add GNOME_CFLAGS
     register/ledger-core/test/Makefile.am - add libgnc-gnome.la

8.  Adjust register sort and sort labels related to Num/Action radio buttons to
    correspond to book option for clarity:
     gnome/gnc-plugin-page-register.c -
         define gnc_plugin_page_register_sort_book_option_changed to adjust labels
         register function in gnc_plugin_page_register_cmd_view_sort_by
             and save num and action radio widgets
         initialize radio widget labels to correspond to book option
         remove function in gnc_plugin_page_register_sort_response_cb
             and clear num and action radio widgets
     gnome/gnc-split-reg.c & h. - 
         create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
             a re-sort to be used when num-source book option changes
     engine/Transaction.c & .h -
         modify default sort to use split action in place of tran num per book
             option if called from xaccSplitOrder
     engine/Split.c - 
         modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
             split action and tran num per book option
     engine/test/utest-Split.c -
         modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
             book option

9.  Adjust transaction find labels related to Num/Action to correspond to book option
    for clarity:
     gnome/dialog-find-transactions.c - adjust labels in search criteria based
         on book option
     gnome-search/dialog-search.c -
         define gnc_search_dialog_book_option_changed to adjust labels
         register function in gnc_search_dialog_init_widgets when searching
             for splits
         remove function in gnc_search_dialog_close_cb if registered

10. Modify new file process to allow setting of num-source (actually, all) book
    option(s) during New Account Hierarchy Setup:
     gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
         the default setting for 'num-source' for new books
     core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
     gnome-utils/gnc-gnome-utils.c & h. -
         define gnc_options_dialog_set_new_book_option_values to retrieve
         preference values
     gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
         surpress apply button
     gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
         with arguments so that the window can be called in modal mode and the
         title changed and return dialog widget; call gnc_options_dialog_new_modal
         instead of gnc_options_dialog_new; call this function from
         gnc_main_window_cmd_file_properties with new arguments; for modal mode,
         call gnc-options-dialog-set-new-book-option-values to initialize values
         from preferences
     app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
         determining when a new book is being created
     gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
         display book options dialog in modal mode
     gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
         options to currency page
     gnome/assistant-hierarchy.c - add ability to set book option initialized
         from preferences value for new books by using functions gnc_is_new_book
         and gnc_new_book_option_display

11. Modify Import QIF process to recognize a new-book situation and allow setting
    of book options during first import into a new book; also follow book option
    setting for num source in importing number whether new book or not:
     import-export/qif-import/assistant-qif-import.glade - add notification about
         book options to currency page
     import-export/qif-import/assistant-qif-import.c - using function
         gnc_is_new_book to identify 'new book' situation and set flag; add
         logic to handle 'new-book' situation by calling
         gnc_new_book_option_display function
     import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
         to import number to correct field based on book option

12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
    of book options during first import into a new book; also follow book option
    setting for num source in importing number whether new book or not:
     import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
         number based on book option; identify 'new book' situation using function
         gnc_is_new_book and set flag; add logic to handle 'new-book' situation
         by raising book options dialog by calling gnc_new_book_option_display
         function
     import-export/import-backend.c - use 'gnc_get_num_action' function to 
         retrieve number from transactions to be matched based on book option

13. Modify Import AqBanking process to recognize a new-book situation and allow
    setting of book options during first import into a new book; also follow
    book option setting for num source in importing number:
     import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
         situation using function gnc_is_new_book and handle by raising book
         options dialog by calling gnc_new_book_option_display function
     import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
         to set number based on book option

14. Modify Import Transactions from CSV process to recognize a new-book situation
    and allow setting of book options during first import into a new book; also
    follow book option setting for num source in importing number whether new
    book or not:
     import-export/csv-import/assistant-csv-trans-import.glade - modify
         commments to alert user of raising book options dialog in cases of csv
         import into a new book
     import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
         function to import number based on book option
     import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
         'new-book' situation by raising book options dialog by calling
         gnc_new_book_option_display function; identify 'new book' situation
         using function gnc_is_new_book and set flag

15. Modify Import Accounts from CSV process to recognize a new-book situation
    and allow setting of book options during first import into a new book
     import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
         handle 'new-book' situation by raising book options dialog by calling
         gnc_new_book_option_display function; identify 'new book' situation
         using function gnc_is_new_book and set flag

16. Modify Export Transactions to CSV process to follow book option setting
    for num source in exporting transactions:
     import-export/csv-export/csv-transactions-export.c - modify headings to
         reflect num-source book option and use 'gnc_get_num_action' function
         to retrieve number and action

17. Modify register reporting to reflect book option setting for num source:
     gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
         argument to gnc:register-report-create function
     gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
         argument to gnc:register-report-create function
     report/standard-reports/standard-reports.scm - add ledger-type? argument
         to gnc:register-report-create function; pass it along to
         gnc:register-report-create-internal function
     report/standard-reports/register.scm - add ledger-type? argument to
         gnc:register-report-create-internal function; use 'gnc-get-num-action'
         function in place of xaccTransGetNum and 'gnc-get-action-num' function
         in place of xaccSplitGetAction and modify report headings and option
         text accordingly

18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
    'gnc_set_num_action' function to set number based on book option except
    engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
    engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
    engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
    backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
     engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
         on book option
     engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
         on book option
     engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
         action
     engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
     gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
         number based on book option
     gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
         to set number/action based on book option
     gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
         split-action

19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
    'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
    on book option except engine/Transaction.c & .h,
    engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
    engine/test/utest-Split.c, engine/engine-helpers.c,
    engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
    backend/xml/test/test-xml-transaction.c:
     gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
         number based on book option
     gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
         retrieve number and action
     gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
         retrieve number and 'gnc_get_action_num' function to retrieve action
     register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
         function to retrieve number based on book option
     register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
         function to retrieve number based on book option
     register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
         function to retrieve action
     register/ledger-core/split-register.c - use 'gnc_get_num_action'
         function to retrieve transaction-num 
     engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
     gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
         to retrieve number and 'gnc_get_action_num' function to retrieve action
     gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
         to retrieve transaction-number but may not be getting what is expected
         if book option to use split-action for 'num' is set
     report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
         place of xaccTransGetNum and 'gnc-get-action-num' function in place of 
         xaccSplitGetAction and modify report headings and option text accordingly
     report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
         in place of xaccTransGetNum, adjust sorting based on book option and
         modify report headings and option text accordingly; add 'SPLIT-ACTION'
         as a term for sorting queries
     report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
         function in place of xaccTransGetNum
     report/business-reports/owner-report.scm - use 'gnc-get-num-action'
         function in place of xaccTransGetNum
     report/business-reports/job-report.scm - use 'gnc-get-num-action' function
         in place of xaccTransGetNum
     business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
         function to retrieve number based on book option


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
J. Alex Aycinena committed Dec 22, 2012
1 parent 5ff9e09 commit 7cdd737
Show file tree
Hide file tree
Showing 84 changed files with 2,152 additions and 323 deletions.
4 changes: 3 additions & 1 deletion src/app-utils/app-utils.scm
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@
(define gnc:*option-section-accounts* OPTION-SECTION-ACCOUNTS)
(define gnc:*option-name-trading-accounts* OPTION-NAME-TRADING-ACCOUNTS)
(define gnc:*option-name-auto-readonly-days* OPTION-NAME-AUTO-READONLY-DAYS)
(define gnc:*option-name-num-field-source* OPTION-NAME-NUM-FIELD-SOURCE)

(export gnc:*option-section-accounts* gnc:*option-name-trading-accounts* gnc:*option-name-auto-readonly-days*)
(export gnc:*option-section-accounts* gnc:*option-name-trading-accounts*
gnc:*option-name-auto-readonly-days* gnc:*option-name-num-field-source*)

(define gnc:*option-section-budgeting* OPTION-SECTION-BUDGETING)
(define gnc:*option-name-default-budget* OPTION-NAME-DEFAULT-BUDGET)
Expand Down
6 changes: 6 additions & 0 deletions src/app-utils/business-prefs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
1 ;; step size
))

(reg-option
(gnc:make-simple-boolean-option
gnc:*option-section-accounts* gnc:*option-name-num-field-source*
"c" (N_ "Check to have split action field used in registers for 'Num' field in place of transaction number; transaction number shown as 'T-Num' on second line of register. Has corresponding effect on business features, reporting and imports/exports.")
#f))

;; Budgeting Tab

(reg-option
Expand Down
42 changes: 42 additions & 0 deletions src/app-utils/gnc-ui-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
#include "app-utils/gnc-euro.h"
#include "engine/gnc-hooks.h"
#include "engine/gnc-session.h"
#include "engine-helpers.h"
#include "gnc-locale-utils.h"
#include "gnc-component-manager.h"
#include "gnc-features.h"

#define KEY_CURRENCY_CHOICE "currency_choice"
#define KEY_CURRENCY_OTHER "currency_other"
Expand Down Expand Up @@ -193,6 +196,25 @@ gnc_get_current_book (void)
return qof_session_get_book (gnc_get_current_session ());
}

/* If there is no current session, there is no book and we must be dealing
* with a new book. When gnucash is started with --nofile, there is
* initially no session (and no book), but by the time we check, one
* could have been created (for example, if an empty account tree tab is
* opened, a session is created which creates a new, but empty, book).
* A session is created and a book is loaded from a backend when gnucash is
* started with a file, but selecting 'new file' keeps a session open. So we
* need to check as well for a book with no accounts (root with no children). */
gboolean
gnc_is_new_book (void)
{
return ((!gnc_current_session_exist() ||
(gnc_current_session_exist() &&
!gnc_account_get_children(
gnc_book_get_root_account(
gnc_get_current_book()))))
? TRUE : FALSE);
}

#define OPTION_TAXUS_NAME "book/tax_US/name"
#define OPTION_TAXUS_TYPE "book/tax_US/type"

Expand Down Expand Up @@ -220,6 +242,26 @@ gnc_get_current_book_tax_type (void)
return qof_book_get_string_option(gnc_get_current_book(), OPTION_TAXUS_TYPE);
}

/** Calls gnc_book_option_num_field_source_change to initiate registered
* callbacks when num_field_source book option changes so that
* registers/reports can update themselves; sets feature flag */
void
gnc_book_option_num_field_source_change_cb (gboolean num_action)
{
gnc_suspend_gui_refresh ();
if (num_action)
{
/* Set a feature flag in the book for use of the split action field as number.
* This will prevent older GnuCash versions that don't support this feature
* from opening this file. */
gnc_features_set_used (gnc_get_current_book(),
GNC_FEATURE_NUM_FIELD_SOURCE);
}
gnc_book_option_num_field_source_change (num_action);
gnc_resume_gui_refresh ();
gnc_gui_refresh_all ();
}

Account *
gnc_get_current_root_account (void)
{
Expand Down
15 changes: 15 additions & 0 deletions src/app-utils/gnc-ui-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,25 @@ void gnc_set_default_directory (const gchar *gconf_section,

/* Engine enhancements & i18n ***************************************/
QofBook * gnc_get_current_book (void);

/* If there is no current session, there is no book and we must be dealing
* with a new book. When gnucash is started with --nofile, there is
* initially no session (and no book), but by the time we check, one
* could have been created (for example, if an empty account tree tab is
* opened, a session is created which creates a new, but empty, book).
* A session is created and a book is loaded from a backend when gnucash is
* started with a file, but selecting 'new file' keeps a session open. So we
* need to check as well for a book with no accounts (root with no children). */
gboolean gnc_is_new_book (void);

void gnc_set_current_book_tax_name (const gchar *tax_name);
const gchar * gnc_get_current_book_tax_name (void);
void gnc_set_current_book_tax_type (const gchar *tax_type);
const gchar * gnc_get_current_book_tax_type (void);
/** Calls gnc_book_option_num_field_source_change to initiate registered
* callbacks when num_field_source book option changes so that
* registers/reports can update themselves; sets feature flag */
void gnc_book_option_num_field_source_change_cb (gboolean num_action);
Account * gnc_get_current_root_account (void);
gnc_commodity_table * gnc_get_current_commodities (void);

Expand Down
3 changes: 2 additions & 1 deletion src/business/business-gnome/dialog-payment.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "Transaction.h"
#include "Account.h"
#include "gncOwner.h"
#include "engine-helpers.h"

#include "gncInvoice.h"

Expand Down Expand Up @@ -1120,7 +1121,7 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn)

// Fill in the values from the given txn
pw->pre_existing_txn = txn;
gnc_ui_payment_window_set_num(pw, xaccTransGetNum(txn));
gnc_ui_payment_window_set_num(pw, gnc_get_num_action(txn, assetaccount_split));
gnc_ui_payment_window_set_memo(pw, xaccTransGetDescription(txn));
{
GDate txn_date = xaccTransGetDatePostedGDate (txn);
Expand Down
1 change: 1 addition & 0 deletions src/core-utils/gnc-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static GHashTable *features_table = NULL;
static gncFeature known_features[] =
{
{ GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at least GnuCash 2.5.0)" },
{ GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; either transaction number or split action (requires at least GnuCash 2.5.0)" },
{ NULL },
};

Expand Down
1 change: 1 addition & 0 deletions src/core-utils/gnc-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@{
*/
#define GNC_FEATURE_CREDIT_NOTES "Credit Notes"
#define GNC_FEATURE_NUM_FIELD_SOURCE "Number Field Source"

/** @} */

Expand Down
1 change: 1 addition & 0 deletions src/core-utils/gnc-gconf-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#define KEY_ACCOUNTING_LABELS "use_accounting_labels"
#define KEY_ACCOUNT_SEPARATOR "account_separator"
#define KEY_NEGATIVE_IN_RED "negative_in_red"
#define KEY_NUM_SOURCE "num_source"
#define KEY_ENABLE_EURO "enable_euro"
#define KEY_DATE_FORMAT "date_format"
#define KEY_DATE_COMPLETION "date_completion"
Expand Down
12 changes: 8 additions & 4 deletions src/engine/SchedXaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "SchedXaction.h"
#include "Transaction.h"
#include "gnc-engine.h"
#include "engine-helpers.h"

#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.engine.sx"
Expand Down Expand Up @@ -1039,10 +1040,11 @@ pack_split_info (TTSplitInfo *s_info, Account *parent_acct,
xaccSplitSetMemo(split,
gnc_ttsplitinfo_get_memo(s_info));

xaccSplitSetAction(split,
/* Set split-action with gnc_set_num_action which is the same as
* xaccSplitSetAction with these arguments */
gnc_set_num_action(NULL, split, NULL,
gnc_ttsplitinfo_get_action(s_info));


xaccAccountInsertSplit(parent_acct,
split);

Expand Down Expand Up @@ -1113,8 +1115,10 @@ xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list,

xaccTransSetDatePostedSecs(new_trans, gnc_time (NULL));

xaccTransSetNum(new_trans,
gnc_ttinfo_get_num(tti));
/* Set tran-num with gnc_set_num_action which is the same as
* xaccTransSetNum with these arguments */
gnc_set_num_action(new_trans, NULL,
gnc_ttinfo_get_num(tti), NULL);
xaccTransSetCurrency( new_trans,
gnc_ttinfo_get_currency(tti) );

Expand Down
12 changes: 11 additions & 1 deletion src/engine/Split.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#endif

#include "qof.h"
#include "qofbook.h"
#include "Split.h"
#include "AccountP.h"
#include "Scrub.h"
Expand Down Expand Up @@ -1259,13 +1260,22 @@ xaccSplitOrder (const Split *sa, const Split *sb)
int retval;
int comp;
char *da, *db;
gboolean action_for_num;

if (sa == sb) return 0;
/* nothing is always less than something */
if (!sa) return -1;
if (!sb) return +1;

retval = xaccTransOrder (sa->parent, sb->parent);
/* sort in transaction order, but use split action rather than trans num
* according to book option */
action_for_num = qof_book_use_split_action_for_num_field
(xaccSplitGetBook (sa));
if (action_for_num)
retval = xaccTransOrder_num_action (sa->parent, sa->action,
sb->parent, sb->action);
else
retval = xaccTransOrder (sa->parent, sb->parent);
if (retval) return retval;

/* otherwise, sort on memo strings */
Expand Down
12 changes: 10 additions & 2 deletions src/engine/Split.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,18 @@ const char * xaccSplitGetMemo (const Split *split);
* It is meant to be a very short (one to ten character) string that
* signifies the "type" of this split, such as e.g. Buy, Sell, Div,
* Withdraw, Deposit, ATM, Check, etc. The idea is that this field
* can be used to create custom reports or graphs of data. */
* can be used to create custom reports or graphs of data. Rather than use
* this function directly, see 'gnc_set_num_action' in
* engine/engine-helpers.c & .h which takes a user-set book option for selecting
* the source for the num-cell (the transaction-number or the split-action field)
* in registers/reports into account automatically */
void xaccSplitSetAction (Split *split, const char *action);

/** Returns the action string. */
/** Returns the action string. Rather than use this function directly, see
* 'gnc_get_num_action' and 'gnc_get_action_num'in
* engine/engine-helpers.c & .h which takes a user-set book option for selecting
* the source for the num-cell (the transaction-number or the split-action field)
* in registers/reports into account automatically */
const char * xaccSplitGetAction (const Split *split);
/** @} */

Expand Down
19 changes: 17 additions & 2 deletions src/engine/Transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,13 @@ xaccTransIsOpen (const Transaction *trans)

int
xaccTransOrder (const Transaction *ta, const Transaction *tb)
{
return xaccTransOrder_num_action (ta, NULL, tb, NULL);
}

int
xaccTransOrder_num_action (const Transaction *ta, const char *actna,
const Transaction *tb, const char *actnb)
{
char *da, *db;
int na, nb, retval;
Expand All @@ -1631,8 +1638,16 @@ xaccTransOrder (const Transaction *ta, const Transaction *tb)
DATE_CMP(ta, tb, date_posted);

/* otherwise, sort on number string */
na = atoi(ta->num);
nb = atoi(tb->num);
if (actna && actnb) /* split action string, if not NULL */
{
na = atoi(actna);
nb = atoi(actnb);
}
else /* else transaction num string */
{
na = atoi(ta->num);
nb = atoi(tb->num);
}
if (na < nb) return -1;
if (na > nb) return +1;

Expand Down
37 changes: 35 additions & 2 deletions src/engine/Transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ void xaccTransSetTxnType (Transaction *trans, char type);
* See #TXN_TYPE_NONE, #TXN_TYPE_INVOICE and #TXN_TYPE_PAYMENT */
char xaccTransGetTxnType (const Transaction *trans);

/** Sets the transaction Number (or ID) field*/
/** Sets the transaction Number (or ID) field; rather than use this function
* directly, see 'gnc_set_num_action' in engine/engine-helpers.c & .h which
* takes a user-set book option for selecting the source for the num-cell (the
* transaction-number or the split-action field) in registers/reports into
* account automatically */
void xaccTransSetNum (Transaction *trans, const char *num);

/** Sets the transaction Description */
Expand All @@ -275,7 +279,11 @@ void xaccTransSetDescription (Transaction *trans, const char *desc);
The Notes field is only visible in the register in double-line mode */
void xaccTransSetNotes (Transaction *trans, const char *notes);

/** Gets the transaction Number (or ID) field*/
/** Gets the transaction Number (or ID) field; rather than use this function
* directly, see 'gnc_get_num_action' and 'gnc_get_action_num' in
* engine/engine-helpers.c & .h which takes a user-set book option for
* selecting the source for the num-cell (the transaction-number or the
* split-action field) in registers/reports into account automatically */
const char * xaccTransGetNum (const Transaction *trans);
/** Gets the transaction Description */
const char * xaccTransGetDescription (const Transaction *trans);
Expand Down Expand Up @@ -455,9 +463,34 @@ gnc_numeric xaccTransGetAccountBalance (const Transaction *trans,
* GncGUID (compare as a guid)
* Finally, it returns zero if all of the above match.
* Note that it does *NOT* compare its member splits.
* Note also that it calls xaccTransOrder_num_action with actna and actnb
* set as NULL.
*/
int xaccTransOrder (const Transaction *ta, const Transaction *tb);


/**
* The xaccTransOrder_num_action(ta,actna,tb,actnb) method is useful for sorting.
* Orders ta and tb
* return <0 if ta sorts before tb
* return >0 if ta sorts after tb
* return 0 if they are absolutely equal
*
* The comparrison uses the following fields, in order:
* date posted (compare as a date)
* if actna and actnb are NULL,
* num field (compare as an integer)
* else actna and actnb (compare as an integer)
* date entered (compare as a date)
* description field (comcpare as a string using strcmp())
* GncGUID (compare as a guid)
* Finally, it returns zero if all of the above match.
* Note that it does *NOT* compare its member splits (except action as
* specified above).
*/
int xaccTransOrder_num_action (const Transaction *ta, const char *actna,
const Transaction *tb, const char *actnb);

/** @} */


Expand Down
6 changes: 5 additions & 1 deletion src/engine/cap-gains.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "TransactionP.h"
#include "cap-gains.h"
#include "gnc-engine.h"
#include "engine-helpers.h"
#include "gnc-lot.h"
#include "policy.h"
#include "policy-p.h"
Expand Down Expand Up @@ -532,7 +533,10 @@ xaccSplitAssignToLot (Split *split, GNCLot *lot)

/* Copy most of the split attributes */
xaccSplitSetMemo (new_split, xaccSplitGetMemo (split));
xaccSplitSetAction (new_split, xaccSplitGetAction (split));
/* Set split-action with gnc_set_num_action which is the same as
* xaccSplitSetAction with these arguments; use gnc_get_num_action to get
* split-action which is the same as xaccSplitGetAction */
gnc_set_num_action(NULL, new_split, NULL, gnc_get_num_action(NULL, split));
xaccSplitSetReconcile (new_split, xaccSplitGetReconcile (split));
ts = xaccSplitRetDateReconciledTS (split);
xaccSplitSetDateReconciledTS (new_split, &ts);
Expand Down
Loading

0 comments on commit 7cdd737

Please sign in to comment.