mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Introduce two convenience functions to simplify quantity handling for invoice/credit note entries.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21990 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
4a9933211a
commit
45d0b1d19b
@ -316,6 +316,7 @@ find_entry_in_book_by_desc(GncEntryLedger *reg, const char* desc)
|
||||
break;
|
||||
default:
|
||||
use_invoice = FALSE;
|
||||
break;
|
||||
};
|
||||
|
||||
query = new_query_for_entry_desc(reg, desc, use_invoice);
|
||||
@ -543,21 +544,25 @@ gnc_entry_ledger_auto_completion (GncEntryLedger *ledger,
|
||||
set_value_combo_cell (cell, account_name);
|
||||
g_free (account_name);
|
||||
|
||||
/* Auto-complete quantity cell
|
||||
* Note: we always autofill a positive quantity value. This allows us to
|
||||
* - reuse invoice entries on credit note ledgers, meaning you can credit
|
||||
* some invoice entry via autofill without having to manually fix the sign
|
||||
* on the credit note.
|
||||
* - autofill credit note entries on other credit note entries (without having
|
||||
* to juggle sign reversals internally)
|
||||
* - autofill credit note entries on invoice ledgers
|
||||
*
|
||||
* Disadvantage: invoice entries with explicitly set negative quantities will
|
||||
* be autofilled to positive quantities in later uses. But it seems less common
|
||||
* to me to require a negative entry again next time.
|
||||
*/
|
||||
cell = gnc_table_layout_get_cell (ledger->table->layout, ENTRY_QTY_CELL);
|
||||
set_value_price_cell (cell, gnc_numeric_abs(gncEntryGetQuantity (auto_entry)));
|
||||
/* Auto-complete quantity cell. Note that this requires some care because
|
||||
* credit notes store quantities with a reversed sign. So we need to figure
|
||||
* out if the original document from which we extract the autofill entry
|
||||
* was a credit note or not. */
|
||||
{
|
||||
gboolean orig_is_cn;
|
||||
switch (ledger->type)
|
||||
{
|
||||
case GNCENTRY_INVOICE_ENTRY:
|
||||
case GNCENTRY_CUST_CREDIT_NOTE_ENTRY:
|
||||
orig_is_cn = gncInvoiceGetIsCreditNote (gncEntryGetInvoice (auto_entry));
|
||||
break;
|
||||
default:
|
||||
orig_is_cn = gncInvoiceGetIsCreditNote (gncEntryGetBill (auto_entry));
|
||||
break;
|
||||
}
|
||||
cell = gnc_table_layout_get_cell (ledger->table->layout, ENTRY_QTY_CELL);
|
||||
set_value_price_cell (cell, gncEntryGetDocQuantity (auto_entry, orig_is_cn));
|
||||
}
|
||||
|
||||
/* Auto-complete price cell */
|
||||
{
|
||||
@ -570,6 +575,7 @@ gnc_entry_ledger_auto_completion (GncEntryLedger *ledger,
|
||||
break;
|
||||
default:
|
||||
price = gncEntryGetBillPrice (auto_entry);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Auto-complete price cell */
|
||||
@ -595,6 +601,7 @@ gnc_entry_ledger_auto_completion (GncEntryLedger *ledger,
|
||||
taxable = gncEntryGetBillTaxable (auto_entry);
|
||||
taxincluded = gncEntryGetBillTaxIncluded (auto_entry);
|
||||
taxtable = gncEntryGetBillTaxTable (auto_entry);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Taxable? cell */
|
||||
|
@ -313,18 +313,11 @@ static const char * get_qty_entry (VirtualLocation virt_loc,
|
||||
gnc_numeric qty;
|
||||
|
||||
entry = gnc_entry_ledger_get_entry (ledger, virt_loc.vcell_loc);
|
||||
qty = gncEntryGetQuantity (entry);
|
||||
qty = gncEntryGetDocQuantity (entry, ledger->is_credit_note);
|
||||
|
||||
if (gnc_numeric_zero_p (qty))
|
||||
return NULL;
|
||||
|
||||
/* Credit notes have negative quantities, but the ledger should
|
||||
* display it as on the document, meaning positive.
|
||||
* So reverse the quantity for credit notes.
|
||||
*/
|
||||
if (ledger->is_credit_note)
|
||||
qty = gnc_numeric_neg (qty);
|
||||
|
||||
return xaccPrintAmount (qty, gnc_default_print_info (FALSE));
|
||||
}
|
||||
|
||||
@ -1079,13 +1072,7 @@ static void gnc_entry_ledger_save_cells (gpointer save_data,
|
||||
|
||||
if (gnc_entry_ledger_get_numeric (ledger, ENTRY_QTY_CELL, &amount))
|
||||
{
|
||||
/* Credit notes have negative quantities, but the ledger should
|
||||
* display it as on the document, meaning positive.
|
||||
* So reverse the quantity for credit notes.
|
||||
*/
|
||||
if (ledger->is_credit_note)
|
||||
amount = gnc_numeric_neg (amount);
|
||||
gncEntrySetQuantity (entry, amount);
|
||||
gncEntrySetDocQuantity (entry, amount, ledger->is_credit_note);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -531,6 +531,17 @@ void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity)
|
||||
gncEntryCommitEdit (entry);
|
||||
}
|
||||
|
||||
void gncEntrySetDocQuantity (GncEntry *entry, gnc_numeric quantity, gboolean is_cn)
|
||||
{
|
||||
if (!entry) return;
|
||||
if (gnc_numeric_eq (entry->quantity, quantity)) return;
|
||||
gncEntryBeginEdit (entry);
|
||||
entry->quantity = (is_cn ? gnc_numeric_neg (quantity) : quantity);
|
||||
entry->values_dirty = TRUE;
|
||||
mark_entry (entry);
|
||||
gncEntryCommitEdit (entry);
|
||||
}
|
||||
|
||||
/* Customer Invoices */
|
||||
|
||||
void gncEntrySetInvAccount (GncEntry *entry, Account *acc)
|
||||
@ -883,6 +894,12 @@ gnc_numeric gncEntryGetQuantity (const GncEntry *entry)
|
||||
return entry->quantity;
|
||||
}
|
||||
|
||||
gnc_numeric gncEntryGetDocQuantity (const GncEntry *entry, gboolean is_cn)
|
||||
{
|
||||
gnc_numeric value = gncEntryGetQuantity (entry);
|
||||
return (is_cn ? gnc_numeric_neg (value) : value);
|
||||
}
|
||||
|
||||
/* Customer Invoice */
|
||||
|
||||
Account * gncEntryGetInvAccount (const GncEntry *entry)
|
||||
|
@ -106,7 +106,19 @@ void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
|
||||
void gncEntrySetDescription (GncEntry *entry, const char *desc);
|
||||
void gncEntrySetAction (GncEntry *entry, const char *action);
|
||||
void gncEntrySetNotes (GncEntry *entry, const char *notes);
|
||||
/** Set the internal quantity without any conversion.
|
||||
* This distinction is made because credit notes store their quantity
|
||||
* sign-reversed compared to how the quantity is written on the
|
||||
* actual credit note (and hence how the ledger and reports show it
|
||||
* to the user). */
|
||||
void gncEntrySetQuantity (GncEntry *entry, gnc_numeric quantity);
|
||||
/** Set the internal quantity converting from the quantity as
|
||||
* visible on the physical document.
|
||||
* This distinction is made because credit notes store their quantity
|
||||
* sign-reversed compared to how the quantity is written on the
|
||||
* actual credit note (and hence how the ledger and reports show it
|
||||
* to the user). */
|
||||
void gncEntrySetDocQuantity (GncEntry *entry, gnc_numeric quantity, gboolean is_cn);
|
||||
/** @} */
|
||||
|
||||
/** @name Customer Invoices
|
||||
@ -152,7 +164,18 @@ Timespec gncEntryGetDateEntered (const GncEntry *entry);
|
||||
const char * gncEntryGetDescription (const GncEntry *entry);
|
||||
const char * gncEntryGetAction (const GncEntry *entry);
|
||||
const char * gncEntryGetNotes (const GncEntry *notes);
|
||||
/** Get the quantity as stored internally.
|
||||
* This distinction is made because credit notes store their quantity
|
||||
* sign-reversed compared to how the quantity is written on the
|
||||
* actual credit note (and hence how the ledger and reports show it
|
||||
* to the user). */
|
||||
gnc_numeric gncEntryGetQuantity (const GncEntry *entry);
|
||||
/** Get the quantity as on the physical document.
|
||||
* This distinction is made because credit notes store their quantity
|
||||
* sign-reversed compared to how the quantity is written on the
|
||||
* actual credit note (and hence how the ledger and reports show it
|
||||
* to the user). */
|
||||
gnc_numeric gncEntryGetDocQuantity (const GncEntry *entry, gboolean is_cn);
|
||||
/** @} */
|
||||
|
||||
/** @name Customer Invoices
|
||||
|
@ -129,16 +129,6 @@
|
||||
|
||||
(define (make-account-hash) (make-hash-table 23))
|
||||
|
||||
;; Internally invoice values are positive and credit-note values are negative
|
||||
;; However on the invoice/cn document they are always displayed as positive
|
||||
;; So depending on the document type the internal values have to be reversed
|
||||
;; before they are printed on the document. This function handles that.
|
||||
;; It should be called for each internal value that is to be displayed on the document.
|
||||
(define (inv-or-cn-value value credit-note?)
|
||||
(if (not credit-note?)
|
||||
value
|
||||
(gnc-numeric-neg value)))
|
||||
|
||||
(define (update-account-hash hash values)
|
||||
(for-each
|
||||
(lambda (item)
|
||||
@ -191,7 +181,7 @@
|
||||
(addto! row-contents
|
||||
(gnc:make-html-table-cell/markup
|
||||
"number-cell"
|
||||
(inv-or-cn-value (gncEntryGetQuantity entry) credit-note?))))
|
||||
(gncEntryGetDocQuantity entry credit-note?))))
|
||||
|
||||
(if (price-col column-vector)
|
||||
(addto! row-contents
|
||||
|
@ -147,16 +147,6 @@
|
||||
|
||||
(define (make-account-hash) (make-hash-table 23))
|
||||
|
||||
;; Internally invoice values are positive and credit-note values are negative
|
||||
;; However on the invoice/cn document they are always displayed as positive
|
||||
;; So depending on the document type the internal values have to be reversed
|
||||
;; before they are printed on the document. This function handles that.
|
||||
;; It should be called for each internal value that is to be displayed on the document.
|
||||
(define (inv-or-cn-value value credit-note?)
|
||||
(if (not credit-note?)
|
||||
value
|
||||
(gnc-numeric-neg value)))
|
||||
|
||||
(define (update-account-hash hash values)
|
||||
(for-each
|
||||
(lambda (item)
|
||||
@ -199,7 +189,7 @@
|
||||
(addto! row-contents
|
||||
(gnc:make-html-table-cell/markup
|
||||
"number-cell"
|
||||
(inv-or-cn-value (gncEntryGetQuantity entry) credit-note?))))
|
||||
(gncEntryGetDocQuantity entry credit-note?))))
|
||||
|
||||
(if (price-col column-vector)
|
||||
(addto! row-contents
|
||||
|
@ -123,16 +123,6 @@
|
||||
|
||||
(define (make-account-hash) (make-hash-table 23))
|
||||
|
||||
;; Internally invoice values are positive and credit-note values are negative
|
||||
;; However on the invoice/cn document they are always displayed as positive
|
||||
;; So depending on the document type the internal values have to be reversed
|
||||
;; before they are printed on the document. This function handles that.
|
||||
;; It should be called for each internal value that is to be displayed on the document.
|
||||
(define (inv-or-cn-value value credit-note?)
|
||||
(if (not credit-note?)
|
||||
value
|
||||
(gnc-numeric-neg value)))
|
||||
|
||||
(define (update-account-hash hash values)
|
||||
(for-each
|
||||
(lambda (item)
|
||||
@ -186,7 +176,7 @@
|
||||
(addto! row-contents
|
||||
(gnc:make-html-table-cell/markup
|
||||
"number-cell"
|
||||
(inv-or-cn-value (gncEntryGetQuantity entry) credit-note?))))
|
||||
(gncEntryGetDocQuantity entry credit-note?))))
|
||||
|
||||
(if (price-col column-vector)
|
||||
(addto! row-contents
|
||||
|
Loading…
Reference in New Issue
Block a user