mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
More numerics conversions.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3142 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
bce4b808ea
commit
45774a4aa7
@ -2278,8 +2278,7 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm,
|
||||
if (gnc_trans_scm_get_num_splits(trans_scm) == 1) {
|
||||
Split *temp_split;
|
||||
char *temp_string;
|
||||
double price;
|
||||
double amount;
|
||||
gnc_numeric num;
|
||||
|
||||
temp_split = xaccMallocSplit ();
|
||||
other_split_scm = gnc_copy_split(temp_split, use_cut_semantics);
|
||||
@ -2297,10 +2296,11 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm,
|
||||
free(temp_string);
|
||||
}
|
||||
|
||||
price = gnc_split_scm_get_share_price(other_split_scm);
|
||||
amount = gnc_split_scm_get_share_amount(other_split_scm);
|
||||
gnc_split_scm_set_share_price_and_amount(other_split_scm,
|
||||
price, amount);
|
||||
num = gnc_split_scm_get_quantity (split_scm);
|
||||
gnc_split_scm_set_quantity (other_split_scm, gnc_numeric_neg (num));
|
||||
|
||||
num = gnc_split_scm_get_value (split_scm);
|
||||
gnc_split_scm_set_value (other_split_scm, gnc_numeric_neg (num));
|
||||
|
||||
gnc_trans_scm_append_split_scm(trans_scm, other_split_scm);
|
||||
}
|
||||
@ -2318,48 +2318,25 @@ xaccSRSaveRegEntryToSCM (SplitRegister *reg, SCM trans_scm, SCM split_scm,
|
||||
}
|
||||
|
||||
if (MOD_AMNT & changed) {
|
||||
gnc_numeric new_amount;
|
||||
gnc_numeric new_value;
|
||||
gnc_numeric credit;
|
||||
gnc_numeric debit;
|
||||
gnc_numeric price;
|
||||
|
||||
credit = xaccGetPriceCellValue(reg->creditCell);
|
||||
debit = xaccGetPriceCellValue(reg->debitCell);
|
||||
new_amount = gnc_numeric_sub_fixed (debit, credit);
|
||||
new_value = gnc_numeric_sub_fixed (debit, credit);
|
||||
|
||||
price = double_to_gnc_numeric (gnc_split_scm_get_share_price(split_scm),
|
||||
100000, GNC_RND_ROUND);
|
||||
|
||||
new_amount = gnc_numeric_div (new_amount, price, GNC_DENOM_AUTO,
|
||||
GNC_RND_ROUND | GNC_DENOM_EXACT);
|
||||
|
||||
gnc_split_scm_set_share_price_and_amount(split_scm,
|
||||
gnc_numeric_to_double (price),
|
||||
gnc_numeric_to_double (new_amount));
|
||||
gnc_split_scm_set_value (split_scm, new_value);
|
||||
}
|
||||
|
||||
if (MOD_PRIC & changed) {
|
||||
gnc_numeric price;
|
||||
gnc_numeric amount;
|
||||
|
||||
price = xaccGetPriceCellValue(reg->priceCell);
|
||||
amount = double_to_gnc_numeric (gnc_split_scm_get_share_amount(split_scm),
|
||||
100000, GNC_RND_ROUND);
|
||||
|
||||
gnc_split_scm_set_share_price_and_amount(split_scm,
|
||||
gnc_numeric_to_double (price),
|
||||
gnc_numeric_to_double (amount));
|
||||
/* do nothing for now */
|
||||
}
|
||||
|
||||
if (MOD_SHRS & changed) {
|
||||
gnc_numeric shares = xaccGetPriceCellValue(reg->sharesCell);
|
||||
gnc_numeric price =
|
||||
double_to_gnc_numeric (gnc_split_scm_get_share_price(split_scm),
|
||||
100000, GNC_RND_ROUND);
|
||||
|
||||
gnc_split_scm_set_share_price_and_amount(split_scm,
|
||||
gnc_numeric_to_double (price),
|
||||
gnc_numeric_to_double (shares));
|
||||
gnc_split_scm_set_quantity (split_scm, shares);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -1,6 +1,6 @@
|
||||
;; engine-interface.scm -- support for working with the GnuCash
|
||||
;; engine data structures
|
||||
;; Copyright (C) 2000 Dave Peticolas <peticola@cs.ucdavis.edu>
|
||||
;; Copyright (C) 2000 Dave Peticolas <dave@krondo.com>
|
||||
;;
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License as
|
||||
@ -24,7 +24,7 @@
|
||||
(make-record-type
|
||||
"gnc:split-structure"
|
||||
'(split-guid account-guid transaction-guid memo action
|
||||
reconcile-state reconciled-date share-amount share-price)))
|
||||
reconcile-state reconciled-date quantity value)))
|
||||
|
||||
;; constructor
|
||||
(define gnc:make-split-scm
|
||||
@ -56,11 +56,11 @@
|
||||
(define gnc:split-scm-get-reconciled-date
|
||||
(record-accessor gnc:split-structure 'reconciled-date))
|
||||
|
||||
(define gnc:split-scm-get-share-amount
|
||||
(record-accessor gnc:split-structure 'share-amount))
|
||||
(define gnc:split-scm-get-quantity
|
||||
(record-accessor gnc:split-structure 'quantity))
|
||||
|
||||
(define gnc:split-scm-get-share-price
|
||||
(record-accessor gnc:split-structure 'share-price))
|
||||
(define gnc:split-scm-get-value
|
||||
(record-accessor gnc:split-structure 'value))
|
||||
|
||||
;; modifiers
|
||||
(define gnc:split-scm-set-split-guid
|
||||
@ -84,11 +84,11 @@
|
||||
(define gnc:split-scm-set-reconciled-date
|
||||
(record-modifier gnc:split-structure 'reconciled-date))
|
||||
|
||||
(define gnc:split-scm-set-share-amount
|
||||
(record-modifier gnc:split-structure 'share-amount))
|
||||
(define gnc:split-scm-set-quantity
|
||||
(record-modifier gnc:split-structure 'quantity))
|
||||
|
||||
(define gnc:split-scm-set-share-price
|
||||
(record-modifier gnc:split-structure 'share-price))
|
||||
(define gnc:split-scm-set-value
|
||||
(record-modifier gnc:split-structure 'value))
|
||||
|
||||
;; This function take a C split and returns a representation
|
||||
;; of it as a split-structure. Assumes the transaction is open
|
||||
@ -102,8 +102,8 @@
|
||||
(gnc:split-get-action split)
|
||||
(gnc:split-get-reconcile-state split)
|
||||
(gnc:split-get-reconciled-date split)
|
||||
(d-gnc:split-get-share-amount split)
|
||||
(d-gnc:split-get-share-price split)))
|
||||
(gnc:split-get-share-amount split)
|
||||
(gnc:split-get-value split)))
|
||||
|
||||
;; Copy a scheme representation of a split onto a C split.
|
||||
;; If possible, insert the C split into the account of the
|
||||
@ -114,14 +114,14 @@
|
||||
(if (pointer-token-null? split)
|
||||
#f
|
||||
(begin
|
||||
(let ((memo (gnc:split-scm-get-memo split-scm))
|
||||
(action (gnc:split-scm-get-action split-scm))
|
||||
(price (gnc:split-scm-get-share-price split-scm))
|
||||
(amount (gnc:split-scm-get-share-amount split-scm)))
|
||||
(if memo (gnc:split-set-memo split memo))
|
||||
(if action (gnc:split-set-action split action))
|
||||
(if (and price amount)
|
||||
(d-gnc:split-set-share-price-and-amount split price amount)))
|
||||
(let ((memo (gnc:split-scm-get-memo split-scm))
|
||||
(action (gnc:split-scm-get-action split-scm))
|
||||
(quantity (gnc:split-scm-get-quantity split-scm))
|
||||
(value (gnc:split-scm-get-value split-scm)))
|
||||
(if memo (gnc:split-set-memo split memo))
|
||||
(if action (gnc:split-set-action split action))
|
||||
(if quantity (gnc:split-set-share-amount split quantity))
|
||||
(if value (gnc:split-set-value split value)))
|
||||
(let ((account (gnc:account-lookup
|
||||
(gnc:split-scm-get-account-guid split-scm))))
|
||||
(if (and account (gnc:account-can-insert-split? account split))
|
||||
|
Loading…
Reference in New Issue
Block a user