/* Is current split a security account */ static gboolean gtu_sr_use_security (GncTreeViewSplitReg *view) { RowDepth depth; Account *account = NULL; Split *split; split = gnc_tree_view_split_reg_get_current_split (view); depth = gnc_tree_view_reg_get_selected_row_depth (view); if (!split) return TRUE; if (depth != SPLIT3) return TRUE; if (!account) account = xaccSplitGetAccount (split); if (!account) return TRUE; if (xaccTransUseTradingAccounts (xaccSplitGetParent (split))) { if (!gnc_commodity_is_iso (xaccAccountGetCommodity (account))) return TRUE; } return xaccAccountIsPriced (account); }
GtkWidget * gnc_split_reg2_create_summary_bar (GNCSplitReg2 *gsr) { GtkWidget *summarybar; gsr->cleared_label = NULL; gsr->balance_label = NULL; gsr->reconciled_label = NULL; gsr->future_label = NULL; gsr->projectedminimum_label = NULL; gsr->shares_label = NULL; gsr->value_label = NULL; if (gnc_ledger_display2_type (gsr->ledger) >= LD2_SUBACCOUNT) { gsr->summarybar = NULL; return NULL; } summarybar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_set_homogeneous (GTK_BOX (summarybar), FALSE); if (!xaccAccountIsPriced(gnc_ledger_display2_leader(gsr->ledger))) { gsr->balance_label = add_summary_label (summarybar, _("Present:")); gsr->future_label = add_summary_label (summarybar, _("Future:")); gsr->cleared_label = add_summary_label (summarybar, _("Cleared:")); gsr->reconciled_label = add_summary_label (summarybar, _("Reconciled:")); gsr->projectedminimum_label = add_summary_label (summarybar, _("Projected Minimum:")); } else { gsr->shares_label = add_summary_label (summarybar, _("Shares:")); gsr->value_label = add_summary_label (summarybar, _("Current Value:")); } gsr->summarybar = summarybar; /* Force the first update */ gsr2_redraw_all_cb (NULL, gsr); return gsr->summarybar; }
static void gnc_split_register_save_amount_values (SRSaveData *sd, SplitRegister *reg) { Account *acc; gnc_numeric new_amount, convrate, amtconv, value; gnc_commodity *curr, *reg_com, *xfer_com; Account *xfer_acc; new_amount = gnc_split_register_debcred_cell_value (reg); acc = gnc_split_register_get_default_account (reg); xfer_acc = xaccSplitGetAccount (sd->split); xfer_com = xaccAccountGetCommodity (xfer_acc); reg_com = xaccAccountGetCommodity (acc); curr = xaccTransGetCurrency (sd->trans); /* First, compute the conversion rate to convert the value to the * amount. */ amtconv = convrate = gnc_split_register_get_rate_cell (reg, RATE_CELL); if (acc && gnc_split_register_needs_conv_rate (reg, sd->trans, acc)) { /* If we are in an expanded register and the xfer_acc->comm != * reg_acc->comm then we need to compute the convrate here. * Otherwise, we _can_ use the rate_cell! */ if (sd->reg_expanded && ! gnc_commodity_equal (reg_com, xfer_com)) amtconv = xaccTransGetAccountConvRate(sd->trans, acc); } if (xaccTransUseTradingAccounts (sd->trans)) { /* Using currency accounts, the amount is probably really the amount and not the value. */ gboolean is_amount; if (reg->type == STOCK_REGISTER || reg->type == CURRENCY_REGISTER || reg->type == PORTFOLIO_LEDGER) { if (xaccAccountIsPriced(xfer_acc) || !gnc_commodity_is_iso(xaccAccountGetCommodity(xfer_acc))) is_amount = FALSE; else is_amount = TRUE; } else { is_amount = TRUE; } if (is_amount) { xaccSplitSetAmount(sd->split, new_amount); if (gnc_split_register_split_needs_amount (reg, sd->split)) { value = gnc_numeric_div(new_amount, amtconv, gnc_commodity_get_fraction(curr), GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetValue(sd->split, value); } else xaccSplitSetValue(sd->split, new_amount); } else { xaccSplitSetValue(sd->split, new_amount); } return; } /* How to interpret new_amount depends on our view of this * transaction. If we're sitting in an account with the same * commodity as the transaction, then we can set the Value and then * compute the amount. Otherwise we are setting the "converted * value". This means we need to convert new_amount to the actual * 'value' by dividing by the convrate in order to set the value. */ /* Now compute/set the split value. Amount is in the register * currency but we need to convert to the txn currency. */ if (gnc_split_register_needs_conv_rate (reg, sd->trans, acc)) { /* convert the amount to the Value ... */ value = gnc_numeric_div (new_amount, amtconv, gnc_commodity_get_fraction (curr), GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetValue (sd->split, value); } else xaccSplitSetValue (sd->split, new_amount); /* Now re-compute the Amount from the Value. We may need to convert * from the Value back to the amount here using the convrate from * earlier. */ value = xaccSplitGetValue (sd->split); if (gnc_split_register_split_needs_amount (reg, sd->split)) { acc = xaccSplitGetAccount (sd->split); new_amount = gnc_numeric_mul (value, convrate, xaccAccountGetCommoditySCU (acc), GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetAmount (sd->split, new_amount); } }
static int fill_account_list (StockSplitInfo *info, Account *selected_account) { GtkTreeRowReference *reference = NULL; GtkTreeView *view; GtkListStore *list; GtkTreeIter iter; GtkTreePath *path; GList *accounts; GList *node; gint rows = 0; gchar *full_name; view = GTK_TREE_VIEW(info->account_view); list = GTK_LIST_STORE(gtk_tree_view_get_model(view)); gtk_list_store_clear (list); accounts = gnc_account_get_descendants_sorted (gnc_get_current_root_account ()); for (node = accounts; node; node = node->next) { Account *account = node->data; GNCPrintAmountInfo print_info; const gnc_commodity *commodity; gnc_numeric balance; if (!xaccAccountIsPriced(account)) continue; balance = xaccAccountGetBalance (account); if (gnc_numeric_zero_p (balance)) continue; if (xaccAccountGetPlaceholder (account)) continue; commodity = xaccAccountGetCommodity (account); full_name = gnc_account_get_full_name (account); print_info = gnc_account_print_info (account, FALSE); gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, SPLIT_COL_ACCOUNT, account, SPLIT_COL_FULLNAME, full_name, SPLIT_COL_MNEMONIC, gnc_commodity_get_mnemonic(commodity), SPLIT_COL_SHARES, xaccPrintAmount(balance, print_info), -1); if (account == selected_account) { path = gtk_tree_model_get_path(GTK_TREE_MODEL(list), &iter); reference = gtk_tree_row_reference_new(GTK_TREE_MODEL(list), path); gtk_tree_path_free(path); } g_free (full_name); rows++; } g_list_free(accounts); if (reference) { GtkTreeSelection* selection = gtk_tree_view_get_selection(view); path = gtk_tree_row_reference_get_path(reference); gtk_tree_row_reference_free(reference); if (path) { gtk_tree_selection_select_path(selection, path); gtk_tree_view_scroll_to_cell(view, path, NULL, TRUE, 0.5, 0.0); gtk_tree_path_free(path); } } return rows; }
void gnc_tree_util_split_reg_save_amount_values (GncTreeViewSplitReg *view, Transaction *trans, Split *split, gnc_numeric input) { GncTreeModelSplitReg *model; Account *acc; gnc_numeric new_amount, convrate, amtconv, value; gnc_commodity *curr, *reg_com, *xfer_com; Account *xfer_acc; ENTER("View is %p, trans is %p, split is %p, input is %s", view, trans, split, gnc_numeric_to_string (input)); model = gnc_tree_view_split_reg_get_model_from_view (view); new_amount = input; acc = gnc_tree_model_split_reg_get_anchor (model); xfer_acc = xaccSplitGetAccount (split); xfer_com = xaccAccountGetCommodity (xfer_acc); reg_com = xaccAccountGetCommodity (acc); curr = xaccTransGetCurrency (trans); if (!xaccTransGetRateForCommodity (trans, reg_com, NULL, &convrate)) convrate = gnc_numeric_create (100, 100); amtconv = convrate; if (gnc_tree_util_split_reg_needs_conv_rate (view, trans, acc)) { /* If we are in an expanded register and the xfer_acc->comm != * reg_acc->comm then we need to compute the convrate here. * Otherwise, we _can_ use the rate_cell! */ if (gnc_commodity_equal (reg_com, xfer_com)) amtconv = xaccTransGetAccountConvRate (trans, acc); } if (xaccTransUseTradingAccounts (trans)) { /* Using currency accounts, the amount is probably really the amount and not the value. */ gboolean is_amount; if (model->type == STOCK_REGISTER2 || model->type == CURRENCY_REGISTER2 || model->type == PORTFOLIO_LEDGER2) { if (xaccAccountIsPriced (xfer_acc) || !gnc_commodity_is_iso (xaccAccountGetCommodity (xfer_acc))) is_amount = FALSE; else is_amount = TRUE; } else { is_amount = TRUE; } if (is_amount) { xaccSplitSetAmount (split, new_amount); if (gnc_tree_util_split_reg_needs_amount (view, split)) { value = gnc_numeric_div (new_amount, amtconv, gnc_commodity_get_fraction (curr), GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetValue (split, value); } else xaccSplitSetValue (split, new_amount); } else { xaccSplitSetValue (split, new_amount); } LEAVE(" "); return; } /* How to interpret new_amount depends on our view of this * transaction. If we're sitting in an account with the same * commodity as the transaction, then we can set the Value and then * compute the amount. Otherwise we are setting the "converted * value". This means we need to convert new_amount to the actual * 'value' by dividing by the convrate in order to set the value. */ /* Now compute/set the split value. Amount is in the register * currency but we need to convert to the txn currency. */ if (gnc_tree_util_split_reg_needs_conv_rate (view, trans, acc)) { /* convert the amount to the Value ... */ value = gnc_numeric_div (new_amount, amtconv, gnc_commodity_get_fraction (curr), GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetValue (split, value); } else { xaccSplitSetValue (split, new_amount); } /* Now re-compute the Amount from the Value. We may need to convert * from the Value back to the amount here using the convrate from * earlier. */ value = xaccSplitGetValue (split); if (gnc_tree_util_split_reg_needs_amount (view, split)) { acc = xaccSplitGetAccount (split); new_amount = gnc_numeric_mul (value, convrate, xaccAccountGetCommoditySCU (acc), GNC_HOW_RND_ROUND_HALF_UP); xaccSplitSetAmount (split, new_amount); } else { xaccSplitSetAmount (split, value); } LEAVE(" "); }
/* 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 = NULL; 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); /* Check for sub account view */ if (!gnc_tree_model_split_reg_get_sub_account (model)) 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(expanded) { if (price_changed) default_value = 2; /* change the value */ else default_value = 1; /* change the price */ } else { if (price_changed) default_value = 0; /* change the amount / shares */ else default_value = 1; /* change the price */ } 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_sr_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_sr_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(""); }
static gpointer look_for_portfolio_cb (Account *account, gpointer data) { return xaccAccountIsPriced(account) ? (gpointer) PORTFOLIO_LEDGER : NULL; }