|
|
|
|
@ -821,15 +821,6 @@ gnc_payment_leave_amount_cb (GtkWidget *widget, GdkEventFocus *event,
|
|
|
|
|
gnc_payment_window_check_payment (pw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean AccountTypeOkForPayments (GNCAccountType type)
|
|
|
|
|
{
|
|
|
|
|
if (xaccAccountIsAssetLiabType(type) ||
|
|
|
|
|
xaccAccountIsEquityType(type))
|
|
|
|
|
return TRUE;
|
|
|
|
|
else
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Select the list of accounts to show in the tree */
|
|
|
|
|
static void
|
|
|
|
|
gnc_payment_set_account_types (GncTreeViewAccount *tree)
|
|
|
|
|
@ -840,7 +831,7 @@ gnc_payment_set_account_types (GncTreeViewAccount *tree)
|
|
|
|
|
gnc_tree_view_account_get_view_info (tree, &avi);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_ACCOUNT_TYPES; i++)
|
|
|
|
|
avi.include_type[i] = AccountTypeOkForPayments (i);
|
|
|
|
|
avi.include_type[i] = gncBusinessIsPaymentAcctType (i);
|
|
|
|
|
|
|
|
|
|
gnc_tree_view_account_set_view_info (tree, &avi);
|
|
|
|
|
}
|
|
|
|
|
@ -1151,67 +1142,11 @@ gnc_ui_payment_new (GncOwner *owner, QofBook *book)
|
|
|
|
|
return gnc_ui_payment_new_with_invoice (owner, book, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////
|
|
|
|
|
static void increment_if_asset_account (gpointer data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
int *r = user_data;
|
|
|
|
|
const Split *split = data;
|
|
|
|
|
const Account *account = xaccSplitGetAccount(split);
|
|
|
|
|
if (AccountTypeOkForPayments(xaccAccountGetType (account)))
|
|
|
|
|
++(*r);
|
|
|
|
|
}
|
|
|
|
|
static int countAssetAccounts(SplitList* slist)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
g_list_foreach(slist, &increment_if_asset_account, &result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint predicate_is_asset_account(gconstpointer a,
|
|
|
|
|
gconstpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
const Split *split = a;
|
|
|
|
|
const Account *account = xaccSplitGetAccount(split);
|
|
|
|
|
if (AccountTypeOkForPayments(xaccAccountGetType(account)))
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
static gint predicate_is_apar_account(gconstpointer a,
|
|
|
|
|
gconstpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
const Split *split = a;
|
|
|
|
|
const Account *account = xaccSplitGetAccount(split);
|
|
|
|
|
if (xaccAccountIsAPARType(xaccAccountGetType(account)))
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
static Split *getFirstAssetAccountSplit(SplitList* slist)
|
|
|
|
|
{
|
|
|
|
|
GList *r = g_list_find_custom(slist, NULL, &predicate_is_asset_account);
|
|
|
|
|
if (r)
|
|
|
|
|
return r->data;
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
static Split *getFirstAPARAccountSplit(SplitList* slist)
|
|
|
|
|
{
|
|
|
|
|
GList *r = g_list_find_custom(slist, NULL, &predicate_is_apar_account);
|
|
|
|
|
if (r)
|
|
|
|
|
return r->data;
|
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ///////////////
|
|
|
|
|
|
|
|
|
|
gboolean gnc_ui_payment_is_customer_payment(const Transaction *txn)
|
|
|
|
|
{
|
|
|
|
|
SplitList *slist;
|
|
|
|
|
gboolean result = TRUE;
|
|
|
|
|
|
|
|
|
|
Split *assetaccount_split;
|
|
|
|
|
gnc_numeric amount;
|
|
|
|
|
|
|
|
|
|
@ -1220,17 +1155,17 @@ gboolean gnc_ui_payment_is_customer_payment(const Transaction *txn)
|
|
|
|
|
|
|
|
|
|
// We require the txn to have one split in an A/R or A/P account.
|
|
|
|
|
|
|
|
|
|
slist = xaccTransGetSplitList(txn);
|
|
|
|
|
if (!slist)
|
|
|
|
|
if (!xaccTransGetSplitList(txn))
|
|
|
|
|
return result;
|
|
|
|
|
if (countAssetAccounts(slist) == 0)
|
|
|
|
|
assetaccount_split = xaccTransGetFirstPaymentAcctSplit(txn);
|
|
|
|
|
if (!assetaccount_split)
|
|
|
|
|
{
|
|
|
|
|
g_message("No asset splits in txn \"%s\"; cannot use this for assigning a payment.",
|
|
|
|
|
xaccTransGetDescription(txn));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assetaccount_split = getFirstAssetAccountSplit(slist);
|
|
|
|
|
assetaccount_split = xaccTransGetFirstPaymentAcctSplit(txn);
|
|
|
|
|
amount = xaccSplitGetValue(assetaccount_split);
|
|
|
|
|
result = gnc_numeric_positive_p(amount); // positive amounts == customer
|
|
|
|
|
//g_message("Amount=%s", gnc_numeric_to_string(amount));
|
|
|
|
|
@ -1241,8 +1176,6 @@ gboolean gnc_ui_payment_is_customer_payment(const Transaction *txn)
|
|
|
|
|
|
|
|
|
|
PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn)
|
|
|
|
|
{
|
|
|
|
|
SplitList *slist;
|
|
|
|
|
|
|
|
|
|
Split *assetaccount_split;
|
|
|
|
|
Split *postaccount_split;
|
|
|
|
|
gnc_numeric amount;
|
|
|
|
|
@ -1253,23 +1186,22 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn)
|
|
|
|
|
|
|
|
|
|
// We require the txn to have one split in an Asset account.
|
|
|
|
|
|
|
|
|
|
slist = xaccTransGetSplitList(txn);
|
|
|
|
|
if (!slist)
|
|
|
|
|
if (!xaccTransGetSplitList(txn))
|
|
|
|
|
return NULL;
|
|
|
|
|
if (countAssetAccounts(slist) == 0)
|
|
|
|
|
assetaccount_split = xaccTransGetFirstPaymentAcctSplit(txn);
|
|
|
|
|
if (!assetaccount_split)
|
|
|
|
|
{
|
|
|
|
|
g_message("No asset splits in txn \"%s\"; cannot use this for assigning a payment.",
|
|
|
|
|
xaccTransGetDescription(txn));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assetaccount_split = getFirstAssetAccountSplit(slist);
|
|
|
|
|
postaccount_split = getFirstAPARAccountSplit(slist); // watch out: Might be NULL
|
|
|
|
|
postaccount_split = xaccTransGetFirstAPARAcctSplit(txn); // watch out: Might be NULL
|
|
|
|
|
amount = xaccSplitGetValue(assetaccount_split);
|
|
|
|
|
|
|
|
|
|
pw = gnc_ui_payment_new(owner,
|
|
|
|
|
qof_instance_get_book(QOF_INSTANCE(txn)));
|
|
|
|
|
g_assert(assetaccount_split); // we can rely on this because of the countAssetAccounts() check above
|
|
|
|
|
g_assert(assetaccount_split); // we can rely on this because of the check above
|
|
|
|
|
g_debug("Amount=%s", gnc_numeric_to_string(amount));
|
|
|
|
|
|
|
|
|
|
// Fill in the values from the given txn
|
|
|
|
|
|