2003-10-13 22:34:37 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gncOwner.c -- Business Interface: Object OWNERs *
|
|
|
|
* *
|
|
|
|
* 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*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2003-10-13 22:34:37 -05:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
|
|
|
|
2001-12-05 23:46:42 -06:00
|
|
|
/*
|
2002-01-22 09:51:14 -06:00
|
|
|
* Copyright (C) 2001, 2002 Derek Atkins
|
2003-10-13 22:34:37 -05:00
|
|
|
* Copyright (C) 2003 Linas Vepstas <linas@linas.org>
|
2005-11-01 21:32:36 -06:00
|
|
|
* Copyright (c) 2005 Neil Williams <linux@codehelp.co.uk>
|
2006-01-23 00:38:20 -06:00
|
|
|
* Copyright (c) 2006 David Hampton <hampton@employees.org>
|
2011-08-13 10:33:27 -05:00
|
|
|
* Copyright (c) 2011 Geert Janssens <geert@kobaltwit.be>
|
2001-12-05 23:46:42 -06:00
|
|
|
* Author: Derek Atkins <warlord@MIT.EDU>
|
|
|
|
*/
|
|
|
|
|
2014-05-07 08:37:14 -05:00
|
|
|
#include <config.h>
|
2001-12-05 23:46:42 -06:00
|
|
|
|
|
|
|
#include <glib.h>
|
2011-08-13 10:33:27 -05:00
|
|
|
#include <glib/gi18n.h>
|
2001-12-05 23:46:42 -06:00
|
|
|
#include <string.h> /* for memcpy() */
|
2014-05-07 08:37:14 -05:00
|
|
|
#include <qofinstance-p.h>
|
2001-12-05 23:46:42 -06:00
|
|
|
|
2003-10-13 22:34:37 -05:00
|
|
|
#include "gncCustomerP.h"
|
2003-10-21 00:12:38 -05:00
|
|
|
#include "gncEmployeeP.h"
|
2003-10-13 22:34:37 -05:00
|
|
|
#include "gncJobP.h"
|
2001-12-05 23:46:42 -06:00
|
|
|
#include "gncOwner.h"
|
2002-02-03 20:53:13 -06:00
|
|
|
#include "gncOwnerP.h"
|
2003-10-21 00:12:38 -05:00
|
|
|
#include "gncVendorP.h"
|
2011-08-13 10:33:27 -05:00
|
|
|
#include "gncInvoice.h"
|
|
|
|
#include "gnc-commodity.h"
|
2014-08-27 08:59:00 -05:00
|
|
|
#include "Scrub2.h"
|
2011-08-13 10:33:27 -05:00
|
|
|
#include "Split.h"
|
2014-08-27 08:59:00 -05:00
|
|
|
#include "Transaction.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 00:00:54 -06:00
|
|
|
#include "engine-helpers.h"
|
2002-02-03 20:53:13 -06:00
|
|
|
|
2011-03-20 14:17:11 -05:00
|
|
|
#define _GNC_MOD_NAME GNC_ID_OWNER
|
2001-12-05 23:46:42 -06:00
|
|
|
|
2011-03-20 14:17:11 -05:00
|
|
|
#define GNC_OWNER_ID "gncOwner"
|
2002-06-25 10:08:50 -05:00
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
static QofLogModule log_module = GNC_MOD_ENGINE;
|
|
|
|
|
2011-05-11 16:51:17 -05:00
|
|
|
GncOwner * gncOwnerNew (void)
|
2002-02-04 22:11:31 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncOwner *o;
|
2005-11-01 21:32:36 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
o = g_new0 (GncOwner, 1);
|
|
|
|
o->type = GNC_OWNER_NONE;
|
|
|
|
return o;
|
2002-02-04 22:11:31 -06:00
|
|
|
}
|
|
|
|
|
2011-05-11 16:51:17 -05:00
|
|
|
void gncOwnerFree (GncOwner *owner)
|
2002-02-04 22:11:31 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return;
|
|
|
|
g_free (owner);
|
2002-02-04 22:11:31 -06:00
|
|
|
}
|
|
|
|
|
2011-05-11 16:51:27 -05:00
|
|
|
void gncOwnerBeginEdit (GncOwner *owner)
|
|
|
|
{
|
|
|
|
if (!owner) return;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE :
|
|
|
|
case GNC_OWNER_UNDEFINED :
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_CUSTOMER :
|
|
|
|
{
|
|
|
|
gncCustomerBeginEdit(owner->owner.customer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_JOB :
|
|
|
|
{
|
|
|
|
gncJobBeginEdit(owner->owner.job);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_VENDOR :
|
|
|
|
{
|
|
|
|
gncVendorBeginEdit(owner->owner.vendor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_EMPLOYEE :
|
|
|
|
{
|
|
|
|
gncEmployeeBeginEdit(owner->owner.employee);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 08:37:14 -05:00
|
|
|
void gncOwnerCommitEdit (GncOwner *owner)
|
|
|
|
{
|
|
|
|
if (!owner) return;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE :
|
|
|
|
case GNC_OWNER_UNDEFINED :
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_CUSTOMER :
|
|
|
|
{
|
|
|
|
gncCustomerCommitEdit(owner->owner.customer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_JOB :
|
|
|
|
{
|
|
|
|
gncJobCommitEdit(owner->owner.job);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_VENDOR :
|
|
|
|
{
|
|
|
|
gncVendorCommitEdit(owner->owner.vendor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_EMPLOYEE :
|
|
|
|
{
|
|
|
|
gncEmployeeCommitEdit(owner->owner.employee);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-11 16:51:27 -05:00
|
|
|
|
|
|
|
void gncOwnerDestroy (GncOwner *owner)
|
|
|
|
{
|
|
|
|
if (!owner) return;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE :
|
|
|
|
case GNC_OWNER_UNDEFINED :
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_CUSTOMER :
|
|
|
|
{
|
|
|
|
gncCustomerDestroy(owner->owner.customer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_JOB :
|
|
|
|
{
|
|
|
|
gncJobDestroy(owner->owner.job);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_VENDOR :
|
|
|
|
{
|
|
|
|
gncVendorDestroy(owner->owner.vendor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_EMPLOYEE :
|
|
|
|
{
|
|
|
|
gncEmployeeDestroy(owner->owner.employee);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-05 23:46:42 -06:00
|
|
|
void gncOwnerInitUndefined (GncOwner *owner, gpointer obj)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return;
|
|
|
|
owner->type = GNC_OWNER_UNDEFINED;
|
|
|
|
owner->owner.undefined = obj;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return;
|
|
|
|
owner->type = GNC_OWNER_CUSTOMER;
|
|
|
|
owner->owner.customer = customer;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncOwnerInitJob (GncOwner *owner, GncJob *job)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return;
|
|
|
|
owner->type = GNC_OWNER_JOB;
|
|
|
|
owner->owner.job = job;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return;
|
|
|
|
owner->type = GNC_OWNER_VENDOR;
|
|
|
|
owner->owner.vendor = vendor;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2003-03-03 00:47:54 -06:00
|
|
|
void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return;
|
|
|
|
owner->type = GNC_OWNER_EMPLOYEE;
|
|
|
|
owner->owner.employee = employee;
|
2003-03-03 00:47:54 -06:00
|
|
|
}
|
|
|
|
|
2002-01-22 09:51:14 -06:00
|
|
|
GncOwnerType gncOwnerGetType (const GncOwner *owner)
|
2001-12-05 23:46:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return GNC_OWNER_NONE;
|
|
|
|
return owner->type;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2010-10-02 09:59:33 -05:00
|
|
|
QofIdTypeConst
|
2008-08-01 11:02:07 -05:00
|
|
|
qofOwnerGetType(const GncOwner *owner)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
2010-10-02 09:59:33 -05:00
|
|
|
return gncOwnerTypeToQofIdType(owner->type);
|
|
|
|
}
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2010-10-02 09:59:33 -05:00
|
|
|
QofIdTypeConst gncOwnerTypeToQofIdType(GncOwnerType t)
|
|
|
|
{
|
|
|
|
QofIdTypeConst type = NULL;
|
|
|
|
switch (t)
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE :
|
|
|
|
{
|
|
|
|
type = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_UNDEFINED :
|
|
|
|
{
|
|
|
|
type = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_CUSTOMER :
|
|
|
|
{
|
|
|
|
type = GNC_ID_CUSTOMER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_JOB :
|
|
|
|
{
|
|
|
|
type = GNC_ID_JOB;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_VENDOR :
|
|
|
|
{
|
|
|
|
type = GNC_ID_VENDOR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_EMPLOYEE :
|
|
|
|
{
|
|
|
|
type = GNC_ID_EMPLOYEE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return type;
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
QofInstance*
|
2008-08-01 11:02:07 -05:00
|
|
|
qofOwnerGetOwner (const GncOwner *owner)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
QofInstance *ent;
|
|
|
|
|
|
|
|
if (!owner)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ent = NULL;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE :
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_UNDEFINED :
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_CUSTOMER :
|
|
|
|
{
|
|
|
|
ent = QOF_INSTANCE(owner->owner.customer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_JOB :
|
|
|
|
{
|
|
|
|
ent = QOF_INSTANCE(owner->owner.job);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_VENDOR :
|
|
|
|
{
|
|
|
|
ent = QOF_INSTANCE(owner->owner.vendor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GNC_OWNER_EMPLOYEE :
|
|
|
|
{
|
|
|
|
ent = QOF_INSTANCE(owner->owner.employee);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ent;
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-04-01 17:18:50 -05:00
|
|
|
qofOwnerSetEntity (GncOwner *owner, QofInstance *ent)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner || !ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
if (0 == g_strcmp0(ent->e_type, GNC_ID_CUSTOMER))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
owner->type = GNC_OWNER_CUSTOMER;
|
|
|
|
gncOwnerInitCustomer(owner, (GncCustomer*)ent);
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
else if (0 == g_strcmp0(ent->e_type, GNC_ID_JOB))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
owner->type = GNC_OWNER_JOB;
|
|
|
|
gncOwnerInitJob(owner, (GncJob*)ent);
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
else if (0 == g_strcmp0(ent->e_type, GNC_ID_VENDOR))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
owner->type = GNC_OWNER_VENDOR;
|
|
|
|
gncOwnerInitVendor(owner, (GncVendor*)ent);
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
else if (0 == g_strcmp0(ent->e_type, GNC_ID_EMPLOYEE))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
owner->type = GNC_OWNER_EMPLOYEE;
|
|
|
|
gncOwnerInitEmployee(owner, (GncEmployee*)ent);
|
|
|
|
}
|
2011-05-11 16:52:12 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
owner->type = GNC_OWNER_NONE;
|
2011-07-17 12:35:30 -05:00
|
|
|
owner->owner.undefined = NULL;
|
2011-05-11 16:52:12 -05:00
|
|
|
}
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2011-08-17 05:54:27 -05:00
|
|
|
gboolean GNC_IS_OWNER (QofInstance *ent)
|
|
|
|
{
|
|
|
|
if (!ent)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return (GNC_IS_VENDOR(ent) ||
|
|
|
|
GNC_IS_CUSTOMER(ent) ||
|
|
|
|
GNC_IS_EMPLOYEE(ent) ||
|
|
|
|
GNC_IS_JOB(ent));
|
|
|
|
}
|
2002-01-22 09:51:14 -06:00
|
|
|
gpointer gncOwnerGetUndefined (const GncOwner *owner)
|
2001-12-05 23:46:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
|
|
|
if (owner->type != GNC_OWNER_UNDEFINED) return NULL;
|
|
|
|
return owner->owner.undefined;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2002-01-22 09:51:14 -06:00
|
|
|
GncCustomer * gncOwnerGetCustomer (const GncOwner *owner)
|
2001-12-05 23:46:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
|
|
|
if (owner->type != GNC_OWNER_CUSTOMER) return NULL;
|
|
|
|
return owner->owner.customer;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2002-01-22 09:51:14 -06:00
|
|
|
GncJob * gncOwnerGetJob (const GncOwner *owner)
|
2001-12-05 23:46:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
|
|
|
if (owner->type != GNC_OWNER_JOB) return NULL;
|
|
|
|
return owner->owner.job;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2002-01-22 09:51:14 -06:00
|
|
|
GncVendor * gncOwnerGetVendor (const GncOwner *owner)
|
2001-12-05 23:46:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
|
|
|
if (owner->type != GNC_OWNER_VENDOR) return NULL;
|
|
|
|
return owner->owner.vendor;
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2003-03-03 00:47:54 -06:00
|
|
|
GncEmployee * gncOwnerGetEmployee (const GncOwner *owner)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
|
|
|
if (owner->type != GNC_OWNER_EMPLOYEE) return NULL;
|
|
|
|
return owner->owner.employee;
|
2003-03-03 00:47:54 -06:00
|
|
|
}
|
|
|
|
|
2001-12-05 23:46:42 -06:00
|
|
|
void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!src || !dest) return;
|
|
|
|
if (src == dest) return;
|
|
|
|
memcpy (dest, src, sizeof (*dest));
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2002-01-22 09:51:14 -06:00
|
|
|
gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!a || !b) return FALSE;
|
|
|
|
if (gncOwnerGetType (a) != gncOwnerGetType (b)) return FALSE;
|
|
|
|
return (a->owner.undefined == b->owner.undefined);
|
2002-01-22 09:51:14 -06:00
|
|
|
}
|
|
|
|
|
2011-05-11 16:51:45 -05:00
|
|
|
int gncOwnerGCompareFunc (const GncOwner *a, const GncOwner *b)
|
|
|
|
{
|
|
|
|
if (gncOwnerEqual (a, b))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-03-20 14:33:55 -05:00
|
|
|
const char * gncOwnerGetID (const GncOwner *owner)
|
|
|
|
{
|
|
|
|
if (!owner) return NULL;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return gncCustomerGetID (owner->owner.customer);
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
return gncJobGetID (owner->owner.job);
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
return gncVendorGetID (owner->owner.vendor);
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return gncEmployeeGetID (owner->owner.employee);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncOwnerGetName (const GncOwner *owner)
|
2001-12-05 23:46:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return gncCustomerGetName (owner->owner.customer);
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
return gncJobGetName (owner->owner.job);
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
return gncVendorGetName (owner->owner.vendor);
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
2012-05-08 06:38:57 -05:00
|
|
|
return gncEmployeeGetName (owner->owner.employee);
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
2001-12-05 23:46:42 -06:00
|
|
|
}
|
|
|
|
|
2011-03-20 14:33:55 -05:00
|
|
|
GncAddress * gncOwnerGetAddr (const GncOwner *owner)
|
|
|
|
{
|
|
|
|
if (!owner) return NULL;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return gncCustomerGetAddr (owner->owner.customer);
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
return gncVendorGetAddr (owner->owner.vendor);
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return gncEmployeeGetAddr (owner->owner.employee);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 14:17:11 -05:00
|
|
|
gnc_commodity * gncOwnerGetCurrency (const GncOwner *owner)
|
|
|
|
{
|
|
|
|
if (!owner) return NULL;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return gncCustomerGetCurrency (owner->owner.customer);
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
return gncVendorGetCurrency (owner->owner.vendor);
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return gncEmployeeGetCurrency (owner->owner.employee);
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
return gncOwnerGetCurrency (gncJobGetOwner (owner->owner.job));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 14:33:55 -05:00
|
|
|
gboolean gncOwnerGetActive (const GncOwner *owner)
|
|
|
|
{
|
|
|
|
if (!owner) return FALSE;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return gncCustomerGetActive (owner->owner.customer);
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
return gncVendorGetActive (owner->owner.vendor);
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return gncEmployeeGetActive (owner->owner.employee);
|
|
|
|
case GNC_OWNER_JOB:
|
2011-05-11 16:50:25 -05:00
|
|
|
return gncJobGetActive (owner->owner.job);
|
2011-03-20 14:33:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-27 16:01:21 -05:00
|
|
|
const GncGUID * gncOwnerGetGUID (const GncOwner *owner)
|
2002-02-03 20:53:13 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
2002-02-03 20:53:13 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return qof_instance_get_guid (QOF_INSTANCE(owner->owner.customer));
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
return qof_instance_get_guid (QOF_INSTANCE(owner->owner.job));
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
return qof_instance_get_guid (QOF_INSTANCE(owner->owner.vendor));
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return qof_instance_get_guid (QOF_INSTANCE(owner->owner.employee));
|
|
|
|
}
|
2002-02-03 20:53:13 -06:00
|
|
|
}
|
|
|
|
|
2011-05-11 16:50:45 -05:00
|
|
|
void
|
|
|
|
gncOwnerSetActive (const GncOwner *owner, gboolean active)
|
|
|
|
{
|
|
|
|
if (!owner) return;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
gncCustomerSetActive (owner->owner.customer, active);
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
gncVendorSetActive (owner->owner.vendor, active);
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
gncEmployeeSetActive (owner->owner.employee, active);
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
gncJobSetActive (owner->owner.job, active);
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-27 16:01:21 -05:00
|
|
|
GncGUID gncOwnerRetGUID (GncOwner *owner)
|
2002-06-27 15:03:19 -05:00
|
|
|
{
|
2010-03-27 16:01:21 -05:00
|
|
|
const GncGUID *guid = gncOwnerGetGUID (owner);
|
2010-03-02 15:41:05 -06:00
|
|
|
if (guid)
|
|
|
|
return *guid;
|
|
|
|
return *guid_null ();
|
2002-06-27 15:03:19 -05:00
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
const GncOwner * gncOwnerGetEndOwner (const GncOwner *owner)
|
2002-02-03 20:53:13 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
|
|
|
switch (owner->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return owner;
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
return gncJobGetOwner (owner->owner.job);
|
|
|
|
}
|
2002-02-03 20:53:13 -06:00
|
|
|
}
|
|
|
|
|
2002-02-04 12:54:06 -06:00
|
|
|
int gncOwnerCompare (const GncOwner *a, const GncOwner *b)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!a && !b) return 0;
|
|
|
|
if (!a && b) return 1;
|
|
|
|
if (a && !b) return -1;
|
2002-02-04 12:54:06 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (a->type != b->type)
|
|
|
|
return (a->type - b->type);
|
2002-02-04 12:54:06 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
switch (a->type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_NONE:
|
|
|
|
case GNC_OWNER_UNDEFINED:
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return gncCustomerCompare (a->owner.customer, b->owner.customer);
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
return gncVendorCompare (a->owner.vendor, b->owner.vendor);
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return gncEmployeeCompare (a->owner.employee, b->owner.employee);
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
return gncJobCompare (a->owner.job, b->owner.job);
|
|
|
|
}
|
2002-02-04 12:54:06 -06:00
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
const GncGUID * gncOwnerGetEndGUID (const GncOwner *owner)
|
2002-02-03 20:53:13 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return NULL;
|
2011-10-10 07:34:58 -05:00
|
|
|
return gncOwnerGetGUID (gncOwnerGetEndOwner (owner));
|
2002-02-03 20:53:13 -06:00
|
|
|
}
|
2001-12-05 23:46:42 -06:00
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
|
2002-06-25 10:08:50 -05:00
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
if (!owner || !lot)
|
2010-03-02 15:41:05 -06:00
|
|
|
return;
|
2002-06-25 10:08:50 -05:00
|
|
|
|
2011-12-18 18:47:20 -06:00
|
|
|
gnc_lot_begin_edit (lot);
|
2002-06-25 10:08:50 -05:00
|
|
|
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_set (QOF_INSTANCE (lot),
|
2014-07-05 00:06:40 -05:00
|
|
|
GNC_OWNER_TYPE, (gint64)gncOwnerGetType (owner),
|
|
|
|
GNC_OWNER_GUID, gncOwnerGetGUID (owner),
|
2014-05-07 08:37:14 -05:00
|
|
|
NULL);
|
2011-12-19 05:27:41 -06:00
|
|
|
gnc_lot_commit_edit (lot);
|
2002-06-25 10:08:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
|
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
GncGUID *guid = NULL;
|
2010-03-02 15:41:05 -06:00
|
|
|
QofBook *book;
|
2014-05-07 08:37:14 -05:00
|
|
|
GncOwnerType type = GNC_OWNER_NONE;
|
2014-07-04 23:44:01 -05:00
|
|
|
guint64 type64 = 0;
|
2010-03-02 15:41:05 -06:00
|
|
|
|
|
|
|
if (!lot || !owner) return FALSE;
|
|
|
|
|
|
|
|
book = gnc_lot_get_book (lot);
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_get (QOF_INSTANCE (lot),
|
2014-07-05 00:06:40 -05:00
|
|
|
GNC_OWNER_TYPE, &type64,
|
|
|
|
GNC_OWNER_GUID, &guid,
|
2014-05-07 08:37:14 -05:00
|
|
|
NULL);
|
2014-07-04 23:44:01 -05:00
|
|
|
type = (GncOwnerType) type64;
|
2010-03-02 15:41:05 -06:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_JOB:
|
|
|
|
gncOwnerInitJob (owner, gncJobLookup (book, guid));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (owner->owner.undefined != NULL);
|
2002-06-25 10:08:50 -05:00
|
|
|
}
|
|
|
|
|
2016-03-25 11:39:20 -05:00
|
|
|
gboolean gncOwnerGetOwnerFromTxn (Transaction *txn, GncOwner *owner)
|
|
|
|
{
|
|
|
|
Split *apar_split = NULL;
|
|
|
|
|
|
|
|
if (!txn || !owner) return FALSE;
|
|
|
|
|
|
|
|
if (xaccTransGetTxnType (txn) == TXN_TYPE_NONE)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-11-13 12:15:04 -06:00
|
|
|
apar_split = xaccTransGetFirstAPARAcctSplit (txn, TRUE);
|
2016-03-25 11:39:20 -05:00
|
|
|
if (apar_split)
|
|
|
|
{
|
|
|
|
GNCLot *lot = xaccSplitGetLot (apar_split);
|
|
|
|
GncInvoice *invoice = gncInvoiceGetInvoiceFromLot (lot);
|
|
|
|
if (invoice)
|
|
|
|
gncOwnerCopy (gncInvoiceGetOwner (invoice), owner);
|
|
|
|
else if (!gncOwnerGetOwnerFromLot (lot, owner))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE; // Got owner from either invoice or lot
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gboolean gncOwnerIsValid (const GncOwner *owner)
|
2002-10-17 10:17:47 -05:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!owner) return FALSE;
|
|
|
|
return (owner->owner.undefined != NULL);
|
2002-10-17 10:17:47 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 09:35:15 -06:00
|
|
|
gboolean
|
|
|
|
gncOwnerLotMatchOwnerFunc (GNCLot *lot, gpointer user_data)
|
2011-08-13 10:33:27 -05:00
|
|
|
{
|
2012-05-08 06:39:09 -05:00
|
|
|
const GncOwner *req_owner = user_data;
|
|
|
|
GncOwner lot_owner;
|
|
|
|
const GncOwner *end_owner;
|
|
|
|
GncInvoice *invoice = gncInvoiceGetInvoiceFromLot (lot);
|
2011-08-13 10:33:27 -05:00
|
|
|
|
2012-05-08 06:39:09 -05:00
|
|
|
/* Determine the owner associated to the lot */
|
2011-08-13 10:33:27 -05:00
|
|
|
if (invoice)
|
2012-05-08 06:39:09 -05:00
|
|
|
/* Invoice lots */
|
|
|
|
end_owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
|
|
|
|
else if (gncOwnerGetOwnerFromLot (lot, &lot_owner))
|
|
|
|
/* Pre-payment lots */
|
|
|
|
end_owner = gncOwnerGetEndOwner (&lot_owner);
|
2011-08-13 10:33:27 -05:00
|
|
|
else
|
2012-05-08 06:39:09 -05:00
|
|
|
return FALSE;
|
2011-08-13 10:33:27 -05:00
|
|
|
|
2012-05-08 06:39:09 -05:00
|
|
|
/* Is this a lot for the requested owner ? */
|
|
|
|
return gncOwnerEqual (end_owner, req_owner);
|
2011-08-13 10:33:27 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 09:35:15 -06:00
|
|
|
gint
|
|
|
|
gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB)
|
2011-08-13 10:33:27 -05:00
|
|
|
{
|
|
|
|
GncInvoice *ia, *ib;
|
2017-12-29 15:07:08 -06:00
|
|
|
time64 da, db;
|
2011-08-13 10:33:27 -05:00
|
|
|
|
2012-02-10 09:35:15 -06:00
|
|
|
ia = gncInvoiceGetInvoiceFromLot (lotA);
|
|
|
|
ib = gncInvoiceGetInvoiceFromLot (lotB);
|
2011-08-13 10:33:27 -05:00
|
|
|
|
2012-02-10 09:35:15 -06:00
|
|
|
if (ia)
|
|
|
|
da = gncInvoiceGetDateDue (ia);
|
|
|
|
else
|
2017-12-31 06:37:02 -06:00
|
|
|
da = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_earliest_split (lotA)));
|
2012-02-10 09:35:15 -06:00
|
|
|
|
|
|
|
if (ib)
|
|
|
|
db = gncInvoiceGetDateDue (ib);
|
|
|
|
else
|
2017-12-31 06:37:02 -06:00
|
|
|
db = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_earliest_split (lotB)));
|
2011-08-13 10:33:27 -05:00
|
|
|
|
2017-12-29 15:07:08 -06:00
|
|
|
return (da > db) - (da < db);
|
2011-08-13 10:33:27 -05:00
|
|
|
}
|
|
|
|
|
2012-02-10 09:34:55 -06:00
|
|
|
GNCLot *
|
2018-08-02 15:55:24 -05:00
|
|
|
gncOwnerCreatePaymentLotSecs (const GncOwner *owner, Transaction **preset_txn,
|
|
|
|
Account *posted_acc, Account *xfer_acc,
|
|
|
|
gnc_numeric amount, gnc_numeric exch, time64 date,
|
|
|
|
const char *memo, const char *num)
|
2012-02-10 09:34:55 -06:00
|
|
|
{
|
|
|
|
QofBook *book;
|
|
|
|
Split *split;
|
|
|
|
const char *name;
|
|
|
|
gnc_commodity *commodity;
|
|
|
|
Split *xfer_split = NULL;
|
2016-03-25 10:16:00 -05:00
|
|
|
Transaction *txn = NULL;
|
2012-02-10 09:34:55 -06:00
|
|
|
GNCLot *payment_lot;
|
|
|
|
|
|
|
|
/* Verify our arguments */
|
|
|
|
if (!owner || !posted_acc || !xfer_acc) return NULL;
|
|
|
|
g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
|
|
|
|
|
|
|
|
/* Compute the ancillary data */
|
|
|
|
book = gnc_account_get_book (posted_acc);
|
|
|
|
name = gncOwnerGetName (gncOwnerGetEndOwner ((GncOwner*)owner));
|
|
|
|
commodity = gncOwnerGetCurrency (owner);
|
2012-08-04 11:09:04 -05:00
|
|
|
// reverse = use_reversed_payment_amounts(owner);
|
2012-02-10 09:34:55 -06:00
|
|
|
|
2016-03-25 10:16:00 -05:00
|
|
|
if (preset_txn && *preset_txn)
|
|
|
|
txn = *preset_txn;
|
|
|
|
|
2012-02-10 09:34:55 -06:00
|
|
|
if (txn)
|
|
|
|
{
|
2017-11-18 10:42:46 -06:00
|
|
|
xaccTransSetDescription (txn, name ? name : "");
|
|
|
|
|
2012-02-10 09:34:55 -06:00
|
|
|
/* Pre-existing transaction was specified. We completely clear it,
|
|
|
|
* except for the split in the transfer account, unless the
|
|
|
|
* transaction can't be reused (wrong currency, wrong transfer account).
|
|
|
|
* In that case, the transaction is simply removed and an new
|
|
|
|
* one created. */
|
|
|
|
|
|
|
|
xfer_split = xaccTransFindSplitByAccount(txn, xfer_acc);
|
|
|
|
|
|
|
|
if (xaccTransGetCurrency(txn) != gncOwnerGetCurrency (owner))
|
|
|
|
{
|
|
|
|
g_message("Uh oh, mismatching currency/commodity between selected transaction and owner. We fall back to manual creation of a new transaction.");
|
|
|
|
xfer_split = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xfer_split)
|
|
|
|
{
|
|
|
|
g_message("Huh? Asset account not found anymore. Fully deleting old txn and now creating a new one.");
|
|
|
|
|
|
|
|
xaccTransBeginEdit (txn);
|
|
|
|
xaccTransDestroy (txn);
|
|
|
|
xaccTransCommitEdit (txn);
|
|
|
|
|
|
|
|
txn = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
xaccTransBeginEdit (txn);
|
|
|
|
while (i < xaccTransCountSplits(txn))
|
|
|
|
{
|
|
|
|
Split *split = xaccTransGetSplit (txn, i);
|
|
|
|
if (split == xfer_split)
|
|
|
|
{
|
2014-02-17 14:22:23 -06:00
|
|
|
gnc_set_num_action (NULL, split, num, _("Payment"));
|
2012-02-10 09:34:55 -06:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xaccSplitDestroy(split);
|
|
|
|
}
|
|
|
|
}
|
2014-02-17 14:22:23 -06:00
|
|
|
/* Note: don't commit transaction now - that would insert an imbalance split.*/
|
2012-02-10 09:34:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the transaction if we don't have one yet */
|
|
|
|
if (!txn)
|
2014-02-17 14:22:23 -06:00
|
|
|
{
|
2012-02-10 09:34:55 -06:00
|
|
|
txn = xaccMallocTransaction (book);
|
2014-02-17 14:22:23 -06:00
|
|
|
xaccTransBeginEdit (txn);
|
|
|
|
}
|
2012-02-10 09:34:55 -06:00
|
|
|
|
|
|
|
/* Insert a split for the transfer account if we don't have one yet */
|
|
|
|
if (!xfer_split)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Set up the transaction */
|
|
|
|
xaccTransSetDescription (txn, name ? name : "");
|
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 00:00:54 -06:00
|
|
|
/* set per book option */
|
2012-02-10 09:34:55 -06:00
|
|
|
xaccTransSetCurrency (txn, commodity);
|
2012-12-01 16:44:53 -06:00
|
|
|
xaccTransSetDateEnteredSecs (txn, gnc_time (NULL));
|
2018-07-31 16:43:27 -05:00
|
|
|
xaccTransSetDatePostedSecs (txn, date);
|
2012-02-10 09:34:55 -06:00
|
|
|
|
|
|
|
|
|
|
|
/* The split for the transfer account */
|
|
|
|
split = xaccMallocSplit (book);
|
|
|
|
xaccSplitSetMemo (split, memo);
|
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 00:00:54 -06:00
|
|
|
/* set per book option */
|
|
|
|
gnc_set_num_action (NULL, split, num, _("Payment"));
|
2012-02-10 09:34:55 -06:00
|
|
|
xaccAccountBeginEdit (xfer_acc);
|
|
|
|
xaccAccountInsertSplit (xfer_acc, split);
|
|
|
|
xaccAccountCommitEdit (xfer_acc);
|
|
|
|
xaccTransAppendSplit (txn, split);
|
|
|
|
|
|
|
|
if (gnc_commodity_equal(xaccAccountGetCommodity(xfer_acc), commodity))
|
|
|
|
{
|
2012-08-04 11:09:04 -05:00
|
|
|
xaccSplitSetBaseValue (split, amount, commodity);
|
2012-02-10 09:34:55 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-13 10:43:54 -05:00
|
|
|
/* This will be a multi-currency transaction. The amount passed to this
|
|
|
|
* function is in the owner commodity (also used by the post account).
|
|
|
|
* For the xfer split we also need to value the payment in the xfer account's
|
|
|
|
* commodity.
|
|
|
|
* exch is from post account to xfer account so that can be used directly
|
|
|
|
* to calculate the equivalent amount in the xfer account's commodity. */
|
|
|
|
gnc_numeric xfer_amount = gnc_numeric_mul (amount, exch, GNC_DENOM_AUTO,
|
|
|
|
GNC_HOW_RND_ROUND_HALF_UP);
|
|
|
|
|
|
|
|
xaccSplitSetAmount(split, xfer_amount); /* Payment in xfer account currency */
|
|
|
|
xaccSplitSetValue(split, amount); /* Payment in transaction currency */
|
2012-02-10 09:34:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a split in the post account */
|
|
|
|
split = xaccMallocSplit (book);
|
|
|
|
xaccSplitSetMemo (split, memo);
|
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 00:00:54 -06:00
|
|
|
/* set per book option */
|
|
|
|
gnc_set_num_action (NULL, split, num, _("Payment"));
|
2012-02-10 09:34:55 -06:00
|
|
|
xaccAccountBeginEdit (posted_acc);
|
|
|
|
xaccAccountInsertSplit (posted_acc, split);
|
|
|
|
xaccAccountCommitEdit (posted_acc);
|
|
|
|
xaccTransAppendSplit (txn, split);
|
2012-08-04 11:09:04 -05:00
|
|
|
xaccSplitSetBaseValue (split, gnc_numeric_neg (amount), commodity);
|
2012-02-10 09:34:55 -06:00
|
|
|
|
|
|
|
/* Create a new lot for the payment */
|
|
|
|
payment_lot = gnc_lot_new (book);
|
|
|
|
gncOwnerAttachToLot (owner, payment_lot);
|
|
|
|
gnc_lot_add_split (payment_lot, split);
|
|
|
|
|
2014-02-17 14:22:23 -06:00
|
|
|
/* Mark the transaction as a payment */
|
|
|
|
gnc_set_num_action (txn, NULL, num, _("Payment"));
|
|
|
|
xaccTransSetTxnType (txn, TXN_TYPE_PAYMENT);
|
2012-02-10 09:34:55 -06:00
|
|
|
|
|
|
|
/* Commit this new transaction */
|
|
|
|
xaccTransCommitEdit (txn);
|
2016-03-25 10:16:00 -05:00
|
|
|
if (preset_txn)
|
|
|
|
*preset_txn = txn;
|
2012-02-10 09:34:55 -06:00
|
|
|
|
|
|
|
return payment_lot;
|
|
|
|
}
|
|
|
|
|
2014-08-27 04:45:07 -05:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
is_equal = 8,
|
|
|
|
is_more = 4,
|
|
|
|
is_less = 2,
|
|
|
|
is_pay_split = 1
|
|
|
|
} split_flags;
|
|
|
|
|
|
|
|
Split *gncOwnerFindOffsettingSplit (GNCLot *lot, gnc_numeric target_value)
|
|
|
|
{
|
|
|
|
SplitList *ls_iter = NULL;
|
|
|
|
Split *best_split = NULL;
|
|
|
|
gnc_numeric best_val = { 0, 1};
|
|
|
|
gint best_flags = 0;
|
|
|
|
|
|
|
|
if (!lot)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (ls_iter = gnc_lot_get_split_list (lot); ls_iter; ls_iter = ls_iter->next)
|
|
|
|
{
|
|
|
|
Split *split = ls_iter->data;
|
|
|
|
Transaction *txn;
|
|
|
|
gnc_numeric split_value;
|
|
|
|
gint new_flags = 0;
|
|
|
|
gint val_cmp = 0;
|
|
|
|
|
|
|
|
if (!split)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
txn = xaccSplitGetParent (split);
|
|
|
|
if (!txn)
|
|
|
|
{
|
|
|
|
// Ooops - the split doesn't belong to any transaction !
|
|
|
|
// This is not expected so issue a warning and continue with next split
|
|
|
|
PWARN("Encountered a split in a payment lot that's not part of any transaction. "
|
|
|
|
"This is unexpected! Skipping split %p.", split);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if this split has the opposite sign of the target value we want to offset
|
|
|
|
split_value = xaccSplitGetValue (split);
|
|
|
|
if (gnc_numeric_positive_p (target_value) == gnc_numeric_positive_p (split_value))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Ok we have found a split that potentially can offset the target value
|
|
|
|
// Let's see if it's better than what we have found already.
|
|
|
|
val_cmp = gnc_numeric_compare (gnc_numeric_abs (split_value),
|
|
|
|
gnc_numeric_abs (target_value));
|
|
|
|
if (val_cmp == 0)
|
|
|
|
new_flags += is_equal;
|
|
|
|
else if (val_cmp > 0)
|
|
|
|
new_flags += is_more;
|
|
|
|
else
|
|
|
|
new_flags += is_less;
|
|
|
|
|
|
|
|
if (xaccTransGetTxnType (txn) != TXN_TYPE_LINK)
|
|
|
|
new_flags += is_pay_split;
|
|
|
|
|
|
|
|
if ((new_flags >= best_flags) &&
|
|
|
|
(gnc_numeric_compare (gnc_numeric_abs (split_value),
|
|
|
|
gnc_numeric_abs (best_val)) > 0))
|
|
|
|
{
|
|
|
|
// The new split is a better match than what we found so far
|
|
|
|
best_split = split;
|
|
|
|
best_flags = new_flags;
|
|
|
|
best_val = split_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best_split;
|
|
|
|
}
|
|
|
|
|
2014-08-26 12:24:56 -05:00
|
|
|
gboolean
|
|
|
|
gncOwnerReduceSplitTo (Split *split, gnc_numeric target_value)
|
|
|
|
{
|
|
|
|
gnc_numeric split_val = xaccSplitGetValue (split);
|
|
|
|
gnc_numeric rem_val;
|
|
|
|
Split *rem_split;
|
|
|
|
Transaction *txn;
|
|
|
|
GNCLot *lot;
|
|
|
|
|
|
|
|
if (gnc_numeric_positive_p (split_val) != gnc_numeric_positive_p (target_value))
|
|
|
|
return FALSE; // Split and target value have to be of the same sign
|
|
|
|
|
|
|
|
if (gnc_numeric_equal (split_val, target_value))
|
|
|
|
return FALSE; // Split already has the target value
|
|
|
|
|
|
|
|
rem_val = gnc_numeric_sub (split_val, target_value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD); // note: values are of opposite sign
|
|
|
|
rem_split = xaccMallocSplit (xaccSplitGetBook (split));
|
|
|
|
xaccSplitCopyOnto (split, rem_split);
|
2016-11-06 10:11:30 -06:00
|
|
|
xaccSplitSetAmount (rem_split, rem_val);
|
2014-08-26 12:24:56 -05:00
|
|
|
xaccSplitSetValue (rem_split, rem_val);
|
|
|
|
|
|
|
|
txn = xaccSplitGetParent (split);
|
|
|
|
xaccTransBeginEdit (txn);
|
2016-11-06 10:11:30 -06:00
|
|
|
xaccSplitSetAmount (split, target_value);
|
2014-08-26 12:24:56 -05:00
|
|
|
xaccSplitSetValue (split, target_value);
|
|
|
|
xaccSplitSetParent (rem_split, txn);
|
|
|
|
xaccTransCommitEdit (txn);
|
|
|
|
|
|
|
|
lot = xaccSplitGetLot (split);
|
|
|
|
gnc_lot_add_split (lot, rem_split);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-08-26 12:00:41 -05:00
|
|
|
void
|
|
|
|
gncOwnerSetLotLinkMemo (Transaction *ll_txn)
|
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
gchar *memo_prefix = _("Offset between documents: ");
|
2014-08-26 12:00:41 -05:00
|
|
|
gchar *new_memo;
|
|
|
|
SplitList *lts_iter;
|
|
|
|
SplitList *splits = NULL, *siter;
|
|
|
|
GList *titles = NULL, *titer;
|
|
|
|
|
|
|
|
if (!ll_txn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (xaccTransGetTxnType (ll_txn) != TXN_TYPE_LINK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Find all splits in the lot link transaction that are also in a document lot
|
|
|
|
for (lts_iter = xaccTransGetSplitList (ll_txn); lts_iter; lts_iter = lts_iter->next)
|
|
|
|
{
|
|
|
|
Split *split = lts_iter->data;
|
|
|
|
GNCLot *lot;
|
|
|
|
GncInvoice *invoice;
|
|
|
|
gchar *title;
|
|
|
|
|
|
|
|
if (!split)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lot = xaccSplitGetLot (split);
|
|
|
|
if (!lot)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
invoice = gncInvoiceGetInvoiceFromLot (lot);
|
|
|
|
if (!invoice)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
title = g_strdup_printf ("%s %s", gncInvoiceGetTypeString (invoice), gncInvoiceGetID (invoice));
|
|
|
|
|
|
|
|
titles = g_list_insert_sorted (titles, title, (GCompareFunc)g_strcmp0);
|
|
|
|
splits = g_list_prepend (splits, split); // splits don't need to be sorted
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!titles)
|
|
|
|
return; // We didn't find document lots
|
|
|
|
|
|
|
|
// Create the memo as we'd want it to be
|
2014-08-27 08:59:00 -05:00
|
|
|
new_memo = g_strconcat (memo_prefix, titles->data, NULL);
|
2014-08-26 12:00:41 -05:00
|
|
|
for (titer = titles->next; titer; titer = titer->next)
|
|
|
|
{
|
|
|
|
gchar *tmp_memo = g_strconcat (new_memo, " - ", titer->data, NULL);
|
|
|
|
g_free (new_memo);
|
|
|
|
new_memo = tmp_memo;
|
|
|
|
}
|
|
|
|
g_list_free_full (titles, g_free);
|
|
|
|
|
|
|
|
// Update the memos of all the splits we found previously (if needed)
|
|
|
|
for (siter = splits; siter; siter = siter->next)
|
|
|
|
{
|
|
|
|
if (g_strcmp0 (xaccSplitGetMemo (siter->data), new_memo) != 0)
|
|
|
|
xaccSplitSetMemo (siter->data, new_memo);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (splits);
|
|
|
|
g_free (new_memo);
|
|
|
|
}
|
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
/* Find an existing lot link transaction in the given lot
|
|
|
|
* Only use a lot link that already links at least two
|
|
|
|
* documents (to avoid perpetuating the lot link proliferation
|
|
|
|
* that happened in 2.6.0-2.6.3).
|
|
|
|
*/
|
|
|
|
static Transaction *
|
|
|
|
get_ll_transaction_from_lot (GNCLot *lot)
|
|
|
|
{
|
|
|
|
SplitList *ls_iter;
|
|
|
|
|
|
|
|
/* This should really only be called on a document lot */
|
|
|
|
if (!gncInvoiceGetInvoiceFromLot (lot))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* The given lot is a valid document lot. Now iterate over all
|
|
|
|
* other lot links in this lot to find one more document lot.
|
|
|
|
*/
|
|
|
|
for (ls_iter = gnc_lot_get_split_list (lot); ls_iter; ls_iter = ls_iter->next)
|
|
|
|
{
|
|
|
|
Split *ls = ls_iter->data;
|
|
|
|
Transaction *ll_txn = xaccSplitGetParent (ls);
|
|
|
|
SplitList *ts_iter;
|
|
|
|
|
|
|
|
if (xaccTransGetTxnType (ll_txn) != TXN_TYPE_LINK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (ts_iter = xaccTransGetSplitList (ll_txn); ts_iter; ts_iter = ts_iter->next)
|
|
|
|
{
|
|
|
|
Split *ts = ts_iter->data;
|
|
|
|
GNCLot *tslot = xaccSplitGetLot (ts);
|
|
|
|
|
|
|
|
if (!tslot)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tslot == lot)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (gncInvoiceGetInvoiceFromLot (lot))
|
|
|
|
return ll_txn; /* Got one more document lot - mission accomplished */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The lot doesn't have an ll_txn with the requested criteria... */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gncOwnerCreateLotLink (GNCLot *from_lot, GNCLot *to_lot, const GncOwner *owner)
|
|
|
|
{
|
|
|
|
const gchar *action = _("Lot Link");
|
|
|
|
Account *acct = gnc_lot_get_account (from_lot);
|
|
|
|
const gchar *name = gncOwnerGetName (gncOwnerGetEndOwner (owner));
|
|
|
|
Transaction *ll_txn = NULL;
|
|
|
|
gnc_numeric from_lot_bal, to_lot_bal;
|
2017-12-31 06:37:02 -06:00
|
|
|
time64 from_time, to_time;
|
2014-08-27 08:59:00 -05:00
|
|
|
time64 time_posted;
|
|
|
|
Split *split;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (!gncInvoiceGetInvoiceFromLot (from_lot) ||
|
|
|
|
!gncInvoiceGetInvoiceFromLot (to_lot))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Determine transaction date based on lot splits */
|
2017-12-31 06:37:02 -06:00
|
|
|
from_time = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_latest_split (from_lot)));
|
|
|
|
to_time = xaccTransRetDatePosted (xaccSplitGetParent (gnc_lot_get_latest_split (to_lot)));
|
|
|
|
if (from_time >= to_time)
|
|
|
|
time_posted = from_time;
|
2014-08-27 08:59:00 -05:00
|
|
|
else
|
2017-12-31 06:37:02 -06:00
|
|
|
time_posted = to_time;
|
2014-08-27 08:59:00 -05:00
|
|
|
|
|
|
|
/* Figure out how much we can offset between the lots */
|
|
|
|
from_lot_bal = gnc_lot_get_balance (from_lot);
|
|
|
|
to_lot_bal = gnc_lot_get_balance (to_lot);
|
|
|
|
if (gnc_numeric_compare (gnc_numeric_abs (from_lot_bal),
|
|
|
|
gnc_numeric_abs (to_lot_bal)) > 0)
|
|
|
|
from_lot_bal = gnc_numeric_neg (to_lot_bal);
|
|
|
|
else
|
|
|
|
to_lot_bal = gnc_numeric_neg (from_lot_bal);
|
|
|
|
|
|
|
|
xaccAccountBeginEdit (acct);
|
|
|
|
|
|
|
|
/* Look for a pre-existing lot link we can extend */
|
|
|
|
ll_txn = get_ll_transaction_from_lot (from_lot);
|
|
|
|
|
|
|
|
if (!ll_txn)
|
|
|
|
ll_txn = get_ll_transaction_from_lot (to_lot);
|
|
|
|
|
|
|
|
if (!ll_txn)
|
|
|
|
{
|
|
|
|
/* No pre-existing lot link. Create one. */
|
|
|
|
ll_txn = xaccMallocTransaction (gnc_lot_get_book (from_lot));
|
|
|
|
xaccTransBeginEdit (ll_txn);
|
|
|
|
xaccTransSetDescription (ll_txn, name ? name : "(Unknown)");
|
|
|
|
xaccTransSetCurrency (ll_txn, xaccAccountGetCommodity(acct));
|
|
|
|
xaccTransSetDateEnteredSecs (ll_txn, gnc_time (NULL));
|
2017-12-31 06:37:02 -06:00
|
|
|
xaccTransSetDatePostedSecs (ll_txn, time_posted);
|
2014-08-27 08:59:00 -05:00
|
|
|
xaccTransSetTxnType (ll_txn, TXN_TYPE_LINK);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-31 06:37:02 -06:00
|
|
|
time64 time = xaccTransRetDatePosted (ll_txn);
|
2014-08-27 08:59:00 -05:00
|
|
|
xaccTransBeginEdit (ll_txn);
|
|
|
|
|
|
|
|
/* Maybe we need to update the post date of the transaction ? */
|
2017-12-31 06:37:02 -06:00
|
|
|
if (time_posted > time)
|
|
|
|
xaccTransSetDatePostedSecs (ll_txn, time_posted);
|
2014-08-27 08:59:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a split for the from_lot */
|
|
|
|
split = xaccMallocSplit (gnc_lot_get_book (from_lot));
|
|
|
|
/* set Action using utility function */
|
|
|
|
gnc_set_num_action (NULL, split, NULL, action);
|
|
|
|
xaccAccountInsertSplit (acct, split);
|
|
|
|
xaccTransAppendSplit (ll_txn, split);
|
|
|
|
/* To offset the lot balance, the split must be of the opposite sign */
|
|
|
|
xaccSplitSetBaseValue (split, gnc_numeric_neg (from_lot_bal), xaccAccountGetCommodity(acct));
|
|
|
|
gnc_lot_add_split (from_lot, split);
|
|
|
|
|
|
|
|
/* Create a split for the to_lot */
|
|
|
|
split = xaccMallocSplit (gnc_lot_get_book (to_lot));
|
|
|
|
/* set Action using utility function */
|
|
|
|
gnc_set_num_action (NULL, split, NULL, action);
|
|
|
|
xaccAccountInsertSplit (acct, split);
|
|
|
|
xaccTransAppendSplit (ll_txn, split);
|
|
|
|
/* To offset the lot balance, the split must be of the opposite sign */
|
|
|
|
xaccSplitSetBaseValue (split, gnc_numeric_neg (to_lot_bal), xaccAccountGetCommodity(acct));
|
|
|
|
gnc_lot_add_split (to_lot, split);
|
|
|
|
|
|
|
|
xaccTransCommitEdit (ll_txn);
|
|
|
|
|
|
|
|
|
|
|
|
/* Do some post-cleaning on the lots
|
|
|
|
* The above actions may have created splits that are
|
|
|
|
* in the same transaction and lot. These can be merged.
|
|
|
|
*/
|
|
|
|
xaccScrubMergeLotSubSplits (to_lot, FALSE);
|
|
|
|
xaccScrubMergeLotSubSplits (from_lot, FALSE);
|
|
|
|
/* And finally set the same memo for all remaining splits
|
|
|
|
* It's a convenience for the users to identify all documents
|
|
|
|
* involved in the link.
|
|
|
|
*/
|
|
|
|
gncOwnerSetLotLinkMemo (ll_txn);
|
|
|
|
xaccAccountCommitEdit (acct);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gncOwnerOffsetLots (GNCLot *from_lot, GNCLot *to_lot, const GncOwner *owner)
|
|
|
|
{
|
|
|
|
gnc_numeric target_offset;
|
|
|
|
Split *split;
|
|
|
|
|
|
|
|
/* from lot should not be a document lot because we're removing a split from there ! */
|
|
|
|
if (gncInvoiceGetInvoiceFromLot (from_lot))
|
|
|
|
{
|
|
|
|
PWARN ("from_lot %p is a document lot. That is not allowed in gncOwnerOffsetLots", from_lot);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get best matching split from from_lot to offset to_lot */
|
|
|
|
target_offset = gnc_lot_get_balance (to_lot);
|
|
|
|
if (gnc_numeric_zero_p (target_offset))
|
|
|
|
return; // to_lot is already balanced, nothing more to do
|
|
|
|
|
|
|
|
split = gncOwnerFindOffsettingSplit (from_lot, target_offset);
|
|
|
|
if (!split)
|
|
|
|
return; // No suitable offsetting split found, nothing more to do
|
|
|
|
|
|
|
|
/* If the offsetting split is bigger than the amount needed to balance
|
|
|
|
* to_lot, reduce the split so its reduced value closes to_lot exactly.
|
|
|
|
* Note the negation in the reduction function. The split must be of
|
|
|
|
* opposite sign of to_lot's balance in order to be able to close it.
|
|
|
|
*/
|
|
|
|
if (gnc_numeric_compare (gnc_numeric_abs (xaccSplitGetValue (split)),
|
|
|
|
gnc_numeric_abs (target_offset)) > 0)
|
|
|
|
gncOwnerReduceSplitTo (split, gnc_numeric_neg (target_offset));
|
|
|
|
|
|
|
|
/* Move the reduced split from from_lot to to_lot */
|
|
|
|
gnc_lot_add_split (to_lot, split);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-10 09:34:18 -06:00
|
|
|
void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots)
|
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
GList *left_iter;
|
2012-02-10 09:34:18 -06:00
|
|
|
|
|
|
|
/* General note: in the code below the term "payment" can
|
|
|
|
* both mean a true payment or a document of
|
|
|
|
* the opposite sign (invoice vs credit note) relative to
|
|
|
|
* the lot being processed. In general this function will
|
|
|
|
* perform a balancing action on a set of lots, so you
|
|
|
|
* will also find frequent references to balancing instead. */
|
|
|
|
|
2012-02-10 09:34:55 -06:00
|
|
|
/* Payments can only be applied when at least an owner
|
|
|
|
* and a list of lots to use are given */
|
2012-02-10 09:34:18 -06:00
|
|
|
if (!owner) return;
|
|
|
|
if (!lots) return;
|
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
for (left_iter = lots; left_iter; left_iter = left_iter->next)
|
2012-02-10 09:34:18 -06:00
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
GNCLot *left_lot = left_iter->data;
|
|
|
|
gnc_numeric left_lot_bal;
|
|
|
|
gboolean left_lot_has_doc;
|
|
|
|
gboolean left_modified = FALSE;
|
2012-02-10 09:34:18 -06:00
|
|
|
Account *acct;
|
2014-08-27 08:59:00 -05:00
|
|
|
GList *right_iter;
|
2012-02-10 09:34:18 -06:00
|
|
|
|
|
|
|
/* Only attempt to apply payments to open lots.
|
|
|
|
* Note that due to the iterative nature of this function lots
|
2014-08-27 08:59:00 -05:00
|
|
|
* in the list may become empty/closed before they are evaluated as
|
2012-02-10 09:34:18 -06:00
|
|
|
* base lot, so we should check this for each lot. */
|
2014-12-29 09:30:04 -06:00
|
|
|
if (!left_lot)
|
2014-08-27 08:59:00 -05:00
|
|
|
continue;
|
|
|
|
if (gnc_lot_count_splits (left_lot) == 0)
|
|
|
|
{
|
|
|
|
gnc_lot_destroy (left_lot);
|
2014-12-29 09:30:04 -06:00
|
|
|
left_iter->data = NULL;
|
2014-08-27 08:59:00 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (gnc_lot_is_closed (left_lot))
|
2012-02-10 09:34:18 -06:00
|
|
|
continue;
|
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
acct = gnc_lot_get_account (left_lot);
|
|
|
|
xaccAccountBeginEdit (acct);
|
2012-02-10 09:34:18 -06:00
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
left_lot_bal = gnc_lot_get_balance (left_lot);
|
|
|
|
left_lot_has_doc = (gncInvoiceGetInvoiceFromLot (left_lot) != NULL);
|
2012-02-10 09:34:18 -06:00
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
/* Attempt to offset left_lot with any of the remaining lots. To do so
|
|
|
|
* iterate over the remaining lots adding lot links or moving payments
|
|
|
|
* around.
|
2012-02-10 09:34:18 -06:00
|
|
|
*/
|
2014-08-27 08:59:00 -05:00
|
|
|
for (right_iter = left_iter->next; right_iter; right_iter = right_iter->next)
|
2012-02-10 09:34:18 -06:00
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
GNCLot *right_lot = right_iter->data;
|
|
|
|
gnc_numeric right_lot_bal;
|
|
|
|
gboolean right_lot_has_doc;
|
2012-02-10 09:34:18 -06:00
|
|
|
|
|
|
|
/* Only attempt to use open lots to balance the base lot.
|
|
|
|
* Note that due to the iterative nature of this function lots
|
2014-08-27 08:59:00 -05:00
|
|
|
* in the list may become empty/closed before they are evaluated as
|
2012-02-10 09:34:18 -06:00
|
|
|
* base lot, so we should check this for each lot. */
|
2014-12-29 09:30:04 -06:00
|
|
|
if (!right_lot)
|
2014-08-27 08:59:00 -05:00
|
|
|
continue;
|
|
|
|
if (gnc_lot_count_splits (right_lot) == 0)
|
|
|
|
{
|
|
|
|
gnc_lot_destroy (right_lot);
|
2014-12-29 09:30:04 -06:00
|
|
|
right_iter->data = NULL;
|
2014-08-27 08:59:00 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (gnc_lot_is_closed (right_lot))
|
2012-02-10 09:34:18 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Balancing transactions for invoice/payments can only happen
|
|
|
|
* in the same account. */
|
2014-08-27 08:59:00 -05:00
|
|
|
if (acct != gnc_lot_get_account (right_lot))
|
2012-02-10 09:34:18 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
/* Only attempt to balance if the base lot and balancing lot are
|
|
|
|
* of the opposite sign. (Otherwise we would increase the balance
|
|
|
|
* of the lot - Duh */
|
2014-08-27 08:59:00 -05:00
|
|
|
right_lot_bal = gnc_lot_get_balance (right_lot);
|
|
|
|
if (gnc_numeric_positive_p (left_lot_bal) == gnc_numeric_positive_p (right_lot_bal))
|
2012-02-10 09:34:18 -06:00
|
|
|
continue;
|
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
/* Ok we found two lots than can (partly) offset each other.
|
|
|
|
* Depending on the lot types, a different action is needed to accomplish this.
|
|
|
|
* 1. Both lots are document lots (invoices/credit notes)
|
|
|
|
* -> Create a lot linking transaction between the lots
|
|
|
|
* 2. Both lots are payment lots (lots without a document attached)
|
|
|
|
* -> Use part of the bigger lot to the close the smaller lot
|
|
|
|
* 3. One document lot with one payment lot
|
|
|
|
* -> Use (part of) the payment to offset (part of) the document lot,
|
|
|
|
* Which one will be closed depends on which is the bigger one
|
2012-02-10 09:34:18 -06:00
|
|
|
*/
|
2014-08-27 08:59:00 -05:00
|
|
|
right_lot_has_doc = (gncInvoiceGetInvoiceFromLot (right_lot) != NULL);
|
|
|
|
if (left_lot_has_doc && right_lot_has_doc)
|
|
|
|
gncOwnerCreateLotLink (left_lot, right_lot, owner);
|
|
|
|
else if (!left_lot_has_doc && !right_lot_has_doc)
|
2012-02-10 09:34:18 -06:00
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
gint cmp = gnc_numeric_compare (gnc_numeric_abs (left_lot_bal),
|
|
|
|
gnc_numeric_abs (right_lot_bal));
|
|
|
|
if (cmp >= 0)
|
|
|
|
gncOwnerOffsetLots (left_lot, right_lot, owner);
|
|
|
|
else
|
|
|
|
gncOwnerOffsetLots (right_lot, left_lot, owner);
|
2012-02-10 09:34:18 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
GNCLot *doc_lot = left_lot_has_doc ? left_lot : right_lot;
|
|
|
|
GNCLot *pay_lot = left_lot_has_doc ? right_lot : left_lot;
|
|
|
|
// Ok, let's try to move a payment from pay_lot to doc_lot
|
|
|
|
gncOwnerOffsetLots (pay_lot, doc_lot, owner);
|
2012-02-10 09:34:18 -06:00
|
|
|
}
|
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
/* If we get here, then right_lot was modified
|
|
|
|
* If the lot has a document, send an event for send an event for it as well
|
|
|
|
* so it gets potentially updated as paid */
|
2012-02-10 09:34:18 -06:00
|
|
|
|
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
GncInvoice *this_invoice = gncInvoiceGetInvoiceFromLot(right_lot);
|
2012-02-10 09:34:18 -06:00
|
|
|
if (this_invoice)
|
|
|
|
qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
|
|
|
|
}
|
2014-08-27 08:59:00 -05:00
|
|
|
left_modified = TRUE;
|
2012-02-10 09:34:18 -06:00
|
|
|
}
|
|
|
|
|
2014-08-27 08:59:00 -05:00
|
|
|
/* If left_lot was modified and the lot has a document,
|
|
|
|
* send an event for send an event for it as well
|
|
|
|
* so it gets potentially updated as paid */
|
|
|
|
if (left_modified)
|
2012-02-10 09:34:18 -06:00
|
|
|
{
|
2014-08-27 08:59:00 -05:00
|
|
|
GncInvoice *this_invoice = gncInvoiceGetInvoiceFromLot(left_lot);
|
2012-02-10 09:34:18 -06:00
|
|
|
if (this_invoice)
|
|
|
|
qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
|
|
|
|
}
|
2014-08-27 08:59:00 -05:00
|
|
|
xaccAccountCommitEdit (acct);
|
2012-02-10 09:34:18 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 06:39:09 -05:00
|
|
|
/*
|
|
|
|
* Create a payment of "amount" for the owner and match it with
|
2014-12-17 11:46:54 -06:00
|
|
|
* the set of lots passed in.
|
|
|
|
* If
|
|
|
|
* - no lots were given
|
|
|
|
* - auto_pay is true
|
|
|
|
* then all open lots for the owner are considered.
|
2012-05-08 06:39:09 -05:00
|
|
|
*/
|
|
|
|
void
|
2018-08-02 15:55:24 -05:00
|
|
|
gncOwnerApplyPaymentSecs (const GncOwner *owner, Transaction **preset_txn,
|
|
|
|
GList *lots, Account *posted_acc, Account *xfer_acc,
|
|
|
|
gnc_numeric amount, gnc_numeric exch, time64 date,
|
|
|
|
const char *memo, const char *num, gboolean auto_pay)
|
2012-05-08 06:39:09 -05:00
|
|
|
{
|
2014-02-19 00:35:17 -06:00
|
|
|
GNCLot *payment_lot = NULL;
|
2013-10-31 17:24:05 -05:00
|
|
|
GList *selected_lots = NULL;
|
2012-05-08 06:39:09 -05:00
|
|
|
|
|
|
|
/* Verify our arguments */
|
2014-02-17 19:03:44 -06:00
|
|
|
if (!owner || !posted_acc
|
|
|
|
|| (!xfer_acc && !gnc_numeric_zero_p (amount)) ) return;
|
2012-05-08 06:39:09 -05:00
|
|
|
g_return_if_fail (owner->owner.undefined);
|
|
|
|
|
2014-02-17 19:03:44 -06:00
|
|
|
/* If there's a real amount to transfer create a lot for this payment */
|
|
|
|
if (!gnc_numeric_zero_p (amount))
|
2018-08-02 15:55:24 -05:00
|
|
|
payment_lot = gncOwnerCreatePaymentLotSecs (owner, preset_txn,
|
|
|
|
posted_acc, xfer_acc,
|
|
|
|
amount, exch, date, memo,
|
|
|
|
num);
|
2012-05-08 06:39:09 -05:00
|
|
|
|
|
|
|
if (lots)
|
|
|
|
selected_lots = lots;
|
2013-10-31 17:24:05 -05:00
|
|
|
else if (auto_pay)
|
2012-05-08 06:39:09 -05:00
|
|
|
selected_lots = xaccAccountFindOpenLots (posted_acc, gncOwnerLotMatchOwnerFunc,
|
2013-10-31 17:22:53 -05:00
|
|
|
(gpointer)owner, NULL);
|
2012-05-08 06:39:09 -05:00
|
|
|
|
|
|
|
/* And link the selected lots and the payment lot together as well as possible.
|
|
|
|
* If the payment was bigger than the selected documents/overpayments, only
|
|
|
|
* part of the payment will be used. Similarly if more documents were selected
|
|
|
|
* than the payment value set, not all documents will be marked as paid. */
|
|
|
|
if (payment_lot)
|
|
|
|
selected_lots = g_list_prepend (selected_lots, payment_lot);
|
|
|
|
gncOwnerAutoApplyPaymentsWithLots (owner, selected_lots);
|
2013-10-31 17:24:05 -05:00
|
|
|
g_list_free (selected_lots);
|
2012-05-08 06:39:09 -05:00
|
|
|
}
|
|
|
|
|
2011-08-13 10:33:27 -05:00
|
|
|
GList *
|
|
|
|
gncOwnerGetAccountTypesList (const GncOwner *owner)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (owner, NULL);
|
|
|
|
|
|
|
|
switch (gncOwnerGetType (owner))
|
|
|
|
{
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_RECEIVABLE));
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_PAYABLE));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (g_list_prepend (NULL, (gpointer)ACCT_TYPE_NONE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
|
|
|
gncOwnerGetCommoditiesList (const GncOwner *owner)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (owner, NULL);
|
|
|
|
g_return_val_if_fail (gncOwnerGetCurrency(owner), NULL);
|
|
|
|
|
|
|
|
return (g_list_prepend (NULL, gncOwnerGetCurrency(owner)));
|
|
|
|
}
|
|
|
|
|
2011-08-13 10:33:42 -05:00
|
|
|
/*********************************************************************/
|
|
|
|
/* Owner balance calculation routines */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an owner, extract the open balance from the owner and then
|
|
|
|
* convert it to the desired currency.
|
|
|
|
*/
|
|
|
|
gnc_numeric
|
2011-09-30 13:47:43 -05:00
|
|
|
gncOwnerGetBalanceInCurrency (const GncOwner *owner,
|
2011-08-13 10:33:42 -05:00
|
|
|
const gnc_commodity *report_currency)
|
|
|
|
{
|
|
|
|
gnc_numeric balance = gnc_numeric_zero ();
|
|
|
|
GList *acct_list, *acct_node, *acct_types, *lot_list = NULL, *lot_node;
|
|
|
|
QofBook *book;
|
|
|
|
gnc_commodity *owner_currency;
|
|
|
|
GNCPriceDB *pdb;
|
|
|
|
|
|
|
|
g_return_val_if_fail (owner, gnc_numeric_zero ());
|
|
|
|
|
|
|
|
/* Get account list */
|
|
|
|
book = qof_instance_get_book (qofOwnerGetOwner (owner));
|
|
|
|
acct_list = gnc_account_get_descendants (gnc_book_get_root_account (book));
|
|
|
|
acct_types = gncOwnerGetAccountTypesList (owner);
|
|
|
|
owner_currency = gncOwnerGetCurrency (owner);
|
|
|
|
|
|
|
|
/* For each account */
|
|
|
|
for (acct_node = acct_list; acct_node; acct_node = acct_node->next)
|
|
|
|
{
|
|
|
|
Account *account = acct_node->data;
|
|
|
|
|
|
|
|
/* Check if this account can have lots for the owner, otherwise skip to next */
|
|
|
|
if (g_list_index (acct_types, (gpointer)xaccAccountGetType (account))
|
|
|
|
== -1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (!gnc_commodity_equal (owner_currency, xaccAccountGetCommodity (account)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Get a list of open lots for this owner and account */
|
2012-02-10 09:35:15 -06:00
|
|
|
lot_list = xaccAccountFindOpenLots (account, gncOwnerLotMatchOwnerFunc,
|
2012-02-10 09:34:28 -06:00
|
|
|
(gpointer)owner, NULL);
|
2011-08-13 10:33:42 -05:00
|
|
|
/* For each lot */
|
|
|
|
for (lot_node = lot_list; lot_node; lot_node = lot_node->next)
|
|
|
|
{
|
|
|
|
GNCLot *lot = lot_node->data;
|
|
|
|
gnc_numeric lot_balance = gnc_lot_get_balance (lot);
|
2014-08-31 01:36:59 -05:00
|
|
|
GncInvoice *invoice = gncInvoiceGetInvoiceFromLot(lot);
|
|
|
|
if (invoice)
|
|
|
|
balance = gnc_numeric_add (balance, lot_balance,
|
|
|
|
gnc_commodity_get_fraction (owner_currency), GNC_HOW_RND_ROUND_HALF_UP);
|
2011-08-13 10:33:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pdb = gnc_pricedb_get_db (book);
|
|
|
|
|
|
|
|
if (report_currency)
|
|
|
|
balance = gnc_pricedb_convert_balance_latest_price (
|
|
|
|
pdb, balance, owner_currency, report_currency);
|
|
|
|
|
|
|
|
return balance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-27 23:39:18 -05:00
|
|
|
/* XXX: Yea, this is broken, but it should work fine for Queries.
|
|
|
|
* We're single-threaded, right?
|
|
|
|
*/
|
|
|
|
static GncOwner *
|
|
|
|
owner_from_lot (GNCLot *lot)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
static GncOwner owner;
|
2002-06-27 23:39:18 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!lot) return NULL;
|
|
|
|
if (gncOwnerGetOwnerFromLot (lot, &owner))
|
|
|
|
return &owner;
|
2002-06-27 23:39:18 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return NULL;
|
2002-06-27 23:39:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reg_lot (void)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
static QofParam params[] =
|
|
|
|
{
|
|
|
|
{ OWNER_FROM_LOT, _GNC_MOD_NAME, (QofAccessFunc)owner_from_lot, NULL },
|
|
|
|
{ NULL },
|
|
|
|
};
|
2002-06-27 23:39:18 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
qof_class_register (GNC_ID_LOT, NULL, params);
|
2002-06-27 23:39:18 -05:00
|
|
|
}
|
|
|
|
|
2010-03-27 16:01:21 -05:00
|
|
|
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid)
|
2006-01-18 22:09:00 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!book || !owner || !type || !guid) return FALSE;
|
|
|
|
|
2012-08-07 12:24:55 -05:00
|
|
|
if (0 == g_strcmp0(type, GNC_ID_CUSTOMER))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
GncCustomer *customer = gncCustomerLookup(book, guid);
|
|
|
|
gncOwnerInitCustomer(owner, customer);
|
|
|
|
return (NULL != customer);
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
else if (0 == g_strcmp0(type, GNC_ID_JOB))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
GncJob *job = gncJobLookup(book, guid);
|
|
|
|
gncOwnerInitJob(owner, job);
|
|
|
|
return (NULL != job);
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
else if (0 == g_strcmp0(type, GNC_ID_VENDOR))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
GncVendor *vendor = gncVendorLookup(book, guid);
|
|
|
|
gncOwnerInitVendor(owner, vendor);
|
|
|
|
return (NULL != vendor);
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
else if (0 == g_strcmp0(type, GNC_ID_EMPLOYEE))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
GncEmployee *employee = gncEmployeeLookup(book, guid);
|
|
|
|
gncOwnerInitEmployee(owner, employee);
|
|
|
|
return (NULL != employee);
|
|
|
|
}
|
|
|
|
return 0;
|
2006-01-18 22:09:00 -06:00
|
|
|
}
|
|
|
|
|
2002-02-03 20:53:13 -06:00
|
|
|
gboolean gncOwnerRegister (void)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
static QofParam params[] =
|
|
|
|
{
|
|
|
|
{ OWNER_TYPE, QOF_TYPE_INT64, (QofAccessFunc)gncOwnerGetType, NULL },
|
|
|
|
{ OWNER_CUSTOMER, GNC_ID_CUSTOMER, (QofAccessFunc)gncOwnerGetCustomer, NULL },
|
|
|
|
{ OWNER_JOB, GNC_ID_JOB, (QofAccessFunc)gncOwnerGetJob, NULL },
|
|
|
|
{ OWNER_VENDOR, GNC_ID_VENDOR, (QofAccessFunc)gncOwnerGetVendor, NULL },
|
|
|
|
{ OWNER_EMPLOYEE, GNC_ID_EMPLOYEE, (QofAccessFunc)gncOwnerGetEmployee, NULL },
|
|
|
|
{ OWNER_PARENT, GNC_ID_OWNER, (QofAccessFunc)gncOwnerGetEndOwner, NULL },
|
|
|
|
{ OWNER_PARENTG, QOF_TYPE_GUID, (QofAccessFunc)gncOwnerGetEndGUID, NULL },
|
|
|
|
{ OWNER_NAME, QOF_TYPE_STRING, (QofAccessFunc)gncOwnerGetName, NULL },
|
|
|
|
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)gncOwnerGetGUID, NULL },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
qof_class_register (GNC_ID_OWNER, (QofSortFunc)gncOwnerCompare, params);
|
|
|
|
reg_lot ();
|
|
|
|
|
|
|
|
return TRUE;
|
2002-02-03 20:53:13 -06:00
|
|
|
}
|