static const char * get_taxval_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; gnc_numeric value; /* Check if this is the current cursor */ if (virt_cell_loc_equal (ledger->table->current_cursor_loc.vcell_loc, virt_loc.vcell_loc)) { /* Sign attention: this function works with values as seen * on-screen in the ledger, so they are always in the proper sign. */ gnc_entry_ledger_compute_value (ledger, NULL, &value); } else { GncEntry *entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); if (entry == gnc_entry_ledger_get_blank_entry (ledger)) return NULL; /* Ledger should display values with the same sign as on the document * so get the document value instead of the internal value here. */ value = gncEntryGetDocTaxValue (entry, TRUE, ledger->is_cust_doc, ledger->is_credit_note); } return xaccPrintAmount (value, gnc_default_print_info (FALSE)); }
static const char * get_taxval_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; gnc_numeric value; /* Check if this is the current cursor */ if (virt_cell_loc_equal (ledger->table->current_cursor_loc.vcell_loc, virt_loc.vcell_loc)) { gnc_entry_ledger_compute_value (ledger, NULL, &value); } else { GncEntry *entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); if (entry == gnc_entry_ledger_get_blank_entry (ledger)) return NULL; value = gncEntryReturnTaxValue (entry, ledger->is_cust_doc); } /* Credit notes have negative values, but the ledger should * display it as on the document, meaning positive. * So reverse the value for credit notes. */ if (ledger->is_credit_note) value = gnc_numeric_neg (value); return xaccPrintAmount (value, gnc_default_print_info (FALSE)); }
/* Copy the values in the financial_info structure to the GUI */ static void fi_to_gui(FinCalcDialog *fcd) { const gnc_commodity *commodity; static char string[64]; gnc_numeric total; gnc_numeric npp; gnc_numeric pmt; int i; if (fcd == NULL) return; npp = gnc_numeric_create (fcd->financial_info.npp, 1); gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]), npp); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[INTEREST_RATE]), fcd->financial_info.ir); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PRESENT_VALUE]), fcd->financial_info.pv); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PERIODIC_PAYMENT]), fcd->financial_info.pmt); gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[FUTURE_VALUE]), -fcd->financial_info.fv); pmt = double_to_gnc_numeric (fcd->financial_info.pmt, 100000, GNC_HOW_RND_ROUND_HALF_UP); commodity = gnc_default_currency (); total = gnc_numeric_mul (npp, pmt, gnc_commodity_get_fraction (commodity), GNC_HOW_RND_ROUND_HALF_UP); xaccSPrintAmount (string, total, gnc_default_print_info (FALSE)); gtk_label_set_text (GTK_LABEL(fcd->payment_total_label), string); i = normalize_period(&fcd->financial_info.CF); gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->compounding_combo), i); i = normalize_period(&fcd->financial_info.PF); gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->payment_combo), i); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fcd->end_of_period_radio), !fcd->financial_info.bep); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(fcd->discrete_compounding_radio), fcd->financial_info.disc); }
static const char * get_disc_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; GncEntry *entry; gnc_numeric discount; entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); discount = gncEntryGetInvDiscount (entry); if (gnc_numeric_zero_p (discount)) return NULL; return xaccPrintAmount (discount, gnc_default_print_info (FALSE)); }
static const char * get_qty_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; GncEntry *entry; gnc_numeric qty; entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); qty = gncEntryGetDocQuantity (entry, ledger->is_credit_note); if (gnc_numeric_zero_p (qty)) return NULL; return xaccPrintAmount (qty, gnc_default_print_info (FALSE)); }
void gnc_price_cell_init (PriceCell *cell) { gnc_basic_cell_init (&(cell->cell)); cell->amount = gnc_numeric_zero (); cell->fraction = 0; cell->blank_zero = TRUE; cell->print_info = gnc_default_print_info (FALSE); cell->need_to_parse = FALSE; cell->cell.enter_cell = gnc_price_cell_enter; cell->cell.modify_verify = gnc_price_cell_modify_verify; cell->cell.leave_cell = gnc_price_cell_leave; cell->cell.set_value = gnc_price_cell_set_value_internal; }
static const char * get_value_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; gnc_numeric value; /* Credit notes need some attention here: the ledger displays values * as on the document, meaning positive for credit notes. Credit note * values are negative internally though. So depending on which values * are used to calculate the subtotal, the resulting subtotal has to be * sign-reversed before displaying. */ /* Check if this is the current cursor */ if (virt_cell_loc_equal (ledger->table->current_cursor_loc.vcell_loc, virt_loc.vcell_loc)) { gnc_entry_ledger_compute_value (ledger, &value, NULL); /* Credit note info: this function works with values as seen * on-screen in the ledger, so they are always in the proper sign. * As per the above no sign reversal is needed for * credit note type ledgers. */ } else { GncEntry *entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); if (entry == gnc_entry_ledger_get_blank_entry (ledger)) return NULL; value = gncEntryReturnValue (entry, ledger->is_cust_doc); /* Credit note info: this function works with internal values, * so they are negative for credit note type ledgers and have to * be sign-reversed as per the above. */ if (ledger->is_credit_note) value = gnc_numeric_neg (value); } return xaccPrintAmount (value, gnc_default_print_info (FALSE)); }
static const char * get_pric_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; GncEntry *entry; gnc_numeric price; entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); if (ledger->is_cust_doc) price = gncEntryGetInvPrice (entry); else price = gncEntryGetBillPrice (entry); if (gnc_numeric_zero_p (price)) return NULL; return xaccPrintAmount (price, gnc_default_print_info (FALSE)); }
static const char * get_qty_entry (VirtualLocation virt_loc, gboolean translate, gboolean *conditionally_changed, gpointer user_data) { GncEntryLedger *ledger = user_data; GncEntry *entry; gnc_numeric qty; entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc); qty = gncEntryGetQuantity (entry); if (gnc_numeric_zero_p (qty)) return NULL; /* Credit notes have negative quantities, but the ledger should * display it as on the document, meaning positive. * So reverse the quantity for credit notes. */ if (ledger->is_credit_note) qty = gnc_numeric_neg (qty); return xaccPrintAmount (qty, gnc_default_print_info (FALSE)); }
static guint sxftd_add_template_trans(SXFromTransInfo *sxfti) { Transaction *tr = sxfti->trans; GList *tt_list = NULL; GList *splits, *template_splits = NULL; TTInfo *tti = gnc_ttinfo_malloc(); TTSplitInfo *ttsi; Split *sp; gnc_numeric runningBalance; gnc_numeric split_value; const char *tmpStr; runningBalance = gnc_numeric_zero(); gnc_ttinfo_set_description(tti, xaccTransGetDescription(tr)); gnc_ttinfo_set_num(tti, gnc_get_num_action(tr, NULL)); gnc_ttinfo_set_currency(tti, xaccTransGetCurrency(tr)); for (splits = xaccTransGetSplitList(tr); splits; splits = splits->next) { sp = splits->data; ttsi = gnc_ttsplitinfo_malloc(); gnc_ttsplitinfo_set_action(ttsi, gnc_get_num_action(NULL, sp)); split_value = xaccSplitGetValue(sp); gnc_ttsplitinfo_set_memo(ttsi, xaccSplitGetMemo(sp)); runningBalance = gnc_numeric_add( runningBalance, split_value, 100, (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); if (gnc_numeric_positive_p(split_value)) { tmpStr = xaccPrintAmount( split_value, gnc_default_print_info(FALSE) ); gnc_ttsplitinfo_set_debit_formula( ttsi, tmpStr ); } else { /* Negate the numeric so it prints w/o the sign at the front. */ tmpStr = xaccPrintAmount( gnc_numeric_neg( split_value ), gnc_default_print_info(FALSE) ); gnc_ttsplitinfo_set_credit_formula( ttsi, tmpStr ); } /* Copy over per-split account info */ gnc_ttsplitinfo_set_account( ttsi, xaccSplitGetAccount( sp ) ); template_splits = g_list_append(template_splits, ttsi); } if ( ! gnc_numeric_zero_p( runningBalance ) && !gnc_verify_dialog( (GtkWidget *)sxfti->dialog, FALSE, "%s", _("The Scheduled Transaction Editor " "cannot automatically balance " "this transaction. " "Should it still be " "entered?") ) ) { return SXFTD_ERRNO_UNBALANCED_XACTION; } gnc_ttinfo_set_template_splits(tti, template_splits); tt_list = g_list_append(tt_list, tti); gnc_suspend_gui_refresh (); xaccSchedXactionSetTemplateTrans(sxfti->sx, tt_list, gnc_get_current_book ()); gnc_resume_gui_refresh (); return 0; }
static void downloaded_transaction_append(GNCImportMatchPicker * matcher, GNCImportTransInfo * transaction_info) { GtkListStore *store; GtkTreeIter iter; GtkTreeSelection *selection; Transaction *trans; Split *split; gchar *text; const gchar *ro_text; gboolean found = FALSE; GNCImportTransInfo *local_info; g_assert(matcher); g_assert(transaction_info); /*DEBUG("Begin");*/ /* Has the transaction already been added? */ store = GTK_LIST_STORE(gtk_tree_view_get_model(matcher->downloaded_view)); if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) { do { gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DOWNLOADED_COL_INFO_PTR, &local_info, -1); if (local_info == transaction_info) { found = TRUE; break; } } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)); } if (!found) gtk_list_store_append(store, &iter); split = gnc_import_TransInfo_get_fsplit(transaction_info); trans = gnc_import_TransInfo_get_trans(transaction_info); /*Account*/ ro_text = xaccAccountGetName(xaccSplitGetAccount(split)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_ACCOUNT, ro_text, -1); /*Date*/ text = qof_print_date(xaccTransGetDate(trans)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_DATE, text, -1); g_free(text); /*Amount*/ ro_text = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_AMOUNT, ro_text, -1); /*Description*/ ro_text = xaccTransGetDescription(trans); gtk_list_store_set(store, &iter, DOWNLOADED_COL_DESCRIPTION, ro_text, -1); /*Memo*/ ro_text = xaccSplitGetMemo(split); gtk_list_store_set(store, &iter, DOWNLOADED_COL_MEMO, ro_text, -1); /*Imbalance*/ /* Assume that the importer won't create a transaction that involves two or more currencies and no non-currency commodity. In that case can use the simpler value imbalance check. */ ro_text = xaccPrintAmount(xaccTransGetImbalanceValue(trans), gnc_default_print_info(TRUE)); gtk_list_store_set(store, &iter, DOWNLOADED_COL_BALANCED, ro_text, -1); gtk_list_store_set(store, &iter, DOWNLOADED_COL_INFO_PTR, transaction_info, -1); selection = gtk_tree_view_get_selection(matcher->downloaded_view); gtk_tree_selection_select_iter(selection, &iter); }
void gnc_payment_window_fill_docs_list (PaymentWindow *pw) { GtkListStore *store; GList *list = NULL, *node; g_return_if_fail (pw->docs_list_tree_view && GTK_IS_TREE_VIEW(pw->docs_list_tree_view)); /* Get a list of open lots for this owner and post account */ if (pw->owner.owner.undefined) list = xaccAccountFindOpenLots (pw->post_acct, gncOwnerLotMatchOwnerFunc, &pw->owner, NULL); /* Clear the existing list */ store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(pw->docs_list_tree_view))); gtk_list_store_clear(store); /* Add the documents and overpayments to the tree view */ for (node = list; node; node = node->next) { GNCLot *lot = node->data; time64 doc_date_time = 0; const gchar *doc_type_str = NULL; const gchar *doc_id_str = NULL; const gchar *doc_deb_str = NULL; const gchar *doc_cred_str = NULL; GtkTreeIter iter; Timespec doc_date; GncInvoice *document; gnc_numeric value = gnc_numeric_zero(); gnc_numeric debit = gnc_numeric_zero(); gnc_numeric credit = gnc_numeric_zero(); /* Find the lot's document if it exists, * it could also be a prepayment lot. */ document = gncInvoiceGetInvoiceFromLot (lot); /* Find the document's date or pre-payment date */ if (document) doc_date = gncInvoiceGetDatePosted (document); else { /* Calculate the payment date based on the lot splits */ Transaction *trans = xaccSplitGetParent (gnc_lot_get_latest_split (lot)); if (trans) doc_date = xaccTransRetDatePostedTS (trans); else continue; /* No valid split in this lot, skip it */ } doc_date_time = timespecToTime64 (doc_date); /* Find the document type. No type means pre-payment in this case */ if (document) { doc_type_str = gncInvoiceGetTypeString (document); } else doc_type_str = _("Pre-Payment"); /* Find the document id. Empty for pre-payments. */ if (document) { doc_id_str = gncInvoiceGetID (document); } /* Find the debit/credit amount. * Invoices/vendor credit notes are debit (increasing the balance) * Customer credit notes/bills are credit (decreasing the balance) * Pre-payments are debit or credit depending on their sign */ value = gnc_lot_get_balance (lot); if (gnc_numeric_positive_p (value)) debit = value; else credit = gnc_numeric_neg (value); /* Only display non-zero debits/credits */ if (!gnc_numeric_zero_p (debit)) doc_deb_str = xaccPrintAmount (debit, gnc_default_print_info (FALSE)); if (!gnc_numeric_zero_p (credit)) doc_cred_str = xaccPrintAmount (credit, gnc_default_print_info (FALSE)); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, doc_date_time, 1, doc_id_str, 2, doc_type_str, 3, doc_deb_str, 4, doc_cred_str, 5, (gpointer)lot, -1); } g_list_free (list); /* Highlight the preset invoice if it's in the new list */ gnc_payment_dialog_highlight_document (pw); }
static void tax_table_entries_refresh (TaxTableWindow *ttw) { GList *list, *node; GtkTreeView *view; GtkListStore *store; GtkTreeIter iter; GtkTreePath *path; GtkTreeSelection *selection; GtkTreeRowReference *reference = NULL; GncTaxTableEntry *selected_entry; g_return_if_fail (ttw); view = GTK_TREE_VIEW (ttw->entries_view); store = GTK_LIST_STORE(gtk_tree_view_get_model(view)); /* Clear the list */ selected_entry = ttw->current_entry; gtk_list_store_clear (store); if (ttw->current_table == NULL) return; /* Add the items to the list */ list = gncTaxTableGetEntries (ttw->current_table); if (list) list = g_list_reverse (g_list_copy (list)); for (node = list ; node; node = node->next) { char *row_text[3]; GncTaxTableEntry *entry = node->data; Account *acc = gncTaxTableEntryGetAccount (entry); gnc_numeric amount = gncTaxTableEntryGetAmount (entry); row_text[0] = gnc_account_get_full_name (acc); switch (gncTaxTableEntryGetType (entry)) { case GNC_AMT_TYPE_PERCENT: row_text[1] = g_strdup_printf ("%s%%", xaccPrintAmount (amount, gnc_default_print_info (FALSE))); break; default: row_text[1] = g_strdup_printf ("%s", xaccPrintAmount (amount, gnc_default_print_info (TRUE))); break; } gtk_list_store_prepend(store, &iter); gtk_list_store_set(store, &iter, TAX_ENTRY_COL_NAME, row_text[0], TAX_ENTRY_COL_POINTER, entry, TAX_ENTRY_COL_AMOUNT, row_text[1], -1); if (entry == selected_entry) { path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); reference = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), path); gtk_tree_path_free(path); } g_free (row_text[0]); g_free (row_text[1]); } if (reference) { path = gtk_tree_row_reference_get_path(reference); gtk_tree_row_reference_free(reference); if (path) { selection = gtk_tree_view_get_selection(view); 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); } } }
static void gnc_query_list_fill(GNCQueryList *list) { GNCQueryListPriv *priv; gchar *strings[list->num_columns + 1]; GList *entries, *item; const GncGUID *guid; gint i; /* Clear all watches */ priv = GNC_QUERY_LIST_GET_PRIVATE(list); gnc_gui_component_clear_watches (priv->component_id); /* Reverse the list now because 'append()' takes too long */ entries = qof_query_run(list->query); for (item = entries; item; item = item->next) { GList *node; gint row; const QofParam *gup; QofParam *qp = NULL; for (i = 0, node = list->column_params; node; node = node->next) { GNCSearchParam *param = node->data; GSList *converters = gnc_search_param_get_converters (param); const char *type = gnc_search_param_get_param_type (param); gpointer res = item->data; /* if this is a boolean, ignore it now -- we'll use a checkmark later */ if (!safe_strcmp (type, QOF_TYPE_BOOLEAN)) { strings[i++] = g_strdup(""); continue; } /* Do all the object conversions */ for (; converters; converters = converters->next) { qp = converters->data; if (converters->next) { res = (qp->param_getfcn)(res, qp); } } /* Now convert this to a text value for the row */ if (!safe_strcmp(type, QOF_TYPE_DEBCRED) || !safe_strcmp(type, QOF_TYPE_NUMERIC)) { gnc_numeric (*nfcn)(gpointer, QofParam *) = (gnc_numeric(*)(gpointer, QofParam *))(qp->param_getfcn); gnc_numeric value = nfcn(res, qp); if (list->numeric_abs) value = gnc_numeric_abs (value); strings[i++] = g_strdup(xaccPrintAmount(value, gnc_default_print_info(FALSE))); } else strings[i++] = qof_query_core_to_string (type, res, qp); } row = gtk_clist_append (GTK_CLIST(list), (gchar **) strings); gtk_clist_set_row_data (GTK_CLIST(list), row, item->data); /* Free up our strings */ for (i = 0; i < list->num_columns; i++) { if (strings[i]) g_free (strings[i]); } /* Now update any checkmarks */ update_booleans (list, row); /* and set a watcher on this item */ gup = priv->get_guid; guid = (const GncGUID*)((gup->param_getfcn)(item->data, gup)); gnc_gui_component_watch_entity (priv->component_id, guid, QOF_EVENT_MODIFY | QOF_EVENT_DESTROY); list->num_entries++; } }