mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* src/scm/fin.scm: Made the exposed calcualtion functions output positive values. * src/gnome/window-main.c (gnc_main_window_create_menus): Added accelerators to SX-related menu items. * src/gnome/druid-loan.c: Primary change: actually create the Scheduled Transactions which are setup by the user. Miscellaneous other cleanups, text, layout and consistency changes. * src/gnome/dialog-sxsincelast.c: Support handling of the instance-count in forward-looking transaction creation. Simplfied some of the internal data-representation regarding lists of items to be created [removed autoCreateTuple, now uses toCreateTuple]. Removed some DEBUGging output. Handles setting up the implicit 'i' variable. * src/gnome/dialog-sx-from-trans.c (sxftd_compute_sx): Create SXes with an appropriate initial instance-count value. * src/gnome/dialog-scheduledxaction.c (schedXact_editor_populate): Create SXes with an appropriate initial instance-count value. * src/engine/SchedXaction.[ch]: Added support for an instance-count, in order to support an implicit 'i' [of N] variable to SX formula/function processing. * src/engine/SX-ttinfo.c (gnc_ttsplitinfo_free): Made the ttsplitinfo_free'ing a bit safer. * src/calculation/expression_parser.c: Added support for parsing/handling quoted strings. Intended to be parameters to functions. Fixed bug regarding nested handling of strings in the parser. * src/backend/file/gnc-schedxaction-xml-v2.c: Added support for saving/restoring instance-count field of SXes. * src/app-utils/test/test-exp-parser.c (run_parser_test): Fixed pass/fail indication check. (test_parser): Added tests for string params to functions. * ChangeLog: Added entry I forgot from last time. * src/app-utils/gnc-exp-parser.c (func_op): Added support for typed parameters to functions; params are either numerics or strings. Result of function is now parsed correctly. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7125 57a11ea4-9604-0410-9ed3-97b8803252fd
353 lines
7.0 KiB
C
353 lines
7.0 KiB
C
/********************************************************************\
|
|
* SX-ttinfo.c -- Template Transaction manipulation functions *
|
|
* for scheduled transactions *
|
|
* Copyright (C) 2001 Robert Merkel <rgmerk@mira.net> *
|
|
* *
|
|
* 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 *
|
|
* *
|
|
\********************************************************************/
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "SX-ttinfo.h"
|
|
|
|
/* kvp_frame policy? */
|
|
struct TTInfo_s
|
|
{
|
|
/* FIXME add notes field */
|
|
char *description; /* owned by us */
|
|
char *num; /* owned by us */
|
|
gnc_commodity *common_currency; /* not freed */
|
|
|
|
GList *splits; /* list of template splits, owned by us */
|
|
};
|
|
|
|
struct TTSplitInfo_s
|
|
{
|
|
char *action; /* owned by us */
|
|
/* FIXME: What about the split's kvp_frame */
|
|
char *memo; /* owned by us */
|
|
char *credit_formula, *debit_formula; /* owned by us */
|
|
Account *acc;
|
|
};
|
|
|
|
TTInfo *
|
|
gnc_ttinfo_malloc(void)
|
|
{
|
|
TTInfo *tti = g_malloc(sizeof(TTInfo));
|
|
|
|
tti->description = NULL;
|
|
tti->num = NULL;
|
|
tti->common_currency = NULL;
|
|
tti->splits = NULL;
|
|
return tti;
|
|
}
|
|
|
|
static void
|
|
delete_splitinfo(gpointer data, gpointer user_data)
|
|
{
|
|
gnc_ttsplitinfo_free( (TTSplitInfo *) data);
|
|
return;
|
|
}
|
|
|
|
void gnc_ttinfo_free(TTInfo *info)
|
|
{
|
|
g_return_if_fail(info);
|
|
|
|
g_free(info->description);
|
|
g_free(info->num);
|
|
g_list_foreach(info->splits,
|
|
delete_splitinfo,
|
|
NULL);
|
|
|
|
g_list_free(info->splits);
|
|
|
|
g_free(info);
|
|
|
|
return;
|
|
}
|
|
|
|
void
|
|
gnc_ttinfo_set_description(TTInfo *tti, const char *description)
|
|
{
|
|
g_return_if_fail(tti);
|
|
|
|
if(tti->description)
|
|
{
|
|
g_free(tti->description);
|
|
}
|
|
|
|
tti->description = g_strdup(description);
|
|
|
|
return;
|
|
}
|
|
|
|
const char *
|
|
gnc_ttinfo_get_description(TTInfo *tti)
|
|
{
|
|
g_return_val_if_fail(tti, NULL);
|
|
|
|
return tti->description;
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
gnc_ttinfo_set_num(TTInfo *tti, const char *num)
|
|
{
|
|
g_return_if_fail(tti);
|
|
|
|
if(tti->num)
|
|
{
|
|
g_free(tti->num);
|
|
}
|
|
|
|
tti->num = g_strdup(num);
|
|
|
|
return;
|
|
}
|
|
|
|
const char
|
|
*gnc_ttinfo_get_num(TTInfo *tti)
|
|
{
|
|
g_return_val_if_fail(tti, NULL);
|
|
|
|
return tti->num;
|
|
}
|
|
|
|
|
|
void
|
|
gnc_ttinfo_set_currency(TTInfo *tti, gnc_commodity *common_currency)
|
|
{
|
|
g_return_if_fail(tti);
|
|
|
|
tti->common_currency = common_currency;
|
|
return;
|
|
}
|
|
|
|
gnc_commodity *
|
|
gnc_ttinfo_get_currency(TTInfo *tti)
|
|
{
|
|
g_return_val_if_fail(tti, NULL);
|
|
|
|
return tti->common_currency;
|
|
}
|
|
|
|
|
|
void gnc_ttinfo_set_template_splits(TTInfo *tti, GList *splits)
|
|
{
|
|
g_return_if_fail(tti);
|
|
|
|
tti->splits = splits;
|
|
return;
|
|
}
|
|
|
|
void gnc_ttinfo_append_template_split(TTInfo *tti, TTSplitInfo *split_i)
|
|
{
|
|
g_return_if_fail(tti && split_i);
|
|
|
|
tti->splits = g_list_append(tti->splits, split_i);
|
|
|
|
return;
|
|
}
|
|
|
|
GList *
|
|
gnc_ttinfo_get_template_splits(TTInfo *tti)
|
|
{
|
|
g_return_val_if_fail(tti, NULL);
|
|
return tti->splits;
|
|
}
|
|
|
|
TTSplitInfo *
|
|
gnc_ttsplitinfo_malloc(void)
|
|
{
|
|
TTSplitInfo *ttsi = g_malloc(sizeof(TTSplitInfo));
|
|
|
|
ttsi->action = NULL;
|
|
ttsi->memo = NULL;
|
|
ttsi->credit_formula = NULL;
|
|
ttsi->debit_formula = NULL;
|
|
ttsi->acc = NULL;
|
|
return ttsi;
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_free(TTSplitInfo *ttsi)
|
|
{
|
|
if ( ttsi->action )
|
|
g_free(ttsi->action);
|
|
if ( ttsi->memo )
|
|
g_free(ttsi->memo);
|
|
if ( ttsi->credit_formula )
|
|
g_free(ttsi->credit_formula);
|
|
if ( ttsi->debit_formula )
|
|
g_free(ttsi->debit_formula);
|
|
g_free(ttsi);
|
|
return;
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_set_action(TTSplitInfo *ttsi, const char *action)
|
|
{
|
|
g_return_if_fail(ttsi);
|
|
|
|
if (ttsi->action)
|
|
g_free(ttsi->action);
|
|
|
|
ttsi->action = g_strdup(action);
|
|
return;
|
|
}
|
|
|
|
const char *
|
|
gnc_ttsplitinfo_get_action(TTSplitInfo *ttsi)
|
|
{
|
|
g_return_val_if_fail(ttsi, NULL);
|
|
|
|
return ttsi->action;
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_set_memo(TTSplitInfo *ttsi, const char *memo)
|
|
{
|
|
g_return_if_fail(ttsi);
|
|
|
|
if (ttsi->memo)
|
|
g_free(ttsi->memo);
|
|
|
|
ttsi->memo = g_strdup(memo);
|
|
return;
|
|
}
|
|
|
|
const char *
|
|
gnc_ttsplitinfo_get_memo(TTSplitInfo *ttsi)
|
|
{
|
|
g_return_val_if_fail(ttsi, NULL);
|
|
|
|
return ttsi->memo;
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_set_credit_formula_numeric(TTSplitInfo *ttsi, gnc_numeric credit)
|
|
{
|
|
g_return_if_fail(ttsi);
|
|
|
|
if(ttsi->credit_formula)
|
|
g_free(ttsi->credit_formula);
|
|
|
|
ttsi->credit_formula = gnc_numeric_to_string(credit);
|
|
|
|
if(ttsi->debit_formula)
|
|
{
|
|
g_free(ttsi->debit_formula);
|
|
ttsi->debit_formula = NULL;
|
|
}
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_set_credit_formula(TTSplitInfo *ttsi, const char *credit_formula)
|
|
{
|
|
g_return_if_fail(ttsi);
|
|
|
|
if (ttsi->credit_formula)
|
|
g_free(ttsi->credit_formula);
|
|
|
|
ttsi->credit_formula = g_strdup(credit_formula);
|
|
|
|
if(ttsi->debit_formula)
|
|
{
|
|
g_free(ttsi->debit_formula);
|
|
ttsi->debit_formula = NULL;
|
|
}
|
|
return;
|
|
}
|
|
|
|
const char *
|
|
gnc_ttsplitinfo_get_credit_formula(TTSplitInfo *ttsi)
|
|
{
|
|
g_return_val_if_fail(ttsi, NULL);
|
|
|
|
return ttsi->credit_formula;
|
|
}
|
|
|
|
|
|
const char *
|
|
gnc_ttsplitinfo_get_debit_formula(TTSplitInfo *ttsi)
|
|
{
|
|
g_return_val_if_fail(ttsi, NULL);
|
|
|
|
if (ttsi->debit_formula)
|
|
g_free(ttsi->credit_formula);
|
|
return ttsi->debit_formula;
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_set_debit_formula_numeric(TTSplitInfo *ttsi, gnc_numeric debit)
|
|
{
|
|
g_return_if_fail(ttsi);
|
|
|
|
if (ttsi->debit_formula)
|
|
{
|
|
g_free(ttsi->debit_formula);
|
|
}
|
|
ttsi->debit_formula = gnc_numeric_to_string(debit);
|
|
|
|
if (ttsi->credit_formula)
|
|
{
|
|
g_free(ttsi->credit_formula);
|
|
ttsi->credit_formula = NULL;
|
|
}
|
|
return;
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_set_debit_formula(TTSplitInfo *ttsi, const char *debit_formula)
|
|
{
|
|
g_return_if_fail(ttsi);
|
|
|
|
if (ttsi->debit_formula)
|
|
g_free(ttsi->debit_formula);
|
|
|
|
ttsi->debit_formula = g_strdup(debit_formula);
|
|
|
|
if (ttsi->credit_formula)
|
|
{
|
|
g_free(ttsi->credit_formula);
|
|
ttsi->credit_formula = NULL;
|
|
}
|
|
return;
|
|
}
|
|
|
|
void
|
|
gnc_ttsplitinfo_set_account(TTSplitInfo *ttsi, Account *acc)
|
|
{
|
|
g_return_if_fail(ttsi && acc);
|
|
|
|
ttsi->acc = acc;
|
|
return;
|
|
}
|
|
|
|
Account *
|
|
gnc_ttsplitinfo_get_account(TTSplitInfo *ttsi)
|
|
{
|
|
g_return_val_if_fail(ttsi, NULL);
|
|
|
|
return ttsi->acc;
|
|
}
|