mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-29 20:24:25 -06:00
Factor out a convenience function to retrieve a (business) owner starting from a transaction
This commit is contained in:
parent
656a3a9b57
commit
6fd35694e2
@ -637,6 +637,31 @@ gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner)
|
||||
return (owner->owner.undefined != NULL);
|
||||
}
|
||||
|
||||
gboolean gncOwnerGetOwnerFromTxn (Transaction *txn, GncOwner *owner)
|
||||
{
|
||||
Split *apar_split = NULL;
|
||||
|
||||
if (!txn || !owner) return FALSE;
|
||||
|
||||
if (xaccTransGetTxnType (txn) == TXN_TYPE_NONE)
|
||||
return FALSE;
|
||||
|
||||
apar_split = xaccTransGetFirstAPARAcctSplit (txn);
|
||||
if (apar_split)
|
||||
{
|
||||
GNCLot *lot = xaccSplitGetLot (apar_split);
|
||||
GncInvoice *invoice = gncInvoiceGetInvoiceFromLot (lot);
|
||||
if (invoice)
|
||||
gncOwnerCopy (gncInvoiceGetOwner (invoice), owner);
|
||||
else if (!gncOwnerGetOwnerFromLot (lot, owner))
|
||||
return FALSE;
|
||||
|
||||
return TRUE; // Got owner from either invoice or lot
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean gncOwnerIsValid (const GncOwner *owner)
|
||||
{
|
||||
if (!owner) return FALSE;
|
||||
|
@ -195,6 +195,15 @@ gint gncOwnerLotsSortFunc (GNCLot *lotA, GNCLot *lotB);
|
||||
*/
|
||||
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
|
||||
|
||||
/** Convenience function to get the owner from a transaction.
|
||||
* Transactions don't really have an owner. What this function will
|
||||
* do it figure out whether the transaction is part of a business
|
||||
* transaction (either a posted invoice/bill/voucher/credit note or
|
||||
* a payment transaction) and use the business object behind it
|
||||
* to extract owner information.
|
||||
*/
|
||||
gboolean gncOwnerGetOwnerFromTxn (Transaction *txn, GncOwner *owner);
|
||||
|
||||
gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GncGUID *guid);
|
||||
|
||||
/** Get the kvp-frame from the underlying owner object */
|
||||
|
@ -1706,28 +1706,20 @@ gnc_ui_print_check_dialog_create(GtkWidget *parent,
|
||||
* it would create build problems */
|
||||
if (g_list_length(pcd->splits) == 1)
|
||||
{
|
||||
trans = xaccSplitGetParent((Split *)(pcd->splits->data));
|
||||
if (xaccTransGetTxnType (trans) == TXN_TYPE_PAYMENT)
|
||||
{
|
||||
Split *apar_split = xaccTransGetFirstAPARAcctSplit (trans);
|
||||
if (apar_split)
|
||||
{
|
||||
GNCLot *lot = xaccSplitGetLot (apar_split);
|
||||
GncOwner owner;
|
||||
if (!gncOwnerGetOwnerFromLot (lot, &owner))
|
||||
{
|
||||
GncInvoice *invoice = gncInvoiceGetInvoiceFromLot (lot);
|
||||
if (invoice)
|
||||
gncOwnerCopy (gncOwnerGetEndOwner (gncInvoiceGetOwner (invoice)), &owner);
|
||||
}
|
||||
GncOwner txn_owner;
|
||||
|
||||
/* Got a business owner, get the address */
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_name), gncOwnerGetName(&owner));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_1), gncAddressGetAddr1 (gncOwnerGetAddr(&owner)));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_2), gncAddressGetAddr2 (gncOwnerGetAddr(&owner)));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_3), gncAddressGetAddr3 (gncOwnerGetAddr(&owner)));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_4), gncAddressGetAddr4 (gncOwnerGetAddr(&owner)));
|
||||
}
|
||||
trans = xaccSplitGetParent((Split *)(pcd->splits->data));
|
||||
if (gncOwnerGetOwnerFromTxn (trans, &txn_owner))
|
||||
{
|
||||
GncOwner owner;
|
||||
gncOwnerCopy (gncOwnerGetEndOwner (&txn_owner), &owner);
|
||||
|
||||
/* Got a business owner, get the address */
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_name), gncOwnerGetName(&owner));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_1), gncAddressGetAddr1 (gncOwnerGetAddr(&owner)));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_2), gncAddressGetAddr2 (gncOwnerGetAddr(&owner)));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_3), gncAddressGetAddr3 (gncOwnerGetAddr(&owner)));
|
||||
gtk_entry_set_text(GTK_ENTRY(pcd->check_address_4), gncAddressGetAddr4 (gncOwnerGetAddr(&owner)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user