Work on transaction cut/copy/paste.

Keith Refson's Solaris fixes.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2302 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-05-12 09:47:17 +00:00
parent 97813eea86
commit 9ce424e31f
18 changed files with 644 additions and 291 deletions

View File

@ -1,3 +1,14 @@
2000-05-12 Dave Peticolas <peticola@cs.ucdavis.edu>
* Makefile.in: add -follow arguments to find commands
* Makefile.common (CFLAGS): removed hard-coded profiling option
* configure.in: add a profiling argument.
* src/guile/gnucash.c: use putenv, not setenv. putenv is POSIX,
seems to be more common.
2000-05-10 Dave Peticolas <peticola@cs.ucdavis.edu>
* many: removed use of SCM registry in favor of scm_protect_object

View File

@ -42,7 +42,7 @@ MOTIF_OBJS += $(addprefix obj/motif/,${MOTIF_SRCS:.c=.o})
QT_OBJS := $(addprefix obj/qt/,${COMMON_SRCS:.c=.o})
QT_OBJS += $(addprefix obj/qt/,${QT_SRCS:.cpp=.o})
CFLAGS += -pg ${DEFS}
CFLAGS += ${DEFS}
ifdef GNOME_CONFIG_BIN
GNOME_CFLAGS += $(shell ${GNOME_CONFIG_BIN} --cflags gnomeui)

View File

@ -199,13 +199,13 @@ install:
# Share directory
# Try to do this in a platform independent way...
# Directories
for dir in `find share/scm/ -type d`; do \
for dir in `find share/scm/ -type d -follow`; do \
dest=`echo $$dir | cut -c 11-` ;\
mkdir -p ${GNC_SHAREDIR}/scm/$$dest; \
done
# Files
for file in `find share/scm/ -name "*.scm"`; do \
for file in `find share/scm/ -name "*.scm" -follow`; do \
dest=`echo $$file | cut -c 11-` ;\
${INSTALL_DATA} $$file ${GNC_SHAREDIR}/scm/$$dest; \
done

View File

@ -42,6 +42,9 @@
/* Standard C headers present */
#undef STDC_HEADERS
/* limits.h header present */
#undef HAVE_LIMITS_H
/* memcpy present */
#undef HAVE_MEMCPY

389
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -40,8 +40,10 @@ AC_C_BIGENDIAN
AC_PROG_MAKE_SET
AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h)
AC_CHECK_FUNCS(stpcpy memcpy)
### --------------------------------------------------------------------------
### Variables
### Set up all the initial variable values...
@ -70,6 +72,11 @@ AC_ARG_ENABLE( debug,
AC_DEFINE(DEBUG_MEMORY,1) AC_DEFINE(USE_DEBUG,1),
AC_DEFINE(DEBUG_MEMORY,0) AC_DEFINE(USE_DEBUG,0) )
AC_ARG_ENABLE( profile,
[ --enable-profile compile with profiling set],
CFLAGS="${CFLAGS} -pg"
LDFLAGS="${LDFLAGS} -pg")
AC_ARG_ENABLE( warnings,
[ --enable-warnings compile with lots of warnings generated],
CFLAGS="${CFLAGS} -g -Wall -ansi -pedantic -Wwrite-strings -Wid-clash-31 -Wpointer-arith -Wcast-qual -Wcast-align -Wtraditional -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wshadow -Woverloaded-virtual -Winline -felide-constructors -fnonnull-objects"

View File

@ -595,6 +595,7 @@ Peter Pointner <peter@wuzel.m.isar.de> QIF import fixes, Qt patches
Gavin Porter <maufk@csv.warwick.ac.uk> for euro style dates
Tomas Pospisek <tpo@spin.ch> debian patches
Ron Record <rr@sco.com> for SCO Unixware & OpenServer binaries
Keith Refson <Keith.Refson@earth.ox.ac.uk> Solaris fixes
Dirk Schoenberger <schoenberger@signsoft.com> Qt/KDE work
Jan Schrage <jan.schrage@urz.uni-heidelberg.de> documentation patches
Christopher Seawood <cls@seawood.org> for XbaeMatrix core dump

View File

@ -447,6 +447,10 @@
<dd>for SCO Unixware and OpenServer binaries</dd>
<dt> <a href="mailto:Keith.Refson@earth.ox.ac.uk"> Keith Refson</a></dt>
<dd>Solaris fixes</dd>
<dt> <a href="mailto:schoenberger@signsoft.com"> Dirk
Schoenberger</a></dt>

View File

@ -184,7 +184,6 @@ static SRReverseBalanceCallback reverse_balance = NULL;
/* The copied split or transaction, if any */
static SCM copied_item = SCM_UNDEFINED;
static SCM copied_item_id = SCM_UNDEFINED;
/* static prototypes */
static void xaccSRLoadRegEntry (SplitRegister *reg, Split *split);
@ -278,9 +277,7 @@ xaccSRSetReverseBalanceCallback(SRReverseBalanceCallback callback)
}
/* copies basic split values from 'from' split to 'to' split.
* doesn't copy reconciled flag, or open the parent transactions
* for editing. Does *not* insert the 'to' split into an account!! */
/* Uses the scheme split copying routines */
static void
gnc_copy_split_onto_split(Split *from, Split *to)
{
@ -296,48 +293,20 @@ gnc_copy_split_onto_split(Split *from, Split *to)
gnc_copy_split_scm_onto_split(split_scm, to);
}
/* copies the basic transaction values and the splits from the
* 'from' trans to the 'to' trans. Any existing splits in the
* 'to' trans are deleted. Does *not* open the 'to' trans for
* editing!!! Splits are copied using gnc_copy_split_onto_split
* above. The new splits will be in exactly the same order as in
* the 'from' transaction. */
/* Uses the scheme transaction copying routines */
static void
gnc_copy_trans(Transaction *from, Transaction *to)
gnc_copy_trans_onto_trans(Transaction *from, Transaction *to)
{
Split *from_split, *to_split;
Timespec timespec;
int num_splits;
int i;
SCM trans_scm;
if ((from == NULL) || (to == NULL))
return;
/* remove the old splits */
to_split = xaccTransGetSplit(to, 0);
while (to_split != NULL)
{
xaccSplitDestroy(to_split);
to_split = xaccTransGetSplit(to, 0);
}
trans_scm = gnc_copy_trans(from);
if (trans_scm == SCM_UNDEFINED)
return;
/* add in the new splits */
num_splits = xaccTransCountSplits(from);
for (i = 0; i < num_splits; i++)
{
from_split = xaccTransGetSplit(from, i);
to_split = xaccMallocSplit();
gnc_copy_split_onto_split(from_split, to_split);
xaccTransAppendSplit(to, to_split);
}
/* now do the transaction-specific values */
xaccTransGetDateTS(from, &timespec);
xaccTransSetDateTS(to, &timespec);
xaccTransSetDescription(to, xaccTransGetDescription(from));
xaccTransSetDocref(to, xaccTransGetDocref(from));
gnc_copy_trans_scm_onto_trans(trans_scm, to);
}
/* ======================================================== */
@ -467,7 +436,8 @@ LedgerMoveCursor (Table *table,
else if (new_phys_col >= table->num_phys_cols)
new_phys_col = table->num_phys_cols - 1;
gnc_table_find_valid_cell_horiz(table, &new_phys_row, &new_phys_col, GNC_F);
gnc_table_find_valid_cell_horiz(table, &new_phys_row,
&new_phys_col, GNC_F);
*p_new_phys_row = new_phys_row;
*p_new_phys_col = new_phys_col;
@ -887,46 +857,35 @@ xaccSRDuplicateCurrent (SplitRegister *reg)
else
{
Transaction *new_trans;
int split_index;
int num_splits;
int i;
/* We are on a transaction row. Copy the whole transaction. */
split_index = -1;
num_splits = xaccTransCountSplits(trans);
for (i = 0; i < num_splits; i++)
if (xaccTransGetSplit(trans, i) == split)
{
split_index = i;
break;
}
/* we should *always* find the split, but be paranoid */
if (split_index < 0)
return NULL;
new_trans = xaccMallocTransaction();
xaccTransBeginEdit(new_trans, GNC_T);
gnc_copy_trans(trans, new_trans);
num_splits = xaccTransCountSplits(trans);
return_split = NULL;
/* Link the new splits into the accounts. */
for (i = 0; i < num_splits; i++)
{
Account *account;
Split *old_split;
Split *new_split;
old_split = xaccTransGetSplit(trans, i);
account = xaccSplitGetAccount(old_split);
new_split = xaccTransGetSplit(new_trans, i);
xaccAccountBeginEdit(account, GNC_T);
xaccAccountInsertSplit(account, new_split);
xaccAccountCommitEdit(account);
/* Returned split is the transaction split */
if (old_split == split)
return_split = new_split;
}
xaccTransCommitEdit(new_trans);
gnc_copy_trans_onto_trans(trans, new_trans);
/* This shouldn't happen, but be paranoid. */
if (return_split == NULL)
return_split = xaccTransGetSplit(new_trans, 0);
num_splits = xaccTransCountSplits(new_trans);
if (split_index >= num_splits)
split_index = 0;
return_split = xaccTransGetSplit(new_trans, split_index);
}
/* Refresh the GUI. */
@ -1246,6 +1205,168 @@ xaccSRRedrawRegEntry (SplitRegister *reg)
gnc_refresh_main_window();
}
/* ======================================================== */
/* Copy from the register object to scheme.
* This needs to be in sync with xaccSRSaveRegEntry. */
static gncBoolean
xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm)
{
Transaction *trans;
unsigned int changed;
int style;
/* use the changed flag to avoid heavy-weight updates
* of the split & transaction fields. This will help
* cut down on uneccessary register redraws. */
changed = xaccSplitRegisterGetChangeFlag (reg);
if (!changed)
return GNC_F;
style = (reg->type) & REG_STYLE_MASK;
/* get the handle to the current split and transaction */
trans = xaccSRGetCurrentTrans (reg);
if (trans == NULL)
return GNC_F;
/* copy the contents from the cursor to the split */
if (MOD_DATE & changed) {
Timespec ts;
xaccDateCellGetDate(reg->dateCell, &ts);
gnc_trans_scm_set_date(trans_scm, &ts);
}
if (MOD_NUM & changed)
gnc_trans_scm_set_num(trans_scm, reg->numCell->cell.value);
if (MOD_DESC & changed)
gnc_trans_scm_set_description(trans_scm, reg->descCell->cell.value);
if (MOD_RECN & changed)
gnc_split_scm_set_reconcile_state(split_scm, reg->recnCell->value[0]);
if (MOD_ACTN & changed)
gnc_split_scm_set_action(split_scm, reg->actionCell->cell.value);
if (MOD_MEMO & changed)
gnc_split_scm_set_memo(split_scm, reg->memoCell->cell.value);
if ((MOD_XFRM | MOD_XTO) & changed) {
Account *new_account;
char *new_name;
if (MOD_XFRM & changed)
new_name = reg->xfrmCell->cell.value;
else
new_name = reg->xtoCell->cell.value;
new_account = xaccGetAccountByFullName(trans, new_name, account_separator);
if (new_account != NULL)
gnc_split_scm_set_account(split_scm, new_account);
}
if (MOD_MXFRM & changed) {
SCM other_split_scm;
other_split_scm = gnc_trans_scm_get_other_split_scm(trans_scm, split_scm);
if (other_split_scm == SCM_UNDEFINED) {
if (gnc_trans_scm_get_num_splits(trans_scm) == 1) {
Split *temp_split;
char *temp_string;
double price;
double amount;
temp_split = xaccMallocSplit ();
other_split_scm = gnc_copy_split(temp_split);
xaccSplitDestroy(temp_split);
temp_string = gnc_split_scm_get_memo(split_scm);
if (temp_string != NULL) {
gnc_split_scm_set_memo(other_split_scm, temp_string);
free(temp_string);
}
temp_string = gnc_split_scm_get_action(split_scm);
if (temp_string != NULL) {
gnc_split_scm_set_action(other_split_scm, temp_string);
free(temp_string);
}
price = gnc_split_scm_get_share_price(other_split_scm);
amount = gnc_split_scm_get_share_amount(other_split_scm);
gnc_split_scm_set_share_price_and_amount(other_split_scm,
price, amount);
gnc_trans_scm_append_split_scm(trans_scm, other_split_scm);
}
}
if (other_split_scm != SCM_UNDEFINED) {
Account *new_account;
new_account = xaccGetAccountByFullName(trans, reg->mxfrmCell->cell.value,
account_separator);
if (new_account != NULL)
gnc_split_scm_set_account(other_split_scm, new_account);
}
}
if ((MOD_AMNT | MOD_NAMNT) & changed) {
double new_amount;
double price;
double credit;
double debit;
if (MOD_AMNT & changed) {
credit = xaccGetPriceCellValue(reg->creditCell);
debit = xaccGetPriceCellValue(reg->debitCell);
new_amount = debit - credit;
} else {
credit = xaccGetPriceCellValue(reg->ncreditCell);
debit = xaccGetPriceCellValue(reg->ndebitCell);
new_amount = -(debit - credit);
}
price = gnc_split_scm_get_share_price(split_scm);
if ((EQUITY_REGISTER == (reg->type & REG_TYPE_MASK)) ||
(STOCK_REGISTER == (reg->type & REG_TYPE_MASK)) ||
(CURRENCY_REGISTER == (reg->type & REG_TYPE_MASK)) ||
(PORTFOLIO_LEDGER == (reg->type & REG_TYPE_MASK)))
;
else
new_amount = new_amount / price;
gnc_split_scm_set_share_price_and_amount(split_scm, price, new_amount);
}
if (MOD_PRIC & changed) {
double price;
double amount;
price = xaccGetPriceCellValue(reg->priceCell);
amount = gnc_split_scm_get_share_amount(split_scm);
gnc_split_scm_set_share_price_and_amount(split_scm, price, amount);
}
if (MOD_VALU & changed) {
double value = xaccGetPriceCellValue(reg->valueCell);
double price = gnc_split_scm_get_share_price(split_scm);
value = value / price;
gnc_split_scm_set_share_price_and_amount(split_scm, price, value);
}
return GNC_T;
}
/* ======================================================== */
/* Copy from the register object to the engine */
@ -1262,7 +1383,7 @@ xaccSRSaveRegEntry (SplitRegister *reg, Transaction *new_trans)
/* use the changed flag to avoid heavy-weight updates
* of the split & transaction fields. This will help
* cut down on uneccessary register redraws. */
* cut down on uneccessary register redraws. */
changed = xaccSplitRegisterGetChangeFlag (reg);
if (!changed)
return GNC_F;

View File

@ -154,6 +154,10 @@ void xaccSREmptyCurrentTrans (SplitRegister *reg);
void xaccSRCancelCursorSplitChanges (SplitRegister *reg);
void xaccSRCancelCursorTransChanges (SplitRegister *reg);
void xaccSRCopyCurrent (SplitRegister *reg);
void xaccSRCutCurrent (SplitRegister *reg);
void xaccSRPasteCurrent (SplitRegister *reg);
void xaccSRLoadRegister (SplitRegister *reg, Split **slist,
Account *default_source_acc);

View File

@ -2131,7 +2131,7 @@ xaccGetAccountByFullName (Transaction *trans, const char * name,
s = trans->splits[i];
}
if (!acc) return 0x0;
if (!acc) return NULL;
acc = xaccGetPeerAccountFromFullName (acc, name, separator);
return acc;

View File

@ -145,7 +145,7 @@ gnc_option_set_ui_value(GNCOption *option, gboolean use_default)
value = gh_cdr(value);
row = gnc_option_permissible_value_index(option, item);
if (index < 0)
if (row < 0)
{
bad_value = TRUE;
break;

View File

@ -82,6 +82,9 @@
"choose an account to reconcile.\n")
#define AMOUNT_NUM_MSG _("The amount must be a number.")
#define BALANCE_NUM_MSG _("The balance must be a number.")
#define CHANGE_RECN_MSG _("Do you really want to mark this transaction"\
"not reconciled?\nDoing so might make future"\
"reconciliation difficult!")
#define DEL_SPLITS_MSG _("Delete all the splits")
#define DEL_TRANS_MSG _("Delete the whole transaction")
#define DEL_USUAL_MSG _("This selection will delete the whole "\

View File

@ -376,6 +376,19 @@ xaccCommitDateCell (DateCell *cell)
/* ================================================ */
void
xaccDateCellGetDate (DateCell *cell, Timespec *ts)
{
if (!cell || !ts) return;
xaccParseDate (&(cell->date), cell->cell.value);
ts->tv_sec = mktime(&cell->date);
ts->tv_nsec = 0;
}
/* ================================================ */
DateCell *
xaccMallocDateCell (void)
{

View File

@ -88,7 +88,10 @@
#define __XACC_DATE_CELL_C__
#include <time.h>
#include "basiccell.h"
#include "Transaction.h"
typedef struct _DateCell {
BasicCell cell;
@ -106,6 +109,8 @@ void xaccSetDateCellValueSecsL (DateCell *, long long secs);
void xaccCommitDateCell (DateCell *);
void xaccDateCellGetDate (DateCell *cell, Timespec *ts);
#endif /* __XACC_DATE_CELL_C__ */
/* --------------- end of file ---------------------- */

View File

@ -1,14 +1,3 @@
/*
* FILE:
* recncell.c
*
* FUNCTION:
* Implements a mouse-click cell that allows a series
* of values to be clicked through.
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
*/
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -21,10 +10,26 @@
* 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, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
* *
\********************************************************************/
/*
* FILE:
* recncell.c
*
* FUNCTION:
* Implements a mouse-click cell that allows a series
* of values to be clicked through.
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
*/
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -32,6 +37,7 @@
#include "basiccell.h"
#include "recncell.h"
#include "ui-callbacks.h"
#include "messages.h"
/* hack alert -- I am uncomfortable with including engine
* stuff here; all code in this directory should really be
@ -41,6 +47,7 @@
*/
#include "Transaction.h"
/* ================================================ */
static const char *
@ -59,10 +66,7 @@ ToggleRecn (BasicCell *_cell, const char *cur_val,
but that's still perhaps not optimal... */
if(cur_val[0] == YREC) {
if(!gnc_verify_dialog("Do you really want to mark this transaction"
"not reconciled?\nDoing so might make future"
"reconciliation difficult!",
GNC_T)) {
if(!gnc_verify_dialog(CHANGE_RECN_MSG, GNC_T)) {
return strdup(cur_val);
}
}

View File

@ -1,3 +1,23 @@
/********************************************************************\
* 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 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
* *
\********************************************************************/
/*
* FILE:
* recncell.h
@ -13,21 +33,6 @@
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
*/
/********************************************************************\
* 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, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
\********************************************************************/
#ifndef __XACC_RECN_CELL_C__
#define __XACC_RECN_CELL_C__

View File

@ -26,12 +26,15 @@
'(split-guid account-guid transaction-guid memo action docref
reconcile-state reconciled-date share-amount share-price)))
;; constructor
(define gnc:make-split-scm
(record-constructor gnc:split-structure))
;; type predicate
(define gnc:split-scm?
(record-predicate gnc:split-structure))
;; accessors
(define gnc:split-scm-get-split-guid
(record-accessor gnc:split-structure 'split-guid))
@ -62,6 +65,37 @@
(define gnc:split-scm-get-share-price
(record-accessor gnc:split-structure 'share-price))
;; modifiers
(define gnc:split-scm-set-split-guid
(record-modifier gnc:split-structure 'split-guid))
(define gnc:split-scm-set-account-guid
(record-modifier gnc:split-structure 'account-guid))
(define gnc:split-scm-set-transaction-guid
(record-modifier gnc:split-structure 'transaction-guid))
(define gnc:split-scm-set-memo
(record-modifier gnc:split-structure 'memo))
(define gnc:split-scm-set-action
(record-modifier gnc:split-structure 'action))
(define gnc:split-scm-set-docref
(record-modifier gnc:split-structure 'docref))
(define gnc:split-scm-set-reconcile-state
(record-modifier gnc:split-structure 'reconcile-state))
(define gnc:split-scm-set-reconciled-date
(record-modifier gnc:split-structure 'reconciled-date))
(define gnc:split-scm-set-share-amount
(record-modifier gnc:split-structure 'share-amount))
(define gnc:split-scm-set-share-price
(record-modifier gnc:split-structure 'share-price))
;; This function take a C split and returns a representation
;; of it as a split-structure. Assumes the transaction is open
;; for editing.
@ -87,17 +121,23 @@
(if (pointer-token-null? split)
#f
(begin
(let ((memo (gnc:split-scm-get-memo split-scm))
(action (gnc:split-scm-get-action split-scm))
(docref (gnc:split-scm-get-docref split-scm))
(price (gnc:split-scm-get-share-price split-scm))
(amount (gnc:split-scm-get-share-amount split-scm)))
(if memo (gnc:split-set-memo split memo))
(if action (gnc:split-set-action split action))
(if docref (gnc:split-set-docref split docref))
(if (and price amount)
(gnc:split-set-share-price-and-amount split price amount)))
(let ((account (gnc:account-lookup
(gnc:split-scm-get-account-guid split-scm))))
(if (and account (gnc:account-can-insert-split? account split))
(gnc:account-insert-split account split)))
(gnc:split-set-memo split (gnc:split-scm-get-memo split-scm))
(gnc:split-set-action split (gnc:split-scm-get-action split-scm))
(gnc:split-set-docref split (gnc:split-scm-get-docref split-scm))
(gnc:split-set-share-price-and-amount
split
(gnc:split-scm-get-share-price split-scm)
(gnc:split-scm-get-share-amount split-scm)))))
(begin
(gnc:account-begin-edit account 1)
(gnc:account-insert-split account split)
(gnc:account-commit-edit account)))))))
;; Returns true if we can insert the C split into the given account.
(define (gnc:account-can-insert-split? account split)
@ -113,14 +153,18 @@
(define gnc:transaction-structure
(make-record-type
"gnc:transaction-structure"
'(transaction-guid date-entered date-posted num description docref splits)))
'(transaction-guid date-entered date-posted num
description docref split-scms)))
;; constructor
(define gnc:make-transaction-scm
(record-constructor gnc:transaction-structure))
;; type predicate
(define gnc:transaction-scm?
(record-predicate gnc:transaction-structure))
;; accessors
(define gnc:transaction-scm-get-transaction-guid
(record-accessor gnc:transaction-structure 'transaction-guid))
@ -139,17 +183,58 @@
(define gnc:transaction-scm-get-docref
(record-accessor gnc:transaction-structure 'docref))
(define gnc:transaction-scm-get-splits
(record-accessor gnc:transaction-structure 'splits))
(define gnc:transaction-scm-get-split-scms
(record-accessor gnc:transaction-structure 'split-scms))
(define (gnc:transaction-scm-get-split-scm trans-scm index)
(let ((split-scms (gnc:transaction-scm-get-split-scms trans-scm)))
(cond ((< index 0) #f)
((not (pair? split-scms)) #f)
((>= index (length split-scms)) #f)
(else (list-ref index split-scms)))))
(define (gnc:transaction-scm-get-other-split-scm trans-scm split-scm)
(let ((split-scms (gnc:transaction-scm-get-split-scms trans-scm)))
(cond ((not (= (length split-scms) 2)) #f)
((= split-scm (car split-scms)) (cadr split-scms))
(else (car split-scms)))))
;; modifiers
(define gnc:transaction-scm-set-transaction-guid
(record-modifier gnc:transaction-structure 'transaction-guid))
(define gnc:transaction-scm-set-date-entered
(record-modifier gnc:transaction-structure 'date-entered))
(define gnc:transaction-scm-set-date-posted
(record-modifier gnc:transaction-structure 'date-posted))
(define gnc:transaction-scm-set-num
(record-modifier gnc:transaction-structure 'num))
(define gnc:transaction-scm-set-description
(record-modifier gnc:transaction-structure 'description))
(define gnc:transaction-scm-set-docref
(record-modifier gnc:transaction-structure 'docref))
(define gnc:transaction-scm-set-split-scms
(record-modifier gnc:transaction-structure 'split-scms))
(define (gnc:transaction-scm-append-split-scm trans-scm split-scm)
(let ((split-scms (gnc:transaction-scm-get-split-scms trans-scm)))
(gnc:transaction-scm-set-split-scms
trans-scm (append split-scms (list split-scm)))))
;; This function takes a C transaction and returns
;; a representation of it as a transaction-structure.
(define (gnc:transaction->transaction-scm trans)
(define (trans-splits i)
(let (split ((gnc:transaction-get-split trans i)))
(let ((split (gnc:transaction-get-split trans i)))
(if (pointer-token-null? split)
'()
(cons split (trans-splits (+ i 1))))))
(cons (gnc:split->split-scm split)
(trans-splits (+ i 1))))))
(gnc:make-transaction-scm
(gnc:transaction-get-guid trans)
(gnc:transaction-get-date-entered trans)
@ -159,6 +244,42 @@
(gnc:transaction-get-docref trans)
(trans-splits 0)))
;; Copy a scheme representation of a transaction onto a C transaction.
(define (gnc:transaction-scm-onto-transaction trans-scm trans)
(if (pointer-token-null? trans)
#f
(begin
;; open the transaction for editing
(gnc:transaction-begin-edit trans 1)
;; copy in the transaction values
(let ((date-posted (gnc:transaction-scm-get-date-posted trans-scm))
(description (gnc:transaction-scm-get-description trans-scm))
(docref (gnc:transaction-scm-get-docref trans-scm)))
(if date-posted (gnc:transaction-set-date-posted trans date-posted))
(if description (gnc:transaction-set-description trans description))
(if docref (gnc:transaction-set-docref trans docref)))
;; strip off the old splits
(let loop ((split (gnc:transaction-get-split trans 0)))
(if (not (pointer-token-null? split))
(begin
(gnc:split-destroy split)
(loop (gnc:transaction-get-split trans 0)))))
;; and put on the new ones! Please note they go in the *same*
;; order as in the original transaction. This is important.
(let loop ((split-scms (gnc:transaction-scm-get-split-scms trans-scm)))
(if (pair? split-scms)
(let ((new-split (gnc:split-create)))
(gnc:transaction-append-split trans new-split)
(gnc:split-scm-onto-split (car split-scms) new-split)
(loop (cdr split-scms)))))
;; close the transaction
(gnc:transaction-commit-edit trans))))
;; Return a scheme symbol identifying the type of guid passed in.
(define gnc:guid-type #f)