From 91a961d7921a5ef63c0fb51d79db7429cb5e2dca Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Tue, 2 Jul 2002 22:10:18 +0000 Subject: [PATCH] * fill out the Invoice Window Menu, based upon the Register Window. Fill in the callbacks required to get the menu to work. * Create a hook into the "owner-report" and link that into the Invoice Window, so you can print the report from any Invoice. * add a hook in the entry ledger to obtain the current Query (to set the sort order). git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7075 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 9 + src/business/business-gnome/Makefile.am | 1 + src/business/business-gnome/dialog-invoice.c | 266 +++++++- .../business-gnome/glade/invoice.glade | 604 +++++++++++++++++- src/business/business-ledger/gncEntryLedger.c | 9 + src/business/business-ledger/gncEntryLedger.h | 3 + .../business-ledger/gncEntryLedgerP.h | 1 - .../business-reports/business-reports.scm | 2 + .../business-reports/owner-report.scm | 91 ++- 9 files changed, 950 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 596a8e81f3..d4cc78a47c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,15 @@ menu in glade. * add a menubar to the Invoice Window in glade + + * fill out the Invoice Window Menu, based upon the Register + Window. Fill in the callbacks required to get the menu to work. + + * Create a hook into the "owner-report" and link that into the + Invoice Window, so you can print the report from any Invoice. + + * add a hook in the entry ledger to obtain the current Query (to + set the sort order). 2002-07-01 Derek Atkins diff --git a/src/business/business-gnome/Makefile.am b/src/business/business-gnome/Makefile.am index 808d0aab14..302e7a6097 100644 --- a/src/business/business-gnome/Makefile.am +++ b/src/business/business-gnome/Makefile.am @@ -13,6 +13,7 @@ AM_CFLAGS = \ -I${top_srcdir}/src/report/report-gnome \ -I${top_srcdir}/src/business/business-core \ -I${top_srcdir}/src/business/business-ledger \ + -I${top_srcdir}/src/business/dialog-tax-table \ ${GNOME_PRINT_CFLAGS} \ ${GNOME_INCLUDEDIR} \ ${GLADE_CFLAGS} \ diff --git a/src/business/business-gnome/dialog-invoice.c b/src/business/business-gnome/dialog-invoice.c index 7e00557023..b4105f301f 100644 --- a/src/business/business-gnome/dialog-invoice.c +++ b/src/business/business-gnome/dialog-invoice.c @@ -36,6 +36,9 @@ #include "dialog-job.h" #include "business-utils.h" #include "dialog-payment.h" +#include "dialog-tax-table.h" +#include "dialog-billterms.h" +#include "AccWindow.h" #define DIALOG_NEW_INVOICE_CM_CLASS "dialog-new-invoice" #define DIALOG_VIEW_INVOICE_CM_CLASS "dialog-view-invoice" @@ -48,6 +51,16 @@ typedef enum VIEW_INVOICE } InvoiceDialogType; +typedef enum +{ + BY_STANDARD = 0, + BY_DATE, + BY_DATE_ENTERED, + BY_DESC, + BY_QTY, + BY_PRICE +} sort_type_t; + struct _invoice_select_window { GNCBook * book; GncOwner * owner; @@ -60,8 +73,6 @@ struct _invoice_window { GtkWidget * dialog; - GtkWidget * menubar_dock; - GtkWidget * menubar; GtkWidget * statusbar; /* Popup Menu */ @@ -78,6 +89,13 @@ struct _invoice_window { GtkWidget * print_button; GtkWidget * post_button; + /* Menu Widgets */ + GtkWidget * menu_print; + GtkWidget * menu_cut; + GtkWidget * menu_paste; + GtkWidget * menu_edit_invoice; + GtkWidget * menu_actions; + /* Data Widgets */ GtkWidget * id_entry; GtkWidget * notes_text; @@ -100,6 +118,8 @@ struct _invoice_window { GnucashRegister * reg; GncEntryLedger * ledger; + sort_type_t last_sort; + InvoiceDialogType dialog_type; GUID invoice_guid; gint component_id; @@ -121,6 +141,27 @@ void gnc_invoice_window_blankCB (GtkWidget *widget, gpointer data); void gnc_invoice_window_printCB (GtkWidget *widget, gpointer data); void gnc_invoice_window_postCB (GtkWidget *widget, gpointer data); +void gnc_invoice_window_cut_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_copy_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_paste_cb (GtkWidget *widget, gpointer data); + +void gnc_invoice_window_new_account_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_new_invoice_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_report_owner_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_taxtable_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_billterm_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_payment_cb (GtkWidget *widget, gpointer data); + +void gnc_invoice_window_sort_standard_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_sort_date_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_sort_date_entered_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_sort_description_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_sort_quantity_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_sort_price_cb (GtkWidget *widget, gpointer data); + +void gnc_invoice_window_toolbar_cb (GtkWidget *widget, gpointer data); +void gnc_invoice_window_statusbar_cb (GtkWidget *widget, gpointer data); + #define WIDTH_PREFIX "invoice_reg" static int last_width = 0; @@ -503,6 +544,210 @@ gnc_invoice_window_postCB (GtkWidget *widget, gpointer data) gnc_table_refresh_gui (gnc_entry_ledger_get_table (iw->ledger), TRUE); } +void gnc_invoice_window_cut_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnucash_register_cut_clipboard (iw->reg); +} + +void gnc_invoice_window_copy_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnucash_register_copy_clipboard (iw->reg); +} + +void gnc_invoice_window_paste_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnucash_register_paste_clipboard (iw->reg); +} + +void gnc_invoice_window_new_account_cb (GtkWidget *widget, gpointer data) +{ + gnc_ui_new_account_window (NULL); +} + +void gnc_invoice_window_new_invoice_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + if (gncOwnerGetJob (&iw->job)) { + gnc_ui_invoice_new (&iw->job, iw->book); + } else { + gnc_ui_invoice_new (&iw->owner, iw->book); + } +} + +void gnc_invoice_window_report_owner_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + int id; + SCM qtype; + SCM args; + SCM func; + SCM arg; + + args = SCM_EOL; + + func = gh_eval_str ("gnc:owner-report-create"); + g_return_if_fail (gh_procedure_p (func)); + + qtype = gh_eval_str(""); + g_return_if_fail (qtype != SCM_UNDEFINED); + + arg = gw_wcp_assimilate_ptr (&iw->owner, qtype); + g_return_if_fail (arg != SCM_UNDEFINED); + + args = gh_cons (SCM_BOOL_F, args); + args = gh_cons (arg, args); + + /* Apply the function to the args */ + arg = gh_apply (func, args); + g_return_if_fail (gh_exact_p (arg)); + id = gh_scm2int (arg); + + if (id >= 0) + reportWindow (id); +} + +void gnc_invoice_window_taxtable_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_ui_tax_table_window_new (iw->book); +} + +void gnc_invoice_window_billterm_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_ui_billterms_window_new (iw->book); +} + +void gnc_invoice_window_payment_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + if (gncOwnerGetJob (&iw->job)) + gnc_ui_payment_new (&iw->job, iw->book); + else + gnc_ui_payment_new (&iw->owner, iw->book); +} + +/* Sorting callbacks */ + +static void +gnc_invoice_window_sort (InvoiceWindow *iw, sort_type_t sort_code) +{ + QueryNew *query = gnc_entry_ledger_get_query (iw->ledger); + GSList *p1 = NULL, *p2 = NULL, *p3 = NULL, *standard; + + if (iw->last_sort == sort_code) + return; + + standard = g_slist_prepend (NULL, QUERY_DEFAULT_SORT); + + switch (sort_code) + { + case BY_STANDARD: + p1 = standard; + break; + case BY_DATE: + p1 = g_slist_prepend (p1, ENTRY_DATE); + p2 = standard; + break; + case BY_DATE_ENTERED: + p1 = g_slist_prepend (p1, ENTRY_DATE_ENTERED); + p2 = standard; + break; + case BY_DESC: + p1 = g_slist_prepend (p1, ENTRY_DESC); + p2 = standard; + break; + case BY_QTY: + p1 = g_slist_prepend (p1, ENTRY_QTY); + p2 = standard; + break; + case BY_PRICE: + p1 = g_slist_prepend (p1, ENTRY_PRICE); + p2 = standard; + break; + default: + g_slist_free (standard); + g_return_if_fail (FALSE); + } + + gncQuerySetSortOrder (query, p1, p2, p3); + iw->last_sort = sort_code; + gnc_entry_ledger_display_refresh (iw->ledger); +} + +void +gnc_invoice_window_sort_standard_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_invoice_window_sort (iw, BY_STANDARD); +} + +void +gnc_invoice_window_sort_date_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_invoice_window_sort (iw, BY_DATE); +} + +void +gnc_invoice_window_sort_date_entered_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_invoice_window_sort (iw, BY_DATE_ENTERED); +} + +void +gnc_invoice_window_sort_description_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_invoice_window_sort (iw, BY_DESC); +} + +void +gnc_invoice_window_sort_quantity_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_invoice_window_sort (iw, BY_QTY); +} + +void +gnc_invoice_window_sort_price_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + gnc_invoice_window_sort (iw, BY_PRICE); +} + +/* Window configuration callbacks */ + +void gnc_invoice_window_toolbar_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + GtkCheckMenuItem *checkmenu = GTK_CHECK_MENU_ITEM(widget); + + if (checkmenu->active) { + gtk_widget_show(iw->toolbar_dock); + } else { + gtk_widget_hide(iw->toolbar_dock); + gtk_widget_queue_resize(iw->toolbar_dock); + } +} + +void gnc_invoice_window_statusbar_cb (GtkWidget *widget, gpointer data) +{ + InvoiceWindow *iw = data; + GtkCheckMenuItem *checkmenu = GTK_CHECK_MENU_ITEM(widget); + + if (checkmenu->active) { + gtk_widget_show(iw->statusbar); + } else { + gtk_widget_hide(iw->statusbar); + gtk_widget_queue_resize(iw->statusbar); + } +} + static GtkWidget * gnc_invoice_window_create_popup_menu (InvoiceWindow *iw) { @@ -959,6 +1204,7 @@ gnc_invoice_update_window (InvoiceWindow *iw) } } + /* Set the toolbar widgets sensitivity */ gtk_widget_set_sensitive (iw->edit_button, !is_posted); gtk_widget_set_sensitive (iw->enter_button, !is_posted); gtk_widget_set_sensitive (iw->cancel_button, !is_posted); @@ -968,6 +1214,13 @@ gnc_invoice_update_window (InvoiceWindow *iw) gtk_widget_set_sensitive (iw->print_button, is_posted); gtk_widget_set_sensitive (iw->post_button, !is_posted); + /* Set the menubar widgets sensitivity */ + gtk_widget_set_sensitive (iw->menu_print, is_posted); + gtk_widget_set_sensitive (iw->menu_cut, !is_posted); + gtk_widget_set_sensitive (iw->menu_paste, !is_posted); + gtk_widget_set_sensitive (iw->menu_edit_invoice, !is_posted); + gtk_widget_set_sensitive (iw->menu_actions, !is_posted); + if (is_posted) { // GtkWidget *hide; @@ -1098,9 +1351,12 @@ gnc_invoice_new_window (GNCBook *bookp, InvoiceDialogType type, iw->print_button = glade_xml_get_widget (xml, "print_button"); iw->post_button = glade_xml_get_widget (xml, "post_button"); - /* grab the menubar widgets */ - iw->menubar_dock = glade_xml_get_widget (xml, "menu_dock"); - iw->menubar = glade_xml_get_widget (xml, "menubar1"); + /* grab the menu widgets */ + iw->menu_print = glade_xml_get_widget (xml, "menu_print"); + iw->menu_cut = glade_xml_get_widget (xml, "menu_cut"); + iw->menu_paste = glade_xml_get_widget (xml, "menu_paste"); + iw->menu_edit_invoice = glade_xml_get_widget (xml, "menu_edit_invoice"); + iw->menu_actions = glade_xml_get_widget (xml, "menu_actions"); /* grab the statusbar */ iw->statusbar = glade_xml_get_widget (xml, "status_bar"); diff --git a/src/business/business-gnome/glade/invoice.glade b/src/business/business-gnome/glade/invoice.glade index 93024a2039..3e4f755222 100644 --- a/src/business/business-gnome/glade/invoice.glade +++ b/src/business/business-gnome/glade/invoice.glade @@ -427,7 +427,7 @@ False True True - False + True False @@ -459,13 +459,603 @@ GtkMenuBar menubar1 - GTK_SHADOW_OUT + GTK_SHADOW_NONE GtkMenuItem - placeholder1 - + menu_file + GNOMEUIINFO_MENU_FILE_TREE + + + GtkMenu + menu_file_menu + + + GtkPixmapMenuItem + menu_new_invoice + Create a new invoice + + activate + gnc_invoice_window_new_invoice_cb + Wed, 12 Jun 2002 05:41:11 GMT + + + False + GNOME_STOCK_MENU_NEW + + + + GtkPixmapMenuItem + menu_new_account + Create a new Account + + activate + gnc_invoice_window_new_account_cb + Tue, 02 Jul 2002 20:55:21 GMT + + + False + GNOME_STOCK_MENU_NEW + + + + GtkMenuItem + separator10 + False + + + + GtkPixmapMenuItem + menu_save + + activate + gnc_main_window_file_save_cb + Sun, 16 Jun 2002 17:35:28 GMT + + GNOMEUIINFO_MENU_SAVE_ITEM + + + + GtkPixmapMenuItem + menu_saveas + + activate + gnc_main_window_file_save_as_cb + Sun, 16 Jun 2002 17:35:28 GMT + + GNOMEUIINFO_MENU_SAVE_AS_ITEM + + + + GtkMenuItem + separator12 + False + + + + GtkPixmapMenuItem + menu_print + + activate + gnc_invoice_window_printCB + Wed, 12 Jun 2002 06:07:26 GMT + + GNOMEUIINFO_MENU_PRINT_ITEM + + + + GtkMenuItem + separator1 + False + + + + GtkPixmapMenuItem + menu_close + + activate + gnc_invoice_window_closeCB + Wed, 12 Jun 2002 01:59:32 GMT + + GNOMEUIINFO_MENU_CLOSE_ITEM + + + + GtkPixmapMenuItem + menu_exit + + activate + gnc_main_window_exit_cb + Wed, 12 Jun 2002 05:55:04 GMT + + GNOMEUIINFO_MENU_EXIT_ITEM + + + + + + GtkMenuItem + menu_edit + GNOMEUIINFO_MENU_EDIT_TREE + + + GtkMenu + menu_edit_menu + + + GtkPixmapMenuItem + menu_cut + + activate + gnc_invoice_window_cut_cb + Sun, 16 Jun 2002 17:35:28 GMT + + GNOMEUIINFO_MENU_CUT_ITEM + + + + GtkPixmapMenuItem + menu_copy + + activate + gnc_invoice_window_copy_cb + Sun, 16 Jun 2002 17:35:28 GMT + + GNOMEUIINFO_MENU_COPY_ITEM + + + + GtkPixmapMenuItem + menu_paste + + activate + gnc_invoice_window_paste_cb + Sun, 16 Jun 2002 17:35:28 GMT + + GNOMEUIINFO_MENU_PASTE_ITEM + + + + GtkMenuItem + separator13 + False + + + + GtkMenuItem + menu_edit_invoice + Edit this Invoice + + activate + gnc_invoice_window_editCB + Wed, 12 Jun 2002 05:42:08 GMT + + + False + + + + GtkMenuItem + separator11 + False + + + + + + GtkMenuItem + menu_view + GNOMEUIINFO_MENU_VIEW_TREE + + + GtkMenu + menu_view_menu + + + GtkCheckMenuItem + menu_toolbar + Display the toolbar + + activate + gnc_invoice_window_toolbar_cb + Wed, 12 Jun 2002 05:55:04 GMT + + + True + True + + + + GtkCheckMenuItem + menu_status_bar + Display the Status Bar + + activate + gnc_invoice_window_statusbar_cb + Wed, 12 Jun 2002 06:03:51 GMT + + + True + True + + + + GtkMenuItem + separator4 + False + + + + GtkMenuItem + menu_sort_order + + False + + + GtkMenu + menu_sort_order_menu + + + GtkRadioMenuItem + menu_sort_standard + Keep normal invoice order + + activate + gnc_invoice_window_sort_standard_cb + Wed, 12 Jun 2002 02:13:24 GMT + + + False + True + sort + + + + GtkMenuItem + separator5 + False + + + + GtkRadioMenuItem + menu_sort_date + Sort by date + + activate + gnc_invoice_window_sort_date_cb + Wed, 12 Jun 2002 02:13:24 GMT + + + False + True + sort + + + + GtkRadioMenuItem + menu_sort_date_of_entry + Sort by the date of entry + + activate + gnc_invoice_window_sort_date_entered_cb + Wed, 12 Jun 2002 02:13:24 GMT + + + False + True + sort + + + + GtkRadioMenuItem + menu_sort_quantity + Sort by quantity + + activate + gnc_invoice_window_sort_quantity_cb + Wed, 12 Jun 2002 02:13:24 GMT + + + False + True + sort + + + + GtkRadioMenuItem + menu_price_quantity + Sort by price + + activate + gnc_invoice_window_sort_price_cb + Wed, 12 Jun 2002 02:13:24 GMT + + + False + True + sort + + + + GtkRadioMenuItem + menu_sort_description + Sort by description + + activate + gnc_invoice_window_sort_description_cb + Wed, 12 Jun 2002 02:13:24 GMT + + + True + True + sort + + + + + + + + GtkMenuItem + menu_actions + False + + + GtkMenu + menu_actions_menu + + + GtkMenuItem + menu_enter + Record the current entry + + activate + gnc_invoice_window_recordCB + Wed, 12 Jun 2002 02:01:51 GMT + + + False + + + + GtkMenuItem + menu_cancel + Cancel the current entry + + activate + gnc_invoice_window_cancelCB + Wed, 12 Jun 2002 06:10:40 GMT + + + False + + + + GtkMenuItem + menu_delete + Delete the current entry + + activate + gnc_invoice_window_deleteCB + Tue, 18 Jun 2002 07:59:59 GMT + + + False + + + + GtkMenuItem + separator8 + False + + + + GtkMenuItem + menu_duplicate + Make a copy of the current entry + + activate + gnc_invoice_window_duplicateCB + Sun, 16 Jun 2002 00:14:37 GMT + + + False + + + + GtkMenuItem + menu_blank + Move to the blank entry at the bottom of the Invoice + + activate + gnc_invoice_window_blankCB + Wed, 12 Jun 2002 06:13:45 GMT + + + False + + + + + + GtkMenuItem + menu_reports + + False + + + GtkMenu + menu_reports_menu + + + GtkMenuItem + menu_report_owner + Open a company report window for the owner of this Invoice + + activate + gnc_invoice_window_report_owner_cb + Sun, 16 Jun 2002 17:31:17 GMT + + + False + + + + + + GtkMenuItem + menu_tools + + False + + + GtkMenu + menu_tools_menu + + + GtkMenuItem + menu_general_ledger + Open a general ledger window + + activate + gnc_main_window_gl_cb + Wed, 12 Jun 2002 06:22:56 GMT + + + False + + + + GtkMenuItem + menu_price_editor + View and edit the prices for stocks and mutual funds + + activate + gnc_main_window_prices_cb + Wed, 12 Jun 2002 06:22:56 GMT + + + False + + + + GtkMenuItem + menu_commodity_editor + View and edit the commodities for stocks and mutual funds + + activate + gnc_main_window_commodities_cb + Wed, 12 Jun 2002 06:22:56 GMT + + + False + + + + GtkMenuItem + menu_fincalc + Use the financial calculator + + activate + gnc_main_window_fincalc_cb + Wed, 12 Jun 2002 06:22:56 GMT + + + False + + + + GtkMenuItem + menu_taxtable + View and edit the list of Tax Tables + + activate + gnc_invoice_window_taxtable_cb + Tue, 02 Jul 2002 20:55:22 GMT + + + False + + + + GtkMenuItem + menu_billterm + View and edit the list of Billing Terms + + activate + gnc_invoice_window_billterm_cb + Tue, 02 Jul 2002 20:55:22 GMT + + + False + + + + GtkMenuItem + menu_payment + Enter a payment for the owner of this Invoice + + activate + gnc_invoice_window_payment_cb + Tue, 02 Jul 2002 20:55:22 GMT + + + False + + + + + + GtkMenuItem + menu_help + GNOMEUIINFO_MENU_HELP_TREE + + + GtkMenu + menu_help_menu + + + GtkMenuItem + menu_manual + + activate + gnc_main_window_help_cb + Wed, 12 Jun 2002 01:57:06 GMT + + + False + + + + GtkMenuItem + menu_totd + + activate + gnc_main_window_totd_cb + Wed, 12 Jun 2002 01:57:06 GMT + + + False + + + + GtkMenuItem + separator9 + False + + + + GtkPixmapMenuItem + menu_about + + activate + gnc_main_window_about_cb + Sun, 16 Jun 2002 01:12:45 GMT + + GNOMEUIINFO_MENU_ABOUT_ITEM + + @@ -487,13 +1077,13 @@ GtkToolbar - toolbar1 + toolbar 2 GTK_ORIENTATION_HORIZONTAL GTK_TOOLBAR_BOTH - 5 + 10 GTK_TOOLBAR_SPACE_LINE - GTK_RELIEF_NORMAL + GTK_RELIEF_NONE True diff --git a/src/business/business-ledger/gncEntryLedger.c b/src/business/business-ledger/gncEntryLedger.c index b673a8235a..74764d63b1 100644 --- a/src/business/business-ledger/gncEntryLedger.c +++ b/src/business/business-ledger/gncEntryLedger.c @@ -646,3 +646,12 @@ gnc_entry_ledger_duplicate_current_entry (GncEntryLedger *ledger) gnc_resume_gui_refresh (); return; } + +QueryNew * +gnc_entry_ledger_get_query (GncEntryLedger *ledger) +{ + if (!ledger) + return NULL; + + return ledger->query; +} diff --git a/src/business/business-ledger/gncEntryLedger.h b/src/business/business-ledger/gncEntryLedger.h index 5d048b4892..6b1151d015 100644 --- a/src/business/business-ledger/gncEntryLedger.h +++ b/src/business/business-ledger/gncEntryLedger.h @@ -7,6 +7,7 @@ #ifndef GNC_ENTRY_LEDGER_H #define GNC_ENTRY_LEDGER_H +#include "QueryNew.h" #include "gncEntry.h" #include "gncOrder.h" #include "gnc-book.h" @@ -104,4 +105,6 @@ gboolean gnc_entry_ledger_get_entry_virt_loc (GncEntryLedger *ledger, void gnc_entry_ledger_delete_current_entry (GncEntryLedger *ledger); void gnc_entry_ledger_duplicate_current_entry (GncEntryLedger *ledger); +QueryNew * gnc_entry_ledger_get_query (GncEntryLedger *ledger); + #endif /* GNC_ENTRY_LEDGER_H */ diff --git a/src/business/business-ledger/gncEntryLedgerP.h b/src/business/business-ledger/gncEntryLedgerP.h index d199c3de38..83a60e3c64 100644 --- a/src/business/business-ledger/gncEntryLedgerP.h +++ b/src/business/business-ledger/gncEntryLedgerP.h @@ -10,7 +10,6 @@ #include "guid.h" #include "gnc-book.h" #include "table-allgui.h" -#include "QueryNew.h" #include "gncEntryLedger.h" struct GncEntryLedger_s { diff --git a/src/business/business-reports/business-reports.scm b/src/business/business-reports/business-reports.scm index 3a57a5f95d..7bf8f09f50 100644 --- a/src/business/business-reports/business-reports.scm +++ b/src/business/business-reports/business-reports.scm @@ -15,3 +15,5 @@ (use-modules (gnucash report owner-report)) (define gnc:invoice-report-create gnc:invoice-report-create-internal) + +(export gnc:owner-report-create) diff --git a/src/business/business-reports/owner-report.scm b/src/business/business-reports/owner-report.scm index 163d3a8caa..9c83a1e056 100644 --- a/src/business/business-reports/owner-report.scm +++ b/src/business/business-reports/owner-report.scm @@ -446,6 +446,39 @@ document)) +(define (find-first-account type) + (define (find-first group num index) + (if (>= index num) + #f + (let* ((this-account (gnc:group-get-account group index)) + (account-type (gw:enum--val->sym + (gnc:account-get-type this-account) #f))) + (if (eq? account-type type) + this-account + (find-first group num (+ index 1)))))) + + (let* ((current-group (gnc:get-current-group)) + (num-accounts (gnc:group-get-num-accounts + current-group))) + (if (> num-accounts 0) + (find-first current-group num-accounts 0) + #f))) + +(define (find-first-account-for-owner owner) + (let ((type (gw:enum--val->sym + (gnc:owner-get-type (gnc:owner-get-end-owner owner)) #f))) + (case type + ((gnc-owner-customer) + (find-first-account 'receivable)) + + ((gnc-owner-vendor) + (find-first-account 'payable)) + + ((gnc-owner-job) + (find-first-account-for-owner (gnc:owner-get-end-owner owner))) + + (else + #f)))) (gnc:define-report 'version 1 @@ -483,6 +516,37 @@ (owner-report-create-internal "Vendor Report" owner query account))) )) +(define (gnc:owner-report-create owner account) + (let* ((q (gnc:malloc-query)) + (guid (gnc:owner-get-guid (gnc:owner-get-end-owner owner)))) + + ; Figure out an account to use if nothing exists here. + (if (not account) + (set! account (find-first-account-for-owner owner))) + + (gnc:query-add-guid-match + q + (list gnc:split-trans gnc:invoice-from-txn gnc:invoice-owner + gnc:owner-parentg) + guid 'query-or) + (gnc:query-add-guid-match + q + (list gnc:split-lot gnc:owner-from-lot gnc:owner-parentg) + guid 'query-or) + (gnc:query-add-guid-match + q + (list gnc:split-lot gnc:invoice-from-lot gnc:invoice-owner + gnc:owner-parentg) + guid 'query-or) + + (gnc:query-add-single-account-match q account 'query-and) + (gnc:query-set-book q (gnc:get-current-book)) + + (let ((res (owner-report-create owner q account))) + (gnc:free-query q) + res))) + + (define (gnc:owner-report-create-internal account split query journal? double? title debit-string credit-string) @@ -490,7 +554,6 @@ (let* ((trans (gnc:split-get-parent split)) (invoice (gnc:invoice-get-invoice-from-txn trans)) (temp-owner (gnc:owner-create)) - (q (gnc:malloc-query)) (owner #f)) (if invoice @@ -511,33 +574,15 @@ (check-splits (cdr splits))))) (check-splits split-list))) - (let ((guid (gnc:owner-get-guid (gnc:owner-get-end-owner owner)))) - (gnc:query-add-guid-match - q - (list gnc:split-trans gnc:invoice-from-txn gnc:invoice-owner - gnc:owner-parentg) - guid 'query-or) - (gnc:query-add-guid-match - q - (list gnc:split-lot gnc:owner-from-lot gnc:owner-parentg) - guid 'query-or) - (gnc:query-add-guid-match - q - (list gnc:split-lot gnc:invoice-from-lot gnc:invoice-owner - gnc:owner-parentg) - guid 'query-or) - ) - - (gnc:query-add-single-account-match q account 'query-and) - (gnc:query-set-book q (gnc:get-current-book)) - - (let ((res (owner-report-create owner q account))) + (let ((res (gnc:owner-report-create owner account))) (gnc:owner-destroy temp-owner) - (gnc:free-query q) res))) + (gnc:register-report-hook 'receivable #t gnc:owner-report-create-internal) (gnc:register-report-hook 'payable #t gnc:owner-report-create-internal) + +(export gnc:owner-report-create)