Owner
[Business]


Files

file  gncOwner.h
 Business Interface: Object OWNERs.

Data Structures

struct  _gncOwner
struct  GncOwner

QOF handling

Whilst GncOwner is not a formal QOF object, these functions are still expected to be useful in making GncOwner transparent to QOF as they can be used by objects like GncInvoice.

QofIdType qofOwnerGetType (const GncOwner *owner)
QofInstanceqofOwnerGetOwner (const GncOwner *owner)
void qofOwnerSetEntity (GncOwner *owner, QofInstance *ent)
gboolean gncOwnerRegister (void)

Setup routines

void gncOwnerInitUndefined (GncOwner *owner, gpointer obj)
void gncOwnerInitCustomer (GncOwner *owner, GncCustomer *customer)
void gncOwnerInitJob (GncOwner *owner, GncJob *job)
void gncOwnerInitVendor (GncOwner *owner, GncVendor *vendor)
void gncOwnerInitEmployee (GncOwner *owner, GncEmployee *employee)

Get routines.

GncOwnerType gncOwnerGetType (const GncOwner *owner)
gpointer gncOwnerGetUndefined (const GncOwner *owner)
GncCustomergncOwnerGetCustomer (const GncOwner *owner)
GncJobgncOwnerGetJob (const GncOwner *owner)
GncVendorgncOwnerGetVendor (const GncOwner *owner)
GncEmployeegncOwnerGetEmployee (const GncOwner *owner)

Defines

#define GNC_ID_OWNER   "gncOwner"
#define OWNER_TYPE   "type"
#define OWNER_TYPE_STRING   "type-string"
#define OWNER_CUSTOMER   "customer"
#define OWNER_JOB   "job"
#define OWNER_VENDOR   "vendor"
#define OWNER_EMPLOYEE   "employee"
#define OWNER_PARENT   "parent"
#define OWNER_PARENTG   "parent-guid"
#define OWNER_NAME   "name"
#define OWNER_FROM_LOT   "owner-from-lot"

Typedefs

typedef _gncOwner GncOwner

Enumerations

enum  GncOwnerType {
  GNC_OWNER_NONE, GNC_OWNER_UNDEFINED, GNC_OWNER_CUSTOMER, GNC_OWNER_JOB,
  GNC_OWNER_VENDOR, GNC_OWNER_EMPLOYEE
}

Functions

void gncOwnerCopy (const GncOwner *src, GncOwner *dest)
gboolean gncOwnerEqual (const GncOwner *a, const GncOwner *b)
int gncOwnerCompare (const GncOwner *a, const GncOwner *b)
const char * gncOwnerGetName (const GncOwner *owner)
gnc_commoditygncOwnerGetCurrency (const GncOwner *owner)
const GUIDgncOwnerGetGUID (const GncOwner *owner)
GUID gncOwnerRetGUID (GncOwner *owner)
gboolean gncOwnerIsValid (const GncOwner *owner)
GncOwnergncOwnerGetEndOwner (GncOwner *owner)
const GUIDgncOwnerGetEndGUID (GncOwner *owner)
void gncOwnerAttachToLot (const GncOwner *owner, GNCLot *lot)
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid)
KvpFramegncOwnerGetSlots (GncOwner *owner)
GncOwnergncOwnerCreate (void)
void gncOwnerDestroy (GncOwner *owner)


Define Documentation

#define OWNER_TYPE_STRING   "type-string"

Allows the type to be handled externally.

Definition at line 145 of file gncOwner.h.


Enumeration Type Documentation

enum GncOwnerType

Enumerator:
GNC_OWNER_NONE 
GNC_OWNER_UNDEFINED 
GNC_OWNER_CUSTOMER 
GNC_OWNER_JOB 
GNC_OWNER_VENDOR 
GNC_OWNER_EMPLOYEE 

Definition at line 47 of file gncOwner.h.


Function Documentation

void gncOwnerAttachToLot ( const GncOwner owner,
GNCLot lot 
)

attach an owner to a lot

Definition at line 396 of file gncOwner.c.

00397 {
00398   KvpFrame *kvp;
00399   KvpValue *value;
00400   
00401   if (!owner || !lot)
00402     return;
00403 
00404   kvp = gnc_lot_get_slots (lot);
00405 
00406   value = kvp_value_new_gint64 (gncOwnerGetType (owner));
00407   kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
00408   kvp_value_delete (value);
00409 
00410   value = kvp_value_new_guid (gncOwnerGetGUID (owner));
00411   kvp_frame_set_slot_path (kvp, value, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
00412   kvp_value_delete (value);
00413 
00414 }

GncOwner* gncOwnerCreate ( void   ) 

These two functions are mainly for the convenience of scheme code. Normal C code has no need to ever use these two functions, and rather can just use a GncOwner directly and just pass around a pointer to it.

Definition at line 49 of file gncOwner.c.

00050 {
00051   GncOwner *o;
00052 
00053   o = g_new0 (GncOwner, 1);
00054   o->type = GNC_OWNER_NONE;
00055   return o;
00056 }

GncOwner* gncOwnerGetEndOwner ( GncOwner owner  ) 

Get the "parent" Owner or GUID thereof. The "parent" owner is the Customer or Vendor, or the Owner of a Job

Definition at line 347 of file gncOwner.c.

00348 {
00349   if (!owner) return NULL;
00350   switch (owner->type) {
00351   case GNC_OWNER_NONE:
00352   case GNC_OWNER_UNDEFINED:
00353   default:
00354     return NULL;
00355   case GNC_OWNER_CUSTOMER:
00356   case GNC_OWNER_VENDOR:
00357   case GNC_OWNER_EMPLOYEE:
00358     return owner;
00359   case GNC_OWNER_JOB:
00360     return gncJobGetOwner (owner->owner.job);
00361   }
00362 }

const GUID* gncOwnerGetGUID ( const GncOwner owner  ) 

Get the GUID of the immediate owner

Definition at line 319 of file gncOwner.c.

00320 {
00321   if (!owner) return NULL;
00322 
00323   switch (owner->type) {
00324   case GNC_OWNER_NONE:
00325   case GNC_OWNER_UNDEFINED:
00326   default:
00327     return NULL;
00328   case GNC_OWNER_CUSTOMER:
00329     return qof_instance_get_guid (QOF_INSTANCE(owner->owner.customer));
00330   case GNC_OWNER_JOB:
00331     return qof_instance_get_guid (QOF_INSTANCE(owner->owner.job));
00332   case GNC_OWNER_VENDOR:
00333     return qof_instance_get_guid (QOF_INSTANCE(owner->owner.vendor));
00334   case GNC_OWNER_EMPLOYEE:
00335     return qof_instance_get_guid (QOF_INSTANCE(owner->owner.employee));
00336   }
00337 }

gboolean gncOwnerGetOwnerFromLot ( GNCLot lot,
GncOwner owner 
)

Get the owner from the lot. If an owner is found in the lot, fill in "owner" and return TRUE. Otherwise return FALSE.

Definition at line 416 of file gncOwner.c.

00417 {
00418   KvpFrame *kvp;
00419   KvpValue *value;
00420   GUID *guid;
00421   QofBook *book;
00422   GncOwnerType type;
00423 
00424   if (!lot || !owner) return FALSE;
00425 
00426   book = gnc_lot_get_book (lot);
00427   kvp = gnc_lot_get_slots (lot);
00428 
00429   value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_TYPE, NULL);
00430   if (!value) return FALSE;
00431 
00432   type = kvp_value_get_gint64 (value);
00433 
00434   value = kvp_frame_get_slot_path (kvp, GNC_OWNER_ID, GNC_OWNER_GUID, NULL);
00435   if (!value) return FALSE;
00436 
00437   guid = kvp_value_get_guid (value);
00438   if (!guid)
00439     return FALSE;
00440 
00441   switch (type) {
00442   case GNC_OWNER_CUSTOMER:
00443     gncOwnerInitCustomer (owner, gncCustomerLookup (book, guid));
00444     break;
00445   case GNC_OWNER_VENDOR:
00446     gncOwnerInitVendor (owner, gncVendorLookup (book, guid));
00447     break;
00448   case GNC_OWNER_EMPLOYEE:
00449     gncOwnerInitEmployee (owner, gncEmployeeLookup (book, guid));
00450     break;
00451   case GNC_OWNER_JOB:
00452     gncOwnerInitJob (owner, gncJobLookup (book, guid));
00453     break;
00454   default:
00455     return FALSE;
00456   }
00457   
00458   return (owner->owner.undefined != NULL);
00459 }

KvpFrame* gncOwnerGetSlots ( GncOwner owner  ) 

Get the kvp-frame from the underlying owner object

Definition at line 467 of file gncOwner.c.

00468 {
00469   if (!owner) return NULL;
00470 
00471   switch (gncOwnerGetType(owner)) {
00472   case GNC_OWNER_CUSTOMER:
00473   case GNC_OWNER_VENDOR:
00474   case GNC_OWNER_EMPLOYEE:
00475     return qof_instance_get_slots(QOF_INSTANCE(owner->owner.undefined));
00476   case GNC_OWNER_JOB:
00477     return gncOwnerGetSlots(gncJobGetOwner(gncOwnerGetJob(owner)));
00478   default:
00479     return NULL;
00480   }
00481 }

QofInstance* qofOwnerGetOwner ( const GncOwner owner  ) 

return the owner itself as an entity.

Definition at line 142 of file gncOwner.c.

00143 {
00144         QofInstance *ent;
00145 
00146         if(!owner) { return NULL; }
00147         ent = NULL;
00148         switch(owner->type)
00149         {
00150                 case GNC_OWNER_NONE : {
00151                         break;
00152                 }
00153                 case GNC_OWNER_UNDEFINED : {
00154                         break;
00155                 }
00156                 case GNC_OWNER_CUSTOMER : {
00157                         ent = QOF_INSTANCE(owner->owner.customer);
00158                         break;
00159                 }
00160                 case GNC_OWNER_JOB : {
00161                         ent = QOF_INSTANCE(owner->owner.job);
00162                         break;
00163                 }
00164                 case GNC_OWNER_VENDOR : {
00165                         ent = QOF_INSTANCE(owner->owner.vendor);
00166                         break;
00167                 }
00168                 case GNC_OWNER_EMPLOYEE : {
00169                         ent = QOF_INSTANCE(owner->owner.employee);
00170                         break;
00171                 }
00172         }
00173         return ent;
00174 }

QofIdType qofOwnerGetType ( const GncOwner owner  ) 

return the type for the collection.

Definition at line 106 of file gncOwner.c.

00107 {
00108         QofIdType type;
00109 
00110         type = NULL;
00111         switch(owner->type)
00112         {
00113                 case GNC_OWNER_NONE : {
00114                         type = NULL;
00115                         break;
00116                 }
00117                 case GNC_OWNER_UNDEFINED : {
00118                         type = NULL;
00119                         break;
00120                 }
00121                 case GNC_OWNER_CUSTOMER : {
00122                         type = GNC_ID_CUSTOMER;
00123                         break;
00124                 }
00125                 case GNC_OWNER_JOB : {
00126                         type = GNC_ID_JOB;
00127                         break;
00128                 }
00129                 case GNC_OWNER_VENDOR : {
00130                         type = GNC_ID_VENDOR;
00131                         break;
00132                 }
00133                 case GNC_OWNER_EMPLOYEE : {
00134                         type = GNC_ID_EMPLOYEE;
00135                         break;
00136                 }
00137         }
00138         return type;
00139 }

void qofOwnerSetEntity ( GncOwner owner,
QofInstance ent 
)

set the owner from the entity.

Definition at line 177 of file gncOwner.c.

00178 {
00179         if(!owner || !ent) { return; }
00180         if(0 == safe_strcmp(ent->e_type, GNC_ID_CUSTOMER))
00181         {
00182                 owner->type = GNC_OWNER_CUSTOMER;
00183                 gncOwnerInitCustomer(owner, (GncCustomer*)ent);
00184         }
00185         if(0 == safe_strcmp(ent->e_type, GNC_ID_JOB))
00186         {
00187                 owner->type = GNC_OWNER_JOB;
00188                 gncOwnerInitJob(owner, (GncJob*)ent);
00189         }
00190         if(0 == safe_strcmp(ent->e_type, GNC_ID_VENDOR))
00191         {
00192                 owner->type = GNC_OWNER_VENDOR;
00193                 gncOwnerInitVendor(owner, (GncVendor*)ent);
00194         }
00195         if(0 == safe_strcmp(ent->e_type, GNC_ID_EMPLOYEE))
00196         {
00197                 owner->type = GNC_OWNER_EMPLOYEE;
00198                 gncOwnerInitEmployee(owner, (GncEmployee*)ent);
00199         }
00200 }


Generated on Thu Aug 28 05:06:12 2008 for GnuCash by  doxygen 1.5.2