gchar * qof_book_increment_and_format_counter (QofBook *book, const char *counter_name) { KvpFrame *kvp; KvpValue *value; gint64 counter; gchar* format; gchar* result; if (!book) { PWARN ("No book!!!"); return NULL; } if (!counter_name || *counter_name == '\0') { PWARN ("Invalid counter name."); return NULL; } /* Get the current counter value from the KVP in the book. */ counter = qof_book_get_counter(book, counter_name); /* Check if an error occurred */ if (counter < 0) return NULL; /* Increment the counter */ counter++; /* Get the KVP from the current book */ kvp = qof_instance_get_slots (QOF_INSTANCE (book)); if (!kvp) { PWARN ("Book has no KVP_Frame"); return NULL; } /* Save off the new counter */ qof_book_begin_edit(book); value = new KvpValue(counter); delete kvp->set_path({"counters", counter_name}, value); qof_instance_set_dirty (QOF_INSTANCE (book)); qof_book_commit_edit(book); format = qof_book_get_counter_format(book, counter_name); if (!format) { PWARN("Cannot get format for counter"); return NULL; } /* Generate a string version of the counter */ result = g_strdup_printf(format, counter); g_free (format); return result; }
gint64 gncEmployeeNextID (QofBook *book) { return qof_book_get_counter (book, _GNC_MOD_NAME); }