r22001 - gnucash/trunk/src - Remove some obsolete (and now malfunctioning) code.
Geert Janssens
gjanssens at code.gnucash.org
Fri Feb 10 10:35:05 EST 2012
Author: gjanssens
Date: 2012-02-10 10:35:05 -0500 (Fri, 10 Feb 2012)
New Revision: 22001
Trac: http://svn.gnucash.org/trac/changeset/22001
Modified:
gnucash/trunk/src/engine/gncOwner.c
gnucash/trunk/src/engine/gncOwner.h
gnucash/trunk/src/optional/python-bindings/gnucash_business.py
Log:
Remove some obsolete (and now malfunctioning) code.
Modified: gnucash/trunk/src/engine/gncOwner.c
===================================================================
--- gnucash/trunk/src/engine/gncOwner.c 2012-02-10 15:34:55 UTC (rev 22000)
+++ gnucash/trunk/src/engine/gncOwner.c 2012-02-10 15:35:05 UTC (rev 22001)
@@ -702,202 +702,10 @@
return (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER);
}
-gint
-gncOwnerAssignPaymentTxn(const GncOwner *owner, Transaction *txn,
- Account *posted_account, GncInvoice* invoice)
-{
- Account *inv_posted_acc;
- GList *lot_iter, *open_lot_fifo;
- GNCLot *inv_posted_lot = NULL, *prepay_lot = NULL;
- gnc_numeric split_amt;
- gboolean inv_passed = TRUE;
- Split *split;
- QofBook *book = gnc_account_get_book(posted_account);
- gnc_commodity *txn_commodity = xaccTransGetCurrency(txn);
- gint result = 0;
- gnc_numeric payment_value;
- const char *memo;
- g_assert(owner);
- g_assert(txn);
- g_assert(xaccTransIsOpen(txn));
- g_assert(posted_account);
-
- if (txn_commodity != gncOwnerGetCurrency (owner))
- {
- // Uh oh
- return result;
- }
- // We require exactly one split in the transaction
- if (xaccTransCountSplits(txn) != 1)
- {
- // Uh oh
- return result;
- }
-
- {
- // Retrieve the payment value from the existing first split.
- Split *asset_split = xaccTransGetSplit(txn, 0);
- g_assert(asset_split);
-
- /* Note: to balance the transaction the payment to assign
- * must have the opposite sign of the existing first split */
- payment_value = gnc_numeric_neg(xaccSplitGetValue(asset_split));
- memo = xaccSplitGetMemo(asset_split);
- }
-
- /* Now, find all "open" lots in the posting account for this
- * company and apply the payment on a FIFO basis. Create
- * a new split for each open lot until the payment is gone.
- */
-
- open_lot_fifo = xaccAccountFindOpenLots (posted_account, gnc_lot_match_invoice_owner,
- (gpointer)owner,
- (GCompareFunc)gnc_lot_sort_func);
-
- /* Check if an invoice was passed in. */
- if (invoice)
- {
- /* If so, does it match the account, and is it an open lot?
- * If so, put it at the beginning of the lot list fifo so we
- * post to this invoice's lot first.
- */
- inv_posted_acc = gncInvoiceGetPostedAcc(invoice);
- inv_posted_lot = gncInvoiceGetPostedLot(invoice);
- if (inv_posted_acc && inv_posted_lot &&
- guid_equal(xaccAccountGetGUID(inv_posted_acc),
- xaccAccountGetGUID(posted_account)) &&
- !gnc_lot_is_closed(inv_posted_lot))
- {
- /* Put this invoice at the beginning of the FIFO */
- open_lot_fifo = g_list_prepend (open_lot_fifo, inv_posted_lot);
- inv_passed = FALSE;
- }
- }
-
- xaccAccountBeginEdit (posted_account);
-
- /* Now iterate over the fifo until the payment is fully applied
- * (or all the lots are paid)
- */
- for (lot_iter = open_lot_fifo; lot_iter; lot_iter = lot_iter->next)
- {
- gnc_numeric balance;
-
- GNCLot *lot = lot_iter->data;
-
- /* Skip this lot if it matches the invoice that was passed in and
- * we've seen it already. This way we post to it the first time
- * (from the beginning of the lot-list) but not when we reach it
- * the second time.
- */
- if (inv_posted_lot &&
- guid_equal(qof_instance_get_guid(QOF_INSTANCE(lot)),
- qof_instance_get_guid(QOF_INSTANCE(inv_posted_lot))))
- {
- if (inv_passed)
- continue;
- else
- inv_passed = TRUE;
- }
-
- balance = gnc_lot_get_balance (lot);
-
- /* The balance can be positive or negative. But in order to assign a payment to it,
- * it has to have the opposite sign of the payment_value we have left.
- * If they are of the same sign, we may reserve it as the pre-payment lot for later
- */
- if ( (gnc_numeric_negative_p (balance) && gnc_numeric_negative_p (payment_value)) ||
- (gnc_numeric_positive_p (balance) && gnc_numeric_positive_p (payment_value)) )
- {
- if (prepay_lot)
- {
- g_warning ("Multiple pre-payment lots are found. Skipping.");
- }
- else
- {
- /* A lot can only be used as a pre-payment lot if it has no document (invoice/credit note) attached */
- if (!gncInvoiceGetInvoiceFromLot(lot))
- prepay_lot = lot;
- }
- continue;
- }
-
- /*
- * If there is less to pay than there's open in the lot; we're done -- apply the payment_value.
- * Note that payment_value and balance are opposite in sign, so we have to compare absolute values here
- *
- * Otherwise, apply the balance, subtract that from the payment_value,
- * and move on to the next one.
- */
- if (gnc_numeric_compare (gnc_numeric_abs (payment_value), gnc_numeric_abs (balance)) <= 0)
- {
- /* abs(payment_value) <= abs(balance) */
- split_amt = payment_value;
- }
- else
- {
- /* abs(payment_value) > abs(balance)
- * Remember payment_value and balance are opposite in sign,
- * and we want a payment to neutralize the current balance
- * so we need to negate here */
- split_amt = gnc_numeric_neg (balance);
- }
-
- /* reduce the payment_value by split_amt */
- payment_value = gnc_numeric_sub (payment_value, split_amt, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
-
- /* Create the split for this lot in the post account */
- ++result;
- split = xaccMallocSplit (book);
- xaccSplitSetMemo (split, memo);
- xaccSplitSetAction (split, _("Payment"));
- xaccAccountInsertSplit (posted_account, split);
- xaccTransAppendSplit (txn, split);
- xaccSplitSetBaseValue (split, split_amt, txn_commodity);
- gnc_lot_add_split (lot, split);
-
- /* If the lot was linked to a document (invoice/credit note),
- * send an event for it so it gets updated as paid */
- {
- GncInvoice *this_invoice = gncInvoiceGetInvoiceFromLot(lot);
- if (this_invoice)
- qof_event_gen (QOF_INSTANCE(this_invoice), QOF_EVENT_MODIFY, NULL);
- }
-
- if (gnc_numeric_zero_p (payment_value))
- break;
- }
-
- g_list_free (open_lot_fifo);
-
- /* If there is still money left here, then create a pre-payment lot */
- if (!gnc_numeric_zero_p (payment_value))
- {
- if (prepay_lot == NULL)
- {
- prepay_lot = gnc_lot_new (book);
- gncOwnerAttachToLot (owner, prepay_lot);
- }
-
- split = xaccMallocSplit (book);
- xaccSplitSetMemo (split, memo);
- xaccSplitSetAction (split, _("Pre-Payment"));
- xaccAccountInsertSplit (posted_account, split);
- xaccTransAppendSplit (txn, split);
- xaccSplitSetBaseValue (split, payment_value, txn_commodity);
- gnc_lot_add_split (prepay_lot, split);
- }
-
- xaccAccountCommitEdit (posted_account);
-
- return result;
-}
-
-
/*
- * Apply a payment of "amount" for the owner, between the xfer_account
- * (bank or other asset) and the posted_account (A/R or A/P).
+ * Create a payment of "amount" for the owner and return
+ * the new lot associated with this payment.
*/
GNCLot *
gncOwnerCreatePaymentLot (const GncOwner *owner, Transaction *txn,
@@ -1033,76 +841,6 @@
return payment_lot;
}
-/*
- * Apply a payment of "amount" for the owner, between the xfer_account
- * (bank or other asset) and the posted_account (A/R or A/P).
- */
-Transaction *
-gncOwnerApplyPayment (const GncOwner *owner, GncInvoice* invoice,
- Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, Timespec date,
- const char *memo, const char *num)
-{
- QofBook *book;
- Transaction *txn;
- Split *split;
- const char *name;
- gnc_commodity *commodity;
- gboolean reverse;
- gnc_numeric payment_value = amount;
-
- /* Verify our arguments */
- if (!owner || !posted_acc || !xfer_acc) return NULL;
- g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
-
- /* Compute the ancillary data */
- book = gnc_account_get_book (posted_acc);
- name = gncOwnerGetName (gncOwnerGetEndOwner ((GncOwner*)owner));
- commodity = gncOwnerGetCurrency (owner);
- reverse = use_reversed_payment_amounts(owner);
-
- txn = xaccMallocTransaction (book);
- xaccTransBeginEdit (txn);
-
- /* Set up the transaction */
- xaccTransSetDescription (txn, name ? name : "");
- xaccTransSetNum (txn, num);
- xaccTransSetCurrency (txn, commodity);
- xaccTransSetDateEnteredSecs (txn, time(NULL));
- xaccTransSetDatePostedTS (txn, &date);
- xaccTransSetTxnType (txn, TXN_TYPE_PAYMENT);
-
-
- /* The split for the transfer account */
- split = xaccMallocSplit (book);
- xaccSplitSetMemo (split, memo);
- xaccSplitSetAction (split, _("Payment"));
- xaccAccountBeginEdit (xfer_acc);
- xaccAccountInsertSplit (xfer_acc, split);
- xaccAccountCommitEdit (xfer_acc);
- xaccTransAppendSplit (txn, split);
-
- if (gnc_commodity_equal(xaccAccountGetCommodity(xfer_acc), commodity))
- {
- xaccSplitSetBaseValue (split, reverse ? amount :
- gnc_numeric_neg (amount), commodity);
- }
- else
- {
- /* Need to value the payment in terms of the owner commodity */
- xaccSplitSetAmount(split, reverse ? amount : gnc_numeric_neg (amount));
- payment_value = gnc_numeric_mul(amount, exch, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND_HALF_UP);
- xaccSplitSetValue(split, reverse ? payment_value : gnc_numeric_neg(payment_value));
- }
-
- gncOwnerAssignPaymentTxn(owner, txn, posted_acc, invoice);
-
- /* Commit this new transaction */
- xaccTransCommitEdit (txn);
-
- return txn;
-}
-
void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots)
{
GList *base_iter;
Modified: gnucash/trunk/src/engine/gncOwner.h
===================================================================
--- gnucash/trunk/src/engine/gncOwner.h 2012-02-10 15:34:55 UTC (rev 22000)
+++ gnucash/trunk/src/engine/gncOwner.h 2012-02-10 15:35:05 UTC (rev 22001)
@@ -204,18 +204,6 @@
const char *memo, const char *num);
/**
- * Apply a payment of "amount" for the owner, between the xfer_account
- * (bank or other asset) and the posted_account (A/R or A/P). If the
- * caller supplies an (optional) invoice argument, then apply the
- * payment to that invoice first before any other invoice.
- */
-Transaction *
-gncOwnerApplyPayment (const GncOwner *owner, GncInvoice *invoice,
- Account *posted_acc, Account *xfer_acc,
- gnc_numeric amount, gnc_numeric exch, Timespec date,
- const char *memo, const char *num);
-
-/**
* Given a list of lots, try to balance as many of them as possible
* by creating balancing transactions between them. This can be used
* to automatically link invoices to payments (to "mark" invoices as
@@ -251,32 +239,6 @@
*/
void gncOwnerAutoApplyPaymentsWithLots (const GncOwner *owner, GList *lots);
-/**
- * Fill in a half-finished payment transaction for the owner. The
- * transaction txn must already contain one split that belongs to a
- * bank or other asset account. This function will add the other split
- * (or splits) that go to the posted_account (A/R or A/P), including
- * the linking to the lots so that the payment is recorded in the
- * correct lot(s).
- *
- * If the caller supplies an (optional) invoice argument, then apply
- * the payment to that invoice first before any other invoice.
- *
- * Preconditions: The arguments owner, txn, and posted_account must
- * not be NULL. The txn must be open (by xaccTransBeginEdit()); it
- * must contain exactly one split; its commodity (by
- * xaccTransGetCurrency()) must be equal to the owner's commodity (by
- * gncOwnerGetCurrency()).
- *
- * \return The number of splits that have been assigned as owner
- * payments. On success, this is always positive (1 or larger). In
- * case of failure (due to unfulfilled conditions on the input
- * values), null is returned.
- */
-gint
-gncOwnerAssignPaymentTxn(const GncOwner *owner, Transaction *txn,
- Account *posted_account, GncInvoice* invoice);
-
/** Returns a GList of account-types based on the owner type */
GList * gncOwnerGetAccountTypesList (const GncOwner *owner);
Modified: gnucash/trunk/src/optional/python-bindings/gnucash_business.py
===================================================================
--- gnucash/trunk/src/optional/python-bindings/gnucash_business.py 2012-02-10 15:34:55 UTC (rev 22000)
+++ gnucash/trunk/src/optional/python-bindings/gnucash_business.py 2012-02-10 15:35:05 UTC (rev 22001)
@@ -38,7 +38,7 @@
Split, Book, GncLot, Account
from gnucash_core_c import GNC_OWNER_CUSTOMER, GNC_OWNER_JOB, \
- GNC_OWNER_EMPLOYEE, GNC_OWNER_VENDOR, gncOwnerApplyPayment, \
+ GNC_OWNER_EMPLOYEE, GNC_OWNER_VENDOR, gncOwnerCreatePaymentLot, \
GNC_PAYMENT_CASH, GNC_PAYMENT_CARD, \
GNC_DISC_PRETAX, GNC_DISC_SAMETIME, GNC_DISC_POSTTAX, \
GNC_TAXINCLUDED_YES, GNC_TAXINCLUDED_NO, GNC_TAXINCLUDED_USEGLOBAL, \
More information about the gnucash-changes
mailing list