Exemplo n.º 1
0
GtkWidget*
gnc_frequency_new(GList *recurrences, const GDate *start_date)
{
    GncFrequency *toRet;
    toRet = g_object_new(gnc_frequency_get_type(), NULL);
    gnc_frequency_setup_recurrence(toRet, recurrences, start_date);
    return GTK_WIDGET(toRet);
}
void
ap_assistant_finish (GtkAssistant *assistant, gpointer user_data)
{
    AcctPeriodInfo *info = user_data;
    GtkTextBuffer * buffer;
    GtkTextIter startiter, enditer;
    gint len;
    const char *btitle;
    char *bnotes;
    Timespec closing_date;

    ENTER("info=%p", info);

    btitle = gtk_entry_get_text (GTK_ENTRY(info->book_title));
    buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(info->book_notes));
    len = gtk_text_buffer_get_char_count (buffer);
    gtk_text_buffer_get_iter_at_offset(buffer, &startiter, 0);
    gtk_text_buffer_get_iter_at_offset(buffer, &enditer, len);

    bnotes = gtk_text_buffer_get_text(buffer, &startiter, &enditer , 0);
    PINFO("Book title is - %s\n", btitle);

    timespecFromTime64 (&closing_date,
                        gnc_time64_get_day_end_gdate (&info->closing_date));
    g_free(bnotes);

    /* Report the status back to the user. */
    info->close_status = 0;  /* XXX fixme success or failure? */

    /* Find the next closing date ... */
    info->prev_closing_date = info->closing_date;
    recurrenceListNextInstance (info->period, &info->prev_closing_date,
				&info->closing_date);


    /* FIXME Test for valid closing date, not sure why it won't be!!! */
    if (g_date_valid(&info->closing_date) == TRUE)
    {
        /* If the next closing date is in the future, then we are done. */
        if (gnc_time (NULL) >
	    gnc_time64_get_day_end_gdate (&info->closing_date))
        {
            /* Load up the GUI for the next closing period. */
            gnc_frequency_setup_recurrence (info->period_menu, NULL,
					    &info->closing_date);
            /* Jump back to the Close Book page. */
            gtk_assistant_set_current_page (GTK_ASSISTANT(info->window), 1);
        }
    }
}
Exemplo n.º 3
0
static gboolean
ap_close_period (GnomeDruidPage *druidpage,
                 GtkWidget *druid,
                 gpointer user_data)
{
    AcctPeriodInfo *info = user_data;
    QofBook *closed_book = NULL, *current_book;
    const char *btitle;
    char *bnotes;
    Timespec closing_date;
    KvpFrame *book_frame;
    gboolean really_do_close_books = FALSE;

    ENTER("info=%p", info);

    current_book = gnc_get_current_book ();

    btitle = gtk_entry_get_text (info->book_title);
    bnotes = xxxgtk_textview_get_text (info->book_notes);
    PINFO("book title=%s\n", btitle);

    timespecFromTime_t (&closing_date,
                        gnc_timet_get_day_end_gdate (&info->closing_date));

#define REALLY_DO_CLOSE_BOOKS
#ifdef REALLY_DO_CLOSE_BOOKS
    really_do_close_books = TRUE;
#endif /* REALLY_DO_CLOSE_BOOKS */

    if (really_do_close_books)
    {
        /* Close the books ! */
        qof_event_suspend ();
        gnc_suspend_gui_refresh ();

        scrub_all();
        closed_book = gnc_book_close_period (current_book, closing_date, NULL, btitle);

        book_frame = qof_book_get_slots(closed_book);
        kvp_frame_set_str (book_frame, "/book/title", btitle);
        kvp_frame_set_str (book_frame, "/book/notes", bnotes);

        qof_session_add_book (gnc_get_current_session(), closed_book);

        /* We must save now; if we don't, and the user bails without saving,
         * then opening account balances will be incorrect, and this can only
         * lead to unhappiness.
         */
        gnc_file_save ();
        gnc_resume_gui_refresh ();
        qof_event_resume ();
        gnc_gui_refresh_all ();  /* resume above should have been enough ??? */
    }
    g_free(bnotes);

    /* Report the status back to the user. */
    info->close_status = 0;  /* XXX fixme success or failure? */

    /* Find the next closing date ... */
    info->prev_closing_date = info->closing_date;
    recurrenceListNextInstance(info->period, &info->prev_closing_date, &info->closing_date);

    /* If the next closing date is in the future, then we are done. */
    if (time(NULL) < gnc_timet_get_day_end_gdate (&info->closing_date))
    {
        return FALSE;
    }

    /* Load up the GUI for the next closing period. */
    gnc_frequency_setup_recurrence(info->period_menu, NULL, &info->closing_date);

    show_book_details (info);
    return TRUE;
}