gboolean xaccScrubMergeSubSplits (Split *split, gboolean strict) { gboolean rc = FALSE; Transaction *txn; SplitList *node; GNCLot *lot; if (strict && (FALSE == is_subsplit (split))) return FALSE; txn = split->parent; // Don't mess with splits from an invoice transaction // Those are the responsibility of the business code if (gncInvoiceGetInvoiceFromTxn (txn)) return FALSE; lot = xaccSplitGetLot (split); ENTER ("(Lot=%s)", gnc_lot_get_title(lot)); restart: for (node = txn->splits; node; node = node->next) { Split *s = node->data; if (xaccSplitGetLot (s) != lot) continue; if (s == split) continue; if (qof_instance_get_destroying(s)) continue; // Don't mess with splits from an invoice transaction // Those are the responsibility of the business code if (gncInvoiceGetInvoiceFromTxn (s->parent)) return FALSE; if (strict) { /* OK, this split is in the same lot (and thus same account) * as the indicated split. Make sure it is really a subsplit * of the split we started with. It's possible to have two * splits in the same lot and transaction that are not subsplits * of each other, the test-period test suite does this, for * example. Only worry about adjacent sub-splits. By * repeatedly merging adjacent subsplits, we'll get the non- * adjacent ones too. */ if (!xaccSplitIsPeerSplit (split, s)) continue; } merge_splits (split, s); rc = TRUE; goto restart; } if (rc && gnc_numeric_zero_p (split->amount)) { time64 pdate = xaccTransGetDate (txn); gchar *pdatestr = gnc_ctime (&pdate); PWARN ("Result of merge has zero amt!"); PWARN ("Transaction details - posted date %s - description %s", pdatestr, xaccTransGetDescription(txn)); g_free (pdatestr); } LEAVE (" splits merged=%d", rc); return rc; }
static GtkWidget * ap_assistant_create (AcctPeriodInfo *info) { GtkBuilder *builder; GtkWidget *window; GtkWidget *box; builder = gtk_builder_new(); gnc_builder_add_from_file (builder , "assistant-acct-period.glade", "account_period_assistant"); window = GTK_WIDGET(gtk_builder_get_object (builder, "account_period_assistant")); info->window = window; // Set the style context for this assistant so it can be easily manipulated with css gnc_widget_set_style_context (GTK_WIDGET(window), "GncAssistAccountPeriod"); /* Enable all pages except menu page. */ gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "start_page")), TRUE); gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "book_page")), TRUE); gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "finish_page")), TRUE); gtk_assistant_set_page_complete (GTK_ASSISTANT (window), GTK_WIDGET(gtk_builder_get_object(builder, "summary_page")), TRUE); info->close_status = -1; /* Find the date of the earliest transaction in the book. * Add a year minus a day as the first guess for book closing, * and use that to set up the freq spec widget. */ info->earliest = get_earliest_in_book (gnc_get_current_book()); info->earliest_str = qof_print_date(info->earliest); PINFO ("date of earliest transaction is %" G_GINT64_FORMAT " %s", info->earliest, gnc_ctime (&info->earliest)); g_date_clear (&info->closing_date, 1); gnc_gdate_set_time64 (&info->closing_date, info->earliest); g_date_clear (&info->prev_closing_date, 1); info->prev_closing_date = info->closing_date; g_date_add_years (&info->closing_date, 1); { Recurrence *r = g_new0(Recurrence, 1); recurrenceSet(r, 1, PERIOD_MONTH, &info->closing_date, WEEKEND_ADJ_NONE); info->period = NULL; info->period = g_list_append(info->period, r); } info->period_menu = GNC_FREQUENCY( gnc_frequency_new_from_recurrence(info->period, &info->closing_date)); /* Change the text so that its more mainingful for this assistant */ gnc_frequency_set_frequency_label_text(info->period_menu, _("Period:")); gnc_frequency_set_date_label_text(info->period_menu, _("Closing Date:")); /* Reparent to the correct location */ box = GTK_WIDGET(gtk_builder_get_object(builder, "period_hbox")); gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (info->period_menu), TRUE, TRUE, 0); g_signal_connect (info->period_menu, "changed", G_CALLBACK (ap_assistant_menu_changed_cb), info); /* Get handles to all of the other widgets we'll need */ info->period_remarks = GTK_WIDGET(gtk_builder_get_object(builder, "remarks_label")); info->close_results = GTK_WIDGET(gtk_builder_get_object(builder, "results_label")); info->book_details = GTK_WIDGET(gtk_builder_get_object(builder, "book_label")); info->book_title = GTK_WIDGET(gtk_builder_get_object(builder, "book_title_entry")); info->book_notes = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "book_notes_view")); info->apply_label = GTK_WIDGET(gtk_builder_get_object(builder, "finish_page")); info->summary = GTK_WIDGET(gtk_builder_get_object(builder, "summary_label")); g_signal_connect (G_OBJECT(window), "destroy", G_CALLBACK (ap_assistant_destroy_cb), info); gtk_builder_connect_signals(builder, info); g_object_unref(G_OBJECT(builder)); return window; }
void ap_assistant_menu_prepare (GtkAssistant *assistant, gpointer user_data) { int nperiods; GDate period_begin, period_end, date_now; char * str; AcctPeriodInfo *info = user_data; ENTER ("info=%p", info); /* Pull info from widget, push into freq spec */ //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date); recurrenceListFree(&info->period); gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date); /* Count the number of periods that would be generated. */ g_date_clear (&period_begin, 1); g_date_clear (&period_end, 1); g_date_clear (&date_now, 1); nperiods = 0; period_end = info->closing_date; gnc_gdate_set_time64 (&date_now, gnc_time (NULL)); while (0 > g_date_compare(&period_end, &date_now )) { nperiods ++; PINFO ("Period = %d and End date is %d/%d/%d", nperiods, g_date_get_month(&period_end), g_date_get_day(&period_end), g_date_get_year(&period_end)); period_begin = period_end; recurrenceListNextInstance(info->period, &period_begin, &period_end); /* FIXME Check for valid period_end, not sure why it won't be!!! */ if (g_date_valid (&period_end) != TRUE) break; } /* Find the date of the earliest transaction in the current book. * Note that this could have changed since last time, since * we may have closed books since last time. */ info->earliest = get_earliest_in_book (gnc_get_current_book()); info->earliest_str = qof_print_date(info->earliest); PINFO ("Date of earliest transaction is %" G_GINT64_FORMAT " %s", info->earliest, gnc_ctime (&info->earliest)); /* Display the results */ str = g_strdup_printf ( /* Translators: %s is a date string. %d is the number of books * that will be created. This is a ngettext(3) message (but * only for the %d part). */ ngettext("The earliest transaction date found in this book is %s. " "Based on the selection made above, this book will be split " "into %d book.", "The earliest transaction date found in this book is %s. " "Based on the selection made above, this book will be split " "into %d books.", nperiods), info->earliest_str, nperiods); gtk_label_set_text (GTK_LABEL(info->period_remarks), str); g_free (str); }