[gncOwner] add gncOwnerGetTypeString returns owner-type

* will have several uses
This commit is contained in:
Christopher Lam 2019-10-28 20:01:39 +08:00
parent d893723479
commit 644cb4100e
3 changed files with 26 additions and 8 deletions

View File

@ -1200,15 +1200,8 @@ flawed. see report-utilities.scm. please update reports.")
(format #f "[~a]"
(gnc:monetary->string mon)))
(define (owner->str owner)
(define owner-alist
(list (cons GNC-OWNER-NONE "None")
(cons GNC-OWNER-UNDEFINED "Undefined")
(cons GNC-OWNER-JOB "Job")
(cons GNC-OWNER-CUSTOMER "Cust")
(cons GNC-OWNER-VENDOR "Vend")
(cons GNC-OWNER-EMPLOYEE "Emp")))
(format #f "[~a:~a]"
(or (assv-ref owner-alist (gncOwnerGetType owner)) "Owner")
(gncOwnerGetTypeString owner)
(gncOwnerGetName owner)))
(define (invoice->str inv)
(format #f "~a<Post:~a,Owner:~a,Notes:~a,Total:~a>"

View File

@ -204,6 +204,29 @@ GncOwnerType gncOwnerGetType (const GncOwner *owner)
return owner->type;
}
const char * gncOwnerGetTypeString (const GncOwner *owner)
{
GncOwnerType type = gncOwnerGetType(owner);
switch (type)
{
case GNC_OWNER_NONE:
return "None";
case GNC_OWNER_UNDEFINED:
return "Undefined";
case GNC_OWNER_CUSTOMER:
return "Customer";
case GNC_OWNER_JOB:
return "Job";
case GNC_OWNER_VENDOR:
return "Vendor";
case GNC_OWNER_EMPLOYEE:
return "Employee";
default:
PWARN ("Unknown owner type");
return NULL;
}
}
QofIdTypeConst
qofOwnerGetType(const GncOwner *owner)
{

View File

@ -65,6 +65,8 @@ to QOF as they can be used by objects like GncInvoice.
*/
/** return the type for the collection. */
QofIdTypeConst qofOwnerGetType(const GncOwner *owner);
/** return the type for the owner as an untranslated string. */
const char * gncOwnerGetTypeString (const GncOwner *owner);
/** return the owner itself as an entity. */
QofInstance* qofOwnerGetOwner (const GncOwner *owner);
/** set the owner from the entity. */