mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add functions to retrieve a copy of splits of a certain type from business transactions
This commit is contained in:
parent
de4414b2a1
commit
0dfb921e86
@ -1179,7 +1179,11 @@ gboolean gnc_ui_payment_is_customer_payment(const Transaction *txn)
|
||||
|
||||
/* First test if one split is in an A/R or A/P account.
|
||||
* That will give us the best Customer vs Vendor/Employee distinction */
|
||||
aparaccount_split = xaccTransGetFirstAPARAcctSplit(txn);
|
||||
// Prefer true business split (one that's linked to a lot)
|
||||
aparaccount_split = xaccTransGetFirstAPARAcctSplit(txn, TRUE);
|
||||
if (!aparaccount_split)
|
||||
// No true business split found, try again but this time more relaxed
|
||||
aparaccount_split = xaccTransGetFirstAPARAcctSplit(txn, FALSE);
|
||||
if (aparaccount_split)
|
||||
{
|
||||
if (xaccAccountGetType (xaccSplitGetAccount (aparaccount_split)) == ACCT_TYPE_RECEIVABLE)
|
||||
@ -1242,7 +1246,11 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GtkWidget* parent, GncOwner *owner,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
postaccount_split = xaccTransGetFirstAPARAcctSplit(txn); // watch out: Might be NULL
|
||||
// Prefer true business split (one that's linked to a lot)
|
||||
postaccount_split = xaccTransGetFirstAPARAcctSplit(txn, TRUE); // watch out: Might be NULL
|
||||
if (!postaccount_split)
|
||||
// No true business split found, try again but this time more relaxed
|
||||
postaccount_split = xaccTransGetFirstAPARAcctSplit(txn, FALSE); // watch out: Might be NULL
|
||||
amount = xaccSplitGetValue(assetaccount_split);
|
||||
|
||||
pw = gnc_ui_payment_new(owner,
|
||||
|
@ -66,6 +66,8 @@ struct timeval
|
||||
#include "SchedXaction.h"
|
||||
#include "gncBusiness.h"
|
||||
#include <qofinstance-p.h>
|
||||
#include "gncInvoice.h"
|
||||
#include "gncOwner.h"
|
||||
|
||||
/* Notes about xaccTransBeginEdit(), xaccTransCommitEdit(), and
|
||||
* xaccTransRollback():
|
||||
@ -2241,23 +2243,76 @@ xaccTransGetSplitList (const Transaction *trans)
|
||||
return trans ? trans->splits : NULL;
|
||||
}
|
||||
|
||||
SplitList *
|
||||
xaccTransGetPaymentAcctSplitList (const Transaction *trans)
|
||||
{
|
||||
GList *pay_splits = NULL;
|
||||
FOR_EACH_SPLIT (trans,
|
||||
const Account *account = xaccSplitGetAccount(s);
|
||||
if (account && gncBusinessIsPaymentAcctType(xaccAccountGetType(account)))
|
||||
pay_splits = g_list_prepend (pay_splits, s);
|
||||
);
|
||||
|
||||
pay_splits = g_list_reverse (pay_splits);
|
||||
return pay_splits;
|
||||
}
|
||||
|
||||
SplitList *
|
||||
xaccTransGetAPARAcctSplitList (const Transaction *trans, gboolean strict)
|
||||
{
|
||||
GList *apar_splits = NULL;
|
||||
FOR_EACH_SPLIT (trans,
|
||||
const Account *account = xaccSplitGetAccount(s);
|
||||
if (account && xaccAccountIsAPARType(xaccAccountGetType(account)))
|
||||
{
|
||||
|
||||
if (!strict)
|
||||
apar_splits = g_list_prepend (apar_splits, s);
|
||||
else
|
||||
{
|
||||
GncOwner owner;
|
||||
GNCLot *lot = xaccSplitGetLot(s);
|
||||
if (lot &&
|
||||
(gncInvoiceGetInvoiceFromLot (lot) ||
|
||||
gncOwnerGetOwnerFromLot (lot, &owner)))
|
||||
apar_splits = g_list_prepend (apar_splits, s);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
apar_splits = g_list_reverse (apar_splits);
|
||||
return apar_splits;
|
||||
}
|
||||
|
||||
Split *xaccTransGetFirstPaymentAcctSplit(const Transaction *trans)
|
||||
{
|
||||
FOR_EACH_SPLIT (trans,
|
||||
const Account *account = xaccSplitGetAccount(s);
|
||||
if (gncBusinessIsPaymentAcctType(xaccAccountGetType(account)))
|
||||
if (account && gncBusinessIsPaymentAcctType(xaccAccountGetType(account)))
|
||||
return s;
|
||||
);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Split *xaccTransGetFirstAPARAcctSplit(const Transaction *trans)
|
||||
Split *xaccTransGetFirstAPARAcctSplit (const Transaction *trans, gboolean strict)
|
||||
{
|
||||
FOR_EACH_SPLIT (trans,
|
||||
const Account *account = xaccSplitGetAccount(s);
|
||||
if (xaccAccountIsAPARType(xaccAccountGetType(account)))
|
||||
return s;
|
||||
if (account && xaccAccountIsAPARType(xaccAccountGetType(account)))
|
||||
{
|
||||
GNCLot *lot;
|
||||
GncOwner owner;
|
||||
|
||||
if (!strict)
|
||||
return s;
|
||||
|
||||
lot = xaccSplitGetLot(s);
|
||||
if (lot &&
|
||||
(gncInvoiceGetInvoiceFromLot (lot) ||
|
||||
gncOwnerGetOwnerFromLot (lot, &owner)))
|
||||
return s;
|
||||
}
|
||||
);
|
||||
|
||||
return NULL;
|
||||
|
@ -370,10 +370,27 @@ int xaccTransGetSplitIndex(const Transaction *trans, const Split *split);
|
||||
|
||||
/** The xaccTransGetSplitList() method returns a GList of the splits
|
||||
in a transaction.
|
||||
@param trans The transaction
|
||||
@return The list of splits. This list must NOT be modified. Do *NOT* free
|
||||
this list when you are done with it. */
|
||||
/*@ dependent @*/
|
||||
SplitList * xaccTransGetSplitList (const Transaction *trans);
|
||||
|
||||
/** The xaccTransGetPaymentAcctSplitList() method returns a GList of the splits
|
||||
in a transaction that belong to an account which is considered a
|
||||
valid account for business payments.
|
||||
@param trans The transaction
|
||||
@return The list of splits. This list must be freed when you are done with it. */
|
||||
SplitList * xaccTransGetPaymentAcctSplitList (const Transaction *trans);
|
||||
|
||||
/** The xaccTransGetAPARSplitList() method returns a GList of the splits
|
||||
in a transaction that belong to an AR or AP account.
|
||||
@param trans The transaction
|
||||
@param strict This slightly modifies the test to only consider splits in an AR or AP account and the split is part of a business lot
|
||||
@return The list of splits. This list must be freed when you are done with it. */
|
||||
SplitList * xaccTransGetAPARAcctSplitList (const Transaction *trans, gboolean strict);
|
||||
|
||||
|
||||
gboolean xaccTransStillHasSplit(const Transaction *trans, const Split *s);
|
||||
|
||||
/** The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first
|
||||
@ -387,9 +404,10 @@ Split * xaccTransGetFirstPaymentAcctSplit (const Transaction *trans);
|
||||
/** The xaccTransGetFirstPaymentAcctSplit() method returns a pointer to the first
|
||||
split in this transaction that belongs to an AR or AP account.
|
||||
@param trans The transaction
|
||||
@param strict This slightly modifies the test to only consider splits in an AR or AP account and the split is part of a business lot
|
||||
|
||||
If there is no such split in the transaction NULL will be returned. */
|
||||
Split * xaccTransGetFirstAPARAcctSplit (const Transaction *trans);
|
||||
Split * xaccTransGetFirstAPARAcctSplit (const Transaction *trans, gboolean strict);
|
||||
|
||||
/** Set the transaction to be ReadOnly by setting a non-NULL value as "reason".
|
||||
*
|
||||
|
@ -656,7 +656,7 @@ gboolean gncOwnerGetOwnerFromTxn (Transaction *txn, GncOwner *owner)
|
||||
if (xaccTransGetTxnType (txn) == TXN_TYPE_NONE)
|
||||
return FALSE;
|
||||
|
||||
apar_split = xaccTransGetFirstAPARAcctSplit (txn);
|
||||
apar_split = xaccTransGetFirstAPARAcctSplit (txn, TRUE);
|
||||
if (apar_split)
|
||||
{
|
||||
GNCLot *lot = xaccSplitGetLot (apar_split);
|
||||
|
Loading…
Reference in New Issue
Block a user