33 #include <qofinstance-p.h> 36 #include "gncAddressP.h" 37 #include "gncBillTermP.h" 40 #include "gncTaxTableP.h" 42 #include "gncVendorP.h" 44 static gint vend_qof_event_handler_id = 0;
46 gpointer user_data, gpointer event_data);
47 static void qofVendorSetAddr (GncVendor *vendor,
QofInstance *addr_ent);
48 static const char* qofVendorGetTaxIncluded(
const GncVendor *vendor);
49 static void qofVendorSetTaxIncluded(GncVendor *vendor,
const char* type_string);
60 gnc_commodity * currency;
62 gboolean taxtable_override;
66 gnc_numeric * balance;
71 QofInstanceClass parent_class;
74 static QofLogModule log_module = GNC_MOD_BUSINESS;
76 #define _GNC_MOD_NAME GNC_ID_VENDOR 81 static inline void mark_vendor (GncVendor *vendor);
82 void mark_vendor (GncVendor *vendor)
84 qof_instance_set_dirty(&vendor->inst);
98 PROP_TAXTABLE_OVERRIDE,
103 PROP_TAX_INCLUDED_STR,
106 PROP_PAYMENT_LAST_ACCT,
110 G_DEFINE_TYPE(GncVendor, gnc_vendor, QOF_TYPE_INSTANCE)
113 gnc_vendor_init(GncVendor* vendor)
118 gnc_vendor_dispose(GObject *vendorp)
120 G_OBJECT_CLASS(gnc_vendor_parent_class)->dispose(vendorp);
124 gnc_vendor_finalize(GObject* vendorp)
126 G_OBJECT_CLASS(gnc_vendor_parent_class)->finalize(vendorp);
136 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:
184 case PROP_LAST_POSTED:
187 case PROP_PAYMENT_LAST_ACCT:
191 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
197 gnc_vendor_set_property (GObject *
object,
204 g_return_if_fail(GNC_IS_VENDOR(
object));
206 vendor = GNC_VENDOR(
object);
207 g_assert (qof_instance_get_editlevel(vendor));
212 gncVendorSetName(vendor, g_value_get_string(value));
215 gncVendorSetID(vendor, g_value_get_string(value));
218 gncVendorSetNotes(vendor, g_value_get_string(value));
221 gncVendorSetCurrency(vendor, g_value_get_object(value));
224 gncVendorSetActive(vendor, g_value_get_boolean(value));
226 case PROP_TAXTABLE_OVERRIDE:
227 gncVendorSetTaxTableOverride(vendor, g_value_get_boolean(value));
230 gncVendorSetTerms(vendor, g_value_get_object(value));
233 gncVendorSetTaxTable(vendor, g_value_get_object(value));
236 qofVendorSetAddr(vendor, g_value_get_object(value));
238 case PROP_TAX_INCLUDED:
239 gncVendorSetTaxIncluded(vendor, (
GncTaxIncluded)g_value_get_int(value));
241 case PROP_TAX_INCLUDED_STR:
242 qofVendorSetTaxIncluded(vendor, g_value_get_string(value));
244 case PROP_PDF_DIRNAME:
247 case PROP_LAST_POSTED:
250 case PROP_PAYMENT_LAST_ACCT:
254 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
265 g_return_val_if_fail(inst != NULL, FALSE);
266 g_return_val_if_fail(GNC_IS_VENDOR(inst), FALSE);
268 v = GNC_VENDOR(inst);
270 if (GNC_IS_BILLTERM(ref))
272 return (v->terms == GNC_BILLTERM(ref));
274 else if (GNC_IS_TAXTABLE(ref))
276 return (v->taxtable == GNC_TAXTABLE(ref));
291 if (!GNC_IS_BILLTERM(ref) && !GNC_IS_TAXTABLE(ref))
300 gnc_vendor_class_init (GncVendorClass *klass)
302 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
303 QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
305 gobject_class->dispose = gnc_vendor_dispose;
306 gobject_class->finalize = gnc_vendor_finalize;
307 gobject_class->set_property = gnc_vendor_set_property;
308 gobject_class->get_property = gnc_vendor_get_property;
310 qof_class->get_display_name = NULL;
311 qof_class->refers_to_object = impl_refers_to_object;
312 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
314 g_object_class_install_property
317 g_param_spec_string (
"name",
319 "The vendor name is an arbitrary string " 320 "assigned by the user to provide the vendor name.",
324 g_object_class_install_property
327 g_param_spec_string (
"id",
329 "The vendor id is an arbitrary string " 330 "assigned by the user to identify the vendor.",
334 g_object_class_install_property
337 g_param_spec_string (
"notes",
339 "The vendor notes is an arbitrary string " 340 "assigned by the user to add extra information about the vendor.",
344 g_object_class_install_property
347 g_param_spec_object (
"currency",
349 "The currency property denotes the currency used by this vendor.",
353 g_object_class_install_property
356 g_param_spec_boolean (
"active",
358 "TRUE if the vendor is active. FALSE if inactive.",
362 g_object_class_install_property
364 PROP_TAXTABLE_OVERRIDE,
365 g_param_spec_boolean (
"tax-table-override",
366 "Tax table override",
367 "TRUE if the vendor has a specific tax table which overrides the default " 368 "tax table. FALSE if the default table should be used.",
372 g_object_class_install_property
375 g_param_spec_object (
"terms",
377 "The billing terms used by this vendor.",
381 g_object_class_install_property
384 g_param_spec_object (
"tax-table",
386 "The tax table which applies to this vendor.",
390 g_object_class_install_property
393 g_param_spec_object (
"address",
395 "The address property contains the address information for this vendor.",
399 g_object_class_install_property
402 g_param_spec_int (
"tax-included",
404 "The tax-included property contains the information about tax calculation this vendor.",
410 g_object_class_install_property
412 PROP_TAX_INCLUDED_STR,
413 g_param_spec_string(
"tax-included-string",
414 "Tax included string",
415 "The tax-included-string property contains a character version of tax-included.",
418 g_object_class_install_property
421 g_param_spec_string (
"export-pdf-dir",
422 "Export PDF Directory Name",
423 "A subdirectory for exporting PDF reports which is " 424 "appended to the target directory when writing them " 425 "out. It is retrieved from preferences and stored on " 426 "each 'Owner' object which prints items after " 431 g_object_class_install_property(
434 g_param_spec_boxed(
"invoice-last-posted-account",
435 "Invoice Last Posted Account",
436 "The last account to which an invoice belonging to " 437 "this owner was posted.",
441 g_object_class_install_property(
443 PROP_PAYMENT_LAST_ACCT,
444 g_param_spec_boxed(
"payment-last-account",
445 "Payment Last Account",
446 "The last account to which an payment belonging to " 447 "this owner was posted.",
453 GncVendor *gncVendorCreate (QofBook *book)
457 if (!book)
return NULL;
459 vendor = g_object_new (GNC_TYPE_VENDOR, NULL);
462 vendor->id = CACHE_INSERT (
"");
463 vendor->name = CACHE_INSERT (
"");
464 vendor->notes = CACHE_INSERT (
"");
465 vendor->addr = gncAddressCreate (book, &vendor->inst);
467 vendor->active = TRUE;
469 vendor->balance = NULL;
471 if (vend_qof_event_handler_id == 0)
479 void gncVendorDestroy (GncVendor *vendor)
482 qof_instance_set_destroying(vendor, TRUE);
483 gncVendorCommitEdit (vendor);
486 static void gncVendorFree (GncVendor *vendor)
492 CACHE_REMOVE (vendor->id);
493 CACHE_REMOVE (vendor->name);
494 CACHE_REMOVE (vendor->notes);
495 gncAddressBeginEdit (vendor->addr);
496 gncAddressDestroy (vendor->addr);
498 gncJobFreeList (vendor->jobs);
499 g_list_free (vendor->jobs);
500 g_free (vendor->balance);
505 gncBillTermDecRef (vendor->terms);
506 if (vendor->taxtable)
507 gncTaxTableDecRef (vendor->taxtable);
511 g_object_unref (vendor);
517 #define SET_STR(obj, member, str) { \ 518 if (!g_strcmp0 (member, str)) return; \ 519 gncVendorBeginEdit (obj); \ 520 CACHE_REPLACE (member, str); \ 523 void gncVendorSetID (GncVendor *vendor,
const char *
id)
527 SET_STR(vendor, vendor->id,
id);
528 mark_vendor (vendor);
529 gncVendorCommitEdit (vendor);
532 void gncVendorSetName (GncVendor *vendor,
const char *name)
536 SET_STR(vendor, vendor->name, name);
537 mark_vendor (vendor);
538 gncVendorCommitEdit (vendor);
541 void gncVendorSetNotes (GncVendor *vendor,
const char *notes)
545 SET_STR(vendor, vendor->notes, notes);
546 mark_vendor (vendor);
547 gncVendorCommitEdit (vendor);
550 void gncVendorSetTerms (GncVendor *vendor, GncBillTerm *terms)
553 if (vendor->terms == terms)
return;
555 gncVendorBeginEdit (vendor);
557 gncBillTermDecRef (vendor->terms);
558 vendor->terms = terms;
560 gncBillTermIncRef (vendor->terms);
561 mark_vendor (vendor);
562 gncVendorCommitEdit (vendor);
565 void gncVendorSetTaxIncluded (GncVendor *vendor,
GncTaxIncluded taxincl)
568 if (taxincl == vendor->taxincluded)
return;
569 gncVendorBeginEdit (vendor);
570 vendor->taxincluded = taxincl;
571 mark_vendor (vendor);
572 gncVendorCommitEdit (vendor);
575 void gncVendorSetCurrency (GncVendor *vendor, gnc_commodity *currency)
577 if (!vendor || !currency)
return;
578 if (vendor->currency &&
581 gncVendorBeginEdit (vendor);
582 vendor->currency = currency;
583 mark_vendor (vendor);
584 gncVendorCommitEdit (vendor);
587 void gncVendorSetActive (GncVendor *vendor, gboolean active)
590 if (active == vendor->active)
return;
591 gncVendorBeginEdit (vendor);
592 vendor->active = active;
593 mark_vendor (vendor);
594 gncVendorCommitEdit (vendor);
597 void gncVendorSetTaxTableOverride (GncVendor *vendor, gboolean
override)
600 if (vendor->taxtable_override ==
override)
return;
601 gncVendorBeginEdit (vendor);
602 vendor->taxtable_override =
override;
603 mark_vendor (vendor);
604 gncVendorCommitEdit (vendor);
610 if (vendor->taxtable ==
table)
return;
611 gncVendorBeginEdit (vendor);
612 if (vendor->taxtable)
613 gncTaxTableDecRef (vendor->taxtable);
615 gncTaxTableIncRef (
table);
616 vendor->taxtable =
table;
617 mark_vendor (vendor);
618 gncVendorCommitEdit (vendor);
622 qofVendorSetAddr (GncVendor *vendor,
QofInstance *addr_ent)
626 if (!vendor || !addr_ent)
631 if (addr == vendor->addr)
635 if (vendor->addr != NULL)
637 gncAddressBeginEdit(vendor->addr);
638 gncAddressDestroy(vendor->addr);
640 gncVendorBeginEdit(vendor);
642 gncVendorCommitEdit(vendor);
646 qofVendorSetTaxIncluded(GncVendor *vendor,
const char* type_string)
650 if (!gncTaxIncludedStringToType(type_string, &inc))
654 gncVendorBeginEdit(vendor);
655 vendor->taxincluded = inc;
656 gncVendorCommitEdit(vendor);
662 const char * gncVendorGetID (
const GncVendor *vendor)
664 if (!vendor)
return NULL;
668 const char * gncVendorGetName (
const GncVendor *vendor)
670 if (!vendor)
return NULL;
674 GncAddress * gncVendorGetAddr (
const GncVendor *vendor)
676 if (!vendor)
return NULL;
680 const char * gncVendorGetNotes (
const GncVendor *vendor)
682 if (!vendor)
return NULL;
683 return vendor->notes;
686 GncBillTerm * gncVendorGetTerms (
const GncVendor *vendor)
688 if (!vendor)
return 0;
689 return vendor->terms;
695 return vendor->taxincluded;
698 gnc_commodity * gncVendorGetCurrency (
const GncVendor *vendor)
700 if (!vendor)
return NULL;
701 return vendor->currency;
704 gboolean gncVendorGetActive (
const GncVendor *vendor)
706 if (!vendor)
return FALSE;
707 return vendor->active;
710 gboolean gncVendorGetTaxTableOverride (
const GncVendor *vendor)
712 if (!vendor)
return FALSE;
713 return vendor->taxtable_override;
716 GncTaxTable* gncVendorGetTaxTable (
const GncVendor *vendor)
718 if (!vendor)
return NULL;
719 return vendor->taxtable;
723 qofVendorGetTaxIncluded(
const GncVendor *vendor)
725 return gncTaxIncludedTypeToString(vendor->taxincluded);
729 void gncVendorAddJob (GncVendor *vendor, GncJob *job)
734 if (g_list_index(vendor->jobs, job) == -1)
735 vendor->jobs = g_list_insert_sorted (vendor->jobs, job,
736 (GCompareFunc)gncJobCompare);
741 void gncVendorRemoveJob (GncVendor *vendor, GncJob *job)
748 node = g_list_find (vendor->jobs, job);
755 vendor->jobs = g_list_remove_link (vendor->jobs, node);
756 g_list_free_1 (node);
762 void gncVendorBeginEdit (GncVendor *vendor)
769 PERR(
"Vendor QofBackend Failure: %d", errcode);
770 gnc_engine_signal_commit_error( errcode );
775 GncVendor *vendor = (GncVendor *) inst;
776 gncAddressClearDirty (vendor->addr);
781 GncVendor *vendor = (GncVendor *) inst;
782 gncVendorFree (vendor);
785 void gncVendorCommitEdit (GncVendor *vendor)
789 gncVendorOnDone, vendor_free);
797 if (!a && !b)
return 0;
798 if (!a && b)
return 1;
799 if (a && !b)
return -1;
801 return(strcmp(a->name, b->name));
806 if (a == NULL && b == NULL)
return TRUE;
807 if (a == NULL || b == NULL)
return FALSE;
809 g_return_val_if_fail(GNC_IS_VENDOR(a), FALSE);
810 g_return_val_if_fail(GNC_IS_VENDOR(b), FALSE);
812 if (g_strcmp0(a->id, b->id) != 0)
814 PWARN(
"IDs differ: %s vs %s", a->id, b->id);
818 if (g_strcmp0(a->name, b->name) != 0)
820 PWARN(
"Names differ: %s vs %s", a->name, b->name);
824 if (g_strcmp0(a->notes, b->notes) != 0)
826 PWARN(
"Notes differ");
832 PWARN(
"BillTerms differ");
838 PWARN(
"Addresses differ");
844 PWARN(
"Currencies differ");
848 if (!gncTaxTableEqual(a->taxtable, b->taxtable))
850 PWARN(
"Tax tables differ");
854 if (a->taxtable_override != b->taxtable_override)
856 PWARN(
"Tax table override flags differ");
860 if (a->taxincluded != b->taxincluded)
862 PWARN(
"Tax included flags differ");
866 if (a->active != b->active)
868 PWARN(
"Active flags differ");
877 gncVendorIsDirty (
const GncVendor *vendor)
879 if (!vendor)
return FALSE;
881 || gncAddressIsDirty (vendor->addr));
898 gpointer user_data, gpointer event_data)
901 if ((GNC_IS_ADDRESS (entity) &&
902 (event_type & QOF_EVENT_MODIFY) != 0))
904 if (GNC_IS_VENDOR (event_data))
906 GncVendor* vend = GNC_VENDOR (event_data);
907 gncVendorBeginEdit (vend);
909 gncVendorCommitEdit (vend);
915 if (GNC_IS_LOT (entity))
917 GNCLot *lot = GNC_LOT (entity);
934 g_free (vend->balance);
935 vend->balance = NULL;
944 static const char * _gncVendorPrintable (gpointer item)
947 if (!item)
return NULL;
952 destroy_vendor_on_book_close(
QofInstance *ent, gpointer data)
954 GncVendor* v = GNC_VENDOR(ent);
956 gncVendorBeginEdit(v);
965 gnc_vendor_book_end(QofBook* book)
970 qof_collection_foreach(col, destroy_vendor_on_book_close, NULL);
973 static QofObject gncVendorDesc =
976 DI(.e_type = ) _GNC_MOD_NAME,
977 DI(.type_label = ) "Vendor",
978 DI(.create = ) (gpointer)gncVendorCreate,
979 DI(.book_begin = ) NULL,
980 DI(.book_end = ) gnc_vendor_book_end,
983 DI(.foreach = ) qof_collection_foreach,
984 DI(.printable = ) _gncVendorPrintable,
988 gboolean gncVendorRegister (
void)
990 static QofParam params[] =
998 VENDOR_TAX_OVERRIDE, QOF_TYPE_BOOLEAN, (
QofAccessFunc)gncVendorGetTaxTableOverride,
1002 VENDOR_TAX_TABLE, GNC_ID_TAXTABLE, (
QofAccessFunc)gncVendorGetTaxTable,
1006 VENDOR_TAX_INC, QOF_TYPE_STRING, (
QofAccessFunc)qofVendorGetTaxIncluded,
1011 { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (
QofAccessFunc)gncVendorGetActive, NULL },
1020 gchar *gncVendorNextID (QofBook *book)
1026 gncVendorGetCachedBalance (GncVendor *vend)
1028 return vend->balance;
1031 void gncVendorSetCachedBalance (GncVendor *vend,
const gnc_numeric *new_bal)
1037 g_free (vend->balance);
1038 vend->balance = NULL;
1044 vend->balance = g_new0 (gnc_numeric, 1);
1046 *vend->balance = *new_bal;
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
GncTaxIncluded
How to interpret the TaxIncluded.
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)
This will increment the named counter for this book and format it.
GList * qof_instance_get_referring_object_list_from_collection(const QofCollection *coll, const QofInstance *ref)
Returns a list of objects from the collection which refer to the specific object. ...
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
QofCollection * qof_instance_get_collection(gconstpointer ptr)
Return the collection this instance belongs to.
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
#define PERR(format, args...)
Log a serious error.
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
gboolean gncBillTermEqual(const GncBillTerm *a, const GncBillTerm *b)
Check if all internal fields of a and b match.
gint qof_event_register_handler(QofEventHandler handler, gpointer user_data)
Register a handler for events.
#define PWARN(format, args...)
Log a warning.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
gint QofEventId
Define the type of events allowed.
gboolean qof_instance_get_dirty_flag(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object has been modified.
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gboolean gncOwnerGetOwnerFromLot(GNCLot *lot, GncOwner *owner)
Get the owner from the lot.
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
int gncVendorCompare(const GncVendor *a, const GncVendor *b)
XXX should be renamed to RetJobList to be consistent with other usage, since caller must free the cop...
gboolean gncAddressEqual(const GncAddress *a, const GncAddress *b)
Deeply compare two addresses.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
const GncOwner * gncOwnerGetEndOwner(const GncOwner *owner)
Get the "parent" Owner or GncGUID thereof.
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Business Invoice Interface.
gboolean gncVendorEqual(const GncVendor *a, const GncVendor *b)
Test support function, used by test-dbi-business-stuff.c.
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object...
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
gboolean qof_book_shutting_down(const QofBook *book)
Is the book shutting down?
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Commodity handling public routines.
modtime is the internal date of the last modtime See libgnucash/engine/TaxTableBillTermImmutability.txt for an explanation of the following Code that handles refcount, parent, child, invisible and children is identical to that in ::GncBillTerm