33 #include <qofinstance-p.h>
36 #include "gncAddressP.h"
37 #include "gncBillTermP.h"
40 #include "gncTaxTableP.h"
42 #include "gncVendorP.h"
44 static gint gs_address_event_handler_id = 0;
46 gpointer user_data, gpointer event_data);
48 static const char* qofVendorGetTaxIncluded(
const GncVendor *vendor);
49 static void qofVendorSetTaxIncluded(
GncVendor *vendor,
const char* type_string);
62 gboolean taxtable_override;
75 #define _GNC_MOD_NAME GNC_ID_VENDOR
80 G_INLINE_FUNC
void mark_vendor (
GncVendor *vendor);
83 qof_instance_set_dirty(&vendor->inst);
97 PROP_TAXTABLE_OVERRIDE,
102 PROP_TAX_INCLUDED_STR,
105 PROP_PAYMENT_LAST_ACCT,
109 G_DEFINE_TYPE(
GncVendor, gnc_vendor, QOF_TYPE_INSTANCE);
117 gnc_vendor_dispose(GObject *vendorp)
119 G_OBJECT_CLASS(gnc_vendor_parent_class)->dispose(vendorp);
123 gnc_vendor_finalize(GObject* vendorp)
125 G_OBJECT_CLASS(gnc_vendor_parent_class)->finalize(vendorp);
135 gnc_vendor_get_property (GObject *
object,
143 g_return_if_fail(GNC_IS_VENDOR(
object));
145 vendor = GNC_VENDOR(
object);
149 g_value_set_string(value, vendor->name);
152 g_value_set_string(value, vendor->id);
155 g_value_set_string(value, vendor->notes);
158 g_value_take_object(value, vendor->currency);
161 g_value_set_boolean(value, vendor->active);
163 case PROP_TAXTABLE_OVERRIDE:
164 g_value_set_boolean(value, vendor->taxtable_override);
167 g_value_take_object(value, vendor->terms);
170 g_value_take_object(value, vendor->taxtable);
173 g_value_take_object(value, vendor->addr);
175 case PROP_TAX_INCLUDED:
176 g_value_set_int(value, vendor->taxincluded);
178 case PROP_TAX_INCLUDED_STR:
179 g_value_set_string(value, qofVendorGetTaxIncluded(vendor));
181 case PROP_PDF_DIRNAME:
182 key = OWNER_EXPORT_PDF_DIRNAME;
183 qof_instance_get_kvp (QOF_INSTANCE (vendor), key, value);
185 case PROP_LAST_POSTED:
186 key = LAST_POSTED_TO_ACCT;
187 qof_instance_get_kvp (QOF_INSTANCE (vendor), key, value);
189 case PROP_PAYMENT_LAST_ACCT:
190 key = GNC_PAYMENT
"/" GNC_LAST_ACCOUNT;
191 qof_instance_get_kvp (QOF_INSTANCE (vendor), key, value);
194 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
200 gnc_vendor_set_property (GObject *
object,
208 g_return_if_fail(GNC_IS_VENDOR(
object));
210 vendor = GNC_VENDOR(
object);
211 g_assert (qof_instance_get_editlevel(vendor));
216 gncVendorSetName(vendor, g_value_get_string(value));
219 gncVendorSetID(vendor, g_value_get_string(value));
222 gncVendorSetNotes(vendor, g_value_get_string(value));
225 gncVendorSetCurrency(vendor, g_value_get_object(value));
228 gncVendorSetActive(vendor, g_value_get_boolean(value));
230 case PROP_TAXTABLE_OVERRIDE:
231 gncVendorSetTaxTableOverride(vendor, g_value_get_boolean(value));
234 gncVendorSetTerms(vendor, g_value_get_object(value));
237 gncVendorSetTaxTable(vendor, g_value_get_object(value));
240 qofVendorSetAddr(vendor, g_value_get_object(value));
242 case PROP_TAX_INCLUDED:
243 gncVendorSetTaxIncluded(vendor, (
GncTaxIncluded)g_value_get_int(value));
245 case PROP_TAX_INCLUDED_STR:
246 qofVendorSetTaxIncluded(vendor, g_value_get_string(value));
248 case PROP_PDF_DIRNAME:
249 key = OWNER_EXPORT_PDF_DIRNAME;
250 qof_instance_set_kvp (QOF_INSTANCE (vendor), key, value);
252 case PROP_LAST_POSTED:
253 key = LAST_POSTED_TO_ACCT;
254 qof_instance_set_kvp (QOF_INSTANCE (vendor), key, value);
256 case PROP_PAYMENT_LAST_ACCT:
257 key = GNC_PAYMENT
"/" GNC_LAST_ACCOUNT;
258 qof_instance_set_kvp (QOF_INSTANCE (vendor), key, value);
261 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
272 g_return_val_if_fail(inst != NULL, FALSE);
273 g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
275 v = GNC_VENDOR(inst);
277 if (GNC_IS_BILLTERM(ref))
279 return (v->terms == GNC_BILLTERM(ref));
281 else if (GNC_IS_TAXTABLE(ref))
283 return (v->taxtable == GNC_TAXTABLE(ref));
298 if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
309 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
312 gobject_class->dispose = gnc_vendor_dispose;
313 gobject_class->finalize = gnc_vendor_finalize;
314 gobject_class->set_property = gnc_vendor_set_property;
315 gobject_class->get_property = gnc_vendor_get_property;
317 qof_class->get_display_name = NULL;
318 qof_class->refers_to_object = impl_refers_to_object;
319 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
321 g_object_class_install_property
324 g_param_spec_string (
"name",
326 "The vendor name is an arbitrary string "
327 "assigned by the user to provide the vendor name.",
331 g_object_class_install_property
334 g_param_spec_string (
"id",
336 "The vendor id is an arbitrary string "
337 "assigned by the user to identify the vendor.",
341 g_object_class_install_property
344 g_param_spec_string (
"notes",
346 "The vendor notes is an arbitrary string "
347 "assigned by the user to add extra information about the vendor.",
351 g_object_class_install_property
354 g_param_spec_object (
"currency",
356 "The currency property denotes the currency used by this vendor.",
360 g_object_class_install_property
363 g_param_spec_boolean (
"active",
365 "TRUE if the vendor is active. FALSE if inactive.",
369 g_object_class_install_property
371 PROP_TAXTABLE_OVERRIDE,
372 g_param_spec_boolean (
"tax-table-override",
373 "Tax table override",
374 "TRUE if the vendor has a specific tax table which overrides the default "
375 "tax table. FALSE if the default table should be used.",
379 g_object_class_install_property
382 g_param_spec_object (
"terms",
384 "The billing terms used by this vendor.",
388 g_object_class_install_property
391 g_param_spec_object (
"tax-table",
393 "The tax table which applies to this vendor.",
397 g_object_class_install_property
400 g_param_spec_object (
"address",
402 "The address property contains the address information for this vendor.",
406 g_object_class_install_property
409 g_param_spec_int (
"tax-included",
411 "The tax-included property contains the information about tax calculation this vendor.",
417 g_object_class_install_property
419 PROP_TAX_INCLUDED_STR,
420 g_param_spec_string(
"tax-included-string",
421 "Tax included string",
422 "The tax-included-string property contains a character version of tax-included.",
425 g_object_class_install_property
428 g_param_spec_string (
"export-pdf-dir",
429 "Export PDF Directory Name",
430 "A subdirectory for exporting PDF reports which is "
431 "appended to the target directory when writing them "
432 "out. It is retrieved from preferences and stored on "
433 "each 'Owner' object which prints items after "
438 g_object_class_install_property(
441 g_param_spec_boxed(
"invoice-last-posted-account",
442 "Invoice Last Posted Account",
443 "The last account to which an invoice belonging to "
444 "this owner was posted.",
448 g_object_class_install_property(
450 PROP_PAYMENT_LAST_ACCT,
451 g_param_spec_boxed(
"payment-last-account",
452 "Payment Last Account",
453 "The last account to which an payment belonging to "
454 "this owner was posted.",
464 if (!book)
return NULL;
466 vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
469 vendor->id = CACHE_INSERT (
"");
470 vendor->name = CACHE_INSERT (
"");
471 vendor->notes = CACHE_INSERT (
"");
472 vendor->addr = gncAddressCreate (book, &vendor->inst);
474 vendor->active = TRUE;
477 if (gs_address_event_handler_id == 0)
487 void gncVendorDestroy (
GncVendor *vendor)
490 qof_instance_set_destroying(vendor, TRUE);
491 gncVendorCommitEdit (vendor);
494 static void gncVendorFree (
GncVendor *vendor)
500 CACHE_REMOVE (vendor->id);
501 CACHE_REMOVE (vendor->name);
502 CACHE_REMOVE (vendor->notes);
503 gncAddressBeginEdit (vendor->addr);
504 gncAddressDestroy (vendor->addr);
505 g_list_free (vendor->jobs);
508 gncBillTermDecRef (vendor->terms);
509 if (vendor->taxtable)
510 gncTaxTableDecRef (vendor->taxtable);
513 g_object_unref (vendor);
519 #define SET_STR(obj, member, str) { \
522 if (!g_strcmp0 (member, str)) return; \
523 gncVendorBeginEdit (obj); \
524 tmp = CACHE_INSERT (str); \
525 CACHE_REMOVE (member); \
529 void gncVendorSetID (
GncVendor *vendor,
const char *
id)
533 SET_STR(vendor, vendor->id,
id);
534 mark_vendor (vendor);
535 gncVendorCommitEdit (vendor);
538 void gncVendorSetName (
GncVendor *vendor,
const char *name)
542 SET_STR(vendor, vendor->name, name);
543 mark_vendor (vendor);
544 gncVendorCommitEdit (vendor);
547 void gncVendorSetNotes (
GncVendor *vendor,
const char *notes)
551 SET_STR(vendor, vendor->notes, notes);
552 mark_vendor (vendor);
553 gncVendorCommitEdit (vendor);
559 if (vendor->terms == terms)
return;
561 gncVendorBeginEdit (vendor);
563 gncBillTermDecRef (vendor->terms);
564 vendor->terms = terms;
566 gncBillTermIncRef (vendor->terms);
567 mark_vendor (vendor);
568 gncVendorCommitEdit (vendor);
574 if (taxincl == vendor->taxincluded)
return;
575 gncVendorBeginEdit (vendor);
576 vendor->taxincluded = taxincl;
577 mark_vendor (vendor);
578 gncVendorCommitEdit (vendor);
583 if (!vendor || !currency)
return;
584 if (vendor->currency &&
587 gncVendorBeginEdit (vendor);
588 vendor->currency = currency;
589 mark_vendor (vendor);
590 gncVendorCommitEdit (vendor);
593 void gncVendorSetActive (
GncVendor *vendor, gboolean active)
596 if (active == vendor->active)
return;
597 gncVendorBeginEdit (vendor);
598 vendor->active = active;
599 mark_vendor (vendor);
600 gncVendorCommitEdit (vendor);
603 void gncVendorSetTaxTableOverride (
GncVendor *vendor, gboolean
override)
606 if (vendor->taxtable_override ==
override)
return;
607 gncVendorBeginEdit (vendor);
608 vendor->taxtable_override =
override;
609 mark_vendor (vendor);
610 gncVendorCommitEdit (vendor);
616 if (vendor->taxtable == table)
return;
617 gncVendorBeginEdit (vendor);
618 if (vendor->taxtable)
619 gncTaxTableDecRef (vendor->taxtable);
621 gncTaxTableIncRef (table);
622 vendor->taxtable = table;
623 mark_vendor (vendor);
624 gncVendorCommitEdit (vendor);
632 if (!vendor || !addr_ent)
637 if (addr == vendor->addr)
641 if (vendor->addr != NULL)
643 gncAddressBeginEdit(vendor->addr);
644 gncAddressDestroy(vendor->addr);
646 gncVendorBeginEdit(vendor);
648 gncVendorCommitEdit(vendor);
652 qofVendorSetTaxIncluded(
GncVendor *vendor,
const char* type_string)
656 if (!gncTaxIncludedStringToType(type_string, &inc))
660 gncVendorBeginEdit(vendor);
661 vendor->taxincluded = inc;
662 gncVendorCommitEdit(vendor);
668 const char * gncVendorGetID (
const GncVendor *vendor)
670 if (!vendor)
return NULL;
674 const char * gncVendorGetName (
const GncVendor *vendor)
676 if (!vendor)
return NULL;
682 if (!vendor)
return NULL;
686 const char * gncVendorGetNotes (
const GncVendor *vendor)
688 if (!vendor)
return NULL;
689 return vendor->notes;
694 if (!vendor)
return 0;
695 return vendor->terms;
701 return vendor->taxincluded;
706 if (!vendor)
return NULL;
707 return vendor->currency;
710 gboolean gncVendorGetActive (
const GncVendor *vendor)
712 if (!vendor)
return FALSE;
713 return vendor->active;
716 gboolean gncVendorGetTaxTableOverride (
const GncVendor *vendor)
718 if (!vendor)
return FALSE;
719 return vendor->taxtable_override;
724 if (!vendor)
return NULL;
725 return vendor->taxtable;
729 qofVendorGetTaxIncluded(
const GncVendor *vendor)
731 return gncTaxIncludedTypeToString(vendor->taxincluded);
740 if (g_list_index(vendor->jobs, job) == -1)
741 vendor->jobs = g_list_insert_sorted (vendor->jobs, job,
742 (GCompareFunc)gncJobCompare);
754 node = g_list_find (vendor->jobs, job);
761 vendor->jobs = g_list_remove_link (vendor->jobs, node);
762 g_list_free_1 (node);
768 void gncVendorBeginEdit (
GncVendor *vendor)
775 PERR(
"Vendor QofBackend Failure: %d", errcode);
776 gnc_engine_signal_commit_error( errcode );
782 gncAddressClearDirty (vendor->addr);
788 gncVendorFree (vendor);
791 void gncVendorCommitEdit (
GncVendor *vendor)
795 gncVendorOnDone, vendor_free);
803 if (!a && !b)
return 0;
804 if (!a && b)
return 1;
805 if (a && !b)
return -1;
807 return(strcmp(a->name, b->name));
812 if (a == NULL && b == NULL)
return TRUE;
813 if (a == NULL || b == NULL)
return FALSE;
815 g_return_val_if_fail(GNC_IS_VENDOR(a), FALSE);
816 g_return_val_if_fail(GNC_IS_VENDOR(b), FALSE);
818 if (g_strcmp0(a->id, b->id) != 0)
820 PWARN(
"IDs differ: %s vs %s", a->id, b->id);
824 if (g_strcmp0(a->name, b->name) != 0)
826 PWARN(
"Names differ: %s vs %s", a->name, b->name);
830 if (g_strcmp0(a->notes, b->notes) != 0)
832 PWARN(
"Notes differ");
838 PWARN(
"BillTerms differ");
844 PWARN(
"Addresses differ");
850 PWARN(
"Currencies differ");
854 if (!gncTaxTableEqual(a->taxtable, b->taxtable))
856 PWARN(
"Tax tables differ");
860 if (a->taxtable_override != b->taxtable_override)
862 PWARN(
"Tax table override flags differ");
866 if (a->taxincluded != b->taxincluded)
868 PWARN(
"Tax included flags differ");
872 if (a->active != b->active)
874 PWARN(
"Active flags differ");
883 gncVendorIsDirty (
const GncVendor *vendor)
885 if (!vendor)
return FALSE;
887 || gncAddressIsDirty (vendor->addr));
901 gpointer user_data, gpointer event_data)
905 if ((event_type & QOF_EVENT_MODIFY) == 0)
909 if (!GNC_IS_ADDRESS(entity))
913 if (!GNC_IS_VENDOR(event_data))
917 v = GNC_VENDOR(event_data);
918 gncVendorBeginEdit(v);
920 gncVendorCommitEdit(v);
925 static const char * _gncVendorPrintable (gpointer item)
928 if (!item)
return NULL;
933 destroy_vendor_on_book_close(
QofInstance *ent, gpointer data)
937 gncVendorBeginEdit(v);
946 gnc_vendor_book_end(
QofBook* book)
957 DI(.e_type = ) _GNC_MOD_NAME,
958 DI(.type_label = ) "Vendor",
959 DI(.create = ) (gpointer)gncVendorCreate,
960 DI(.book_begin = ) NULL,
961 DI(.book_end = ) gnc_vendor_book_end,
965 DI(.printable = ) _gncVendorPrintable,
969 gboolean gncVendorRegister (
void)
979 VENDOR_TAX_OVERRIDE, QOF_TYPE_BOOLEAN, (
QofAccessFunc)gncVendorGetTaxTableOverride,
983 VENDOR_TAX_TABLE, GNC_ID_TAXTABLE, (
QofAccessFunc)gncVendorGetTaxTable,
987 VENDOR_TAX_INC, QOF_TYPE_STRING, (
QofAccessFunc)qofVendorGetTaxIncluded,
992 { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (
QofAccessFunc)gncVendorGetActive, NULL },
1010 gchar *gncVendorNextID (
QofBook *book)
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
const GncGUID * qof_instance_get_guid(gconstpointer)
QofBook * qof_instance_get_book(gconstpointer)
gboolean qof_collection_is_dirty(const QofCollection *col)
QofBackendError
The errors that can be reported to the GUI & other front-end users.
gchar * qof_book_increment_and_format_counter(QofBook *book, const char *counter_name)
GList * qof_instance_get_referring_object_list_from_collection(const QofCollection *coll, const QofInstance *ref)
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_fcn, const QofParam *params)
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
QofCollection * qof_instance_get_collection(gconstpointer inst)
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
#define QOF_OBJECT_VERSION
gboolean qof_commit_edit(QofInstance *inst)
#define PERR(format, args...)
void qof_collection_foreach(const QofCollection *, QofInstanceForeachCB, gpointer user_data)
gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b)
gint qof_event_register_handler(QofEventHandler handler, gpointer handler_data)
Register a handler for events.
#define PWARN(format, args...)
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean qof_begin_edit(QofInstance *inst)
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
int(* QofSortFunc)(gconstpointer, gconstpointer)
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
void qof_collection_mark_clean(QofCollection *)
int gncVendorCompare(const GncVendor *a, const GncVendor *b)
gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b)
Deeply compare two addresses.
Business Invoice Interface.
gboolean qof_choice_add_class(const char *choice, char *add, char *param_name)
Add the choices for this parameter to the object.
gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b)
void(* QofSetterFunc)(gpointer, gpointer)
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
gboolean qof_object_register(const QofObject *object)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Commodity handling public routines.
const gchar * QofLogModule