1997-11-01 01:39:32 +00:00
|
|
|
/********************************************************************\
|
2001-07-01 21:09:09 +00:00
|
|
|
* gnc-ui-util.c -- utility functions for the GnuCash UI *
|
2000-11-01 08:52:30 +00:00
|
|
|
* Copyright (C) 2000 Dave Peticolas <dave@krondo.com> *
|
1997-11-01 01:39:32 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
2000-04-24 21:12:41 +00:00
|
|
|
* along with this program; if not, contact: *
|
1997-11-01 01:39:32 +00:00
|
|
|
* *
|
2000-04-24 21:12:41 +00:00
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-17 05:35:02 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
1997-11-01 01:39:32 +00:00
|
|
|
\********************************************************************/
|
|
|
|
|
|
2017-10-26 11:14:21 +02:00
|
|
|
#include <config.h>
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2017-05-26 13:51:51 -07:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
|
#define __USE_MINGW_ANSI_STDIO 1
|
|
|
|
|
#endif
|
2010-03-07 20:30:08 +00:00
|
|
|
#include "gnc-ui-util.h"
|
2005-11-19 23:53:34 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib/gi18n.h>
|
2013-10-07 14:08:17 +00:00
|
|
|
#include <gio/gio.h>
|
2006-10-15 19:02:05 +00:00
|
|
|
#include <libguile.h>
|
2000-08-31 07:16:55 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <locale.h>
|
2002-12-16 01:40:26 +00:00
|
|
|
#include <math.h>
|
2010-03-08 18:48:44 +00:00
|
|
|
#if defined(G_OS_WIN32) && !defined(_MSC_VER)
|
|
|
|
|
# include <pow.h>
|
2007-02-01 01:08:05 +00:00
|
|
|
#endif
|
2000-10-31 01:27:31 +00:00
|
|
|
#include <stdarg.h>
|
2000-08-31 07:16:55 +00:00
|
|
|
#include <stdlib.h>
|
2000-11-01 08:52:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2000-03-22 10:10:50 +00:00
|
|
|
|
2010-03-07 20:30:08 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
#include "qof.h"
|
2003-02-22 08:15:53 +00:00
|
|
|
#include "guile-mappings.h"
|
2013-10-07 14:08:17 +00:00
|
|
|
#include "gnc-prefs.h"
|
2017-08-10 13:56:00 +02:00
|
|
|
#include "gnc-module.h"
|
|
|
|
|
#include "Account.h"
|
|
|
|
|
#include "Transaction.h"
|
|
|
|
|
#include "gnc-engine.h"
|
|
|
|
|
#include "gnc-euro.h"
|
|
|
|
|
#include "gnc-hooks.h"
|
|
|
|
|
#include "gnc-session.h"
|
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
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 06:00:54 +00:00
|
|
|
#include "engine-helpers.h"
|
2011-01-31 04:29:48 +00:00
|
|
|
#include "gnc-locale-utils.h"
|
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
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 06:00:54 +00:00
|
|
|
#include "gnc-component-manager.h"
|
|
|
|
|
#include "gnc-features.h"
|
2012-12-22 18:20:39 +00:00
|
|
|
#include "gnc-guile-utils.h"
|
2000-10-31 01:27:31 +00:00
|
|
|
|
2013-10-07 14:30:10 +00:00
|
|
|
#define GNC_PREF_CURRENCY_CHOICE_LOCALE "currency-choice-locale"
|
|
|
|
|
#define GNC_PREF_CURRENCY_CHOICE_OTHER "currency-choice-other"
|
|
|
|
|
#define GNC_PREF_CURRENCY_OTHER "currency-other"
|
|
|
|
|
#define GNC_PREF_REVERSED_ACCTS_NONE "reversed-accounts-none"
|
|
|
|
|
#define GNC_PREF_REVERSED_ACCTS_CREDIT "reversed-accounts-credit"
|
|
|
|
|
#define GNC_PREF_REVERSED_ACCTS_INC_EXP "reversed-accounts-incomeexpense"
|
2005-11-02 03:32:36 +00:00
|
|
|
|
|
|
|
|
static QofLogModule log_module = GNC_MOD_GUI;
|
2000-10-31 01:27:31 +00:00
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
static gboolean auto_decimal_enabled = FALSE;
|
|
|
|
|
static int auto_decimal_places = 2; /* default, can be changed */
|
2000-10-31 01:27:31 +00:00
|
|
|
|
2001-08-20 10:08:09 +00:00
|
|
|
static gboolean reverse_balance_inited = FALSE;
|
|
|
|
|
static gboolean reverse_type[NUM_ACCOUNT_TYPES];
|
2000-10-31 01:27:31 +00:00
|
|
|
|
2013-10-07 14:08:17 +00:00
|
|
|
/* Cache currency ISO codes and only look them up in the settings when
|
2006-03-08 05:14:54 +00:00
|
|
|
* absolutely necessary. Can't cache a pointer to the data structure
|
|
|
|
|
* as that will change any time the book changes. */
|
|
|
|
|
static gchar *user_default_currency = NULL;
|
|
|
|
|
static gchar *user_report_currency = NULL;
|
|
|
|
|
|
2013-10-07 14:15:18 +00:00
|
|
|
gchar *gnc_normalize_account_separator (const gchar* separator)
|
|
|
|
|
{
|
|
|
|
|
gchar *new_sep=NULL;
|
|
|
|
|
|
|
|
|
|
if (!separator || !*separator || g_strcmp0(separator, "colon") == 0)
|
|
|
|
|
new_sep = g_strdup (":");
|
|
|
|
|
else if (g_strcmp0(separator, "slash") == 0)
|
|
|
|
|
new_sep = g_strdup ("/");
|
|
|
|
|
else if (g_strcmp0(separator, "backslash") == 0)
|
|
|
|
|
new_sep = g_strdup ("\\");
|
|
|
|
|
else if (g_strcmp0(separator, "dash") == 0)
|
|
|
|
|
new_sep = g_strdup ("-");
|
|
|
|
|
else if (g_strcmp0(separator, "period") == 0)
|
|
|
|
|
new_sep = g_strdup (".");
|
|
|
|
|
else
|
|
|
|
|
new_sep = g_strdup (separator);
|
|
|
|
|
|
|
|
|
|
return new_sep;
|
|
|
|
|
}
|
2000-11-29 20:40:25 +00:00
|
|
|
/********************************************************************\
|
2006-03-04 03:04:46 +00:00
|
|
|
* gnc_configure_account_separator *
|
|
|
|
|
* updates the current account separator character *
|
2000-11-29 20:40:25 +00:00
|
|
|
* *
|
|
|
|
|
* Args: none *
|
|
|
|
|
\*******************************************************************/
|
2006-03-02 07:20:33 +00:00
|
|
|
static void
|
|
|
|
|
gnc_configure_account_separator (void)
|
2000-11-29 20:40:25 +00:00
|
|
|
{
|
2013-10-07 14:15:18 +00:00
|
|
|
gchar *separator;
|
2009-12-29 20:12:48 +00:00
|
|
|
char *string;
|
|
|
|
|
|
2013-10-07 14:08:17 +00:00
|
|
|
string = gnc_prefs_get_string(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNT_SEPARATOR);
|
2013-10-07 14:15:18 +00:00
|
|
|
separator = gnc_normalize_account_separator (string);
|
2006-03-04 03:04:46 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_set_account_separator(separator);
|
2000-11-29 20:40:25 +00:00
|
|
|
|
2013-10-07 14:15:18 +00:00
|
|
|
g_free(string);
|
|
|
|
|
g_free(separator);
|
2000-11-29 20:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-20 10:08:09 +00:00
|
|
|
static void
|
|
|
|
|
gnc_configure_reverse_balance (void)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
|
|
|
|
|
reverse_type[i] = FALSE;
|
|
|
|
|
|
2013-10-07 14:16:36 +00:00
|
|
|
if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_INC_EXP))
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
|
|
|
|
reverse_type[ACCT_TYPE_INCOME] = TRUE;
|
|
|
|
|
reverse_type[ACCT_TYPE_EXPENSE] = TRUE;
|
|
|
|
|
}
|
2013-10-07 14:16:36 +00:00
|
|
|
else if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_CREDIT))
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
|
|
|
|
reverse_type[ACCT_TYPE_LIABILITY] = TRUE;
|
|
|
|
|
reverse_type[ACCT_TYPE_PAYABLE] = TRUE;
|
|
|
|
|
reverse_type[ACCT_TYPE_EQUITY] = TRUE;
|
|
|
|
|
reverse_type[ACCT_TYPE_INCOME] = TRUE;
|
|
|
|
|
reverse_type[ACCT_TYPE_CREDIT] = TRUE;
|
|
|
|
|
}
|
2013-10-07 14:16:36 +00:00
|
|
|
else if (!gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_NONE))
|
|
|
|
|
PWARN("no reversed account preference set, using none");
|
2009-12-29 20:12:48 +00:00
|
|
|
|
2001-08-20 10:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gnc_reverse_balance_init (void)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_configure_reverse_balance ();
|
|
|
|
|
reverse_balance_inited = TRUE;
|
2001-08-20 10:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2006-02-26 20:06:15 +00:00
|
|
|
gnc_reverse_balance (const Account *account)
|
2001-08-20 10:08:09 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
int type;
|
2001-08-20 10:08:09 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (account == NULL)
|
|
|
|
|
return FALSE;
|
2001-08-20 10:08:09 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
type = xaccAccountGetType (account);
|
|
|
|
|
if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
|
|
|
|
|
return FALSE;
|
2001-08-20 10:08:09 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!reverse_balance_inited)
|
|
|
|
|
gnc_reverse_balance_init ();
|
2001-08-20 10:08:09 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return reverse_type[type];
|
2001-08-20 10:08:09 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-13 01:09:27 +00:00
|
|
|
|
2006-11-08 16:40:41 +00:00
|
|
|
gchar *
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_get_default_directory (const gchar *section)
|
2003-01-13 01:09:27 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gchar *dir;
|
2006-11-08 16:40:41 +00:00
|
|
|
|
2013-10-07 14:08:17 +00:00
|
|
|
dir = gnc_prefs_get_string (section, GNC_PREF_LAST_PATH);
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!dir)
|
2011-01-14 21:47:44 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
dir = g_strdup (g_get_user_data_dir ()); /* equivalent of "My Documents" */
|
|
|
|
|
#else
|
2009-12-29 20:12:48 +00:00
|
|
|
dir = g_strdup (g_get_home_dir ());
|
2011-01-14 21:47:44 +00:00
|
|
|
#endif
|
2006-11-08 16:40:41 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return dir;
|
2003-01-13 01:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_set_default_directory (const gchar *section, const gchar *directory)
|
2003-01-13 01:09:27 +00:00
|
|
|
{
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_prefs_set_string(section, GNC_PREF_LAST_PATH, directory);
|
2003-01-13 01:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-27 02:38:40 +00:00
|
|
|
QofBook *
|
2001-10-02 09:10:35 +00:00
|
|
|
gnc_get_current_book (void)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
return qof_session_get_book (gnc_get_current_session ());
|
2001-10-02 09:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
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
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 06:00:54 +00:00
|
|
|
/* 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);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-31 20:03:23 +00:00
|
|
|
#define OPTION_TAXUS_NAME "book/tax_US/name"
|
|
|
|
|
#define OPTION_TAXUS_TYPE "book/tax_US/type"
|
|
|
|
|
|
Bug #554394: Income Tax Enhancements
Patch by J. Alex Aycinena. Patch does the following:
- update the tax information in 'txf.scm', which is based on V037 of
the TXF Spec, to V041, the last version issued (bug #554394)
- provide support for multiple copies of certain tax Forms/Schedules
(e.g., Schedule C(1), Schedule C(2), etc.)
- support multiple types of tax entities: partnerships, corporations
and S corporations, in addition to individual tax payers
- support balance sheet accounts, required for these new tax entity types
- add the term 'Income' in several places to avoid confusion with
sales or VAT style taxes in the business features (e.g., change the
menu from 'Tax Options' to 'Income Tax Options')
The following files were changed, as follows, to implement these changes:
1. src/engine/Account.c and
2. src/engine/Account.h: add copy number capability (define
'xaccAccountGetTaxUSCopyNumber' and 'xaccAccountSetTaxUSCopyNumber');
modify 'xaccAccountSetTaxUSCode' to remove KVP when no tax-code
assigned, clean up tax-source descriptions
3. src/gnome/gnc-plugin-basic-commands.c: change 'Tax Options' to
'Income Tax Options'
4. src/app-utils/gnc-ui-util.c and
5. src/app-utils/gnc-ui-util.h: add setter and getter functions for
book tax name and book tax type which are stored in a book KVP, show
copy information in accounts page, tax column, show error messages for
various conditions
6. src/app-utils/app-utils.i: add 'gnc_get_current_book_tax_name' and
'gnc_get_current_book_tax_type' functions
7. src/gnome/dialog-tax-info.c: add copy number and tax entity name
and type, and balance sheet account handling capability
8. src/gnome/glade/tax.glade: add tax entity name, tax entity type,
asset, liability/equity and copy number widgets
9. src/tax/us/txf.scm: update to V041 for individuals, add V041
support for multiple additional tax entity types and balance sheet
accounts and related tax codes, add tax form line data
10. src/tax/us/us.scm: export new functions defined in txf.scm
11. src/report/locale-specific/us/taxtxf.scm: add support for multiple
copies of Forms/Schedules, add support for Format 6, use Form/Schedule
line #'s to sort report, update from "V037" to "V041", add support for
taxpayer types other than F1040, add warning messages if there are
some inconsistent codes assigned and list
12. src/tax/us/txf-de_DE.scm: make functions called from outside (e.g., from
dialog-tax-info.c) have a consistent signature with those same
functions in txf.scm (define tax-entity-type , define getters/setters,
add tax-entity-type as an argument to existing functions)
13. src/tax/us/de_DE.scm: export new functions added to txf-de_DE.scm
14. src/report/locale-specific/us/taxtxf-de_DE.scm: add "" as
tax-entity-type argument to functions
called on txf-de_DE.scm (which defaults to existing codes)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18413 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-15 20:35:50 +00:00
|
|
|
void
|
|
|
|
|
gnc_set_current_book_tax_name (const gchar *tax_name)
|
|
|
|
|
{
|
2010-02-18 05:31:54 +00:00
|
|
|
qof_book_set_string_option(gnc_get_current_book(), OPTION_TAXUS_NAME, tax_name);
|
Bug #554394: Income Tax Enhancements
Patch by J. Alex Aycinena. Patch does the following:
- update the tax information in 'txf.scm', which is based on V037 of
the TXF Spec, to V041, the last version issued (bug #554394)
- provide support for multiple copies of certain tax Forms/Schedules
(e.g., Schedule C(1), Schedule C(2), etc.)
- support multiple types of tax entities: partnerships, corporations
and S corporations, in addition to individual tax payers
- support balance sheet accounts, required for these new tax entity types
- add the term 'Income' in several places to avoid confusion with
sales or VAT style taxes in the business features (e.g., change the
menu from 'Tax Options' to 'Income Tax Options')
The following files were changed, as follows, to implement these changes:
1. src/engine/Account.c and
2. src/engine/Account.h: add copy number capability (define
'xaccAccountGetTaxUSCopyNumber' and 'xaccAccountSetTaxUSCopyNumber');
modify 'xaccAccountSetTaxUSCode' to remove KVP when no tax-code
assigned, clean up tax-source descriptions
3. src/gnome/gnc-plugin-basic-commands.c: change 'Tax Options' to
'Income Tax Options'
4. src/app-utils/gnc-ui-util.c and
5. src/app-utils/gnc-ui-util.h: add setter and getter functions for
book tax name and book tax type which are stored in a book KVP, show
copy information in accounts page, tax column, show error messages for
various conditions
6. src/app-utils/app-utils.i: add 'gnc_get_current_book_tax_name' and
'gnc_get_current_book_tax_type' functions
7. src/gnome/dialog-tax-info.c: add copy number and tax entity name
and type, and balance sheet account handling capability
8. src/gnome/glade/tax.glade: add tax entity name, tax entity type,
asset, liability/equity and copy number widgets
9. src/tax/us/txf.scm: update to V041 for individuals, add V041
support for multiple additional tax entity types and balance sheet
accounts and related tax codes, add tax form line data
10. src/tax/us/us.scm: export new functions defined in txf.scm
11. src/report/locale-specific/us/taxtxf.scm: add support for multiple
copies of Forms/Schedules, add support for Format 6, use Form/Schedule
line #'s to sort report, update from "V037" to "V041", add support for
taxpayer types other than F1040, add warning messages if there are
some inconsistent codes assigned and list
12. src/tax/us/txf-de_DE.scm: make functions called from outside (e.g., from
dialog-tax-info.c) have a consistent signature with those same
functions in txf.scm (define tax-entity-type , define getters/setters,
add tax-entity-type as an argument to existing functions)
13. src/tax/us/de_DE.scm: export new functions added to txf-de_DE.scm
14. src/report/locale-specific/us/taxtxf-de_DE.scm: add "" as
tax-entity-type argument to functions
called on txf-de_DE.scm (which defaults to existing codes)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18413 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-15 20:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
|
gnc_get_current_book_tax_name (void)
|
|
|
|
|
{
|
2010-01-31 20:03:23 +00:00
|
|
|
return qof_book_get_string_option(gnc_get_current_book(), OPTION_TAXUS_NAME);
|
Bug #554394: Income Tax Enhancements
Patch by J. Alex Aycinena. Patch does the following:
- update the tax information in 'txf.scm', which is based on V037 of
the TXF Spec, to V041, the last version issued (bug #554394)
- provide support for multiple copies of certain tax Forms/Schedules
(e.g., Schedule C(1), Schedule C(2), etc.)
- support multiple types of tax entities: partnerships, corporations
and S corporations, in addition to individual tax payers
- support balance sheet accounts, required for these new tax entity types
- add the term 'Income' in several places to avoid confusion with
sales or VAT style taxes in the business features (e.g., change the
menu from 'Tax Options' to 'Income Tax Options')
The following files were changed, as follows, to implement these changes:
1. src/engine/Account.c and
2. src/engine/Account.h: add copy number capability (define
'xaccAccountGetTaxUSCopyNumber' and 'xaccAccountSetTaxUSCopyNumber');
modify 'xaccAccountSetTaxUSCode' to remove KVP when no tax-code
assigned, clean up tax-source descriptions
3. src/gnome/gnc-plugin-basic-commands.c: change 'Tax Options' to
'Income Tax Options'
4. src/app-utils/gnc-ui-util.c and
5. src/app-utils/gnc-ui-util.h: add setter and getter functions for
book tax name and book tax type which are stored in a book KVP, show
copy information in accounts page, tax column, show error messages for
various conditions
6. src/app-utils/app-utils.i: add 'gnc_get_current_book_tax_name' and
'gnc_get_current_book_tax_type' functions
7. src/gnome/dialog-tax-info.c: add copy number and tax entity name
and type, and balance sheet account handling capability
8. src/gnome/glade/tax.glade: add tax entity name, tax entity type,
asset, liability/equity and copy number widgets
9. src/tax/us/txf.scm: update to V041 for individuals, add V041
support for multiple additional tax entity types and balance sheet
accounts and related tax codes, add tax form line data
10. src/tax/us/us.scm: export new functions defined in txf.scm
11. src/report/locale-specific/us/taxtxf.scm: add support for multiple
copies of Forms/Schedules, add support for Format 6, use Form/Schedule
line #'s to sort report, update from "V037" to "V041", add support for
taxpayer types other than F1040, add warning messages if there are
some inconsistent codes assigned and list
12. src/tax/us/txf-de_DE.scm: make functions called from outside (e.g., from
dialog-tax-info.c) have a consistent signature with those same
functions in txf.scm (define tax-entity-type , define getters/setters,
add tax-entity-type as an argument to existing functions)
13. src/tax/us/de_DE.scm: export new functions added to txf-de_DE.scm
14. src/report/locale-specific/us/taxtxf-de_DE.scm: add "" as
tax-entity-type argument to functions
called on txf-de_DE.scm (which defaults to existing codes)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18413 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-15 20:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gnc_set_current_book_tax_type (const gchar *tax_type)
|
|
|
|
|
{
|
2010-01-31 20:03:23 +00:00
|
|
|
qof_book_set_string_option(gnc_get_current_book(), OPTION_TAXUS_TYPE, tax_type);
|
Bug #554394: Income Tax Enhancements
Patch by J. Alex Aycinena. Patch does the following:
- update the tax information in 'txf.scm', which is based on V037 of
the TXF Spec, to V041, the last version issued (bug #554394)
- provide support for multiple copies of certain tax Forms/Schedules
(e.g., Schedule C(1), Schedule C(2), etc.)
- support multiple types of tax entities: partnerships, corporations
and S corporations, in addition to individual tax payers
- support balance sheet accounts, required for these new tax entity types
- add the term 'Income' in several places to avoid confusion with
sales or VAT style taxes in the business features (e.g., change the
menu from 'Tax Options' to 'Income Tax Options')
The following files were changed, as follows, to implement these changes:
1. src/engine/Account.c and
2. src/engine/Account.h: add copy number capability (define
'xaccAccountGetTaxUSCopyNumber' and 'xaccAccountSetTaxUSCopyNumber');
modify 'xaccAccountSetTaxUSCode' to remove KVP when no tax-code
assigned, clean up tax-source descriptions
3. src/gnome/gnc-plugin-basic-commands.c: change 'Tax Options' to
'Income Tax Options'
4. src/app-utils/gnc-ui-util.c and
5. src/app-utils/gnc-ui-util.h: add setter and getter functions for
book tax name and book tax type which are stored in a book KVP, show
copy information in accounts page, tax column, show error messages for
various conditions
6. src/app-utils/app-utils.i: add 'gnc_get_current_book_tax_name' and
'gnc_get_current_book_tax_type' functions
7. src/gnome/dialog-tax-info.c: add copy number and tax entity name
and type, and balance sheet account handling capability
8. src/gnome/glade/tax.glade: add tax entity name, tax entity type,
asset, liability/equity and copy number widgets
9. src/tax/us/txf.scm: update to V041 for individuals, add V041
support for multiple additional tax entity types and balance sheet
accounts and related tax codes, add tax form line data
10. src/tax/us/us.scm: export new functions defined in txf.scm
11. src/report/locale-specific/us/taxtxf.scm: add support for multiple
copies of Forms/Schedules, add support for Format 6, use Form/Schedule
line #'s to sort report, update from "V037" to "V041", add support for
taxpayer types other than F1040, add warning messages if there are
some inconsistent codes assigned and list
12. src/tax/us/txf-de_DE.scm: make functions called from outside (e.g., from
dialog-tax-info.c) have a consistent signature with those same
functions in txf.scm (define tax-entity-type , define getters/setters,
add tax-entity-type as an argument to existing functions)
13. src/tax/us/de_DE.scm: export new functions added to txf-de_DE.scm
14. src/report/locale-specific/us/taxtxf-de_DE.scm: add "" as
tax-entity-type argument to functions
called on txf-de_DE.scm (which defaults to existing codes)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18413 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-15 20:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
|
gnc_get_current_book_tax_type (void)
|
|
|
|
|
{
|
2010-01-31 20:03:23 +00:00
|
|
|
return qof_book_get_string_option(gnc_get_current_book(), OPTION_TAXUS_TYPE);
|
Bug #554394: Income Tax Enhancements
Patch by J. Alex Aycinena. Patch does the following:
- update the tax information in 'txf.scm', which is based on V037 of
the TXF Spec, to V041, the last version issued (bug #554394)
- provide support for multiple copies of certain tax Forms/Schedules
(e.g., Schedule C(1), Schedule C(2), etc.)
- support multiple types of tax entities: partnerships, corporations
and S corporations, in addition to individual tax payers
- support balance sheet accounts, required for these new tax entity types
- add the term 'Income' in several places to avoid confusion with
sales or VAT style taxes in the business features (e.g., change the
menu from 'Tax Options' to 'Income Tax Options')
The following files were changed, as follows, to implement these changes:
1. src/engine/Account.c and
2. src/engine/Account.h: add copy number capability (define
'xaccAccountGetTaxUSCopyNumber' and 'xaccAccountSetTaxUSCopyNumber');
modify 'xaccAccountSetTaxUSCode' to remove KVP when no tax-code
assigned, clean up tax-source descriptions
3. src/gnome/gnc-plugin-basic-commands.c: change 'Tax Options' to
'Income Tax Options'
4. src/app-utils/gnc-ui-util.c and
5. src/app-utils/gnc-ui-util.h: add setter and getter functions for
book tax name and book tax type which are stored in a book KVP, show
copy information in accounts page, tax column, show error messages for
various conditions
6. src/app-utils/app-utils.i: add 'gnc_get_current_book_tax_name' and
'gnc_get_current_book_tax_type' functions
7. src/gnome/dialog-tax-info.c: add copy number and tax entity name
and type, and balance sheet account handling capability
8. src/gnome/glade/tax.glade: add tax entity name, tax entity type,
asset, liability/equity and copy number widgets
9. src/tax/us/txf.scm: update to V041 for individuals, add V041
support for multiple additional tax entity types and balance sheet
accounts and related tax codes, add tax form line data
10. src/tax/us/us.scm: export new functions defined in txf.scm
11. src/report/locale-specific/us/taxtxf.scm: add support for multiple
copies of Forms/Schedules, add support for Format 6, use Form/Schedule
line #'s to sort report, update from "V037" to "V041", add support for
taxpayer types other than F1040, add warning messages if there are
some inconsistent codes assigned and list
12. src/tax/us/txf-de_DE.scm: make functions called from outside (e.g., from
dialog-tax-info.c) have a consistent signature with those same
functions in txf.scm (define tax-entity-type , define getters/setters,
add tax-entity-type as an argument to existing functions)
13. src/tax/us/de_DE.scm: export new functions added to txf-de_DE.scm
14. src/report/locale-specific/us/taxtxf-de_DE.scm: add "" as
tax-entity-type argument to functions
called on txf-de_DE.scm (which defaults to existing codes)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18413 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-15 20:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
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
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 06:00:54 +00:00
|
|
|
/** 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 ();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 17:16:02 -07:00
|
|
|
/** Calls gnc_book_option_book_currency_selected to initiate registered
|
|
|
|
|
* callbacks when currency accounting book option changes to book-currency so
|
|
|
|
|
* that registers/reports can update themselves; sets feature flag */
|
|
|
|
|
void
|
|
|
|
|
gnc_book_option_book_currency_selected_cb (gboolean use_book_currency)
|
|
|
|
|
{
|
|
|
|
|
gnc_suspend_gui_refresh ();
|
|
|
|
|
if (use_book_currency)
|
|
|
|
|
{
|
|
|
|
|
/* Set a feature flag in the book for use of book currency. 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_BOOK_CURRENCY);
|
|
|
|
|
}
|
|
|
|
|
gnc_book_option_book_currency_selected (use_book_currency);
|
|
|
|
|
gnc_resume_gui_refresh ();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 16:06:56 -07:00
|
|
|
/** Returns TRUE if both book-currency and default gain/loss policy KVPs exist
|
|
|
|
|
* and are valid and trading accounts are not used. */
|
|
|
|
|
gboolean
|
|
|
|
|
gnc_book_use_book_currency (QofBook *book)
|
|
|
|
|
{
|
|
|
|
|
const gchar *policy;
|
|
|
|
|
const gchar *currency;
|
|
|
|
|
|
|
|
|
|
if (!book) return FALSE;
|
|
|
|
|
|
|
|
|
|
policy = qof_book_get_default_gains_policy (book);
|
2016-06-17 13:48:03 -07:00
|
|
|
currency = qof_book_get_book_currency_name (book);
|
2015-06-27 16:06:56 -07:00
|
|
|
|
|
|
|
|
/* If either a default gain/loss policy or a book-currency does not exist,
|
|
|
|
|
book-currency accounting method not valid */
|
|
|
|
|
if (!policy || !currency)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* If both exist, both must be valid */
|
2016-06-17 13:48:03 -07:00
|
|
|
if (!gnc_valid_policy_name (policy) || !gnc_commodity_table_lookup
|
|
|
|
|
(gnc_commodity_table_get_table
|
|
|
|
|
(gnc_get_current_book()),
|
|
|
|
|
GNC_COMMODITY_NS_CURRENCY,
|
|
|
|
|
currency))
|
2015-06-27 16:06:56 -07:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* If both exist and are valid, there must be no trading accounts flag */
|
|
|
|
|
if (qof_book_use_trading_accounts (book))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns pointer to Book Currency name for book or NULL; determines
|
|
|
|
|
* that both book-currency and default gain/loss policy KVPs exist and that
|
|
|
|
|
* both are valid, a requirement for the 'book-currency' currency accounting
|
|
|
|
|
* method to apply. */
|
|
|
|
|
const gchar *
|
2016-06-17 13:48:03 -07:00
|
|
|
gnc_book_get_book_currency_name (QofBook *book)
|
|
|
|
|
{
|
|
|
|
|
if (!book) return NULL;
|
|
|
|
|
|
|
|
|
|
if (gnc_book_use_book_currency (book))
|
|
|
|
|
return qof_book_get_book_currency_name (book);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns pointer to Book Currency for book or NULL; determines
|
|
|
|
|
* that both book-currency and default gain/loss policy KVPs exist and that
|
|
|
|
|
* both are valid, a requirement for the 'book-currency' currency accounting
|
|
|
|
|
* method to apply. */
|
|
|
|
|
gnc_commodity *
|
2015-06-27 16:06:56 -07:00
|
|
|
gnc_book_get_book_currency (QofBook *book)
|
|
|
|
|
{
|
|
|
|
|
if (!book) return NULL;
|
|
|
|
|
|
|
|
|
|
if (gnc_book_use_book_currency (book))
|
2016-06-17 13:48:03 -07:00
|
|
|
return gnc_commodity_table_lookup
|
|
|
|
|
(gnc_commodity_table_get_table(book),
|
|
|
|
|
GNC_COMMODITY_NS_CURRENCY,
|
|
|
|
|
qof_book_get_book_currency_name (book));
|
2015-06-27 16:06:56 -07:00
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns pointer to default gain/loss policy for book or NULL; determines
|
|
|
|
|
* that both book-currency and default gain/loss policy KVPs exist and that
|
|
|
|
|
* both are valid, a requirement for the 'book-currency' currency accounting
|
|
|
|
|
* method to apply. */
|
|
|
|
|
const gchar *
|
|
|
|
|
gnc_book_get_default_gains_policy (QofBook *book)
|
|
|
|
|
{
|
|
|
|
|
if (!book) return NULL;
|
|
|
|
|
|
|
|
|
|
if (gnc_book_use_book_currency (book))
|
|
|
|
|
return qof_book_get_default_gains_policy (book);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 13:48:03 -07:00
|
|
|
/** Returns pointer to default gain/loss account for book or NULL; determines
|
|
|
|
|
* that both book-currency and default gain/loss policy KVPs exist and that
|
|
|
|
|
* both are valid, a requirement for the 'book-currency' currency accounting
|
2017-07-09 12:19:36 -07:00
|
|
|
* method to apply. Also, account must not be hidden or a placeholder, and
|
|
|
|
|
* must be of same currency as book-currency and income or expense type */
|
2016-06-17 13:48:03 -07:00
|
|
|
Account *
|
|
|
|
|
gnc_book_get_default_gain_loss_acct (QofBook *book)
|
|
|
|
|
{
|
|
|
|
|
Account *gains_account = NULL;
|
|
|
|
|
|
|
|
|
|
if (!book) return NULL;
|
|
|
|
|
|
|
|
|
|
if (gnc_book_use_book_currency (book))
|
|
|
|
|
gains_account = xaccAccountLookup
|
|
|
|
|
(qof_book_get_default_gain_loss_acct_guid (book), book);
|
|
|
|
|
|
2017-07-09 12:19:36 -07:00
|
|
|
if (gains_account &&
|
|
|
|
|
!xaccAccountGetPlaceholder(gains_account) &&
|
|
|
|
|
!xaccAccountGetHidden(gains_account) &&
|
|
|
|
|
(gnc_commodity_equal(xaccAccountGetCommodity(gains_account),
|
|
|
|
|
gnc_book_get_book_currency(book))) &&
|
|
|
|
|
((xaccAccountGetType(gains_account) == ACCT_TYPE_INCOME) ||
|
|
|
|
|
(xaccAccountGetType(gains_account) == ACCT_TYPE_EXPENSE)))
|
|
|
|
|
{
|
|
|
|
|
return gains_account;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2016-06-17 13:48:03 -07:00
|
|
|
}
|
|
|
|
|
|
2007-02-23 01:23:31 +00:00
|
|
|
Account *
|
|
|
|
|
gnc_get_current_root_account (void)
|
2001-09-18 07:26:42 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
return gnc_book_get_root_account (gnc_get_current_book ());
|
2001-09-18 07:26:42 +00:00
|
|
|
}
|
2001-08-20 10:08:09 +00:00
|
|
|
|
2001-10-03 10:07:45 +00:00
|
|
|
gnc_commodity_table *
|
|
|
|
|
gnc_get_current_commodities (void)
|
|
|
|
|
{
|
2010-10-16 14:05:29 +00:00
|
|
|
return gnc_commodity_table_get_table (gnc_get_current_book ());
|
2001-10-03 10:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-13 21:28:45 +00:00
|
|
|
gchar *
|
|
|
|
|
gnc_get_account_name_for_register(const Account *account)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gboolean show_leaf_accounts;
|
2013-10-07 14:08:17 +00:00
|
|
|
show_leaf_accounts = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
|
|
|
|
|
GNC_PREF_SHOW_LEAF_ACCT_NAMES);
|
2008-07-13 21:28:45 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (show_leaf_accounts)
|
|
|
|
|
return g_strdup (xaccAccountGetName (account));
|
|
|
|
|
else
|
|
|
|
|
return gnc_account_get_full_name (account);
|
2008-07-13 21:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Account *
|
|
|
|
|
gnc_account_lookup_for_register(const Account *base_account, const char *name)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gboolean show_leaf_accounts;
|
2013-10-07 14:08:17 +00:00
|
|
|
show_leaf_accounts = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
|
|
|
|
|
GNC_PREF_SHOW_LEAF_ACCT_NAMES);
|
2008-07-13 21:28:45 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (show_leaf_accounts)
|
|
|
|
|
return gnc_account_lookup_by_name (base_account, name);
|
|
|
|
|
else
|
|
|
|
|
return gnc_account_lookup_by_full_name (base_account, name);
|
2008-07-13 21:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
/* Caller is responsible for g_free'ing returned memory */
|
|
|
|
|
char *
|
2006-02-27 23:57:16 +00:00
|
|
|
gnc_ui_account_get_tax_info_string (const Account *account)
|
2001-08-19 11:15:56 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
static SCM get_form = SCM_UNDEFINED;
|
|
|
|
|
static SCM get_desc = SCM_UNDEFINED;
|
|
|
|
|
|
|
|
|
|
gboolean tax_related = FALSE;
|
2011-03-27 19:18:10 +00:00
|
|
|
const char *code;
|
2009-12-29 20:12:48 +00:00
|
|
|
|
|
|
|
|
if (!account)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2011-01-30 20:34:55 +00:00
|
|
|
tax_related = xaccAccountGetTaxRelated (account);
|
|
|
|
|
code = xaccAccountGetTaxUSCode (account);
|
|
|
|
|
|
|
|
|
|
if (!code)
|
2011-01-08 23:52:13 +00:00
|
|
|
{
|
2011-01-30 20:34:55 +00:00
|
|
|
if (!tax_related)
|
|
|
|
|
return NULL;
|
|
|
|
|
/* tax_related && !code */
|
|
|
|
|
else
|
2011-02-26 14:04:34 +00:00
|
|
|
/* Translators: This and the following strings appear on
|
|
|
|
|
* the account tab if the Tax Info column is displayed,
|
|
|
|
|
* i.e. if the user wants to record the tax form number
|
|
|
|
|
* and location on that tax form which corresponds to this
|
|
|
|
|
* gnucash account. For the US Income Tax support in
|
|
|
|
|
* gnucash, each tax code that can be assigned to an
|
|
|
|
|
* account generally corresponds to a specific line number
|
|
|
|
|
* on a paper form and each form has a unique
|
|
|
|
|
* identification (e.g., Form 1040, Schedule A). */
|
2011-01-30 20:34:55 +00:00
|
|
|
return g_strdup (_("Tax-related but has no tax code"));
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
|
|
|
|
else /* with tax code */
|
Bug #554394: Income Tax Enhancements
Patch by J. Alex Aycinena. Patch does the following:
- update the tax information in 'txf.scm', which is based on V037 of
the TXF Spec, to V041, the last version issued (bug #554394)
- provide support for multiple copies of certain tax Forms/Schedules
(e.g., Schedule C(1), Schedule C(2), etc.)
- support multiple types of tax entities: partnerships, corporations
and S corporations, in addition to individual tax payers
- support balance sheet accounts, required for these new tax entity types
- add the term 'Income' in several places to avoid confusion with
sales or VAT style taxes in the business features (e.g., change the
menu from 'Tax Options' to 'Income Tax Options')
The following files were changed, as follows, to implement these changes:
1. src/engine/Account.c and
2. src/engine/Account.h: add copy number capability (define
'xaccAccountGetTaxUSCopyNumber' and 'xaccAccountSetTaxUSCopyNumber');
modify 'xaccAccountSetTaxUSCode' to remove KVP when no tax-code
assigned, clean up tax-source descriptions
3. src/gnome/gnc-plugin-basic-commands.c: change 'Tax Options' to
'Income Tax Options'
4. src/app-utils/gnc-ui-util.c and
5. src/app-utils/gnc-ui-util.h: add setter and getter functions for
book tax name and book tax type which are stored in a book KVP, show
copy information in accounts page, tax column, show error messages for
various conditions
6. src/app-utils/app-utils.i: add 'gnc_get_current_book_tax_name' and
'gnc_get_current_book_tax_type' functions
7. src/gnome/dialog-tax-info.c: add copy number and tax entity name
and type, and balance sheet account handling capability
8. src/gnome/glade/tax.glade: add tax entity name, tax entity type,
asset, liability/equity and copy number widgets
9. src/tax/us/txf.scm: update to V041 for individuals, add V041
support for multiple additional tax entity types and balance sheet
accounts and related tax codes, add tax form line data
10. src/tax/us/us.scm: export new functions defined in txf.scm
11. src/report/locale-specific/us/taxtxf.scm: add support for multiple
copies of Forms/Schedules, add support for Format 6, use Form/Schedule
line #'s to sort report, update from "V037" to "V041", add support for
taxpayer types other than F1040, add warning messages if there are
some inconsistent codes assigned and list
12. src/tax/us/txf-de_DE.scm: make functions called from outside (e.g., from
dialog-tax-info.c) have a consistent signature with those same
functions in txf.scm (define tax-entity-type , define getters/setters,
add tax-entity-type as an argument to existing functions)
13. src/tax/us/de_DE.scm: export new functions added to txf-de_DE.scm
14. src/report/locale-specific/us/taxtxf-de_DE.scm: add "" as
tax-entity-type argument to functions
called on txf-de_DE.scm (which defaults to existing codes)
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18413 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-11-15 20:35:50 +00:00
|
|
|
{
|
2011-05-11 22:17:56 +00:00
|
|
|
const gchar *tax_type;
|
|
|
|
|
GNCAccountType atype;
|
|
|
|
|
SCM tax_entity_type;
|
|
|
|
|
SCM category;
|
|
|
|
|
gchar *num_code = NULL;
|
2010-09-27 15:58:52 +00:00
|
|
|
const gchar *prefix = "N";
|
2011-05-11 22:17:56 +00:00
|
|
|
gchar *return_string = NULL;
|
2010-10-03 12:27:44 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
tax_type = gnc_get_current_book_tax_type ();
|
2012-08-07 17:24:55 +00:00
|
|
|
if (tax_type == NULL || (g_strcmp0 (tax_type, "") == 0))
|
2011-01-30 20:34:55 +00:00
|
|
|
return g_strdup (_("Tax entity type not specified"));
|
2011-05-03 00:06:11 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
atype = xaccAccountGetType (account);
|
2013-12-13 20:21:41 +00:00
|
|
|
tax_entity_type = scm_from_utf8_string (tax_type);
|
2009-12-29 20:12:48 +00:00
|
|
|
|
|
|
|
|
if (get_form == SCM_UNDEFINED)
|
|
|
|
|
{
|
|
|
|
|
GNCModule module;
|
|
|
|
|
const gchar *tax_module;
|
|
|
|
|
/* load the tax info */
|
|
|
|
|
/* This is a very simple hack that loads the (new, special) German
|
|
|
|
|
tax definition file in a German locale, or (default) loads the
|
2017-10-20 20:50:33 +02:00
|
|
|
US tax file. */
|
2007-04-22 00:48:03 +00:00
|
|
|
# ifdef G_OS_WIN32
|
2009-12-29 20:12:48 +00:00
|
|
|
gchar *thislocale = g_win32_getlocale();
|
|
|
|
|
gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
|
|
|
|
|
g_free(thislocale);
|
2007-04-22 00:48:03 +00:00
|
|
|
# else /* !G_OS_WIN32 */
|
2009-12-29 20:12:48 +00:00
|
|
|
const char *thislocale = setlocale(LC_ALL, NULL);
|
|
|
|
|
gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
|
2007-04-22 00:48:03 +00:00
|
|
|
# endif /* G_OS_WIN32 */
|
2009-12-29 20:12:48 +00:00
|
|
|
tax_module = is_de_DE ?
|
|
|
|
|
"gnucash/tax/de_DE" :
|
|
|
|
|
"gnucash/tax/us";
|
2001-08-19 11:15:56 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
module = gnc_module_load ((char *)tax_module, 0);
|
2001-08-19 11:15:56 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
g_return_val_if_fail (module, NULL);
|
2001-08-19 11:15:56 +00:00
|
|
|
|
2011-05-03 00:06:11 +00:00
|
|
|
get_form = scm_c_eval_string
|
2011-08-22 07:10:56 +00:00
|
|
|
("(false-if-exception gnc:txf-get-form)");
|
2009-12-29 20:12:48 +00:00
|
|
|
get_desc = scm_c_eval_string
|
2011-08-22 07:10:56 +00:00
|
|
|
("(false-if-exception gnc:txf-get-description)");
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
2001-08-19 11:15:56 +00:00
|
|
|
|
2009-12-31 14:41:12 +00:00
|
|
|
g_return_val_if_fail (scm_is_procedure (get_form), NULL);
|
|
|
|
|
g_return_val_if_fail (scm_is_procedure (get_desc), NULL);
|
2009-12-29 20:12:48 +00:00
|
|
|
|
|
|
|
|
category = scm_c_eval_string (atype == ACCT_TYPE_INCOME ?
|
|
|
|
|
"txf-income-categories" :
|
|
|
|
|
(atype == ACCT_TYPE_EXPENSE ?
|
|
|
|
|
"txf-expense-categories" :
|
|
|
|
|
(((atype == ACCT_TYPE_BANK) ||
|
|
|
|
|
(atype == ACCT_TYPE_CASH) ||
|
|
|
|
|
(atype == ACCT_TYPE_ASSET) ||
|
|
|
|
|
(atype == ACCT_TYPE_STOCK) ||
|
|
|
|
|
(atype == ACCT_TYPE_MUTUAL) ||
|
|
|
|
|
(atype == ACCT_TYPE_RECEIVABLE)) ?
|
|
|
|
|
"txf-asset-categories" :
|
|
|
|
|
(((atype == ACCT_TYPE_CREDIT) ||
|
|
|
|
|
(atype == ACCT_TYPE_LIABILITY) ||
|
|
|
|
|
(atype == ACCT_TYPE_EQUITY) ||
|
|
|
|
|
(atype == ACCT_TYPE_PAYABLE)) ?
|
|
|
|
|
"txf-liab-eq-categories" : ""))));
|
|
|
|
|
|
2011-05-11 22:17:56 +00:00
|
|
|
if (g_str_has_prefix (code, prefix))
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
2011-05-11 22:17:56 +00:00
|
|
|
const gchar *num_code_tmp;
|
|
|
|
|
num_code_tmp = g_strdup (code);
|
|
|
|
|
num_code_tmp++; /* to lose the leading N */
|
|
|
|
|
num_code = g_strdup (num_code_tmp);
|
|
|
|
|
num_code_tmp--;
|
|
|
|
|
g_free ((gpointer *) num_code_tmp);
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
2011-05-11 22:17:56 +00:00
|
|
|
else
|
2010-09-27 15:58:52 +00:00
|
|
|
{
|
2011-05-11 22:17:56 +00:00
|
|
|
num_code = g_strdup (code);
|
2011-03-27 19:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-11 22:17:56 +00:00
|
|
|
if (category == SCM_UNDEFINED)
|
2011-03-27 19:18:10 +00:00
|
|
|
{
|
|
|
|
|
if (tax_related)
|
2011-05-11 22:17:56 +00:00
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Tax type %s: invalid code %s for account type"),
|
|
|
|
|
tax_type, num_code);
|
2010-09-27 15:58:52 +00:00
|
|
|
else
|
2011-05-11 22:17:56 +00:00
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Not tax-related; tax type %s: invalid code %s for account type"),
|
|
|
|
|
tax_type, num_code);
|
2010-09-27 15:58:52 +00:00
|
|
|
}
|
2011-05-11 22:17:56 +00:00
|
|
|
else
|
2011-03-27 19:18:10 +00:00
|
|
|
{
|
2011-05-11 22:17:56 +00:00
|
|
|
SCM code_scm;
|
|
|
|
|
SCM form_scm;
|
2012-12-15 17:58:58 +00:00
|
|
|
code_scm = scm_from_locale_symbol (code);
|
2011-05-11 22:17:56 +00:00
|
|
|
form_scm = scm_call_3 (get_form, category, code_scm, tax_entity_type);
|
|
|
|
|
if (!scm_is_string (form_scm))
|
|
|
|
|
{
|
|
|
|
|
if (tax_related)
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Invalid code %s for tax type %s"),
|
|
|
|
|
num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
else
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Not tax-related; invalid code %s for tax type %s"),
|
|
|
|
|
num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
2011-03-27 19:18:10 +00:00
|
|
|
else
|
2011-05-11 22:17:56 +00:00
|
|
|
{
|
|
|
|
|
gchar *form = NULL;
|
2012-12-22 18:20:39 +00:00
|
|
|
|
2013-12-13 20:21:41 +00:00
|
|
|
/* Note: using scm_to_utf8_string directly here instead
|
|
|
|
|
of our wrapper gnc_scm_to_utf8_string. 'form' should
|
2012-12-22 18:20:39 +00:00
|
|
|
be freed with 'free' instead of 'g_free'. This will
|
|
|
|
|
be taken care of automatically during scm_dynwind_end,
|
|
|
|
|
because we inform guile of this memory allocation via
|
|
|
|
|
scm_dynwind_free a little further. */
|
2013-12-13 20:21:41 +00:00
|
|
|
form = scm_to_utf8_string (form_scm);
|
2011-05-11 22:17:56 +00:00
|
|
|
if (!form)
|
|
|
|
|
{
|
|
|
|
|
if (tax_related)
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("No form: code %s, tax type %s"), num_code,
|
|
|
|
|
tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
else
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Not tax-related; no form: code %s, tax type %s"),
|
|
|
|
|
num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SCM desc_scm;
|
2012-12-22 18:20:39 +00:00
|
|
|
|
|
|
|
|
/* Create a dynwind context because we will be calling (scm) functions
|
|
|
|
|
that potentially exit non-locally */
|
|
|
|
|
scm_dynwind_begin (0);
|
|
|
|
|
scm_dynwind_free (form);
|
2011-05-11 22:17:56 +00:00
|
|
|
desc_scm = scm_call_3 (get_desc, category, code_scm,
|
2011-08-22 07:10:56 +00:00
|
|
|
tax_entity_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
if (!scm_is_string (desc_scm))
|
|
|
|
|
{
|
|
|
|
|
if (tax_related)
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("No description: form %s, code %s, tax type %s"),
|
|
|
|
|
form, num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
else
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Not tax-related; no description: form %s, code %s, tax type %s"),
|
|
|
|
|
form, num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gchar *desc = NULL;
|
2013-12-13 20:21:41 +00:00
|
|
|
desc = gnc_scm_to_utf8_string (desc_scm);
|
2011-05-11 22:17:56 +00:00
|
|
|
if (!desc)
|
|
|
|
|
{
|
|
|
|
|
if (tax_related)
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("No description: form %s, code %s, tax type %s"),
|
|
|
|
|
form, num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
else
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Not tax-related; no description: form %s, code %s, tax type %s"),
|
|
|
|
|
form, num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gint64 copy_number;
|
|
|
|
|
gchar *copy_txt = NULL;
|
|
|
|
|
copy_number = xaccAccountGetTaxUSCopyNumber (account);
|
|
|
|
|
copy_txt = (copy_number == 1) ?
|
2011-08-22 07:10:56 +00:00
|
|
|
g_strdup ("") :
|
|
|
|
|
g_strdup_printf ("(%d)",
|
|
|
|
|
(gint) copy_number);
|
2011-05-11 22:17:56 +00:00
|
|
|
if (tax_related)
|
|
|
|
|
{
|
2012-08-07 17:24:55 +00:00
|
|
|
if (g_strcmp0 (form, "") == 0)
|
2011-05-11 22:17:56 +00:00
|
|
|
return_string = g_strdup_printf ("%s", desc);
|
|
|
|
|
else
|
|
|
|
|
return_string = g_strdup_printf ("%s%s: %s",
|
2011-08-22 07:10:56 +00:00
|
|
|
form, copy_txt, desc);
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return_string = g_strdup_printf
|
2011-08-22 07:10:56 +00:00
|
|
|
(_("Not tax-related; %s%s: %s (code %s, tax type %s)"),
|
|
|
|
|
form, copy_txt, desc, num_code, tax_type);
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
|
|
|
|
g_free (copy_txt);
|
|
|
|
|
}
|
2012-12-22 18:20:39 +00:00
|
|
|
g_free (desc);
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
2012-12-22 18:20:39 +00:00
|
|
|
scm_dynwind_end ();
|
2011-05-11 22:17:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-03-27 19:18:10 +00:00
|
|
|
}
|
2011-05-11 22:17:56 +00:00
|
|
|
g_free (num_code);
|
|
|
|
|
return return_string;
|
2011-01-30 20:34:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Caller is responsible for g_free'ing returned memory */
|
|
|
|
|
char *
|
|
|
|
|
gnc_ui_account_get_tax_info_sub_acct_string (const Account *account)
|
|
|
|
|
{
|
|
|
|
|
GList *descendant, *account_descendants;
|
|
|
|
|
|
|
|
|
|
if (!account)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
account_descendants = gnc_account_get_descendants (account);
|
|
|
|
|
if (account_descendants)
|
|
|
|
|
{
|
|
|
|
|
gint sub_acct_tax_number = 0;
|
|
|
|
|
for (descendant = account_descendants; descendant;
|
|
|
|
|
descendant = g_list_next(descendant))
|
2011-01-24 14:10:09 +00:00
|
|
|
{
|
2011-01-30 20:34:55 +00:00
|
|
|
if (xaccAccountGetTaxRelated (descendant->data))
|
|
|
|
|
sub_acct_tax_number++;
|
2011-01-24 14:10:09 +00:00
|
|
|
}
|
2011-03-03 00:30:10 +00:00
|
|
|
g_list_free (account_descendants);
|
|
|
|
|
g_list_free (descendant);
|
2011-01-30 20:34:55 +00:00
|
|
|
/* Translators: This and the following strings appear on
|
|
|
|
|
* the account tab if the Tax Info column is displayed,
|
|
|
|
|
* i.e. if the user wants to record the tax form number
|
|
|
|
|
* and location on that tax form which corresponds to this
|
|
|
|
|
* gnucash account. For the US Income Tax support in
|
|
|
|
|
* gnucash, each tax code that can be assigned to an
|
|
|
|
|
* account generally corresponds to a specific line number
|
|
|
|
|
* on a paper form and each form has a unique
|
|
|
|
|
* identification (e.g., Form 1040, Schedule A). */
|
2011-05-11 22:17:56 +00:00
|
|
|
return (sub_acct_tax_number == 0) ? NULL :
|
2011-02-26 14:04:34 +00:00
|
|
|
g_strdup_printf (_("(Tax-related subaccounts: %d)"),
|
|
|
|
|
sub_acct_tax_number);
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
2011-01-30 20:34:55 +00:00
|
|
|
else
|
2011-05-11 22:17:56 +00:00
|
|
|
return NULL;
|
2000-11-29 20:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
2006-04-30 10:32:34 +00:00
|
|
|
static const char *
|
|
|
|
|
string_after_colon (const char *msgstr)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
const char *string_at_colon;
|
|
|
|
|
g_assert(msgstr);
|
|
|
|
|
string_at_colon = strchr(msgstr, ':');
|
|
|
|
|
if (string_at_colon)
|
|
|
|
|
return string_at_colon + 1;
|
|
|
|
|
else
|
|
|
|
|
/* No colon found; we assume the translation contains only the
|
|
|
|
|
part after the colon, similar to the disambiguation prefixes */
|
|
|
|
|
return msgstr;
|
2006-04-30 10:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-29 20:40:25 +00:00
|
|
|
/********************************************************************\
|
|
|
|
|
* gnc_get_reconcile_str *
|
|
|
|
|
* return the i18n'd string for the given reconciled flag *
|
|
|
|
|
* *
|
2011-08-13 15:33:17 +00:00
|
|
|
* Args: reconciled_flag - the flag to convert into a string *
|
2000-11-29 20:40:25 +00:00
|
|
|
* Returns: the i18n'd reconciled string *
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
const char *
|
|
|
|
|
gnc_get_reconcile_str (char reconciled_flag)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
switch (reconciled_flag)
|
|
|
|
|
{
|
2010-06-25 18:22:59 +00:00
|
|
|
case NREC:
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Translators: For the following strings, the single letters
|
|
|
|
|
after the colon are abbreviations of the word before the
|
|
|
|
|
colon. You should only translate the letter *after* the colon. */
|
|
|
|
|
return string_after_colon(_("not cleared:n"));
|
|
|
|
|
case CREC:
|
|
|
|
|
/* Translators: Please only translate the letter *after* the colon. */
|
2010-06-25 18:22:59 +00:00
|
|
|
return string_after_colon(_("cleared:c"));
|
2009-12-29 20:12:48 +00:00
|
|
|
case YREC:
|
|
|
|
|
/* Translators: Please only translate the letter *after* the colon. */
|
2010-06-25 18:22:59 +00:00
|
|
|
return string_after_colon(_("reconciled:y"));
|
2009-12-29 20:12:48 +00:00
|
|
|
case FREC:
|
|
|
|
|
/* Translators: Please only translate the letter *after* the colon. */
|
2010-06-25 18:22:59 +00:00
|
|
|
return string_after_colon(_("frozen:f"));
|
2009-12-29 20:12:48 +00:00
|
|
|
case VREC:
|
2010-06-25 18:22:59 +00:00
|
|
|
/* Translators: Please only translate the letter *after* the colon. */
|
2009-12-29 20:12:48 +00:00
|
|
|
return string_after_colon(_("void:v"));
|
2000-11-29 20:40:25 +00:00
|
|
|
default:
|
2009-12-29 20:12:48 +00:00
|
|
|
PERR("Bad reconciled flag\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2000-11-29 20:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
2001-11-29 03:00:06 +00:00
|
|
|
/********************************************************************\
|
2001-11-30 02:11:24 +00:00
|
|
|
* gnc_get_reconcile_valid_flags *
|
|
|
|
|
* return a string containing the list of reconciled flags *
|
2001-11-29 03:00:06 +00:00
|
|
|
* *
|
|
|
|
|
* Returns: the i18n'd reconciled flags string *
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
const char *
|
2001-11-30 02:11:24 +00:00
|
|
|
gnc_get_reconcile_valid_flags (void)
|
2001-11-29 03:00:06 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
static const char flags[] = { NREC, CREC, YREC, FREC, VREC, 0 };
|
|
|
|
|
return flags;
|
2001-11-29 03:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************************************************************\
|
2001-11-30 02:11:24 +00:00
|
|
|
* gnc_get_reconcile_flag_order *
|
|
|
|
|
* return a string containing the reconciled-flag change order *
|
2001-11-29 03:00:06 +00:00
|
|
|
* *
|
2011-08-13 15:33:17 +00:00
|
|
|
* Args: reconciled_flag - the flag to convert into a string *
|
2001-11-29 03:00:06 +00:00
|
|
|
* Returns: the i18n'd reconciled string *
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
const char *
|
2001-11-30 02:11:24 +00:00
|
|
|
gnc_get_reconcile_flag_order (void)
|
2001-11-29 03:00:06 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
static const char flags[] = { NREC, CREC, 0 };
|
|
|
|
|
return flags;
|
2001-11-29 03:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-29 20:40:25 +00:00
|
|
|
|
2001-04-03 10:18:59 +00:00
|
|
|
static const char *
|
|
|
|
|
equity_base_name (GNCEquityType equity_type)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
switch (equity_type)
|
|
|
|
|
{
|
2001-04-03 10:18:59 +00:00
|
|
|
case EQUITY_OPENING_BALANCE:
|
2009-12-29 20:12:48 +00:00
|
|
|
return N_("Opening Balances");
|
2001-04-03 10:18:59 +00:00
|
|
|
|
|
|
|
|
case EQUITY_RETAINED_EARNINGS:
|
2009-12-29 20:12:48 +00:00
|
|
|
return N_("Retained Earnings");
|
2001-04-03 10:18:59 +00:00
|
|
|
|
|
|
|
|
default:
|
2009-12-29 20:12:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2001-04-03 10:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Account *
|
2007-03-03 16:41:42 +00:00
|
|
|
gnc_find_or_create_equity_account (Account *root,
|
2001-06-09 07:35:24 +00:00
|
|
|
GNCEquityType equity_type,
|
2007-02-23 01:23:31 +00:00
|
|
|
gnc_commodity *currency)
|
2001-04-03 10:18:59 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
Account *parent;
|
|
|
|
|
Account *account;
|
|
|
|
|
gboolean name_exists;
|
|
|
|
|
gboolean base_name_exists;
|
|
|
|
|
const char *base_name;
|
|
|
|
|
char *name;
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
g_return_val_if_fail (equity_type >= 0, NULL);
|
|
|
|
|
g_return_val_if_fail (equity_type < NUM_EQUITY_TYPES, NULL);
|
|
|
|
|
g_return_val_if_fail (currency != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (root != NULL, NULL);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
base_name = equity_base_name (equity_type);
|
2001-06-09 06:50:25 +00:00
|
|
|
|
2007-02-23 01:23:31 +00:00
|
|
|
account = gnc_account_lookup_by_name(root, base_name);
|
2006-08-06 22:07:12 +00:00
|
|
|
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
|
2009-12-29 20:12:48 +00:00
|
|
|
account = NULL;
|
2001-06-09 06:50:25 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!account)
|
|
|
|
|
{
|
|
|
|
|
base_name = base_name && *base_name ? _(base_name) : "";
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
account = gnc_account_lookup_by_name(root, base_name);
|
|
|
|
|
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
|
|
|
|
|
account = NULL;
|
|
|
|
|
}
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
base_name_exists = (account != NULL);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (account &&
|
|
|
|
|
gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
|
|
|
|
|
return account;
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
name = g_strconcat (base_name, " - ",
|
|
|
|
|
gnc_commodity_get_mnemonic (currency), NULL);
|
|
|
|
|
account = gnc_account_lookup_by_name(root, name);
|
|
|
|
|
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
|
|
|
|
|
account = NULL;
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
name_exists = (account != NULL);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (account &&
|
|
|
|
|
gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
|
|
|
|
|
return account;
|
|
|
|
|
|
|
|
|
|
/* Couldn't find one, so create it */
|
|
|
|
|
if (name_exists && base_name_exists)
|
|
|
|
|
{
|
|
|
|
|
PWARN ("equity account with unexpected currency");
|
|
|
|
|
g_free (name);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!base_name_exists &&
|
|
|
|
|
gnc_commodity_equiv (currency, gnc_default_currency ()))
|
|
|
|
|
{
|
|
|
|
|
g_free (name);
|
|
|
|
|
name = g_strdup (base_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent = gnc_account_lookup_by_name(root, _("Equity"));
|
|
|
|
|
if (!parent || xaccAccountGetType (parent) != ACCT_TYPE_EQUITY)
|
|
|
|
|
parent = root;
|
|
|
|
|
g_assert(parent);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
account = xaccMallocAccount (gnc_account_get_book(root));
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccAccountBeginEdit (account);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccAccountSetName (account, name);
|
|
|
|
|
xaccAccountSetType (account, ACCT_TYPE_EQUITY);
|
|
|
|
|
xaccAccountSetCommodity (account, currency);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccAccountBeginEdit (parent);
|
|
|
|
|
gnc_account_append_child (parent, account);
|
|
|
|
|
xaccAccountCommitEdit (parent);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccAccountCommitEdit (account);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
g_free (name);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return account;
|
2001-04-03 10:18:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gnc_account_create_opening_balance (Account *account,
|
|
|
|
|
gnc_numeric balance,
|
2012-12-01 22:44:41 +00:00
|
|
|
time64 date,
|
2003-06-27 02:38:40 +00:00
|
|
|
QofBook *book)
|
2001-04-03 10:18:59 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
Account *equity_account;
|
|
|
|
|
Transaction *trans;
|
|
|
|
|
Split *split;
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (gnc_numeric_zero_p (balance))
|
|
|
|
|
return TRUE;
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
g_return_val_if_fail (account != NULL, FALSE);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
equity_account =
|
|
|
|
|
gnc_find_or_create_equity_account (gnc_account_get_root(account),
|
|
|
|
|
EQUITY_OPENING_BALANCE,
|
|
|
|
|
xaccAccountGetCommodity (account));
|
|
|
|
|
if (!equity_account)
|
|
|
|
|
return FALSE;
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccAccountBeginEdit (account);
|
|
|
|
|
xaccAccountBeginEdit (equity_account);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
trans = xaccMallocTransaction (book);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccTransBeginEdit (trans);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2013-06-19 15:47:39 +00:00
|
|
|
xaccTransSetCurrency (trans, gnc_account_or_default_currency (account, NULL));
|
2013-06-09 21:33:19 +00:00
|
|
|
xaccTransSetDatePostedSecsNormalized (trans, date);
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccTransSetDescription (trans, _("Opening Balance"));
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
split = xaccMallocSplit (book);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccTransAppendSplit (trans, split);
|
|
|
|
|
xaccAccountInsertSplit (account, split);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccSplitSetAmount (split, balance);
|
|
|
|
|
xaccSplitSetValue (split, balance);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
balance = gnc_numeric_neg (balance);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
split = xaccMallocSplit (book);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccTransAppendSplit (trans, split);
|
|
|
|
|
xaccAccountInsertSplit (equity_account, split);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccSplitSetAmount (split, balance);
|
|
|
|
|
xaccSplitSetValue (split, balance);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
xaccTransCommitEdit (trans);
|
|
|
|
|
xaccAccountCommitEdit (equity_account);
|
|
|
|
|
xaccAccountCommitEdit (account);
|
2001-04-03 10:18:59 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return TRUE;
|
2001-04-03 10:18:59 +00:00
|
|
|
}
|
2000-11-29 20:40:25 +00:00
|
|
|
|
2012-05-26 23:47:34 +00:00
|
|
|
#if 0 /* Not Used */
|
2000-11-01 08:52:30 +00:00
|
|
|
static void
|
2005-11-02 03:32:36 +00:00
|
|
|
gnc_lconv_set_utf8 (char **p_value, char *default_value)
|
2000-10-31 01:27:31 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
char *value = *p_value;
|
|
|
|
|
*p_value = NULL;
|
2000-10-31 01:27:31 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if ((value == NULL) || (value[0] == 0))
|
|
|
|
|
value = default_value;
|
2001-03-30 12:43:11 +00:00
|
|
|
|
2007-02-06 03:37:17 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
|
|
|
|
/* get number of resulting wide characters */
|
|
|
|
|
size_t count = mbstowcs (NULL, value, 0);
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
/* malloc and convert */
|
|
|
|
|
wchar_t *wvalue = g_malloc ((count + 1) * sizeof(wchar_t));
|
|
|
|
|
count = mbstowcs (wvalue, value, count + 1);
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
*p_value = g_utf16_to_utf8 (wvalue, -1, NULL, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
g_free (wvalue);
|
|
|
|
|
}
|
2007-02-06 03:37:17 +00:00
|
|
|
}
|
|
|
|
|
#else /* !G_OS_WIN32 */
|
2009-12-29 20:12:48 +00:00
|
|
|
*p_value = g_locale_to_utf8 (value, -1, NULL, NULL, NULL);
|
2007-02-06 03:37:17 +00:00
|
|
|
#endif
|
2009-12-29 20:12:48 +00:00
|
|
|
|
|
|
|
|
if (*p_value == NULL)
|
|
|
|
|
{
|
|
|
|
|
// The g_locale_to_utf8 conversion failed. FIXME: Should we rather
|
|
|
|
|
// use an empty string instead of the default_value? Not sure.
|
|
|
|
|
*p_value = default_value;
|
|
|
|
|
}
|
2000-10-31 01:27:31 +00:00
|
|
|
}
|
2000-06-05 05:51:39 +00:00
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
static void
|
2000-11-29 20:40:25 +00:00
|
|
|
gnc_lconv_set_char (char *p_value, char default_value)
|
2000-06-30 06:12:37 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
if ((p_value != NULL) && (*p_value == CHAR_MAX))
|
|
|
|
|
*p_value = default_value;
|
2000-08-27 08:25:53 +00:00
|
|
|
}
|
2012-05-26 23:47:34 +00:00
|
|
|
#endif /* Not Used */
|
2000-05-25 18:30:24 +00:00
|
|
|
|
2001-10-03 10:07:45 +00:00
|
|
|
gnc_commodity *
|
2002-11-30 13:38:34 +00:00
|
|
|
gnc_locale_default_currency_nodefault (void)
|
2001-10-03 10:07:45 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_commodity * currency;
|
|
|
|
|
gnc_commodity_table *table;
|
|
|
|
|
const char *code;
|
2001-04-30 06:56:00 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
table = gnc_get_current_commodities ();
|
|
|
|
|
code = gnc_locale_default_iso_currency_code ();
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
currency = gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, code);
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Some very old locales (notably on win32) still announce a euro
|
|
|
|
|
currency as default, although it has been replaced by EUR in
|
|
|
|
|
2001. We use EUR as default in that case, but the user can always
|
2013-10-07 14:08:17 +00:00
|
|
|
override from gsettings. */
|
2009-12-29 20:12:48 +00:00
|
|
|
if (gnc_is_euro_currency (currency))
|
|
|
|
|
currency = gnc_get_euro();
|
2007-06-19 19:40:49 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return (currency ? currency : NULL);
|
2002-11-30 13:38:34 +00:00
|
|
|
}
|
2000-05-25 18:30:24 +00:00
|
|
|
|
2002-11-30 13:38:34 +00:00
|
|
|
gnc_commodity *
|
|
|
|
|
gnc_locale_default_currency (void)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_commodity * currency = gnc_locale_default_currency_nodefault ();
|
2002-11-30 13:38:34 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return (currency ? currency :
|
|
|
|
|
gnc_commodity_table_lookup (gnc_get_current_commodities (),
|
|
|
|
|
GNC_COMMODITY_NS_CURRENCY, "USD"));
|
2000-05-25 18:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-10-14 21:00:46 +00:00
|
|
|
static gnc_commodity *
|
|
|
|
|
gnc_default_currency_common (gchar *requested_currency,
|
2013-10-07 14:08:17 +00:00
|
|
|
const gchar *section)
|
2005-11-02 03:32:36 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_commodity *currency = NULL;
|
2013-10-07 14:16:36 +00:00
|
|
|
gchar *mnemonic;
|
2009-12-29 20:12:48 +00:00
|
|
|
|
2010-10-14 21:00:46 +00:00
|
|
|
if (requested_currency)
|
2009-12-29 20:12:48 +00:00
|
|
|
return gnc_commodity_table_lookup(gnc_get_current_commodities(),
|
|
|
|
|
GNC_COMMODITY_NS_CURRENCY,
|
2010-10-14 21:00:46 +00:00
|
|
|
requested_currency);
|
2009-12-29 20:12:48 +00:00
|
|
|
|
2016-06-17 13:48:03 -07:00
|
|
|
if (gnc_book_use_book_currency (gnc_get_current_book ()))
|
|
|
|
|
return gnc_book_get_book_currency (gnc_get_current_book ());
|
|
|
|
|
|
2013-10-07 14:16:36 +00:00
|
|
|
if (gnc_prefs_get_bool (section, GNC_PREF_CURRENCY_CHOICE_OTHER))
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
2013-10-07 14:08:17 +00:00
|
|
|
mnemonic = gnc_prefs_get_string(section, GNC_PREF_CURRENCY_OTHER);
|
2009-12-29 20:12:48 +00:00
|
|
|
currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
|
|
|
|
|
GNC_COMMODITY_NS_CURRENCY, mnemonic);
|
|
|
|
|
DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
|
|
|
|
|
g_free(mnemonic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!currency)
|
|
|
|
|
currency = gnc_locale_default_currency ();
|
|
|
|
|
if (currency)
|
|
|
|
|
{
|
2010-10-14 21:00:46 +00:00
|
|
|
mnemonic = requested_currency;
|
2010-12-31 01:38:37 +00:00
|
|
|
// ??? Does anyone know what this is supposed to be doing?
|
|
|
|
|
// requested_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
|
2009-12-29 20:12:48 +00:00
|
|
|
g_free(mnemonic);
|
|
|
|
|
}
|
|
|
|
|
return currency;
|
2005-11-02 03:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gnc_commodity *
|
2010-10-14 21:00:46 +00:00
|
|
|
gnc_default_currency (void)
|
2005-11-02 03:32:36 +00:00
|
|
|
{
|
2013-10-07 14:08:17 +00:00
|
|
|
return gnc_default_currency_common (user_default_currency, GNC_PREFS_GROUP_GENERAL);
|
2006-03-08 05:14:54 +00:00
|
|
|
}
|
2005-11-02 03:32:36 +00:00
|
|
|
|
2013-06-19 15:47:27 +00:00
|
|
|
gnc_commodity * gnc_account_or_default_currency(const Account* account, gboolean * currency_from_account_found)
|
|
|
|
|
{
|
|
|
|
|
gnc_commodity *currency;
|
|
|
|
|
if (!account)
|
|
|
|
|
{
|
|
|
|
|
if (currency_from_account_found)
|
|
|
|
|
*currency_from_account_found = FALSE;
|
|
|
|
|
return gnc_default_currency();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currency = gnc_account_get_currency_or_parent(account);
|
|
|
|
|
if (currency)
|
|
|
|
|
{
|
|
|
|
|
if (currency_from_account_found)
|
|
|
|
|
*currency_from_account_found = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (currency_from_account_found)
|
|
|
|
|
*currency_from_account_found = FALSE;
|
|
|
|
|
currency = gnc_default_currency();
|
|
|
|
|
}
|
|
|
|
|
return currency;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-14 21:00:46 +00:00
|
|
|
gnc_commodity *
|
|
|
|
|
gnc_default_report_currency (void)
|
|
|
|
|
{
|
2013-10-07 14:08:17 +00:00
|
|
|
return gnc_default_currency_common (user_report_currency, GNC_PREFS_GROUP_GENERAL_REPORT);
|
2010-10-14 21:00:46 +00:00
|
|
|
}
|
2006-03-08 05:14:54 +00:00
|
|
|
|
|
|
|
|
static void
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_currency_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
|
2006-03-08 05:14:54 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
user_default_currency = NULL;
|
|
|
|
|
user_report_currency = NULL;
|
|
|
|
|
gnc_hook_run(HOOK_CURRENCY_CHANGED, NULL);
|
2005-11-02 03:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
GNCPrintAmountInfo
|
|
|
|
|
gnc_default_print_info (gboolean use_symbol)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
static GNCPrintAmountInfo info;
|
|
|
|
|
static gboolean got_it = FALSE;
|
|
|
|
|
struct lconv *lc;
|
2000-03-24 09:47:27 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* These must be updated each time. */
|
|
|
|
|
info.use_symbol = use_symbol ? 1 : 0;
|
|
|
|
|
info.commodity = gnc_default_currency ();
|
2001-10-03 10:07:45 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (got_it)
|
|
|
|
|
return info;
|
2000-03-24 09:47:27 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
lc = gnc_localeconv ();
|
2000-03-24 09:47:27 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info.max_decimal_places = lc->frac_digits;
|
|
|
|
|
info.min_decimal_places = lc->frac_digits;
|
2000-03-24 09:47:27 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info.use_separators = 1;
|
|
|
|
|
info.use_locale = 1;
|
|
|
|
|
info.monetary = 1;
|
|
|
|
|
info.force_fit = 0;
|
|
|
|
|
info.round = 0;
|
1999-07-05 22:47:57 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
got_it = TRUE;
|
2000-11-01 08:52:30 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info;
|
1999-07-05 22:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
static gboolean
|
2000-11-08 10:53:39 +00:00
|
|
|
is_decimal_fraction (int fraction, guint8 *max_decimal_places_p)
|
2000-11-01 08:52:30 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
guint8 max_decimal_places = 0;
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (fraction <= 0)
|
|
|
|
|
return FALSE;
|
1997-12-06 02:59:44 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
while (fraction != 1)
|
|
|
|
|
{
|
|
|
|
|
if (fraction % 10 != 0)
|
|
|
|
|
return FALSE;
|
2000-11-08 10:53:39 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
fraction = fraction / 10;
|
|
|
|
|
max_decimal_places += 1;
|
|
|
|
|
}
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (max_decimal_places_p)
|
|
|
|
|
*max_decimal_places_p = max_decimal_places;
|
2000-11-08 10:53:39 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return TRUE;
|
2000-01-17 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
GNCPrintAmountInfo
|
2001-04-30 06:56:00 +00:00
|
|
|
gnc_commodity_print_info (const gnc_commodity *commodity,
|
2000-11-01 08:52:30 +00:00
|
|
|
gboolean use_symbol)
|
2000-02-27 21:33:56 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
GNCPrintAmountInfo info;
|
|
|
|
|
gboolean is_iso;
|
2000-11-01 08:52:30 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (commodity == NULL)
|
|
|
|
|
return gnc_default_print_info (use_symbol);
|
2000-11-01 08:52:30 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info.commodity = commodity;
|
2000-11-01 08:52:30 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
is_iso = gnc_commodity_is_iso (commodity);
|
2000-11-01 08:52:30 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (is_decimal_fraction (gnc_commodity_get_fraction (commodity),
|
|
|
|
|
&info.max_decimal_places))
|
|
|
|
|
{
|
|
|
|
|
if (is_iso)
|
|
|
|
|
info.min_decimal_places = info.max_decimal_places;
|
|
|
|
|
else
|
|
|
|
|
info.min_decimal_places = 0;
|
|
|
|
|
}
|
2000-11-01 08:52:30 +00:00
|
|
|
else
|
2009-12-29 20:12:48 +00:00
|
|
|
info.max_decimal_places = info.min_decimal_places = 0;
|
2000-11-01 08:52:30 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info.use_separators = 1;
|
|
|
|
|
info.use_symbol = use_symbol ? 1 : 0;
|
|
|
|
|
info.use_locale = is_iso ? 1 : 0;
|
|
|
|
|
info.monetary = 1;
|
|
|
|
|
info.force_fit = 0;
|
|
|
|
|
info.round = 0;
|
2000-11-01 08:52:30 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info;
|
2000-02-27 21:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-09 22:04:07 +00:00
|
|
|
static GNCPrintAmountInfo
|
2006-02-27 23:57:16 +00:00
|
|
|
gnc_account_print_info_helper(const Account *account, gboolean use_symbol,
|
2005-11-02 03:32:36 +00:00
|
|
|
gnc_commodity * (*efffunc)(const Account *),
|
|
|
|
|
int (*scufunc)(const Account*))
|
2000-01-17 21:39:42 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
GNCPrintAmountInfo info;
|
|
|
|
|
gboolean is_iso;
|
|
|
|
|
int scu;
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (account == NULL)
|
|
|
|
|
return gnc_default_print_info (use_symbol);
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info.commodity = efffunc (account);
|
2000-11-01 21:37:15 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
is_iso = gnc_commodity_is_iso (info.commodity);
|
2000-11-01 21:37:15 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
scu = scufunc (account);
|
2000-11-01 21:37:15 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (is_decimal_fraction (scu, &info.max_decimal_places))
|
|
|
|
|
{
|
|
|
|
|
if (is_iso)
|
|
|
|
|
info.min_decimal_places = info.max_decimal_places;
|
|
|
|
|
else
|
|
|
|
|
info.min_decimal_places = 0;
|
|
|
|
|
}
|
2000-11-01 21:37:15 +00:00
|
|
|
else
|
2009-12-29 20:12:48 +00:00
|
|
|
info.max_decimal_places = info.min_decimal_places = 0;
|
2000-11-01 21:37:15 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info.use_separators = 1;
|
|
|
|
|
info.use_symbol = use_symbol ? 1 : 0;
|
|
|
|
|
info.use_locale = is_iso ? 1 : 0;
|
|
|
|
|
info.monetary = 1;
|
|
|
|
|
info.force_fit = 0;
|
|
|
|
|
info.round = 0;
|
2000-11-01 21:37:15 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info;
|
2000-11-01 21:37:15 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-09 22:04:07 +00:00
|
|
|
GNCPrintAmountInfo
|
2006-02-27 23:57:16 +00:00
|
|
|
gnc_account_print_info (const Account *account, gboolean use_symbol)
|
2001-03-09 22:04:07 +00:00
|
|
|
{
|
|
|
|
|
return gnc_account_print_info_helper(account, use_symbol,
|
2001-07-05 08:32:40 +00:00
|
|
|
xaccAccountGetCommodity,
|
|
|
|
|
xaccAccountGetCommoditySCU);
|
2000-11-01 08:52:30 +00:00
|
|
|
}
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
GNCPrintAmountInfo
|
2001-07-12 22:21:13 +00:00
|
|
|
gnc_split_amount_print_info (Split *split, gboolean use_symbol)
|
2000-11-01 08:52:30 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!split)
|
|
|
|
|
{
|
|
|
|
|
GNCPrintAmountInfo info = gnc_default_share_print_info ();
|
|
|
|
|
info.use_symbol = use_symbol;
|
|
|
|
|
return info;
|
|
|
|
|
}
|
2001-03-09 22:20:02 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return gnc_account_print_info (xaccSplitGetAccount (split), use_symbol);
|
2000-11-01 08:52:30 +00:00
|
|
|
}
|
1998-11-16 07:01:09 +00:00
|
|
|
|
2001-03-09 22:04:07 +00:00
|
|
|
static GNCPrintAmountInfo
|
2001-03-09 22:20:02 +00:00
|
|
|
gnc_default_print_info_helper (int decplaces)
|
2001-03-09 22:04:07 +00:00
|
|
|
{
|
|
|
|
|
GNCPrintAmountInfo info;
|
|
|
|
|
|
|
|
|
|
info.commodity = NULL;
|
2001-03-09 22:20:02 +00:00
|
|
|
|
2001-03-09 22:04:07 +00:00
|
|
|
info.max_decimal_places = decplaces;
|
|
|
|
|
info.min_decimal_places = 0;
|
2001-03-09 22:20:02 +00:00
|
|
|
|
2001-03-09 22:04:07 +00:00
|
|
|
info.use_separators = 1;
|
|
|
|
|
info.use_symbol = 0;
|
|
|
|
|
info.use_locale = 1;
|
|
|
|
|
info.monetary = 1;
|
2002-12-16 01:40:26 +00:00
|
|
|
info.force_fit = 0;
|
|
|
|
|
info.round = 0;
|
2001-03-09 22:04:07 +00:00
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
2001-03-09 22:20:02 +00:00
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
GNCPrintAmountInfo
|
|
|
|
|
gnc_default_share_print_info (void)
|
2000-10-23 10:16:07 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
static GNCPrintAmountInfo info;
|
|
|
|
|
static gboolean got_it = FALSE;
|
2000-10-23 09:41:51 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!got_it)
|
|
|
|
|
{
|
|
|
|
|
info = gnc_default_print_info_helper (5);
|
|
|
|
|
got_it = TRUE;
|
|
|
|
|
}
|
2001-03-09 22:20:02 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info;
|
2000-03-23 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
2002-12-16 01:40:26 +00:00
|
|
|
GNCPrintAmountInfo
|
|
|
|
|
gnc_share_print_info_places (int decplaces)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
GNCPrintAmountInfo info;
|
2002-12-16 01:40:26 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
info = gnc_default_share_print_info ();
|
|
|
|
|
info.max_decimal_places = decplaces;
|
|
|
|
|
info.min_decimal_places = decplaces;
|
|
|
|
|
info.force_fit = 1;
|
|
|
|
|
info.round = 1;
|
|
|
|
|
return info;
|
2002-12-16 01:40:26 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
GNCPrintAmountInfo
|
|
|
|
|
gnc_default_price_print_info (void)
|
2000-08-27 08:25:53 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
static GNCPrintAmountInfo info;
|
|
|
|
|
static gboolean got_it = FALSE;
|
2000-08-27 08:25:53 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!got_it)
|
|
|
|
|
{
|
|
|
|
|
info = gnc_default_print_info_helper (6);
|
|
|
|
|
got_it = TRUE;
|
|
|
|
|
}
|
2000-08-27 08:25:53 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info;
|
2000-08-27 08:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-09 06:09:04 +00:00
|
|
|
GNCPrintAmountInfo
|
|
|
|
|
gnc_integral_print_info (void)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
static GNCPrintAmountInfo info;
|
|
|
|
|
static gboolean got_it = FALSE;
|
2000-11-09 06:09:04 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!got_it)
|
|
|
|
|
{
|
|
|
|
|
info = gnc_default_print_info_helper (0);
|
|
|
|
|
got_it = TRUE;
|
|
|
|
|
}
|
2000-11-09 06:09:04 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return info;
|
2000-11-09 06:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
2000-01-17 21:39:42 +00:00
|
|
|
/* Utility function for printing non-negative amounts */
|
1998-11-16 06:28:13 +00:00
|
|
|
static int
|
2008-09-19 20:51:53 +00:00
|
|
|
PrintAmountInternal(char *buf, gnc_numeric val, const GNCPrintAmountInfo *info)
|
1998-11-16 06:28:13 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
struct lconv *lc = gnc_localeconv();
|
|
|
|
|
int num_whole_digits;
|
|
|
|
|
char temp_buf[128];
|
|
|
|
|
gnc_numeric whole, rounding;
|
|
|
|
|
int min_dp, max_dp;
|
|
|
|
|
gboolean value_is_negative, value_is_decimal;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, 0);
|
|
|
|
|
|
|
|
|
|
if (gnc_numeric_check (val))
|
|
|
|
|
{
|
2011-02-12 15:53:37 +00:00
|
|
|
PWARN ("Bad numeric: %s.",
|
|
|
|
|
gnc_numeric_errorCode_to_string(gnc_numeric_check (val)));
|
2006-01-06 22:28:38 +00:00
|
|
|
*buf = '\0';
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2000-09-26 00:45:16 +00:00
|
|
|
|
2011-08-13 15:33:17 +00:00
|
|
|
/* Print the absolute value, but remember sign */
|
2009-12-29 20:12:48 +00:00
|
|
|
value_is_negative = gnc_numeric_negative_p (val);
|
|
|
|
|
val = gnc_numeric_abs (val);
|
|
|
|
|
|
|
|
|
|
/* Try to print as decimal. */
|
|
|
|
|
value_is_decimal = gnc_numeric_to_decimal(&val, NULL);
|
|
|
|
|
|
|
|
|
|
/* Force at least auto_decimal_places zeros */
|
|
|
|
|
if (auto_decimal_enabled)
|
2000-09-26 00:45:16 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
min_dp = MAX(auto_decimal_places, info->min_decimal_places);
|
|
|
|
|
max_dp = MAX(auto_decimal_places, info->max_decimal_places);
|
2000-09-26 00:45:16 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
min_dp = info->min_decimal_places;
|
|
|
|
|
max_dp = info->max_decimal_places;
|
2000-01-17 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Don to limit the number of decimal places _UNLESS_ force_fit is
|
|
|
|
|
* true. */
|
|
|
|
|
if (!info->force_fit)
|
|
|
|
|
max_dp = 99;
|
2000-09-26 00:45:16 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* rounding? -- can only ROUND if force_fit is also true */
|
|
|
|
|
if (value_is_decimal && info->round && info->force_fit)
|
2000-09-26 00:45:16 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
rounding.num = 5; /* Limit the denom to 10^13 ~= 2^44, leaving max at ~524288 */
|
|
|
|
|
rounding.denom = pow(10, max_dp + 1);
|
2017-01-30 13:29:48 -08:00
|
|
|
val = gnc_numeric_add(val, rounding, val.denom,
|
|
|
|
|
GNC_HOW_DENOM_EXACT | GNC_HOW_RND_TRUNC);
|
2014-12-03 10:18:03 -08:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (gnc_numeric_check(val))
|
|
|
|
|
{
|
2011-02-12 15:53:37 +00:00
|
|
|
PWARN ("Bad numeric from rounding: %s.",
|
|
|
|
|
gnc_numeric_errorCode_to_string(gnc_numeric_check (val)));
|
2009-12-29 20:12:48 +00:00
|
|
|
*buf = '\0';
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-09-26 00:45:16 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* calculate the integer part and the remainder */
|
|
|
|
|
whole = gnc_numeric_convert(val, 1, GNC_HOW_RND_TRUNC);
|
|
|
|
|
val = gnc_numeric_sub (val, whole, GNC_DENOM_AUTO, GNC_HOW_RND_NEVER);
|
|
|
|
|
if (gnc_numeric_check (val))
|
|
|
|
|
{
|
2011-02-12 15:53:37 +00:00
|
|
|
PWARN ("Problem with remainder: %s.",
|
|
|
|
|
gnc_numeric_errorCode_to_string(gnc_numeric_check (val)));
|
2009-12-29 20:12:48 +00:00
|
|
|
*buf = '\0';
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* print the integer part without separators */
|
|
|
|
|
sprintf(temp_buf, "%" G_GINT64_FORMAT, whole.num);
|
|
|
|
|
num_whole_digits = strlen (temp_buf);
|
2000-09-26 00:45:16 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!info->use_separators)
|
|
|
|
|
strcpy (buf, temp_buf);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int group_count;
|
|
|
|
|
char *separator;
|
|
|
|
|
char *temp_ptr;
|
|
|
|
|
char *buf_ptr;
|
|
|
|
|
char *group;
|
|
|
|
|
gchar *rev_buf;
|
|
|
|
|
|
|
|
|
|
if (info->monetary)
|
2000-09-26 00:45:16 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
separator = lc->mon_thousands_sep;
|
|
|
|
|
group = lc->mon_grouping;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
separator = lc->thousands_sep;
|
|
|
|
|
group = lc->grouping;
|
2000-09-26 00:45:16 +00:00
|
|
|
}
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
buf_ptr = buf;
|
|
|
|
|
temp_ptr = &temp_buf[num_whole_digits - 1];
|
|
|
|
|
group_count = 0;
|
1998-11-16 06:28:13 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
while (temp_ptr != temp_buf)
|
|
|
|
|
{
|
|
|
|
|
*buf_ptr++ = *temp_ptr--;
|
|
|
|
|
|
|
|
|
|
if (*group != CHAR_MAX)
|
|
|
|
|
{
|
|
|
|
|
group_count++;
|
|
|
|
|
|
|
|
|
|
if (group_count == *group)
|
|
|
|
|
{
|
|
|
|
|
g_utf8_strncpy(buf_ptr, separator, 1);
|
|
|
|
|
buf_ptr = g_utf8_find_next_char(buf_ptr, NULL);
|
|
|
|
|
group_count = 0;
|
|
|
|
|
|
|
|
|
|
/* Peek ahead at the next group code */
|
|
|
|
|
switch (group[1])
|
|
|
|
|
{
|
|
|
|
|
/* A null char means repeat the last group indefinitely */
|
|
|
|
|
case '\0':
|
|
|
|
|
break;
|
|
|
|
|
/* CHAR_MAX means no more grouping allowed */
|
|
|
|
|
case CHAR_MAX:
|
|
|
|
|
/* fall through */
|
|
|
|
|
/* Anything else means another group size */
|
|
|
|
|
default:
|
|
|
|
|
group++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* We built the string backwards, now reverse */
|
|
|
|
|
*buf_ptr++ = *temp_ptr;
|
|
|
|
|
*buf_ptr = '\0';
|
|
|
|
|
rev_buf = g_utf8_strreverse(buf, -1);
|
|
|
|
|
strcpy (buf, rev_buf);
|
|
|
|
|
g_free(rev_buf);
|
|
|
|
|
} /* endif */
|
2008-08-07 19:40:15 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* at this point, buf contains the whole part of the number */
|
|
|
|
|
|
|
|
|
|
/* If it's not decimal, print the fraction as an expression. */
|
|
|
|
|
if (!value_is_decimal)
|
|
|
|
|
{
|
|
|
|
|
val = gnc_numeric_reduce (val);
|
|
|
|
|
|
|
|
|
|
if (val.denom > 0)
|
|
|
|
|
sprintf (temp_buf, "%" G_GINT64_FORMAT "/%" G_GINT64_FORMAT,
|
|
|
|
|
val.num, val.denom);
|
|
|
|
|
else
|
|
|
|
|
sprintf (temp_buf, "%" G_GINT64_FORMAT " * %" G_GINT64_FORMAT,
|
|
|
|
|
val.num, -val.denom);
|
|
|
|
|
|
|
|
|
|
if (whole.num == 0)
|
|
|
|
|
*buf = '\0';
|
|
|
|
|
else if (value_is_negative)
|
|
|
|
|
strcat(buf, " - ");
|
|
|
|
|
else
|
|
|
|
|
strcat(buf, " + ");
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
strcat (buf, temp_buf);
|
|
|
|
|
}
|
2008-08-07 19:40:15 +00:00
|
|
|
else
|
2000-11-03 08:43:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
char *decimal_point;
|
|
|
|
|
guint8 num_decimal_places = 0;
|
|
|
|
|
char *temp_ptr = temp_buf;
|
|
|
|
|
|
|
|
|
|
decimal_point = info->monetary
|
|
|
|
|
? lc->mon_decimal_point
|
|
|
|
|
: lc->decimal_point;
|
|
|
|
|
g_utf8_strncpy(temp_ptr, decimal_point, 1);
|
|
|
|
|
temp_ptr = g_utf8_find_next_char(temp_ptr, NULL);
|
|
|
|
|
|
|
|
|
|
while (!gnc_numeric_zero_p (val)
|
|
|
|
|
&& (val.denom != 1)
|
|
|
|
|
&& (num_decimal_places < max_dp))
|
|
|
|
|
{
|
|
|
|
|
gint64 digit;
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
val.denom = val.denom / 10;
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
digit = val.num / val.denom;
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
*temp_ptr++ = digit + '0';
|
|
|
|
|
num_decimal_places++;
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
val.num = val.num - (digit * val.denom);
|
|
|
|
|
}
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
while (num_decimal_places < min_dp)
|
|
|
|
|
{
|
|
|
|
|
*temp_ptr++ = '0';
|
|
|
|
|
num_decimal_places++;
|
|
|
|
|
}
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* cap the end and move to the last character */
|
|
|
|
|
*temp_ptr-- = '\0';
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Here we strip off trailing decimal zeros per the argument. */
|
|
|
|
|
while (*temp_ptr == '0' && num_decimal_places > min_dp)
|
|
|
|
|
{
|
|
|
|
|
*temp_ptr-- = '\0';
|
|
|
|
|
num_decimal_places--;
|
|
|
|
|
}
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (num_decimal_places > max_dp)
|
|
|
|
|
{
|
|
|
|
|
PWARN ("max_decimal_places too small; limit %d, value %s%s",
|
|
|
|
|
info->max_decimal_places, buf, temp_buf);
|
|
|
|
|
}
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (num_decimal_places > 0)
|
|
|
|
|
strcat (buf, temp_buf);
|
|
|
|
|
}
|
2000-11-03 08:43:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return strlen(buf);
|
1998-11-16 06:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
2002-12-16 00:35:27 +00:00
|
|
|
/**
|
|
|
|
|
* @param bufp Should be at least 64 chars.
|
|
|
|
|
**/
|
1999-01-30 21:22:13 +00:00
|
|
|
int
|
2000-11-08 10:53:39 +00:00
|
|
|
xaccSPrintAmount (char * bufp, gnc_numeric val, GNCPrintAmountInfo info)
|
1997-12-06 02:59:44 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
struct lconv *lc;
|
|
|
|
|
|
|
|
|
|
char *orig_bufp = bufp;
|
|
|
|
|
const char *currency_symbol;
|
|
|
|
|
const char *sign;
|
|
|
|
|
|
|
|
|
|
char cs_precedes;
|
|
|
|
|
char sep_by_space;
|
|
|
|
|
char sign_posn;
|
|
|
|
|
|
|
|
|
|
gboolean print_sign = TRUE;
|
|
|
|
|
gboolean print_absolute = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!bufp)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
lc = gnc_localeconv();
|
2013-10-24 12:27:49 +00:00
|
|
|
if (info.use_locale)
|
|
|
|
|
if (gnc_numeric_negative_p (val))
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
2013-10-24 12:27:49 +00:00
|
|
|
cs_precedes = lc->n_cs_precedes;
|
|
|
|
|
sep_by_space = lc->n_sep_by_space;
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-10-24 12:27:49 +00:00
|
|
|
cs_precedes = lc->p_cs_precedes;
|
|
|
|
|
sep_by_space = lc->p_sep_by_space;
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-10-24 12:27:49 +00:00
|
|
|
cs_precedes = TRUE;
|
|
|
|
|
sep_by_space = TRUE;
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
2013-10-24 12:27:49 +00:00
|
|
|
|
|
|
|
|
if (info.commodity && info.use_symbol)
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
2015-11-01 11:17:50 +01:00
|
|
|
currency_symbol = gnc_commodity_get_nice_symbol (info.commodity);
|
|
|
|
|
if (!gnc_commodity_is_iso (info.commodity))
|
2009-12-29 20:12:48 +00:00
|
|
|
{
|
2013-10-24 12:27:49 +00:00
|
|
|
cs_precedes = FALSE;
|
|
|
|
|
sep_by_space = TRUE;
|
2009-12-29 20:12:48 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-10-24 12:27:49 +00:00
|
|
|
else /* !info.use_symbol || !info.commodity */
|
|
|
|
|
currency_symbol = "";
|
2009-12-29 20:12:48 +00:00
|
|
|
|
|
|
|
|
if (gnc_numeric_negative_p (val))
|
|
|
|
|
{
|
|
|
|
|
sign = lc->negative_sign;
|
|
|
|
|
sign_posn = lc->n_sign_posn;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sign = lc->positive_sign;
|
|
|
|
|
sign_posn = lc->p_sign_posn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gnc_numeric_zero_p (val) || (sign == NULL) || (sign[0] == 0))
|
|
|
|
|
print_sign = FALSE;
|
|
|
|
|
|
|
|
|
|
/* See if we print sign now */
|
|
|
|
|
if (print_sign && (sign_posn == 1))
|
|
|
|
|
bufp = g_stpcpy(bufp, sign);
|
|
|
|
|
|
|
|
|
|
/* Now see if we print currency */
|
|
|
|
|
if (cs_precedes)
|
|
|
|
|
{
|
|
|
|
|
/* See if we print sign now */
|
|
|
|
|
if (print_sign && (sign_posn == 3))
|
|
|
|
|
bufp = g_stpcpy(bufp, sign);
|
|
|
|
|
|
|
|
|
|
if (info.use_symbol)
|
|
|
|
|
{
|
|
|
|
|
bufp = g_stpcpy(bufp, currency_symbol);
|
|
|
|
|
if (sep_by_space)
|
|
|
|
|
bufp = g_stpcpy(bufp, " ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See if we print sign now */
|
|
|
|
|
if (print_sign && (sign_posn == 4))
|
|
|
|
|
bufp = g_stpcpy(bufp, sign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now see if we print parentheses */
|
|
|
|
|
if (print_sign && (sign_posn == 0))
|
|
|
|
|
{
|
|
|
|
|
bufp = g_stpcpy(bufp, "(");
|
|
|
|
|
print_absolute = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now print the value */
|
|
|
|
|
bufp += PrintAmountInternal(bufp,
|
|
|
|
|
print_absolute ? gnc_numeric_abs(val) : val,
|
|
|
|
|
&info);
|
|
|
|
|
|
|
|
|
|
/* Now see if we print parentheses */
|
|
|
|
|
if (print_sign && (sign_posn == 0))
|
|
|
|
|
bufp = g_stpcpy(bufp, ")");
|
|
|
|
|
|
|
|
|
|
/* Now see if we print currency */
|
|
|
|
|
if (!cs_precedes)
|
|
|
|
|
{
|
|
|
|
|
/* See if we print sign now */
|
|
|
|
|
if (print_sign && (sign_posn == 3))
|
|
|
|
|
bufp = g_stpcpy(bufp, sign);
|
|
|
|
|
|
|
|
|
|
if (info.use_symbol)
|
|
|
|
|
{
|
|
|
|
|
if (sep_by_space)
|
|
|
|
|
bufp = g_stpcpy(bufp, " ");
|
|
|
|
|
bufp = g_stpcpy(bufp, currency_symbol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See if we print sign now */
|
|
|
|
|
if (print_sign && (sign_posn == 4))
|
|
|
|
|
bufp = g_stpcpy(bufp, sign);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* See if we print sign now */
|
|
|
|
|
if (print_sign && (sign_posn == 2))
|
|
|
|
|
bufp = g_stpcpy(bufp, sign);
|
|
|
|
|
|
|
|
|
|
/* return length of printed string */
|
|
|
|
|
return (bufp - orig_bufp);
|
1999-01-30 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
|
2000-08-22 01:35:47 +00:00
|
|
|
const char *
|
2000-11-08 10:53:39 +00:00
|
|
|
xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
|
1999-01-30 21:22:13 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
/* hack alert -- this is not thread safe ... */
|
|
|
|
|
static char buf[1024];
|
1999-01-30 21:22:13 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!xaccSPrintAmount (buf, val, info))
|
|
|
|
|
buf[0] = '\0';
|
1999-01-30 21:22:13 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* its OK to return buf, since we declared it static */
|
|
|
|
|
return buf;
|
1997-12-06 02:59:44 +00:00
|
|
|
}
|
|
|
|
|
|
1998-02-02 23:25:44 +00:00
|
|
|
|
2007-03-13 03:43:24 +00:00
|
|
|
/********************************************************************\
|
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
|
|
#define FUDGE .00001
|
|
|
|
|
|
2007-04-15 18:53:56 +00:00
|
|
|
/* This function is basically untranslatable. I'd
|
2007-04-14 11:24:15 +00:00
|
|
|
guess out of the 29 translations we have, 20 will have their number
|
|
|
|
|
wordings in a totally different way than English has (not to
|
|
|
|
|
mention gender-dependent number endings). Which means this
|
|
|
|
|
word-by-word translation will be useless or even plain
|
2007-04-15 18:53:56 +00:00
|
|
|
wrong. For this reason, we don't even start to pretend a
|
|
|
|
|
word-by-word translation would be of any use, so we don't mark any
|
|
|
|
|
of these strings for translation. cstim, 2007-04-15. */
|
2009-12-29 20:12:48 +00:00
|
|
|
static gchar *small_numbers[] =
|
|
|
|
|
{
|
|
|
|
|
/* Translators: This section is for generating the "amount, in
|
|
|
|
|
words" field when printing a check. This function gets the
|
|
|
|
|
wording right for English, but unfortunately not for most other
|
|
|
|
|
languages. Decide for yourself whether the check printing is
|
|
|
|
|
actually needed in your language; if not, you can safely skip the
|
|
|
|
|
translation of all of these strings. */
|
|
|
|
|
"Zero", "One", "Two", "Three", "Four",
|
|
|
|
|
"Five", "Six", "Seven", "Eight", "Nine",
|
|
|
|
|
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
|
|
|
|
|
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen",
|
|
|
|
|
"Twenty"
|
|
|
|
|
};
|
|
|
|
|
static gchar *medium_numbers[] =
|
|
|
|
|
{
|
|
|
|
|
"Zero", "Ten", "Twenty", "Thirty", "Forty",
|
|
|
|
|
"Fifty", "Sixty", "Seventy", "Eighty", "Ninety"
|
|
|
|
|
};
|
|
|
|
|
static gchar *big_numbers[] =
|
|
|
|
|
{
|
|
|
|
|
/* Translators: This is the word for the number 10^2 */
|
|
|
|
|
"Hundred",
|
|
|
|
|
/* Translators: This is the word for the number 10^3 */
|
|
|
|
|
"Thousand",
|
|
|
|
|
/* Translators: This is the word for the number 10^6, one thousand
|
|
|
|
|
thousands. */
|
|
|
|
|
"Million",
|
|
|
|
|
/* Translators: This is the word for the number 10^9, one thousand
|
2011-08-13 15:33:17 +00:00
|
|
|
millions. WATCH OUT: In British English and many other languages
|
2009-12-29 20:12:48 +00:00
|
|
|
this word is used for 10^12 which is one million millions! In
|
|
|
|
|
contrast to this, here in GnuCash this is used in the American
|
2011-08-13 15:33:17 +00:00
|
|
|
English meaning of 10^9. */
|
2009-12-29 20:12:48 +00:00
|
|
|
"Billion",
|
|
|
|
|
/* Translators: This is the word for the number 10^12, one million
|
|
|
|
|
millions. */
|
|
|
|
|
"Trillion",
|
|
|
|
|
/* Translators: This is the word for the number 10^15 */
|
|
|
|
|
"Quadrillion",
|
|
|
|
|
/* Translators: This is the word for the number 10^18 */
|
|
|
|
|
"Quintillion"
|
|
|
|
|
};
|
2007-03-13 03:43:24 +00:00
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
|
integer_to_words(gint64 val)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gint64 log_val, pow_val, this_part;
|
|
|
|
|
GString *result;
|
|
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
|
|
if (val == 0)
|
|
|
|
|
return g_strdup("zero");
|
|
|
|
|
if (val < 0)
|
|
|
|
|
val = -val;
|
|
|
|
|
|
|
|
|
|
result = g_string_sized_new(100);
|
|
|
|
|
|
|
|
|
|
while (val >= 1000)
|
|
|
|
|
{
|
|
|
|
|
log_val = log10(val) / 3 + FUDGE;
|
|
|
|
|
pow_val = exp(log_val * 3 * G_LN10) + FUDGE;
|
|
|
|
|
this_part = val / pow_val;
|
|
|
|
|
val -= this_part * pow_val;
|
|
|
|
|
tmp = integer_to_words(this_part);
|
|
|
|
|
g_string_append_printf(result, "%s %s ", tmp,
|
|
|
|
|
gettext(big_numbers[log_val]));
|
|
|
|
|
g_free(tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (val >= 100)
|
|
|
|
|
{
|
|
|
|
|
this_part = val / 100;
|
|
|
|
|
val -= this_part * 100;
|
|
|
|
|
g_string_append_printf(result, "%s %s ",
|
|
|
|
|
gettext(small_numbers[this_part]),
|
|
|
|
|
gettext(big_numbers[0]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (val > 20)
|
|
|
|
|
{
|
|
|
|
|
this_part = val / 10;
|
|
|
|
|
val -= this_part * 10;
|
|
|
|
|
g_string_append(result, gettext(medium_numbers[this_part]));
|
|
|
|
|
g_string_append_c(result, ' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (val > 0)
|
|
|
|
|
{
|
|
|
|
|
this_part = val;
|
|
|
|
|
val -= this_part;
|
|
|
|
|
g_string_append(result, gettext(small_numbers[this_part]));
|
|
|
|
|
g_string_append_c(result, ' ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = g_string_truncate(result, result->len - 1);
|
|
|
|
|
return g_string_free(result, FALSE);
|
2007-03-13 03:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-08 18:48:44 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
static double round(double x)
|
|
|
|
|
{
|
2010-03-27 21:01:56 +00:00
|
|
|
// A simple round() implementation because MSVC doesn't seem to have that
|
|
|
|
|
return floor(x + 0.5);
|
2010-03-08 18:48:44 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-03-13 03:43:24 +00:00
|
|
|
gchar *
|
|
|
|
|
number_to_words(gdouble val, gint64 denom)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gint64 int_part, frac_part;
|
|
|
|
|
gchar *int_string, *nomin_string, *denom_string, *full_string;
|
|
|
|
|
|
|
|
|
|
if (val < 0) val = -val;
|
|
|
|
|
if (denom < 0) denom = -denom;
|
|
|
|
|
|
2010-03-08 18:48:44 +00:00
|
|
|
int_part = floor(val);
|
2009-12-29 20:12:48 +00:00
|
|
|
frac_part = round((val - int_part) * denom);
|
|
|
|
|
|
|
|
|
|
int_string = integer_to_words(int_part);
|
|
|
|
|
/* Inside of the gettext macro _(...) we must not use any macros but
|
|
|
|
|
only plain string literals. For this reason, convert the strings
|
|
|
|
|
separately. */
|
2010-02-03 20:54:26 +00:00
|
|
|
nomin_string = g_strdup_printf("%02" G_GINT64_FORMAT, frac_part);
|
2009-12-29 20:12:48 +00:00
|
|
|
denom_string = g_strdup_printf("%" G_GINT64_FORMAT, denom);
|
|
|
|
|
full_string =
|
|
|
|
|
/* Translators: This is for the "amount, in words" field in check
|
|
|
|
|
printing. The first %s is the integer amount of dollars (or
|
|
|
|
|
whatever currency), the second and third %s the cent amount as
|
|
|
|
|
a fraction, e.g. 47/100. */
|
|
|
|
|
g_strdup_printf("%s and %s/%s",
|
|
|
|
|
int_string, nomin_string, denom_string);
|
|
|
|
|
g_free(int_string);
|
|
|
|
|
g_free(nomin_string);
|
|
|
|
|
g_free(denom_string);
|
|
|
|
|
return full_string;
|
2007-03-13 03:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
|
numeric_to_words(gnc_numeric val)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
return number_to_words(gnc_numeric_to_double(val),
|
|
|
|
|
gnc_numeric_denom(val));
|
2007-03-13 03:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
|
printable_value (gdouble val, gint denom)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
GNCPrintAmountInfo info;
|
|
|
|
|
gnc_numeric num;
|
2007-03-13 03:43:24 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
num = gnc_numeric_create(round(val * denom), denom);
|
|
|
|
|
info = gnc_share_print_info_places(log10(denom));
|
|
|
|
|
return xaccPrintAmount (num, info);
|
2007-03-13 03:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
1998-02-02 23:25:44 +00:00
|
|
|
/********************************************************************\
|
2000-11-08 10:53:39 +00:00
|
|
|
* xaccParseAmount *
|
2000-01-17 21:39:42 +00:00
|
|
|
* parses amount strings using locale data *
|
|
|
|
|
* *
|
2000-08-31 07:16:55 +00:00
|
|
|
* Args: in_str -- pointer to string rep of num *
|
|
|
|
|
* monetary -- boolean indicating whether value is monetary *
|
|
|
|
|
* result -- pointer to result location, may be NULL *
|
|
|
|
|
* endstr -- used to store first digit not used in parsing *
|
|
|
|
|
* Return: gboolean -- TRUE if a number found and parsed *
|
|
|
|
|
* If FALSE, result is not changed *
|
2000-01-17 21:39:42 +00:00
|
|
|
\********************************************************************/
|
|
|
|
|
|
2000-08-31 07:16:55 +00:00
|
|
|
/* Parsing state machine states */
|
|
|
|
|
typedef enum
|
2000-01-17 21:39:42 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
START_ST, /* Parsing initial whitespace */
|
|
|
|
|
NEG_ST, /* Parsed a negative sign or a left paren */
|
|
|
|
|
PRE_GROUP_ST, /* Parsing digits before grouping and decimal characters */
|
|
|
|
|
START_GROUP_ST, /* Start of a digit group encountered (possibly) */
|
|
|
|
|
IN_GROUP_ST, /* Within a digit group */
|
|
|
|
|
FRAC_ST, /* Parsing the fractional portion of a number */
|
|
|
|
|
DONE_ST, /* Finished, number is correct module grouping constraints */
|
|
|
|
|
NO_NUM_ST /* Finished, number was malformed */
|
2000-08-31 07:16:55 +00:00
|
|
|
} ParseState;
|
|
|
|
|
|
|
|
|
|
#define done_state(state) (((state) == DONE_ST) || ((state) == NO_NUM_ST))
|
|
|
|
|
|
2001-04-15 23:07:30 +00:00
|
|
|
G_INLINE_FUNC long long int multiplier (int num_decimals);
|
2000-09-13 22:33:15 +00:00
|
|
|
|
2005-11-02 03:32:36 +00:00
|
|
|
long long int
|
2000-10-29 20:32:38 +00:00
|
|
|
multiplier (int num_decimals)
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
switch (num_decimals)
|
|
|
|
|
{
|
2000-08-31 07:16:55 +00:00
|
|
|
case 8:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 100000000;
|
2000-08-31 07:16:55 +00:00
|
|
|
case 7:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 10000000;
|
2000-08-31 07:16:55 +00:00
|
|
|
case 6:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 1000000;
|
2000-08-31 07:16:55 +00:00
|
|
|
case 5:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 100000;
|
2000-08-31 07:16:55 +00:00
|
|
|
case 4:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 10000;
|
2000-08-31 07:16:55 +00:00
|
|
|
case 3:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 1000;
|
2000-08-31 07:16:55 +00:00
|
|
|
case 2:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 100;
|
2000-08-31 07:16:55 +00:00
|
|
|
case 1:
|
2009-12-29 20:12:48 +00:00
|
|
|
return 10;
|
2000-08-31 07:16:55 +00:00
|
|
|
default:
|
2009-12-29 20:12:48 +00:00
|
|
|
PERR("bad fraction length");
|
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return 1;
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
2000-05-19 10:27:33 +00:00
|
|
|
|
2000-10-29 20:32:38 +00:00
|
|
|
gboolean
|
|
|
|
|
xaccParseAmount (const char * in_str, gboolean monetary, gnc_numeric *result,
|
|
|
|
|
char **endstr)
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
struct lconv *lc = gnc_localeconv();
|
2003-07-10 03:10:08 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
gunichar negative_sign;
|
|
|
|
|
gunichar decimal_point;
|
|
|
|
|
gunichar group_separator;
|
|
|
|
|
char *group;
|
2003-07-10 03:10:08 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
negative_sign = g_utf8_get_char(lc->negative_sign);
|
|
|
|
|
if (monetary)
|
|
|
|
|
{
|
|
|
|
|
group_separator = g_utf8_get_char(lc->mon_thousands_sep);
|
|
|
|
|
decimal_point = g_utf8_get_char(lc->mon_decimal_point);
|
|
|
|
|
group = lc->mon_grouping;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
group_separator = g_utf8_get_char(lc->thousands_sep);
|
|
|
|
|
decimal_point = g_utf8_get_char(lc->decimal_point);
|
|
|
|
|
group = lc->grouping;
|
|
|
|
|
}
|
2003-07-10 03:10:08 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return xaccParseAmountExtended(in_str, monetary, negative_sign, decimal_point,
|
|
|
|
|
group_separator, group, NULL, result, endstr);
|
2003-07-10 03:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Note: xaccParseAmountExtended causes test-print-parse-amount
|
2006-04-14 16:45:10 +00:00
|
|
|
to fail if QOF_SCANF_LLD is simply replaced by G_GINT64_FORMAT. Why?
|
|
|
|
|
A: Because scanf and printf use different symbols for 64-bit numbers.
|
|
|
|
|
*/
|
2003-07-10 03:10:08 +00:00
|
|
|
gboolean
|
|
|
|
|
xaccParseAmountExtended (const char * in_str, gboolean monetary,
|
2009-12-29 20:12:48 +00:00
|
|
|
gunichar negative_sign, gunichar decimal_point,
|
2016-01-23 15:53:11 +01:00
|
|
|
gunichar group_separator, const char *group, const char *ignore_list,
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_numeric *result, char **endstr)
|
|
|
|
|
{
|
|
|
|
|
gboolean is_negative;
|
|
|
|
|
gboolean got_decimal;
|
|
|
|
|
gboolean need_paren;
|
|
|
|
|
GList * group_data;
|
|
|
|
|
long long int numer;
|
|
|
|
|
long long int denom;
|
|
|
|
|
int count, group_count;
|
|
|
|
|
|
|
|
|
|
ParseState state;
|
|
|
|
|
|
|
|
|
|
const gchar *in;
|
|
|
|
|
gunichar uc;
|
|
|
|
|
gchar *out_str;
|
|
|
|
|
gchar *out;
|
2003-07-10 03:10:08 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Initialize *endstr to in_str */
|
|
|
|
|
if (endstr != NULL)
|
|
|
|
|
*endstr = (char *) in_str;
|
|
|
|
|
|
|
|
|
|
if (in_str == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!g_utf8_validate(in_str, -1, &in))
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
printf("Invalid utf8 string '%s'. Bad character at position %ld.\n",
|
|
|
|
|
in_str, g_utf8_pointer_to_offset (in_str, in));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* 'out_str' will be used to store digits for numeric conversion.
|
|
|
|
|
* 'out' will be used to traverse out_str. */
|
|
|
|
|
out = out_str = g_new(gchar, strlen(in_str) + 128);
|
2000-05-19 10:27:33 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* 'in' is used to traverse 'in_str'. */
|
|
|
|
|
in = in_str;
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
is_negative = FALSE;
|
|
|
|
|
got_decimal = FALSE;
|
|
|
|
|
need_paren = FALSE;
|
|
|
|
|
group_data = NULL;
|
|
|
|
|
group_count = 0;
|
|
|
|
|
numer = 0;
|
|
|
|
|
denom = 1;
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Initialize the state machine */
|
|
|
|
|
state = START_ST;
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* This while loop implements a state machine for parsing numbers. */
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
|
|
|
|
ParseState next_state = state;
|
2000-06-21 09:48:39 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
uc = g_utf8_get_char(in);
|
|
|
|
|
|
|
|
|
|
/* Ignore anything in the 'ignore list' */
|
|
|
|
|
if (ignore_list && uc && g_utf8_strchr(ignore_list, -1, uc) != NULL)
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
in = g_utf8_next_char(in);
|
|
|
|
|
continue;
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
2000-06-21 09:48:39 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Note we never need to check for the end of 'in_str' explicitly.
|
|
|
|
|
* The 'else' clauses on all the state transitions will handle that. */
|
|
|
|
|
switch (state)
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
/* START_ST means we have parsed 0 or more whitespace characters */
|
|
|
|
|
case START_ST:
|
|
|
|
|
if (g_unichar_isdigit(uc))
|
|
|
|
|
{
|
|
|
|
|
count = g_unichar_to_utf8(uc, out);
|
|
|
|
|
out += count; /* we record the digits themselves in out_str
|
|
|
|
|
* for later conversion by libc routines */
|
|
|
|
|
next_state = PRE_GROUP_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == decimal_point)
|
|
|
|
|
{
|
|
|
|
|
next_state = FRAC_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (g_unichar_isspace(uc))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else if (uc == negative_sign)
|
|
|
|
|
{
|
|
|
|
|
is_negative = TRUE;
|
|
|
|
|
next_state = NEG_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == '(')
|
|
|
|
|
{
|
|
|
|
|
is_negative = TRUE;
|
|
|
|
|
need_paren = TRUE;
|
|
|
|
|
next_state = NEG_ST;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* NEG_ST means we have just parsed a negative sign. For now,
|
|
|
|
|
* we only recognize formats where the negative sign comes first. */
|
|
|
|
|
case NEG_ST:
|
|
|
|
|
if (g_unichar_isdigit(uc))
|
|
|
|
|
{
|
|
|
|
|
count = g_unichar_to_utf8(uc, out);
|
|
|
|
|
out += count;
|
|
|
|
|
next_state = PRE_GROUP_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == decimal_point)
|
|
|
|
|
{
|
|
|
|
|
next_state = FRAC_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (g_unichar_isspace(uc))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* PRE_GROUP_ST means we have started parsing the number, but
|
|
|
|
|
* have not encountered a decimal point or a grouping character. */
|
|
|
|
|
case PRE_GROUP_ST:
|
|
|
|
|
if (g_unichar_isdigit(uc))
|
|
|
|
|
{
|
|
|
|
|
count = g_unichar_to_utf8(uc, out);
|
|
|
|
|
out += count;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == decimal_point)
|
|
|
|
|
{
|
|
|
|
|
next_state = FRAC_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == group_separator)
|
|
|
|
|
{
|
|
|
|
|
next_state = START_GROUP_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == ')' && need_paren)
|
|
|
|
|
{
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
need_paren = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* START_GROUP_ST means we have just parsed a group character.
|
|
|
|
|
* Note that group characters might be whitespace!!! In general,
|
|
|
|
|
* if a decimal point or a group character is whitespace, we
|
|
|
|
|
* try to interpret it in the fashion that will allow parsing
|
|
|
|
|
* of the current number to continue. */
|
|
|
|
|
case START_GROUP_ST:
|
|
|
|
|
if (g_unichar_isdigit(uc))
|
|
|
|
|
{
|
|
|
|
|
count = g_unichar_to_utf8(uc, out);
|
|
|
|
|
out += count;
|
|
|
|
|
group_count++; /* We record the number of digits
|
2000-08-31 07:16:55 +00:00
|
|
|
* in the group for later checking. */
|
2009-12-29 20:12:48 +00:00
|
|
|
next_state = IN_GROUP_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == decimal_point)
|
|
|
|
|
{
|
|
|
|
|
/* If we now get a decimal point, and both the decimal
|
|
|
|
|
* and the group separator are also whitespace, assume
|
|
|
|
|
* the last group separator was actually whitespace and
|
|
|
|
|
* stop parsing. Otherwise, there's a problem. */
|
|
|
|
|
if (g_unichar_isspace(group_separator) &&
|
|
|
|
|
g_unichar_isspace(decimal_point))
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
else
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == ')' && need_paren)
|
|
|
|
|
{
|
|
|
|
|
if (g_unichar_isspace(group_separator))
|
|
|
|
|
{
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
need_paren = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* If the last group separator is also whitespace,
|
|
|
|
|
* assume it was intended as such and stop parsing.
|
|
|
|
|
* Otherwise, there is a problem. */
|
|
|
|
|
if (g_unichar_isspace(group_separator))
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
else
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* IN_GROUP_ST means we are in the middle of parsing
|
|
|
|
|
* a group of digits. */
|
|
|
|
|
case IN_GROUP_ST:
|
|
|
|
|
if (g_unichar_isdigit(uc))
|
|
|
|
|
{
|
|
|
|
|
count = g_unichar_to_utf8(uc, out);
|
|
|
|
|
out += count;
|
|
|
|
|
group_count++; /* We record the number of digits
|
|
|
|
|
* in the group for later checking. */
|
|
|
|
|
}
|
|
|
|
|
else if (uc == decimal_point)
|
|
|
|
|
{
|
|
|
|
|
next_state = FRAC_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == group_separator)
|
|
|
|
|
{
|
|
|
|
|
next_state = START_GROUP_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == ')' && need_paren)
|
|
|
|
|
{
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
need_paren = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* FRAC_ST means we are now parsing fractional digits. */
|
|
|
|
|
case FRAC_ST:
|
|
|
|
|
if (g_unichar_isdigit(uc))
|
|
|
|
|
{
|
|
|
|
|
count = g_unichar_to_utf8(uc, out);
|
|
|
|
|
out += count;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == decimal_point)
|
|
|
|
|
{
|
|
|
|
|
/* If a subsequent decimal point is also whitespace,
|
|
|
|
|
* assume it was intended as such and stop parsing.
|
|
|
|
|
* Otherwise, there is a problem. */
|
|
|
|
|
if (g_unichar_isspace(decimal_point))
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
else
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == group_separator)
|
|
|
|
|
{
|
|
|
|
|
/* If a subsequent group separator is also whitespace,
|
|
|
|
|
* assume it was intended as such and stop parsing.
|
|
|
|
|
* Otherwise, there is a problem. */
|
|
|
|
|
if (g_unichar_isspace(group_separator))
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
else
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (uc == ')' && need_paren)
|
|
|
|
|
{
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
need_paren = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
next_state = DONE_ST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
default:
|
|
|
|
|
PERR("bad state");
|
|
|
|
|
g_assert_not_reached();
|
|
|
|
|
break;
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
2009-12-29 20:12:48 +00:00
|
|
|
|
|
|
|
|
/* If we're moving out of the IN_GROUP_ST, record data for the group */
|
|
|
|
|
if ((state == IN_GROUP_ST) && (next_state != IN_GROUP_ST))
|
2000-10-27 20:30:30 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
group_data = g_list_prepend(group_data, GINT_TO_POINTER(group_count));
|
|
|
|
|
group_count = 0;
|
2000-10-27 20:30:30 +00:00
|
|
|
}
|
2009-12-29 20:12:48 +00:00
|
|
|
|
|
|
|
|
/* If we're moving into the FRAC_ST or out of the machine
|
|
|
|
|
* without going through FRAC_ST, record the integral value. */
|
|
|
|
|
if (((next_state == FRAC_ST) && (state != FRAC_ST)) ||
|
|
|
|
|
((next_state == DONE_ST) && !got_decimal))
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
*out = '\0';
|
|
|
|
|
|
|
|
|
|
if (*out_str != '\0' && sscanf(out_str, QOF_SCANF_LLD, &numer) < 1)
|
|
|
|
|
{
|
|
|
|
|
next_state = NO_NUM_ST;
|
|
|
|
|
}
|
|
|
|
|
else if (next_state == FRAC_ST)
|
|
|
|
|
{
|
|
|
|
|
/* reset the out pointer to record the fraction */
|
|
|
|
|
out = out_str;
|
|
|
|
|
*out = '\0';
|
|
|
|
|
|
|
|
|
|
got_decimal = TRUE;
|
|
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
state = next_state;
|
|
|
|
|
if (done_state (state))
|
|
|
|
|
break;
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
in = g_utf8_next_char(in);
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* If there was an error, just quit */
|
|
|
|
|
if (need_paren || (state == NO_NUM_ST))
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
g_free(out_str);
|
|
|
|
|
g_list_free(group_data);
|
|
|
|
|
return FALSE;
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* If there were groups, validate them */
|
|
|
|
|
if (group_data != NULL)
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gboolean good_grouping = TRUE;
|
|
|
|
|
GList *node;
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* The groups were built in reverse order. This
|
|
|
|
|
* is the easiest order to verify them in. */
|
|
|
|
|
for (node = group_data; group && node; node = node->next)
|
|
|
|
|
{
|
|
|
|
|
/* Verify group size */
|
|
|
|
|
if (*group != GPOINTER_TO_INT(node->data))
|
|
|
|
|
{
|
|
|
|
|
good_grouping = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Peek ahead at the next group code */
|
|
|
|
|
switch (group[1])
|
|
|
|
|
{
|
|
|
|
|
/* A null char means repeat the last group indefinitely */
|
|
|
|
|
case '\0':
|
|
|
|
|
break;
|
|
|
|
|
/* CHAR_MAX means no more grouping allowed */
|
|
|
|
|
case CHAR_MAX:
|
|
|
|
|
if (node->next != NULL)
|
|
|
|
|
good_grouping = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
/* Anything else means another group size */
|
|
|
|
|
default:
|
|
|
|
|
group++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (!good_grouping)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
g_list_free(group_data);
|
|
|
|
|
|
|
|
|
|
if (!good_grouping)
|
|
|
|
|
{
|
|
|
|
|
g_free(out_str);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Cap the end of the fraction string, if any */
|
|
|
|
|
*out = '\0';
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
/* Add in fractional value */
|
|
|
|
|
if (got_decimal && (*out_str != '\0'))
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
size_t len;
|
|
|
|
|
long long int fraction;
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
len = strlen(out_str);
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (len > 8)
|
|
|
|
|
{
|
|
|
|
|
out_str[8] = '\0';
|
|
|
|
|
len = 8;
|
|
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (sscanf (out_str, QOF_SCANF_LLD, &fraction) < 1)
|
|
|
|
|
{
|
|
|
|
|
g_free(out_str);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
denom = multiplier(len);
|
|
|
|
|
numer *= denom;
|
|
|
|
|
numer += fraction;
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
2009-12-29 20:12:48 +00:00
|
|
|
else if (monetary && auto_decimal_enabled && !got_decimal)
|
2000-08-31 07:16:55 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
if ((auto_decimal_places > 0) && (auto_decimal_places < 9))
|
|
|
|
|
{
|
|
|
|
|
denom = multiplier(auto_decimal_places);
|
|
|
|
|
|
|
|
|
|
/* No need to multiply numer by denom at this point,
|
|
|
|
|
* since by specifying the auto decimal places the
|
|
|
|
|
* user has effectively determined the scaling factor
|
|
|
|
|
* for the numerator they entered.
|
|
|
|
|
*/
|
|
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
}
|
2000-10-29 20:32:38 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (result != NULL)
|
2000-10-29 20:32:38 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
*result = gnc_numeric_create (numer, denom);
|
|
|
|
|
if (is_negative)
|
|
|
|
|
*result = gnc_numeric_neg (*result);
|
2000-10-29 20:32:38 +00:00
|
|
|
}
|
2000-08-31 07:16:55 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
if (endstr != NULL)
|
|
|
|
|
*endstr = (char *) in;
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
g_free (out_str);
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2009-12-29 20:12:48 +00:00
|
|
|
return TRUE;
|
2000-01-17 21:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
/* enable/disable the auto_decimal_enabled option */
|
2005-11-02 03:32:36 +00:00
|
|
|
static void
|
2013-10-07 14:13:51 +00:00
|
|
|
gnc_set_auto_decimal_enabled (gpointer settings, gchar *key, gpointer user_data)
|
2000-11-01 08:52:30 +00:00
|
|
|
{
|
2013-10-07 14:13:51 +00:00
|
|
|
auto_decimal_enabled =
|
|
|
|
|
gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_POINT);
|
2000-11-01 08:52:30 +00:00
|
|
|
}
|
2000-01-17 21:39:42 +00:00
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
/* set the number of auto decimal places to use */
|
2005-11-02 03:32:36 +00:00
|
|
|
static void
|
2013-10-07 14:13:51 +00:00
|
|
|
gnc_set_auto_decimal_places (gpointer settings, gchar *key, gpointer user_data)
|
2005-11-02 03:32:36 +00:00
|
|
|
{
|
2013-10-07 14:13:51 +00:00
|
|
|
auto_decimal_places =
|
2013-10-07 14:31:50 +00:00
|
|
|
gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_PLACES);
|
2005-11-02 03:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
2006-06-15 03:54:53 +00:00
|
|
|
static void
|
|
|
|
|
gnc_auto_decimal_init (void)
|
|
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
auto_decimal_enabled =
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_POINT);
|
2009-12-29 20:12:48 +00:00
|
|
|
auto_decimal_places =
|
2013-10-07 14:31:50 +00:00
|
|
|
gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_PLACES);
|
2006-06-15 03:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
void
|
2005-11-02 03:32:36 +00:00
|
|
|
gnc_ui_util_init (void)
|
2000-11-01 08:52:30 +00:00
|
|
|
{
|
2009-12-29 20:12:48 +00:00
|
|
|
gnc_configure_account_separator ();
|
|
|
|
|
gnc_auto_decimal_init();
|
|
|
|
|
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNT_SEPARATOR,
|
|
|
|
|
gnc_configure_account_separator, NULL);
|
2013-10-07 14:16:36 +00:00
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_NONE,
|
|
|
|
|
gnc_configure_reverse_balance, NULL);
|
|
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_CREDIT,
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_configure_reverse_balance, NULL);
|
2013-10-07 14:16:36 +00:00
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_INC_EXP,
|
|
|
|
|
gnc_configure_reverse_balance, NULL);
|
|
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_CURRENCY_CHOICE_LOCALE,
|
|
|
|
|
gnc_currency_changed_cb, NULL);
|
|
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_CURRENCY_CHOICE_OTHER,
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_currency_changed_cb, NULL);
|
|
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_CURRENCY_OTHER,
|
|
|
|
|
gnc_currency_changed_cb, NULL);
|
2013-10-07 14:16:36 +00:00
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL_REPORT, GNC_PREF_CURRENCY_CHOICE_LOCALE,
|
|
|
|
|
gnc_currency_changed_cb, NULL);
|
|
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL_REPORT, GNC_PREF_CURRENCY_CHOICE_OTHER,
|
|
|
|
|
gnc_currency_changed_cb, NULL);
|
|
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL_REPORT, GNC_PREF_CURRENCY_OTHER,
|
|
|
|
|
gnc_currency_changed_cb, NULL);
|
2013-10-07 14:08:17 +00:00
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_POINT,
|
|
|
|
|
gnc_set_auto_decimal_enabled, NULL);
|
|
|
|
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_PLACES,
|
|
|
|
|
gnc_set_auto_decimal_places, NULL);
|
2009-12-29 20:12:48 +00:00
|
|
|
|
2000-11-01 08:52:30 +00:00
|
|
|
}
|