r22681 - gnucash/trunk/src - Implement a Book Option to give users the choice to use the transaction 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.

J. Alex Aycinena alex.aycinena at code.gnucash.org
Sat Dec 22 01:00:55 EST 2012


Author: alex.aycinena
Date: 2012-12-22 01:00:54 -0500 (Sat, 22 Dec 2012)
New Revision: 22681
Trac: http://svn.gnucash.org/trac/changeset/22681

Modified:
   gnucash/trunk/src/app-utils/app-utils.scm
   gnucash/trunk/src/app-utils/business-prefs.scm
   gnucash/trunk/src/app-utils/gnc-ui-util.c
   gnucash/trunk/src/app-utils/gnc-ui-util.h
   gnucash/trunk/src/business/business-gnome/dialog-payment.c
   gnucash/trunk/src/core-utils/gnc-features.c
   gnucash/trunk/src/core-utils/gnc-features.h
   gnucash/trunk/src/core-utils/gnc-gconf-utils.h
   gnucash/trunk/src/engine/SchedXaction.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Split.h
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/Transaction.h
   gnucash/trunk/src/engine/cap-gains.c
   gnucash/trunk/src/engine/engine-helpers.c
   gnucash/trunk/src/engine/engine-helpers.h
   gnucash/trunk/src/engine/engine.i
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncOwner.c
   gnucash/trunk/src/engine/test/utest-Split.c
   gnucash/trunk/src/gnome-search/dialog-search.c
   gnucash/trunk/src/gnome-utils/dialog-dup-trans.c
   gnucash/trunk/src/gnome-utils/dialog-dup-trans.h
   gnucash/trunk/src/gnome-utils/dialog-options.c
   gnucash/trunk/src/gnome-utils/dialog-options.h
   gnucash/trunk/src/gnome-utils/dialog-transfer.c
   gnucash/trunk/src/gnome-utils/dialog-utils.c
   gnucash/trunk/src/gnome-utils/dialog-utils.h
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.h
   gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c
   gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c
   gnucash/trunk/src/gnome-utils/gnc-ui.h
   gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade
   gnucash/trunk/src/gnome/assistant-hierarchy.c
   gnucash/trunk/src/gnome/assistant-stock-split.c
   gnucash/trunk/src/gnome/dialog-find-transactions.c
   gnucash/trunk/src/gnome/dialog-lot-viewer.c
   gnucash/trunk/src/gnome/dialog-print-check.c
   gnucash/trunk/src/gnome/dialog-sx-from-trans.c
   gnucash/trunk/src/gnome/gnc-plugin-page-register.c
   gnucash/trunk/src/gnome/gnc-plugin-page-register.h
   gnucash/trunk/src/gnome/gnc-plugin-page-register2.c
   gnucash/trunk/src/gnome/gnc-split-reg.c
   gnucash/trunk/src/gnome/gnc-split-reg.h
   gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade
   gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade
   gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c
   gnucash/trunk/src/import-export/aqbanking/gnc-file-aqb-import.c
   gnucash/trunk/src/import-export/csv-export/csv-transactions-export.c
   gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.c
   gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.h
   gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.c
   gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.glade
   gnucash/trunk/src/import-export/csv-import/gnc-csv-model.c
   gnucash/trunk/src/import-export/csv-import/gnc-csv-model.h
   gnucash/trunk/src/import-export/import-backend.c
   gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
   gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c
   gnucash/trunk/src/import-export/qif-import/assistant-qif-import.glade
   gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm
   gnucash/trunk/src/libqof/qof/qofbook.c
   gnucash/trunk/src/libqof/qof/qofbook.h
   gnucash/trunk/src/libqof/qof/qofbookslots.h
   gnucash/trunk/src/libqof/qof/test/test-qofbook.c
   gnucash/trunk/src/register/ledger-core/Makefile.am
   gnucash/trunk/src/register/ledger-core/split-register-control.c
   gnucash/trunk/src/register/ledger-core/split-register-layout.c
   gnucash/trunk/src/register/ledger-core/split-register-load.c
   gnucash/trunk/src/register/ledger-core/split-register-model-save.c
   gnucash/trunk/src/register/ledger-core/split-register-model.c
   gnucash/trunk/src/register/ledger-core/split-register-util.c
   gnucash/trunk/src/register/ledger-core/split-register.c
   gnucash/trunk/src/register/ledger-core/split-register.h
   gnucash/trunk/src/register/ledger-core/test/Makefile.am
   gnucash/trunk/src/report/business-reports/customer-summary.scm
   gnucash/trunk/src/report/business-reports/job-report.scm
   gnucash/trunk/src/report/business-reports/owner-report.scm
   gnucash/trunk/src/report/locale-specific/us/taxtxf.scm
   gnucash/trunk/src/report/standard-reports/register.scm
   gnucash/trunk/src/report/standard-reports/standard-reports.scm
   gnucash/trunk/src/report/standard-reports/transaction.scm
Log:
Implement a Book Option to give users the choice to use the transaction 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


Modified: gnucash/trunk/src/app-utils/app-utils.scm
===================================================================
--- gnucash/trunk/src/app-utils/app-utils.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/app-utils/app-utils.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -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)

Modified: gnucash/trunk/src/app-utils/business-prefs.scm
===================================================================
--- gnucash/trunk/src/app-utils/business-prefs.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/app-utils/business-prefs.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -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

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -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"
@@ -193,6 +196,25 @@
     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"
 
@@ -220,6 +242,26 @@
     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)
 {

Modified: gnucash/trunk/src/app-utils/gnc-ui-util.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -58,10 +58,25 @@
 
 /* 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);
 

Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -40,6 +40,7 @@
 #include "Transaction.h"
 #include "Account.h"
 #include "gncOwner.h"
+#include "engine-helpers.h"
 
 #include "gncInvoice.h"
 
@@ -1120,7 +1121,7 @@
 
     // 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);

Modified: gnucash/trunk/src/core-utils/gnc-features.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-features.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/core-utils/gnc-features.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -42,6 +42,7 @@
 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 },
 };
 

Modified: gnucash/trunk/src/core-utils/gnc-features.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-features.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/core-utils/gnc-features.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -40,6 +40,7 @@
 @{
  */
 #define GNC_FEATURE_CREDIT_NOTES "Credit Notes"
+#define GNC_FEATURE_NUM_FIELD_SOURCE "Number Field Source"
 
 /** @} */
 

Modified: gnucash/trunk/src/core-utils/gnc-gconf-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-gconf-utils.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/core-utils/gnc-gconf-utils.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -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"

Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/SchedXaction.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -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"
@@ -1039,10 +1040,11 @@
     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);
 
@@ -1113,8 +1115,10 @@
 
         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) );
 

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/Split.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -39,6 +39,7 @@
 #endif
 
 #include "qof.h"
+#include "qofbook.h"
 #include "Split.h"
 #include "AccountP.h"
 #include "Scrub.h"
@@ -1259,13 +1260,22 @@
     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 */

Modified: gnucash/trunk/src/engine/Split.h
===================================================================
--- gnucash/trunk/src/engine/Split.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/Split.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -161,10 +161,18 @@
  * 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);
 /** @} */
 

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/Transaction.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -1620,6 +1620,13 @@
 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;
 
@@ -1631,8 +1638,16 @@
     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;
 

Modified: gnucash/trunk/src/engine/Transaction.h
===================================================================
--- gnucash/trunk/src/engine/Transaction.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/Transaction.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -264,7 +264,11 @@
  * 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 */
@@ -275,7 +279,11 @@
  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);
@@ -455,9 +463,34 @@
  *      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);
+
 /** @} */
 
 

Modified: gnucash/trunk/src/engine/cap-gains.c
===================================================================
--- gnucash/trunk/src/engine/cap-gains.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/cap-gains.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -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"
@@ -532,7 +533,10 @@
 
         /* 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);

Modified: gnucash/trunk/src/engine/engine-helpers.c
===================================================================
--- gnucash/trunk/src/engine/engine-helpers.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/engine-helpers.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -33,9 +33,11 @@
 #include "glib-helpers.h"
 #include "gnc-date.h"
 #include "gnc-engine.h"
+#include "gnc-session.h"
 #include "guile-mappings.h"
 #include "gnc-guile-utils.h"
 #include "qof.h"
+#include "qofbookslots.h"
 /** \todo Code dependent on the private query headers
 qofquery-p.h and qofquerycore-p.h may need to be modified.
 These files are temporarily exported for QOF 0.6.0 but
@@ -77,6 +79,194 @@
     xaccTransSetDatePostedTS(t, &ts);
 }
 
+/** Gets the transaction Number or split Action based on book option:
+  * if the book option is TRUE (split action is used for NUM) and a
+  * split is provided, split-action is returned; if book option is FALSE
+  * (tran-num is used for NUM) and a trans is provided, transaction-num
+  * is returned; if split is provided and tran is NULL, split-action is
+  * returned; if tran is provided and split is NULL, transaction-num is
+  * returned. Otherwise NULL is returned.*/
+const char *
+gnc_get_num_action (const Transaction *trans, const Split *split)
+{
+    gboolean num_action = qof_book_use_split_action_for_num_field
+                           (qof_session_get_book(gnc_get_current_session ()));
+
+    if (trans && !split)
+        return xaccTransGetNum(trans);
+    if (split && !trans)
+        return xaccSplitGetAction(split);
+    if (trans && split)
+    {
+        if (num_action)
+            return xaccSplitGetAction(split);
+        else
+            return xaccTransGetNum(trans);
+    }
+    else return NULL;
+}
+
+/** Opposite of 'gnc_get_num_action'; if the book option is TRUE (split action
+  * is used for NUM) and a trans is provided, transaction-num is returned; if
+  * book option is FALSE (tran-num is used for NUM) and a split is provided,
+  * split-action is returned; if split is provided and tran is NULL,
+  * split-action is returned; if tran is provided and split is NULL,
+  * transaction-num is returned. Otherwise NULL is returned.*/
+const char *
+gnc_get_action_num (const Transaction *trans, const Split *split)
+{
+    gboolean num_action = qof_book_use_split_action_for_num_field
+                           (qof_session_get_book(gnc_get_current_session ()));
+
+    if (trans && !split)
+        return xaccTransGetNum(trans);
+    if (split && !trans)
+        return xaccSplitGetAction(split);
+    if (trans && split)
+    {
+        if (num_action)
+            return xaccTransGetNum(trans);
+        else
+            return xaccSplitGetAction(split);
+    }
+    else return NULL;
+}
+
+/** Sets the transaction Number and/or split Action based on book option:
+  * if the book option is TRUE (split action is to be used for NUM) then 'num'
+  * sets split-action and, if 'tran' and 'action' are provided, 'action'
+  * sets transaction-num; if book option is FALSE (tran-num is to be used for NUM)
+  * then 'num' sets transaction-num and, if 'split' and 'action' are
+  * provided, 'action' sets 'split-action'. If any arguments are NULL (#f, for
+  * the guile version), no change is made to the field that would otherwise be
+  * affected. If 'tran' and 'num' are passed with 'split and 'action' set to
+  * NULL, it is xaccTransSetNum (trans, num). Likewise, if 'split and 'action'
+  * are passed with 'tran' and 'num' set to NULL, it is xaccSplitSetAction (split,
+  * action). */
+void
+gnc_set_num_action (Transaction *trans, Split *split,
+                    const char *num, const char *action)
+{
+    gboolean num_action = qof_book_use_split_action_for_num_field
+                           (qof_session_get_book(gnc_get_current_session ()));
+
+    if (trans && num && !split && !action)
+    {
+        xaccTransSetNum (trans, num);
+        return;
+    }
+
+    if (!trans && !num && split && action)
+    {
+        xaccSplitSetAction (split, action);
+        return;
+    }
+
+    if (trans)
+    {
+        if (!num_action && num)
+            xaccTransSetNum (trans, num);
+        if (num_action && action)
+            xaccTransSetNum (trans, action);
+    }
+    if (split)
+    {
+        if (!num_action && action)
+            xaccSplitSetAction (split, action);
+        if (num_action && num)
+           xaccSplitSetAction (split, num);
+    }
+}
+
+/************************************************************/
+/*           Notification of Book Option Changes            */
+/************************************************************/
+
+static GOnce bo_init_once = G_ONCE_INIT;
+static GHashTable *bo_callback_hash = NULL;
+static GHookList *bo_final_hook_list = NULL;
+
+static gpointer
+bo_init (gpointer unused)
+{
+    bo_callback_hash = g_hash_table_new(g_str_hash, g_str_equal);
+
+    bo_final_hook_list = g_malloc(sizeof(GHookList));
+    g_hook_list_init(bo_final_hook_list, sizeof(GHook));
+    return NULL;
+}
+
+static void
+bo_call_hook (GHook *hook, gpointer data)
+{
+    ((GFunc)hook->func)(data, hook->data);
+}
+
+/** Calls registered callbacks when num_field_source book option changes so that
+  * registers/reports can update themselves */
+void
+gnc_book_option_num_field_source_change (gboolean num_action)
+{
+    GHookList *hook_list;
+    const gchar *key = OPTION_NAME_NUM_FIELD_SOURCE;
+
+    g_once(&bo_init_once, bo_init, NULL);
+
+    hook_list = g_hash_table_lookup(bo_callback_hash, key);
+    if (hook_list != NULL)
+        g_hook_list_marshal(hook_list, TRUE, bo_call_hook, &num_action);
+    g_hook_list_invoke(bo_final_hook_list, TRUE);
+}
+
+void
+gnc_book_option_register_cb (gchar *key, GncBOCb func, gpointer user_data)
+{
+    GHookList *hook_list;
+    GHook *hook;
+
+    g_once(&bo_init_once, bo_init, NULL);
+    hook_list = g_hash_table_lookup(bo_callback_hash, key);
+    if (hook_list == NULL)
+    {
+        hook_list = g_malloc(sizeof(GHookList));
+        g_hook_list_init(hook_list, sizeof(GHook));
+        g_hash_table_insert(bo_callback_hash, (gpointer)key, hook_list);
+    }
+
+    hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
+    if (hook != NULL)
+    {
+        return;
+    }
+
+    hook = g_hook_alloc(hook_list);
+    hook->func = func;
+    hook->data = user_data;
+    g_hook_append(hook_list, hook);
+}
+
+void
+gnc_book_option_remove_cb (gchar *key, GncBOCb func, gpointer user_data)
+{
+    GHookList *hook_list;
+    GHook *hook;
+
+    g_once(&bo_init_once, bo_init, NULL);
+    hook_list = g_hash_table_lookup(bo_callback_hash, key);
+    if (hook_list == NULL)
+        return;
+    hook = g_hook_find_func_data(hook_list, TRUE, func, user_data);
+    if (hook == NULL)
+        return;
+
+    g_hook_destroy_link(hook_list, hook);
+    if (hook_list->hooks == NULL)
+    {
+        g_hash_table_remove(bo_callback_hash, key);
+        g_free(hook_list);
+    }
+}
+
 SCM
 gnc_timespec2timepair(Timespec t)
 {

Modified: gnucash/trunk/src/engine/engine-helpers.h
===================================================================
--- gnucash/trunk/src/engine/engine-helpers.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/engine-helpers.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -33,6 +33,8 @@
 #include "Query.h"
 #include "Transaction.h"
 
+typedef void (*GncBOCb)    (gpointer new_val, gpointer user_data);
+
 Timespec gnc_transaction_get_date_posted(const Transaction *t);
 Timespec gnc_transaction_get_date_entered(const Transaction *t);
 
@@ -40,6 +42,51 @@
 
 void gnc_transaction_set_date(Transaction *t, Timespec ts);
 
+/** Gets the transaction Number or split Action based on book option:
+  * if the book option is TRUE (split action is used for NUM) and a
+  * split is provided, split-action is returned; if book option is FALSE
+  * (tran-num is used for NUM) and a trans is provided, transaction-num
+  * is returned; if split is provided and tran is NULL, split-action is
+  * returned; if tran is provided and split is NULL, transaction-num is
+  * returned. Otherwise NULL is returned.*/
+const char *  gnc_get_num_action (const Transaction *trans, const Split *split);
+
+/** Opposite of 'gnc_get_num_action'; if the book option is TRUE (split action
+  * is used for NUM) and a trans is provided, transaction-num is returned; if
+  * book option is FALSE (tran-num is used for NUM) and a split is provided,
+  * split-action is returned; if split is provided and tran is NULL,
+  * split-action is returned; if tran is provided and split is NULL,
+  * transaction-num is returned. Otherwise NULL is returned.*/
+const char *  gnc_get_action_num (const Transaction *trans, const Split *split);
+
+/** Sets the transaction Number and/or split Action based on book option:
+  * if the book option is TRUE (split action is to be used for NUM) then 'num'
+  * sets split-action and, if 'tran' and 'action' are provided, 'action'
+  * sets transaction-num; if book option is FALSE (tran-num is to be used for NUM)
+  * then 'num' sets transaction-num and, if 'split' and 'action' are
+  * provided, 'action' sets 'split-action'. If any arguments are NULL (#f, for
+  * the guile version), no change is made to the field that would otherwise be
+  * affected. If 'tran' and 'num' are passed with 'split and 'action' set to
+  * NULL, it is xaccTransSetNum (trans, num). Likewise, if 'split and 'action'
+  * are passed with 'tran' and 'num' set to NULL, it is xaccSplitSetAction (split,
+  * action). */
+void gnc_set_num_action (Transaction *trans, Split *split,
+                            const char *num, const char *action);
+
+/** Calls registered callbacks when num_field_source book option changes so that
+  * registers/reports can update themselves */
+void
+gnc_book_option_num_field_source_change (gboolean num_action);
+
+/** Registers callbacks to be called when the book option changes for the
+  * specified book option key */
+void
+gnc_book_option_register_cb (gchar *key, GncBOCb func, gpointer user_data);
+
+/** Removes previously registered callbacks for the specified book option key */
+void
+gnc_book_option_remove_cb (gchar *key, GncBOCb func, gpointer user_data);
+
 /* Helpers for various types */
 
 SCM      gnc_timespec2timepair(Timespec t);

Modified: gnucash/trunk/src/engine/engine.i
===================================================================
--- gnucash/trunk/src/engine/engine.i	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/engine.i	2012-12-22 06:00:54 UTC (rev 22681)
@@ -88,7 +88,49 @@
   static QofIdType QOF_ID_BOOK_SCM (void) { return QOF_ID_BOOK; }
 }
 
+/* Allow '#f' in guile to be used to represent NULL in 'C' for functions *
+ * 'gnc_set_num_action', 'gnc_get_num_action' and 'gnc_get_action_num' in *
+ * 'engine-helpers.c' */
+%typemap(in) Transaction *trans {
+  if ($input == SCM_BOOL_F)
+    $1 = NULL;
+  else
+    $1 = (Transaction *)SWIG_MustGetPtr($input, SWIGTYPE_p_Transaction, 1, 0);
+}
+
+%typemap(in) Split *split {
+  if ($input == SCM_BOOL_F)
+    $1 = NULL;
+  else
+    $1 = (Split *)SWIG_MustGetPtr($input, SWIGTYPE_p_Split, 2, 0);
+}
+
+%typemap(in) char * num (int must_free = 0) {
+  if ($input == SCM_BOOL_F)
+    $1 = NULL;
+  else
+  {
+    $1 = (char *)SWIG_scm2str($input);
+    must_free3 = 1;
+  }
+}
+
+%typemap(in) char * action (int must_free = 0) {
+  if ($input == SCM_BOOL_F)
+    $1 = NULL;
+  else
+  {
+    $1 = (char *)SWIG_scm2str($input);
+    must_free4 = 1;
+  }
+}
+
 %include <engine-helpers.h>
+%typemap(in) Transaction *trans;
+%typemap(in) Split *split;
+%typemap(in) char * num;
+%typemap(in) char * action;
+
 %include <gnc-pricedb.h>
 
 QofSession * qof_session_new (void);
@@ -280,6 +322,7 @@
     SET_ENUM("SPLIT-ACCOUNT");
     SET_ENUM("SPLIT-VALUE");
     SET_ENUM("SPLIT-MEMO");
+    SET_ENUM("SPLIT-ACTION");
     SET_ENUM("SPLIT-DATE-RECONCILED");
     SET_ENUM("SPLIT-ACCT-FULLNAME");
     SET_ENUM("SPLIT-CORR-ACCT-NAME");
@@ -294,6 +337,7 @@
     SET_ENUM("OPTION-SECTION-ACCOUNTS");
     SET_ENUM("OPTION-NAME-TRADING-ACCOUNTS");
     SET_ENUM("OPTION-NAME-AUTO-READONLY-DAYS");
+    SET_ENUM("OPTION-NAME-NUM-FIELD-SOURCE");
 
     SET_ENUM("OPTION-SECTION-BUDGETING");
     SET_ENUM("OPTION-NAME-DEFAULT-BUDGET");

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/gncInvoice.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -42,6 +42,7 @@
 #include "gncInvoice.h"
 #include "gncInvoiceP.h"
 #include "gncOwnerP.h"
+#include "engine-helpers.h"
 
 struct _gncInvoice
 {
@@ -1192,7 +1193,8 @@
     /* set action and memo? */
 
     xaccSplitSetMemo (split, memo);
-    xaccSplitSetAction (split, type);
+    /* set per book option */
+    gnc_set_num_action (NULL, split, gncInvoiceGetID(invoice), type);
 
     /* Need to insert this split into the account AND txn before
      * we set the Base Value.  Otherwise SetBaseValue complains
@@ -1298,9 +1300,10 @@
 
     name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)));
 
-    /* Set Transaction Description (Owner Name) , Num (invoice ID), Currency */
+    /* Set Transaction Description (Owner Name) , Num (invoice ID or type, based
+     * on book option), Currency */
     xaccTransSetDescription (txn, name ? name : "");
-    xaccTransSetNum (txn, gncInvoiceGetID (invoice));
+    gnc_set_num_action (txn, NULL, gncInvoiceGetID (invoice), type);
     xaccTransSetCurrency (txn, invoice->currency);
 
     /* Entered and Posted at date */
@@ -1380,9 +1383,9 @@
                     Split *split;
 
                     split = xaccMallocSplit (book);
-                    /* set action? */
                     xaccSplitSetMemo (split, gncEntryGetDescription (entry));
-                    xaccSplitSetAction (split, type);
+                    /* set action based on book option */
+                    gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
                     xaccAccountBeginEdit (ccard_acct);
                     xaccAccountInsertSplit (ccard_acct, split);
                     xaccAccountCommitEdit (ccard_acct);
@@ -1438,9 +1441,10 @@
         gnc_numeric to_charge_bal_amount = (is_cn ? gnc_numeric_neg (invoice->to_charge_amount)
                                             : invoice->to_charge_amount);
 
-        /* Set memo.  action? */
+        /* Set memo. */
         xaccSplitSetMemo (split, _("Extra to Charge Card"));
-        xaccSplitSetAction (split, type);
+        /* Set action based on book option */
+        gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
 
         xaccAccountBeginEdit (ccard_acct);
         xaccAccountInsertSplit (ccard_acct, split);
@@ -1457,9 +1461,10 @@
     {
         Split *split = xaccMallocSplit (book);
 
-        /* Set action/memo */
+        /* Set memo */
         xaccSplitSetMemo (split, memo);
-        xaccSplitSetAction (split, type);
+        /* Set action based on book option */
+        gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
 
         xaccAccountBeginEdit (acc);
         xaccAccountInsertSplit (acc, split);

Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/gncOwner.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -45,6 +45,7 @@
 #include "gnc-commodity.h"
 #include "Transaction.h"
 #include "Split.h"
+#include "engine-helpers.h"
 
 #define _GNC_MOD_NAME   GNC_ID_OWNER
 
@@ -780,7 +781,8 @@
 
         /* Set up the transaction */
         xaccTransSetDescription (txn, name ? name : "");
-        xaccTransSetNum (txn, num);
+        /* set per book option */
+        gnc_set_num_action (txn, NULL, num, _("Payment"));
         xaccTransSetCurrency (txn, commodity);
         xaccTransSetDateEnteredSecs (txn, gnc_time (NULL));
         xaccTransSetDatePostedTS (txn, &date);
@@ -790,7 +792,8 @@
         /* The split for the transfer account */
         split = xaccMallocSplit (book);
         xaccSplitSetMemo (split, memo);
-        xaccSplitSetAction (split, _("Payment"));
+        /* set per book option */
+        gnc_set_num_action (NULL, split, num, _("Payment"));
         xaccAccountBeginEdit (xfer_acc);
         xaccAccountInsertSplit (xfer_acc, split);
         xaccAccountCommitEdit (xfer_acc);
@@ -814,7 +817,8 @@
     /* Add a split in the post account */
     split = xaccMallocSplit (book);
     xaccSplitSetMemo (split, memo);
-    xaccSplitSetAction (split, _("Payment"));
+    /* set per book option */
+    gnc_set_num_action (NULL, split, num, _("Payment"));
     xaccAccountBeginEdit (posted_acc);
     xaccAccountInsertSplit (posted_acc, split);
     xaccAccountCommitEdit (posted_acc);
@@ -960,7 +964,8 @@
             /* Create the split for this link in current balancing lot */
             split = xaccMallocSplit (book);
             xaccSplitSetMemo (split, memo);
-            xaccSplitSetAction (split, action);
+            /* set Action using utility function */
+            gnc_set_num_action (NULL, split, NULL, action);
             xaccAccountInsertSplit (acct, split);
             xaccTransAppendSplit (txn, split);
             xaccSplitSetBaseValue (split, gnc_numeric_neg (split_amt), xaccAccountGetCommodity(acct));
@@ -989,7 +994,8 @@
             Split *split = xaccMallocSplit (book);
 
             xaccSplitSetMemo (split, memo);
-            xaccSplitSetAction (split, action);
+            /* set Action with utiltity function */
+            gnc_set_num_action (NULL, split, NULL, action);
             xaccAccountInsertSplit (acct, split);
             xaccTransAppendSplit (txn, split);
             xaccSplitSetBaseValue (split, val_paid, xaccAccountGetCommodity(acct));

Modified: gnucash/trunk/src/engine/test/utest-Split.c
===================================================================
--- gnucash/trunk/src/engine/test/utest-Split.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/engine/test/utest-Split.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -1106,8 +1106,10 @@
 static void
 test_xaccSplitOrder (Fixture *fixture, gconstpointer pData)
 {
+    const char *slot_path;
     Split *split = fixture->split;
     Split *o_split = xaccMallocSplit (xaccSplitGetBook (split));
+    Transaction *o_txn = xaccMallocTransaction (xaccSplitGetBook (split));
     Transaction *txn = split->parent;
 
     g_assert_cmpint (xaccSplitOrder (split, split), ==, 0);
@@ -1118,12 +1120,57 @@
  */
     g_assert_cmpint (xaccSplitOrder (split, o_split), ==, -1);
 
+/* This is testing the call to xaccTransOrder_num_action: split and o_split have
+ * parents with the same date_posted so will sort on tran-num or
+ * split-action based on book option.
+ */
+    o_split->parent = o_txn;
+    split->parent->date_posted = timespec_now ();
+    o_split->parent->date_posted = split->parent->date_posted;
+
+/* The book_use_split_action_for_num_field book option hasn't been set so it
+ * should sort on tran-num, so xaccTransOrder_num_action returns -1.
+ */
+    split->parent->num = "123";
+    split->action = "5";
+    o_split->parent->num = "124";
+    o_split->action = "6";
+    g_assert_cmpint (xaccSplitOrder (split, o_split), ==, -1);
+
+/* Reverse, so xaccTransOrder_num_action returns +1.
+ */
+    split->parent->num = "124";
+    o_split->parent->num = "123";
+    g_assert_cmpint (xaccSplitOrder (split, o_split), ==, +1);
+
+/* Now set the book_use_split_action_for_num_field book option so it will
+ * sort on split-action, so xaccTransOrder_num_action returns -1, initially.
+ */
+
+    /* create correct slot path */
+    slot_path = (const char *) g_strconcat( KVP_OPTION_PATH, "/",
+            OPTION_SECTION_ACCOUNTS, "/", OPTION_NAME_NUM_FIELD_SOURCE, NULL );
+    g_assert( slot_path != NULL );
+    g_test_message( "Testing with use-split-action-for-num set to true - t" );
+    qof_book_set_string_option( xaccSplitGetBook (split), slot_path, "t" );
+    g_assert(qof_book_use_split_action_for_num_field(xaccSplitGetBook(split)) == TRUE);
+
+    g_assert_cmpint (xaccSplitOrder (split, o_split), ==, -1);
+
+    split->action = "7";
+    g_assert_cmpint (xaccSplitOrder (split, o_split), ==, +1);
+
+/* Revert settings for the rest of the test */
+    o_split->action = NULL;
+    split->action = "foo";
+    o_split->parent = NULL;
+    qof_book_set_string_option( xaccSplitGetBook (split), slot_path, "f" );
+    g_assert(qof_book_use_split_action_for_num_field(xaccSplitGetBook(split)) == FALSE);
     split->parent = NULL;
 /* This should return > 0 because o_split has no memo string */
     g_assert_cmpint (xaccSplitOrder (split, o_split), >, 0);
     o_split->memo = "baz";
     g_assert_cmpint (xaccSplitOrder (split, o_split), <, 0);
-
 /* This should return > 0 because o_split has no action string */
     o_split->memo = split->memo;
     g_assert_cmpint (xaccSplitOrder (split, o_split), >, 0);
@@ -1166,6 +1213,7 @@
 /* so that it won't assert during teardown */
     split->parent = txn;
     test_destroy (o_split);
+    test_destroy (o_txn);
 }
 /* xaccSplitOrderDateOnly
 gint

Modified: gnucash/trunk/src/gnome/assistant-hierarchy.c
===================================================================
--- gnucash/trunk/src/gnome/assistant-hierarchy.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/assistant-hierarchy.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -96,6 +96,7 @@
 
     gboolean account_list_added;
     gboolean use_defaults;
+    gboolean new_book;  /* presumably only used for new book creation but we check*/
 
     GncHierarchyAssistantFinishedCallback when_completed;
 
@@ -455,6 +456,11 @@
 {
     GtkTextBuffer* buffer;
 
+    /* Before creating transactions, if this is a new book, let user specify
+     * book options, since they affect how transactions are created */
+    if (data->new_book)
+        data->new_book = gnc_new_book_option_display ();
+
     if (!data->account_list_added)
     {
         /* clear out the description/tree */
@@ -1067,6 +1073,14 @@
     GtkBuilder *builder;
 
     data = g_new0 (hierarchy_data, 1);
+
+    /* Presumably this assistant is only used to create a new book but we check.
+     * When gnucash is started with --nofile, there is initially no session (and
+     * no book), but by the time we get here, 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). */
+    data->new_book = gnc_is_new_book();
+
     builder = gtk_builder_new();
     gnc_builder_add_from_file (builder, "assistant-hierarchy.glade", "Hierarchy Assistant");
 
@@ -1084,7 +1098,7 @@
                                      GTK_WIDGET(gtk_builder_get_object(builder, "intro_page_label")),
                                      TRUE);
     gtk_assistant_set_page_complete (GTK_ASSISTANT (dialog),
-                                     GTK_WIDGET(gtk_builder_get_object(builder, "currency_page_vbox")),
+                                     GTK_WIDGET(gtk_builder_get_object(builder, "currency_book_option_page_vbox")),
                                      TRUE);
     gtk_assistant_set_page_complete (GTK_ASSISTANT (dialog),
                                      GTK_WIDGET(gtk_builder_get_object(builder, "final_account_vbox")),

Modified: gnucash/trunk/src/gnome/assistant-stock-split.c
===================================================================
--- gnucash/trunk/src/gnome/assistant-stock-split.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/assistant-stock-split.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -29,6 +29,7 @@
 #include <glib/gi18n.h>
 
 #include "Transaction.h"
+#include "engine-helpers.h"
 #include "dialog-utils.h"
 #include "assistant-stock-split.h"
 #include "assistant-utils.h"
@@ -403,8 +404,10 @@
 
     xaccSplitSetAmount (split, amount);
     xaccSplitMakeStockSplit (split);
+    /* Set split-action with gnc_set_num_action which is the same as
+     * xaccSplitSetAction with these arguments */
     /* Translators: This string has a disambiguation prefix */
-    xaccSplitSetAction (split, Q_("Action Column|Split"));
+    gnc_set_num_action (NULL, split, NULL, Q_("Action Column|Split"));
 
     amount = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (info->price_edit));
     if (gnc_numeric_positive_p (amount))

Modified: gnucash/trunk/src/gnome/dialog-find-transactions.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-find-transactions.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/dialog-find-transactions.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -94,6 +94,8 @@
     struct _ftd_data *ftd;
     static GList *params = NULL;
     QofQuery *start_q, *show_q = NULL;
+    gboolean num_action =
+                qof_book_use_split_action_for_num_field(gnc_get_current_book());
 
     /* Build parameter list in reverse order */
     if (params == NULL)
@@ -121,9 +123,13 @@
                                            NULL);
         params = gnc_search_param_prepend (params, N_("Notes"), NULL,
                                            type, SPLIT_TRANS, TRANS_NOTES, NULL);
-        params = gnc_search_param_prepend (params, N_("Action"), NULL,
+        params = gnc_search_param_prepend (params, (num_action
+                                                    ? N_("Number/Action")
+                                                    : N_("Action")), NULL,
                                            type, SPLIT_ACTION, NULL);
-        params = gnc_search_param_prepend (params, N_("Number"), NULL,
+        params = gnc_search_param_prepend (params, (num_action
+                                                    ? N_("Transaction Number")
+                                                    : N_("Number")), NULL,
                                            type, SPLIT_TRANS, TRANS_NUM, NULL);
         params = gnc_search_param_prepend (params, N_("Memo"), NULL,
                                            type, SPLIT_MEMO, NULL);
@@ -131,7 +137,30 @@
                                            type, SPLIT_TRANS, TRANS_DESCRIPTION,
                                            NULL);
     }
+    else
+    {
+        GList *l;
+        for (l = params; l; l = l->next)
+        {
+            GNCSearchParam *param = l->data;
 
+            if (num_action)
+            {
+                if (strcmp (param->title, N_("Action")) == 0)
+                    gnc_search_param_set_title (param, N_("Number/Action"));
+                if (strcmp (param->title, N_("Number")) == 0)
+                    gnc_search_param_set_title (param, N_("Transaction Number"));
+            }
+            else
+            {
+                if (strcmp (param->title, N_("Number/Action")) == 0)
+                    gnc_search_param_set_title (param, N_("Action"));
+                if (strcmp (param->title, N_("Transaction Number")) == 0)
+                    gnc_search_param_set_title (param, N_("Number"));
+            }
+        }
+    }
+
     ftd = g_new0 (struct _ftd_data, 1);
 
     if (orig_ledg)

Modified: gnucash/trunk/src/gnome/dialog-lot-viewer.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-lot-viewer.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/dialog-lot-viewer.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -39,6 +39,7 @@
 #include "gnc-lot.h"
 #include "Scrub3.h"
 #include "Transaction.h"
+#include "engine-helpers.h"
 #include "gncInvoice.h"
 
 #include "dialog-utils.h"
@@ -512,8 +513,9 @@
         qof_print_date_buff (dbuff, MAX_DATE_LENGTH, date);
         gtk_list_store_set (store, &iter, SPLIT_COL_DATE, dbuff, -1);
 
-        /* Num */
-        gtk_list_store_set (store, &iter, SPLIT_COL_NUM, xaccTransGetNum (trans), -1);
+        /* Num  - retrieve number based on book option */
+        gtk_list_store_set (store, &iter, SPLIT_COL_NUM,
+                                        gnc_get_num_action (trans, split), -1);
 
         /* Description */
         gtk_list_store_set (store, &iter, SPLIT_COL_DESCRIPTION, xaccTransGetDescription (trans), -1);

Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/dialog-print-check.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -53,6 +53,7 @@
 #include "gnc-gkeyfile-utils.h"
 
 #include "gnc-engine.h"
+#include "engine-helpers.h"
 #include "Split.h"
 #include "Transaction.h"
 
@@ -2171,11 +2172,13 @@
             break;
 
         case ACTION:
-            draw_text(context, xaccSplitGetAction(pcd->split), item, default_desc);
+            draw_text(context, gnc_get_action_num(trans, pcd->split), item,
+                                                                default_desc);
             break;
 
         case CHECK_NUMBER:
-            draw_text(context, xaccTransGetNum(trans), item, default_desc);
+            draw_text(context, gnc_get_num_action(trans, pcd->split), item,
+                                                                default_desc);
             break;
 
         case AMOUNT_NUMBER:

Modified: gnucash/trunk/src/gnome/dialog-sx-from-trans.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-sx-from-trans.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/dialog-sx-from-trans.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -35,6 +35,7 @@
 #include "gnc-dense-cal-store.h"
 #include "gnc-dense-cal.h"
 #include "gnc-engine.h"
+#include "engine-helpers.h"
 #include "gnc-gconf-utils.h"
 #include "gnc-ui-util.h"
 #include "gnc-ui.h"
@@ -219,14 +220,14 @@
     runningBalance = gnc_numeric_zero();
 
     gnc_ttinfo_set_description(tti, xaccTransGetDescription(tr));
-    gnc_ttinfo_set_num(tti, xaccTransGetNum(tr));
+    gnc_ttinfo_set_num(tti, gnc_get_num_action(tr, NULL));
     gnc_ttinfo_set_currency(tti, xaccTransGetCurrency(tr));
 
     for (splits = xaccTransGetSplitList(tr); splits; splits = splits->next)
     {
         sp = splits->data;
         ttsi = gnc_ttsplitinfo_malloc();
-        gnc_ttsplitinfo_set_action(ttsi, xaccSplitGetAction(sp));
+        gnc_ttsplitinfo_set_action(ttsi, gnc_get_num_action(NULL, sp));
         split_value = xaccSplitGetValue(sp);
         gnc_ttsplitinfo_set_memo(ttsi, xaccSplitGetMemo(sp));
 

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -75,6 +75,9 @@
 #include "window-reconcile.h"
 #include "window-autoclear.h"
 #include "window-report.h"
+#include "split-register-p.h"
+#include "engine-helpers.h"
+#include "qofbookslots.h"
 
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_GUI;
@@ -484,6 +487,8 @@
     struct
     {
         GtkWidget *dialog;
+        GtkWidget *num_radio;
+        GtkWidget *act_radio;
         SortType original_sort_type;
         gboolean original_save_order;
         gboolean save_order;
@@ -1610,6 +1615,40 @@
 /*                     "Sort By" Dialog                     */
 /************************************************************/
 
+/** This function is called whenever the number source book options is changed
+ *  to adjust the displayed labels. Since the book option change may change the
+ *  query sort, the gnc_split_reg_set_sort_type_force function is called to
+ *  ensure the page is refreshed.
+ *
+ *  @param new_val A pointer to the boolean for the new value of the book option.
+ *
+ *  @param page A pointer to the GncPluginPageRegister that is
+ *  associated with this sort order dialog.
+ */
+static void
+gnc_plugin_page_register_sort_book_option_changed (gpointer new_val,
+                                                    gpointer user_data)
+{
+    GncPluginPageRegisterPrivate *priv;
+    GncPluginPageRegister *page = user_data;
+    gboolean *new_data = (gboolean*)new_val;
+
+    g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page));
+
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+    if (*new_data)
+    {
+        gtk_button_set_label(GTK_BUTTON (priv->sd.num_radio), _("Transaction Number"));
+        gtk_button_set_label(GTK_BUTTON (priv->sd.act_radio), _("Number/Action"));
+    }
+    else
+    {
+        gtk_button_set_label(GTK_BUTTON (priv->sd.num_radio), _("Number"));
+        gtk_button_set_label(GTK_BUTTON (priv->sd.act_radio), _("Action"));
+    }
+    gnc_split_reg_set_sort_type_force (priv->gsr, priv->gsr->sort_type, TRUE);
+}
+
 /** This function is called when the "Sort By..." dialog is closed.
  *  If the dialog was closed by any method other than clicking the OK
  *  button, the original sorting order will be restored.
@@ -1655,7 +1694,12 @@
             gnc_plugin_page_register_set_sort_order (plugin_page, order);
         }
     }
+    gnc_book_option_remove_cb(OPTION_NAME_NUM_FIELD_SOURCE,
+                                gnc_plugin_page_register_sort_book_option_changed,
+                                page);
     priv->sd.dialog = NULL;
+    priv->sd.num_radio = NULL;
+    priv->sd.act_radio = NULL;
     gtk_widget_destroy(GTK_WIDGET(dialog));
     LEAVE(" ");
 }
@@ -2368,6 +2412,10 @@
     arg = SCM_BOOL (reg->use_double_line);
     args = scm_cons (arg, args);
 
+    arg = SCM_BOOL (reg->type == GENERAL_LEDGER || reg->type == INCOME_LEDGER
+                                                || reg->type == SEARCH_LEDGER);
+    args = scm_cons (arg, args);
+
     arg = SCM_BOOL (reg->style == REG_STYLE_JOURNAL);
     args = scm_cons (arg, args);
 
@@ -2782,6 +2830,7 @@
         GncPluginPageRegister *page)
 {
     GncPluginPageRegisterPrivate *priv;
+    SplitRegister *reg;
     GtkWidget *dialog, *button;
     GtkBuilder *builder;
     SortType sort;
@@ -2825,7 +2874,20 @@
     if (priv->sd.save_order == TRUE)
         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
 
-    /* Wire it up */
+    priv->sd.num_radio = GTK_WIDGET(gtk_builder_get_object (builder, "BY_NUM"));
+    priv->sd.act_radio = GTK_WIDGET(gtk_builder_get_object (builder, "BY_ACTION"));
+    /* Adjust labels related to Num/Action radio buttons based on book option */
+    reg = gnc_ledger_display_get_split_register(priv->ledger);
+    if (reg && !reg->use_tran_num_for_num_field)
+    {
+        gtk_button_set_label(GTK_BUTTON (priv->sd.num_radio), _("Transaction Number"));
+        gtk_button_set_label(GTK_BUTTON (priv->sd.act_radio), _("Number/Action"));
+    }
+    gnc_book_option_register_cb(OPTION_NAME_NUM_FIELD_SOURCE,
+                                gnc_plugin_page_register_sort_book_option_changed,
+                                page);
+
+     /* Wire it up */
     gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, page);
 
     /* Show it */
@@ -3580,6 +3642,43 @@
     gnc_plugin_page_register_ui_update(NULL, page);
 }
 
+static gboolean
+find_reg_by_acct (gpointer find_data, gpointer user_data)
+{
+    GncPluginPageRegisterPrivate *priv;
+    SplitRegister *reg;
+    Account *account = find_data;
+    GncPluginPageRegister *page = user_data;
+
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+    reg = gnc_ledger_display_get_split_register(priv->ledger);
+
+    return (xaccAccountEqual(account,
+                             gnc_split_register_get_default_account (reg),
+                             TRUE));
+}
+
+SplitRegister *
+gnc_find_register_by_account (Account *account)
+{
+    GncPluginPageRegister *page;
+
+    if (!account) return NULL;
+
+    page = gnc_find_first_gui_component (GNC_PLUGIN_PAGE_REGISTER_NAME,
+                                            find_reg_by_acct,
+                                            (gpointer) account);
+    if (page)
+    {
+        GncPluginPageRegisterPrivate *priv;
+        SplitRegister *reg;
+
+        priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page);
+        return reg = gnc_ledger_display_get_split_register(priv->ledger);
+    }
+    else return NULL;
+}
+
 static void
 gnc_plugin_page_register_close_cb (gpointer user_data)
 {

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.h
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -66,6 +66,17 @@
 
 /* function prototypes */
 
+/* gnc_find_register_by_account
+ *   Search for an open register for the specified account.
+ *
+ * @param account The pointer to the account to search open register pages for;
+ *              must be non-NULL
+ *
+ * @return The pointer to the open register of the account, or NULL if none found
+ */
+SplitRegister *
+gnc_find_register_by_account (Account *account);
+
 /** Retrieve the type number for the plugin page.
  *
  *  @return The type number.

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register2.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register2.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register2.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -2430,6 +2430,10 @@
     arg = SCM_BOOL (reg->use_double_line);
     args = scm_cons (arg, args);
 
+    arg = SCM_BOOL (reg->type == GENERAL_LEDGER || reg->type == INCOME_LEDGER
+                                                || reg->type == SEARCH_LEDGER);
+    args = scm_cons (arg, args);
+
     arg = SCM_BOOL (reg->style == REG_STYLE_JOURNAL);
     args = scm_cons (arg, args);
 

Modified: gnucash/trunk/src/gnome/gnc-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/gnc-split-reg.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -1570,14 +1570,14 @@
 }
 
 static void
-gnc_split_reg_sort( GNCSplitReg *gsr, SortType sort_code )
+gnc_split_reg_sort_force( GNCSplitReg *gsr, SortType sort_code, gboolean force )
 {
     Query *query = gnc_ledger_display_get_query( gsr->ledger );
     gboolean show_present_divider = FALSE;
     GSList *p1 = NULL, *p2 = NULL, *p3 = NULL, *standard;
     SplitRegister *reg;
 
-    if (gsr->sort_type == sort_code)
+    if ((gsr->sort_type == sort_code) && !force)
         return;
 
     standard = g_slist_prepend( NULL, QUERY_DEFAULT_SORT );
@@ -1644,6 +1644,12 @@
     gnc_ledger_display_refresh( gsr->ledger );
 }
 
+static void
+gnc_split_reg_sort( GNCSplitReg *gsr, SortType sort_code )
+{
+    gnc_split_reg_sort_force( gsr, sort_code, FALSE );
+}
+
 void
 gnc_split_reg_sort_standard_cb(GtkWidget *w, gpointer data)
 {
@@ -2100,6 +2106,12 @@
     gnc_split_reg_sort( gsr, t );
 }
 
+void
+gnc_split_reg_set_sort_type_force( GNCSplitReg *gsr, SortType t, gboolean force )
+{
+    gnc_split_reg_sort_force( gsr, t, force );
+}
+
 GtkWidget*
 gnc_split_reg_get_summarybar( GNCSplitReg *gsr )
 {

Modified: gnucash/trunk/src/gnome/gnc-split-reg.h
===================================================================
--- gnucash/trunk/src/gnome/gnc-split-reg.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/gnc-split-reg.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -185,10 +185,12 @@
 GtkWidget *gsr_create_summary_bar( GNCSplitReg *gsr );
 
 /**
- * Gets/sets the sort-type of the GNCSplitReg.
+ * Gets/sets the sort-type of the GNCSplitReg. The 'force' version causes the
+ * query to be redone even if SortType has not changed.
  **/
 SortType gnc_split_reg_get_sort_type( GNCSplitReg *gsr );
 void gnc_split_reg_set_sort_type( GNCSplitReg *gsr, SortType t );
+void gnc_split_reg_set_sort_type_force( GNCSplitReg *gsr, SortType t, gboolean force);
 
 /**
  * Gets/sets the style of the GNCSplitReg.

Modified: gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade
===================================================================
--- gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/gtkbuilder/assistant-hierarchy.glade	2012-12-22 06:00:54 UTC (rev 22681)
@@ -28,7 +28,7 @@
       </packing>
     </child>
     <child>
-      <object class="GtkVBox" id="currency_page_vbox">
+      <object class="GtkVBox" id="currency_book_option_page_vbox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="spacing">5</property>
@@ -93,6 +93,32 @@
           </packing>
         </child>
         <child>
+          <object class="GtkLabel" id="book_option_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes"><b>Book Options</b></property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="book_option_message_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Since you are creating a new file, you will next see a dialog for setting book options. These can affect how GnuCash transactions are handled later, during account setup. If you come back to this page without cancelling and starting over, the dialog for setting book options will not be shown a second time when you go forward. You can access it directly from the menu via File->Properties.</property>
+            <property name="wrap">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+        <child>
           <placeholder/>
         </child>
       </object>

Modified: gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade
===================================================================
--- gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome/gtkbuilder/gnc-plugin-page-register.glade	2012-12-22 06:00:54 UTC (rev 22681)
@@ -84,7 +84,7 @@
               <object class="GtkTable" id="duplicate_table">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="n_rows">2</property>
+                <property name="n_rows">3</property>
                 <property name="n_columns">2</property>
                 <property name="column_spacing">12</property>
                 <property name="row_spacing">6</property>
@@ -128,7 +128,7 @@
                     <property name="secondary_icon_activatable">False</property>
                     <property name="primary_icon_sensitive">True</property>
                     <property name="secondary_icon_sensitive">True</property>
-                    <property name="adjustment">adjustment1</property>
+                    <property name="adjustment">num_adjustment</property>
                     <property name="climb_rate">1</property>
                   </object>
                   <packing>
@@ -154,6 +154,40 @@
                     <property name="y_options">GTK_FILL</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkLabel" id="tnum_label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">_Transaction Number:</property>
+                    <property name="use_underline">True</property>
+                    <property name="justify">center</property>
+                    <property name="mnemonic_widget">tnum_spin</property>
+                  </object>
+                  <packing>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="tnum_spin">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="primary_icon_activatable">False</property>
+                    <property name="secondary_icon_activatable">False</property>
+                    <property name="adjustment">tnum_adjustment</property>
+                    <property name="climb_rate">1</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
               </object>
             </child>
           </object>
@@ -1011,7 +1045,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkHSeparator" id="hseparator1">
+              <object class="GtkHSeparator" id="hseparator3">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
               </object>
@@ -1033,7 +1067,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkHBox" id="hbox1">
+              <object class="GtkHBox" id="hbox2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <child>
@@ -1185,9 +1219,14 @@
       <action-widget response="-5">okbutton1</action-widget>
     </action-widgets>
   </object>
-  <object class="GtkAdjustment" id="adjustment1">
+  <object class="GtkAdjustment" id="num_adjustment">
     <property name="upper">1000000000</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="tnum_adjustment">
+    <property name="upper">1000000000</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
 </interface>

Modified: gnucash/trunk/src/gnome-search/dialog-search.c
===================================================================
--- gnucash/trunk/src/gnome-search/dialog-search.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-search/dialog-search.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -37,6 +37,8 @@
 #include "gnc-gconf-utils.h"
 #include "gnc-session.h"
 #include "qof.h"
+#include "engine-helpers.h"
+#include "qofbookslots.h"
 
 #include "Transaction.h"	/* for the SPLIT_* and TRANS_* */
 
@@ -762,29 +764,15 @@
 
 
 static GtkWidget *
-get_element_widget (GNCSearchWindow *sw, GNCSearchCoreType *element)
+get_comb_box_widget (GNCSearchWindow *sw, struct _crit_data *data)
 {
-    GtkWidget *combo_box, *hbox, *p;
+    GtkWidget *combo_box;
     GtkListStore *store;
     GtkTreeIter iter;
     GtkCellRenderer *cell;
     GList *l;
-    struct _crit_data *data;
     int index = 0, current = 0;
 
-    data = g_new0 (struct _crit_data, 1);
-    data->element = element;
-    data->dialog = GTK_DIALOG (sw->dialog);
-
-    hbox = gtk_hbox_new (FALSE, 0);
-    /* only set to automaticaly clean up the memory */
-    g_object_set_data_full (G_OBJECT (hbox), "data", data, g_free);
-
-    p = gnc_search_core_type_get_widget (element);
-    data->elemwidget = p;
-    data->container = hbox;
-    data->param = sw->last_param;
-
     store = gtk_list_store_new(NUM_SEARCH_COLS, G_TYPE_STRING, G_TYPE_POINTER);
     combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
     g_object_unref(store);
@@ -814,6 +802,29 @@
     gtk_combo_box_set_active (GTK_COMBO_BOX(combo_box), current);
     g_signal_connect (combo_box, "changed", G_CALLBACK (combo_box_changed), data);
 
+    return combo_box;
+}
+
+static GtkWidget *
+get_element_widget (GNCSearchWindow *sw, GNCSearchCoreType *element)
+{
+    GtkWidget *combo_box, *hbox, *p;
+    struct _crit_data *data;
+
+    data = g_new0 (struct _crit_data, 1);
+    data->element = element;
+    data->dialog = GTK_DIALOG (sw->dialog);
+
+    hbox = gtk_hbox_new (FALSE, 0);
+    /* only set to automaticaly clean up the memory */
+    g_object_set_data_full (G_OBJECT (hbox), "data", data, g_free);
+
+    p = gnc_search_core_type_get_widget (element);
+    data->elemwidget = p;
+    data->container = hbox;
+    data->param = sw->last_param;
+
+    combo_box = get_comb_box_widget (sw, data);
     gtk_box_pack_start (GTK_BOX (hbox), combo_box, FALSE, FALSE, 0);
     if (p)
         gtk_box_pack_start (GTK_BOX (hbox), p, FALSE, FALSE, 0);
@@ -822,7 +833,77 @@
     return hbox;
 }
 
+static void
+gnc_search_dialog_book_option_changed (gpointer new_val, gpointer user_data)
+{
+    GList *l;
+    GNCSearchWindow *sw = user_data;
+    gboolean *new_data = (gboolean*)new_val;
+    /* Save current dialog focus */
+    GtkWidget *focused_widget = gtk_window_get_focus(GTK_WINDOW(sw->dialog));
 
+    g_return_if_fail (sw);
+    if (strcmp (sw->search_for, GNC_ID_SPLIT) != 0)
+        return;
+
+    /* Adjust labels for future added search criteria */
+    for (l = sw->params_list; l; l = l->next)
+    {
+        GNCSearchParam *param = l->data;
+
+        if (*new_data)
+        {
+            if (strcmp (param->title, N_("Action")) == 0)
+                gnc_search_param_set_title (param, N_("Number/Action"));
+            if (strcmp (param->title, N_("Number")) == 0)
+                gnc_search_param_set_title (param, N_("Transaction Number"));
+        }
+        else
+        {
+            if (strcmp (param->title, N_("Number/Action")) == 0)
+                gnc_search_param_set_title (param, N_("Action"));
+            if (strcmp (param->title, N_("Transaction Number")) == 0)
+                gnc_search_param_set_title (param, N_("Number"));
+        }
+    }
+    /* Adjust labels for existing search criteria; walk the list of criteria */
+    for (l = sw->crit_list; l; l = l->next)
+    {
+        struct _crit_data *data = l->data;
+        GList *children;
+
+        /* For each, walk the list of container children to get combo_box */
+        for (children = gtk_container_get_children(GTK_CONTAINER(data->container));
+                children; children = children->next)
+        {
+            GtkWidget *combo_box = children->data;
+
+            /* Get current active item if combo_box */
+            if (GTK_IS_COMBO_BOX(combo_box))
+            {
+                GtkWidget *new_combo_box;
+                gint index;
+
+                /* Set index to current active item */
+                index = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box));
+                /* Create new combo_box to replace existing one */
+                new_combo_box = get_comb_box_widget (sw, data);
+                /* If current combo_box has focus, point to new_combo-box */
+                if (focused_widget == combo_box)
+                    focused_widget = new_combo_box;
+                gtk_widget_destroy(combo_box);
+                /* Set new combo_box to current active item */
+                gtk_combo_box_set_active(GTK_COMBO_BOX(new_combo_box), index);
+                gtk_box_pack_start (GTK_BOX (data->container), new_combo_box,
+                                                               FALSE, FALSE, 0);
+                gtk_box_reorder_child(GTK_BOX (data->container), new_combo_box, 0);
+                gtk_widget_show_all (data->container);
+            }
+        }
+    }
+    gtk_widget_grab_focus(focused_widget);
+}
+
 static void
 gnc_search_dialog_add_criterion (GNCSearchWindow *sw)
 {
@@ -878,6 +959,12 @@
 {
     g_return_val_if_fail (sw, TRUE);
 
+    /* Unregister callback on book option changes originally registered
+     * if searching for splits */
+    if (strcmp (sw->search_for, GNC_ID_SPLIT) == 0)
+        gnc_book_option_remove_cb(OPTION_NAME_NUM_FIELD_SOURCE,
+                                    gnc_search_dialog_book_option_changed, sw);
+
     gnc_unregister_gui_component (sw->component_id);
 
     /* Clear the crit list */
@@ -1087,6 +1174,12 @@
     /* add the first criterion */
     gnc_search_dialog_add_criterion (sw);
 
+    /* register to update criterion/criteria labels based on book option changes
+     * if searching for splits */
+    if (strcmp (sw->search_for, GNC_ID_SPLIT) == 0)
+        gnc_book_option_register_cb(OPTION_NAME_NUM_FIELD_SOURCE,
+                                    gnc_search_dialog_book_option_changed, sw);
+
     /* Hide the 'new' button if there is no new_item_cb */
     if (!sw->new_item_cb)
         gtk_widget_hide (new_item_button);

Modified: gnucash/trunk/src/gnome-utils/dialog-dup-trans.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-dup-trans.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/dialog-dup-trans.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -44,10 +44,13 @@
 
     GtkWidget * date_edit;
     GtkWidget * num_edit;
+    GtkWidget * tnum_edit;
 
     GtkWidget *duplicate_title_label; // GtkLabel
     GtkWidget *duplicate_table; // GtkTable
+    GtkWidget *date_label; // GtkLabel
     GtkWidget *num_label; // GtkLabel
+    GtkWidget *tnum_label; // GtkLabel
 } DupTransDialog;
 
 /* Parses the string value and returns true if it is a
@@ -91,13 +94,15 @@
 
 static void
 gnc_dup_trans_dialog_create (GtkWidget * parent, DupTransDialog *dt_dialog,
-                             time64 date, const char *num_str)
+                             gboolean show_date, time64 date,
+                             const char *num_str, const char *tnum_str)
 {
     GtkWidget *dialog;
     GtkBuilder  *builder;
 
     builder = gtk_builder_new();
-    gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "adjustment1");
+    gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "num_adjustment");
+    gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "tnum_adjustment");
     gnc_builder_add_from_file (builder, "gnc-plugin-page-register.glade", "Duplicate Transaction Dialog");
 
     dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Duplicate Transaction Dialog"));
@@ -108,6 +113,8 @@
         gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
 
     /* date widget */
+    dt_dialog->date_label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label"));
+    if (show_date)
     {
         GtkWidget *date_edit;
         GtkWidget *hbox;
@@ -118,32 +125,45 @@
         hbox = GTK_WIDGET(gtk_builder_get_object (builder, "date_hbox"));
         gtk_widget_show (date_edit);
 
-        label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label"));
-        gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date_edit), label);
+        gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date_edit), dt_dialog->date_label);
 
         gtk_box_pack_end (GTK_BOX (hbox), date_edit, TRUE, TRUE, 0);
         dt_dialog->date_edit = date_edit;
     }
+    else
+    {
+        dt_dialog->date_edit = NULL;
+    }
 
     dt_dialog->duplicate_title_label = GTK_WIDGET(gtk_builder_get_object (builder, "duplicate_title_label"));
     dt_dialog->duplicate_table = GTK_WIDGET(gtk_builder_get_object (builder, "duplicate_table"));
     dt_dialog->num_label = GTK_WIDGET(gtk_builder_get_object (builder, "num_label"));
+    dt_dialog->tnum_label = GTK_WIDGET(gtk_builder_get_object (builder, "tnum_label"));
 
     {
-        GtkWidget *num_spin;
-        long int num;
+        GtkWidget *num_spin, *tnum_spin;
+        long int num, tnum;
 
         num_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_spin"));
+        tnum_spin = GTK_WIDGET(gtk_builder_get_object (builder, "tnum_spin"));
         dt_dialog->num_edit = num_spin;
+        dt_dialog->tnum_edit = tnum_spin;
 
         gtk_entry_set_activates_default(GTK_ENTRY(num_spin), TRUE);
         g_signal_connect(num_spin, "output",
                          G_CALLBACK(gnc_dup_trans_output_cb), dt_dialog);
+        g_signal_connect(tnum_spin, "output",
+                         G_CALLBACK(gnc_dup_trans_output_cb), dt_dialog);
 
         if (num_str && parse_num (num_str, &num))
             gtk_spin_button_set_value (GTK_SPIN_BUTTON (num_spin), num + 1);
         else
             gtk_entry_set_text (GTK_ENTRY (num_spin), "");
+
+        if (tnum_str && parse_num (tnum_str, &tnum))
+            gtk_spin_button_set_value (GTK_SPIN_BUTTON (tnum_spin), tnum + 1);
+        else
+            gtk_entry_set_text (GTK_ENTRY (tnum_spin), "");
     }
 
     gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dt_dialog);
@@ -153,26 +173,38 @@
 
 static gboolean
 gnc_dup_trans_dialog_internal (GtkWidget * parent, const char* title,
-                               time64 *date_p, GDate *gdate_p,
-                               const char *num, char **out_num)
+                               gboolean show_date, time64 *date_p,
+                               GDate *gdate_p, const char *num, char **out_num,
+                               const char *tnum, char **out_tnum)
 {
     DupTransDialog *dt_dialog;
-    GNCDateEdit *gde;
     GtkWidget *entry;
     gboolean ok;
     gint result;
 
-    if (!date_p)
-        return FALSE;
-
     dt_dialog = g_new0 (DupTransDialog, 1);
 
-    gnc_dup_trans_dialog_create (parent, dt_dialog, *date_p, num);
+    gnc_dup_trans_dialog_create (parent, dt_dialog, show_date,
+                                    *date_p, num, tnum);
 
-    gde = GNC_DATE_EDIT (dt_dialog->date_edit);
-    entry = gde->date_entry;
+    if (!show_date)
+    {
+        // The "date" field isn't being asked for, so we make the widgets invisible
+        gtk_widget_set_visible(dt_dialog->date_label, FALSE);
+        if (dt_dialog->date_edit)
+            gtk_widget_set_visible(dt_dialog->date_edit, FALSE);
+        // If no "date" field, there must be a "num" field, so give it focus
+        if (out_num)
+            gtk_widget_grab_focus (dt_dialog->num_edit);
+    }
+    else
+    {
+        GNCDateEdit *gde;
 
-    gtk_widget_grab_focus (entry);
+        gde = GNC_DATE_EDIT (dt_dialog->date_edit);
+        entry = gde->date_entry;
+        gtk_widget_grab_focus (entry);
+    }
 
     if (title)
     {
@@ -188,6 +220,25 @@
         gtk_widget_set_visible(dt_dialog->num_edit, FALSE);
     }
 
+    if (!tnum)
+    {
+        // The "tnum" field isn't being asked for, so we make the widgets invisible
+        gtk_widget_set_visible(dt_dialog->tnum_label, FALSE);
+        gtk_widget_set_visible(dt_dialog->tnum_edit, FALSE);
+    }
+
+    if (!show_date && !tnum)
+    {
+        // The "date" and the "tnum" fields aren't being asked for, this is a split copy
+        gtk_label_set_markup(GTK_LABEL (dt_dialog->num_label), _("Action/Number:"));
+    }
+
+    if (tnum)
+    {
+        gtk_entry_set_activates_default(GTK_ENTRY(dt_dialog->num_edit), FALSE);
+        gtk_entry_set_activates_default(GTK_ENTRY(dt_dialog->tnum_edit), TRUE);
+    }
+
     result = gtk_dialog_run (GTK_DIALOG (dt_dialog->dialog));
 
     if (result == GTK_RESPONSE_OK)
@@ -198,6 +249,8 @@
             gnc_date_edit_get_gdate(GNC_DATE_EDIT (dt_dialog->date_edit), gdate_p);
         if (out_num)
             *out_num = g_strdup (gtk_entry_get_text (GTK_ENTRY (dt_dialog->num_edit)));
+        if (tnum)
+            *out_tnum = g_strdup (gtk_entry_get_text (GTK_ENTRY (dt_dialog->tnum_edit)));
         ok = TRUE;
     }
     else
@@ -210,10 +263,12 @@
 }
 
 gboolean
-gnc_dup_trans_dialog (GtkWidget * parent, time64 *date_p,
-                      const char *num, char **out_num)
+gnc_dup_trans_dialog (GtkWidget * parent, const char* title, gboolean show_date,
+                      time64 *date_p, const char *num, char **out_num,
+                      const char *tnum, char **out_tnum)
 {
-    return gnc_dup_trans_dialog_internal(parent, NULL, date_p, NULL, num, out_num);
+    return gnc_dup_trans_dialog_internal(parent, title, show_date, date_p, NULL,
+                                            num, out_num, tnum, out_tnum);
 }
 
 gboolean
@@ -224,7 +279,8 @@
     g_assert(gdate_p);
 
     tmp_time = timespecToTime64(gdate_to_timespec(*gdate_p));
-    return gnc_dup_trans_dialog_internal(parent, NULL, &tmp_time, gdate_p, num, out_num);
+    return gnc_dup_trans_dialog_internal(parent, NULL, TRUE, &tmp_time, gdate_p,
+                                            num, out_num, NULL, NULL);
 }
 
 gboolean
@@ -234,5 +290,6 @@
     g_assert(gdate_p);
 
     tmp_time = timespecToTime64(gdate_to_timespec(*gdate_p));
-    return gnc_dup_trans_dialog_internal(parent, title, &tmp_time, gdate_p, NULL, NULL);
+    return gnc_dup_trans_dialog_internal(parent, title, TRUE, &tmp_time, gdate_p,
+                                            NULL, NULL, NULL, NULL);
 }

Modified: gnucash/trunk/src/gnome-utils/dialog-dup-trans.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-dup-trans.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/dialog-dup-trans.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -35,16 +35,22 @@
  * gnc_dup_trans_dialog                                             *
  *   opens up a window to do an automatic transfer between accounts *
  *                                                                  *
- * Args:   parent  - the parent of the window to be created         *
- *         date    - the initial date to use, and the output        *
- *                   parameter for the new date                     *
- *         num     - input num field                                *
- *         out_num - output num field, g_newed string               *
+ * Args:   parent    - the parent of the window to be created       *
+ *         title     - the text of the title label, otherwise       *
+ *                     defaults to "New Transaction Information"    *
+ *         show_date - TRUE to display date label and edit widgets  *
+ *         date      - the initial date to use, and the output      *
+ *                     parameter for the new date                   *
+ *         num       - input num field                              *
+ *         out_num   - output num field, g_newed string             *
+ *         tnum      - input tnum field, if used, else NULL         *
+ *         out_tnum  - output tnum field, g_newed string            *
  * Return: TRUE if user closes dialog with 'OK'                     *
 \********************************************************************/
 gboolean
-gnc_dup_trans_dialog (GtkWidget * parent, time64 *date_p,
-                      const char *num, char **out_num);
+gnc_dup_trans_dialog (GtkWidget * parent, const char* title, gboolean show_date,
+                      time64 *date_p, const char *num, char **out_num,
+                      const char *tnum, char **out_tnum);
 
 gboolean
 gnc_dup_trans_dialog_gdate (GtkWidget * parent, GDate *gdate_p,

Modified: gnucash/trunk/src/gnome-utils/dialog-options.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/dialog-options.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -1381,6 +1381,20 @@
 GNCOptionWin *
 gnc_options_dialog_new(gchar *title)
 {
+    return gnc_options_dialog_new_modal(FALSE, title);
+}
+
+/* gnc_options_dialog_new_modal:
+ *
+ *   - Opens the dialog-options glade file
+ *   - Connects signals specified in the builder file
+ *   - Sets the window's title
+ *   - Initializes a new GtkNotebook, and adds it to the window
+ *   - If modal TRUE, hides 'apply' button
+ */
+GNCOptionWin *
+gnc_options_dialog_new_modal(gboolean modal, gchar *title)
+{
     GNCOptionWin *retval;
     GtkBuilder   *builder;
     GtkWidget    *hbox;
@@ -1427,6 +1441,15 @@
     if (title)
         gtk_window_set_title(GTK_WINDOW(retval->dialog), title);
 
+    /* modal */
+    if (modal == TRUE)
+    {
+        GtkWidget *apply_button;
+
+        apply_button = GTK_WIDGET(gtk_builder_get_object (builder, "applybutton"));
+        gtk_widget_hide (apply_button);
+    } 
+
     /* glade doesn't suport a notebook with zero pages */
     hbox = GTK_WIDGET(gtk_builder_get_object (builder, "notebook placeholder"));
     retval->notebook = gtk_notebook_new();

Modified: gnucash/trunk/src/gnome-utils/dialog-options.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-options.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/dialog-options.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -24,7 +24,7 @@
 #define OPTIONS_DIALOG_H
 
 #include <libguile.h>
-#include "option-util.h"
+#include "app-utils/option-util.h"
 #include <gtk/gtk.h>
 
 /** A simple wrapper that casts the gpointer result of
@@ -35,6 +35,7 @@
 
 typedef void (* GNCOptionWinCallback)(GNCOptionWin *, gpointer data);
 
+GNCOptionWin * gnc_options_dialog_new_modal(gboolean modal, gchar *title);
 GNCOptionWin * gnc_options_dialog_new(gchar *title);
 GNCOptionWin * gnc_options_dialog_new_w_dialog(gchar *title, GtkWidget *dialog);
 void gnc_options_dialog_destroy(GNCOptionWin * win);

Modified: gnucash/trunk/src/gnome-utils/dialog-transfer.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-transfer.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/dialog-transfer.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -1489,8 +1489,8 @@
         xaccTransSetCurrency(trans, from_commodity);
         xaccTransSetDatePostedTS(trans, &ts);
 
-        string = gtk_entry_get_text(GTK_ENTRY(xferData->num_entry));
-        xaccTransSetNum(trans, string);
+        /* Trans-Num or Split-Action set with gnc_set_num_action below per book
+         * option */
 
         string = gtk_entry_get_text(GTK_ENTRY(xferData->description_entry));
         xaccTransSetDescription(trans, string);
@@ -1513,6 +1513,10 @@
         xaccSplitSetBaseValue(to_split, amount, from_commodity);
         xaccSplitSetBaseValue(to_split, to_amount, to_commodity);
 
+        /* Set the transaction number or split action field based on book option*/
+        string = gtk_entry_get_text(GTK_ENTRY(xferData->num_entry));
+        gnc_set_num_action (trans, from_split, string, NULL);
+
         /* Set the memo fields */
         string = gtk_entry_get_text(GTK_ENTRY(xferData->memo_entry));
         xaccSplitSetMemo(from_split, string);

Modified: gnucash/trunk/src/gnome-utils/dialog-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -40,6 +40,8 @@
 #include "gnc-euro.h"
 #include "gnc-ui-util.h"
 #include "gnc-gconf-utils.h"
+#include "guile-util.h"
+#include "gnc-main-window.h"
 #include <gnc-gdate-utils.h>
 
 /* This static indicates the debugging module that this .o belongs to. */
@@ -612,3 +614,26 @@
     }
     return response;
 }
+
+/* If this is a new book, this function can be used to display book options
+ * dialog so user can specify options, before any transactions can be
+ * imported/entered, since they can affect how transactions are created
+ * Note: This dialog is modal! */
+gboolean
+gnc_new_book_option_display (void)
+{
+    GtkWidget *window;
+    gint result = GTK_RESPONSE_HELP;
+
+    window = gnc_book_options_dialog_cb (TRUE, _( "New Book Options"));
+    if (window)
+    {
+        /* close dialog and proceed unless help button selected */
+        while (result == GTK_RESPONSE_HELP)
+        {
+            result = gtk_dialog_run(GTK_DIALOG(window));
+        }
+        return FALSE;
+    }
+    return TRUE;
+}

Modified: gnucash/trunk/src/gnome-utils/dialog-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -100,4 +100,10 @@
 gint
 gnc_dialog_run(GtkDialog *dialog, const gchar *gconf_key);
 
+/* If this is a new book, this function can be used to display book options
+ * dialog so user can specify options, before any transactions can be
+ * imported/entered, since they can affect how transactions are created
+ * Note: This dialog is modal! */
+gboolean gnc_new_book_option_display (void);
+
 #endif /* DIALOG_UTILS_H */

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -52,6 +52,7 @@
 #include "dialog-totd.h"
 #include "gnc-ui-util.h"
 #include "gnc-session.h"
+#include "qofbookslots.h"
 #ifdef G_OS_WIN32
 #    include "gnc-help-utils.h"
 #endif
@@ -67,6 +68,8 @@
 
 #define ACCEL_MAP_NAME "accelerator-map"
 
+static void gnc_book_options_help_cb (GNCOptionWin *win, gpointer dat);
+
 static void
 gnc_global_options_help_cb (GNCOptionWin *win, gpointer dat)
 {
@@ -74,6 +77,44 @@
 }
 
 static void
+gnc_book_options_help_cb (GNCOptionWin *win, gpointer dat)
+{
+    gnc_gnome_help (HF_HELP, HL_BOOK_OPTIONS);
+}
+
+void
+gnc_options_dialog_set_book_options_help_cb (GNCOptionWin *win)
+{
+    gnc_options_dialog_set_help_cb(win,
+                                (GNCOptionWinCallback)gnc_book_options_help_cb,
+                                NULL);
+}
+
+void
+gnc_options_dialog_set_new_book_option_values (GNCOptionDB *odb)
+{
+    GNCOption *num_source_option;
+    GtkWidget *num_source_is_split_action_button;
+    gboolean num_source_is_split_action;
+
+    if (!odb) return;
+    num_source_is_split_action = gnc_gconf_get_bool(GCONF_GENERAL,
+                                                    KEY_NUM_SOURCE,
+                                                    NULL);
+    if (num_source_is_split_action)
+    {
+        num_source_option = gnc_option_db_get_option_by_name(odb,
+                                                 OPTION_SECTION_ACCOUNTS,
+                                                 OPTION_NAME_NUM_FIELD_SOURCE);
+        num_source_is_split_action_button =
+                                gnc_option_get_gtk_widget (num_source_option);
+        gtk_toggle_button_set_active
+                    (GTK_TOGGLE_BUTTON (num_source_is_split_action_button),
+                        num_source_is_split_action);
+    }
+}
+
+static void
 gnc_commodity_help_cb (void)
 {
     gnc_gnome_help (HF_HELP, HL_COMMODITY);

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -36,6 +36,7 @@
 #define GNC_GNOME_UTILS_H
 
 #include <gnc-main-window.h>
+#include "dialog-options.h"
 
 /** Load a gtk resource configuration file to customize gtk
  *  appearance and behviour.
@@ -56,6 +57,15 @@
 void gnc_gnome_help (const char *file_name,
                      const char *anchor);
 
+/** Set the help callback to 'gnc_book_options_help_cb' to open a help browser
+ *  and point it to the Book Options link in the Help file.
+ */
+void gnc_options_dialog_set_book_options_help_cb (GNCOptionWin *win);
+ 
+/** Set the intial values of new book options to values specified in user
+ *  preferences.
+ */
+void gnc_options_dialog_set_new_book_option_values (GNCOptionDB *odb);
 
 /** Given a file name, find and load the requested pixmap.  This
  *  routine will display an error message if it can't find the file or

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -3754,21 +3754,28 @@
 }
 
 static void
-gnc_options_dialog_apply_cb(GNCOptionWin * optionwin,
+gnc_book_options_dialog_apply_cb(GNCOptionWin * optionwin,
                             gpointer user_data)
 {
     GNCOptionDB * options = user_data;
     kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
+    gboolean use_split_action_for_num_before =
+        qof_book_use_split_action_for_num_field (gnc_get_current_book ());
+    gboolean use_split_action_for_num_after;
 
     if (!options) return;
 
     gnc_option_db_commit (options);
     gnc_option_db_save_to_kvp (options, slots, TRUE);
     qof_book_kvp_changed (gnc_get_current_book());
+    use_split_action_for_num_after =
+        qof_book_use_split_action_for_num_field (gnc_get_current_book ());
+    if (use_split_action_for_num_before != use_split_action_for_num_after)
+        gnc_book_option_num_field_source_change_cb (use_split_action_for_num_after);
 }
 
 static void
-gnc_options_dialog_close_cb(GNCOptionWin * optionwin,
+gnc_book_options_dialog_close_cb(GNCOptionWin * optionwin,
                             gpointer user_data)
 {
     GNCOptionDB * options = user_data;
@@ -3777,8 +3784,8 @@
     gnc_option_db_destroy(options);
 }
 
-static void
-gnc_main_window_cmd_file_properties (GtkAction *action, GncMainWindow *window)
+GtkWidget *
+gnc_book_options_dialog_cb (gboolean modal, gchar *title)
 {
     kvp_frame *slots = qof_book_get_slots (gnc_get_current_book ());
     GNCOptionDB *options;
@@ -3788,18 +3795,30 @@
     gnc_option_db_load_from_kvp (options, slots);
     gnc_option_db_clean (options);
 
-    optionwin = gnc_options_dialog_new (_( "Book Options"));
+    optionwin = gnc_options_dialog_new_modal (modal,
+                                                (title ? title : _( "Book Options")));
     gnc_options_dialog_build_contents (optionwin, options);
 
+    gnc_options_dialog_set_book_options_help_cb (optionwin);
+
     gnc_options_dialog_set_apply_cb (optionwin,
-                                     gnc_options_dialog_apply_cb,
+                                     gnc_book_options_dialog_apply_cb,
                                      (gpointer)options);
     gnc_options_dialog_set_close_cb (optionwin,
-                                     gnc_options_dialog_close_cb,
+                                     gnc_book_options_dialog_close_cb,
                                      (gpointer)options);
+    if (modal)
+        gnc_options_dialog_set_new_book_option_values (options);
+    return gnc_options_dialog_widget (optionwin);
 }
 
 static void
+gnc_main_window_cmd_file_properties (GtkAction *action, GncMainWindow *window)
+{
+    gnc_book_options_dialog_cb (FALSE, NULL);
+}
+
+static void
 gnc_main_window_cmd_file_close (GtkAction *action, GncMainWindow *window)
 {
     GncMainWindowPrivate *priv;

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -410,6 +410,18 @@
  **/
 void gnc_main_window_show_all_windows(void);
 
+/**
+ * Opens the Book Options dialog.
+ *
+ *  @param modal True to open in modal mode, false otherwise.
+ *
+ *  @param title Title of the dialog; "Book Options" if NULL.
+ *
+ *  @return A pointer to the GtkWidget for the dialog that can be used
+ *  when started in modal mode.
+ **/
+GtkWidget *gnc_book_options_dialog_cb (gboolean modal, gchar *title);
+
 #endif /* __GNC_MAIN_WINDOW_H */
 
 /** @} */

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-model-split-reg.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -42,6 +42,7 @@
 #include "Scrub.h"
 
 #include "gnc-ui-util.h"
+#include "engine-helpers.h"
 
 #define TREE_MODEL_SPLIT_REG_CM_CLASS "tree-model-split-reg"
 
@@ -2142,7 +2143,12 @@
         }
 
         /* Add to the Num list */
-        string = xaccTransGetNum (trans);
+        /* Get transaction-number with gnc_get_num_action which is the same as
+         * xaccTransGetNum with these arguments; not sure what is being done
+         * here so not sure if this is correct; won't get the same 'num' entered
+         * by user in a register if book option to use split-action for 'num'
+         * field is set */
+        string = gnc_get_num_action (trans, NULL);
         if(g_strcmp0 (string, ""))
         {
             if(gtm_check_for_duplicates (priv->num_list, string) == FALSE)

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-split-reg.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -37,6 +37,7 @@
 #include "dialog-utils.h"
 #include "gnc-gconf-utils.h"
 #include "Transaction.h"
+#include "engine-helpers.h"
 #include "Scrub.h"
 #include "gnc-exp-parser.h"
 #include "dialog-transfer.h"
@@ -858,7 +859,8 @@
         /* fill in the dialog entries */
         gnc_xfer_dialog_set_description (xfer, xaccTransGetDescription (trans));
         gnc_xfer_dialog_set_memo (xfer, xaccSplitGetMemo (split));
-        gnc_xfer_dialog_set_num (xfer, xaccTransGetNum (trans));
+        /* Get per book option */
+        gnc_xfer_dialog_set_num (xfer, gnc_get_num_action (trans, split));
         gnc_xfer_dialog_set_date (xfer, timespecToTime64 (xaccTransRetDatePostedTS (trans)));
 
         value = amount;
@@ -1442,11 +1444,15 @@
         editable = TRUE;
 
         if (is_trow1)
-            s = xaccTransGetNum (trans);
+            /* Get per book option */
+            s = gnc_get_num_action (trans, get_this_split (view, trans));
         else if (is_trow2 && !expanded)
-            s = xaccSplitGetAction (get_this_split (view, trans));
+            /* Get per book option */
+            s = gnc_get_action_num (trans, get_this_split (view, trans));
         else if (is_split)
-            s = xaccSplitGetAction (split);
+            /* Get split-action with gnc_get_num_action which is the same as
+             * xaccSplitGetAction with these arguments */
+            s = gnc_get_num_action (NULL, split);
         else
         {
             s = "";
@@ -3104,15 +3110,21 @@
         begin_edit (view, split, trans);
         if (is_trow1)
         {
-            xaccTransSetNum (trans, new_text);
+            /* set per book option */
+            gnc_set_num_action (trans, get_this_split (view, trans),
+                                                                new_text, NULL);
         }
         if (is_trow2)
         {
-            xaccSplitSetAction (get_this_split (view, trans), new_text);
+            /* set per book option */
+            gnc_set_num_action (trans, get_this_split (view, trans),
+                                                                NULL, new_text);
         }
         if (is_split)
         {
-            xaccSplitSetAction (split, new_text);
+            /* Set split-action with gnc_set_num_action which is the same as
+             * xaccSplitSetAction with these arguments */
+            gnc_set_num_action(NULL, split, NULL, new_text);
         }
         break;
 

Modified: gnucash/trunk/src/gnome-utils/gnc-ui.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-ui.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gnc-ui.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -61,6 +61,7 @@
 #define HL_RECNWIN           "acct-reconcile"
 #define HL_SXEDITOR          "tool-sched"
 #define HL_GCONF             "gconf"
+#define HL_BOOK_OPTIONS      "book-options"
 
 /* GTK Windows - Common Response Codes */
 

Modified: gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade	2012-12-22 06:00:54 UTC (rev 22681)
@@ -1425,7 +1425,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="border_width">6</property>
-                <property name="n_rows">21</property>
+                <property name="n_rows">22</property>
                 <property name="n_columns">4</property>
                 <child>
                   <object class="GtkLabel" id="label50">
@@ -1463,6 +1463,28 @@
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkCheckButton" id="gconf/general/num_source">
+                    <property name="label" translatable="yes">Set book option on new files to use split "action" field for "Num" field on registers/reports</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="has_tooltip">True</property>
+                    <property name="tooltip_markup">If selected, the default book option for new files is set so that the &quot;Num&quot; cell on registers shows/updates the split &quot;action&quot; field and the transaction &quot;num&quot; field is shown on the second line in double line mode (and is not visible in single line mode). Otherwise, the default book option for new files is set so that the &quot;Num&quot; cell on registers shows/updates the transaction &quot;num&quot; field.</property>
+                    <property name="tooltip_text" translatable="yes">If selected, the default book option for new files is set so that the 'Num' cell on registers shows/updates the split 'action' field and the transaction 'num' field is shown on the second line in double line mode (and is not visible in single line mode). Otherwise, the default book option for new files is set so that the 'Num' cell on registers shows/updates the transaction 'num' field.</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="use_underline">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="right_attach">4</property>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options"></property>
+                    <property name="x_padding">12</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkCheckButton" id="gconf/dialogs/tip_of_the_day/show_at_startup">
                     <property name="label" translatable="yes">Display "_tip of the day" dialog</property>
                     <property name="visible">True</property>
@@ -1528,8 +1550,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">3</property>
-                    <property name="top_attach">16</property>
-                    <property name="bottom_attach">17</property>
+                    <property name="top_attach">17</property>
+                    <property name="bottom_attach">18</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options">GTK_FILL</property>
                   </packing>
@@ -1545,8 +1567,8 @@
                   </object>
                   <packing>
                     <property name="right_attach">4</property>
-                    <property name="top_attach">14</property>
-                    <property name="bottom_attach">15</property>
+                    <property name="top_attach">15</property>
+                    <property name="bottom_attach">16</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1567,8 +1589,8 @@
                   </object>
                   <packing>
                     <property name="right_attach">4</property>
-                    <property name="top_attach">11</property>
-                    <property name="bottom_attach">12</property>
+                    <property name="top_attach">12</property>
+                    <property name="bottom_attach">13</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1583,8 +1605,8 @@
                     <property name="use_markup">True</property>
                   </object>
                   <packing>
-                    <property name="top_attach">10</property>
-                    <property name="bottom_attach">11</property>
+                    <property name="top_attach">11</property>
+                    <property name="bottom_attach">12</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1594,10 +1616,10 @@
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
-                  </object>
-                  <packing>
-                    <property name="top_attach">9</property>
-                    <property name="bottom_attach">10</property>
+                 </object>
+                 <packing>
+                    <property name="top_attach">10</property>
+                    <property name="bottom_attach">11</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1612,8 +1634,8 @@
                     <property name="mnemonic_widget">gconf/general/auto_decimal_places</property>
                   </object>
                   <packing>
-                    <property name="top_attach">8</property>
-                    <property name="bottom_attach">9</property>
+                    <property name="top_attach">9</property>
+                    <property name="bottom_attach">10</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1638,8 +1660,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">8</property>
-                    <property name="bottom_attach">9</property>
+                    <property name="top_attach">9</property>
+                    <property name="bottom_attach">10</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1659,8 +1681,8 @@
                   </object>
                   <packing>
                     <property name="right_attach">4</property>
-                    <property name="top_attach">7</property>
-                    <property name="bottom_attach">8</property>
+                    <property name="top_attach">8</property>
+                    <property name="bottom_attach">9</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1681,8 +1703,8 @@
                   </object>
                   <packing>
                     <property name="right_attach">4</property>
-                    <property name="top_attach">6</property>
-                    <property name="bottom_attach">7</property>
+                    <property name="top_attach">7</property>
+                    <property name="bottom_attach">8</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1697,8 +1719,8 @@
                     <property name="use_markup">True</property>
                   </object>
                   <packing>
-                    <property name="top_attach">5</property>
-                    <property name="bottom_attach">6</property>
+                    <property name="top_attach">6</property>
+                    <property name="bottom_attach">7</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1710,8 +1732,8 @@
                     <property name="xalign">0</property>
                   </object>
                   <packing>
-                    <property name="top_attach">4</property>
-                    <property name="bottom_attach">5</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1725,8 +1747,8 @@
                     <property name="use_markup">True</property>
                   </object>
                   <packing>
-                    <property name="top_attach">19</property>
-                    <property name="bottom_attach">20</property>
+                    <property name="top_attach">20</property>
+                    <property name="bottom_attach">21</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1741,8 +1763,8 @@
                     <property name="mnemonic_widget">gconf/dialogs/search/new_search_limit</property>
                   </object>
                   <packing>
-                    <property name="top_attach">20</property>
-                    <property name="bottom_attach">21</property>
+                    <property name="top_attach">21</property>
+                    <property name="bottom_attach">22</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1767,8 +1789,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">2</property>
-                    <property name="top_attach">20</property>
-                    <property name="bottom_attach">21</property>
+                    <property name="top_attach">21</property>
+                    <property name="bottom_attach">22</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1805,8 +1827,8 @@
                     <property name="mnemonic_widget">gconf/general/autosave_interval_minutes</property>
                   </object>
                   <packing>
-                    <property name="top_attach">13</property>
-                    <property name="bottom_attach">14</property>
+                    <property name="top_attach">14</property>
+                    <property name="bottom_attach">15</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1856,8 +1878,8 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="right_attach">3</property>
-                    <property name="top_attach">13</property>
-                    <property name="bottom_attach">14</property>
+                    <property name="top_attach">14</property>
+                    <property name="bottom_attach">15</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options">GTK_FILL</property>
                   </packing>
@@ -1877,8 +1899,8 @@
                   </object>
                   <packing>
                     <property name="right_attach">4</property>
-                    <property name="top_attach">12</property>
-                    <property name="bottom_attach">13</property>
+                    <property name="top_attach">13</property>
+                    <property name="bottom_attach">14</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                     <property name="x_padding">12</property>
@@ -1891,8 +1913,8 @@
                     <property name="xalign">0</property>
                   </object>
                   <packing>
-                    <property name="top_attach">18</property>
-                    <property name="bottom_attach">19</property>
+                    <property name="top_attach">19</property>
+                    <property name="bottom_attach">20</property>
                     <property name="x_options">GTK_FILL</property>
                     <property name="y_options"></property>
                   </packing>
@@ -1908,8 +1930,8 @@
                     <property name="group">gconf/general/retain_type/days</property>
                   </object>
                   <packing>
-                    <property name="top_attach">15</property>
-                    <property name="bottom_attach">16</property>
+                    <property name="top_attach">16</property>
+                    <property name="bottom_attach">17</property>
                     <property name="x_padding">12</property>
                   </packing>
                 </child>
@@ -1924,8 +1946,8 @@
                     <property name="draw_indicator">True</property>
                   </object>
                   <packing>
-                    <property name="top_attach">16</property>
-                    <property name="bottom_attach">17</property>
+                    <property name="top_attach">17</property>
+                    <property name="bottom_attach">18</property>
                     <property name="x_padding">12</property>
                   </packing>
                 </child>
@@ -1940,8 +1962,8 @@
                     <property name="group">gconf/general/retain_type/days</property>
                   </object>
                   <packing>
-                    <property name="top_attach">17</property>
-                    <property name="bottom_attach">18</property>
+                    <property name="top_attach">18</property>
+                    <property name="bottom_attach">19</property>
                     <property name="x_padding">12</property>
                   </packing>
                 </child>

Modified: gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c
===================================================================
--- gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/aqbanking/gnc-ab-utils.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -46,6 +46,7 @@
 #include "import-main-matcher.h"
 #include "import-utilities.h"
 #include "qof.h"
+#include "engine-helpers.h"
 
 #ifdef AQBANKING_VERSION_5_PLUS
 # include <aqbanking/abgui.h>
@@ -501,11 +502,8 @@
     /* Currency.  We take simply the default currency of the gnucash account */
     xaccTransSetCurrency(gnc_trans, xaccAccountGetCommodity(gnc_acc));
 
-    /* Number.  We use the "customer reference", if there is one. */
-    custref = AB_Transaction_GetCustomerReference(ab_trans);
-    if (custref && *custref
-            && g_ascii_strncasecmp(custref, "NONREF", 6) != 0)
-        xaccTransSetNum(gnc_trans, custref);
+    /* Trans-Num or Split-Action set with gnc_set_num_action below per book
+     * option */
 
     /* Description */
     description = gnc_ab_description_to_gnc(ab_trans);
@@ -521,6 +519,13 @@
     xaccSplitSetParent(split, gnc_trans);
     xaccSplitSetAccount(split, gnc_acc);
 
+    /* Set the transaction number or split action field based on book option.
+     * We use the "customer reference", if there is one. */
+    custref = AB_Transaction_GetCustomerReference(ab_trans);
+    if (custref && *custref
+            && g_ascii_strncasecmp(custref, "NONREF", 6) != 0)
+        gnc_set_num_action (gnc_trans, split, custref, NULL);
+
     /* Set OFX unique transaction ID */
     fitid = AB_Transaction_GetFiId(ab_trans);
     if (fitid && *fitid)
@@ -648,7 +653,7 @@
                         _("The backend found an error during the preparation "
                           "of the job. It is not possible to execute this job. \n"
                           "\n"
-                          "Most probable the bank does not support your chosen "
+                          "Most probably the bank does not support your chosen "
                           "job or your Online Banking account does not have the permission "
                           "to execute this job. More error messages might be "
                           "visible on your console log.\n"

Modified: gnucash/trunk/src/import-export/aqbanking/gnc-file-aqb-import.c
===================================================================
--- gnucash/trunk/src/import-export/aqbanking/gnc-file-aqb-import.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/aqbanking/gnc-file-aqb-import.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -50,6 +50,7 @@
 #endif
 
 #include "dialog-ab-trans.h"
+#include "dialog-utils.h"
 #include "gnc-file.h"
 #include "gnc-file-aqb-import.h"
 #include "gnc-gwen-gui.h"
@@ -220,6 +221,11 @@
 #endif
     io = NULL;
 
+    /* Before importing the results, if this is a new book, let user specify
+     * book options, since they affect how transactions are created */
+    if (gnc_is_new_book())
+        gnc_new_book_option_display();
+
     /* Import the results */
     ieci = gnc_ab_import_context(context, AWAIT_TRANSACTIONS,
                                  execute_transactions,

Modified: gnucash/trunk/src/import-export/csv-export/csv-transactions-export.c
===================================================================
--- gnucash/trunk/src/import-export/csv-export/csv-transactions-export.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/csv-export/csv-transactions-export.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -34,6 +34,8 @@
 #include "gnc-ui-util.h"
 #include "Query.h"
 #include "Transaction.h"
+#include "engine-helpers.h"
+#include "qofbookslots.h"
 
 #include "csv-transactions-export.h"
 
@@ -137,7 +139,7 @@
         part2 = g_strconcat ( part1, currentSel, mid_sep, NULL);
         g_free(part1);
         /* Number */
-        currentSel = xaccTransGetNum(trans);
+        currentSel = gnc_get_num_action(trans, NULL);
         part1 = g_strconcat ( part2, currentSel, mid_sep, NULL);
         g_free(part2);
         /* Description */
@@ -160,7 +162,7 @@
         part1 = g_strconcat ( part2, currentSel, mid_sep, "T", mid_sep, NULL);
         g_free(part2);
         /* Action */
-        currentSel =  xaccSplitGetAction(split);
+        currentSel =  gnc_get_num_action(NULL, split);
         part2 = g_strconcat ( part1, currentSel, mid_sep, NULL);
         g_free(part1);
         /* Reconcile */
@@ -233,7 +235,7 @@
             g_free(part2);
 
             /* Action */
-            currentSel = xaccSplitGetAction(t_split);
+            currentSel = gnc_get_num_action(NULL, t_split);
             part2 = g_strconcat ( part1, currentSel, mid_sep, NULL);
             g_free(part1);
 
@@ -309,6 +311,7 @@
     FILE    *fh;
     Account *acc;
     GList   *ptr;
+    gboolean num_action = qof_book_use_split_action_for_num_field(gnc_get_current_book());
 
     ENTER("");
     DEBUG("File name is : %s", info->file_name);
@@ -338,12 +341,16 @@
 
         /* Header string */
         header = g_strconcat ( end_sep, _("Date"), mid_sep, _("Account Name"), mid_sep,
-                               _("Number"), mid_sep, _("Description"), mid_sep,
-                               _("Notes"), mid_sep, _("Memo"), mid_sep, _("Category"), mid_sep,
-                               _("Type"), mid_sep, _("Action"), mid_sep, _("Reconcile"), mid_sep,
-                               _("To With Sym"), mid_sep, _("From With Sym"), mid_sep,
-                               _("To Num."), mid_sep, _("From Num."), mid_sep,
-                               _("To Rate/Price"), mid_sep, _("From Rate/Price"), end_sep, "\n", NULL);
+                                (num_action ? _("Transaction Number") : _("Number")),
+                                mid_sep, _("Description"), mid_sep, _("Notes"),
+                                mid_sep, _("Memo"), mid_sep, _("Category"), mid_sep,
+                                _("Type"), mid_sep,
+                                (num_action ? _("Number/Action") : _("Action")),
+                                mid_sep, _("Reconcile"), mid_sep,
+                                _("To With Sym"), mid_sep, _("From With Sym"), mid_sep,
+                                _("To Num."), mid_sep, _("From Num."), mid_sep,
+                                _("To Rate/Price"), mid_sep, _("From Rate/Price"),
+                                end_sep, "\n", NULL);
         DEBUG("Header String: %s", header);
 
         /* Write header line */

Modified: gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.c
===================================================================
--- gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -72,6 +72,15 @@
             "You can also go back and verify your selections by clicking on 'Back'"
             " or 'Cancel' to Abort Import.\n");
 
+static const gchar *new_book_finish_tree_string = N_(
+            "The accounts will be imported from the file '%s' when you click 'Apply'.\n\n"
+            "You can also go back and verify your selections by clicking on 'Back'"
+            " or 'Cancel' to Abort Import.\n\n"
+            "If this is your initial import into a new file, you will first see "
+            "a dialog for setting book options, since these can affect how "
+            "imported data are converted to GnuCash transactions. If this is an "
+            "existing file, the dialog will not be shown.\n");
+
 /*************************************************************************/
 
 /**************************************************
@@ -366,7 +375,16 @@
     gchar *text;
 
     /* Set Finish page text */
-    text = g_strdup_printf (gettext (finish_tree_string), info->file_name);
+    /* Before creating accounts, if this is a new book, tell user they can
+     * specify book options, since they affect how transactions are created */
+    if (info->new_book)
+    {
+        text = g_strdup_printf (gettext (new_book_finish_tree_string), info->file_name);
+    }
+    else
+    {
+        text = g_strdup_printf (gettext (finish_tree_string), info->file_name);
+    }
     gtk_label_set_text (GTK_LABEL(info->finish_label), text);
     g_free(text);
 
@@ -385,6 +403,11 @@
     CsvImportInfo *info = user_data;
     gchar *text, *errtext, *mtext;
 
+    /* Before creating accounts, if this is a new book, let user specify
+     * book options, since they affect how transactions are created */
+    if (info->new_book)
+        info->new_book = gnc_new_book_option_display();
+
     if (!g_strcmp0(info->error, "") == 0)
     {
         text = g_strdup_printf(gettext ("Import completed but with errors!\n\nThe number of Accounts added was %u and "
@@ -608,6 +631,10 @@
 
     info = g_new0 (CsvImportInfo, 1);
 
+    /* In order to trigger a book options display on the creation of a new book,
+     * we need to detect when we are dealing with a new book. */
+    info->new_book = gnc_is_new_book();
+
     csv_import_assistant_create (info);
 
     gnc_register_gui_component (ASSISTANT_CSV_IMPORT_CM_CLASS,

Modified: gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.h
===================================================================
--- gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/csv-import/assistant-csv-account-import.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -58,6 +58,7 @@
     int           header_rows;
     int           num_new;
     int           num_updates;
+    gboolean      new_book; /**< Are we importing into a new book?; if yes, call book options */
 } CsvImportInfo;
 
 

Modified: gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.c
===================================================================
--- gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -33,6 +33,7 @@
 
 #include "gnc-ui.h"
 #include "gnc-uri-utils.h"
+#include "gnc-ui-util.h"
 #include "dialog-utils.h"
 
 #include "gnc-component-manager.h"
@@ -119,6 +120,8 @@
 
     GtkWidget            *summary_label;            /**< The summary text */
 
+    gboolean              new_book;                 /**< Are we importing into a new book?; if yes, call book options */
+
 } CsvImportTrans;
 
 
@@ -1439,6 +1442,11 @@
     /* Block going back */
     gtk_assistant_commit (GTK_ASSISTANT(info->window));
 
+    /* Before creating transactions, if this is a new book, let user specify
+     * book options, since they affect how transactions are created */
+    if (info->new_book)
+        info->new_book = gnc_new_book_option_display();
+
     /* Create transactions from the parsed data, first time with FALSE
        Subsequent times with TRUE */
     if ( info->match_parse_run == FALSE)
@@ -1829,6 +1837,10 @@
 
     info = g_new0 (CsvImportTrans, 1);
 
+    /* In order to trigger a book options display on the creation of a new book,
+     * we need to detect when we are dealing with a new book. */
+    info->new_book = gnc_is_new_book();
+
     csv_import_trans_assistant_create (info);
 
     gnc_register_gui_component (ASSISTANT_CSV_IMPORT_TRANS_CM_CLASS,

Modified: gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.glade
===================================================================
--- gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.glade	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/csv-import/assistant-csv-trans-import.glade	2012-12-22 06:00:54 UTC (rev 22681)
@@ -41,7 +41,7 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="label" translatable="yes">
-Enter file name and location for the Import...
+Select location and file name for the Import, then click 'OK'...
 </property>
             <property name="wrap">True</property>
           </object>
@@ -778,6 +778,8 @@
 
 If this is the first time importing, you will find that all lines may need to be associated. On subsequent imports, the importer will try to associate the transactions based on previous imports.
 
+If this is your initial import into a new file, you will first see a dialog for setting book options, since these can affect how imported data are converted to GnuCash transactions. If this is an existing file, the dialog will not be shown.
+
 The confidence of a correct association is displayed as a colored bar.
 
 More infomation can be displayed by using the help button.</property>

Modified: gnucash/trunk/src/import-export/csv-import/gnc-csv-model.c
===================================================================
--- gnucash/trunk/src/import-export/csv-import/gnc-csv-model.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/csv-import/gnc-csv-model.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -12,6 +12,7 @@
 #include <goffice/utils/go-glib-extras.h>
 
 #include "gnc-ui-util.h"
+#include "engine-helpers.h"
 
 #include <string.h>
 
@@ -771,14 +772,15 @@
  * @param amount The amount of the split
  */
 static void trans_add_split(Transaction* trans, Account* account, QofBook* book,
-gnc_numeric amount)
+gnc_numeric amount, const char *num)
 {
     Split* split = xaccMallocSplit(book);
     xaccSplitSetAccount(split, account);
     xaccSplitSetParent(split, trans);
     xaccSplitSetAmount(split, amount);
     xaccSplitSetValue(split, amount);
-    //xaccSplitSetAction(split, "Deposit");
+    /* set tran-num and/or split-action per book option */
+    gnc_set_num_action(trans, split, num, NULL);
 }
 
 /** Tests a TransPropertyList for having enough essential properties.
@@ -887,6 +889,7 @@
     gnc_commodity* currency = xaccAccountGetCommodity(list->account);
     gnc_numeric amount = double_to_gnc_numeric(0.0, xaccAccountGetCommoditySCU(list->account),
                          GNC_HOW_RND_ROUND_HALF_UP);
+    gchar *num = NULL;
 
     /* This flag is set to TRUE if we can use the "Deposit" or "Withdrawal" column. */
     gboolean amount_set = FALSE;
@@ -894,6 +897,7 @@
     /* The balance is 0 by default. */
     trans_line->balance_set = FALSE;
     trans_line->balance = amount;
+    trans_line->num = NULL;
 
     /* We make the line_no -1 just to mark that it hasn't been set. We
      * may get rid of line_no soon anyway, so it's not particularly
@@ -931,7 +935,14 @@
             break;
 
         case GNC_CSV_NUM:
-            xaccTransSetNum(trans_line->trans, (char*)(prop->value));
+            /* the 'num' is saved and passed to 'trans_add_split' below where 
+             * 'gnc_set_num_action' is used to set tran-num and/or split-action
+             * per book option */
+            num = g_strdup ((char*)(prop->value));
+            /* the 'num' is also saved and used in 'gnc_csv_parse_to_trans' when
+             * it calls 'trans_add_split' after deleting the splits added below
+             * when a balance is used by the user */
+            trans_line->num = g_strdup ((char*)(prop->value));
             break;
 
         case GNC_CSV_DEPOSIT: /* Add deposits to the existing amount. */
@@ -974,7 +985,9 @@
     }
 
     /* Add a split with the cumulative amount value. */
-    trans_add_split(trans_line->trans, list->account, book, amount);
+    trans_add_split(trans_line->trans, list->account, book, amount, num);
+    if (num)
+        g_free(num);
 
     return trans_line;
 }
@@ -1218,7 +1231,10 @@
                     splits = next_splits;
                 }
 
-                trans_add_split(trans_line->trans, account, gnc_account_get_book(account), amount);
+                trans_add_split(trans_line->trans, account,
+                        gnc_account_get_book(account), amount, trans_line->num);
+                if (trans_line->num)
+                    g_free(trans_line->num);
 
                 /* This new transaction needs to be added to the balance offset. */
                 balance_offset = gnc_numeric_add(balance_offset,

Modified: gnucash/trunk/src/import-export/csv-import/gnc-csv-model.h
===================================================================
--- gnucash/trunk/src/import-export/csv-import/gnc-csv-model.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/csv-import/gnc-csv-model.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -82,6 +82,7 @@
     Transaction* trans;
     gnc_numeric balance; /**< The (supposed) balance after this transaction takes place */
     gboolean balance_set; /**< TRUE if balance has been set from user data, FALSE otherwise */
+    gchar *num; /**< Saves the 'num'for use if balance has been set from user data */
 } GncCsvTransLine;
 
 /* A set of currency formats that the user sees. */

Modified: gnucash/trunk/src/import-export/import-backend.c
===================================================================
--- gnucash/trunk/src/import-export/import-backend.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/import-backend.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -41,6 +41,7 @@
 #include "Account.h"
 #include "Query.h"
 #include "gnc-engine.h"
+#include "engine-helpers.h"
 #include "gnc-ui-util.h"
 
 #define GCONF_SECTION "dialogs/import/generic_matcher"
@@ -678,7 +679,7 @@
 
         /* Check number heuristics */
         {
-            const char *new_trans_str = xaccTransGetNum(new_trans);
+            const char *new_trans_str = gnc_get_num_action(new_trans, new_trans_fsplit);
             if (new_trans_str && strlen(new_trans_str) != 0)
             {
                 long new_trans_number, split_number;
@@ -694,7 +695,7 @@
                 if (errno || endptr == new_trans_str)
                     conversion_ok = FALSE;
 
-                split_str = xaccTransGetNum (xaccSplitGetParent (split));
+                split_str = gnc_get_num_action (xaccSplitGetParent (split), split);
                 errno = 0;
                 split_number = strtol(split_str, &endptr, 10);
                 if (errno || endptr == split_str)

Modified: gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
===================================================================
--- gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -40,6 +40,7 @@
 
 #include "Account.h"
 #include "Transaction.h"
+#include "engine-helpers.h"
 #include "gnc-ofx-import.h"
 #include "gnc-file.h"
 #include "gnc-engine.h"
@@ -48,6 +49,7 @@
 #include "core-utils/gnc-gconf-utils.h"
 #include "gnome-utils/gnc-ui.h"
 #include "gnome-utils/dialog-account.h"
+#include "dialog-utils.h"
 
 #include "gnc-ofx-kvp.h"
 
@@ -379,14 +381,6 @@
 
     xaccTransSetDateEnteredSecs(transaction, current_time);
 
-    if (data.check_number_valid)
-    {
-        xaccTransSetNum(transaction, data.check_number);
-    }
-    else if (data.reference_number_valid)
-    {
-        xaccTransSetNum(transaction, data.reference_number);
-    }
     /* Put transaction name in Description, or memo if name unavailable */
     if (data.name_valid)
     {
@@ -490,6 +484,15 @@
             gnc_amount = gnc_ofx_numeric_from_double_txn(data.amount, transaction);
             xaccSplitSetBaseValue(split, gnc_amount, xaccTransGetCurrency(transaction));
 
+            /* set tran-num and/or split-action per book option */
+            if (data.check_number_valid)
+            {
+                gnc_set_num_action(transaction, split, data.check_number, NULL);
+            }
+            else if (data.reference_number_valid)
+            {
+                gnc_set_num_action(transaction, split, data.reference_number, NULL);
+            }
             /* Also put the ofx transaction's memo in the
              * split's memo field */
             if (data.memo_valid)
@@ -637,6 +640,16 @@
                     xaccSplitSetAmount(split, gnc_units);
                     xaccSplitSetValue(split, gnc_amount);
 
+                    /* set tran-num and/or split-action per book option */
+                    if (data.check_number_valid)
+                    {
+                        gnc_set_num_action(transaction, split, data.check_number, NULL);
+                    }
+                    else if (data.reference_number_valid)
+                    {
+                        gnc_set_num_action(transaction, split,
+                                                data.reference_number, NULL);
+                    }
                     if (data.security_data_ptr->memo_valid)
                     {
                         xaccSplitSetMemo(split, data.security_data_ptr->memo);
@@ -779,6 +792,10 @@
     gnc_commodity * default_commodity;
     GNCAccountType default_type = ACCT_TYPE_NONE;
     gchar * account_description;
+    /* In order to trigger a book options display on the creation of a new book,
+     * we need to detect when we are dealing with a new book. */
+    gboolean new_book = gnc_is_new_book();
+
     const gchar * account_type_name = _("Unknown OFX account");
 
     if (data.account_id_valid)
@@ -834,6 +851,15 @@
             }
         }
 
+        /* If the OFX importer was started in Gnucash in a 'new_book' situation,
+         * as described above, the first time the 'ofx_proc_account_cb' function
+         * is called a book is created. (This happens after the 'new_book' flag
+         * is set in 'gnc_get_current_commodities', called above.) So, before
+         * calling 'gnc_import_select_account', allow the user to set book
+         * options. */
+        if (new_book)
+            new_book = gnc_new_book_option_display();
+
         gnc_utf8_strip_invalid(data.account_name);
         account_description = g_strdup_printf( /* This string is a default account
 					      name. It MUST NOT contain the

Modified: gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c
===================================================================
--- gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/qif-import/assistant-qif-import.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -132,8 +132,10 @@
     GtkWidget * memo_view_count;
     GtkWidget * memo_view_btn;
 
-    /* Widgets on the currency page. */
+    /* Widgets on the currency & book options page. */
     GtkWidget * currency_picker;
+    GtkWidget * book_option_label;
+    GtkWidget * book_option_message;
 
     /* Widgets on the commodity page. */
     gint        num_new_pages;
@@ -158,6 +160,7 @@
     gboolean  busy;
     gboolean  load_stop;
     gboolean  acct_tree_found;
+    gboolean  new_book;
 
     SCM       imported_files;
     SCM       selected_file;
@@ -1461,7 +1464,7 @@
     /* Get the saved state of mappings from Quicken accounts and
      * categories to GnuCash accounts. */
     load_map_prefs = scm_c_eval_string("qif-import:load-map-prefs");
-    mapping_info = scm_call_0(load_map_prefs);
+    mapping_info = scm_call_0(load_map_prefs); /* <- gets/creates session/book */
     wind->gnc_acct_info         = scm_list_ref(mapping_info, scm_from_int (0));
     wind->acct_map_info         = scm_list_ref(mapping_info, scm_from_int (1));
     wind->cat_map_info          = scm_list_ref(mapping_info, scm_from_int (2));
@@ -2548,7 +2551,26 @@
 {
     gint num = gtk_assistant_get_current_page (assistant);
     GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
+    QIFImportWindow  *wind = user_data;
 
+    g_return_if_fail(wind);
+
+    /* Only display Book Option data if new book */
+    if (wind->new_book)
+    {
+        gtk_assistant_set_page_title (assistant, page,
+            _("Choose the QIF file currency and select Book Options"));
+        gtk_widget_show (wind->book_option_label);
+        gtk_widget_show (wind->book_option_message);
+    }
+    else
+    {
+        gtk_assistant_set_page_title (assistant, page,
+            _("Choose the QIF file currency"));
+        gtk_widget_hide (wind->book_option_label);
+        gtk_widget_hide (wind->book_option_message);
+    }
+
     /* Enable the Assistant Buttons */
     gtk_assistant_set_page_complete (assistant, page, TRUE);
 }
@@ -3036,6 +3058,11 @@
 
     /* Enable the assistant buttons */
     gtk_assistant_set_page_complete (assistant, page, FALSE);
+
+    /* Before creating transactions, if this is a new book, let user specify
+     * book options, since they affect how transactions are created */
+    if (wind->new_book)
+        wind->new_book = gnc_new_book_option_display();
 }
 
 
@@ -3334,7 +3361,7 @@
         /* Current page is Memo Match page */
         gnc_ui_qif_import_memo_match_prepare (assistant, user_data);
     }
-    else if (!g_strcmp0 (pagename, "currency_page"))
+    else if (!g_strcmp0 (pagename, "currency_book_option_page"))
     {
         /* Current page is Currency page */
         gnc_ui_qif_import_currency_prepare (assistant, user_data);
@@ -3409,6 +3436,8 @@
     wind->selected_file_view = GTK_WIDGET(gtk_builder_get_object (builder, "selected_file_view"));
     wind->unload_file_btn    = GTK_WIDGET(gtk_builder_get_object (builder, "unload_file_button"));
     wind->currency_picker    = GTK_WIDGET(gtk_builder_get_object (builder, "currency_comboboxentry"));
+    wind->book_option_label  = GTK_WIDGET(gtk_builder_get_object (builder, "book_option_label"));
+    wind->book_option_message = GTK_WIDGET(gtk_builder_get_object (builder, "book_option_message_label"));
     wind->acct_view          = GTK_WIDGET(gtk_builder_get_object (builder, "account_page_view"));
     wind->acct_view_count    = GTK_WIDGET(gtk_builder_get_object (builder, "account_page_count"));
     wind->acct_view_btn      = GTK_WIDGET(gtk_builder_get_object (builder, "account_page_change"));
@@ -3594,11 +3623,16 @@
     qif_win->new_namespaces       = NULL;
     qif_win->selected_transaction = 0;
     qif_win->busy                 = FALSE;
+    /* In order to include a book options display on the creation of a new book,
+     * we need to detect when we are dealing with a new book. */
+    qif_win->new_book = gnc_is_new_book();
 
     /* Get all user preferences related to QIF importing. */
     get_preferences(qif_win);
 
-    /* Set up the Scheme side of things. */
+    /* Set up the Scheme side of things. Note that if a session/book did not
+     * exist prior to this function, it is created within scheme function
+     * "qif-import:load-map-prefs", so we need to have set the flag previously */
     initialize_scheme(qif_win);
 
     /* Get all interesting builder-defined widgets. */

Modified: gnucash/trunk/src/import-export/qif-import/assistant-qif-import.glade
===================================================================
--- gnucash/trunk/src/import-export/qif-import/assistant-qif-import.glade	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/qif-import/assistant-qif-import.glade	2012-12-22 06:00:54 UTC (rev 22681)
@@ -38,7 +38,7 @@
             <property name="can_focus">False</property>
             <property name="label" translatable="yes">Please select a file to load. When you click "Forward", the file will be loaded and analyzed. You may need to answer some questions about the account(s) in the file.
 
-You will have the opportunity to load as many files as you wish, so don't  worry if your data is in multiple files. 
+You will have the opportunity to load as many files as you wish, so don't worry if your data is in multiple files. 
 </property>
             <property name="wrap">True</property>
           </object>
@@ -322,7 +322,7 @@
             <property name="can_focus">False</property>
             <property name="label" translatable="yes">The QIF file that you just loaded appears to contain transactions for just one account, but the file does not specify a name for that account.  
 
-Please enter a name for the account. If the file was exported from another accounting program, you should use the same account name that was used  in that program.
+Please enter a name for the account. If the file was exported from another accounting program, you should use the same account name that was used in that program.
 </property>
             <property name="wrap">True</property>
           </object>
@@ -892,7 +892,7 @@
       </packing>
     </child>
     <child>
-      <object class="GtkVBox" id="currency_page">
+      <object class="GtkVBox" id="currency_book_option_page">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="border_width">12</property>
@@ -943,9 +943,35 @@
             <property name="position">2</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkLabel" id="book_option_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes"><b>Book Options</b></property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="book_option_message_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Since you are creating a new file, you will next see a dialog for setting book options. These can affect how GnuCash imports transactions. If you come back to this page without cancelling and starting over, the dialog for setting book options will not be shown a second time when you go forward. You can access it directly from the menu via File->Properties.</property>
+            <property name="wrap">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">4</property>
+          </packing>
+        </child>
       </object>
       <packing>
-        <property name="title" translatable="yes">Enter the QIF file currency</property>
+        <property name="title" translatable="yes">Choose the QIF file currency and select Book Options</property>
       </packing>
     </child>
     <child>

Modified: gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm
===================================================================
--- gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/import-export/qif-import/qif-to-gnc.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -478,7 +478,9 @@
     (if qif-payee
         (xaccTransSetDescription gnc-xtn qif-payee))
     (if qif-number
-        (xaccTransSetNum gnc-xtn qif-number))
+        ;; Use function that will set either tran-num or split-action per
+        ;; book option.
+        (gnc-set-num-action gnc-xtn gnc-near-split qif-number #f))
 
     ;; Look for the transaction memo (QIF "M" line). When a default split
     ;; exists, the memo can be found there. Otherwise, it will be in the

Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/libqof/qof/qofbook.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -640,6 +640,30 @@
     return FALSE;
 }
 
+/* Returns TRUE if this book uses split action field as the 'Num' field, FALSE
+ * if it uses transaction number field */
+gboolean
+qof_book_use_split_action_for_num_field (const QofBook *book)
+{
+    const char *opt;
+    kvp_value *kvp_val;
+
+    g_assert(book);
+    kvp_val = kvp_frame_get_slot_path (qof_book_get_slots (book),
+                                       KVP_OPTION_PATH,
+                                       OPTION_SECTION_ACCOUNTS,
+                                       OPTION_NAME_NUM_FIELD_SOURCE,
+                                       NULL);
+    if (kvp_val == NULL)
+        return FALSE;
+
+    opt = kvp_value_get_string (kvp_val);
+
+    if (opt && opt[0] == 't' && opt[1] == 0)
+        return TRUE;
+    return FALSE;
+}
+
 gboolean qof_book_uses_autoreadonly (const QofBook *book)
 {
     g_assert(book);

Modified: gnucash/trunk/src/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/libqof/qof/qofbook.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -267,6 +267,10 @@
  * g_date_free() the object afterwards. */
 GDate* qof_book_get_autoreadonly_gdate (const QofBook *book);
 
+/** Returns TRUE if this book uses split action field as the 'Num' field, FALSE
+ *  if it uses transaction number field */
+gboolean qof_book_use_split_action_for_num_field (const QofBook *book);
+
 /** Is the book shutting down? */
 gboolean qof_book_shutting_down (const QofBook *book);
 

Modified: gnucash/trunk/src/libqof/qof/qofbookslots.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbookslots.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/libqof/qof/qofbookslots.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -65,6 +65,7 @@
 #define OPTION_SECTION_ACCOUNTS        N_("Accounts")
 #define OPTION_NAME_TRADING_ACCOUNTS   N_("Use Trading Accounts")
 #define OPTION_NAME_AUTO_READONLY_DAYS N_("Day Threshold for Read-Only Transactions (red line)")
+#define OPTION_NAME_NUM_FIELD_SOURCE   N_("Use Split Action Field for Number")
 
 #define OPTION_SECTION_BUDGETING       N_("Budgeting")
 #define OPTION_NAME_DEFAULT_BUDGET     N_("Default Budget")
@@ -76,6 +77,7 @@
  * OPTION-SECTION-ACCOUNTS
  * OPTION-NAME-TRADING-ACCOUNTS
  * OPTION-NAME-AUTO-READONLY-DAYS
+ * OPTION-NAME_NUM-FIELD-SOURCE
  * OPTION-SECTION-BUDGETING
  * OPTION-NAME-DEFAULT-BUDGET
  */

Modified: gnucash/trunk/src/libqof/qof/test/test-qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/test/test-qofbook.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/libqof/qof/test/test-qofbook.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -420,6 +420,32 @@
 }
 
 static void
+test_book_use_split_action_for_num_field( Fixture *fixture, gconstpointer pData )
+{
+    const char *slot_path;
+
+    /* create correct slot path */
+    slot_path = (const char *) g_strconcat( KVP_OPTION_PATH, "/",
+            OPTION_SECTION_ACCOUNTS, "/", OPTION_NAME_NUM_FIELD_SOURCE, NULL );
+    g_assert( slot_path != NULL );
+
+    g_test_message( "Testing default: No selection has been specified" );
+    g_assert( qof_book_use_split_action_for_num_field( fixture-> book ) == FALSE );
+
+    g_test_message( "Testing with incorrect slot path and correct value - t" );
+    qof_book_set_string_option( fixture->book, OPTION_NAME_NUM_FIELD_SOURCE, "t" );
+    g_assert( qof_book_use_split_action_for_num_field( fixture-> book ) == FALSE );
+
+    g_test_message( "Testing with existing use split action for num set to true - t" );
+    qof_book_set_string_option( fixture->book, slot_path, "t" );
+    g_assert( qof_book_use_split_action_for_num_field( fixture-> book ) == TRUE );
+
+    g_test_message( "Testing with existing use split action for num and incorrect value - tt" );
+    qof_book_set_string_option( fixture->book, slot_path, "tt" );
+    g_assert( qof_book_use_split_action_for_num_field( fixture-> book ) == FALSE );
+}
+
+static void
 test_book_mark_session_dirty( Fixture *fixture, gconstpointer pData )
 {
     QofBook *_empty = NULL;
@@ -729,6 +755,7 @@
     GNC_TEST_ADD( suitename, "kvp changed", Fixture, NULL, setup, test_book_kvp_changed, teardown );
     GNC_TEST_ADD( suitename, "use trading accounts", Fixture, NULL, setup, test_book_use_trading_accounts, teardown );
     GNC_TEST_ADD( suitename, "get autofreeze days", Fixture, NULL, setup, test_book_get_num_days_autofreeze, teardown );
+    GNC_TEST_ADD( suitename, "use split action for num field", Fixture, NULL, setup, test_book_use_split_action_for_num_field, teardown );
     GNC_TEST_ADD( suitename, "mark session dirty", Fixture, NULL, setup, test_book_mark_session_dirty, teardown );
     GNC_TEST_ADD( suitename, "session dirty time", Fixture, NULL, setup, test_book_get_session_dirty_time, teardown );
     GNC_TEST_ADD( suitename, "set dirty callback", Fixture, NULL, setup, test_book_set_dirty_cb, teardown );

Modified: gnucash/trunk/src/register/ledger-core/Makefile.am
===================================================================
--- gnucash/trunk/src/register/ledger-core/Makefile.am	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/Makefile.am	2012-12-22 06:00:54 UTC (rev 22681)
@@ -53,7 +53,8 @@
   ${GUILE_INCS} \
   ${GCONF_CFLAGS} \
   ${GTK_CFLAGS} \
-  ${GLIB_CFLAGS}
+  ${GLIB_CFLAGS} \
+  ${GNOME_CFLAGS}
 
 
 AM_CPPFLAGS += -DG_LOG_DOMAIN=\"gnc.register.ledger\"

Modified: gnucash/trunk/src/register/ledger-core/split-register-control.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-control.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register-control.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -38,6 +38,7 @@
 #include "split-register-model-save.h"
 #include "split-register-p.h"
 #include "table-allgui.h"
+#include "engine-helpers.h"
 
 
 /* This static indicates the debugging module that this .o belongs to. */
@@ -967,7 +968,7 @@
         {
             cell = gnc_table_layout_get_cell (reg->table->layout, ACTN_CELL);
             gnc_combo_cell_set_value ((ComboCell *) cell,
-                                      xaccSplitGetAction (auto_split));
+                                      gnc_get_num_action (NULL, auto_split));
         }
 
         /* auto-complete the account name */
@@ -1225,7 +1226,7 @@
         gnc_xfer_dialog_set_num(xfer, gnc_basic_cell_get_value(cell));
     else
     {
-        const char *str = xaccTransGetNum(txn);
+        const char *str = gnc_get_num_action (txn, split);
         gnc_xfer_dialog_set_num(xfer, str ? str : "");
     }
 

Modified: gnucash/trunk/src/register/ledger-core/split-register-layout.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-layout.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register-layout.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -127,6 +127,15 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_LEDGER_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 1);
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SINGLE_JOURNAL);
 
         gnc_table_layout_set_cell (layout, curs, DATE_CELL,  0, 0);
@@ -147,6 +156,15 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 1);
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SPLIT);
 
         gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
@@ -195,6 +213,14 @@
         gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_LEDGER_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 3);
+        gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SINGLE_JOURNAL);
 
         gnc_table_layout_set_cell (layout, curs, DATE_CELL,  0, 0);
@@ -216,6 +242,14 @@
         gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 3);
+        gnc_table_layout_set_cell (layout, curs, MEMO_CELL, 1, 4);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SPLIT);
 
         gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 3);
@@ -236,7 +270,7 @@
                                             CURSOR_SINGLE_LEDGER);
 
         gnc_table_layout_set_cell (layout, curs, DATE_CELL,  0, 0);
-        gnc_table_layout_set_cell (layout, curs, NUM_CELL,   0, 1);
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,   0, 1);
         gnc_table_layout_set_cell (layout, curs, DESC_CELL,  0, 2);
         gnc_table_layout_set_cell (layout, curs, MXFRM_CELL, 0, 3);
         gnc_table_layout_set_cell (layout, curs, RECN_CELL,  0, 4);
@@ -265,10 +299,19 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_LEDGER_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, ACTN_CELL,  1, 1);
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SINGLE_JOURNAL);
 
         gnc_table_layout_set_cell (layout, curs, DATE_CELL,  0, 0);
-        gnc_table_layout_set_cell (layout, curs, NUM_CELL,   0, 1);
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,   0, 1);
         gnc_table_layout_set_cell (layout, curs, DESC_CELL,  0, 2);
         gnc_table_layout_set_cell (layout, curs, TDEBT_CELL, 0, 5);
         gnc_table_layout_set_cell (layout, curs, TCRED_CELL, 0, 6);
@@ -290,6 +333,14 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SPLIT);
 
         gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
@@ -341,6 +392,15 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_LEDGER_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 1);
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SINGLE_JOURNAL);
 
         gnc_table_layout_set_cell (layout, curs, DATE_CELL,  0,  0);
@@ -361,6 +421,15 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 1);
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SPLIT);
 
         gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
@@ -402,6 +471,15 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_LEDGER_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 1);
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SINGLE_JOURNAL);
 
         gnc_table_layout_set_cell (layout, curs, DATE_CELL,  0, 0);
@@ -421,6 +499,15 @@
         gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
 
         curs = gnc_table_layout_get_cursor (layout,
+                                            CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
+
+        copy_cursor_row (layout, curs, curs_last, 0);
+
+        gnc_table_layout_set_cell (layout, curs, TNUM_CELL,  1, 1);
+        gnc_table_layout_set_cell (layout, curs, NOTES_CELL, 1, 2);
+        gnc_table_layout_set_cell (layout, curs, VNOTES_CELL, 1, 3);
+
+        curs = gnc_table_layout_get_cursor (layout,
                                             CURSOR_SPLIT);
 
         gnc_table_layout_set_cell (layout, curs, ACTN_CELL, 0, 1);
@@ -504,6 +591,9 @@
     cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_LEDGER);
     gnc_table_layout_add_cursor (layout, cursor);
 
+    cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_LEDGER_NUM_ACTN);
+    gnc_table_layout_add_cursor (layout, cursor);
+
     /* cursors used for journal mode */
     cursor = gnc_cellblock_new (1, num_cols, CURSOR_SINGLE_JOURNAL);
     gnc_table_layout_add_cursor (layout, cursor);
@@ -511,6 +601,9 @@
     cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_JOURNAL);
     gnc_table_layout_add_cursor (layout, cursor);
 
+    cursor = gnc_cellblock_new (2, num_cols, CURSOR_DOUBLE_JOURNAL_NUM_ACTN);
+    gnc_table_layout_add_cursor (layout, cursor);
+
     cursor = gnc_cellblock_new (1, num_cols, CURSOR_SPLIT);
     gnc_table_layout_add_cursor (layout, cursor);
 }
@@ -549,6 +642,14 @@
                            FALSE);
 
     gnc_register_add_cell (layout,
+                           TNUM_CELL,
+                           BASIC_CELL_TYPE_NAME,
+                           N_("sample:99999") + 7,
+                           CELL_ALIGN_LEFT,
+                           FALSE,
+                           FALSE);
+
+    gnc_register_add_cell (layout,
                            DESC_CELL,
                            QUICKFILL_CELL_TYPE_NAME,
                            N_("sample:Description of a transaction") + 7,

Modified: gnucash/trunk/src/register/ledger-core/split-register-load.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-load.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register-load.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -37,6 +37,7 @@
 #include "recncell.h"
 #include "split-register.h"
 #include "split-register-p.h"
+#include "engine-helpers.h"
 
 
 /* This static indicates the debugging module that this .o belongs to. */
@@ -211,7 +212,7 @@
 }
 
 static void add_quickfill_completions(TableLayout *layout, Transaction *trans,
-                                      gboolean has_last_num)
+                                      Split *split, gboolean has_last_num)
 {
     Split *s;
     int i = 0;
@@ -227,7 +228,7 @@
     if (!has_last_num)
         gnc_num_cell_set_last_num(
             (NumCell *) gnc_table_layout_get_cell(layout, NUM_CELL),
-            xaccTransGetNum(trans));
+            gnc_get_num_action(trans, split));
 
     while ((s = xaccTransGetSplit(trans, i)) != NULL)
     {
@@ -565,7 +566,7 @@
         /* If this is the first load of the register,
          * fill up the quickfill cells. */
         if (info->first_pass)
-            add_quickfill_completions(reg->table->layout, trans, has_last_num);
+            add_quickfill_completions(reg->table->layout, trans, split, has_last_num);
 
         if (trans == find_trans)
             new_trans_row = vcell_loc.virt_row;

Modified: gnucash/trunk/src/register/ledger-core/split-register-model-save.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-model-save.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register-model-save.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -28,6 +28,7 @@
 #include "SchedXaction.h"
 #include "datecell.h"
 #include "gnc-engine.h"
+#include "engine-helpers.h"
 #include "numcell.h"
 #include "pricecell.h"
 #include "recncell.h"
@@ -126,21 +127,41 @@
 
     DEBUG ("NUM: %s\n", value ? value : "(null)");
 
-    xaccTransSetNum (sd->trans, value);
+    /* set per book option */
+    gnc_set_num_action (sd->trans, sd->split, value, NULL);
 
     if (gnc_num_cell_set_last_num ((NumCell *) cell, value))
     {
         SRInfo *info = gnc_split_register_get_info (reg);
         Split *blank_split = xaccSplitLookup (&info->blank_split_guid,
-                                              gnc_get_current_book ());
+                                                  gnc_get_current_book ());
         Transaction *blank_trans = xaccSplitGetParent (blank_split);
 
         if (sd->trans == blank_trans)
-            gnc_split_register_set_last_num (reg, gnc_basic_cell_get_value (cell));
+           gnc_split_register_set_last_num (reg, gnc_basic_cell_get_value (cell));
     }
 }
 
 static void
+gnc_split_register_save_tnum_cell (BasicCell * cell,
+                                  gpointer save_data,
+                                  gpointer user_data)
+{
+    SRSaveData *sd = save_data;
+    SplitRegister *reg = user_data;
+    const char *value;
+
+    g_return_if_fail (gnc_basic_cell_has_name (cell, TNUM_CELL));
+
+    value = gnc_basic_cell_get_value (cell);
+
+    DEBUG ("TNUM: %s\n", value ? value : "(null)");
+
+    /* set tran-num using utility function */
+    gnc_set_num_action (sd->trans, NULL, value, NULL);
+}
+
+static void
 gnc_split_register_save_desc_cell (BasicCell * cell,
                                    gpointer save_data,
                                    gpointer user_data)
@@ -203,7 +224,9 @@
 
     DEBUG ("ACTN: %s", value ? value : "(null)");
 
-    xaccSplitSetAction (sd->split, value);
+    /* Set split-action with gnc_set_num_action which is the same as
+     * xaccSplitSetAction with these arguments */
+    gnc_set_num_action (NULL, sd->split, NULL, value);
 }
 
 static void
@@ -795,6 +818,10 @@
                                       NUM_CELL);
 
     gnc_table_model_set_save_handler (model,
+                                      gnc_split_register_save_tnum_cell,
+                                      TNUM_CELL);
+
+    gnc_table_model_set_save_handler (model,
                                       gnc_split_register_save_desc_cell,
                                       DESC_CELL);
 

Modified: gnucash/trunk/src/register/ledger-core/split-register-model.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-model.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register-model.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -36,6 +36,7 @@
 #include "split-register-model.h"
 #include "split-register-model-save.h"
 #include "split-register-p.h"
+#include "engine-helpers.h"
 
 
 static SplitRegisterColors reg_colors =
@@ -218,6 +219,29 @@
 }
 
 static const char *
+gnc_split_register_get_tran_num_label (VirtualLocation virt_loc,
+                                  gpointer user_data)
+{
+    SplitRegister *reg = user_data;
+
+    switch (reg->type)
+    {
+    case RECEIVABLE_REGISTER:
+    case PAYABLE_REGISTER:
+        return _("T-Ref");
+    case GENERAL_LEDGER:
+    case INCOME_LEDGER:
+    case SEARCH_LEDGER:
+    {
+        if (reg->use_tran_num_for_num_field)
+            return _("Num");
+    }
+    default:
+        return _("T-Num");
+    }
+}
+
+static const char *
 gnc_split_register_get_desc_label (VirtualLocation virt_loc,
                                    gpointer user_data)
 {
@@ -567,7 +591,9 @@
     }
 
     if (g_strcmp0 (cursor_name, CURSOR_DOUBLE_JOURNAL) == 0 ||
-            g_strcmp0 (cursor_name, CURSOR_DOUBLE_LEDGER) == 0)
+            g_strcmp0 (cursor_name, CURSOR_DOUBLE_JOURNAL_NUM_ACTN) == 0 ||
+            g_strcmp0 (cursor_name, CURSOR_DOUBLE_LEDGER) == 0 ||
+            g_strcmp0 (cursor_name, CURSOR_DOUBLE_LEDGER_NUM_ACTN) == 0)
     {
         double_alternate_virt = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER,
                                 "alternate_color_by_transaction",
@@ -650,7 +676,9 @@
     }
 
     if (g_strcmp0 (cursor_name, CURSOR_DOUBLE_JOURNAL) == 0 ||
-            g_strcmp0 (cursor_name, CURSOR_DOUBLE_LEDGER) == 0)
+            g_strcmp0 (cursor_name, CURSOR_DOUBLE_JOURNAL_NUM_ACTN) == 0 ||
+            g_strcmp0 (cursor_name, CURSOR_DOUBLE_LEDGER) == 0 ||
+            g_strcmp0 (cursor_name, CURSOR_DOUBLE_LEDGER_NUM_ACTN) == 0)
     {
         double_alternate_virt = gnc_gconf_get_bool(GCONF_GENERAL_REGISTER,
                                 "alternate_color_by_transaction",
@@ -921,9 +949,25 @@
     split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
     trans = xaccSplitGetParent (split);
 
-    return xaccTransGetNum (trans);
+    return gnc_get_num_action (trans, split); 
 }
 
+static const char *
+gnc_split_register_get_tran_num_entry (VirtualLocation virt_loc,
+                                  gboolean translate,
+                                  gboolean *conditionally_changed,
+                                  gpointer user_data)
+{
+    SplitRegister *reg = user_data;
+    Transaction *trans;
+    Split *split;
+
+    split = gnc_split_register_get_split (reg, virt_loc.vcell_loc);
+    trans = xaccSplitGetParent (split);
+
+    return gnc_get_num_action (trans, NULL);
+}
+
 static char *
 gnc_split_register_get_num_help (VirtualLocation virt_loc,
                                  gpointer user_data)
@@ -937,17 +981,49 @@
         {
         case RECEIVABLE_REGISTER:
         case PAYABLE_REGISTER:
-            help = _("Enter the transaction reference, "
-                     "such as the invoice or check number");
+            help = reg->use_tran_num_for_num_field ?
+                    _("Enter a reference, such as an invoice or check number "
+                        ", common to all entry lines (splits)") :
+                    _("Enter a reference, such as an invoice or check number "
+                        ", unique to each entry line (split)");
             break;
         default:
-            help = _("Enter the transaction number, such as the check number");
+            help = reg->use_tran_num_for_num_field ?
+                    _("Enter a reference, such as a check number "
+                        ", common to all entry lines (splits)") :
+                    _("Enter a reference, such as a check number "
+                        ", unique to each entry line (split)");
             break;
         }
 
     return g_strdup (help);
 }
 
+static char *
+gnc_split_register_get_tran_num_help (VirtualLocation virt_loc,
+                                 gpointer user_data)
+{
+    SplitRegister *reg = user_data;
+    const char *help;
+
+    help = gnc_table_get_entry (reg->table, virt_loc);
+    if (!help || *help == '\0')
+        switch (reg->type)
+        {
+        case RECEIVABLE_REGISTER:
+        case PAYABLE_REGISTER:
+            help = _("Enter a transaction reference, such as an invoice "
+                    "or check number, common to all entry lines (splits)");
+            break;
+        default:
+            help = _("Enter a transaction reference, "
+                    "that will be common to all entry lines (splits)");
+            break;
+        }
+
+    return g_strdup (help);
+}
+
 static const char *
 gnc_split_register_get_desc_entry (VirtualLocation virt_loc,
                                    gboolean translate,
@@ -1126,7 +1202,7 @@
     SplitRegister *reg = user_data;
     Split *split = gnc_split_register_get_split(reg, virt_loc.vcell_loc);
 
-    return xaccSplitGetAction (split);
+    return gnc_get_num_action (NULL, split);
 }
 
 static char *
@@ -1138,7 +1214,9 @@
 
     help = gnc_table_get_entry (reg->table, virt_loc);
     if (!help || *help == '\0')
-        help = _("Enter the type of transaction, or choose one from the list");
+        help = reg->use_tran_num_for_num_field ?
+        _("Enter an action type, or choose one from the list") :
+        _("Enter a reference number, such as the next check number, or choose an action type from the list");
 
     return g_strdup (help);
 }
@@ -2230,6 +2308,10 @@
                                        NUM_CELL);
 
     gnc_table_model_set_entry_handler (model,
+                                       gnc_split_register_get_tran_num_entry,
+                                       TNUM_CELL);
+
+    gnc_table_model_set_entry_handler (model,
                                        gnc_split_register_get_desc_entry,
                                        DESC_CELL);
 
@@ -2323,6 +2405,10 @@
                                        NUM_CELL);
 
     gnc_table_model_set_label_handler (model,
+                                       gnc_split_register_get_tran_num_label,
+                                       TNUM_CELL);
+
+    gnc_table_model_set_label_handler (model,
                                        gnc_split_register_get_desc_label,
                                        DESC_CELL);
 
@@ -2419,6 +2505,10 @@
                                       NUM_CELL);
 
     gnc_table_model_set_help_handler (model,
+                                      gnc_split_register_get_tran_num_help,
+                                      TNUM_CELL);
+
+    gnc_table_model_set_help_handler (model,
                                       gnc_split_register_get_desc_help,
                                       DESC_CELL);
 
@@ -2481,6 +2571,9 @@
         model, gnc_split_register_get_standard_io_flags, NUM_CELL);
 
     gnc_table_model_set_io_flags_handler(
+        model, gnc_split_register_get_standard_io_flags, TNUM_CELL);
+
+    gnc_table_model_set_io_flags_handler(
         model, gnc_split_register_get_standard_io_flags, DESC_CELL);
 
     gnc_table_model_set_io_flags_handler(

Modified: gnucash/trunk/src/register/ledger-core/split-register-util.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register-util.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register-util.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -392,12 +392,16 @@
     case REG_STYLE_LEDGER:
     case REG_STYLE_AUTO_LEDGER:
         cursor_name = reg->use_double_line ?
-                      CURSOR_DOUBLE_LEDGER : CURSOR_SINGLE_LEDGER;
+                      (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_LEDGER
+                                                : CURSOR_DOUBLE_LEDGER_NUM_ACTN)
+                        : CURSOR_SINGLE_LEDGER;
         break;
 
     case REG_STYLE_JOURNAL:
         cursor_name = reg->use_double_line ?
-                      CURSOR_DOUBLE_JOURNAL : CURSOR_SINGLE_JOURNAL;
+                      (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_JOURNAL
+                                                : CURSOR_DOUBLE_JOURNAL_NUM_ACTN)
+                        : CURSOR_SINGLE_JOURNAL;
         break;
     }
 
@@ -422,7 +426,9 @@
         if (!info->trans_expanded)
         {
             cursor_name = reg->use_double_line ?
-                          CURSOR_DOUBLE_LEDGER : CURSOR_SINGLE_LEDGER;
+                      (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_LEDGER
+                                                : CURSOR_DOUBLE_LEDGER_NUM_ACTN)
+                        : CURSOR_SINGLE_LEDGER;
             break;
         }
 
@@ -430,7 +436,9 @@
     case REG_STYLE_AUTO_LEDGER:
     case REG_STYLE_JOURNAL:
         cursor_name = reg->use_double_line ?
-                      CURSOR_DOUBLE_JOURNAL : CURSOR_SINGLE_JOURNAL;
+                      (reg->use_tran_num_for_num_field ? CURSOR_DOUBLE_JOURNAL
+                                                : CURSOR_DOUBLE_JOURNAL_NUM_ACTN)
+                        : CURSOR_SINGLE_JOURNAL;
         break;
     }
 
@@ -509,8 +517,10 @@
 
     if (strcmp (cursor_name, CURSOR_SINGLE_LEDGER) == 0  ||
             strcmp (cursor_name, CURSOR_DOUBLE_LEDGER) == 0  ||
+            strcmp (cursor_name, CURSOR_DOUBLE_LEDGER_NUM_ACTN) == 0  ||
             strcmp (cursor_name, CURSOR_SINGLE_JOURNAL) == 0 ||
-            strcmp (cursor_name, CURSOR_DOUBLE_JOURNAL) == 0)
+            strcmp (cursor_name, CURSOR_DOUBLE_JOURNAL) == 0 ||
+            strcmp (cursor_name, CURSOR_DOUBLE_JOURNAL_NUM_ACTN) == 0)
         return CURSOR_CLASS_TRANS;
 
     if (strcmp (cursor_name, CURSOR_SPLIT) == 0)

Modified: gnucash/trunk/src/register/ledger-core/split-register.c
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register.c	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register.c	2012-12-22 06:00:54 UTC (rev 22681)
@@ -33,6 +33,7 @@
 #include "datecell.h"
 #include "dialog-utils.h"
 #include "gnc-component-manager.h"
+#include "gnome/gnc-plugin-page-register.h"
 #include "gnc-gconf-utils.h"
 #include "split-register-p.h"
 #include "gnc-ledger-display.h"
@@ -50,6 +51,8 @@
 #include "table-allgui.h"
 #include "dialog-account.h"
 #include "dialog-dup-trans.h"
+#include "engine-helpers.h"
+#include "qofbookslots.h"
 
 
 /** static variables ******************************************************/
@@ -486,21 +489,92 @@
     if (cursor_class == CURSOR_CLASS_SPLIT)
     {
         Split *new_split;
+        char *out_num;
+        gboolean new_act_num = FALSE;
 
         /* We are on a split in an expanded transaction.
-         * Just copy the split and add it to the transaction. */
+         * Just copy the split and add it to the transaction.
+         * However, if the split-action field is being used as the register 
+         * number, and the action field is a number, request a new value or
+         * cancel. Need to get next number and update account last num from
+         * split account not register account, which may be the same or not */
 
+        if (!reg->use_tran_num_for_num_field
+            && gnc_strisnum (gnc_get_num_action (NULL, split)))
+        {
+            Account *account = xaccSplitGetAccount (split);
+            const char *in_num = NULL;
+            const char* title = _("New Split Information");
+            time64 date = info->last_date_entered;
+
+            if (account)
+                in_num = xaccAccountGetLastNum (account);
+            else
+                in_num = gnc_get_num_action (NULL, split);
+            if (!gnc_dup_trans_dialog (gnc_split_register_get_parent (reg),
+                                   title, FALSE, &date, in_num, &out_num, NULL, NULL))
+            {
+                gnc_resume_gui_refresh ();
+                LEAVE("dup cancelled");
+                return NULL;
+            }
+            new_act_num = TRUE;
+        }
+
         new_split = xaccMallocSplit (gnc_get_current_book ());
 
         xaccTransBeginEdit (trans);
         xaccSplitSetParent (new_split, trans);
         gnc_copy_split_onto_split (split, new_split, FALSE);
+        if (new_act_num) /* if new number supplied by user dialog */
+            gnc_set_num_action (NULL, new_split, out_num, NULL);
         xaccTransCommitEdit (trans);
 
+        if (new_act_num && gnc_strisnum (out_num))
+        {
+            Account *account = xaccSplitGetAccount (new_split);
+
+            /* If current register is for account, set last num */
+            if (xaccAccountEqual(account,
+                                    gnc_split_register_get_default_account(reg),
+                                    TRUE))
+            {
+                NumCell *num_cell;
+                num_cell = (NumCell *) gnc_table_layout_get_cell (reg->table->layout,
+                       NUM_CELL);
+                if (gnc_num_cell_set_last_num (num_cell, out_num))
+                    gnc_split_register_set_last_num (reg, out_num);
+            }
+            else
+            {
+                SplitRegister *oth_reg = gnc_find_register_by_account(account);
+
+                /* If another register is open for split acct, use that register
+                 * to set last number */
+                if (oth_reg)
+                {
+                    NumCell *num_cell;
+
+                    num_cell = (NumCell *) gnc_table_layout_get_cell
+                                                        (oth_reg->table->layout,
+                                                            NUM_CELL);
+                    if (gnc_num_cell_set_last_num (num_cell, out_num))
+                        gnc_split_register_set_last_num (oth_reg, out_num);
+                }
+                /* else just update acct */
+                else
+                {
+                    xaccAccountSetLastNum (account, out_num);
+                }
+            }
+        }
+
         return_split = new_split;
 
         info->cursor_hint_split = new_split;
         info->cursor_hint_cursor_class = CURSOR_CLASS_SPLIT;
+        if (new_act_num)
+            g_free (out_num);
     }
     else
     {
@@ -509,25 +583,30 @@
         int trans_split_index;
         int split_index;
         const char *in_num = NULL;
+        const char *in_tnum = NULL;
         char *out_num;
+        char *out_tnum;
         time64 date;
         gboolean use_autoreadonly = qof_book_uses_autoreadonly(gnc_get_current_book());
 
         /* We are on a transaction row. Copy the whole transaction. */
 
         date = info->last_date_entered;
-        if (gnc_strisnum (xaccTransGetNum (trans)))
+        if (gnc_strisnum (gnc_get_num_action (trans, trans_split)))
         {
             Account *account = gnc_split_register_get_default_account (reg);
 
             if (account)
                 in_num = xaccAccountGetLastNum (account);
             else
-                in_num = xaccTransGetNum (trans);
+                in_num = gnc_get_num_action (trans, trans_split);
+            in_tnum = (reg->use_tran_num_for_num_field
+                                        ? NULL
+                                        : gnc_get_num_action (trans, NULL));
         }
 
-        if (!gnc_dup_trans_dialog (gnc_split_register_get_parent (reg),
-                                   &date, in_num, &out_num))
+        if (!gnc_dup_trans_dialog (gnc_split_register_get_parent (reg), NULL,
+                                   TRUE, &date, in_num, &out_num, in_tnum, &out_tnum))
         {
             gnc_resume_gui_refresh ();
             LEAVE("dup cancelled");
@@ -574,7 +653,19 @@
         xaccTransBeginEdit (new_trans);
         gnc_copy_trans_onto_trans (trans, new_trans, FALSE, FALSE);
         xaccTransSetDatePostedSecs (new_trans, date);
-        xaccTransSetNum (new_trans, out_num);
+        /* set per book option */
+        gnc_set_num_action (new_trans, NULL, out_num, out_tnum);
+        if (!reg->use_tran_num_for_num_field)
+        {
+            /* find split in new_trans that equals trans_split and set
+             * split_action to out_num */
+            gnc_set_num_action (NULL,
+                                xaccTransGetSplit (new_trans, trans_split_index),
+                                out_num, NULL);
+            /* note that if the transaction has multiple splits to the register
+             * account, only the anchor split will be set with user input. The
+             * user will have to adjust other splits manually. */
+        }
         xaccTransCommitEdit (new_trans);
 
         num_cell = (NumCell *) gnc_table_layout_get_cell (reg->table->layout,
@@ -583,6 +674,8 @@
             gnc_split_register_set_last_num (reg, out_num);
 
         g_free (out_num);
+        if (!reg->use_tran_num_for_num_field)
+            g_free (out_tnum);
 
         /* This shouldn't happen, but be paranoid. */
         if (split_index >= xaccTransCountSplits (new_trans))
@@ -1313,9 +1406,23 @@
         const char *value;
 
         value = gnc_table_layout_get_cell_value (reg->table->layout, NUM_CELL);
-        gnc_trans_scm_set_num (trans_scm, value);
+        if (reg->use_tran_num_for_num_field)
+            gnc_trans_scm_set_num (trans_scm, value);
+     /* else this contains the same as ACTN_CELL which is already handled below *
+      * and the TNUM_CELL contains transaction number which is handled in next  *
+      * if statement. */
     }
 
+    if (gnc_table_layout_get_cell_changed (reg->table->layout, TNUM_CELL, TRUE))
+    {
+        const char *value;
+
+        value = gnc_table_layout_get_cell_value (reg->table->layout, TNUM_CELL);
+        if (!reg->use_tran_num_for_num_field)
+            gnc_trans_scm_set_num (trans_scm, value);
+     /* else this cell is not used */
+    }
+
     if (gnc_table_layout_get_cell_changed (reg->table->layout, DESC_CELL, TRUE))
     {
         const char *value;
@@ -2468,6 +2575,18 @@
 }
 
 static void
+split_register_book_option_changed (gpointer new_val, gpointer user_data)
+{
+    SplitRegister * reg = user_data;
+    gboolean *new_data = (gboolean*)new_val;
+
+    if (reg == NULL)
+        return;
+
+    reg->use_tran_num_for_num_field = (*new_data ? FALSE : TRUE);
+}
+
+static void
 gnc_split_register_init (SplitRegister *reg,
                          SplitRegisterType type,
                          SplitRegisterStyle style,
@@ -2486,6 +2605,9 @@
     gnc_gconf_general_register_cb(KEY_ACCOUNT_SEPARATOR,
                                   split_register_gconf_changed,
                                   reg);
+    gnc_book_option_register_cb(OPTION_NAME_NUM_FIELD_SOURCE,
+                                split_register_book_option_changed,
+                                reg);
 
     reg->sr_info = NULL;
 
@@ -2494,6 +2616,9 @@
     reg->use_double_line = use_double_line;
     reg->do_auto_complete = do_auto_complete;
     reg->is_template = is_template;
+    reg->use_tran_num_for_num_field =
+                (qof_book_use_split_action_for_num_field(gnc_get_current_book())
+                    ? FALSE : TRUE);
 
     layout = gnc_split_register_layout_new (reg);
 
@@ -2740,6 +2865,9 @@
     gnc_gconf_general_remove_cb(KEY_ACCOUNT_SEPARATOR,
                                 split_register_gconf_changed,
                                 reg);
+    gnc_book_option_remove_cb(OPTION_NAME_NUM_FIELD_SOURCE,
+                                split_register_book_option_changed,
+                                reg);
     gnc_split_register_cleanup (reg);
 
     gnc_table_destroy (reg->table);

Modified: gnucash/trunk/src/register/ledger-core/split-register.h
===================================================================
--- gnucash/trunk/src/register/ledger-core/split-register.h	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/split-register.h	2012-12-22 06:00:54 UTC (rev 22681)
@@ -199,6 +199,7 @@
 #define MXFRM_CELL "transfer"
 #define NOTES_CELL "notes"
 #define NUM_CELL   "num"
+#define TNUM_CELL  "trans-num"
 #define PRIC_CELL  "price"
 #define RATE_CELL  "exchrate"
 #define RECN_CELL  "reconcile"
@@ -214,12 +215,16 @@
 /** @} */
 
 /** @name Cursor Names
+  * Cursors ending in 'NUM_ACTN' use the split action field for the NUM_CELL
+  * rather than the transaction number field which is shown in the TNUM_CELL
   * @{
   */
 #define CURSOR_SINGLE_LEDGER  "cursor-single-ledger"
 #define CURSOR_DOUBLE_LEDGER  "cursor-double-ledger"
+#define CURSOR_DOUBLE_LEDGER_NUM_ACTN  "cursor-double-ledger-num-actn"
 #define CURSOR_SINGLE_JOURNAL "cursor-single-journal"
 #define CURSOR_DOUBLE_JOURNAL "cursor-double-journal"
+#define CURSOR_DOUBLE_JOURNAL_NUM_ACTN "cursor-double-journal-num-actn"
 #define CURSOR_SPLIT          "cursor-split"
 /** @} */
 
@@ -261,6 +266,9 @@
     SplitRegisterStyle style;
 
     gboolean use_double_line;  /**< whether to use two lines per transaction */
+    gboolean use_tran_num_for_num_field;  /**< whether to use transaction number
+                                                or split action for number
+                                                field in register */
     gboolean is_template;
     gboolean do_auto_complete; /**< whether to use auto-competion */
 

Modified: gnucash/trunk/src/register/ledger-core/test/Makefile.am
===================================================================
--- gnucash/trunk/src/register/ledger-core/test/Makefile.am	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/register/ledger-core/test/Makefile.am	2012-12-22 06:00:54 UTC (rev 22681)
@@ -7,6 +7,7 @@
 	$(top_builddir)/src/libqof/qof/libgnc-qof.la \
         $(top_builddir)/src/app-utils/libgncmod-app-utils.la \
 	${top_builddir}/src/gnome-utils/libgncmod-gnome-utils.la \
+	${top_builddir}/src/gnome/libgnc-gnome.la \
     ../libgncmod-ledger-core.la
 
 AM_CPPFLAGS = -I${top_srcdir}/src/test-core -I.. ${GLIB_CFLAGS}

Modified: gnucash/trunk/src/report/business-reports/customer-summary.scm
===================================================================
--- gnucash/trunk/src/report/business-reports/customer-summary.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/report/business-reports/customer-summary.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -236,7 +236,7 @@
 	  (if (not (null? invoice))
 	      (set! due-date (gncInvoiceGetDateDue invoice)))
 
-	  (let ((row (make-row column-vector date due-date (xaccTransGetNum txn)
+	  (let ((row (make-row column-vector date due-date (gnc-get-num-action txn split)
 			       type-str (xaccSplitGetMemo split)
 			       (gnc:make-gnc-monetary currency value)))
 		(row-style (if odd-row? "normal-row" "alternate-row")))

Modified: gnucash/trunk/src/report/business-reports/job-report.scm
===================================================================
--- gnucash/trunk/src/report/business-reports/job-report.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/report/business-reports/job-report.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -269,7 +269,7 @@
 	  (if (not (null? invoice))
 	      (set! due-date (gncInvoiceGetDateDue invoice)))
 
-	  (let ((row (make-row column-vector date due-date (xaccTransGetNum txn)
+	  (let ((row (make-row column-vector date due-date (gnc-get-num-action txn split)
 			       type-str (xaccSplitGetMemo split)
 			       (gnc:make-gnc-monetary currency value)))
 		(row-style (if odd-row? "normal-row" "alternate-row")))

Modified: gnucash/trunk/src/report/business-reports/owner-report.scm
===================================================================
--- gnucash/trunk/src/report/business-reports/owner-report.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/report/business-reports/owner-report.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -360,7 +360,7 @@
       (if (not (null? invoice))
           (set! due-date (gncInvoiceGetDateDue invoice)))
 
-      (let ((row (make-row column-vector date due-date (xaccTransGetNum txn)
+      (let ((row (make-row column-vector date due-date (gnc-get-num-action txn split)
                    type-str (xaccSplitGetMemo split)
                    (gnc:make-gnc-monetary currency value)
            (if (not (gnc-numeric-negative-p value))

Modified: gnucash/trunk/src/report/locale-specific/us/taxtxf.scm
===================================================================
--- gnucash/trunk/src/report/locale-specific/us/taxtxf.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/report/locale-specific/us/taxtxf.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -52,6 +52,12 @@
 ;;
 ;; Add support for code N673, Format 4
 ;;
+;; September, 2012 Update:
+;;
+;; Add support of book option for num-source; use function gnc-get-num-action in
+;; place of xaccTransGetNum and function gnc-get-action-num in place of
+;; xaccSplitGetAction and modify report headings accordingly
+;;
 ;; From prior version:
 ;; NOTE: setting of specific dates is squirly! and seems
 ;; to be current-date dependant!  Actually, time of day dependant!  Just
@@ -198,10 +204,15 @@
     gnc:pagename-display (N_ "Print TXF export parameters")
     "i" (N_ "Show TXF export parameters for each TXF code/account on report") #f))
 
-  (gnc:register-tax-option
-   (gnc:make-simple-boolean-option
-    gnc:pagename-display (N_ "Do not print Action:Memo data")
-    "j" (N_ "Do not print Action:Memo data for transactions") #f))
+  (if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
+      (gnc:register-tax-option
+       (gnc:make-simple-boolean-option
+        gnc:pagename-display (N_ "Do not print T-Num:Memo data")
+        "j" (N_ "Do not print T-Num:Memo data for transactions") #f))
+      (gnc:register-tax-option
+       (gnc:make-simple-boolean-option
+        gnc:pagename-display (N_ "Do not print Action:Memo data")
+        "j" (N_ "Do not print Action:Memo data for transactions") #f)))
 
   (gnc:register-tax-option
    (gnc:make-simple-boolean-option
@@ -393,14 +404,21 @@
        (append (list (gnc:make-html-table-header-cell/markup
                           "column-heading-center" "Date"))
                (list (gnc:make-html-table-header-cell/markup
-                          "column-heading-center" "Num"))
+                          "column-heading-center"
+                         (if (qof-book-use-split-action-for-num-field
+                                                         (gnc-get-current-book))
+                             "Num/Action"
+                             "Num")))
                (list (gnc:make-html-table-header-cell/markup
                           "column-heading-center" "Description"))
                (list (gnc:make-html-table-header-cell/markup
                           "column-heading-center"
                          (if suppress-action-memo?
                              "Notes"
-                             "Notes/Action:Memo")))
+                             (if (qof-book-use-split-action-for-num-field
+                                                         (gnc-get-current-book))
+                                 "Notes/T-Num:Memo"
+                                 "Notes/Action:Memo"))))
                (list (gnc:make-html-table-header-cell/markup
                           "column-heading-center"
                          (if format4?
@@ -1300,7 +1318,7 @@
                   (notes (xaccTransGetNotes parent))
                   (action (if suppress-action-memo?
                               ""
-                              (xaccSplitGetAction split)))
+                              (gnc-get-action-num  parent split)))
                   (memo  (if suppress-action-memo?
                              ""
                              (xaccSplitGetMemo split)))
@@ -1446,7 +1464,8 @@
                                           'attribute (list "cellpadding" "0"))
                        (gnc:html-table-append-row!
                             num-table
-                            (gnc:make-html-table-cell (xaccTransGetNum parent)))
+                            (gnc:make-html-table-cell (gnc-get-num-action
+                                                                parent split)))
                        (gnc:html-table-set-style! desc-table "table" 
                                           'attribute (list "border" "0")
                                           'attribute (list "cellspacing" "0")
@@ -2002,8 +2021,14 @@
                                  "Do not print transaction detail")))
          (no-special-dates? (get-option gnc:pagename-display
                                  "Do not use special date processing"))
-         (suppress-action-memo? (get-option gnc:pagename-display 
-                                 "Do not print Action:Memo data"))
+         (suppress-action-memo? (if (gnc:lookup-option
+                                        (gnc:report-options report-obj)
+                                            gnc:pagename-display
+                                            "Do not print Action:Memo data")
+                                    (get-option gnc:pagename-display 
+                                     "Do not print Action:Memo data")
+                                    (get-option gnc:pagename-display 
+                                     "Do not print T-Num:Memo data")))
          (shade-alternate-transactions? (if (gnc-html-engine-supports-css)
                                             #t 
                                             (get-option gnc:pagename-display 

Modified: gnucash/trunk/src/report/standard-reports/register.scm
===================================================================
--- gnucash/trunk/src/report/standard-reports/register.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/report/standard-reports/register.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -75,7 +75,9 @@
   (let* ((col-vector (make-vector columns-used-size #f))
          (set-col (make-set-col col-vector)))
     (set-col (opt-val "Display" "Date") 0)
-    (set-col (opt-val "Display" "Num") 1)
+    (set-col (if (gnc:lookup-option options "Display" "Num")
+                 (opt-val "Display" "Num")
+                 (opt-val "Display" "Num/Action")) 1)
     (set-col 
         (if (opt-val "__reg" "journal")
         (or (opt-val "Display" "Memo") (opt-val "Display" "Description") (opt-val "__reg" "double") )
@@ -111,13 +113,17 @@
 
 (define (make-heading-list column-vector
                            debit-string credit-string amount-string
-                           multi-rows?)
+                           multi-rows? action-for-num? ledger-type?)
   (let ((heading-list '()))
     (gnc:debug "Column-vector" column-vector)
     (if (date-col column-vector)
         (addto! heading-list (_ "Date")))
     (if (num-col column-vector)
-        (addto! heading-list (_ "Num")))
+        (addto! heading-list (if action-for-num?
+                                 (if ledger-type?
+                                     (_ "T-Num")
+                                     (_ "Num/Action"))
+                                 (_ "Num"))))
     (if (description-col column-vector)
         (addto! heading-list (_ "Description")))
     (if (memo-col column-vector)
@@ -159,8 +165,9 @@
         (gnc-numeric-neg balance)
         balance)))
 
-(define (add-split-row table split column-vector row-style
-                       transaction-info? split-info? double? memo? description?)
+(define (add-split-row table split column-vector row-style transaction-info?
+                       split-info? action-for-num? ledger-type? double? memo?
+                       description?)
   (let* ((row-contents '())
          (parent (xaccSplitGetParent split))
          (account (xaccSplitGetAccount split))
@@ -184,9 +191,11 @@
                 (gnc:make-html-table-cell/markup
 					"text-cell"
                     (if transaction-info?
-                        (xaccTransGetNum parent)
+                        (if (and action-for-num? ledger-type?)
+                            (gnc-get-num-action parent #f)
+                            (gnc-get-num-action parent split))
                         (if split-info?
-                            (xaccSplitGetAction split)
+                            (gnc-get-action-num  #f split)
                             " ")))))
     (if (description-col column-vector)
         (addto! row-contents
@@ -307,7 +316,8 @@
 
     (gnc:html-table-append-row/markup! table row-style
                                        (reverse row-contents))
-    (if (and double? transaction-info? (description-col column-vector))
+    (if (and double? transaction-info?)
+        (if (or (num-col column-vector) (description-col column-vector))
         (begin
           (let ((count 0))
             (set! row-contents '())
@@ -315,16 +325,27 @@
                 (begin
                   (set! count (+ count 1))
                   (addto! row-contents " ")))
-            (if (num-col column-vector)
+            (if (and (num-col column-vector) (description-col column-vector))
                 (begin
                   (set! count (+ count 1))
-                  (addto! row-contents " ")))
-            (addto! row-contents
+                  (addto! row-contents
+                    (gnc:make-html-table-cell/markup
+					  "text-cell"
+                      (if (and action-for-num? (not ledger-type?))
+                          (gnc-get-num-action parent #f)
+                          " ")))))
+            (if (description-col column-vector)
+                (addto! row-contents ;; 
                     (gnc:make-html-table-cell/size
                      1 (- (num-columns-required column-vector) count)
                      (xaccTransGetNotes parent)))
+                (gnc:make-html-table-cell/size
+                     1 (- (num-columns-required column-vector) (- count 1))
+                     (if (and action-for-num? (not ledger-type?))
+                         (gnc-get-num-action parent #f)
+                         " ")))
             (gnc:html-table-append-row/markup! table row-style
-                                               (reverse row-contents)))))
+                                               (reverse row-contents))))))
     split-value))
 
 (define (lookup-sort-key sort-option)
@@ -344,6 +365,8 @@
   (gnc:register-reg-option
    (gnc:make-internal-option "__reg" "journal" #f))
   (gnc:register-reg-option
+   (gnc:make-internal-option "__reg" "ledger-type" #f))
+  (gnc:register-reg-option
    (gnc:make-internal-option "__reg" "double" #f))
   (gnc:register-reg-option
    (gnc:make-internal-option "__reg" "debit-string" (_ "Debit")))
@@ -361,10 +384,15 @@
     (N_ "Display") (N_ "Date")
     "b" (N_ "Display the date?") #t))
 
-  (gnc:register-reg-option
-   (gnc:make-simple-boolean-option
-    (N_ "Display") (N_ "Num")
-    "c" (N_ "Display the check number?") #t))
+  (if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
+      (gnc:register-reg-option
+       (gnc:make-simple-boolean-option
+        (N_ "Display") (N_ "Num/Action")
+        "c" (N_ "Display the check number/action?") #t))
+      (gnc:register-reg-option
+       (gnc:make-simple-boolean-option
+        (N_ "Display") (N_ "Num")
+        "c" (N_ "Display the check number?") #t)))
 
   (gnc:register-reg-option
    (gnc:make-simple-boolean-option
@@ -431,6 +459,8 @@
     (gnc:option-value (gnc:lookup-option options section name)))
   (define (reg-report-journal?)
     (opt-val "__reg" "journal"))
+  (define (reg-report-ledger-type?)
+    (opt-val "__reg" "ledger-type"))
   (define (reg-report-double?)
     (opt-val "__reg" "double"))
   (define (reg-report-invoice?)
@@ -511,12 +541,16 @@
       (total-amount 'add split-currency split-amount)
       (total-value 'add trans-currency split-value)))
 
-  (define (add-other-split-rows split table used-columns row-style)
+  (define (add-other-split-rows split table used-columns row-style
+                                action-for-num? ledger-type?)
     (define (other-rows-driver split parent table used-columns i)
       (let ((current (xaccTransGetSplit parent i)))
         (if (not (null? current))
             (begin
-              (add-split-row table current used-columns row-style #f #t #f (opt-val "Display" "Memo") (opt-val "Display" "Description"))
+              (add-split-row table current used-columns row-style #f #t
+                                action-for-num? ledger-type? #f
+                                (opt-val "Display" "Memo")
+                                (opt-val "Display" "Description"))
               (other-rows-driver split parent table
                                  used-columns (+ i 1))))))
 
@@ -529,6 +563,8 @@
                                   used-columns
                                   width
                                   multi-rows?
+                                  action-for-num?
+                                  ledger-type?
                                   double?
                                   odd-row?
                                   total-collector
@@ -574,13 +610,15 @@
                                            current-row-style
                                            #t
                                            (not multi-rows?)
+                                           action-for-num?
+                                           ledger-type?
                                            double?
                                            (opt-val "Display" "Memo")
                                            (opt-val "Display" "Description")))))
 
           (if (and multi-rows? valid-split?)
               (add-other-split-rows 
-               current table used-columns "alternate-row"))
+               current table used-columns "alternate-row" action-for-num? ledger-type?))
 
           (if (and multi-rows? valid-split?)
               (for-each (lambda (split)
@@ -604,6 +642,8 @@
                                   used-columns
                                   width 
                                   multi-rows?
+                                  action-for-num?
+                                  ledger-type?
                                   double?
                                   (not odd-row?)                       
                                   total-collector
@@ -626,13 +666,16 @@
          (used-columns (build-column-used options))
          (width (num-columns-required used-columns))
          (multi-rows? (reg-report-journal?))
-         (double? (reg-report-double?)))
+         (ledger-type? (reg-report-ledger-type?))
+         (double? (reg-report-double?))
+         (action-for-num? (qof-book-use-split-action-for-num-field
+                                                      (gnc-get-current-book))))
 
     (gnc:html-table-set-col-headers!
      table
      (make-heading-list used-columns
                         debit-string credit-string amount-string
-                        multi-rows?))
+                        multi-rows? action-for-num? ledger-type?))
 
     (do-rows-with-subtotals (splits-leader splits)
                             splits
@@ -640,6 +683,8 @@
                             used-columns
                             width
                             multi-rows?
+                            action-for-num?
+                            ledger-type?
                             double?
                             #t
                             (gnc:make-commodity-collector)
@@ -788,11 +833,12 @@
  'renderer reg-renderer
  'in-menu? #f)
 
-(define (gnc:register-report-create-internal invoice? query journal? double?
-                                             title debit-string credit-string)
+(define (gnc:register-report-create-internal invoice? query journal? ledger-type?
+                                             double? title debit-string credit-string)
   (let* ((options (gnc:make-report-options register-report-guid))
          (query-op (gnc:lookup-option options "__reg" "query"))
          (journal-op (gnc:lookup-option options "__reg" "journal"))
+         (ledger-type-op (gnc:lookup-option options "__reg" "ledger-type"))
          (double-op (gnc:lookup-option options "__reg" "double"))
          (title-op (gnc:lookup-option options "General" "Title"))
          (debit-op (gnc:lookup-option options "__reg" "debit-string"))
@@ -806,6 +852,7 @@
 
     (gnc:option-set-value query-op query)
     (gnc:option-set-value journal-op journal?)
+    (gnc:option-set-value ledger-type-op ledger-type?)
     (gnc:option-set-value double-op double?)
     (gnc:option-set-value title-op title)
     (gnc:option-set-value debit-op debit-string)

Modified: gnucash/trunk/src/report/standard-reports/standard-reports.scm
===================================================================
--- gnucash/trunk/src/report/standard-reports/standard-reports.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/report/standard-reports/standard-reports.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -133,13 +133,13 @@
 (use-modules (gnucash gnc-module))
 (gnc:module-load "gnucash/engine" 0)
 
-(define (gnc:register-report-create account split query journal? double?
-				    title debit-string credit-string)
+(define (gnc:register-report-create account split query journal? ledger-type?
+				    double? title debit-string credit-string)
   (let* ((acct-type (xaccAccountGetType account))
 	 (create-fcn (lookup-register-report acct-type split)))
     (gnc:debug "create-fcn: " create-fcn)
     (if create-fcn
 	(create-fcn account split query journal? double? title
 		    debit-string credit-string)
-	(gnc:register-report-create-internal #f query journal? double? title
-					     debit-string credit-string))))
+	(gnc:register-report-create-internal #f query journal? ledger-type? double?
+					     title debit-string credit-string))))

Modified: gnucash/trunk/src/report/standard-reports/transaction.scm
===================================================================
--- gnucash/trunk/src/report/standard-reports/transaction.scm	2012-12-21 09:19:41 UTC (rev 22680)
+++ gnucash/trunk/src/report/standard-reports/transaction.scm	2012-12-22 06:00:54 UTC (rev 22681)
@@ -366,7 +366,9 @@
         (vector-set! column-list 0 #t))
     (if (opt-val (N_ "Display") (N_ "Reconciled Date"))
         (vector-set! column-list 1 #t))
-    (if (opt-val (N_ "Display") (N_ "Num"))
+    (if (if (gnc:lookup-option options (N_ "Display") (N_ "Num"))
+            (opt-val (N_ "Display") (N_ "Num"))
+            (opt-val (N_ "Display") (N_ "Num/Action")))
         (vector-set! column-list 2 #t))
     (if (opt-val (N_ "Display") (N_ "Description"))
         (vector-set! column-list 3 #t))
@@ -404,14 +406,25 @@
         (vector-set! column-list 19 #t))
     column-list))
 
-(define (make-heading-list column-vector)
+(define (make-heading-list column-vector options)
   (let ((heading-list '()))
     (if (used-date column-vector)
         (addto! heading-list (_ "Date")))
     (if (used-reconciled-date column-vector)
         (addto! heading-list (_ "Reconciled Date")))
     (if (used-num column-vector)
-        (addto! heading-list (_ "Num")))
+        (addto! heading-list (if (and (qof-book-use-split-action-for-num-field
+                                                        (gnc-get-current-book))
+                                      (if (gnc:lookup-option options
+                                                    gnc:pagename-display
+                                                    (N_ "Trans Number"))
+                                          (gnc:option-value 
+                                            (gnc:lookup-option options
+                                                    gnc:pagename-display
+                                                    (N_ "Trans Number")))
+                                          #f))
+                                 (_ "Num/T-Num")
+                                 (_ "Num"))))
     (if (used-description column-vector)
         (addto! heading-list (_ "Description")))
     (if (used-memo column-vector)
@@ -487,9 +500,26 @@
     (if (used-num column-vector)
         (addto! row-contents
                 (if transaction-row?
-                    (gnc:make-html-table-cell/markup "text-cell"
-                        (xaccTransGetNum parent))
+                    (if (qof-book-use-split-action-for-num-field
+                                                        (gnc-get-current-book))
+                        (let* ((num (gnc-get-num-action parent split))
+                               (t-num (if (if (gnc:lookup-option options
+                                                    gnc:pagename-display
+                                                    (N_ "Trans Number"))
+                                              (opt-val gnc:pagename-display
+                                                    (N_ "Trans Number"))
+                                              #f)
+                                          (gnc-get-num-action parent #f)
+                                          ""))
+                               (num-string (if (equal? t-num "")
+                                               num
+                                               (string-append num "/" t-num))))
+                              (gnc:make-html-table-cell/markup "text-cell"
+                                   num-string))
+                        (gnc:make-html-table-cell/markup "text-cell"
+                            (gnc-get-num-action parent split)))
                     " ")))
+
     (if (used-description column-vector)
         (addto! row-contents
                 (if transaction-row?
@@ -672,58 +702,114 @@
   (let ((options gnc:*transaction-report-options*)
 
         (key-choice-list 
-         (list (vector 'none
-                       (N_ "None")
-                       (N_ "Do not sort"))
+         (if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
+             (list (vector 'none
+                           (N_ "None")
+                           (N_ "Do not sort"))
 
-               (vector 'account-name
-                       (N_ "Account Name")
-                       (N_ "Sort & subtotal by account name"))
+                   (vector 'account-name
+                           (N_ "Account Name")
+                           (N_ "Sort & subtotal by account name"))
 
-               (vector 'account-code
-                       (N_ "Account Code")
-                       (N_ "Sort & subtotal by account code"))
+                   (vector 'account-code
+                           (N_ "Account Code")
+                           (N_ "Sort & subtotal by account code"))
 
-               (vector 'date
-                       (N_ "Date")
-                       (N_ "Sort by date"))
+                   (vector 'date
+                           (N_ "Date")
+                           (N_ "Sort by date"))
 
-               (vector 'exact-time
-                       (N_ "Exact Time")
-                       (N_ "Sort by exact time"))
+                   (vector 'exact-time
+                           (N_ "Exact Time")
+                           (N_ "Sort by exact time"))
 
-               (vector 'reconciled-date
-                       (N_ "Reconciled Date")
-                       (N_ "Sort by the Reconciled Date"))
+                   (vector 'reconciled-date
+                           (N_ "Reconciled Date")
+                           (N_ "Sort by the Reconciled Date"))
 
-               (vector 'register-order
-                       (N_ "Register Order")
-                       (N_ "Sort as with the register"))
+                   (vector 'register-order
+                           (N_ "Register Order")
+                           (N_ "Sort as with the register"))
 
-               (vector 'corresponding-acc-name 
-                       (N_ "Other Account Name")
-                       (N_ "Sort by account transferred from/to's name"))
+                   (vector 'corresponding-acc-name 
+                           (N_ "Other Account Name")
+                           (N_ "Sort by account transferred from/to's name"))
 
-               (vector 'corresponding-acc-code
-                       (N_ "Other Account Code")
-                       (N_ "Sort by account transferred from/to's code"))
+                   (vector 'corresponding-acc-code
+                           (N_ "Other Account Code")
+                           (N_ "Sort by account transferred from/to's code"))
                
-               (vector 'amount
-                       (N_ "Amount")
-                       (N_ "Sort by amount"))
+                   (vector 'amount
+                           (N_ "Amount")
+                           (N_ "Sort by amount"))
                
-               (vector 'description
-                       (N_ "Description")
-                       (N_ "Sort by description"))
+                   (vector 'description
+                           (N_ "Description")
+                           (N_ "Sort by description"))
                
-               (vector 'number
-                       (N_ "Number")
-                       (N_ "Sort by check/transaction number"))
+                   (vector 'number
+                           (N_ "Number/Action")
+                           (N_ "Sort by check number/action"))
+
+                   (vector 't-number
+                           (N_ "Transaction Number")
+                           (N_ "Sort by transaction number"))
                
-               (vector 'memo
-                       (N_ "Memo")
-                       (N_ "Sort by memo"))))
+                   (vector 'memo
+                           (N_ "Memo")
+                           (N_ "Sort by memo")))
+             (list (vector 'none
+                           (N_ "None")
+                           (N_ "Do not sort"))
 
+                   (vector 'account-name
+                           (N_ "Account Name")
+                           (N_ "Sort & subtotal by account name"))
+
+                   (vector 'account-code
+                           (N_ "Account Code")
+                           (N_ "Sort & subtotal by account code"))
+
+                   (vector 'date
+                           (N_ "Date")
+                           (N_ "Sort by date"))
+
+                   (vector 'exact-time
+                           (N_ "Exact Time")
+                           (N_ "Sort by exact time"))
+
+                   (vector 'reconciled-date
+                           (N_ "Reconciled Date")
+                           (N_ "Sort by the Reconciled Date"))
+
+                   (vector 'register-order
+                           (N_ "Register Order")
+                           (N_ "Sort as with the register"))
+
+                   (vector 'corresponding-acc-name 
+                           (N_ "Other Account Name")
+                           (N_ "Sort by account transferred from/to's name"))
+
+                   (vector 'corresponding-acc-code
+                           (N_ "Other Account Code")
+                           (N_ "Sort by account transferred from/to's code"))
+               
+                   (vector 'amount
+                           (N_ "Amount")
+                           (N_ "Sort by amount"))
+               
+                   (vector 'description
+                           (N_ "Description")
+                           (N_ "Sort by description"))
+               
+                   (vector 'number
+                           (N_ "Number")
+                           (N_ "Sort by check/transaction number"))
+
+                   (vector 'memo
+                           (N_ "Memo")
+                           (N_ "Sort by memo")))))
+
         (ascending-choice-list 
          (list
           (vector 'ascend
@@ -840,7 +926,9 @@
    (list
     (list (N_ "Date")                         "a"  (N_ "Display the date?") #t)
     (list (N_ "Reconciled Date")              "a2" (N_ "Display the reconciled date?") #f)
-    (list (N_ "Num")                          "b"  (N_ "Display the check number?") #t)
+    (if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
+        (list (N_ "Num/Action")               "b"  (N_ "Display the check number?") #t)
+        (list (N_ "Num")                      "b"  (N_ "Display the check number?") #t))
     (list (N_ "Description")                  "c"  (N_ "Display the description?") #t)
     (list (N_ "Notes")                        "d2" (N_ "Display the notes if the memo is unavailable?") #t)
     (list (N_ "Account Name")                 "e"  (N_ "Display the account name?") #f)
@@ -856,6 +944,12 @@
     (list (N_ "Running Balance")              "n"  (N_ "Display a running balance") #f)
     (list (N_ "Totals")                       "o"  (N_ "Display the totals?") #t)))
 
+  (if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
+      (gnc:register-trep-option
+       (gnc:make-simple-boolean-option
+        gnc:pagename-display (N_ "Trans Number")
+                                    "b2" (N_ "Display the trans number?") #f)))
+
   ;; Add an option to display the memo, and disable the notes option
   ;; when memos are not included.
   (gnc:register-trep-option
@@ -1121,7 +1215,7 @@
 
     (gnc:html-table-set-col-headers!
      table
-     (make-heading-list used-columns))
+     (make-heading-list used-columns options))
     ;;     (gnc:warn "Splits:" splits)
     (if (not (null? splits))
         (begin
@@ -1201,7 +1295,10 @@
                                   render-corresponding-account-subtotal))
             (cons 'amount        (vector (list SPLIT-VALUE) #f #f #f))
             (cons 'description   (vector (list SPLIT-TRANS TRANS-DESCRIPTION) #f #f #f))
-            (cons 'number        (vector (list SPLIT-TRANS TRANS-NUM) #f #f #f))
+            (if (qof-book-use-split-action-for-num-field (gnc-get-current-book))
+                (cons 'number    (vector (list SPLIT-ACTION) #f #f #f))
+                (cons 'number    (vector (list SPLIT-TRANS TRANS-NUM) #f #f #f)))
+            (cons 't-number      (vector (list SPLIT-TRANS TRANS-NUM) #f #f #f))
             (cons 'memo          (vector (list SPLIT-MEMO) #f #f #f))
             (cons 'none          (vector '() #f #f #f)))))
 



More information about the gnucash-changes mailing list