mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Save/restore business invoice pages.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12878 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
2006-01-18 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/business/business-core/gncOwner.[ch]:
|
||||
* src/business/business-gnome/dialog-invoice.[ch]:
|
||||
* src/business/business-gnome/gnc-plugin-page-invoice.c:
|
||||
Save/restore business invoice pages.
|
||||
|
||||
* src/app-utils/gnc-component-manager.c: Tweak a debugging
|
||||
statement.
|
||||
|
||||
|
||||
@@ -489,6 +489,30 @@ reg_lot (void)
|
||||
qof_class_register (GNC_ID_LOT, NULL, params);
|
||||
}
|
||||
|
||||
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid)
|
||||
{
|
||||
if (!book || !owner || !type || !guid) return FALSE;
|
||||
|
||||
if (0 == safe_strcmp(type, GNC_ID_CUSTOMER)) {
|
||||
GncCustomer *customer = gncCustomerLookup(book,guid);
|
||||
gncOwnerInitCustomer(owner, customer);
|
||||
return (NULL != customer);
|
||||
} else if (0 == safe_strcmp(type, GNC_ID_JOB)) {
|
||||
GncJob *job = gncJobLookup(book,guid);
|
||||
gncOwnerInitJob(owner, job);
|
||||
return (NULL != job);
|
||||
} else if (0 == safe_strcmp(type, GNC_ID_VENDOR)) {
|
||||
GncVendor *vendor = gncVendorLookup(book,guid);
|
||||
gncOwnerInitVendor(owner, vendor);
|
||||
return (NULL != vendor);
|
||||
} else if (0 == safe_strcmp(type, GNC_ID_EMPLOYEE)) {
|
||||
GncEmployee *employee = gncEmployeeLookup(book,guid);
|
||||
gncOwnerInitEmployee(owner, employee);
|
||||
return (NULL != employee);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
gboolean gncOwnerRegister (void)
|
||||
{
|
||||
static QofParam params[] = {
|
||||
|
||||
@@ -135,6 +135,8 @@ void gncOwnerAttachToLot (GncOwner *owner, GNCLot *lot);
|
||||
*/
|
||||
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
|
||||
|
||||
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid);
|
||||
|
||||
#define OWNER_TYPE "type"
|
||||
#define OWNER_TYPE_STRING "type-string" /**< Allows the type to be handled externally. */
|
||||
#define OWNER_CUSTOMER "customer"
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
#include "gncEntryLedger.h"
|
||||
|
||||
#include "gnc-plugin-page.h"
|
||||
#include "gnc-general-search.h"
|
||||
#include "dialog-date-close.h"
|
||||
#include "dialog-invoice.h"
|
||||
@@ -65,7 +66,6 @@
|
||||
#include "dialog-query-list.h"
|
||||
|
||||
#include "gnc-plugin-business.h"
|
||||
#include "gnc-plugin-page.h"
|
||||
#include "gnc-plugin-page-invoice.h"
|
||||
#include "gnc-main-window.h"
|
||||
|
||||
@@ -79,13 +79,18 @@ void gnc_invoice_window_cancel_cb (GtkWidget *widget, gpointer data);
|
||||
void gnc_invoice_window_help_cb (GtkWidget *widget, gpointer data);
|
||||
void gnc_invoice_id_changed_cb (GtkWidget *widget, gpointer data);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NEW_INVOICE,
|
||||
MOD_INVOICE,
|
||||
EDIT_INVOICE,
|
||||
VIEW_INVOICE
|
||||
} InvoiceDialogType;
|
||||
#define ENUM_INVOICE_TYPE(_) \
|
||||
_(NEW_INVOICE, ) \
|
||||
_(MOD_INVOICE, ) \
|
||||
_(EDIT_INVOICE, ) \
|
||||
_(VIEW_INVOICE, )
|
||||
|
||||
DEFINE_ENUM(InvoiceDialogType, ENUM_INVOICE_TYPE)
|
||||
AS_STRING_DEC(InvoiceDialogType, ENUM_INVOICE_TYPE)
|
||||
FROM_STRING_DEC(InvoiceDialogType, ENUM_INVOICE_TYPE)
|
||||
|
||||
FROM_STRING_FUNC(InvoiceDialogType, ENUM_INVOICE_TYPE)
|
||||
AS_STRING_FUNC(InvoiceDialogType, ENUM_INVOICE_TYPE)
|
||||
|
||||
struct _invoice_select_window {
|
||||
GNCBook * book;
|
||||
@@ -1655,6 +1660,114 @@ gnc_invoice_new_page (GNCBook *bookp, InvoiceDialogType type,
|
||||
return iw;
|
||||
}
|
||||
|
||||
#define KEY_INVOICE_TYPE "Invoice Type"
|
||||
#define KEY_INVOICE_GUID "Invoice GUID"
|
||||
#define KEY_OWNER_TYPE "Owner Type"
|
||||
#define KEY_OWNER_GUID "Owner GUID"
|
||||
|
||||
GncPluginPage *
|
||||
gnc_invoice_recreate_page (GKeyFile *key_file,
|
||||
const gchar *group_name)
|
||||
{
|
||||
InvoiceWindow *iw;
|
||||
GError *error = NULL;
|
||||
char *tmp_string = NULL, *owner_type = NULL;
|
||||
InvoiceDialogType type;
|
||||
GncInvoice *invoice;
|
||||
GUID guid;
|
||||
QofBook *book;
|
||||
GncOwner owner = { 0 };
|
||||
|
||||
/* Get Invoice Type */
|
||||
tmp_string = g_key_file_get_string(key_file, group_name,
|
||||
KEY_INVOICE_TYPE, &error);
|
||||
if (error) {
|
||||
g_warning("Error reading group %s key %s: %s.",
|
||||
group_name, KEY_INVOICE_TYPE, error->message);
|
||||
goto give_up;
|
||||
}
|
||||
type = InvoiceDialogTypefromString(tmp_string);
|
||||
g_free(tmp_string);
|
||||
|
||||
/* Get Invoice GUID */
|
||||
tmp_string = g_key_file_get_string(key_file, group_name,
|
||||
KEY_INVOICE_GUID, &error);
|
||||
if (error) {
|
||||
g_warning("Error reading group %s key %s: %s.",
|
||||
group_name, KEY_INVOICE_GUID, error->message);
|
||||
goto give_up;
|
||||
}
|
||||
if (!string_to_guid(tmp_string, &guid)) {
|
||||
g_warning("Invalid invoice guid: %s.", tmp_string);
|
||||
goto give_up;
|
||||
}
|
||||
book = gnc_get_current_book();
|
||||
invoice = gncInvoiceLookup(gnc_get_current_book(), &guid);
|
||||
if (invoice == NULL) {
|
||||
g_warning("Can't find invoice %s in current book.", tmp_string);
|
||||
goto give_up;
|
||||
}
|
||||
g_free(tmp_string);
|
||||
|
||||
/* Get Owner Type */
|
||||
owner_type = g_key_file_get_string(key_file, group_name,
|
||||
KEY_OWNER_TYPE, &error);
|
||||
if (error) {
|
||||
g_warning("Error reading group %s key %s: %s.",
|
||||
group_name, KEY_OWNER_TYPE, error->message);
|
||||
goto give_up;
|
||||
}
|
||||
|
||||
/* Get Owner GUID */
|
||||
tmp_string = g_key_file_get_string(key_file, group_name,
|
||||
KEY_OWNER_GUID, &error);
|
||||
if (error) {
|
||||
g_warning("Error reading group %s key %s: %s.",
|
||||
group_name, KEY_OWNER_GUID, error->message);
|
||||
goto give_up;
|
||||
}
|
||||
if (!string_to_guid(tmp_string, &guid)) {
|
||||
g_warning("Invalid owner guid: %s.", tmp_string);
|
||||
goto give_up;
|
||||
}
|
||||
|
||||
if (!gncOwnerGetOwnerFromTypeGuid(book, &owner, owner_type, &guid)) {
|
||||
g_warning("Can't find owner %s in current book.", tmp_string);
|
||||
goto give_up;
|
||||
}
|
||||
g_free(tmp_string);
|
||||
g_free(owner_type);
|
||||
|
||||
iw = gnc_invoice_new_page (book, type, invoice, &owner);
|
||||
return iw->page;
|
||||
|
||||
give_up:
|
||||
g_warning("Giving up on restoring '%s'.", group_name);
|
||||
if (error)
|
||||
g_error_free(error);
|
||||
if (tmp_string)
|
||||
g_free(tmp_string);
|
||||
if (owner_type)
|
||||
g_free(owner_type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_invoice_save_page (InvoiceWindow *iw,
|
||||
GKeyFile *key_file,
|
||||
const gchar *group_name)
|
||||
{
|
||||
g_key_file_set_string(key_file, group_name, KEY_INVOICE_TYPE,
|
||||
InvoiceDialogTypeasString(iw->dialog_type));
|
||||
g_key_file_set_string(key_file, group_name, KEY_INVOICE_GUID,
|
||||
guid_to_string(&iw->invoice_guid));
|
||||
|
||||
g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE,
|
||||
qofOwnerGetType(&iw->owner));
|
||||
g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID,
|
||||
guid_to_string(gncOwnerGetGUID(&iw->owner)));
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gnc_invoice_create_page (InvoiceWindow *iw, gpointer page)
|
||||
{
|
||||
|
||||
@@ -77,6 +77,11 @@ gchar *gnc_invoice_get_help (InvoiceWindow *iw);
|
||||
|
||||
gchar *gnc_invoice_get_title (InvoiceWindow *iw);
|
||||
|
||||
#ifdef __GNC_PLUGIN_PAGE_H
|
||||
GncPluginPage *gnc_invoice_recreate_page (GKeyFile *key_file, const gchar *group_name);
|
||||
void gnc_invoice_save_page (InvoiceWindow *iw, GKeyFile *key_file, const gchar *group_name);
|
||||
#endif
|
||||
|
||||
GtkWidget * gnc_invoice_create_page (InvoiceWindow *iw, gpointer page);
|
||||
|
||||
DialogQueryList *gnc_invoice_show_bills_due (QofBook *book, double days_in_advance);
|
||||
|
||||
@@ -49,6 +49,8 @@ static void gnc_plugin_page_invoice_finalize (GObject *object);
|
||||
|
||||
static GtkWidget *gnc_plugin_page_invoice_create_widget (GncPluginPage *plugin_page);
|
||||
static void gnc_plugin_page_invoice_destroy_widget (GncPluginPage *plugin_page);
|
||||
static void gnc_plugin_page_invoice_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
|
||||
static GncPluginPage *gnc_plugin_page_invoice_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
|
||||
static void gnc_plugin_page_invoice_window_changed (GncPluginPage *plugin_page, GtkWidget *window);
|
||||
|
||||
|
||||
@@ -290,6 +292,8 @@ gnc_plugin_page_invoice_class_init (GncPluginPageInvoiceClass *klass)
|
||||
gnc_plugin_class->plugin_name = GNC_PLUGIN_PAGE_INVOICE_NAME;
|
||||
gnc_plugin_class->create_widget = gnc_plugin_page_invoice_create_widget;
|
||||
gnc_plugin_class->destroy_widget = gnc_plugin_page_invoice_destroy_widget;
|
||||
gnc_plugin_class->save_page = gnc_plugin_page_invoice_save_page;
|
||||
gnc_plugin_class->recreate_page = gnc_plugin_page_invoice_recreate_page;
|
||||
gnc_plugin_class->window_changed = gnc_plugin_page_invoice_window_changed;
|
||||
|
||||
g_type_class_add_private(klass, sizeof(GncPluginPageInvoicePrivate));
|
||||
@@ -429,6 +433,67 @@ gnc_plugin_page_invoice_destroy_widget (GncPluginPage *plugin_page)
|
||||
priv->widget = NULL;
|
||||
}
|
||||
|
||||
/** Save enough information about this invoice page that it can be
|
||||
* recreated next time the user starts gnucash.
|
||||
*
|
||||
* @param page The page to save.
|
||||
*
|
||||
* @param key_file A pointer to the GKeyFile data structure where the
|
||||
* page information should be written.
|
||||
*
|
||||
* @param group_name The group name to use when saving data. */
|
||||
static void
|
||||
gnc_plugin_page_invoice_save_page (GncPluginPage *plugin_page,
|
||||
GKeyFile *key_file,
|
||||
const gchar *group_name)
|
||||
{
|
||||
GncPluginPageInvoice *invoice;
|
||||
GncPluginPageInvoicePrivate *priv;
|
||||
|
||||
g_return_if_fail (GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
|
||||
g_return_if_fail (key_file != NULL);
|
||||
g_return_if_fail (group_name != NULL);
|
||||
|
||||
ENTER("page %p, key_file %p, group_name %s", plugin_page, key_file,
|
||||
group_name);
|
||||
|
||||
invoice = GNC_PLUGIN_PAGE_INVOICE(plugin_page);
|
||||
priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice);
|
||||
|
||||
gnc_invoice_save_page(priv->iw, key_file, group_name);
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Create a new invoice page based on the information saved during a
|
||||
* previous instantiation of gnucash.
|
||||
*
|
||||
* @param window The window where this page should be installed.
|
||||
*
|
||||
* @param key_file A pointer to the GKeyFile data structure where the
|
||||
* page information should be read.
|
||||
*
|
||||
* @param group_name The group name to use when restoring data. */
|
||||
static GncPluginPage *
|
||||
gnc_plugin_page_invoice_recreate_page (GtkWidget *window,
|
||||
GKeyFile *key_file,
|
||||
const gchar *group_name)
|
||||
{
|
||||
GncPluginPage *page;
|
||||
|
||||
g_return_val_if_fail(key_file, NULL);
|
||||
g_return_val_if_fail(group_name, NULL);
|
||||
ENTER("key_file %p, group_name %s", key_file, group_name);
|
||||
|
||||
/* Create the new page. */
|
||||
page = gnc_invoice_recreate_page(key_file, group_name);
|
||||
|
||||
LEAVE(" ");
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnc_plugin_page_invoice_window_changed (GncPluginPage *plugin_page,
|
||||
GtkWidget *window)
|
||||
|
||||
Reference in New Issue
Block a user