2003-10-16 23:32:04 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* gncInvoice.c -- the Core Business Invoice *
|
|
|
|
* *
|
|
|
|
* 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-16 23:32:04 -05:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
/*
|
2006-02-26 23:42:45 -06:00
|
|
|
* Copyright (C) 2001,2002,2006 Derek Atkins
|
2003-10-21 21:02:45 -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>
|
2001-11-21 19:23:07 -06:00
|
|
|
* Author: Derek Atkins <warlord@MIT.EDU>
|
|
|
|
*/
|
|
|
|
|
2014-05-07 08:37:14 -05:00
|
|
|
#include <config.h>
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2018-01-20 14:32:42 -06:00
|
|
|
#include <stdint.h>
|
2001-11-21 19:23:07 -06:00
|
|
|
#include <glib.h>
|
2005-11-19 17:53:34 -06:00
|
|
|
#include <glib/gi18n.h>
|
2014-05-07 08:37:14 -05:00
|
|
|
#include <qofinstance-p.h>
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2003-10-21 21:02:45 -05:00
|
|
|
#include "Transaction.h"
|
|
|
|
#include "Account.h"
|
|
|
|
#include "gncBillTermP.h"
|
2001-11-21 19:23:07 -06:00
|
|
|
#include "gncEntry.h"
|
|
|
|
#include "gncEntryP.h"
|
2012-02-10 08:40:52 -06:00
|
|
|
#include "gnc-features.h"
|
2003-10-21 21:02:45 -05:00
|
|
|
#include "gncJobP.h"
|
2001-11-21 19:23:07 -06:00
|
|
|
#include "gncInvoice.h"
|
|
|
|
#include "gncInvoiceP.h"
|
2003-10-21 21:02:45 -05:00
|
|
|
#include "gncOwnerP.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"
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
struct _gncInvoice
|
|
|
|
{
|
2011-10-08 11:59:19 -05:00
|
|
|
QofInstance inst;
|
|
|
|
|
|
|
|
char *id;
|
|
|
|
char *notes;
|
|
|
|
gboolean active;
|
|
|
|
|
|
|
|
char *billing_id;
|
|
|
|
char *printname;
|
|
|
|
GncBillTerm *terms;
|
|
|
|
GList *entries;
|
|
|
|
GList *prices;
|
|
|
|
GncOwner owner;
|
|
|
|
GncOwner billto;
|
|
|
|
GncJob *job;
|
2017-12-29 15:07:08 -06:00
|
|
|
time64 date_opened;
|
|
|
|
time64 date_posted;
|
2011-10-08 11:59:19 -05:00
|
|
|
|
|
|
|
gnc_numeric to_charge_amount;
|
|
|
|
|
|
|
|
gnc_commodity *currency;
|
|
|
|
|
|
|
|
Account *posted_acc;
|
|
|
|
Transaction *posted_txn;
|
|
|
|
GNCLot *posted_lot;
|
2001-11-21 19:23:07 -06:00
|
|
|
};
|
|
|
|
|
2007-04-04 21:44:01 -05:00
|
|
|
struct _gncInvoiceClass
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
QofInstanceClass parent_class;
|
2007-04-04 21:44:01 -05:00
|
|
|
};
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static QofLogModule log_module = GNC_MOD_BUSINESS;
|
2002-11-03 14:21:42 -06:00
|
|
|
|
2011-11-10 09:04:50 -06:00
|
|
|
#define _GNC_MOD_NAME GNC_ID_INVOICE
|
2001-11-24 23:34:34 -06:00
|
|
|
|
2011-11-10 09:04:50 -06:00
|
|
|
#define GNC_INVOICE_IS_CN "credit-note"
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2002-11-03 18:41:01 -06:00
|
|
|
#define SET_STR(obj, member, str) { \
|
2001-11-21 19:23:07 -06:00
|
|
|
char * tmp; \
|
|
|
|
\
|
2012-08-07 12:24:55 -05:00
|
|
|
if (!g_strcmp0 (member, str)) return; \
|
2002-11-03 18:41:01 -06:00
|
|
|
gncInvoiceBeginEdit (obj); \
|
2001-11-21 19:23:07 -06:00
|
|
|
tmp = CACHE_INSERT (str); \
|
|
|
|
CACHE_REMOVE (member); \
|
|
|
|
member = tmp; \
|
|
|
|
}
|
|
|
|
|
2002-06-21 14:00:34 -05:00
|
|
|
static void mark_invoice (GncInvoice *invoice);
|
|
|
|
static void
|
2002-03-02 12:55:01 -06:00
|
|
|
mark_invoice (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
qof_instance_set_dirty(&invoice->inst);
|
|
|
|
qof_event_gen (&invoice->inst, QOF_EVENT_MODIFY, NULL);
|
2002-03-02 12:55:01 -06:00
|
|
|
}
|
|
|
|
|
2006-10-15 14:02:05 -05:00
|
|
|
QofBook * gncInvoiceGetBook(GncInvoice *x)
|
|
|
|
{
|
|
|
|
return qof_instance_get_book(QOF_INSTANCE(x));
|
|
|
|
}
|
|
|
|
|
2003-10-21 21:02:45 -05:00
|
|
|
/* ================================================================== */
|
2010-02-28 13:15:46 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
enum
|
|
|
|
{
|
2010-02-28 13:15:46 -06:00
|
|
|
PROP_0,
|
2014-05-07 08:37:14 -05:00
|
|
|
// PROP_ID, /* Table */
|
|
|
|
// PROP_DATE_OPENED, /* Table */
|
|
|
|
// PROP_DATE_POSTED, /* Table */
|
|
|
|
PROP_NOTES, /* Table */
|
|
|
|
// PROP_ACTIVE, /* Table */
|
|
|
|
// PROP_CURRENCY, /* Table */
|
|
|
|
// PROP_OWNER_TYPE, /* Table */
|
|
|
|
// PROP_OWNER, /* Table */
|
|
|
|
// PROP_TERMS, /* Table */
|
|
|
|
// PROP_BILLING_ID, /* Table */
|
|
|
|
// PROP_POST_TXN, /* Table */
|
|
|
|
// PROP_POST_LOT, /* Table */
|
|
|
|
// PROP_POST_ACCOUNT, /* Table */
|
|
|
|
// PROP_BILLTO_TYPE, /* Table */
|
|
|
|
// PROP_BILLTO, /* Table */
|
|
|
|
// PROP_CHARGE_AMOUNT, /* Table, (numeric) */
|
2010-02-28 13:15:46 -06:00
|
|
|
};
|
|
|
|
|
2007-04-04 21:44:01 -05:00
|
|
|
/* GObject Initialization */
|
2010-02-28 13:15:46 -06:00
|
|
|
G_DEFINE_TYPE(GncInvoice, gnc_invoice, QOF_TYPE_INSTANCE);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2007-04-04 21:44:01 -05:00
|
|
|
static void
|
|
|
|
gnc_invoice_init(GncInvoice* inv)
|
|
|
|
{
|
2018-01-20 14:32:42 -06:00
|
|
|
inv->date_posted = INT64_MAX;
|
|
|
|
inv->date_opened = INT64_MAX;
|
2007-04-04 21:44:01 -05:00
|
|
|
}
|
|
|
|
|
2007-04-04 22:10:26 -05:00
|
|
|
static void
|
2010-02-28 13:15:46 -06:00
|
|
|
gnc_invoice_dispose(GObject *invp)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS(gnc_invoice_parent_class)->dispose(invp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnc_invoice_finalize(GObject* invp)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS(gnc_invoice_parent_class)->finalize(invp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnc_invoice_get_property (GObject *object,
|
2010-03-02 15:41:05 -06:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-02-28 13:15:46 -06:00
|
|
|
{
|
|
|
|
GncInvoice *inv;
|
|
|
|
|
|
|
|
g_return_if_fail(GNC_IS_INVOICE(object));
|
|
|
|
|
|
|
|
inv = GNC_INVOICE(object);
|
2010-03-02 15:41:05 -06:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_NOTES:
|
|
|
|
g_value_set_string(value, inv->notes);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
2010-02-28 13:15:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnc_invoice_set_property (GObject *object,
|
2010-03-02 15:41:05 -06:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2007-04-04 22:10:26 -05:00
|
|
|
{
|
2010-02-28 13:15:46 -06:00
|
|
|
GncInvoice *inv;
|
|
|
|
|
|
|
|
g_return_if_fail(GNC_IS_INVOICE(object));
|
|
|
|
|
|
|
|
inv = GNC_INVOICE(object);
|
2014-05-07 08:37:14 -05:00
|
|
|
g_assert (qof_instance_get_editlevel(inv));
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_NOTES:
|
|
|
|
gncInvoiceSetNotes(inv, g_value_get_string(value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
2010-02-28 13:15:46 -06:00
|
|
|
}
|
2007-04-04 22:10:26 -05:00
|
|
|
}
|
|
|
|
|
2010-03-12 04:16:16 -06:00
|
|
|
/** Returns a string representing this object */
|
|
|
|
static gchar*
|
|
|
|
impl_get_display_name(const QofInstance* inst)
|
|
|
|
{
|
|
|
|
GncInvoice* inv;
|
|
|
|
QofInstance* owner;
|
|
|
|
gchar* s;
|
|
|
|
|
|
|
|
g_return_val_if_fail(inst != NULL, FALSE);
|
|
|
|
g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
|
|
|
|
|
|
|
|
inv = GNC_INVOICE(inst);
|
|
|
|
owner = qofOwnerGetOwner(&inv->owner);
|
|
|
|
if (owner != NULL)
|
|
|
|
{
|
|
|
|
gchar* display_name;
|
|
|
|
|
|
|
|
display_name = qof_instance_get_display_name(owner);
|
|
|
|
s = g_strdup_printf("Invoice %s (%s)", inv->id, display_name);
|
|
|
|
g_free(display_name);
|
|
|
|
}
|
2010-03-27 16:01:56 -05:00
|
|
|
else
|
|
|
|
{
|
2010-03-12 04:16:16 -06:00
|
|
|
s = g_strdup_printf("Invoice %s", inv->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Does this object refer to a specific object */
|
|
|
|
static gboolean
|
|
|
|
impl_refers_to_object(const QofInstance* inst, const QofInstance* ref)
|
|
|
|
{
|
|
|
|
GncInvoice* inv;
|
|
|
|
|
|
|
|
g_return_val_if_fail(inst != NULL, FALSE);
|
|
|
|
g_return_val_if_fail(GNC_IS_INVOICE(inst), FALSE);
|
|
|
|
|
|
|
|
inv = GNC_INVOICE(inst);
|
|
|
|
|
|
|
|
if (GNC_IS_BILLTERM(ref))
|
|
|
|
{
|
|
|
|
return (inv->terms == GNC_BILLTERM(ref));
|
|
|
|
}
|
|
|
|
else if (GNC_IS_JOB(ref))
|
|
|
|
{
|
|
|
|
return (inv->job == GNC_JOB(ref));
|
|
|
|
}
|
|
|
|
else if (GNC_IS_COMMODITY(ref))
|
|
|
|
{
|
|
|
|
return (inv->currency == GNC_COMMODITY(ref));
|
|
|
|
}
|
|
|
|
else if (GNC_IS_ACCOUNT(ref))
|
|
|
|
{
|
|
|
|
return (inv->posted_acc == GNC_ACCOUNT(ref));
|
|
|
|
}
|
|
|
|
else if (GNC_IS_TRANSACTION(ref))
|
|
|
|
{
|
|
|
|
return (inv->posted_txn == GNC_TRANSACTION(ref));
|
|
|
|
}
|
|
|
|
else if (GNC_IS_LOT(ref))
|
|
|
|
{
|
|
|
|
return (inv->posted_lot == GNC_LOT(ref));
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns a list of my type of object which refers to an object. For example, when called as
|
|
|
|
qof_instance_get_typed_referring_object_list(taxtable, account);
|
|
|
|
it will return the list of taxtables which refer to a specific account. The result should be the
|
|
|
|
same regardless of which taxtable object is used. The list must be freed by the caller but the
|
|
|
|
objects on the list must not.
|
|
|
|
*/
|
|
|
|
static GList*
|
|
|
|
impl_get_typed_referring_object_list(const QofInstance* inst, const QofInstance* ref)
|
|
|
|
{
|
|
|
|
if (!GNC_IS_BILLTERM(ref) && !GNC_IS_JOB(ref) && !GNC_IS_COMMODITY(ref) && !GNC_IS_ACCOUNT(ref)
|
|
|
|
&& !GNC_IS_TRANSACTION(ref) && !GNC_IS_LOT(ref))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qof_instance_get_referring_object_list_from_collection(qof_instance_get_collection(inst), ref);
|
|
|
|
}
|
|
|
|
|
2007-04-04 21:44:01 -05:00
|
|
|
static void
|
2010-02-28 13:15:46 -06:00
|
|
|
gnc_invoice_class_init (GncInvoiceClass *klass)
|
2007-04-04 21:44:01 -05:00
|
|
|
{
|
2010-02-28 13:15:46 -06:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2010-03-12 04:16:16 -06:00
|
|
|
QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2010-02-28 13:15:46 -06:00
|
|
|
gobject_class->dispose = gnc_invoice_dispose;
|
|
|
|
gobject_class->finalize = gnc_invoice_finalize;
|
|
|
|
gobject_class->set_property = gnc_invoice_set_property;
|
|
|
|
gobject_class->get_property = gnc_invoice_get_property;
|
|
|
|
|
2010-03-12 04:16:16 -06:00
|
|
|
qof_class->get_display_name = impl_get_display_name;
|
|
|
|
qof_class->refers_to_object = impl_refers_to_object;
|
|
|
|
qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
|
|
|
|
|
2010-02-28 13:15:46 -06:00
|
|
|
g_object_class_install_property
|
2010-03-02 15:41:05 -06:00
|
|
|
(gobject_class,
|
|
|
|
PROP_NOTES,
|
|
|
|
g_param_spec_string ("notes",
|
|
|
|
"Invoice Notes",
|
|
|
|
"The invoice notes is an arbitrary string "
|
|
|
|
"assigned by the user to provide notes regarding "
|
|
|
|
"this invoice.",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE));
|
2007-04-04 21:44:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create/Destroy Functions */
|
2003-06-26 22:05:25 -05:00
|
|
|
GncInvoice *gncInvoiceCreate (QofBook *book)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncInvoice *invoice;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!book) return NULL;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
|
|
|
|
qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->id = CACHE_INSERT ("");
|
|
|
|
invoice->notes = CACHE_INSERT ("");
|
|
|
|
invoice->billing_id = CACHE_INSERT ("");
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->billto.type = GNC_OWNER_CUSTOMER;
|
|
|
|
invoice->active = TRUE;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->to_charge_amount = gnc_numeric_zero();
|
2003-04-01 15:15:22 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
|
2002-03-02 12:55:01 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return invoice;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2011-01-12 14:40:51 -06:00
|
|
|
GncInvoice *gncInvoiceCopy (const GncInvoice *from)
|
|
|
|
{
|
|
|
|
GncInvoice *invoice;
|
|
|
|
QofBook* book;
|
|
|
|
GList *node;
|
2015-06-09 18:19:41 -05:00
|
|
|
GValue v = G_VALUE_INIT;
|
2011-01-12 14:40:51 -06:00
|
|
|
|
|
|
|
g_assert(from);
|
|
|
|
book = qof_instance_get_book(from);
|
|
|
|
g_assert(book);
|
|
|
|
|
|
|
|
invoice = g_object_new (GNC_TYPE_INVOICE, NULL);
|
|
|
|
qof_instance_init_data (&invoice->inst, _GNC_MOD_NAME, book);
|
|
|
|
|
|
|
|
gncInvoiceBeginEdit(invoice);
|
|
|
|
|
|
|
|
invoice->id = CACHE_INSERT (from->id);
|
|
|
|
invoice->notes = CACHE_INSERT (from->notes);
|
|
|
|
invoice->billing_id = CACHE_INSERT (from->billing_id);
|
|
|
|
invoice->active = from->active;
|
2011-11-10 09:04:50 -06:00
|
|
|
|
2017-12-10 07:42:08 -06:00
|
|
|
qof_instance_get_kvp (QOF_INSTANCE (from), &v, 1, GNC_INVOICE_IS_CN);
|
2015-06-09 18:19:41 -05:00
|
|
|
if (G_VALUE_HOLDS_INT64 (&v))
|
2017-12-10 07:42:08 -06:00
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (invoice), &v, 1, GNC_INVOICE_IS_CN);
|
2011-01-12 14:40:51 -06:00
|
|
|
|
|
|
|
invoice->terms = from->terms;
|
|
|
|
gncBillTermIncRef (invoice->terms);
|
|
|
|
|
|
|
|
gncOwnerCopy(&from->billto, &invoice->billto);
|
|
|
|
gncOwnerCopy(&from->owner, &invoice->owner);
|
|
|
|
invoice->job = from->job; // FIXME: Need IncRef or similar here?!?
|
|
|
|
|
|
|
|
invoice->to_charge_amount = from->to_charge_amount;
|
|
|
|
invoice->date_opened = from->date_opened;
|
|
|
|
|
2011-02-09 15:10:55 -06:00
|
|
|
// Oops. Do not forget to copy the pointer to the correct currency here.
|
|
|
|
invoice->currency = from->currency;
|
|
|
|
|
2011-01-12 14:40:51 -06:00
|
|
|
// Copy all invoice->entries
|
|
|
|
for (node = from->entries; node; node = node->next)
|
|
|
|
{
|
|
|
|
GncEntry *from_entry = node->data;
|
|
|
|
GncEntry *to_entry = gncEntryCreate(book);
|
2013-06-29 00:57:35 -05:00
|
|
|
gncEntryCopy(from_entry, to_entry, FALSE);
|
2011-01-12 14:40:51 -06:00
|
|
|
|
2011-04-10 15:18:38 -05:00
|
|
|
switch (gncInvoiceGetOwnerType (invoice))
|
2011-01-12 14:40:51 -06:00
|
|
|
{
|
2011-04-10 15:18:38 -05:00
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
// this is a vendor bill, or an expense voucher
|
2011-01-12 14:40:51 -06:00
|
|
|
gncBillAddEntry(invoice, to_entry);
|
2011-04-10 15:18:38 -05:00
|
|
|
break;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
default:
|
2011-01-12 14:40:51 -06:00
|
|
|
// this is an invoice
|
|
|
|
gncInvoiceAddEntry(invoice, to_entry);
|
2011-12-08 11:11:21 -06:00
|
|
|
break;
|
2011-01-12 14:40:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-16 15:09:53 -06:00
|
|
|
// FIXME: The prices are not (yet) copied; is this a problem?
|
|
|
|
|
|
|
|
// Posted-date and the posted Txn is intentionally not copied; the
|
|
|
|
// copy isn't "posted" but needs to be posted by the user.
|
2013-09-13 18:36:36 -05:00
|
|
|
mark_invoice (invoice);
|
2011-01-12 14:40:51 -06:00
|
|
|
gncInvoiceCommitEdit(invoice);
|
|
|
|
|
|
|
|
return invoice;
|
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceDestroy (GncInvoice *invoice)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
qof_instance_set_destroying(invoice, TRUE);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gncInvoiceFree (GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
qof_event_gen (&invoice->inst, QOF_EVENT_DESTROY, NULL);
|
2002-03-02 12:55:01 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
CACHE_REMOVE (invoice->id);
|
|
|
|
CACHE_REMOVE (invoice->notes);
|
|
|
|
CACHE_REMOVE (invoice->billing_id);
|
|
|
|
g_list_free (invoice->entries);
|
|
|
|
g_list_free (invoice->prices);
|
2001-11-24 23:34:34 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (invoice->printname) g_free (invoice->printname);
|
2002-02-23 22:01:57 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (invoice->terms)
|
|
|
|
gncBillTermDecRef (invoice->terms);
|
2003-06-14 00:17:07 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* qof_instance_release (&invoice->inst); */
|
|
|
|
g_object_unref (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2003-10-21 21:02:45 -05:00
|
|
|
/* ================================================================== */
|
2003-10-16 23:32:04 -05:00
|
|
|
/* Set Functions */
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceSetID (GncInvoice *invoice, const char *id)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !id) return;
|
|
|
|
SET_STR (invoice, invoice->id, id);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2001-12-05 23:46:42 -06:00
|
|
|
void gncInvoiceSetOwner (GncInvoice *invoice, GncOwner *owner)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !owner) return;
|
|
|
|
if (gncOwnerEqual (&invoice->owner, owner)) return;
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
gncOwnerCopy (owner, &invoice->owner);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static void
|
2007-04-01 17:18:50 -05:00
|
|
|
qofInvoiceSetOwner (GncInvoice *invoice, QofInstance *ent)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
qofOwnerSetEntity(&invoice->owner, ent);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-04-01 17:18:50 -05:00
|
|
|
qofInvoiceSetBillTo (GncInvoice *invoice, QofInstance *ent)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
qofOwnerSetEntity(&invoice->billto, ent);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2011-12-10 15:10:05 -06:00
|
|
|
void gncInvoiceSetDateOpenedGDate (GncInvoice *invoice, const GDate *date)
|
|
|
|
{
|
|
|
|
g_assert (date);
|
2017-12-29 15:07:08 -06:00
|
|
|
gncInvoiceSetDateOpened(invoice, time64CanonicalDayTime(gdate_to_time64 (*date)));
|
2011-12-10 15:10:05 -06:00
|
|
|
}
|
|
|
|
|
2017-12-29 15:07:08 -06:00
|
|
|
void gncInvoiceSetDateOpened (GncInvoice *invoice, time64 date)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
2017-12-29 15:07:08 -06:00
|
|
|
if (date == invoice->date_opened) return;
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->date_opened = date;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2017-12-29 15:07:08 -06:00
|
|
|
void gncInvoiceSetDatePosted (GncInvoice *invoice, time64 date)
|
2002-02-10 19:59:54 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
2017-12-29 15:07:08 -06:00
|
|
|
if (date == invoice->date_posted) return;
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->date_posted = date;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-02-10 19:59:54 -06:00
|
|
|
}
|
|
|
|
|
2002-06-21 21:38:13 -05:00
|
|
|
void gncInvoiceSetTerms (GncInvoice *invoice, GncBillTerm *terms)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
if (invoice->terms == terms) return;
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
if (invoice->terms)
|
|
|
|
gncBillTermDecRef (invoice->terms);
|
|
|
|
invoice->terms = terms;
|
|
|
|
if (invoice->terms)
|
|
|
|
gncBillTermIncRef (invoice->terms);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-05-08 15:42:38 -05:00
|
|
|
void gncInvoiceSetBillingID (GncInvoice *invoice, const char *billing_id)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
SET_STR (invoice, invoice->billing_id, billing_id);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncInvoiceSetNotes (GncInvoice *invoice, const char *notes)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !notes) return;
|
|
|
|
SET_STR (invoice, invoice->notes, notes);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncInvoiceSetActive (GncInvoice *invoice, gboolean active)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
if (invoice->active == active) return;
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->active = active;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2011-10-08 11:59:19 -05:00
|
|
|
void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note)
|
|
|
|
{
|
2015-06-09 18:19:41 -05:00
|
|
|
GValue v = G_VALUE_INIT;
|
2011-10-08 11:59:19 -05:00
|
|
|
if (!invoice) return;
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
2015-06-09 18:19:41 -05:00
|
|
|
g_value_init (&v, G_TYPE_INT64);
|
|
|
|
g_value_set_int64(&v, credit_note ? 1 : 0);
|
2017-12-10 07:42:08 -06:00
|
|
|
qof_instance_set_kvp (QOF_INSTANCE (invoice), &v, 1, GNC_INVOICE_IS_CN);
|
2011-10-08 11:59:19 -05:00
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2012-02-10 08:40:52 -06:00
|
|
|
|
|
|
|
/* If this is a credit note, set a feature flag for it in the book
|
|
|
|
* This will prevent older GnuCash versions that don't support
|
|
|
|
* credit notes to open this file. */
|
|
|
|
if (credit_note)
|
|
|
|
gnc_features_set_used (gncInvoiceGetBook (invoice), GNC_FEATURE_CREDIT_NOTES);
|
2011-10-08 11:59:19 -05:00
|
|
|
}
|
|
|
|
|
2003-01-12 16:07:33 -06:00
|
|
|
void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !currency) return;
|
|
|
|
if (invoice->currency &&
|
|
|
|
gnc_commodity_equal (invoice->currency, currency))
|
|
|
|
return;
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->currency = currency;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2002-07-10 16:07:46 -05:00
|
|
|
void gncInvoiceSetBillTo (GncInvoice *invoice, GncOwner *billto)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !billto) return;
|
|
|
|
if (gncOwnerEqual (&invoice->billto, billto)) return;
|
2002-07-10 16:07:46 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
gncOwnerCopy (billto, &invoice->billto);
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-07-10 16:07:46 -05:00
|
|
|
}
|
|
|
|
|
2003-04-01 15:15:22 -06:00
|
|
|
void gncInvoiceSetToChargeAmount (GncInvoice *invoice, gnc_numeric amount)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
if (gnc_numeric_equal (invoice->to_charge_amount, amount)) return;
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->to_charge_amount = amount;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2003-04-01 15:15:22 -06:00
|
|
|
}
|
|
|
|
|
2001-11-23 23:35:08 -06:00
|
|
|
void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
g_return_if_fail (invoice->posted_txn == NULL);
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->posted_txn = txn;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2002-06-24 17:30:36 -05:00
|
|
|
void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
g_return_if_fail (invoice->posted_lot == NULL);
|
2002-06-24 17:30:36 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->posted_lot = lot;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2002-06-24 17:30:36 -05:00
|
|
|
}
|
|
|
|
|
2001-11-23 23:35:08 -06:00
|
|
|
void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
g_return_if_fail (invoice->posted_acc == NULL);
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
invoice->posted_acc = acc;
|
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncInvoice *old;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2011-01-12 14:40:51 -06:00
|
|
|
g_assert(invoice);
|
|
|
|
g_assert(entry);
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !entry) return;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
old = gncEntryGetInvoice (entry);
|
|
|
|
if (old == invoice) return; /* I already own this one */
|
|
|
|
if (old) gncInvoiceRemoveEntry (old, entry);
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
2010-03-02 15:41:05 -06:00
|
|
|
gncEntrySetInvoice (entry, invoice);
|
|
|
|
invoice->entries = g_list_insert_sorted (invoice->entries, entry,
|
|
|
|
(GCompareFunc)gncEntryCompare);
|
|
|
|
mark_invoice (invoice);
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !entry) return;
|
2001-11-21 19:23:07 -06:00
|
|
|
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
2010-03-02 15:41:05 -06:00
|
|
|
gncEntrySetInvoice (entry, NULL);
|
|
|
|
invoice->entries = g_list_remove (invoice->entries, entry);
|
|
|
|
mark_invoice (invoice);
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceCommitEdit (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2008-11-26 07:06:44 -06:00
|
|
|
void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price)
|
|
|
|
{
|
2013-12-05 04:53:32 -06:00
|
|
|
GList *node;
|
|
|
|
gnc_commodity *commodity;
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !price) return;
|
2008-11-26 07:06:44 -06:00
|
|
|
|
2013-12-05 04:53:32 -06:00
|
|
|
/* Keep only one price per commodity per invoice
|
|
|
|
* So if a price was set previously remove it first */
|
|
|
|
node = g_list_first(invoice->prices);
|
|
|
|
commodity = gnc_price_get_commodity (price);
|
|
|
|
while (node != NULL)
|
|
|
|
{
|
|
|
|
GNCPrice *curr = (GNCPrice*)node->data;
|
|
|
|
if (gnc_commodity_equal (commodity, gnc_price_get_commodity (curr)))
|
|
|
|
break;
|
|
|
|
node = g_list_next (node);
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
2013-12-05 04:53:32 -06:00
|
|
|
if (node)
|
|
|
|
invoice->prices = g_list_delete_link (invoice->prices, node);
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->prices = g_list_prepend(invoice->prices, price);
|
|
|
|
mark_invoice (invoice);
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceCommitEdit (invoice);
|
2008-11-26 07:06:44 -06:00
|
|
|
}
|
|
|
|
|
2002-07-09 23:12:19 -05:00
|
|
|
void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncInvoice *old;
|
2002-07-09 23:12:19 -05:00
|
|
|
|
2011-01-12 14:40:51 -06:00
|
|
|
g_assert(bill);
|
|
|
|
g_assert(entry);
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!bill || !entry) return;
|
2002-07-09 23:12:19 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
old = gncEntryGetBill (entry);
|
|
|
|
if (old == bill) return; /* I already own this one */
|
|
|
|
if (old) gncBillRemoveEntry (old, entry);
|
2002-07-09 23:12:19 -05:00
|
|
|
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceBeginEdit (bill);
|
2010-03-02 15:41:05 -06:00
|
|
|
gncEntrySetBill (entry, bill);
|
|
|
|
bill->entries = g_list_insert_sorted (bill->entries, entry,
|
|
|
|
(GCompareFunc)gncEntryCompare);
|
|
|
|
mark_invoice (bill);
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceCommitEdit (bill);
|
2002-07-09 23:12:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!bill || !entry) return;
|
2002-07-09 23:12:19 -05:00
|
|
|
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceBeginEdit (bill);
|
2010-03-02 15:41:05 -06:00
|
|
|
gncEntrySetBill (entry, NULL);
|
|
|
|
bill->entries = g_list_remove (bill->entries, entry);
|
|
|
|
mark_invoice (bill);
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceCommitEdit (bill);
|
2002-07-09 23:12:19 -05:00
|
|
|
}
|
|
|
|
|
2006-02-01 15:49:06 -06:00
|
|
|
void gncInvoiceSortEntries (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return;
|
|
|
|
invoice->entries = g_list_sort(invoice->entries,
|
|
|
|
(GCompareFunc)gncEntryCompare);
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
2010-03-02 15:41:05 -06:00
|
|
|
mark_invoice(invoice);
|
2013-09-13 18:36:36 -05:00
|
|
|
gncInvoiceCommitEdit (invoice);
|
2006-02-01 15:49:06 -06:00
|
|
|
}
|
|
|
|
|
2013-11-16 06:51:54 -06:00
|
|
|
void gncInvoiceRemoveEntries (GncInvoice *invoice)
|
|
|
|
{
|
|
|
|
GList *node;
|
|
|
|
|
|
|
|
if (!invoice) return;
|
|
|
|
|
|
|
|
for (node = invoice->entries; node; node = node->next)
|
|
|
|
{
|
|
|
|
GncEntry *entry = node->data;
|
|
|
|
|
|
|
|
switch (gncInvoiceGetOwnerType (invoice))
|
|
|
|
{
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
case GNC_OWNER_EMPLOYEE:
|
|
|
|
// this is a vendor bill, or an expense voucher
|
|
|
|
gncBillRemoveEntry (invoice, entry);
|
|
|
|
break;
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
|
|
|
default:
|
|
|
|
// this is an invoice
|
|
|
|
gncInvoiceRemoveEntry (invoice, entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the entry is no longer referenced by any document,
|
|
|
|
* remove it.
|
|
|
|
*/
|
|
|
|
if (!(gncEntryGetInvoice (entry) ||
|
|
|
|
gncEntryGetBill (entry) ||
|
|
|
|
gncEntryGetOrder (entry)))
|
|
|
|
{
|
|
|
|
gncEntryBeginEdit (entry);
|
|
|
|
gncEntryDestroy (entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-21 21:02:45 -05:00
|
|
|
/* ================================================================== */
|
2001-11-21 19:23:07 -06:00
|
|
|
/* Get Functions */
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncInvoiceGetID (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->id;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
const GncOwner * gncInvoiceGetOwner (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return &invoice->owner;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
static QofInstance*
|
2005-11-01 21:32:36 -06:00
|
|
|
qofInvoiceGetOwner (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncOwner *owner;
|
2007-04-07 13:24:53 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
owner = &invoice->owner;
|
|
|
|
return QOF_INSTANCE(owner);
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2007-04-01 17:18:50 -05:00
|
|
|
static QofInstance*
|
2005-11-01 21:32:36 -06:00
|
|
|
qofInvoiceGetBillTo (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncOwner *billto;
|
2007-04-07 13:24:53 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
billto = &invoice->billto;
|
|
|
|
return QOF_INSTANCE(billto);
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2017-12-29 15:07:08 -06:00
|
|
|
time64 gncInvoiceGetDateOpened (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2018-01-20 14:32:42 -06:00
|
|
|
if (!invoice) return INT64_MAX;
|
2010-03-02 15:41:05 -06:00
|
|
|
return invoice->date_opened;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2017-12-29 15:07:08 -06:00
|
|
|
time64 gncInvoiceGetDatePosted (const GncInvoice *invoice)
|
2002-02-10 19:59:54 -06:00
|
|
|
{
|
2018-01-20 14:32:42 -06:00
|
|
|
if (!invoice) return INT64_MAX;
|
2010-03-02 15:41:05 -06:00
|
|
|
return invoice->date_posted;
|
2002-02-10 19:59:54 -06:00
|
|
|
}
|
|
|
|
|
2017-12-29 15:07:08 -06:00
|
|
|
time64 gncInvoiceGetDateDue (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
Transaction *txn;
|
2018-04-24 07:19:00 -05:00
|
|
|
if (!invoice) return INT64_MAX;
|
2017-12-29 15:07:08 -06:00
|
|
|
txn = gncInvoiceGetPostedTxn (invoice);
|
2018-04-24 07:19:00 -05:00
|
|
|
if (!txn) return INT64_MAX;
|
2017-12-29 15:07:08 -06:00
|
|
|
return xaccTransRetDateDue (txn);
|
2017-12-17 07:05:21 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->terms;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncInvoiceGetBillingID (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->billing_id;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
const char * gncInvoiceGetNotes (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->notes;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
GncOwnerType gncInvoiceGetOwnerType (const GncInvoice *invoice)
|
2002-05-16 17:45:50 -05:00
|
|
|
{
|
2011-10-09 16:06:31 -05:00
|
|
|
const GncOwner *owner;
|
2010-03-02 15:41:05 -06:00
|
|
|
g_return_val_if_fail (invoice, GNC_OWNER_NONE);
|
2002-05-16 17:45:50 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
|
|
|
|
return (gncOwnerGetType (owner));
|
2002-05-16 17:45:50 -05:00
|
|
|
}
|
|
|
|
|
2003-05-29 11:21:38 -05:00
|
|
|
static gnc_numeric
|
2018-05-24 11:53:15 -05:00
|
|
|
gncInvoiceSumTaxesInternal (AccountValueList *taxes)
|
|
|
|
{
|
|
|
|
gnc_numeric tt = gnc_numeric_zero();
|
|
|
|
|
|
|
|
if (taxes)
|
|
|
|
{
|
|
|
|
GList *node;
|
|
|
|
// Note we can use GNC_DENOM_AUTO below for rounding because
|
|
|
|
// the values passed to this function should already have been rounded
|
|
|
|
// to the desired denom and addition will just preserve it in that case.
|
|
|
|
for (node = taxes; node; node=node->next)
|
|
|
|
{
|
|
|
|
GncAccountValue *acc_val = node->data;
|
|
|
|
tt = gnc_numeric_add (tt, acc_val->value, GNC_DENOM_AUTO,
|
|
|
|
GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gnc_numeric
|
|
|
|
gncInvoiceGetNetAndTaxesInternal (GncInvoice *invoice, gboolean use_value,
|
|
|
|
AccountValueList **taxes,
|
|
|
|
gboolean use_payment_type, GncEntryPaymentType type
|
|
|
|
)
|
2002-10-27 20:23:08 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GList *node;
|
2018-05-24 11:53:15 -05:00
|
|
|
gnc_numeric net_total = gnc_numeric_zero();
|
2012-02-10 09:33:34 -06:00
|
|
|
gboolean is_cust_doc, is_cn;
|
2018-05-24 11:53:15 -05:00
|
|
|
AccountValueList *tv_list = NULL;
|
|
|
|
int denom = gnc_commodity_get_fraction(gncInvoiceGetCurrency(invoice));
|
2002-10-27 20:23:08 -06:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
g_return_val_if_fail (invoice, net_total);
|
2002-10-27 20:23:08 -06:00
|
|
|
|
2011-10-09 16:06:23 -05:00
|
|
|
/* Is the current document an invoice/credit note related to a customer or a vendor/employee ?
|
|
|
|
* The GncEntry code needs to know to return the proper entry amounts
|
|
|
|
*/
|
|
|
|
is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
|
2012-02-10 09:33:34 -06:00
|
|
|
is_cn = gncInvoiceGetIsCreditNote (invoice);
|
2002-10-27 20:23:08 -06:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
for (node = gncInvoiceGetEntries(invoice); node; node = node->next)
|
|
|
|
{
|
|
|
|
GncEntry *entry = node->data;
|
|
|
|
gnc_numeric value, tax;
|
2002-10-27 20:23:08 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (use_payment_type && gncEntryGetBillPayment (entry) != type)
|
|
|
|
continue;
|
2003-05-29 11:21:38 -05:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
if (use_value)
|
|
|
|
{
|
|
|
|
// Always use rounded net values to prevent creating imbalanced transactions on posting
|
2018-07-13 11:49:33 -05:00
|
|
|
// https://bugs.gnucash.org/show_bug.cgi?id=628903
|
2018-05-24 11:53:15 -05:00
|
|
|
value = gncEntryGetDocValue (entry, TRUE, is_cust_doc, is_cn);
|
|
|
|
if (gnc_numeric_check (value) == GNC_ERROR_OK)
|
|
|
|
net_total = gnc_numeric_add (net_total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
|
|
|
|
else
|
|
|
|
g_warning ("bad value in our entry");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (taxes)
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
2018-05-24 11:53:15 -05:00
|
|
|
AccountValueList *entrytaxes = gncEntryGetDocTaxValues (entry, is_cust_doc, is_cn);
|
|
|
|
tv_list = gncAccountValueAddList (tv_list, entrytaxes);
|
|
|
|
gncAccountValueDestroy (entrytaxes);
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
2018-05-24 11:53:15 -05:00
|
|
|
}
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
if (taxes)
|
|
|
|
{
|
|
|
|
GList *node;
|
|
|
|
// Round tax totals (accumulated per tax account) to prevent creating imbalanced transactions on posting
|
|
|
|
// which could otherwise happen when using a tax table with multiple tax rates
|
|
|
|
for (node = tv_list; node; node=node->next)
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
2018-05-24 11:53:15 -05:00
|
|
|
GncAccountValue *acc_val = node->data;
|
|
|
|
acc_val->value = gnc_numeric_convert (acc_val->value,
|
|
|
|
denom, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
2018-05-24 11:53:15 -05:00
|
|
|
*taxes = tv_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
return net_total;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gnc_numeric
|
|
|
|
gncInvoiceGetTotalInternal(GncInvoice *invoice, gboolean use_value,
|
|
|
|
gboolean use_tax,
|
|
|
|
gboolean use_payment_type, GncEntryPaymentType type)
|
|
|
|
{
|
|
|
|
AccountValueList *taxes;
|
|
|
|
gnc_numeric total;
|
|
|
|
int denom;
|
|
|
|
|
|
|
|
if (!invoice) return gnc_numeric_zero();
|
|
|
|
|
|
|
|
denom = gnc_commodity_get_fraction(gncInvoiceGetCurrency(invoice));
|
|
|
|
total = gncInvoiceGetNetAndTaxesInternal(invoice, use_value, use_tax? &taxes : NULL, use_payment_type, type);
|
|
|
|
|
|
|
|
if (use_tax)
|
|
|
|
{
|
|
|
|
// Note we can use GNC_DENOM_AUTO below for rounding because
|
|
|
|
// the values passed to this function should already have been rounded
|
|
|
|
// to the desired denom and addition will just preserve it in that case.
|
|
|
|
total = gnc_numeric_add (total, gncInvoiceSumTaxesInternal (taxes),
|
|
|
|
GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
|
|
|
|
gncAccountValueDestroy (taxes);
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
|
|
|
return total;
|
2002-10-27 20:23:08 -06:00
|
|
|
}
|
|
|
|
|
2003-05-29 11:21:38 -05:00
|
|
|
gnc_numeric gncInvoiceGetTotal (GncInvoice *invoice)
|
2003-04-01 15:15:22 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return gnc_numeric_zero();
|
|
|
|
return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, FALSE, 0);
|
2003-05-29 11:21:38 -05:00
|
|
|
}
|
2003-04-01 15:15:22 -06:00
|
|
|
|
2003-05-29 11:21:38 -05:00
|
|
|
gnc_numeric gncInvoiceGetTotalSubtotal (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return gnc_numeric_zero();
|
|
|
|
return gncInvoiceGetTotalInternal(invoice, TRUE, FALSE, FALSE, 0);
|
2003-05-29 11:21:38 -05:00
|
|
|
}
|
2003-04-01 15:15:22 -06:00
|
|
|
|
2003-05-29 11:21:38 -05:00
|
|
|
gnc_numeric gncInvoiceGetTotalTax (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return gnc_numeric_zero();
|
|
|
|
return gncInvoiceGetTotalInternal(invoice, FALSE, TRUE, FALSE, 0);
|
2003-05-29 11:21:38 -05:00
|
|
|
}
|
2003-04-01 15:15:22 -06:00
|
|
|
|
2003-05-29 11:21:38 -05:00
|
|
|
gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return gnc_numeric_zero();
|
|
|
|
return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, TRUE, type);
|
2003-04-01 15:15:22 -06:00
|
|
|
}
|
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
AccountValueList *gncInvoiceGetTotalTaxList (GncInvoice *invoice)
|
|
|
|
{
|
|
|
|
gnc_numeric unused;
|
|
|
|
AccountValueList *taxes;
|
|
|
|
if (!invoice) return NULL;
|
|
|
|
|
|
|
|
unused = gncInvoiceGetNetAndTaxesInternal(invoice, FALSE, &taxes, FALSE, 0);
|
|
|
|
return taxes;
|
|
|
|
}
|
|
|
|
|
2011-10-09 16:06:02 -05:00
|
|
|
GList * gncInvoiceGetTypeListForOwnerType (GncOwnerType type)
|
2002-05-16 17:45:50 -05:00
|
|
|
{
|
2011-10-09 16:06:02 -05:00
|
|
|
GList *type_list = NULL;
|
2010-05-06 10:15:36 -05:00
|
|
|
switch (type)
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
2011-10-09 16:06:02 -05:00
|
|
|
type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_CUST_INVOICE));
|
|
|
|
type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_CUST_CREDIT_NOTE));
|
|
|
|
return type_list;
|
2010-03-02 15:41:05 -06:00
|
|
|
case GNC_OWNER_VENDOR:
|
2011-10-09 16:06:02 -05:00
|
|
|
type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_VEND_INVOICE));
|
|
|
|
type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_VEND_CREDIT_NOTE));
|
|
|
|
return type_list;
|
2010-03-02 15:41:05 -06:00
|
|
|
case GNC_OWNER_EMPLOYEE:
|
2011-10-09 16:06:02 -05:00
|
|
|
type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_EMPL_INVOICE));
|
|
|
|
type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_EMPL_CREDIT_NOTE));
|
|
|
|
return type_list;
|
2010-03-02 15:41:05 -06:00
|
|
|
default:
|
2011-10-09 16:06:02 -05:00
|
|
|
return NULL;
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
2010-05-06 10:15:36 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
GncInvoiceType gncInvoiceGetType (const GncInvoice *invoice)
|
2010-05-06 10:15:36 -05:00
|
|
|
{
|
2011-10-08 11:59:01 -05:00
|
|
|
if (!invoice) return GNC_INVOICE_UNDEFINED;
|
|
|
|
switch (gncInvoiceGetOwnerType (invoice))
|
|
|
|
{
|
|
|
|
case GNC_OWNER_CUSTOMER:
|
2011-11-10 09:04:50 -06:00
|
|
|
return (gncInvoiceGetIsCreditNote(invoice) ?
|
2012-01-01 14:36:46 -06:00
|
|
|
GNC_INVOICE_CUST_CREDIT_NOTE :
|
|
|
|
GNC_INVOICE_CUST_INVOICE);
|
2011-10-08 11:59:01 -05:00
|
|
|
case GNC_OWNER_VENDOR:
|
2011-11-10 09:04:50 -06:00
|
|
|
return (gncInvoiceGetIsCreditNote(invoice) ?
|
2012-01-01 14:36:46 -06:00
|
|
|
GNC_INVOICE_VEND_CREDIT_NOTE :
|
|
|
|
GNC_INVOICE_VEND_INVOICE);
|
2011-10-08 11:59:01 -05:00
|
|
|
case GNC_OWNER_EMPLOYEE:
|
2011-11-10 09:04:50 -06:00
|
|
|
return (gncInvoiceGetIsCreditNote(invoice) ?
|
2012-01-01 14:36:46 -06:00
|
|
|
GNC_INVOICE_EMPL_CREDIT_NOTE :
|
|
|
|
GNC_INVOICE_EMPL_INVOICE);
|
2011-10-08 11:59:01 -05:00
|
|
|
default:
|
2011-11-10 09:05:05 -06:00
|
|
|
PWARN ("No invoice types defined for owner %d",
|
2012-01-01 14:36:46 -06:00
|
|
|
gncInvoiceGetOwnerType (invoice));
|
2011-10-08 11:59:01 -05:00
|
|
|
return GNC_INVOICE_UNDEFINED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
const char * gncInvoiceGetTypeString (const GncInvoice *invoice)
|
2011-10-08 11:59:01 -05:00
|
|
|
{
|
|
|
|
GncInvoiceType type = gncInvoiceGetType(invoice);
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GNC_INVOICE_CUST_INVOICE:
|
|
|
|
return _("Invoice");
|
|
|
|
case GNC_INVOICE_VEND_INVOICE:
|
|
|
|
return _("Bill");
|
|
|
|
case GNC_INVOICE_EMPL_INVOICE:
|
|
|
|
return _("Expense");
|
|
|
|
case GNC_INVOICE_CUST_CREDIT_NOTE:
|
|
|
|
case GNC_INVOICE_VEND_CREDIT_NOTE:
|
|
|
|
case GNC_INVOICE_EMPL_CREDIT_NOTE:
|
2013-10-31 17:25:03 -05:00
|
|
|
return _("Credit Note");
|
2011-10-08 11:59:01 -05:00
|
|
|
default:
|
2011-11-10 09:05:05 -06:00
|
|
|
PWARN("Unknown invoice type");
|
2011-10-08 11:59:01 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-05-16 17:45:50 -05:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->currency;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2002-07-10 16:07:46 -05:00
|
|
|
GncOwner * gncInvoiceGetBillTo (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return &invoice->billto;
|
2002-07-10 16:07:46 -05:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
GNCLot * gncInvoiceGetPostedLot (const GncInvoice *invoice)
|
2002-06-25 10:08:50 -05:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->posted_lot;
|
2002-06-25 10:08:50 -05:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
Transaction * gncInvoiceGetPostedTxn (const GncInvoice *invoice)
|
2001-11-23 23:35:08 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->posted_txn;
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
Account * gncInvoiceGetPostedAcc (const GncInvoice *invoice)
|
2001-11-23 23:35:08 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->posted_acc;
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gboolean gncInvoiceGetActive (const GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return FALSE;
|
|
|
|
return invoice->active;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2011-10-08 11:59:19 -05:00
|
|
|
gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice)
|
|
|
|
{
|
2015-06-09 18:19:41 -05:00
|
|
|
GValue v = G_VALUE_INIT;
|
2011-10-08 11:59:19 -05:00
|
|
|
if (!invoice) return FALSE;
|
2017-12-10 07:42:08 -06:00
|
|
|
qof_instance_get_kvp (QOF_INSTANCE(invoice), &v, 1, GNC_INVOICE_IS_CN);
|
2015-06-09 18:19:41 -05:00
|
|
|
if (G_VALUE_HOLDS_INT64(&v) && g_value_get_int64(&v))
|
2011-11-10 09:04:50 -06:00
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2011-10-08 11:59:19 -05:00
|
|
|
}
|
|
|
|
|
2004-10-15 21:49:29 -05:00
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gnc_numeric gncInvoiceGetToChargeAmount (const GncInvoice *invoice)
|
2003-04-01 15:15:22 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return gnc_numeric_zero();
|
|
|
|
return invoice->to_charge_amount;
|
2003-04-01 15:15:22 -06:00
|
|
|
}
|
|
|
|
|
2006-10-15 14:02:05 -05:00
|
|
|
EntryList * gncInvoiceGetEntries (GncInvoice *invoice)
|
2001-11-21 19:23:07 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return NULL;
|
|
|
|
return invoice->entries;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2008-11-26 07:06:44 -06:00
|
|
|
GNCPrice * gncInvoiceGetPrice(GncInvoice *invoice, gnc_commodity *commodity)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GList *node = g_list_first(invoice->prices);
|
2008-11-26 07:06:44 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
while (node != NULL)
|
|
|
|
{
|
|
|
|
GNCPrice *curr = (GNCPrice*)node->data;
|
2008-11-26 07:06:44 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (gnc_commodity_equal(commodity, gnc_price_get_commodity(curr)))
|
|
|
|
return curr;
|
2008-11-26 07:06:44 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
node = g_list_next(node);
|
|
|
|
}
|
2008-11-26 07:06:44 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return NULL;
|
2008-11-26 07:06:44 -06:00
|
|
|
}
|
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static QofCollection*
|
|
|
|
qofInvoiceGetEntries (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
QofCollection *entry_coll;
|
|
|
|
GList *list;
|
|
|
|
QofInstance *entry;
|
2005-11-01 21:32:36 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
entry_coll = qof_collection_new(GNC_ID_ENTRY);
|
|
|
|
for (list = gncInvoiceGetEntries(invoice); list != NULL; list = list->next)
|
|
|
|
{
|
|
|
|
entry = QOF_INSTANCE(list->data);
|
|
|
|
qof_collection_add_entity(entry_coll, entry);
|
|
|
|
}
|
|
|
|
return entry_coll;
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-04-01 17:18:50 -05:00
|
|
|
qofInvoiceEntryCB (QofInstance *ent, gpointer user_data)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncInvoice *invoice;
|
|
|
|
|
|
|
|
invoice = (GncInvoice*)user_data;
|
|
|
|
if (!invoice || !ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (gncInvoiceGetOwnerType (invoice))
|
|
|
|
{
|
|
|
|
case GNC_OWNER_VENDOR:
|
|
|
|
{
|
|
|
|
gncBillAddEntry (invoice, (GncEntry*) ent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default :
|
|
|
|
{
|
|
|
|
gncInvoiceAddEntry(invoice, (GncEntry*)ent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
static void
|
2005-11-01 21:32:36 -06:00
|
|
|
qofInvoiceSetEntries(GncInvoice *invoice, QofCollection *entry_coll)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!entry_coll)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-08-07 12:24:55 -05:00
|
|
|
if (0 == g_strcmp0(qof_collection_get_type(entry_coll), GNC_ID_ENTRY))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
qof_collection_foreach(entry_coll, qofInvoiceEntryCB, invoice);
|
|
|
|
}
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static GncJob*
|
2008-08-01 11:02:07 -05:00
|
|
|
qofInvoiceGetJob (const GncInvoice *invoice)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return invoice->job;
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
static void
|
2005-11-01 21:32:36 -06:00
|
|
|
qofInvoiceSetJob (GncInvoice *invoice, GncJob *job)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
invoice->job = job;
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2016-11-11 07:03:13 -06:00
|
|
|
void
|
2003-01-01 22:07:58 -06:00
|
|
|
gncInvoiceDetachFromLot (GNCLot *lot)
|
|
|
|
{
|
2014-05-07 11:08:34 -05:00
|
|
|
if (!lot) return;
|
2014-05-07 08:37:14 -05:00
|
|
|
|
2011-12-18 18:47:20 -06:00
|
|
|
gnc_lot_begin_edit (lot);
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_set (QOF_INSTANCE (lot), "invoice", NULL, NULL);
|
2011-12-19 05:27:41 -06:00
|
|
|
gnc_lot_commit_edit (lot);
|
2003-01-01 22:07:58 -06:00
|
|
|
}
|
|
|
|
|
2016-11-11 07:03:13 -06:00
|
|
|
void
|
2003-01-01 22:07:58 -06:00
|
|
|
gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
|
2002-06-24 17:30:36 -05:00
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
GncGUID *guid;
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !lot)
|
|
|
|
return;
|
2002-06-24 17:30:36 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (invoice->posted_lot) return; /* Cannot reset invoice's lot */
|
2014-05-07 08:37:14 -05:00
|
|
|
guid = (GncGUID*)qof_instance_get_guid (QOF_INSTANCE (invoice));
|
2011-12-18 18:47:20 -06:00
|
|
|
gnc_lot_begin_edit (lot);
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_set (QOF_INSTANCE (lot), "invoice", guid, NULL);
|
2011-12-19 05:27:41 -06:00
|
|
|
gnc_lot_commit_edit (lot);
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceSetPostedLot (invoice, lot);
|
2002-06-24 17:30:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
|
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
GncGUID *guid = NULL;
|
2010-03-02 15:41:05 -06:00
|
|
|
QofBook *book;
|
2002-06-24 17:30:36 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!lot) return NULL;
|
2002-06-24 17:30:36 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
book = gnc_lot_get_book (lot);
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_get (QOF_INSTANCE (lot), "invoice", &guid, NULL);
|
2010-03-02 15:41:05 -06:00
|
|
|
return gncInvoiceLookup(book, guid);
|
2002-06-24 17:30:36 -05:00
|
|
|
}
|
|
|
|
|
2016-11-11 07:03:13 -06:00
|
|
|
void
|
2003-01-01 22:07:58 -06:00
|
|
|
gncInvoiceAttachToTxn (GncInvoice *invoice, Transaction *txn)
|
2001-11-23 23:35:08 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !txn)
|
|
|
|
return;
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (invoice->posted_txn) return; /* Cannot reset invoice's txn */
|
|
|
|
|
|
|
|
xaccTransBeginEdit (txn);
|
2015-01-02 15:12:08 -06:00
|
|
|
qof_instance_set (QOF_INSTANCE (txn), "invoice", //Prop INVOICE
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_get_guid (QOF_INSTANCE (invoice)), NULL);
|
2010-03-02 15:41:05 -06:00
|
|
|
xaccTransSetTxnType (txn, TXN_TYPE_INVOICE);
|
|
|
|
xaccTransCommitEdit (txn);
|
|
|
|
gncInvoiceSetPostedTxn (invoice, txn);
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
GncInvoice *
|
2008-08-01 11:02:07 -05:00
|
|
|
gncInvoiceGetInvoiceFromTxn (const Transaction *txn)
|
2002-06-24 17:30:36 -05:00
|
|
|
{
|
2014-05-07 08:37:14 -05:00
|
|
|
GncGUID *guid = NULL;
|
2010-03-02 15:41:05 -06:00
|
|
|
QofBook *book;
|
2002-06-24 17:30:36 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!txn) return NULL;
|
2002-06-24 17:30:36 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
book = xaccTransGetBook (txn);
|
2014-05-07 08:37:14 -05:00
|
|
|
qof_instance_get (QOF_INSTANCE (txn), "invoice", &guid, NULL);
|
2010-03-02 15:41:05 -06:00
|
|
|
return gncInvoiceLookup(book, guid);
|
2002-06-24 17:30:36 -05:00
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
gboolean gncInvoiceAmountPositive (const GncInvoice *invoice)
|
2011-10-09 16:06:31 -05:00
|
|
|
{
|
|
|
|
switch (gncInvoiceGetType (invoice))
|
|
|
|
{
|
2011-10-17 14:07:41 -05:00
|
|
|
case GNC_INVOICE_CUST_INVOICE:
|
|
|
|
case GNC_INVOICE_VEND_CREDIT_NOTE:
|
|
|
|
case GNC_INVOICE_EMPL_CREDIT_NOTE:
|
|
|
|
return TRUE;
|
|
|
|
case GNC_INVOICE_CUST_CREDIT_NOTE:
|
|
|
|
case GNC_INVOICE_VEND_INVOICE:
|
|
|
|
case GNC_INVOICE_EMPL_INVOICE:
|
|
|
|
return FALSE;
|
|
|
|
case GNC_INVOICE_UNDEFINED:
|
|
|
|
default:
|
|
|
|
/* Should never be reached.
|
|
|
|
* If it is, perhaps a new value is added to GncInvoiceType ? */
|
|
|
|
g_assert_not_reached();
|
|
|
|
return FALSE;
|
2011-10-09 16:06:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-04 10:56:55 -06:00
|
|
|
GHashTable *gncInvoiceGetForeignCurrencies (const GncInvoice *invoice)
|
|
|
|
{
|
|
|
|
EntryList *entries_iter;
|
|
|
|
gboolean is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
|
|
|
|
gboolean is_cn = gncInvoiceGetIsCreditNote (invoice);
|
|
|
|
GHashTable *amt_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
NULL, g_free);
|
|
|
|
|
|
|
|
for (entries_iter = invoice->entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
|
|
|
|
{
|
|
|
|
GncEntry *entry = (GncEntry*)entries_iter->data;
|
|
|
|
Account *this_acc;
|
|
|
|
gnc_commodity *account_currency;
|
|
|
|
AccountValueList *tt_amts = NULL, *tt_iter;
|
|
|
|
|
|
|
|
/* Check entry's account currency */
|
|
|
|
this_acc = (is_cust_doc ? gncEntryGetInvAccount (entry) :
|
|
|
|
gncEntryGetBillAccount (entry));
|
|
|
|
account_currency = xaccAccountGetCommodity (this_acc);
|
|
|
|
|
|
|
|
if (this_acc &&
|
|
|
|
!gnc_commodity_equal (gncInvoiceGetCurrency (invoice), account_currency))
|
|
|
|
{
|
|
|
|
gnc_numeric *curr_amt = (gnc_numeric*) g_hash_table_lookup (amt_hash, account_currency);
|
|
|
|
gnc_numeric *entry_amt = (gnc_numeric*) g_new0 (gnc_numeric, 1);
|
|
|
|
*entry_amt = gncEntryGetDocValue (entry, FALSE, is_cust_doc, is_cn);
|
|
|
|
if (curr_amt)
|
|
|
|
*entry_amt = gnc_numeric_add (*entry_amt, *curr_amt, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
|
|
|
|
g_hash_table_insert (amt_hash, account_currency, entry_amt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check currencies of each account in the tax table linked
|
|
|
|
* to the current entry */
|
|
|
|
tt_amts = gncEntryGetDocTaxValues (entry, is_cust_doc, is_cn);
|
|
|
|
|
|
|
|
if (!tt_amts)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (tt_iter = tt_amts; tt_iter != NULL; tt_iter = g_list_next(tt_iter))
|
|
|
|
{
|
|
|
|
GncAccountValue *tt_amt_val = (GncAccountValue*)tt_iter->data;
|
|
|
|
Account *tt_acc = tt_amt_val->account;
|
|
|
|
gnc_commodity *tt_acc_currency = xaccAccountGetCommodity (tt_acc);
|
|
|
|
|
|
|
|
if (tt_acc &&
|
|
|
|
!gnc_commodity_equal (gncInvoiceGetCurrency (invoice), tt_acc_currency))
|
|
|
|
{
|
|
|
|
gnc_numeric *curr_amt = (gnc_numeric*) g_hash_table_lookup (amt_hash, tt_acc_currency);
|
|
|
|
gnc_numeric *tt_acc_amt = (gnc_numeric*) g_new0 (gnc_numeric, 1);
|
|
|
|
*tt_acc_amt = tt_amt_val->value;
|
|
|
|
if (curr_amt)
|
|
|
|
*tt_acc_amt = gnc_numeric_add (*tt_acc_amt, *curr_amt, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
|
|
|
|
g_hash_table_insert (amt_hash, tt_acc_currency, tt_acc_amt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gncAccountValueDestroy (tt_amts);
|
|
|
|
}
|
|
|
|
return amt_hash;
|
|
|
|
}
|
|
|
|
|
2012-02-10 09:34:02 -06:00
|
|
|
static gboolean gncInvoicePostAddSplit (QofBook *book,
|
2012-03-16 15:27:09 -05:00
|
|
|
Account *acc,
|
|
|
|
Transaction *txn,
|
|
|
|
gnc_numeric value,
|
|
|
|
const gchar *memo,
|
|
|
|
const gchar *type,
|
|
|
|
GncInvoice *invoice)
|
2012-02-10 09:34:02 -06:00
|
|
|
{
|
|
|
|
Split *split;
|
|
|
|
|
|
|
|
split = xaccMallocSplit (book);
|
|
|
|
/* set action and memo? */
|
|
|
|
|
|
|
|
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, gncInvoiceGetID(invoice), type);
|
2012-02-10 09:34:02 -06:00
|
|
|
|
|
|
|
/* Need to insert this split into the account AND txn before
|
|
|
|
* we set the Base Value. Otherwise SetBaseValue complains
|
|
|
|
* that we don't have an account and fails to set the value.
|
|
|
|
*/
|
|
|
|
xaccAccountBeginEdit (acc);
|
|
|
|
xaccAccountInsertSplit (acc, split);
|
|
|
|
xaccAccountCommitEdit (acc);
|
|
|
|
xaccTransAppendSplit (txn, split);
|
|
|
|
|
|
|
|
/* General note on the split creations below:
|
|
|
|
* Invoice and bill amounts are always stored as positive values in entries
|
|
|
|
* So to convert them to proper splits, the amounts may have to be reverted
|
|
|
|
* to have the proper effect on the account balance.
|
|
|
|
* Credit notes have the opposite effect of invoices/bills, but their amounts
|
|
|
|
* are stored as negative values as well. So to convert them into splits
|
|
|
|
* they can be treated exactly the same as their invoice/bill counter parts.
|
|
|
|
* The net effect is that the owner type is sufficient to determine whether a
|
|
|
|
* value has to be reverted when converting an invoice/bill/cn amount to a split.
|
|
|
|
*/
|
|
|
|
if (gnc_commodity_equal(xaccAccountGetCommodity(acc), invoice->currency))
|
|
|
|
{
|
|
|
|
xaccSplitSetBaseValue (split, value,
|
|
|
|
invoice->currency);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*need to do conversion */
|
|
|
|
GNCPrice *price = gncInvoiceGetPrice(invoice, xaccAccountGetCommodity(acc));
|
|
|
|
|
|
|
|
if (price == NULL)
|
|
|
|
{
|
|
|
|
/*This is an error, which shouldn't even be able to happen.
|
|
|
|
We can't really do anything sensible about it, and this is
|
|
|
|
a user-interface free zone so we can't try asking the user
|
|
|
|
again either, have to return NULL*/
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gnc_numeric converted_amount;
|
|
|
|
xaccSplitSetValue(split, value);
|
|
|
|
converted_amount = gnc_numeric_div(value, gnc_price_get_value(price), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
|
|
|
|
DEBUG("converting from %f to %f\n", gnc_numeric_to_double(value), gnc_numeric_to_double(converted_amount));
|
|
|
|
xaccSplitSetAmount(split, converted_amount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-11-23 23:35:08 -06:00
|
|
|
Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
|
2017-12-29 15:07:08 -06:00
|
|
|
time64 post_date, time64 due_date,
|
2013-10-31 17:24:05 -05:00
|
|
|
const char * memo, gboolean accumulatesplits,
|
|
|
|
gboolean autopay)
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
Transaction *txn;
|
|
|
|
QofBook *book;
|
|
|
|
GNCLot *lot = NULL;
|
|
|
|
GList *iter;
|
|
|
|
GList *splitinfo = NULL;
|
|
|
|
gnc_numeric total;
|
2011-10-09 16:06:31 -05:00
|
|
|
gboolean is_cust_doc;
|
2012-02-10 09:33:53 -06:00
|
|
|
gboolean is_cn;
|
2010-03-02 15:41:05 -06:00
|
|
|
const char *name, *type;
|
|
|
|
char *lot_title;
|
|
|
|
Account *ccard_acct = NULL;
|
2011-10-10 07:34:58 -05:00
|
|
|
const GncOwner *owner;
|
2018-05-24 11:53:15 -05:00
|
|
|
int denom = xaccAccountGetCommoditySCU(acc);
|
|
|
|
AccountValueList *taxes;
|
2003-03-10 23:59:51 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice || !acc) return NULL;
|
2016-03-16 07:18:26 -05:00
|
|
|
if (gncInvoiceIsPosted (invoice)) return NULL;
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceBeginEdit (invoice);
|
|
|
|
book = qof_instance_get_book(invoice);
|
2002-06-16 00:11:33 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Stabilize the Billing Terms of this invoice */
|
|
|
|
if (invoice->terms)
|
|
|
|
gncInvoiceSetTerms (invoice,
|
|
|
|
gncBillTermReturnChild (invoice->terms, TRUE));
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2011-10-09 16:06:31 -05:00
|
|
|
/* GncEntry functions need to know if the invoice/credit note is for a customer or a vendor/employee. */
|
|
|
|
is_cust_doc = (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_CUSTOMER);
|
2012-02-10 09:33:53 -06:00
|
|
|
is_cn = gncInvoiceGetIsCreditNote (invoice);
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Figure out if we need to separate out "credit-card" items */
|
|
|
|
owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
|
|
|
|
if (gncInvoiceGetOwnerType (invoice) == GNC_OWNER_EMPLOYEE)
|
|
|
|
ccard_acct = gncEmployeeGetCCard (gncOwnerGetEmployee (owner));
|
2001-11-23 23:35:08 -06:00
|
|
|
|
2012-02-10 09:34:18 -06:00
|
|
|
/* Create a new lot for this invoice */
|
|
|
|
lot = gnc_lot_new (book);
|
2010-03-02 15:41:05 -06:00
|
|
|
gnc_lot_begin_edit (lot);
|
|
|
|
|
2011-10-08 11:59:01 -05:00
|
|
|
type = gncInvoiceGetTypeString (invoice);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
|
|
|
/* Set the lot title */
|
|
|
|
lot_title = g_strdup_printf ("%s %s", type, gncInvoiceGetID (invoice));
|
|
|
|
gnc_lot_set_title (lot, lot_title);
|
|
|
|
g_free (lot_title);
|
|
|
|
|
|
|
|
/* Create a new transaction */
|
|
|
|
txn = xaccMallocTransaction (book);
|
|
|
|
xaccTransBeginEdit (txn);
|
|
|
|
|
|
|
|
name = gncOwnerGetName (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)));
|
|
|
|
|
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 Transaction Description (Owner Name) , Num (invoice ID or type, based
|
|
|
|
* on book option), Currency */
|
2010-03-02 15:41:05 -06:00
|
|
|
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
|
|
|
gnc_set_num_action (txn, NULL, gncInvoiceGetID (invoice), type);
|
2010-03-02 15:41:05 -06:00
|
|
|
xaccTransSetCurrency (txn, invoice->currency);
|
|
|
|
|
|
|
|
/* Entered and Posted at date */
|
2012-12-01 16:44:53 -06:00
|
|
|
xaccTransSetDateEnteredSecs (txn, gnc_time (NULL));
|
2017-12-29 15:07:08 -06:00
|
|
|
xaccTransSetDatePostedSecs (txn, post_date);
|
|
|
|
gncInvoiceSetDatePosted (invoice, post_date);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2017-12-29 15:07:08 -06:00
|
|
|
xaccTransSetDateDue (txn, due_date);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
/* Get invoice total and taxes. */
|
|
|
|
total = gncInvoiceGetTotal (invoice);
|
|
|
|
taxes = gncInvoiceGetTotalTaxList (invoice);
|
|
|
|
/* The two functions above return signs relative to the document
|
2018-08-06 06:29:12 -05:00
|
|
|
* We need to convert them to balance values before we can use them here
|
|
|
|
* Note the odd construct comparing two booleans is to xor them
|
|
|
|
* that is, only evaluate true if both are different.
|
|
|
|
*/
|
|
|
|
if (is_cust_doc != is_cn)
|
2018-05-24 11:53:15 -05:00
|
|
|
{
|
|
|
|
GList *node;
|
|
|
|
total = gnc_numeric_neg (total);
|
|
|
|
for (node = taxes; node; node = node->next)
|
|
|
|
{
|
|
|
|
GncAccountValue *acc_val = node->data;
|
|
|
|
acc_val->value = gnc_numeric_neg (acc_val->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Iterate through the entries; sum up everything for each account.
|
|
|
|
* then create the appropriate splits in this txn.
|
|
|
|
*/
|
2018-05-24 11:53:15 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
for (iter = gncInvoiceGetEntries(invoice); iter; iter = iter->next)
|
2008-11-26 07:06:44 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
gnc_numeric value, tax;
|
|
|
|
GncEntry * entry = iter->data;
|
|
|
|
Account *this_acc;
|
|
|
|
|
|
|
|
/* Stabilize the TaxTable in this entry */
|
|
|
|
gncEntryBeginEdit (entry);
|
2011-10-09 16:06:31 -05:00
|
|
|
if (is_cust_doc)
|
2010-03-02 15:41:05 -06:00
|
|
|
gncEntrySetInvTaxTable
|
|
|
|
(entry, gncTaxTableReturnChild (gncEntryGetInvTaxTable (entry), TRUE));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gncEntrySetBillTaxTable
|
|
|
|
(entry, gncTaxTableReturnChild (gncEntryGetBillTaxTable (entry), TRUE));
|
|
|
|
|
2012-02-10 09:34:02 -06:00
|
|
|
/* If this is a bill, and the entry came from an invoice originally, copy the price */
|
2010-03-02 15:41:05 -06:00
|
|
|
if (gncEntryGetBillable (entry))
|
2017-03-09 08:01:11 -06:00
|
|
|
{
|
|
|
|
/* We need to set the net price since it may be another tax rate for invoices than bills */
|
|
|
|
gncEntrySetInvPrice (entry, gncEntryGetPrice (entry, FALSE, TRUE));
|
|
|
|
gncEntrySetInvTaxIncluded (entry, FALSE);
|
|
|
|
}
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
|
|
|
gncEntryCommitEdit (entry);
|
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
/* Obtain the Entry's Value and TaxValues
|
|
|
|
Note we use rounded values here and below to prevent creating an imbalanced transaction */
|
|
|
|
value = gncEntryGetBalValue (entry, TRUE, is_cust_doc);
|
|
|
|
tax = gncEntryGetBalTaxValue (entry, TRUE, is_cust_doc);
|
2008-11-26 07:06:44 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* add the value for the account split */
|
2011-10-09 16:06:31 -05:00
|
|
|
this_acc = (is_cust_doc ? gncEntryGetInvAccount (entry) :
|
2010-03-02 15:41:05 -06:00
|
|
|
gncEntryGetBillAccount (entry));
|
|
|
|
if (this_acc)
|
2008-11-26 07:06:44 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (gnc_numeric_check (value) == GNC_ERROR_OK)
|
|
|
|
{
|
|
|
|
if (accumulatesplits)
|
|
|
|
splitinfo = gncAccountValueAdd (splitinfo, this_acc, value);
|
2018-05-24 11:53:15 -05:00
|
|
|
/* Adding to total in case of accumulatesplits will be deferred to later when each split is effectively added */
|
2012-02-10 09:34:02 -06:00
|
|
|
else if (!gncInvoicePostAddSplit (book, this_acc, txn, value,
|
2012-03-16 15:27:09 -05:00
|
|
|
gncEntryGetDescription (entry),
|
|
|
|
type, invoice))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
2012-02-10 09:34:02 -06:00
|
|
|
/*This is an error, which shouldn't even be able to happen.
|
|
|
|
We can't really do anything sensible about it, and this is
|
|
|
|
a user-interface free zone so we can't try asking the user
|
|
|
|
again either, have to return NULL*/
|
|
|
|
return NULL;
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If there is a credit-card account, and this is a CCard
|
2018-05-24 11:53:15 -05:00
|
|
|
* payment type, subtract it from the total, and instead
|
2010-03-02 15:41:05 -06:00
|
|
|
* create a split to the CC Acct with a memo of the entry
|
|
|
|
* description instead of the provided memo. Note that the
|
|
|
|
* value reversal is the same as the post account.
|
|
|
|
*
|
|
|
|
* Note: we don't have to worry about the tax values --
|
|
|
|
* expense vouchers don't have them.
|
|
|
|
*/
|
|
|
|
if (ccard_acct && gncEntryGetBillPayment (entry) == GNC_PAYMENT_CARD)
|
|
|
|
{
|
|
|
|
Split *split;
|
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
total = gnc_numeric_sub (total, value, denom,
|
|
|
|
GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
split = xaccMallocSplit (book);
|
|
|
|
xaccSplitSetMemo (split, gncEntryGetDescription (entry));
|
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 action based on book option */
|
|
|
|
gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
|
2010-03-02 15:41:05 -06:00
|
|
|
xaccAccountBeginEdit (ccard_acct);
|
|
|
|
xaccAccountInsertSplit (ccard_acct, split);
|
|
|
|
xaccAccountCommitEdit (ccard_acct);
|
|
|
|
xaccTransAppendSplit (txn, split);
|
2012-02-10 09:32:56 -06:00
|
|
|
xaccSplitSetBaseValue (split, gnc_numeric_neg (value),
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->currency);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("bad value in our entry");
|
2008-11-26 07:06:44 -06:00
|
|
|
}
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
/* check the taxes */
|
|
|
|
if (gnc_numeric_check (tax) != GNC_ERROR_OK)
|
2010-03-02 15:41:05 -06:00
|
|
|
g_warning ("bad tax in our entry");
|
|
|
|
|
|
|
|
} /* for */
|
2008-11-26 07:06:44 -06:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
|
|
|
|
/* now merge in the TaxValues */
|
|
|
|
splitinfo = gncAccountValueAddList (splitinfo, taxes);
|
|
|
|
gncAccountValueDestroy (taxes);
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Iterate through the splitinfo list and generate the splits */
|
|
|
|
for (iter = splitinfo; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
GncAccountValue *acc_val = iter->data;
|
2018-05-24 11:53:15 -05:00
|
|
|
|
|
|
|
//gnc_numeric amt_rounded = gnc_numeric_convert(acc_val->value,
|
|
|
|
// denom, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
|
2012-02-10 09:34:02 -06:00
|
|
|
if (!gncInvoicePostAddSplit (book, acc_val->account, txn, acc_val->value,
|
|
|
|
memo, type, invoice))
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
2012-02-10 09:34:02 -06:00
|
|
|
/*This is an error, which shouldn't even be able to happen.
|
|
|
|
We can't really do anything sensible about it, and this is
|
|
|
|
a user-interface free zone so we can't try asking the user
|
|
|
|
again either, have to return NULL*/
|
|
|
|
return NULL;
|
2008-11-26 07:06:44 -06:00
|
|
|
}
|
|
|
|
}
|
2003-04-01 15:15:22 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* If there is a ccard account, we may have an additional "to_card" payment.
|
2012-02-10 09:32:56 -06:00
|
|
|
* we should make that now.
|
2010-03-02 15:41:05 -06:00
|
|
|
*/
|
|
|
|
if (ccard_acct && !gnc_numeric_zero_p (invoice->to_charge_amount))
|
|
|
|
{
|
|
|
|
Split *split = xaccMallocSplit (book);
|
|
|
|
|
2012-02-10 09:33:53 -06:00
|
|
|
/* To charge amount is stored in document value. We need balance value here
|
|
|
|
* so convert if necessary. */
|
|
|
|
gnc_numeric to_charge_bal_amount = (is_cn ? gnc_numeric_neg (invoice->to_charge_amount)
|
2012-03-16 15:27:09 -05:00
|
|
|
: invoice->to_charge_amount);
|
2012-02-10 09:33:53 -06:00
|
|
|
|
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
|
|
|
/* Set memo. */
|
2010-03-02 15:41:05 -06:00
|
|
|
xaccSplitSetMemo (split, _("Extra to Charge Card"));
|
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 action based on book option */
|
|
|
|
gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
|
|
|
xaccAccountBeginEdit (ccard_acct);
|
|
|
|
xaccAccountInsertSplit (ccard_acct, split);
|
|
|
|
xaccAccountCommitEdit (ccard_acct);
|
|
|
|
xaccTransAppendSplit (txn, split);
|
2012-02-10 09:33:53 -06:00
|
|
|
xaccSplitSetBaseValue (split, gnc_numeric_neg (to_charge_bal_amount),
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->currency);
|
2003-04-01 15:15:22 -06:00
|
|
|
|
2018-05-24 11:53:15 -05:00
|
|
|
total = gnc_numeric_sub (total, to_charge_bal_amount, denom,
|
|
|
|
GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
|
2010-03-02 15:41:05 -06:00
|
|
|
}
|
2002-05-10 19:35:43 -05:00
|
|
|
|
2011-10-09 16:06:31 -05:00
|
|
|
/* Now create the Posted split (which is the opposite sign of the above splits) */
|
2010-03-02 15:41:05 -06:00
|
|
|
{
|
|
|
|
Split *split = xaccMallocSplit (book);
|
2002-06-25 10:08:50 -05:00
|
|
|
|
Implement a Book Option to give users the choice to use the transaction number field (default and current behaviour) or, alternatively, the split action field of the anchor split for 'Num' column on registers, reports, import and export, where applicable. The difference between the two is that with the default, the same 'Num' is displayed for a given transaction regardless of what register it is viewed in and with the new option, a different 'Num' can be entered/displayed for a given transaction in each register it is viewed in. In both cases, the 'next number logic' of the 'Num' cell is based on the account of the register the transaction is entered/viewed from but in one case it fills the transaction number, in the other, it fills the split action field of the anchor split (with the transaction number field displayed in the register cell labeled 'T-Num'). In both cases, both fields are visible and can be used as free-form text in double-line mode for any value the user wants. If the new option is not selected, there should be no change in Gnucash's behaviour with the exception of displaying the book options dialog in 'new book' situations.
The changes made are:
1. Implement the new book option to select source for 'num' cell:
libqof/qof/qofbookslots.h - define num source option
engine/engine.i - define 'NUM-FIELD-SOURCE' as an option name and
'SPLIT-ACTION' as a term for sorting queries
app-utils/business-prefs.scm - define book option for num-field-source
app-utils/app-utils.scm - define and export book option for num-field-source
2. Implement functions to get book option setting and to test:
libqof/qof/qofbook.c & .h - define function to get number source book option
libqof/qof/test/test-qofbook.c - test function to get number source book option
3. Implement a notification mechanism for book option changes:
engine/engine-helpers.c & .h - define functions to register callbacks,
define function to remove callbacks and
define function to initiate callbacks on book num-source option changes
core-utils/gnc-features.c & .h - define feature for num-source
app-utils/gnc-ui-util.c & .h - define gnc_book_option_num_field_source_change_cb;
include setting of feature flag on initial use
gnome-utils/gnc-main-window.c - change name of gnc_options_dialog_apply_cb
function to gnc_book_options_dialog_apply_cb and adjust function to
call function gnc_book_option_num_field_source_change_cb when book
option for num-field-source changes; change name of
gnc_options_dialog_close_cb to gnc_book_options_dialog_close_cb
4. Implement 'help' button response on Book Option Dialog:
gnome-utils/gnc-ui.h - define "book-options" section of help manual
gnome-utils/gnc-gnome-utils.c & .h - implement Book Options help callback
gnome-utils/gnc-main-window.c - use gnc_options_dialog_set_book_options_help_cb
to make help button active
5. Implement utility functions to get/set number/action based on book option:
engine/engine-helpers.c & .h - define 'gnc_get_num_action' function
define 'gnc_get_action_num' function
define 'gnc_set_num_action' function
engine/engine.i - make get/set num/action functions available to guile &
allow #f to be used in place of NULL from guile
engine/Transaction.h - add reference to utility functions in comments to
xaccTransSetNum and xaccTransGetNum functions
engine/Split.h - add reference to utility functions in comments to
xaccSplitSetAction and xaccSplitGetAction functions
6. Implement register use of num source book option; for General, Income and Search
Ledgers, since there is no anchor split, always show tran-num in transaction
cursor, but vary label to correspond to book option:
register/ledger-core/split-register.h - define TNUM_CELL
define CURSOR_DOUBLE_LEDGER_NUM_ACTN cursor name to use TNUM_CELL
define CURSOR_DOUBLE_JOURNAL_NUM_ACTN cursor name to use TNUM_CELL
add boolean to split_reg structure to hold num source book option
register/ledger-core/split-register-layout.c -
add logic to define and set up new ledger/journal cursors with TNUM_CELLs
add logic to add the new cursors to a layout
add logic to add TNUM_CELL to a layout
register/ledger-core/split-register-model.c -
define function to get TNUM_CELL label
add logic to recognize ledger/journal cursors with TNUM_CELL
modify function to get NUM_CELL value based on book option and register
type
define function to get TNUM_CELL value
adjust num help text to reflect book option choice
define function to get TNUM_CELL help
modify function to get action help to reflect book option choice
set up handlers for TNUM_CELL
register/ledger-core/split-register-model-save.c -
use 'gnc_set_num_action' function to set num/action for NUM_CELL based
on book option
define function to save TNUM_CELL using 'gnc_set_num_action' function
set save handler for TNUM_CELL
register/ledger-core/split-register-util.c -
modify logic to recognize ledger/journal cursors with tnum_cell
register/ledger-core/split-register.c -
define split_register_book_option_changed function
register split_register_book_option_changed function in register init
initialize register structure setting to book option
remove split_register_book_option_changed function in register destroy
modify gnc_split_register_save_to_scm to handle TNUM_CELL
7. Enhance transaction copy/duplicate logic to accommodate new book option:
gnome/gtkbuilder/gnc-plugin-page-register.glade -
add widgets to handle trans number and/or split action based on book option
gnome-utils/dialog-dup-trans.c & .h -
add capability to display and handle 'Num' field according to book option
gnome/gnc-plugin-page-register.c - define gnc_find_register_by_account
register/ledger-core/split-register.c -
modify gnc_split_register_duplicate_current to accomodate book option
setting
register/ledger-core/Makefile.am - add GNOME_CFLAGS
register/ledger-core/test/Makefile.am - add libgnc-gnome.la
8. Adjust register sort and sort labels related to Num/Action radio buttons to
correspond to book option for clarity:
gnome/gnc-plugin-page-register.c -
define gnc_plugin_page_register_sort_book_option_changed to adjust labels
register function in gnc_plugin_page_register_cmd_view_sort_by
and save num and action radio widgets
initialize radio widget labels to correspond to book option
remove function in gnc_plugin_page_register_sort_response_cb
and clear num and action radio widgets
gnome/gnc-split-reg.c & h. -
create versions of gnc_split_reg_sort and gnc_split_reg_set_sort to force
a re-sort to be used when num-source book option changes
engine/Transaction.c & .h -
modify default sort to use split action in place of tran num per book
option if called from xaccSplitOrder
engine/Split.c -
modify xaccSplitOrder to call xaccTransOrder_num_action to switch use of
split action and tran num per book option
engine/test/utest-Split.c -
modify test_xaccSplitOrder to call xaccTransOrder_num_action based on
book option
9. Adjust transaction find labels related to Num/Action to correspond to book option
for clarity:
gnome/dialog-find-transactions.c - adjust labels in search criteria based
on book option
gnome-search/dialog-search.c -
define gnc_search_dialog_book_option_changed to adjust labels
register function in gnc_search_dialog_init_widgets when searching
for splits
remove function in gnc_search_dialog_close_cb if registered
10. Modify new file process to allow setting of num-source (actually, all) book
option(s) during New Account Hierarchy Setup:
gnome-utils/gtkbuilder/dialog-preferences.glade - add a user preference for
the default setting for 'num-source' for new books
core-utils/gnc-gconf-utils.h - define KEY_NUM_SOURCE
gnome-utils/gnc-gnome-utils.c & h. -
define gnc_options_dialog_set_new_book_option_values to retrieve
preference values
gnome-utils/dialog-options.c & .h - define gnc_options_dialog_new_modal to
surpress apply button
gnome-utils/gnc-main-window.c - define function gnc_book_options_dialog_cb
with arguments so that the window can be called in modal mode and the
title changed and return dialog widget; call gnc_options_dialog_new_modal
instead of gnc_options_dialog_new; call this function from
gnc_main_window_cmd_file_properties with new arguments; for modal mode,
call gnc-options-dialog-set-new-book-option-values to initialize values
from preferences
app-utils/gnc-ui-util.c & h. - create function gnc_is_new_book for
determining when a new book is being created
gnome-utils/dialog-utils.c & h. - define gnc_new_book_option_display to
display book options dialog in modal mode
gnome/gtkbuilder/assistant-hierarchy.glade - add notification about book
options to currency page
gnome/assistant-hierarchy.c - add ability to set book option initialized
from preferences value for new books by using functions gnc_is_new_book
and gnc_new_book_option_display
11. Modify Import QIF process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/qif-import/assistant-qif-import.glade - add notification about
book options to currency page
import-export/qif-import/assistant-qif-import.c - using function
gnc_is_new_book to identify 'new book' situation and set flag; add
logic to handle 'new-book' situation by calling
gnc_new_book_option_display function
import-export/qif-import/qif-to-gnc.scm - use 'gnc_set_num_action' function
to import number to correct field based on book option
12. Modify Import OFX/QFX process to recognize a new-book situation and allow setting
of book options during first import into a new book; also follow book option
setting for num source in importing number whether new book or not:
import-export/ofx/gnc-ofx-import.c - use 'gnc_set_num_action' function to import
number based on book option; identify 'new book' situation using function
gnc_is_new_book and set flag; add logic to handle 'new-book' situation
by raising book options dialog by calling gnc_new_book_option_display
function
import-export/import-backend.c - use 'gnc_get_num_action' function to
retrieve number from transactions to be matched based on book option
13. Modify Import AqBanking process to recognize a new-book situation and allow
setting of book options during first import into a new book; also follow
book option setting for num source in importing number:
import-export/aqbanking/gnc-file-aqb-import.c - identify 'new book'
situation using function gnc_is_new_book and handle by raising book
options dialog by calling gnc_new_book_option_display function
import-export/aqbanking/gnc-ab-utils.c - use 'gnc_set_num_action' function
to set number based on book option
14. Modify Import Transactions from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book; also
follow book option setting for num source in importing number whether new
book or not:
import-export/csv-import/assistant-csv-trans-import.glade - modify
commments to alert user of raising book options dialog in cases of csv
import into a new book
import-export/csv-import/gnc-csv-model.c & h. - use 'gnc_set_num_action'
function to import number based on book option
import-export/csv-import/assistant-csv-trans-import.c - add logic to handle
'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
15. Modify Import Accounts from CSV process to recognize a new-book situation
and allow setting of book options during first import into a new book
import-export/csv-import/assistant-csv-account-import.c & .h - add logic to
handle 'new-book' situation by raising book options dialog by calling
gnc_new_book_option_display function; identify 'new book' situation
using function gnc_is_new_book and set flag
16. Modify Export Transactions to CSV process to follow book option setting
for num source in exporting transactions:
import-export/csv-export/csv-transactions-export.c - modify headings to
reflect num-source book option and use 'gnc_get_num_action' function
to retrieve number and action
17. Modify register reporting to reflect book option setting for num source:
gnome/gnc-plugin-page-register.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
gnome/gnc-plugin-page-register2.c - determine and pass along ledger-type?
argument to gnc:register-report-create function
report/standard-reports/standard-reports.scm - add ledger-type? argument
to gnc:register-report-create function; pass it along to
gnc:register-report-create-internal function
report/standard-reports/register.scm - add ledger-type? argument to
gnc:register-report-create-internal function; use 'gnc-get-num-action'
function in place of xaccTransGetNum and 'gnc-get-action-num' function
in place of xaccSplitGetAction and modify report headings and option
text accordingly
18. Modify all places that use xaccTransSetNum and/or xaccSplitSetAction to use
'gnc_set_num_action' function to set number based on book option except
engine/Transaction.c & .h, engine/test-core/test-engine-stuff.c,
engine/Split.c & .h, engine/test/utest-Split.c, engine/engine-helpers.c & .h,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/io-gncxml-v1.c, import-export/log-replay/gnc-log-replay.c:
engine/gncOwner.c - use 'gnc_set_num_action' function to set number based
on book option
engine/gncInvoice.c - use 'gnc_set_num_action' function to set number based
on book option
engine/SchedXaction.c - use 'gnc_set_num_action' function to set number and
action
engine/cap-gains.c - use 'gnc_set_num_action' function to set split-action
gnome-utils/dialog-transfer.c - use 'gnc_set_num_action' function to set
number based on book option
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_set_num_action' function
to set number/action based on book option
gnome/assistant-stock-split.c - use 'gnc_set_num_action' function to set
split-action
19. Modify all places that use xaccTransGetNum and/or xaccSplitGetAction to use
'gnc_get_num_action' or 'gnc_get_action_num' functions to get number based
on book option except engine/Transaction.c & .h,
engine/test-core/test-engine-stuff.c, engine/Split.c & h.,
engine/test/utest-Split.c, engine/engine-helpers.c,
engine/engine-interface.scm, backend/xml/gnc-transaction-xml-v2.c,
backend/xml/test/test-xml-transaction.c:
gnome/dialog-lot-viewer.c - use 'gnc_get_num_action' function to retrieve
number based on book option
gnome/dialog-sx-from-trans.c - use 'gnc_get_num_action' function to
retrieve number and action
gnome/dialog-print-check.c - use 'gnc_get_num_action' function to
retrieve number and 'gnc_get_action_num' function to retrieve action
register/ledger-core/split-register-model.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-load.c - use 'gnc_get_num_action'
function to retrieve number based on book option
register/ledger-core/split-register-control.c - use 'gnc_get_num_action'
function to retrieve action
register/ledger-core/split-register.c - use 'gnc_get_num_action'
function to retrieve transaction-num
engine/cap-gains.c - use 'gnc_get_num_action' function to get split-action
gnome-utils/gnc-tree-view-split-reg.c - use 'gnc_get_num_action' function
to retrieve number and 'gnc_get_action_num' function to retrieve action
gnome-utils/gnc-tree-model-split-reg.c - use 'gnc_get_num_action' function
to retrieve transaction-number but may not be getting what is expected
if book option to use split-action for 'num' is set
report/locale-specific/us/taxtxf.scm - use 'gnc-get-num-action' function in
place of xaccTransGetNum and 'gnc-get-action-num' function in place of
xaccSplitGetAction and modify report headings and option text accordingly
report/standard-reports/transaction.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum, adjust sorting based on book option and
modify report headings and option text accordingly; add 'SPLIT-ACTION'
as a term for sorting queries
report/business-reports/customer-summary.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/owner-report.scm - use 'gnc-get-num-action'
function in place of xaccTransGetNum
report/business-reports/job-report.scm - use 'gnc-get-num-action' function
in place of xaccTransGetNum
business/business-gnome/dialog-payment.c - use 'gnc_get_num_action'
function to retrieve number based on book option
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22681 57a11ea4-9604-0410-9ed3-97b8803252fd
2012-12-22 00:00:54 -06:00
|
|
|
/* Set memo */
|
2010-03-02 15:41:05 -06:00
|
|
|
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 action based on book option */
|
|
|
|
gnc_set_num_action (NULL, split, gncInvoiceGetID (invoice), type);
|
2002-06-25 10:08:50 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
xaccAccountBeginEdit (acc);
|
|
|
|
xaccAccountInsertSplit (acc, split);
|
|
|
|
xaccAccountCommitEdit (acc);
|
|
|
|
xaccTransAppendSplit (txn, split);
|
2012-02-10 09:32:56 -06:00
|
|
|
xaccSplitSetBaseValue (split, gnc_numeric_neg (total),
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->currency);
|
|
|
|
|
|
|
|
/* add this split to the lot */
|
|
|
|
gnc_lot_add_split (lot, split);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now attach this invoice to the txn, lot, and account */
|
|
|
|
gncInvoiceAttachToLot (invoice, lot);
|
|
|
|
gncInvoiceAttachToTxn (invoice, txn);
|
|
|
|
gncInvoiceSetPostedAcc (invoice, acc);
|
|
|
|
|
2013-08-04 14:04:39 -05:00
|
|
|
xaccTransSetReadOnly (txn, _("Generated from an invoice. Try unposting the invoice."));
|
2010-03-02 15:41:05 -06:00
|
|
|
xaccTransCommitEdit (txn);
|
|
|
|
|
|
|
|
gncAccountValueDestroy (splitinfo);
|
2002-06-25 10:08:50 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
gnc_lot_commit_edit (lot);
|
2013-09-13 18:36:36 -05:00
|
|
|
/* Not strictly necessary, since it was done by the Set calls
|
|
|
|
* above, but good insurance. */
|
|
|
|
DEBUG("Committing Invoice %s", invoice->id);
|
|
|
|
mark_invoice (invoice);
|
2010-03-02 15:41:05 -06:00
|
|
|
gncInvoiceCommitEdit (invoice);
|
|
|
|
|
2012-02-10 09:34:18 -06:00
|
|
|
/* If requested, attempt to automatically apply open payments
|
|
|
|
* and reverse documents to this lot to close it (or at least
|
|
|
|
* reduce its balance) */
|
|
|
|
if (autopay)
|
|
|
|
gncInvoiceAutoApplyPayments (invoice);
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return txn;
|
2001-11-23 23:35:08 -06:00
|
|
|
}
|
|
|
|
|
2003-01-01 22:07:58 -06:00
|
|
|
gboolean
|
2003-05-28 22:02:11 -05:00
|
|
|
gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables)
|
2003-01-01 22:07:58 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
Transaction *txn;
|
|
|
|
GNCLot *lot;
|
2012-02-10 09:34:18 -06:00
|
|
|
GList *lot_split_list, *lot_split_iter;
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return FALSE;
|
|
|
|
if (!gncInvoiceIsPosted (invoice)) return FALSE;
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
txn = gncInvoiceGetPostedTxn (invoice);
|
|
|
|
g_return_val_if_fail (txn, FALSE);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
lot = gncInvoiceGetPostedLot (invoice);
|
|
|
|
g_return_val_if_fail (lot, FALSE);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Destroy the Posted Transaction */
|
|
|
|
xaccTransClearReadOnly (txn);
|
|
|
|
xaccTransBeginEdit (txn);
|
|
|
|
xaccTransDestroy (txn);
|
|
|
|
xaccTransCommitEdit (txn);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Disconnect the lot from the invoice; re-attach to the invoice owner */
|
|
|
|
gncInvoiceDetachFromLot (lot);
|
|
|
|
gncOwnerAttachToLot (&invoice->owner, lot);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2012-02-10 09:34:18 -06:00
|
|
|
/* Check if this invoice was linked to other lots (payments/inverse signed
|
|
|
|
* invoices).
|
|
|
|
* If this is the case, recreate the link transaction between all the remaining lots.
|
|
|
|
*
|
|
|
|
* Note that before GnuCash 2.6 payments were not stored in separate lots, but
|
|
|
|
* always ended up in invoice lots when matched to an invoice. Over-payments
|
|
|
|
* were copied to a new lot, to which later an invoice was added again and so on.
|
|
|
|
* These over-payments were handled with automatic payment forward transactions.
|
|
|
|
* You could consider these transactions to be links between lots as well, but
|
2012-03-13 16:22:58 -05:00
|
|
|
* to avoid some unexpected behavior, these will not be altered here.
|
2012-02-10 09:34:18 -06:00
|
|
|
*/
|
2012-03-20 05:08:37 -05:00
|
|
|
|
|
|
|
// Note: make a copy of the lot list here, when splits are deleted from the lot,
|
|
|
|
// the original list may be destroyed by the lot code.
|
|
|
|
lot_split_list = g_list_copy (gnc_lot_get_split_list (lot));
|
2012-02-10 09:34:18 -06:00
|
|
|
for (lot_split_iter = lot_split_list; lot_split_iter; lot_split_iter = lot_split_iter->next)
|
|
|
|
{
|
|
|
|
Split *split = lot_split_iter->data;
|
|
|
|
GList *other_split_list, *list_iter;
|
|
|
|
Transaction *other_txn = xaccSplitGetParent (split);
|
|
|
|
GList *lot_list = NULL;
|
|
|
|
|
|
|
|
/* Only work with transactions that link invoices and payments.
|
|
|
|
* Note: this check also catches the possible case of NULL splits. */
|
|
|
|
if (xaccTransGetTxnType (other_txn) != TXN_TYPE_LINK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Save a list of lots this linking transaction linked to */
|
|
|
|
other_split_list = xaccTransGetSplitList (other_txn);
|
|
|
|
for (list_iter = other_split_list; list_iter; list_iter = list_iter->next)
|
|
|
|
{
|
2012-03-13 16:22:58 -05:00
|
|
|
Split *other_split = list_iter->data;
|
2012-02-10 09:34:18 -06:00
|
|
|
GNCLot *other_lot = xaccSplitGetLot (other_split);
|
|
|
|
|
|
|
|
/* Omit the lot we are about to delete */
|
|
|
|
if (other_lot == lot)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
lot_list = g_list_prepend (lot_list, other_lot);
|
|
|
|
}
|
|
|
|
/* Maintain original split order */
|
|
|
|
lot_list = g_list_reverse (lot_list);
|
|
|
|
|
|
|
|
/* Now remove this link transaction. */
|
|
|
|
xaccTransClearReadOnly (other_txn);
|
|
|
|
xaccTransBeginEdit (other_txn);
|
|
|
|
xaccTransDestroy (other_txn);
|
|
|
|
xaccTransCommitEdit (other_txn);
|
|
|
|
|
|
|
|
/* Re-balance the saved lots as well as is possible */
|
|
|
|
gncOwnerAutoApplyPaymentsWithLots (&invoice->owner, lot_list);
|
|
|
|
|
|
|
|
/* If any of the saved lots has no more splits, then destroy it.
|
|
|
|
* Otherwise if any has an invoice associated with it,
|
|
|
|
* send it a modified event to reset its paid status */
|
|
|
|
for (list_iter = lot_list; list_iter; list_iter = list_iter->next)
|
|
|
|
{
|
|
|
|
GNCLot *other_lot = list_iter->data;
|
|
|
|
GncInvoice *other_invoice = gncInvoiceGetInvoiceFromLot (other_lot);
|
|
|
|
|
|
|
|
if (!gnc_lot_count_splits (other_lot))
|
|
|
|
gnc_lot_destroy (other_lot);
|
|
|
|
else if (other_invoice)
|
|
|
|
qof_event_gen (QOF_INSTANCE(other_invoice), QOF_EVENT_MODIFY, NULL);
|
|
|
|
}
|
|
|
|
}
|
2012-03-20 05:08:37 -05:00
|
|
|
g_list_free (lot_split_list);
|
2012-02-10 09:34:18 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* If the lot has no splits, then destroy it */
|
|
|
|
if (!gnc_lot_count_splits (lot))
|
|
|
|
gnc_lot_destroy (lot);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* Clear out the invoice posted information */
|
|
|
|
gncInvoiceBeginEdit (invoice);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->posted_acc = NULL;
|
|
|
|
invoice->posted_txn = NULL;
|
|
|
|
invoice->posted_lot = NULL;
|
2018-01-20 14:32:42 -06:00
|
|
|
invoice->date_posted = INT64_MAX;
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* if we've been asked to reset the tax tables, then do so */
|
|
|
|
if (reset_tax_tables)
|
|
|
|
{
|
2011-10-09 16:06:31 -05:00
|
|
|
gboolean is_cust_doc = (gncInvoiceGetOwnerType(invoice) == GNC_OWNER_CUSTOMER);
|
2010-03-02 15:41:05 -06:00
|
|
|
GList *iter;
|
2003-05-28 22:02:11 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
for (iter = gncInvoiceGetEntries(invoice); iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
GncEntry *entry = iter->data;
|
|
|
|
|
|
|
|
gncEntryBeginEdit(entry);
|
2011-10-09 16:06:31 -05:00
|
|
|
if (is_cust_doc)
|
2010-03-02 15:41:05 -06:00
|
|
|
gncEntrySetInvTaxTable(entry,
|
|
|
|
gncTaxTableGetParent(gncEntryGetInvTaxTable(entry)));
|
|
|
|
else
|
|
|
|
gncEntrySetBillTaxTable(entry,
|
|
|
|
gncTaxTableGetParent(gncEntryGetBillTaxTable(entry)));
|
|
|
|
gncEntryCommitEdit(entry);
|
|
|
|
}
|
2003-05-28 22:02:11 -05:00
|
|
|
}
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
mark_invoice (invoice);
|
|
|
|
gncInvoiceCommitEdit (invoice);
|
2003-01-01 22:07:58 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return TRUE;
|
2003-01-01 22:07:58 -06:00
|
|
|
}
|
|
|
|
|
2012-02-10 09:34:18 -06:00
|
|
|
struct lotmatch
|
|
|
|
{
|
|
|
|
const GncOwner *owner;
|
|
|
|
gboolean positive_balance;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gnc_lot_match_owner_balancing (GNCLot *lot, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct lotmatch *lm = user_data;
|
|
|
|
GncOwner owner_def;
|
|
|
|
const GncOwner *owner;
|
|
|
|
gnc_numeric balance = gnc_lot_get_balance (lot);
|
|
|
|
|
|
|
|
/* Could (part of) this lot serve to balance the lot
|
|
|
|
* for which this query was run ?*/
|
|
|
|
if (lm->positive_balance == gnc_numeric_positive_p (balance))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-02-10 09:34:36 -06:00
|
|
|
/* Is it ours? Either the lot owner or the lot invoice owner should match */
|
2012-02-10 09:34:18 -06:00
|
|
|
if (!gncOwnerGetOwnerFromLot (lot, &owner_def))
|
2012-02-10 09:34:36 -06:00
|
|
|
{
|
|
|
|
const GncInvoice *invoice = gncInvoiceGetInvoiceFromLot (lot);
|
|
|
|
if (!invoice)
|
|
|
|
return FALSE;
|
|
|
|
owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
owner = gncOwnerGetEndOwner (&owner_def);
|
2012-02-10 09:34:18 -06:00
|
|
|
|
|
|
|
return gncOwnerEqual (owner, lm->owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gncInvoiceAutoApplyPayments (GncInvoice *invoice)
|
|
|
|
{
|
|
|
|
GNCLot *inv_lot;
|
|
|
|
Account *acct;
|
|
|
|
const GncOwner *owner;
|
|
|
|
GList *lot_list;
|
|
|
|
struct lotmatch lm;
|
|
|
|
|
|
|
|
/* General note: "paying" in this context means balancing
|
|
|
|
* a lot, by linking opposite signed lots together. So below the term
|
|
|
|
* "payment" can both mean a true payment or it can mean a document of
|
|
|
|
* the opposite sign (invoice vs credit note). It just
|
|
|
|
* depends on what type of document was given as parameter
|
|
|
|
* to this function. */
|
|
|
|
|
|
|
|
/* Payments can only be applied to posted invoices */
|
|
|
|
g_return_if_fail (invoice);
|
|
|
|
g_return_if_fail (invoice->posted_lot);
|
|
|
|
|
|
|
|
inv_lot = invoice->posted_lot;
|
|
|
|
acct = invoice->posted_acc;
|
|
|
|
owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
|
|
|
|
|
|
|
|
/* Find all lots whose balance (or part of their balance) could be
|
|
|
|
* used to close this lot.
|
|
|
|
* To be eligible, the lots have to have an opposite signed balance
|
|
|
|
* and be for the same owner.
|
|
|
|
* For example, for an invoice lot, payment lots and credit note lots
|
|
|
|
* could be used. */
|
|
|
|
lm.positive_balance = gnc_numeric_positive_p (gnc_lot_get_balance (inv_lot));
|
|
|
|
lm.owner = owner;
|
|
|
|
lot_list = xaccAccountFindOpenLots (acct, gnc_lot_match_owner_balancing,
|
|
|
|
&lm, NULL);
|
|
|
|
|
|
|
|
lot_list = g_list_prepend (lot_list, inv_lot);
|
|
|
|
gncOwnerAutoApplyPaymentsWithLots (owner, lot_list);
|
|
|
|
g_list_free (lot_list);
|
|
|
|
}
|
|
|
|
|
2012-05-08 06:39:09 -05:00
|
|
|
/*
|
|
|
|
* Create a payment of "amount" for the invoice owner and attempt
|
|
|
|
* to balance it with the given invoice.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gncInvoiceApplyPayment (const GncInvoice *invoice, Transaction *txn,
|
|
|
|
Account *xfer_acc, gnc_numeric amount,
|
2017-12-29 15:07:08 -06:00
|
|
|
gnc_numeric exch, time64 date,
|
2012-05-08 06:39:09 -05:00
|
|
|
const char *memo, const char *num)
|
|
|
|
{
|
2012-05-26 18:47:34 -05:00
|
|
|
GNCLot *payment_lot;
|
2012-05-08 06:39:09 -05:00
|
|
|
GList *selected_lots = NULL;
|
|
|
|
const GncOwner *owner;
|
|
|
|
|
|
|
|
/* Verify our arguments */
|
|
|
|
if (!invoice || !gncInvoiceIsPosted (invoice) || !xfer_acc) return;
|
|
|
|
|
|
|
|
owner = gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice));
|
|
|
|
g_return_if_fail (owner->owner.undefined);
|
|
|
|
|
|
|
|
/* Create a lot for this payment */
|
2018-07-31 16:43:27 -05:00
|
|
|
payment_lot = gncOwnerCreatePaymentLot (owner, &txn, invoice->posted_acc,
|
|
|
|
xfer_acc, amount, exch,
|
|
|
|
date, memo, num);
|
2012-05-08 06:39:09 -05:00
|
|
|
|
|
|
|
/* Select the invoice as only payment candidate */
|
|
|
|
selected_lots = g_list_prepend (selected_lots, invoice->posted_lot);
|
|
|
|
|
|
|
|
/* And link the invoice lot and the payment lot together as well as possible. */
|
|
|
|
if (payment_lot)
|
|
|
|
selected_lots = g_list_prepend (selected_lots, payment_lot);
|
|
|
|
gncOwnerAutoApplyPaymentsWithLots (owner, selected_lots);
|
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gboolean gncInvoiceIsPosted (const GncInvoice *invoice)
|
2002-02-19 12:23:53 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return FALSE;
|
2018-04-14 11:46:26 -05:00
|
|
|
return GNC_IS_TRANSACTION(gncInvoiceGetPostedTxn(invoice));
|
2002-02-19 12:23:53 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
gboolean gncInvoiceIsPaid (const GncInvoice *invoice)
|
2003-05-12 21:07:15 -05:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!invoice) return FALSE;
|
|
|
|
if (!invoice->posted_lot) return FALSE;
|
|
|
|
return gnc_lot_is_closed(invoice->posted_lot);
|
2003-05-12 21:07:15 -05:00
|
|
|
}
|
|
|
|
|
2003-10-21 21:02:45 -05:00
|
|
|
/* ================================================================== */
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
void gncInvoiceBeginEdit (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
qof_begin_edit(&invoice->inst);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
2002-11-03 14:21:42 -06:00
|
|
|
|
2006-11-29 09:13:02 -06:00
|
|
|
static void gncInvoiceOnError (QofInstance *inst, QofBackendError errcode)
|
2002-11-03 14:21:42 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
PERR("Invoice QofBackend Failure: %d", errcode);
|
|
|
|
gnc_engine_signal_commit_error( errcode );
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2006-11-29 09:13:02 -06:00
|
|
|
static void gncInvoiceOnDone (QofInstance *invoice) { }
|
2003-10-14 16:20:55 -05:00
|
|
|
|
2006-11-29 09:13:02 -06:00
|
|
|
static void invoice_free (QofInstance *inst)
|
2003-10-14 16:20:55 -05:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncInvoice *invoice = (GncInvoice *) inst;
|
|
|
|
gncInvoiceFree (invoice);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
void gncInvoiceCommitEdit (GncInvoice *invoice)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!qof_commit_edit (QOF_INSTANCE(invoice))) return;
|
|
|
|
qof_commit_edit_part2 (&invoice->inst, gncInvoiceOnError,
|
|
|
|
gncInvoiceOnDone, invoice_free);
|
2002-11-03 14:21:42 -06:00
|
|
|
}
|
|
|
|
|
2008-08-01 11:02:07 -05:00
|
|
|
int gncInvoiceCompare (const GncInvoice *a, const GncInvoice *b)
|
2002-02-03 14:01:08 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
int compare;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (a == b) return 0;
|
2011-09-01 01:50:32 -05:00
|
|
|
if (!a) return -1;
|
|
|
|
if (!b) return 1;
|
2002-02-03 14:01:08 -06:00
|
|
|
|
2012-08-07 12:24:55 -05:00
|
|
|
compare = g_strcmp0 (a->id, b->id);
|
2010-03-02 15:41:05 -06:00
|
|
|
if (compare) return compare;
|
2017-12-29 15:07:08 -06:00
|
|
|
if (a->date_opened != b->date_opened) return a->date_opened - b->date_opened;
|
|
|
|
if (a->date_posted != b->date_posted) return a->date_posted - b->date_posted;
|
2010-03-02 15:41:05 -06:00
|
|
|
return qof_instance_guid_compare(a, b);
|
2002-02-03 14:01:08 -06:00
|
|
|
}
|
|
|
|
|
2010-04-17 12:00:18 -05:00
|
|
|
gboolean gncInvoiceEqual(const GncInvoice *a, const GncInvoice *b)
|
|
|
|
{
|
|
|
|
if (a == NULL && b == NULL) return TRUE;
|
|
|
|
if (a == NULL || b == NULL) return FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GNC_IS_INVOICE(a), FALSE);
|
|
|
|
g_return_val_if_fail(GNC_IS_INVOICE(b), FALSE);
|
|
|
|
|
2012-08-07 12:24:55 -05:00
|
|
|
if (g_strcmp0(a->id, b->id) != 0)
|
2010-04-17 12:00:18 -05:00
|
|
|
{
|
|
|
|
PWARN("IDs differ: %s vs %s", a->id, b->id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-07 12:24:55 -05:00
|
|
|
if (g_strcmp0(a->notes, b->notes) != 0)
|
2010-04-17 12:00:18 -05:00
|
|
|
{
|
|
|
|
PWARN("Notes differ: %s vs %s", a->notes, b->notes);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-07 12:24:55 -05:00
|
|
|
if (g_strcmp0(a->billing_id, b->billing_id) != 0)
|
2010-04-17 12:00:18 -05:00
|
|
|
{
|
|
|
|
PWARN("Billing IDs differ: %s vs %s", a->billing_id, b->billing_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-07 12:24:55 -05:00
|
|
|
if (g_strcmp0(a->printname, b->printname) != 0)
|
2010-04-17 12:00:18 -05:00
|
|
|
{
|
|
|
|
PWARN("Printnames differ: %s vs %s", a->printname, b->printname);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->active != b->active)
|
|
|
|
{
|
|
|
|
PWARN("Active flags differ");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gncBillTermEqual(a->terms, b->terms))
|
|
|
|
{
|
|
|
|
PWARN("Billterms differ");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gncJobEqual(a->job, b->job))
|
|
|
|
{
|
|
|
|
PWARN("Jobs differ");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gnc_commodity_equal(a->currency, b->currency))
|
|
|
|
{
|
|
|
|
PWARN("Currencies differ");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xaccAccountEqual(a->posted_acc, b->posted_acc, TRUE))
|
|
|
|
{
|
|
|
|
PWARN("Posted accounts differ");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xaccTransEqual(a->posted_txn, b->posted_txn, TRUE, TRUE, TRUE, FALSE))
|
|
|
|
{
|
|
|
|
PWARN("Posted tx differ");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (!gncLotEqual(a->posted_lot, b->posted_lot))
|
|
|
|
{
|
|
|
|
PWARN("Posted lots differ");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* FIXME: Need real checks */
|
|
|
|
#if 0
|
|
|
|
GList *entries;
|
|
|
|
GList *prices;
|
|
|
|
GncOwner owner;
|
|
|
|
GncOwner billto;
|
2017-12-29 15:07:08 -06:00
|
|
|
time64 date_opened;
|
|
|
|
time64 date_posted;
|
2010-04-17 12:00:18 -05:00
|
|
|
|
|
|
|
gnc_numeric to_charge_amount;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-10-19 00:13:59 -05:00
|
|
|
/* ============================================================= */
|
2001-11-24 23:34:34 -06:00
|
|
|
/* Package-Private functions */
|
|
|
|
|
2002-02-24 16:12:24 -06:00
|
|
|
static const char * _gncInvoicePrintable (gpointer obj)
|
2002-02-23 22:01:57 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
GncInvoice *invoice = obj;
|
2002-02-24 16:12:24 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
g_return_val_if_fail (invoice, NULL);
|
2002-02-23 22:01:57 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (qof_instance_get_dirty_flag(invoice) || invoice->printname == NULL)
|
|
|
|
{
|
|
|
|
if (invoice->printname) g_free (invoice->printname);
|
2002-02-23 22:01:57 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
invoice->printname =
|
|
|
|
g_strdup_printf ("%s%s", invoice->id,
|
|
|
|
gncInvoiceIsPosted (invoice) ? _(" (posted)") : "");
|
|
|
|
}
|
2002-02-23 22:01:57 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return invoice->printname;
|
2002-02-23 22:01:57 -06:00
|
|
|
}
|
|
|
|
|
2010-12-28 19:43:28 -06:00
|
|
|
static void
|
|
|
|
destroy_invoice_on_book_close(QofInstance *ent, gpointer data)
|
|
|
|
{
|
|
|
|
GncInvoice* invoice = GNC_INVOICE(ent);
|
|
|
|
|
|
|
|
gncInvoiceBeginEdit(invoice);
|
|
|
|
gncInvoiceDestroy(invoice);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gnc_invoice_book_end(QofBook* book)
|
|
|
|
{
|
|
|
|
QofCollection *col;
|
|
|
|
|
|
|
|
col = qof_book_get_collection(book, GNC_ID_INVOICE);
|
|
|
|
qof_collection_foreach(col, destroy_invoice_on_book_close, NULL);
|
|
|
|
}
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
static QofObject gncInvoiceDesc =
|
2003-10-19 00:13:59 -05:00
|
|
|
{
|
2010-03-27 16:01:56 -05:00
|
|
|
DI(.interface_version = ) QOF_OBJECT_VERSION,
|
|
|
|
DI(.e_type = ) _GNC_MOD_NAME,
|
|
|
|
DI(.type_label = ) "Invoice",
|
|
|
|
DI(.create = ) (gpointer)gncInvoiceCreate,
|
|
|
|
DI(.book_begin = ) NULL,
|
2010-12-28 19:43:28 -06:00
|
|
|
DI(.book_end = ) gnc_invoice_book_end,
|
2010-03-27 16:01:56 -05:00
|
|
|
DI(.is_dirty = ) qof_collection_is_dirty,
|
|
|
|
DI(.mark_clean = ) qof_collection_mark_clean,
|
|
|
|
DI(.foreach = ) qof_collection_foreach,
|
|
|
|
DI(.printable = ) _gncInvoicePrintable,
|
|
|
|
DI(.version_cmp = ) (int (*)(gpointer, gpointer)) qof_instance_version_cmp,
|
2001-11-21 19:23:07 -06:00
|
|
|
};
|
|
|
|
|
2002-06-27 23:39:18 -05:00
|
|
|
static void
|
|
|
|
reg_lot (void)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
static QofParam params[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
INVOICE_FROM_LOT, _GNC_MOD_NAME,
|
|
|
|
(QofAccessFunc)gncInvoiceGetInvoiceFromLot, 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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reg_txn (void)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
static QofParam params[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
INVOICE_FROM_TXN, _GNC_MOD_NAME,
|
|
|
|
(QofAccessFunc)gncInvoiceGetInvoiceFromTxn, NULL
|
|
|
|
},
|
|
|
|
{ NULL },
|
|
|
|
};
|
2002-06-27 23:39:18 -05:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
qof_class_register (GNC_ID_TRANS, NULL, params);
|
2002-06-27 23:39:18 -05:00
|
|
|
}
|
|
|
|
|
2001-11-21 19:23:07 -06:00
|
|
|
gboolean gncInvoiceRegister (void)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
static QofParam params[] =
|
|
|
|
{
|
2011-10-08 11:59:01 -05:00
|
|
|
{ INVOICE_ID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetID, (QofSetterFunc)gncInvoiceSetID },
|
|
|
|
{ INVOICE_OWNER, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetOwner, NULL },
|
|
|
|
{ INVOICE_OPENED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateOpened, (QofSetterFunc)gncInvoiceSetDateOpened },
|
|
|
|
{ INVOICE_DUE, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDateDue, NULL },
|
|
|
|
{ INVOICE_POSTED, QOF_TYPE_DATE, (QofAccessFunc)gncInvoiceGetDatePosted, (QofSetterFunc)gncInvoiceSetDatePosted },
|
2010-03-02 15:41:05 -06:00
|
|
|
{ INVOICE_IS_POSTED, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPosted, NULL },
|
2011-10-08 11:59:01 -05:00
|
|
|
{ INVOICE_IS_PAID, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceIsPaid, NULL },
|
|
|
|
{ INVOICE_BILLINGID, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetBillingID, (QofSetterFunc)gncInvoiceSetBillingID },
|
|
|
|
{ INVOICE_NOTES, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetNotes, (QofSetterFunc)gncInvoiceSetNotes },
|
|
|
|
{ INVOICE_ACC, GNC_ID_ACCOUNT, (QofAccessFunc)gncInvoiceGetPostedAcc, (QofSetterFunc)gncInvoiceSetPostedAcc },
|
|
|
|
{ INVOICE_POST_TXN, GNC_ID_TRANS, (QofAccessFunc)gncInvoiceGetPostedTxn, (QofSetterFunc)gncInvoiceSetPostedTxn },
|
|
|
|
{ INVOICE_POST_LOT, GNC_ID_LOT, (QofAccessFunc)gncInvoiceGetPostedLot, NULL/*(QofSetterFunc)gncInvoiceSetPostedLot*/ },
|
|
|
|
{ INVOICE_TYPE, QOF_TYPE_INT32, (QofAccessFunc)gncInvoiceGetType, NULL },
|
|
|
|
{ INVOICE_TYPE_STRING, QOF_TYPE_STRING, (QofAccessFunc)gncInvoiceGetTypeString, NULL },
|
|
|
|
{ INVOICE_TERMS, GNC_ID_BILLTERM, (QofAccessFunc)gncInvoiceGetTerms, (QofSetterFunc)gncInvoiceSetTerms },
|
|
|
|
{ INVOICE_BILLTO, GNC_ID_OWNER, (QofAccessFunc)gncInvoiceGetBillTo, NULL },
|
|
|
|
{ INVOICE_ENTRIES, QOF_TYPE_COLLECT, (QofAccessFunc)qofInvoiceGetEntries, (QofSetterFunc)qofInvoiceSetEntries },
|
|
|
|
{ INVOICE_JOB, GNC_ID_JOB, (QofAccessFunc)qofInvoiceGetJob, (QofSetterFunc)qofInvoiceSetJob },
|
|
|
|
{ QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetActive, (QofSetterFunc)gncInvoiceSetActive },
|
2011-10-08 11:59:19 -05:00
|
|
|
{ INVOICE_IS_CN, QOF_TYPE_BOOLEAN, (QofAccessFunc)gncInvoiceGetIsCreditNote, (QofSetterFunc)gncInvoiceSetIsCreditNote },
|
2011-10-08 11:59:01 -05:00
|
|
|
{ QOF_PARAM_BOOK, QOF_ID_BOOK, (QofAccessFunc)qof_instance_get_book, NULL },
|
|
|
|
{ QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_instance_get_guid, NULL },
|
2010-03-02 15:41:05 -06:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
qof_class_register (_GNC_MOD_NAME, (QofSortFunc)gncInvoiceCompare, params);
|
|
|
|
reg_lot ();
|
|
|
|
reg_txn ();
|
|
|
|
|
|
|
|
/* Make the compiler happy... */
|
|
|
|
if (0)
|
|
|
|
{
|
|
|
|
qofInvoiceSetEntries(NULL, NULL);
|
|
|
|
qofInvoiceGetEntries(NULL);
|
|
|
|
qofInvoiceSetOwner(NULL, NULL);
|
|
|
|
qofInvoiceGetOwner(NULL);
|
|
|
|
qofInvoiceSetBillTo(NULL, NULL);
|
|
|
|
qofInvoiceGetBillTo(NULL);
|
|
|
|
}
|
|
|
|
if (!qof_choice_create(GNC_ID_INVOICE))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return qof_object_register (&gncInvoiceDesc);
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|
|
|
|
|
2011-10-10 07:34:58 -05:00
|
|
|
gchar *gncInvoiceNextID (QofBook *book, const GncOwner *owner)
|
2007-12-25 10:56:35 -06:00
|
|
|
{
|
2011-01-10 15:39:06 -06:00
|
|
|
gchar *nextID;
|
2010-03-02 15:41:05 -06:00
|
|
|
switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))
|
|
|
|
{
|
2007-12-25 10:56:35 -06:00
|
|
|
case GNC_OWNER_CUSTOMER:
|
2011-01-10 15:39:06 -06:00
|
|
|
nextID = qof_book_increment_and_format_counter (book, "gncInvoice");
|
2007-12-25 10:56:35 -06:00
|
|
|
break;
|
|
|
|
case GNC_OWNER_VENDOR:
|
2011-01-10 15:39:06 -06:00
|
|
|
nextID = qof_book_increment_and_format_counter (book, "gncBill");
|
2010-03-02 15:41:05 -06:00
|
|
|
break;
|
2007-12-25 10:56:35 -06:00
|
|
|
case GNC_OWNER_EMPLOYEE:
|
2011-01-10 15:39:06 -06:00
|
|
|
nextID = qof_book_increment_and_format_counter (book, "gncExpVoucher");
|
2010-03-02 15:41:05 -06:00
|
|
|
break;
|
2007-12-25 10:56:35 -06:00
|
|
|
default:
|
2011-01-10 15:39:06 -06:00
|
|
|
nextID = qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
|
2010-03-02 15:41:05 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nextID;
|
2001-11-21 19:23:07 -06:00
|
|
|
}
|