mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Bug753307 - Custom Report be selectable as default Report for Printing
This commit changes the preference in Business->'Report for Printing' to be saved as a book property and allow the selection of any Invoice Report to be used as the default.
This commit is contained in:
parent
63f8e73142
commit
019214f1c2
@ -42,6 +42,7 @@
|
||||
|
||||
#include "gnc-general-search.h"
|
||||
#include "qof.h"
|
||||
#include "qofbook.h"
|
||||
#include "business-gnome-utils.h"
|
||||
#include "dialog-customer.h"
|
||||
#include "dialog-job.h"
|
||||
@ -49,6 +50,9 @@
|
||||
#include "dialog-employee.h"
|
||||
#include "dialog-invoice.h"
|
||||
|
||||
#include "guile-mappings.h"
|
||||
#include "gnc-guile-utils.h"
|
||||
#include "gnc-prefs.h"
|
||||
#include "gnc-commodity.h"
|
||||
|
||||
typedef enum
|
||||
@ -57,6 +61,248 @@ typedef enum
|
||||
GNCSEARCH_TYPE_EDIT
|
||||
} GNCSearchType;
|
||||
|
||||
enum
|
||||
{
|
||||
COL_INV_NAME = 0,
|
||||
COL_INV_GUID,
|
||||
COL_INV_MISSING,
|
||||
NUM_INV_COLS
|
||||
};
|
||||
|
||||
#define PRINTABLE_INVOICE_GUID "5123a759ceb9483abf2182d01c140e8d"
|
||||
#define TAX_INVOICE_GUID "0769e242be474010b4acf264a5512e6e"
|
||||
#define EASY_INVOICE_GUID "67112f318bef4fc496bdc27d106bbda4"
|
||||
#define FANCY_INVOICE_GUID "3ce293441e894423a2425d7a22dd1ac6"
|
||||
|
||||
enum
|
||||
{
|
||||
PRINTABLE_INVOICE_PREF_NUM = 0,
|
||||
TAX_INVOICE_PREF_NUM,
|
||||
EASY_INVOICE_PREF_NUM,
|
||||
FANCY_INVOICE_PREF_NUM,
|
||||
};
|
||||
|
||||
static const char* invoice_printreport_values[] =
|
||||
{
|
||||
/* The list below are the guids of reports that can
|
||||
* be used to print an invoice.
|
||||
*
|
||||
* Important: This list matches the order of existing saved
|
||||
* preference entries.
|
||||
*/
|
||||
PRINTABLE_INVOICE_GUID,
|
||||
TAX_INVOICE_GUID,
|
||||
EASY_INVOICE_GUID,
|
||||
FANCY_INVOICE_GUID,
|
||||
NULL
|
||||
};
|
||||
|
||||
#define GNC_PREFS_GROUP_INVOICE "dialogs.business.invoice"
|
||||
#define GNC_PREF_INV_PRINT_RPT "invoice-printreport"
|
||||
|
||||
const char *
|
||||
gnc_get_builtin_default_invoice_print_report (void)
|
||||
{
|
||||
return PRINTABLE_INVOICE_GUID;
|
||||
}
|
||||
|
||||
const char *
|
||||
gnc_migrate_default_invoice_print_report (void)
|
||||
{
|
||||
QofBook *book = gnc_get_current_book ();
|
||||
int old_style_value = gnc_prefs_get_int (GNC_PREFS_GROUP_INVOICE,
|
||||
GNC_PREF_INV_PRINT_RPT);
|
||||
|
||||
if (old_style_value >= TAX_INVOICE_PREF_NUM &&
|
||||
old_style_value <= FANCY_INVOICE_PREF_NUM)
|
||||
{
|
||||
const gchar *ret = invoice_printreport_values[old_style_value];
|
||||
qof_book_set_default_invoice_report (book, ret, " ");
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
return gnc_get_builtin_default_invoice_print_report ();
|
||||
}
|
||||
|
||||
char *
|
||||
gnc_get_default_invoice_print_report (void)
|
||||
{
|
||||
QofBook *book = gnc_get_current_book ();
|
||||
gchar *default_guid = qof_book_get_default_invoice_report_guid (book);
|
||||
|
||||
if (!default_guid)
|
||||
return g_strdup (gnc_migrate_default_invoice_print_report ());
|
||||
|
||||
return default_guid;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
select_default (GtkWidget *combo, const gchar *default_guid)
|
||||
{
|
||||
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX(combo));
|
||||
GtkTreeIter iter;
|
||||
gboolean found = FALSE;
|
||||
gboolean valid_iter = gtk_tree_model_get_iter_first (model, &iter);
|
||||
|
||||
while (valid_iter)
|
||||
{
|
||||
gchar *guid;
|
||||
gtk_tree_model_get (model, &iter, COL_INV_GUID, &guid, -1);
|
||||
|
||||
if (g_strcmp0 (default_guid, guid) == 0)
|
||||
{
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(combo), &iter);
|
||||
g_free (guid);
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
g_free (guid);
|
||||
valid_iter = gtk_tree_model_iter_next (model, &iter);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* update_invoice_list
|
||||
*
|
||||
* this procedure does the real work of displaying a sorted list of
|
||||
* available invoice reports
|
||||
********************************************************************/
|
||||
static gchar *
|
||||
update_invoice_list (GtkWidget *combo)
|
||||
{
|
||||
SCM get_rpt_guids = scm_c_eval_string ("gnc:custom-report-invoice-template-guids");
|
||||
SCM template_menu_name = scm_c_eval_string ("gnc:report-template-menu-name/report-guid");
|
||||
SCM reportlist;
|
||||
SCM rpt_guids;
|
||||
|
||||
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX(combo));
|
||||
GtkListStore *store = GTK_LIST_STORE(model);
|
||||
gchar *default_guid = gnc_get_default_invoice_print_report ();
|
||||
gchar *default_name = NULL;
|
||||
gboolean have_default = FALSE;
|
||||
|
||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(model),
|
||||
COL_INV_NAME, GTK_SORT_ASCENDING);
|
||||
|
||||
reportlist = scm_call_0 (get_rpt_guids);
|
||||
rpt_guids = reportlist;
|
||||
|
||||
gtk_list_store_clear (store);
|
||||
|
||||
if (scm_is_list (rpt_guids))
|
||||
{
|
||||
int i;
|
||||
GtkTreeIter iter;
|
||||
|
||||
for (i = 0; !scm_is_null (rpt_guids); i++)
|
||||
{
|
||||
gchar *guid_str = scm_to_utf8_string (SCM_CAR(rpt_guids));
|
||||
gchar *name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name,
|
||||
SCM_CAR(rpt_guids), SCM_BOOL_F));
|
||||
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
COL_INV_NAME, name,
|
||||
COL_INV_GUID, guid_str,
|
||||
COL_INV_MISSING, FALSE,
|
||||
-1);
|
||||
g_free (name);
|
||||
g_free (guid_str);
|
||||
|
||||
rpt_guids = SCM_CDR(rpt_guids);
|
||||
}
|
||||
}
|
||||
|
||||
have_default = select_default (combo, default_guid);
|
||||
|
||||
if (!have_default)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
QofBook *book = gnc_get_current_book ();
|
||||
default_name = qof_book_get_default_invoice_report_name (book);
|
||||
|
||||
gtk_list_store_prepend (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
COL_INV_NAME, default_name,
|
||||
COL_INV_GUID, default_guid,
|
||||
COL_INV_MISSING, TRUE,
|
||||
-1);
|
||||
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(combo), &iter);
|
||||
}
|
||||
g_free (default_guid);
|
||||
return default_name;
|
||||
}
|
||||
|
||||
static void
|
||||
combo_changed_cb (GtkComboBox *widget, gpointer user_data)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_combo_box_get_active_iter (widget, &iter))
|
||||
{
|
||||
GtkTreeModel *model = gtk_combo_box_get_model (widget);
|
||||
gboolean missing;
|
||||
gtk_tree_model_get (model, &iter, COL_INV_MISSING, &missing, -1);
|
||||
// set visibility of the warning image
|
||||
gtk_widget_set_visible (GTK_WIDGET(user_data), missing);
|
||||
gtk_widget_queue_resize (GTK_WIDGET(widget));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_default_print_report_list (GtkWidget *combo, GtkWidget *warning)
|
||||
{
|
||||
gchar *default_name = update_invoice_list (combo);
|
||||
|
||||
if (default_name)
|
||||
{
|
||||
/* Translators: %s is the default invoice report name. */
|
||||
gchar *tool_tip = g_strdup_printf (_("'%s' is missing"),
|
||||
default_name);
|
||||
gtk_widget_show (warning);
|
||||
|
||||
gtk_widget_set_tooltip_text (warning, tool_tip);
|
||||
g_free (tool_tip);
|
||||
}
|
||||
g_free (default_name);
|
||||
g_signal_connect (G_OBJECT(combo), "changed",
|
||||
G_CALLBACK(combo_changed_cb), warning);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_default_print_report_list_combo_set_report (GtkComboBox *cbox,
|
||||
const gchar *guid)
|
||||
{
|
||||
if (guid && *guid)
|
||||
select_default (GTK_WIDGET(cbox), guid);
|
||||
else
|
||||
select_default (GTK_WIDGET(cbox), gnc_get_builtin_default_invoice_print_report ());
|
||||
}
|
||||
|
||||
gchar*
|
||||
gnc_default_print_report_list_combo_get_report (GtkComboBox *cbox)
|
||||
{
|
||||
GtkTreeModel *model = gtk_combo_box_get_model (cbox);
|
||||
GtkTreeIter iter;
|
||||
gchar *report = NULL;
|
||||
|
||||
if (gtk_combo_box_get_active_iter (cbox, &iter))
|
||||
{
|
||||
gchar *report_guid;
|
||||
gchar *report_name;
|
||||
gtk_tree_model_get (model, &iter, COL_INV_NAME, &report_name,
|
||||
COL_INV_GUID, &report_guid,
|
||||
-1);
|
||||
|
||||
report = g_strconcat (report_guid, "/", report_name, NULL);
|
||||
g_free (report_guid);
|
||||
g_free (report_name);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
static GtkWidget * gnc_owner_new (GtkWidget *label, GtkWidget *hbox,
|
||||
QofBook *book, GncOwner *owner,
|
||||
GNCSearchType type)
|
||||
|
@ -41,6 +41,54 @@ extern "C" {
|
||||
|
||||
#define GNC_PREF_AUTO_PAY "auto-pay"
|
||||
|
||||
/** Retrieve the buitin guid for the Invoice Report to be
|
||||
* used as the default to print Invoices
|
||||
*
|
||||
* @return The guid of the saved Invoice Report
|
||||
*/
|
||||
const char *gnc_get_builtin_default_invoice_print_report (void);
|
||||
|
||||
/** Migrate the Default Invoice Report from prefs to book properties
|
||||
* used to print Invoices
|
||||
*
|
||||
* @return The guid of the saved Invoice Report
|
||||
*/
|
||||
const char * gnc_migrate_default_invoice_print_report (void);
|
||||
|
||||
/** Retrieve the guid of the Invoice Report to be used to
|
||||
* print Invoices
|
||||
*
|
||||
* @return The guid of the saved Invoice Report
|
||||
*/
|
||||
char *gnc_get_default_invoice_print_report (void);
|
||||
|
||||
/** Setup a combo used for displaying list of Invoice Reports.
|
||||
*
|
||||
* @param combo The GtkComboBox that presents the list.
|
||||
*
|
||||
* @param warning The warning image, displayed if the default guid is
|
||||
* not in the Invoice list.
|
||||
*/
|
||||
void gnc_default_print_report_list (GtkWidget *combo, GtkWidget *warning);
|
||||
|
||||
/** Retrieve the string representing the Invoice Report used as the default
|
||||
* to print Invoices. This is a concatination of report name and guid
|
||||
*
|
||||
* @param combo The GtkComboBox that presents the list.
|
||||
*
|
||||
* @return The string used to represent the selected Invoice Report
|
||||
*/
|
||||
gchar *gnc_default_print_report_list_combo_get_report (GtkComboBox *cbox);
|
||||
|
||||
/** Set the active report to the guid string
|
||||
*
|
||||
* @param combo The GtkComboBox that presents the list.
|
||||
*
|
||||
* @param guid The guid of the Invoice Report
|
||||
*/
|
||||
void gnc_default_print_report_list_combo_set_report (GtkComboBox *cbox,
|
||||
const gchar *guid);
|
||||
|
||||
|
||||
GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
|
||||
QofBook *book, GncOwner *owner);
|
||||
|
@ -183,6 +183,54 @@ create_option_widget<GncOptionUIType::TAX_TABLE>(GncOption& option,
|
||||
wrap_widget(option, widget, page_box, row);
|
||||
}
|
||||
|
||||
class GncGtkInvReportUIItem : public GncOptionGtkUIItem
|
||||
{
|
||||
public:
|
||||
GncGtkInvReportUIItem(GtkWidget* widget) :
|
||||
GncOptionGtkUIItem(widget, GncOptionUIType::INV_REPORT) {}
|
||||
void set_ui_item_from_option(GncOption& option) noexcept override
|
||||
{
|
||||
auto guid_string{option.get_value<std::string>()};
|
||||
gnc_default_print_report_list_combo_set_report (GTK_COMBO_BOX(get_widget()),
|
||||
guid_string.c_str());
|
||||
}
|
||||
void set_option_from_ui_item(GncOption& option) noexcept override
|
||||
{
|
||||
auto report_guid_name = gnc_default_print_report_list_combo_get_report (GTK_COMBO_BOX(get_widget()));
|
||||
option.set_value(std::string{report_guid_name});
|
||||
g_free (report_guid_name);
|
||||
}
|
||||
};
|
||||
|
||||
template<> void
|
||||
create_option_widget<GncOptionUIType::INV_REPORT>(GncOption& option,
|
||||
GtkGrid *page_box,
|
||||
int row)
|
||||
{
|
||||
constexpr const char* glade_file{"business-options-gnome.glade"};
|
||||
constexpr const char* glade_store{"liststore_print_invoice"};
|
||||
constexpr const char* glade_hbox{"invoice_report_hbox"};
|
||||
constexpr const char* glade_menu{"invoice_report_combo"};
|
||||
constexpr const char* glade_warning{"invoice_warning_image"};
|
||||
auto builder{gtk_builder_new()};
|
||||
|
||||
gnc_builder_add_from_file(builder, glade_file, glade_store);
|
||||
gnc_builder_add_from_file(builder, glade_file, glade_hbox);
|
||||
auto widget{GTK_WIDGET(gtk_builder_get_object(builder, glade_menu))};
|
||||
auto widget_hbox{GTK_WIDGET(gtk_builder_get_object(builder, glade_hbox))};
|
||||
auto widget_warning{GTK_WIDGET(gtk_builder_get_object(builder, glade_warning))};
|
||||
g_object_set_data(G_OBJECT(widget), "warning-image", widget_warning);
|
||||
gnc_default_print_report_list (GTK_WIDGET(widget), GTK_WIDGET(widget_warning));
|
||||
option.set_ui_item(std::make_unique<GncGtkInvReportUIItem>(widget));
|
||||
option.set_ui_item_from_option();
|
||||
|
||||
g_signal_connect (G_OBJECT (widget), "changed",
|
||||
G_CALLBACK (gnc_option_changed_widget_cb), &option);
|
||||
|
||||
wrap_widget (option, widget_hbox, page_box, row);
|
||||
g_object_unref(builder); // Needs to wait until after widget has been reffed.
|
||||
}
|
||||
|
||||
void
|
||||
gnc_business_options_gnome_initialize(void)
|
||||
{
|
||||
@ -198,4 +246,6 @@ gnc_business_options_gnome_initialize(void)
|
||||
create_option_widget<GncOptionUIType::INVOICE>);
|
||||
GncOptionUIFactory::set_func(GncOptionUIType::TAX_TABLE,
|
||||
create_option_widget<GncOptionUIType::TAX_TABLE>);
|
||||
GncOptionUIFactory::set_func(GncOptionUIType::INV_REPORT,
|
||||
create_option_widget<GncOptionUIType::INV_REPORT>);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <libguile.h>
|
||||
#include "swig-runtime.h"
|
||||
|
||||
#include "business-gnome-utils.h"
|
||||
#include "dialog-custom-report.h"
|
||||
#include "dialog-utils.h"
|
||||
#include "gnc-main-window.h"
|
||||
@ -36,6 +37,7 @@
|
||||
#include "gnc-guile-utils.h"
|
||||
#include "gnc-gui-query.h"
|
||||
#include "gnc-ui.h"
|
||||
#include "gnc-ui-util.h"
|
||||
#include "gnc-report.h"
|
||||
#include "gnc-plugin-page-report.h"
|
||||
|
||||
@ -469,7 +471,23 @@ custom_report_name_edited_cb(GtkCellRendererText *renderer, gchar *path, gchar *
|
||||
return;
|
||||
|
||||
if (scm_is_true (scm_call_2 (unique_name_func, guid, new_name_scm)))
|
||||
{
|
||||
gchar *default_guid = gnc_get_default_invoice_print_report ();
|
||||
|
||||
custom_report_edit_report_name (guid, crd, new_text);
|
||||
|
||||
// check to see if default report name has been changed
|
||||
if (g_strcmp0 (default_guid, scm_to_utf8_string (guid)) == 0)
|
||||
{
|
||||
QofBook *book = gnc_get_current_book ();
|
||||
gchar *default_name = qof_book_get_default_invoice_report_name (book);
|
||||
|
||||
if (g_strcmp0 (default_name, new_text) != 0)
|
||||
qof_book_set_default_invoice_report (book, default_guid, new_text);
|
||||
g_free (default_name);
|
||||
}
|
||||
g_free (default_guid);
|
||||
}
|
||||
else
|
||||
gnc_error_dialog (GTK_WINDOW (crd->dialog), "%s",
|
||||
_("A saved report configuration with this name already exists, please choose another name.") );
|
||||
|
@ -783,19 +783,25 @@ gnc_invoice_window_print_invoice(GtkWindow *parent, GncInvoice *invoice)
|
||||
{
|
||||
SCM func, arg, arg2;
|
||||
SCM args = SCM_EOL;
|
||||
SCM is_invoice_guid;
|
||||
SCM scm_guid;
|
||||
int report_id;
|
||||
const char *reportname = gnc_plugin_business_get_invoice_printreport();
|
||||
char *report_guid = gnc_get_default_invoice_print_report ();
|
||||
GncPluginPage *reportPage = NULL;
|
||||
|
||||
g_return_val_if_fail (invoice, NULL);
|
||||
if (!reportname)
|
||||
reportname = "5123a759ceb9483abf2182d01c140e8d"; // fallback if the option lookup failed
|
||||
|
||||
is_invoice_guid = scm_c_eval_string ("gnc:report-is-invoice-report?");
|
||||
scm_guid = scm_from_utf8_string (report_guid);
|
||||
|
||||
if (scm_is_false (scm_call_1 (is_invoice_guid, scm_guid)))
|
||||
report_guid = g_strdup (gnc_get_builtin_default_invoice_print_report ()); // fallback if the option lookup failed
|
||||
|
||||
func = scm_c_eval_string ("gnc:invoice-report-create");
|
||||
g_return_val_if_fail (scm_is_procedure (func), NULL);
|
||||
|
||||
arg = SWIG_NewPointerObj(invoice, SWIG_TypeQuery("_p__gncInvoice"), 0);
|
||||
arg2 = scm_from_utf8_string(reportname);
|
||||
arg2 = scm_from_utf8_string (report_guid);
|
||||
args = scm_cons2 (arg, arg2, args);
|
||||
|
||||
/* scm_gc_protect_object(func); */
|
||||
@ -810,7 +816,7 @@ gnc_invoice_window_print_invoice(GtkWindow *parent, GncInvoice *invoice)
|
||||
reportPage = gnc_plugin_page_report_new (report_id);
|
||||
gnc_main_window_open_page (GNC_MAIN_WINDOW (parent), reportPage);
|
||||
}
|
||||
|
||||
g_free (report_guid);
|
||||
return reportPage;
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,6 @@ static void bind_extra_toolbuttons_visibility (GncMainWindow *mainwindow);
|
||||
#define PLUGIN_UI_FILENAME "gnc-plugin-business.ui"
|
||||
|
||||
#define GNC_PREF_EXTRA_TOOLBUTTONS "enable-toolbuttons"
|
||||
#define GNC_PREF_INV_PRINT_RPT "invoice-printreport"
|
||||
|
||||
/** This variable maintains a pointer to the last window where a
|
||||
* Business command was executed. It is used to determine where new
|
||||
@ -1050,27 +1049,3 @@ gnc_plugin_business_add_to_window (GncPlugin *plugin,
|
||||
G_CALLBACK(gnc_plugin_business_main_window_menu_changed),
|
||||
plugin);
|
||||
}
|
||||
|
||||
static const char* invoice_printreport_values[] =
|
||||
{
|
||||
/* The list below are the guids of reports that can
|
||||
* be used to print an invoice.
|
||||
* Important: this list must be kept in sync with the one at the end
|
||||
* of business-prefs.glade
|
||||
*/
|
||||
"5123a759ceb9483abf2182d01c140e8d", // "Printable Invoice"
|
||||
"0769e242be474010b4acf264a5512e6e", // "Tax Invoice"
|
||||
"67112f318bef4fc496bdc27d106bbda4", // "Easy Invoice"
|
||||
"3ce293441e894423a2425d7a22dd1ac6", // "Fancy Invoice"
|
||||
NULL
|
||||
};
|
||||
|
||||
const char *
|
||||
gnc_plugin_business_get_invoice_printreport (void)
|
||||
{
|
||||
int value = gnc_prefs_get_int (GNC_PREFS_GROUP_INVOICE, GNC_PREF_INV_PRINT_RPT);
|
||||
if (value >= 0 && value < 4)
|
||||
return invoice_printreport_values[value];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
@ -64,8 +64,6 @@ void gnc_invoice_remind_bills_due (GtkWindow *parent);
|
||||
void gnc_invoice_remind_invoices_due (GtkWindow *parent);
|
||||
void gnc_invoice_remind_bills_due_cb (void);
|
||||
void gnc_invoice_remind_invoices_due_cb (void);
|
||||
const char *gnc_plugin_business_get_invoice_printreport(void);
|
||||
|
||||
|
||||
void gnc_plugin_business_split_reg_ui_update (GncPluginPage *plugin_page);
|
||||
|
||||
|
@ -2,6 +2,56 @@
|
||||
<!-- Generated with glade 3.38.2 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.22"/>
|
||||
<object class="GtkListStore" id="liststore_print_invoice">
|
||||
<columns>
|
||||
<!-- column-name title -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name guid -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name missing -->
|
||||
<column type="gboolean"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkWindow" id="dummy_toplevel_window2">
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="invoice_report_hbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkComboBox" id="invoice_report_combo">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="model">liststore_print_invoice</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" id="cell_renderer_text"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage" id="invoice_warning_image">
|
||||
<property name="can-focus">False</property>
|
||||
<property name="no-show-all">True</property>
|
||||
<property name="icon-name">dialog-warning</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkListStore" id="taxtable_store">
|
||||
<columns>
|
||||
<!-- column-name taxtable_name -->
|
||||
|
@ -32,6 +32,7 @@
|
||||
(use-modules (gnucash gnome-utils))
|
||||
(use-modules (ice-9 match))
|
||||
(use-modules (srfi srfi-1))
|
||||
(use-modules (srfi srfi-2))
|
||||
(use-modules (srfi srfi-9))
|
||||
(use-modules (srfi srfi-26))
|
||||
(use-modules (gnucash report report-register-hooks))
|
||||
@ -46,6 +47,7 @@
|
||||
(export <report>)
|
||||
(export gnc:all-report-template-guids)
|
||||
(export gnc:custom-report-template-guids)
|
||||
(export gnc:custom-report-invoice-template-guids)
|
||||
(export gnc:define-report)
|
||||
(export gnc:delete-report)
|
||||
(export gnc:find-report-template)
|
||||
@ -75,6 +77,7 @@
|
||||
(export gnc:report-export-thunk)
|
||||
(export gnc:report-export-types)
|
||||
(export gnc:report-id)
|
||||
(export gnc:report-is-invoice-report?)
|
||||
(export gnc:report-menu-name)
|
||||
(export gnc:report-name)
|
||||
(export gnc:report-needs-save?)
|
||||
@ -169,7 +172,7 @@
|
||||
(make-new-record-template version name report-guid parent-type options-generator
|
||||
options-cleanup-cb options-changed-cb
|
||||
renderer in-menu? menu-path menu-name
|
||||
menu-tip export-types export-thunk)
|
||||
menu-tip hook export-types export-thunk)
|
||||
report-template?
|
||||
(version report-template-version)
|
||||
(report-guid report-template-report-guid report-template-set-report-guid!)
|
||||
@ -183,11 +186,12 @@
|
||||
(menu-path report-template-menu-path)
|
||||
(menu-name report-template-menu-name)
|
||||
(menu-tip report-template-menu-tip)
|
||||
(hook report-template-hook)
|
||||
(export-types report-template-export-types)
|
||||
(export-thunk report-template-export-thunk))
|
||||
|
||||
(define (make-report-template)
|
||||
(make-new-record-template #f #f #f #f #f #f #f #f #t #f #f #f #f #f))
|
||||
(make-new-record-template #f #f #f #f #f #f #f #f #t #f #f #f #f #f #f))
|
||||
(define gnc:report-template-version report-template-version)
|
||||
(define gnc:report-template-report-guid report-template-report-guid)
|
||||
(define gnc:report-template-set-report-guid! report-template-set-report-guid!)
|
||||
@ -203,6 +207,7 @@
|
||||
(define gnc:report-template-menu-path report-template-menu-path)
|
||||
(define gnc:report-template-menu-name report-template-menu-name)
|
||||
(define gnc:report-template-menu-tip report-template-menu-tip)
|
||||
(define gnc:report-template-hook report-template-hook)
|
||||
(define gnc:report-template-export-types report-template-export-types)
|
||||
(define gnc:report-template-export-thunk report-template-export-thunk)
|
||||
|
||||
@ -450,6 +455,21 @@ not found.")))
|
||||
(define (gnc:custom-report-template-guids)
|
||||
(map car (gnc:custom-report-templates-list)))
|
||||
|
||||
(define (gnc:report-is-invoice-report? guid)
|
||||
(let ((tmpl (gnc:find-report-template guid)))
|
||||
(cond
|
||||
((not tmpl) #f)
|
||||
((eq? (gnc:report-template-hook tmpl) 'invoice) #t)
|
||||
(else (and-let* ((type (gnc:report-template-parent-type tmpl))
|
||||
(template (gnc:find-report-template type)))
|
||||
(eq? (gnc:report-template-hook template) 'invoice))))))
|
||||
|
||||
;; return a list of the invoice report template guids.
|
||||
(define (gnc:custom-report-invoice-template-guids)
|
||||
(hash-fold
|
||||
(lambda (k v p) (if (gnc:report-is-invoice-report? k) (cons k p) p))
|
||||
'() *gnc:_report-templates_*))
|
||||
|
||||
(define (gnc:find-report-template guid)
|
||||
(hash-ref *gnc:_report-templates_* guid))
|
||||
|
||||
|
@ -851,6 +851,7 @@ for styling the invoice. Please see the exported report for the CSS class names.
|
||||
'menu-path (list gnc:menuname-business-reports)
|
||||
'options-generator (lambda () (options-generator 'invoice))
|
||||
'renderer reg-renderer
|
||||
'hook 'invoice
|
||||
'in-menu? #t)
|
||||
|
||||
(gnc:define-report
|
||||
@ -860,6 +861,7 @@ for styling the invoice. Please see the exported report for the CSS class names.
|
||||
'menu-path (list gnc:menuname-business-reports)
|
||||
'options-generator (lambda () (options-generator 'easy-invoice))
|
||||
'renderer reg-renderer
|
||||
'hook 'invoice
|
||||
'in-menu? #t)
|
||||
|
||||
(gnc:define-report
|
||||
@ -869,5 +871,6 @@ for styling the invoice. Please see the exported report for the CSS class names.
|
||||
'menu-path (list gnc:menuname-business-reports)
|
||||
'options-generator (lambda () (options-generator 'fancy-invoice))
|
||||
'renderer reg-renderer
|
||||
'hook 'invoice
|
||||
'in-menu? #t)
|
||||
|
||||
|
@ -304,6 +304,7 @@
|
||||
'menu-name (N_ "Tax Invoice")
|
||||
'menu-tip (N_ "Display a customer invoice with tax columns (using eguile template)")
|
||||
'menu-path (list gnc:menuname-business-reports)
|
||||
'hook 'invoice
|
||||
'options-generator options-generator
|
||||
'renderer report-renderer)
|
||||
|
||||
@ -330,5 +331,6 @@
|
||||
'menu-name (N_ "Australian Tax Invoice")
|
||||
'menu-tip (N_ "Display an Australian customer invoice with tax columns (using eguile template)")
|
||||
'menu-path (list gnc:menuname-business-reports)
|
||||
'hook 'invoice
|
||||
'options-generator au-tax-options-generator
|
||||
'renderer report-renderer)
|
||||
|
@ -66,6 +66,7 @@ enum class GncOptionUIType : unsigned int
|
||||
INVOICE,
|
||||
JOB,
|
||||
TAX_TABLE,
|
||||
INV_REPORT,
|
||||
QUERY,
|
||||
REPORT_PLACEMENT,
|
||||
MAX_VALUE, //Nake sure this one is always last
|
||||
|
@ -883,6 +883,16 @@ gnc_register_taxtable_option(GncOptionDB* db, const char* section,
|
||||
db->register_option(section, std::move(option));
|
||||
}
|
||||
|
||||
void
|
||||
gnc_register_invoice_print_report_option(GncOptionDB* db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string, std::string value)
|
||||
{
|
||||
GncOption option{section, name, key, doc_string,
|
||||
value, GncOptionUIType::INV_REPORT};
|
||||
db->register_option(section, std::move(option));
|
||||
}
|
||||
|
||||
void
|
||||
gnc_register_counter_option(GncOptionDB* db, const char* section,
|
||||
const char* name, const char* key,
|
||||
@ -1266,13 +1276,16 @@ gnc_option_db_book_options(GncOptionDB* odb)
|
||||
gnc_register_string_option(odb, business_section, N_("Company ID"), "c5",
|
||||
N_("The ID for your company (eg 'Tax-ID: 00-000000)."),
|
||||
empty_string);
|
||||
|
||||
gnc_register_invoice_print_report_option(odb, business_section,
|
||||
OPTION_NAME_DEFAULT_INVOICE_REPORT, "e",
|
||||
N_("The invoice report to be used for printing."),
|
||||
empty_string);
|
||||
gnc_register_taxtable_option(odb, business_section,
|
||||
N_("Default Customer TaxTable"), "e",
|
||||
N_("Default Customer TaxTable"), "f1",
|
||||
N_("The default tax table to apply to customers."),
|
||||
nullptr);
|
||||
gnc_register_taxtable_option(odb, business_section,
|
||||
N_("Default Vendor TaxTable"), "f",
|
||||
N_("Default Vendor TaxTable"), "f2",
|
||||
N_("The default tax table to apply to vendors."),
|
||||
nullptr);
|
||||
gnc_register_dateformat_option(odb, business_section,
|
||||
|
@ -713,6 +713,31 @@ inline void gnc_register_taxtable_option(const GncOptionDBPtr& db,
|
||||
doc_string, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new print report option and register it in the options database.
|
||||
*
|
||||
* @param db A GncOptionDB* for calling from C. Caller retains ownership.
|
||||
* @param section The database section for the option.
|
||||
* @param name The option name.
|
||||
* @param doc_string A description of the option. This will be used in tooltips and should be marked for translation.
|
||||
* @param value The initial and default value for the option.
|
||||
*/
|
||||
void gnc_register_invoice_print_report_option(GncOptionDB* db, const char* section,
|
||||
const char* name, const char* key,
|
||||
const char* doc_string, std::string value);
|
||||
|
||||
/**
|
||||
* As above but takes a const GncOptionDBPtr& (const std::unique_ptr<GncOptionDB>&) for calling from C++.
|
||||
*/
|
||||
inline void gnc_register_invoice_print_report_option(const GncOptionDBPtr& db,
|
||||
const char* section, const char* name,
|
||||
const char* key, const char* doc_string,
|
||||
std::string value)
|
||||
{
|
||||
gnc_register_invoice_print_report_option(db.get(), section, name, key,
|
||||
doc_string, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new counter option and register it in the options database.
|
||||
*
|
||||
|
@ -1014,6 +1014,90 @@ qof_book_option_num_autoreadonly_changed_cb (GObject *gobject,
|
||||
book->cached_num_days_autoreadonly_isvalid = FALSE;
|
||||
}
|
||||
|
||||
static KvpValue*
|
||||
get_option_default_invoice_report_value (QofBook *book)
|
||||
{
|
||||
KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE(book));
|
||||
return root->get_slot ({KVP_OPTION_PATH,
|
||||
OPTION_SECTION_BUSINESS,
|
||||
OPTION_NAME_DEFAULT_INVOICE_REPORT});
|
||||
}
|
||||
|
||||
void
|
||||
qof_book_set_default_invoice_report (QofBook *book, const gchar *guid,
|
||||
const gchar *name)
|
||||
{
|
||||
const gchar *existing_guid_name = nullptr;
|
||||
gchar *new_guid_name;
|
||||
|
||||
if (!guid)
|
||||
return;
|
||||
|
||||
KvpValue *value = get_option_default_invoice_report_value (book);
|
||||
|
||||
if (value)
|
||||
existing_guid_name = {value->get<const char*>()};
|
||||
|
||||
new_guid_name = g_strconcat (guid, "/", name, nullptr);
|
||||
|
||||
if (g_strcmp0 (existing_guid_name, new_guid_name) != 0)
|
||||
{
|
||||
auto value = new KvpValue {g_strdup(new_guid_name)};
|
||||
KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE(book));
|
||||
qof_book_begin_edit (book);
|
||||
delete root->set_path ({KVP_OPTION_PATH,
|
||||
OPTION_SECTION_BUSINESS,
|
||||
OPTION_NAME_DEFAULT_INVOICE_REPORT}, value);
|
||||
qof_instance_set_dirty (QOF_INSTANCE(book));
|
||||
qof_book_commit_edit (book);
|
||||
}
|
||||
g_free (new_guid_name);
|
||||
}
|
||||
|
||||
gchar *
|
||||
qof_book_get_default_invoice_report_guid (const QofBook *book)
|
||||
{
|
||||
KvpValue *value = get_option_default_invoice_report_value (const_cast<QofBook*>(book));
|
||||
gchar *report_guid = nullptr;
|
||||
|
||||
if (value)
|
||||
{
|
||||
auto str {value->get<const char*>()};
|
||||
auto ptr = strchr (str, '/');
|
||||
if (ptr)
|
||||
{
|
||||
if (ptr - str == GUID_ENCODING_LENGTH)
|
||||
{
|
||||
if (strlen (str) > GUID_ENCODING_LENGTH + 1)
|
||||
report_guid = g_strndup (&str[0], GUID_ENCODING_LENGTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
return report_guid;
|
||||
}
|
||||
|
||||
gchar *
|
||||
qof_book_get_default_invoice_report_name (const QofBook *book)
|
||||
{
|
||||
KvpValue *value = get_option_default_invoice_report_value (const_cast<QofBook*>(book));
|
||||
gchar *report_name = nullptr;
|
||||
|
||||
if (value)
|
||||
{
|
||||
auto str {value->get<const char*>()};
|
||||
auto ptr = strchr (str, '/');
|
||||
if (ptr)
|
||||
{
|
||||
if (ptr - str == GUID_ENCODING_LENGTH)
|
||||
{
|
||||
if (strlen (str) > GUID_ENCODING_LENGTH + 1)
|
||||
report_name = g_strdup (&str[GUID_ENCODING_LENGTH + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return report_name;
|
||||
}
|
||||
|
||||
/* Note: this will fail if the book slots we're looking for here are flattened at some point !
|
||||
* When that happens, this function can be removed. */
|
||||
static Path opt_name_to_path (const char* opt_name)
|
||||
|
@ -289,6 +289,22 @@ gint qof_book_get_num_days_autoreadonly (const QofBook *book);
|
||||
* g_date_free() the object afterwards. */
|
||||
GDate* qof_book_get_autoreadonly_gdate (const QofBook *book);
|
||||
|
||||
/** Save the Invoice Report name / guid to be used as the default for printing
|
||||
* Invoices
|
||||
*/
|
||||
void qof_book_set_default_invoice_report (QofBook *book, const gchar *guid,
|
||||
const gchar *name);
|
||||
|
||||
/** Get the guid of the Invoice Report to be used as the default for printing
|
||||
* Invoices
|
||||
*/
|
||||
gchar * qof_book_get_default_invoice_report_guid (const QofBook *book);
|
||||
|
||||
/** Get the name of the Invoice Report to be used as the default for printing
|
||||
* Invoices
|
||||
*/
|
||||
gchar * qof_book_get_default_invoice_report_name (const QofBook *book);
|
||||
|
||||
/** Returns TRUE if this book uses split action field as the 'Num' field, FALSE
|
||||
* if it uses transaction number field */
|
||||
gboolean qof_book_use_split_action_for_num_field (const QofBook *book);
|
||||
|
@ -69,6 +69,10 @@
|
||||
#define OPTION_SECTION_BUDGETING N_("Budgeting")
|
||||
#define OPTION_NAME_DEFAULT_BUDGET N_("Default Budget")
|
||||
|
||||
#define OPTION_SECTION_BUSINESS N_("Business")
|
||||
|
||||
#define OPTION_NAME_DEFAULT_INVOICE_REPORT N_("Default Invoice Report")
|
||||
|
||||
/** @} */
|
||||
|
||||
/* For the grep-happy:
|
||||
|
Loading…
Reference in New Issue
Block a user