Register rewrite Update, this adds the schedule option with some other changes.

This update adds the schedule option. The schedule editor files have been duplicated and used to edit the schedule with the template displaying in the tree view. This is accessed from additional menu options on the Scheduled Transactions plugin page under Schedule, New 2 and Edit 2.
Other changes are to the date renderer, FuturePostedDate function, fix the split collapse option and move some functions around.
Author: Robert Fewell

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22931 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens
2013-05-02 14:41:56 +00:00
parent 96f660eeb1
commit 4229695e81
20 changed files with 3460 additions and 997 deletions

View File

@@ -190,6 +190,7 @@ src/gnome/dialog-print-check2.c
src/gnome/dialog-print-check.c
src/gnome/dialog-progress.c
src/gnome/dialog-sx-editor.c
src/gnome/dialog-sx-editor2.c
src/gnome/dialog-sx-from-trans.c
src/gnome/dialog-sx-since-last-run.c
src/gnome/dialog-tax-info.c

View File

@@ -2216,16 +2216,13 @@ gboolean xaccTransIsReadonlyByPostedDate(const Transaction *trans)
gboolean xaccTransInFutureByPostedDate (const Transaction *trans)
{
GDate date_now;
GDate trans_date;
time64 present;
gboolean result;
g_assert(trans);
trans_date = xaccTransGetDatePostedGDate (trans);
present = gnc_time64_get_today_end ();
gnc_gdate_set_time64 (&date_now, gnc_time (NULL));
if (g_date_compare (&trans_date, &date_now) > 0)
if (trans->date_posted.tv_sec > present)
result = TRUE;
else
result = FALSE;

View File

@@ -193,6 +193,7 @@ gtk_cell_editable_key_press_event (GtkEntry *entry,
return FALSE;
gtk_entry_set_text (entry, qof_print_date (gnc_mktime (&when)));
gtk_widget_grab_focus (GTK_WIDGET (entry));
return TRUE;
}
return FALSE;
@@ -204,7 +205,9 @@ gpw_key_press_event (GtkWidget *box,
{
GncPopupEntry *widget = GNC_POPUP_ENTRY (box);
GdkEvent tmp_event;
gtk_widget_grab_focus (widget->entry);
if (key_event->keyval == GDK_Escape) {
widget->editing_canceled = TRUE;
@@ -214,7 +217,17 @@ gpw_key_press_event (GtkWidget *box,
return TRUE;
}
gtk_widget_grab_focus (widget->entry);
if (key_event->keyval == GDK_Left)
{
gtk_editable_set_position (GTK_EDITABLE (widget->entry), 0);
return TRUE;
}
if (key_event->keyval == GDK_Right)
{
gtk_editable_set_position (GTK_EDITABLE (widget->entry), -1);
return TRUE;
}
/* Hackish :/ Synthesize a key press event for the entry. */
memcpy (&tmp_event, key_event, sizeof (GdkEventKey));

View File

@@ -326,7 +326,7 @@ gnc_embedded_window_setup_window (GncEmbeddedWindow *window)
priv->menu_dock = gtk_vbox_new (FALSE, 0);
gtk_widget_show (priv->menu_dock);
gtk_box_pack_start (GTK_BOX (window), priv->menu_dock, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (window), priv->menu_dock, FALSE, TRUE, 0);
priv->statusbar = gtk_statusbar_new ();
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR(priv->statusbar), FALSE);

View File

@@ -527,85 +527,6 @@ gnc_tree_control_split_reg_exchange_rate (GncTreeViewSplitReg *view)
}
#ifdef skip
/**
* Schedules the current transaction for recurring-entry.
* If the selected transaction was created from a scheduled transaction,
* opens the editor for that Scheduled Transaction.
**/
void
gnc_tree_control_split_reg_schedule_current_trans (GncTreeViewSplitReg *view)
{
Transaction *trans;
trans = gnc_tree_view_split_reg_get_current_trans (view);
if (trans == NULL)
return;
/* See if we were asked to schedule a blank trans. */
if (trans == gnc_tree_control_split_reg_get_blank_trans (view))
return;
/* Test for read only */
if (gtc_is_trans_readonly_and_warn (view, trans))
return;
/* See if we are being edited in another register */
if (gtc_trans_test_for_edit (view, trans))
return;
/* Make sure we ask to commit any changes before we procede */
if (gtc_trans_open_and_warn (view, trans))
return;
/* If the transaction has a sched-xact KVP frame, then go to the editor
* for the existing SX; otherwise, do the sx-from-trans dialog. */
{
kvp_frame *txn_frame;
kvp_value *kvp_val;
/* set a kvp-frame element in the transaction indicating and
* pointing-to the SX this was created from. */
txn_frame = xaccTransGetSlots (trans);
if ( txn_frame != NULL )
{
kvp_val = kvp_frame_get_slot (txn_frame, "from-sched-xaction");
if (kvp_val)
{
GncGUID *fromSXId = kvp_value_get_guid (kvp_val);
SchedXaction *theSX = NULL;
GList *sxElts;
/* Get the correct SX */
for ( sxElts = gnc_book_get_schedxactions (gnc_get_current_book())->sx_list;
(!theSX) && sxElts;
sxElts = sxElts->next )
{
SchedXaction *sx = (SchedXaction*)sxElts->data;
theSX =
( ( guid_equal (xaccSchedXactionGetGUID (sx), fromSXId))
? sx : NULL );
}
if (theSX)
{
gnc_ui_scheduled_xaction_editor_dialog_create (theSX, FALSE);
return;
}
}
}
}
gnc_sx_create_from_trans(pending_trans);
}
#endif
/* Void current transaction */
void
gnc_tree_control_split_reg_void_current_trans (GncTreeViewSplitReg *view, const char *reason)
@@ -2049,6 +1970,9 @@ gnc_tree_control_split_reg_sort_changed_cb (GtkTreeSortable *sortable, gpointer
gconf_section = gnc_tree_view_get_gconf_section (GNC_TREE_VIEW (view));
gnc_gconf_set_int (gconf_section, "sort_depth", view->sort_depth, NULL);
/* scroll when view idle */
g_idle_add ((GSourceFunc) gnc_tree_view_split_reg_scroll_to_cell, view);
LEAVE("sort_col %d, sort_direction is %d sort_depth is %d", view->sort_col, view->sort_direction, view->sort_depth );
}

View File

@@ -94,35 +94,24 @@ static void update_completion_models (GncTreeModelSplitReg *model);
/** The instance private data for the split register tree model. */
struct GncTreeModelSplitRegPrivate
{
QofBook *book; // GNC Book
Account *anchor; // Account of register
QofBook *book; // GNC Book
Account *anchor; // Account of register
GList *tlist; // List of unique transactions derived from the query slist in same order
GList *tlist; // List of unique transactions derived from the query slist in same order
Transaction *btrans; // The Blank transaction
Transaction *btrans; // The Blank transaction
Split *bsplit; // The Blank split
GList *bsplit_node; // never added to any list, just for representation of the iter
GList *bsplit_parent_node; // this equals the tnode of the transaction with the blank split
Split *bsplit; // The Blank split
GList *bsplit_node; // never added to any list, just for representation of the iter
GList *bsplit_parent_node; // this equals the tnode of the transaction with the blank split
gboolean display_subacc; // Are we displaying subaccounts
gboolean display_gl; // Is this the General ledger
gboolean display_subacc; // Are we displaying subaccounts
gboolean display_gl; // Is this the General ledger
const GncGUID *template_account; // The template account which template transaction should belong to
/* vvvv ### This is stuff I have dumped here from old reg #### vvvv */
/* The template account which template transaction should belong to */
GncGUID template_account;
/* User data for users of SplitRegisters */
gpointer user_data; //FIXME This is used to get parent window, maybe move to view
/* hook to get parent widget */
SRGetParentCallback2 get_parent; //FIXME This is used to get parent window, maybe move to view
/* ^^^^ #### This is stuff I have dumped here from old reg #### ^^^^ */
gpointer user_data; // User data for users of SplitRegisters, used to get parent window
SRGetParentCallback2 get_parent; // hook to get parent widget, used to get parent window
GtkListStore *description_list; // description field autocomplete list
GtkListStore *notes_list; // notes field autocomplete list
@@ -495,10 +484,9 @@ gnc_tree_model_split_reg_new (SplitRegisterType2 reg_type, SplitRegisterStyle2 s
return model;
}
/* ForEach function to remove all model entries */
/* ForEach function to walk the list of model entries */
static gboolean
gtm_remove_foreach_func (GtkTreeModel *model,
gtm_split_reg_foreach_func (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
GList **rowref_list)
@@ -513,6 +501,39 @@ gtm_remove_foreach_func (GtkTreeModel *model,
}
/* Emit change signal for all visable model entries */
void
gnc_tree_model_split_reg_change_vis_rows (GncTreeModelSplitReg *model, GtkTreePath *start_path, GtkTreePath *end_path)
{
GList *rr_list = NULL; /* list of GtkTreeRowReferences */
GList *node;
GtkTreeIter iter;
gtk_tree_model_foreach (GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc)gtm_split_reg_foreach_func, &rr_list);
for ( node = rr_list; node != NULL; node = node->next )
{
GtkTreePath *path;
path = gtk_tree_row_reference_get_path ((GtkTreeRowReference*)node->data);
if ((path) && gnc_tree_model_split_reg_get_iter (GTK_TREE_MODEL (model), &iter, path))
{
PINFO("path is - '%s'", gtk_tree_path_to_string (path));
// Only emit change if path > start_path and < end_path
if ((gtk_tree_path_compare (path, end_path) == -1) && (gtk_tree_path_compare (start_path, path) == -1))
{
PINFO("row_changed at path - '%s'", gtk_tree_path_to_string (path));
gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
}
gtk_tree_path_free (path);
}
}
g_list_foreach (rr_list, (GFunc) gtk_tree_row_reference_free, NULL);
g_list_free (rr_list);
}
/* Remove all model entries */
static void
gtm_remove_all_rows (GncTreeModelSplitReg *model)
@@ -520,7 +541,7 @@ gtm_remove_all_rows (GncTreeModelSplitReg *model)
GList *rr_list = NULL; /* list of GtkTreeRowReferences to remove */
GList *node;
gtk_tree_model_foreach (GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc)gtm_remove_foreach_func, &rr_list);
gtk_tree_model_foreach (GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc)gtm_split_reg_foreach_func, &rr_list);
rr_list = g_list_reverse (rr_list);
@@ -573,15 +594,36 @@ gnc_tree_model_split_reg_load (GncTreeModelSplitReg *model, GList *slist, Accoun
}
/*FIXME Not sure about this */
/* Set the template account for this register. */
void
gnc_tree_model_split_reg_set_template_account (GncTreeModelSplitReg *model, Account *template_account)
{
GncTreeModelSplitRegPrivate *priv;
//g_print("gnc_tree_model_split_reg_set_template_account\n");
priv = model->priv;
priv->template_account = *xaccAccountGetGUID (template_account);
priv->template_account = xaccAccountGetGUID (template_account);
}
/* Return the template account for this register. */
Account *
gnc_tree_model_split_reg_get_template_account (GncTreeModelSplitReg *model)
{
GncTreeModelSplitRegPrivate *priv;
Account *acct;
priv = model->priv;
acct = xaccAccountLookup (priv->template_account, priv->book);
return acct;
}
/* Return TRUE if this is a template register. */
gboolean
gnc_tree_model_split_reg_get_template (GncTreeModelSplitReg *model)
{
return model->is_template;
}
@@ -1749,6 +1791,26 @@ gnc_tree_model_split_reg_get_split_and_trans (
return TRUE;
}
/* Return TRUE if blank_split is on trans */
gboolean
gnc_tree_model_split_reg_is_blank_split_parent (GncTreeModelSplitReg *model, Transaction *trans)
{
GncTreeModelSplitRegPrivate *priv;
GList *node;
priv = model->priv;
node = priv->bsplit_parent_node;
if (node == NULL)
return FALSE;
if (trans == priv->bsplit_parent_node->data)
return TRUE;
else
return FALSE;
}
/* Return the tree path of trans and split
if trans and split NULL, return last in list */
@@ -2838,9 +2900,14 @@ gnc_tree_model_split_reg_event_handler (QofInstance *entity,
if (!g_list_find (priv->tlist, trans) && priv->display_gl)
{
DEBUG("Insert trans %p for gl (%s)", trans, name);
gtm_insert_trans (model, trans);
g_signal_emit_by_name (model, "refresh_trans", trans);
gnc_commodity *split_com;
split_com = xaccAccountGetCommodity (acc);
if (!g_strcmp0 (gnc_commodity_get_namespace (split_com), "template") == 0)
{
DEBUG("Insert trans %p for gl (%s)", trans, name);
gtm_insert_trans (model, trans);
g_signal_emit_by_name (model, "refresh_trans", trans);
}
}
else if (!g_list_find (priv->tlist, trans) && ((xaccAccountHasAncestor (acc, priv->anchor) && priv->display_subacc) || acc == priv->anchor ))
{

View File

@@ -121,7 +121,7 @@ typedef struct
SplitRegisterStyle2 style; /**<FIXME ? This may be the wrong place for these, may be the view ? */
gboolean use_double_line; /**<FIXME ? As above, whether to use two lines per transaction */
gboolean is_template;
gboolean is_template; /**< Are we using a template */
gboolean use_accounting_labels; /**< whether to use accounting Labels */
gboolean separator_changed; /**< whether the separator has changed */
@@ -134,7 +134,6 @@ typedef struct
time64 filter_start_time; // Start time for Filter.
time64 filter_end_time; // End time for Filter.
}GncTreeModelSplitReg;
@@ -178,9 +177,15 @@ gnc_tree_model_split_reg_new (SplitRegisterType2 reg_type, SplitRegisterStyle2 s
/** Load the model from a slist and set default account for register. */
void gnc_tree_model_split_reg_load (GncTreeModelSplitReg *model, GList * slist, Account *default_account);
/** FIXME Not sure what this is for yet. */
/** Sets the template account. */
void gnc_tree_model_split_reg_set_template_account (GncTreeModelSplitReg *model, Account *template_account);
/** Returns the template account. */
Account * gnc_tree_model_split_reg_get_template_account (GncTreeModelSplitReg *model);
/** Return TRUE if this is a template register. */
gboolean gnc_tree_model_split_reg_get_template (GncTreeModelSplitReg *model);
/** Destroy the model. */
void gnc_tree_model_split_reg_destroy (GncTreeModelSplitReg *model);
@@ -237,6 +242,9 @@ gboolean gnc_tree_model_split_reg_set_blank_split_parent (
/* Return the blank split */
Split * gnc_tree_model_split_get_blank_split (GncTreeModelSplitReg *model);
/* Return TRUE if blank_split is on trans */
gboolean gnc_tree_model_split_reg_is_blank_split_parent (GncTreeModelSplitReg *model, Transaction *trans);
/* Return the blank trans */
Transaction * gnc_tree_model_split_get_blank_trans (GncTreeModelSplitReg *model);
@@ -265,6 +273,10 @@ GtkTreePath * gnc_tree_model_split_reg_get_path_to_split_and_trans (
/* Returns TRUE if iter is a blank transaction */
gboolean gnc_tree_model_split_reg_is_blank_trans (GncTreeModelSplitReg *model, GtkTreeIter *iter);
/* Emit change signal for all visable model entries */
void gnc_tree_model_split_reg_change_vis_rows (GncTreeModelSplitReg *model,
GtkTreePath *start_path, GtkTreePath *end_path);
/*****************************************************************************/
G_END_DECLS

View File

@@ -236,6 +236,45 @@ gtu_split_reg_handle_exchange_rate (GncTreeViewSplitReg *view, gnc_numeric amoun
}
/* Returns the value denom */
static int
gtu_split_reg_get_value_denom (Split *split)
{
gnc_commodity *currency;
int denom;
currency = xaccTransGetCurrency (xaccSplitGetParent (split));
denom = gnc_commodity_get_fraction (currency);
if (denom == 0)
{
gnc_commodity *commodity = gnc_default_currency ();
denom = gnc_commodity_get_fraction (commodity);
if (denom == 0)
denom = 100;
}
return denom;
}
/* Returns the amount denom */
static int
gtu_split_reg_get_amount_denom (Split *split)
{
int denom;
denom = xaccAccountGetCommoditySCU (xaccSplitGetAccount (split));
if (denom == 0)
{
gnc_commodity *commodity = gnc_default_currency ();
denom = gnc_commodity_get_fraction (commodity);
if (denom == 0)
denom = 100;
}
return denom;
}
/*###########################################################################*/
@@ -353,7 +392,58 @@ gnc_tree_util_split_reg_get_transfer_entry (Split *split, gboolean *is_multi)
}
/* Return the string entry for transfer column when template */
const char *
gnc_tree_util_split_reg_template_get_transfer_entry (Split *split)
{
static char *name = NULL;
kvp_frame *kvpf;
if (!split)
return NULL;
kvpf = xaccSplitGetSlots (split);
g_free (name);
if (kvpf)
{
Account *account;
GncGUID *guid;
guid = kvp_value_get_guid(
kvp_frame_get_slot_path (kvpf, "sched-xaction", "account", NULL));
account = xaccAccountLookup (guid, gnc_get_current_book ());
name = account ? gnc_get_account_name_for_register (account) : NULL;
}
else
name = NULL;
return name;
}
const char *
gnc_tree_util_split_reg_template_get_fdebt_entry (Split *split)
{
kvp_frame *kvpf = xaccSplitGetSlots (split);
return kvp_value_get_string(
kvp_frame_get_slot_path (kvpf, "sched-xaction", "debit-formula", NULL));
}
const char *
gnc_tree_util_split_reg_template_get_fcred_entry (Split *split)
{
kvp_frame *kvpf = xaccSplitGetSlots (split);
return kvp_value_get_string(
kvp_frame_get_slot_path (kvpf, "sched-xaction", "credit-formula", NULL));
}
@@ -766,7 +856,345 @@ gnc_tree_util_split_reg_save_amount_values (GncTreeViewSplitReg *view, Transacti
/* Takes the input with column and sets the price / amount / value so they are consistent */
void
gnc_tree_util_set_number_for_input (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gnc_numeric input, gint viewcol)
{
GncTreeModelSplitReg *model;
gnc_numeric price;
gnc_numeric amount;
gnc_numeric value;
gboolean price_changed = FALSE; // Price of each share
gboolean value_changed = FALSE; // Total value of shares
gboolean amount_changed = FALSE; // No of shares
gboolean recalc_amount = FALSE;
gboolean recalc_price = FALSE;
gboolean recalc_value = FALSE;
gboolean expanded = FALSE;
int denom;
Account *account;
ENTER("trans %p and split %p and input is %s and viewcol is %d", trans, split, gnc_numeric_to_string (input), viewcol);
model = gnc_tree_view_split_reg_get_model_from_view (view);
account = gnc_tree_model_split_reg_get_anchor (model);
expanded = gnc_tree_view_split_reg_trans_expanded (view, trans);
if (!account)
account = xaccSplitGetAccount (split);
if (!xaccAccountIsPriced (account))
return;
/* If we are using commodity trading accounts then the value may
not really be the value. Punt if so. */
if (xaccTransUseTradingAccounts (xaccSplitGetParent (split)))
{
gnc_commodity *acc_commodity;
acc_commodity = xaccAccountGetCommodity (account);
if (!(xaccAccountIsPriced (account) || !gnc_commodity_is_iso (acc_commodity)))
return;
}
if (gnc_numeric_zero_p (input))
{
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, input);
LEAVE("zero");
return;
}
amount = xaccSplitGetAmount (split);
value = xaccSplitGetValue (split);
if (viewcol == COL_AMTVAL && !expanded)
{
value_changed = TRUE;
if (gnc_numeric_zero_p (amount))
{
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, input);
LEAVE("");
return;
}
}
else if (viewcol == COL_AMTVAL && expanded)
{
amount_changed = TRUE;
if (gnc_numeric_zero_p (value))
{
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, input);
LEAVE("");
return;
}
}
if (viewcol == COL_PRICE)
{
price_changed = TRUE;
if (gnc_numeric_zero_p (value))
{
amount = gnc_numeric_create (1,1);
value = gnc_numeric_mul (input, amount, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, amount);
LEAVE("");
return;
}
}
if ((viewcol == COL_CREDIT || viewcol == COL_DEBIT) && !expanded)
{
amount_changed = TRUE;
if (gnc_numeric_zero_p (value))
{
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, input);
LEAVE("");
return;
}
}
else if ((viewcol == COL_CREDIT || viewcol == COL_DEBIT) && expanded)
{
value_changed = TRUE;
if (gnc_numeric_zero_p (value))
{
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, input);
LEAVE("");
return;
}
}
DEBUG("value_changed %d, price_changed %d, amount_changed %d", value_changed, price_changed, amount_changed);
{
int choice;
int default_value;
GList *node;
GList *radio_list = NULL;
const char *title = _("Recalculate Transaction");
const char *message = _("The values entered for this transaction "
"are inconsistent. Which value would you "
"like to have recalculated?");
if (amount_changed)
radio_list = g_list_append (radio_list,
g_strdup_printf ("%s (%s)",
_("_Shares"), _("Changed")));
else
radio_list = g_list_append (radio_list, g_strdup (_("_Shares")));
if (price_changed)
radio_list = g_list_append (radio_list,
g_strdup_printf ("%s (%s)",
_("_Price"), _("Changed")));
else
radio_list = g_list_append (radio_list, g_strdup (_("_Price")));
if (value_changed)
radio_list = g_list_append (radio_list,
g_strdup_printf ("%s (%s)",
_("_Value"), _("Changed")));
else
radio_list = g_list_append (radio_list, g_strdup (_("_Value")));
if (price_changed)
default_value = 0; /* change the amount / shares */
else
default_value = 1; /* change the value */
choice = gnc_choose_radio_option_dialog
(gnc_tree_view_split_reg_get_parent (view),
title,
message,
_("_Recalculate"),
default_value,
radio_list);
for (node = radio_list; node; node = node->next)
g_free (node->data);
g_list_free (radio_list);
switch (choice)
{
case 0: /* Modify number of shares */
recalc_amount = TRUE;
break;
case 1: /* Modify the share price */
recalc_price = TRUE;
break;
case 2: /* Modify total value */
recalc_value = TRUE;
break;
default: /* Cancel */
LEAVE(" " );
return;
}
}
DEBUG("recalc_value %d, recalc_price %d, recalc_amount %d", recalc_value, recalc_price, recalc_amount);
if (recalc_amount)
{
denom = gtu_split_reg_get_amount_denom (split);
if (amount_changed)
{
LEAVE("");
return;
}
if (price_changed)
price = input;
else
price = gnc_numeric_div (value, amount, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
if (value_changed)
{
xaccSplitSetValue (split, input);
amount = gnc_numeric_div (input, price, denom, GNC_HOW_RND_ROUND_HALF_UP);
xaccSplitSetAmount (split, amount);
}
else
{
amount = gnc_numeric_div (value, price, denom, GNC_HOW_RND_ROUND_HALF_UP);
xaccSplitSetAmount (split, amount);
}
}
if (recalc_price)
{
if (price_changed)
{
LEAVE("");
return;
}
if (amount_changed)
{
xaccSplitSetAmount (split, input);
xaccSplitSetValue (split, value);
}
if (value_changed)
{
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, amount);
}
}
if (recalc_value)
{
denom = gtu_split_reg_get_value_denom (split);
if (value_changed)
{
LEAVE("");
return;
}
if (price_changed)
price = input;
else
price = gnc_numeric_div (value, amount, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
if (amount_changed)
{
xaccSplitSetAmount (split, input);
value = gnc_numeric_mul (input, price, denom, GNC_HOW_RND_ROUND_HALF_UP);
xaccSplitSetValue (split, value);
}
else
{
value = gnc_numeric_mul (amount, price, denom, GNC_HOW_RND_ROUND_HALF_UP);
xaccSplitSetValue (split, value);
}
}
/* If the number of splits is two, change other split to balance */
if (!gnc_tree_util_split_reg_is_multi (split) && expanded)
{
Split *osplit;
gnc_commodity *osplit_com;
osplit = xaccSplitGetOtherSplit (split);
value = xaccSplitGetValue (split);
osplit_com = xaccAccountGetCommodity (xaccSplitGetAccount (osplit));
if (gnc_commodity_is_currency (osplit_com))
{
xaccSplitSetValue (osplit, gnc_numeric_neg (value));
xaccSplitSetAmount (osplit, gnc_numeric_neg (value));
}
}
LEAVE("");
}
/* Set the value for the given input amount */
void
gnc_tree_util_set_value_for_amount (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gnc_numeric input)
{
gnc_numeric split_rate;
gnc_numeric amount;
gnc_numeric value, new_value;
int denom;
ENTER("trans %p and split %p and input is %s", trans, split, gnc_numeric_to_string (input));
if (gnc_numeric_zero_p (input))
{
xaccSplitSetValue (split, input);
xaccSplitSetAmount (split, input);
LEAVE("zero");
return;
}
amount = xaccSplitGetAmount (split);
value = xaccSplitGetValue (split);
denom = gtu_split_reg_get_value_denom (split);
split_rate = gnc_numeric_div (value, amount, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
if (gnc_numeric_check (split_rate) != GNC_ERROR_OK)
split_rate = gnc_numeric_create (100,100);
new_value = gnc_numeric_mul (input, split_rate, denom, GNC_HOW_RND_ROUND_HALF_UP);
xaccSplitSetValue (split, new_value);
xaccSplitSetAmount (split, input);
LEAVE("");
}
/* Get the rate */
gnc_numeric
gnc_tree_util_get_rate_for (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gboolean is_blank)
{
gnc_numeric num;
ENTER("trans %p and split %p is_blank %d", trans, split, is_blank);
num = gnc_tree_util_split_reg_get_value_for (view, trans, split, is_blank);
//FIXME Not sure about this...
if (xaccTransUseTradingAccounts (trans))
num = gnc_numeric_div (num, xaccSplitGetValue (split), GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
else
num = gnc_numeric_div (xaccSplitGetAmount (split), num, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);
LEAVE("split %p and return num is %s", split, gnc_numeric_to_string (num));
return num;
}
/*****************************************************************************/

View File

@@ -42,6 +42,14 @@ gboolean gnc_tree_util_split_reg_needs_conv_rate (GncTreeViewSplitReg *view,
const char * gnc_tree_util_split_reg_get_transfer_entry (Split *split, gboolean *is_multi);
const char * gnc_tree_util_split_reg_template_get_transfer_entry (Split *split);
const char * gnc_tree_util_split_reg_template_get_fdebt_entry (Split *split);
const char * gnc_tree_util_split_reg_template_get_fcred_entry (Split *split);
gboolean gnc_tree_util_split_reg_is_multi (Split *split);
gboolean gnc_tree_util_split_reg_needs_amount (GncTreeViewSplitReg *view, Split *split);
@@ -61,8 +69,14 @@ gboolean gnc_tree_util_split_reg_get_debcred_entry (GncTreeViewSplitReg *view,
gboolean is_blank,gnc_numeric *ret_num,
GNCPrintAmountInfo *ret_print_info);
void gnc_tree_util_set_number_for_input (GncTreeViewSplitReg *view, Transaction *trans,
Split *split, gnc_numeric input, gint viewcol);
void gnc_tree_util_set_value_for_amount (GncTreeViewSplitReg *view, Transaction *trans,
Split *split, gnc_numeric input);
gnc_numeric gnc_tree_util_get_rate_for (GncTreeViewSplitReg *view, Transaction *trans,
Split *split, gboolean is_blank);
/*****************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@@ -162,6 +162,9 @@ gboolean gnc_tree_view_split_reg_scroll_to_cell (GncTreeViewSplitReg *view);
void gnc_tree_view_split_reg_refilter (GncTreeViewSplitReg *view);
/* Change all visable view entries */
void gnc_tree_view_split_reg_change_vis_rows (GncTreeViewSplitReg *view);
/*************************************************************************************/
void gnc_tree_view_split_reg_delete_current_split (GncTreeViewSplitReg *view);

View File

@@ -41,6 +41,7 @@ libgnc_gnome_la_SOURCES = \
dialog-print-check2.c \
dialog-progress.c \
dialog-sx-editor.c \
dialog-sx-editor2.c \
dialog-sx-from-trans.c \
dialog-sx-since-last-run.c \
dialog-tax-info.c \
@@ -85,6 +86,7 @@ noinst_HEADERS = \
dialog-print-check2.h \
dialog-progress.h \
dialog-sx-editor.h \
dialog-sx-editor2.h \
dialog-sx-from-trans.h \
dialog-sx-since-last-run.h \
gnc-budget-view.h \

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,50 @@
/********************************************************************\
* dialog-sx-editor2.h : dialog for scheduled transaction editing *
* Copyright (C) 2001,2006 Joshua Sled <jsled@asynchronous.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of version 2 and/or version 3 of the *
* GNU General Public License as published by the Free Software *
* Foundation. *
* *
* 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 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
\********************************************************************/
#ifndef DIALOG_SX_EDITOR2_H
#define DIALOG_SX_EDITOR2_H
#include "SchedXaction.h"
#define DIALOG_SCHEDXACTION2_CM_CLASS "dialog-scheduledtransactions"
#define DIALOG_SCHEDXACTION2_EDITOR_CM_CLASS "dialog-scheduledtransaction-editor"
#define SXED_GCONF_SECTION "dialogs/scheduled_trans/transaction_editor"
#define KEY_CREATE_AUTO "create_auto"
#define KEY_NOTIFY "notify"
#define KEY_CREATE_DAYS "create_days"
#define KEY_REMIND_DAYS "remind_days"
typedef struct _GncSxEditorDialog2 GncSxEditorDialog2;
GncSxEditorDialog2* gnc_ui_scheduled_xaction_editor_dialog_create2 (SchedXaction *sx,
gboolean newSX);
void gnc_ui_scheduled_xaction_editor_dialog_destroy2 (GncSxEditorDialog2 *sxd);
/**
* Sets up a book opened hook. The function called may open a "since
* last run" dialog based upon the user's preferences.
**/
void gnc_ui_sx_initialize2 (void);
#endif

View File

@@ -44,8 +44,10 @@
#include "gnc-ui-util.h"
#include "Query.h"
#include "qof.h"
#include "gnc-ledger-display.h"
#include "gnc-plugin-page-register.h"
/*################## Added for Reg2 #################*/
#include "gnc-ledger-display2.h"
#include "gnc-plugin-page-register2.h"
/*################## Added for Reg2 #################*/
#include "gnc-main-window.h"
#include "gnc-component-manager.h"
#include "gnc-gconf-utils.h"
@@ -1004,7 +1006,7 @@ gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances, GList *auto_cr
static void
_show_created_transactions(GncSxSinceLastRunDialog *app_dialog, GList *created_txn_guids)
{
GNCLedgerDisplay *ledger;
GNCLedgerDisplay2 *ledger;
GncPluginPage *page;
Query *book_query, *guid_query, *query;
GList *guid_iter;
@@ -1017,11 +1019,12 @@ _show_created_transactions(GncSxSinceLastRunDialog *app_dialog, GList *created_t
xaccQueryAddGUIDMatch(guid_query, (GncGUID*)guid_iter->data, GNC_ID_TRANS, QOF_QUERY_OR);
}
query = qof_query_merge(book_query, guid_query, QOF_QUERY_AND);
/*################## Added for Reg2 #################*/
// inspired by dialog-find-transactions:do_find_cb:
ledger = gnc_ledger_display_query(query, SEARCH_LEDGER, REG_STYLE_JOURNAL);
gnc_ledger_display_refresh(ledger);
page = gnc_plugin_page_register_new_ledger(ledger);
ledger = gnc_ledger_display2_query(query, SEARCH_LEDGER2, REG2_STYLE_JOURNAL);
gnc_ledger_display2_refresh(ledger);
page = gnc_plugin_page_register2_new_ledger(ledger);
/*################## Added for Reg2 #################*/
g_object_set(G_OBJECT(page), "page-name", _("Created Transactions"), NULL);
gnc_main_window_open_page(NULL, page);

View File

@@ -61,6 +61,9 @@
#include "dialog-utils.h"
#include "SX-book.h"
#include "dialog-sx-editor.h"
/*################## Added for Reg2 #################*/
#include "dialog-sx-editor2.h"
/*################## Added for Reg2 #################*/
#include "dialog-sx-from-trans.h"
#include "assistant-stock-split.h"
#include "gnc-gconf-utils.h"
@@ -79,7 +82,6 @@
#include "gnc-window.h"
#include "gnc-main-window.h"
#include "gnc-session.h"
#include "gnucash-sheet.h"
#include "dialog-lot-viewer.h"
#include "Scrub.h"
#include "qof.h"
@@ -1120,11 +1122,9 @@ gnc_plugin_page_register2_create_widget (GncPluginPage *plugin_page)
gnc_ppr_update_date_filter (page, FALSE);
}
// gnc_ledger_display2_refresh (priv->ledger);
/* This sets the default selection on load */
gnc_tree_view_split_reg_default_selection (view);
/* This sets the default selection on load, not required for templates */
if (!gnc_tree_model_split_reg_get_template (model))
gnc_tree_view_split_reg_default_selection (view);
plugin_page->summarybar = gsr2_create_summary_bar(priv->gsr);
if (plugin_page->summarybar)
@@ -3059,7 +3059,7 @@ gnc_plugin_page_register2_cmd_style_double_line (GtkToggleAction *action,
ENTER("(action %p, plugin_page %p)", action, plugin_page);
g_return_if_fail (GTK_IS_ACTION(action));
g_return_if_fail (GTK_IS_ACTION (action));
g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER2 (plugin_page));
priv = GNC_PLUGIN_PAGE_REGISTER2_GET_PRIVATE (plugin_page);
@@ -3074,6 +3074,10 @@ gnc_plugin_page_register2_cmd_style_double_line (GtkToggleAction *action,
// This will re-display the view.
gnc_tree_view_split_reg_set_format (view);
// This will update the row colors in anything but ledgers
if (model->style != REG2_STYLE_LEDGER)
gnc_tree_view_split_reg_change_vis_rows (view);
}
LEAVE(" ");
}
@@ -3506,7 +3510,7 @@ gnc_plugin_page_register2_cmd_schedule (GtkAction *action,
if (theSX)
{
gnc_ui_scheduled_xaction_editor_dialog_create (theSX, FALSE);
gnc_ui_scheduled_xaction_editor_dialog_create2 (theSX, FALSE);
LEAVE(" ");
return;
}

View File

@@ -52,6 +52,9 @@
#include "Split.h"
#include "Transaction.h"
#include "dialog-sx-editor.h"
/*################## Added for Reg2 #################*/
#include "dialog-sx-editor2.h"
/*################## Added for Reg2 #################*/
#include "dialog-utils.h"
#include "gnc-commodity.h"
#include "gnc-component-manager.h"
@@ -116,6 +119,10 @@ static void gppsl_row_activated_cb(GtkTreeView *tree_view, GtkTreePath *path, Gt
static void gnc_plugin_page_sx_list_cmd_new(GtkAction *action, GncPluginPageSxList *page);
static void gnc_plugin_page_sx_list_cmd_edit(GtkAction *action, GncPluginPageSxList *page);
/*################## Added for Reg2 #################*/
static void gnc_plugin_page_sx_list_cmd_new2(GtkAction *action, GncPluginPageSxList *page);
static void gnc_plugin_page_sx_list_cmd_edit2(GtkAction *action, GncPluginPageSxList *page);
/*################## Added for Reg2 #################*/
static void gnc_plugin_page_sx_list_cmd_delete(GtkAction *action, GncPluginPageSxList *page);
/* Command callbacks */
@@ -126,10 +133,22 @@ static GtkActionEntry gnc_plugin_page_sx_list_actions [] =
"SxListNewAction", GNC_STOCK_NEW_ACCOUNT, N_("_New"), NULL,
N_("Create a new scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_new)
},
/*################## Added for Reg2 #################*/
{
"SxListNewAction2", GNC_STOCK_NEW_ACCOUNT, N_("_New 2"), NULL,
N_("Create a new scheduled transaction 2"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_new2)
},
/*################## Added for Reg2 #################*/
{
"SxListEditAction", GNC_STOCK_EDIT_ACCOUNT, N_("_Edit"), NULL,
N_("Edit the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_edit)
},
/*################## Added for Reg2 #################*/
{
"SxListEditAction2", GNC_STOCK_EDIT_ACCOUNT, N_("_Edit 2"), NULL,
N_("Edit the selected scheduled transaction 2"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_edit2)
},
/*################## Added for Reg2 #################*/
{
"SxListDeleteAction", GNC_STOCK_DELETE_ACCOUNT, N_("_Delete"), NULL,
N_("Delete the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_delete)
@@ -562,6 +581,29 @@ gnc_plugin_page_sx_list_cmd_new(GtkAction *action, GncPluginPageSxList *page)
gnc_ui_scheduled_xaction_editor_dialog_create(new_sx, new_sx_flag);
}
/*################## Added for Reg2 #################*/
static void
gnc_plugin_page_sx_list_cmd_new2 (GtkAction *action, GncPluginPageSxList *page)
{
SchedXaction *new_sx;
gboolean new_sx_flag = TRUE;
new_sx = xaccSchedXactionMalloc (gnc_get_current_book());
{
GDate now;
Recurrence *r = g_new0 (Recurrence, 1);
GList *schedule;
g_date_clear (&now, 1);
gnc_gdate_set_today (&now);
recurrenceSet(r, 1, PERIOD_MONTH, &now, WEEKEND_ADJ_NONE);
schedule = gnc_sx_get_schedule (new_sx);
schedule = g_list_append (schedule, r);
gnc_sx_set_schedule (new_sx, schedule);
}
gnc_ui_scheduled_xaction_editor_dialog_create2 (new_sx, new_sx_flag);
}
/*################## Added for Reg2 #################*/
static void
_edit_sx(gpointer data, gpointer user_data)
@@ -569,6 +611,13 @@ _edit_sx(gpointer data, gpointer user_data)
gnc_ui_scheduled_xaction_editor_dialog_create((SchedXaction*)data, FALSE);
}
/*################## Added for Reg2 #################*/
static void
_edit_sx2 (gpointer data, gpointer user_data)
{
gnc_ui_scheduled_xaction_editor_dialog_create2 ((SchedXaction*)data, FALSE);
}
/*################## Added for Reg2 #################*/
static SchedXaction*
_argument_reorder_fn(GtkTreePath* list_path_data, GncTreeViewSxList* user_tree_view)
@@ -602,6 +651,33 @@ gnc_plugin_page_sx_list_cmd_edit(GtkAction *action, GncPluginPageSxList *page)
g_list_free(selected_paths);
}
/*################## Added for Reg2 #################*/
static void
gnc_plugin_page_sx_list_cmd_edit2 (GtkAction *action, GncPluginPageSxList *page)
{
GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE (page);
GtkTreeSelection *selection;
GList *selected_paths, *to_edit;
GtkTreeModel *model;
selection = gtk_tree_view_get_selection (priv->tree_view);
selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
if (g_list_length (selected_paths) == 0)
{
g_warning ("no selection edit.");
return;
}
to_edit = gnc_g_list_map (selected_paths,
(GncGMapFunc)_argument_reorder_fn,
priv->tree_view);
g_list_foreach(to_edit, (GFunc)_edit_sx2, NULL);
g_list_free (to_edit);
g_list_foreach (selected_paths, (GFunc)gtk_tree_path_free, NULL);
g_list_free (selected_paths);
}
/*################## Added for Reg2 #################*/
static void
gppsl_row_activated_cb(GtkTreeView *tree_view,

View File

@@ -281,7 +281,7 @@ gsr2_create_table (GNCSplitReg2 *gsr)
gnc_tree_view_configure_columns (GNC_TREE_VIEW (view));
if (ledger_type == LD2_GL)
if (ledger_type == LD2_GL && model->type == GENERAL_LEDGER2)
gnc_tree_view_set_show_column_menu (GNC_TREE_VIEW (view), TRUE);
else
gnc_tree_view_set_show_column_menu (GNC_TREE_VIEW (view), FALSE);

View File

@@ -3,7 +3,9 @@
<placeholder name="AdditionalMenusPlaceholder">
<menu action="SxListAction">
<menuitem name="SxListNew" action="SxListNewAction"/>
<menuitem name="SxListNew2" action="SxListNewAction2"/>
<menuitem name="SxListEdit" action="SxListEditAction"/>
<menuitem name="SxListEdit2" action="SxListEditAction2"/>
<menuitem name="SxListDelete" action="SxListDeleteAction"/>
</menu>
</placeholder>

View File

@@ -616,8 +616,11 @@ refresh_handler (GHashTable *changes, gpointer user_data)
splits = qof_query_run (ld->query);
//FIXME Not Needed ? gnc_ledger_display2_set_watches (ld, splits);
gnc_ledger_display2_refresh_internal (ld, splits);
//gconf changes come this way, we only want a full refresh for SEARCH-LEDGER2
if (ld->model->type == SEARCH_LEDGER2)
gnc_ledger_display2_refresh_internal (ld, splits);
else
gnc_tree_view_split_reg_change_vis_rows (ld->view);
LEAVE(" ");
}
@@ -912,6 +915,7 @@ gnc_ledger_display2_refresh_internal (GNCLedgerDisplay2 *ld, GList *splits)
{
/* This is used for the reloading of registers to refresh them and to update the search_ledger */
ld->loading = TRUE;
s_model = gtk_tree_view_get_model (GTK_TREE_VIEW (ld->view)); // this is the sort model
f_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (s_model)); // this is the filter model
model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (f_model)); // our model
@@ -921,13 +925,9 @@ gnc_ledger_display2_refresh_internal (GNCLedgerDisplay2 *ld, GList *splits)
g_object_ref (model);
gnc_tree_view_split_reg_block_selection (ld->view, TRUE); // This blocks the tree selection
gtk_tree_view_set_model (GTK_TREE_VIEW (ld->view), NULL); // Detach sort model from view
gnc_tree_model_split_reg_load (ld->model, splits, gnc_ledger_display2_leader (ld)); //reload splits
gtk_tree_view_set_model (GTK_TREE_VIEW (ld->view), GTK_TREE_MODEL (s_model)); // Re-attach sort model to view
gnc_tree_view_split_reg_block_selection (ld->view, FALSE); // This unblocks the tree selection
/* Set the default selection start position */