mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
fix how splits work, make completly engine independent
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@741 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
2b20f9100d
commit
0305aa09c6
@ -27,8 +27,9 @@
|
|||||||
* *
|
* *
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
|
|
||||||
/* hack alert -- splits & stocks probably not handled correctly
|
/* hack alert -- stocks probably not handled correctly
|
||||||
* this stuff still needs work
|
* this stuff still needs work
|
||||||
|
* also, check out a stock split tooo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -38,12 +39,9 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
#include "AccountP.h"
|
|
||||||
#include "Group.h"
|
#include "Group.h"
|
||||||
#include "GroupP.h"
|
|
||||||
#include "FileIO.h"
|
#include "FileIO.h"
|
||||||
#include "Transaction.h"
|
#include "Transaction.h"
|
||||||
#include "TransactionP.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define PERMS 0666
|
#define PERMS 0666
|
||||||
@ -454,7 +452,7 @@ GetSubQIFAccount (AccountGroup *rootgrp, char *qifline, int acc_type)
|
|||||||
{
|
{
|
||||||
Account *xfer_acc;
|
Account *xfer_acc;
|
||||||
char * sub_ptr;
|
char * sub_ptr;
|
||||||
int i;
|
int i, nacc;
|
||||||
|
|
||||||
/* search for colons in name -- this indicates a sub-account */
|
/* search for colons in name -- this indicates a sub-account */
|
||||||
sub_ptr = strchr (qifline, ':');
|
sub_ptr = strchr (qifline, ':');
|
||||||
@ -465,8 +463,9 @@ GetSubQIFAccount (AccountGroup *rootgrp, char *qifline, int acc_type)
|
|||||||
/* see if the account exists; but search only one level down,
|
/* see if the account exists; but search only one level down,
|
||||||
* not the full account tree */
|
* not the full account tree */
|
||||||
xfer_acc = NULL;
|
xfer_acc = NULL;
|
||||||
for (i=0; i<rootgrp->numAcc; i++) {
|
nacc = xaccGroupGetNumAccounts (rootgrp);
|
||||||
Account *acc = rootgrp->account[i];
|
for (i=0; i<nacc; i++) {
|
||||||
|
Account *acc = xaccGroupGetAccount (rootgrp, i);
|
||||||
char * acc_name = xaccAccountGetName (acc);
|
char * acc_name = xaccAccountGetName (acc);
|
||||||
if (!strcmp(acc_name, qifline)) {
|
if (!strcmp(acc_name, qifline)) {
|
||||||
xfer_acc = acc;
|
xfer_acc = acc;
|
||||||
@ -489,11 +488,11 @@ GetSubQIFAccount (AccountGroup *rootgrp, char *qifline, int acc_type)
|
|||||||
/* if this account name had sub-accounts, get those */
|
/* if this account name had sub-accounts, get those */
|
||||||
if (sub_ptr) {
|
if (sub_ptr) {
|
||||||
sub_ptr ++;
|
sub_ptr ++;
|
||||||
rootgrp = xfer_acc->children;
|
rootgrp = xaccAccountGetChildren (xfer_acc);
|
||||||
if (!rootgrp) {
|
if (!rootgrp) {
|
||||||
rootgrp = xaccMallocAccountGroup();
|
/* inserting a null child has effect of creating empty container */
|
||||||
xfer_acc->children = rootgrp;
|
xaccInsertSubAccount (xfer_acc, NULL);
|
||||||
rootgrp->parent = xfer_acc;
|
rootgrp = xaccAccountGetChildren (xfer_acc);
|
||||||
}
|
}
|
||||||
xfer_acc = GetSubQIFAccount (rootgrp, sub_ptr, acc_type);
|
xfer_acc = GetSubQIFAccount (rootgrp, sub_ptr, acc_type);
|
||||||
}
|
}
|
||||||
@ -627,7 +626,9 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
|
|||||||
|
|
||||||
/* D == date */
|
/* D == date */
|
||||||
if ('D' == qifline [0]) {
|
if ('D' == qifline [0]) {
|
||||||
xaccParseQIFDate (&(trans->date), &qifline[1]);
|
Date dayt;
|
||||||
|
xaccParseQIFDate (&dayt, &qifline[1]);
|
||||||
|
xaccTransSetDate (trans, dayt.day, dayt.month, dayt.year);
|
||||||
} else
|
} else
|
||||||
|
|
||||||
/* E == memo for split */
|
/* E == memo for split */
|
||||||
@ -707,15 +708,17 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
|
|||||||
got_share_quantity = 1;
|
got_share_quantity = 1;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
/* S == split */
|
/* S == split, name of debited account */
|
||||||
if ('S' == qifline [0]) {
|
if ('S' == qifline [0]) {
|
||||||
split = xaccMallocSplit();
|
split = xaccMallocSplit();
|
||||||
|
|
||||||
xaccTransAppendSplit (trans, split);
|
xaccTransAppendSplit (trans, split);
|
||||||
/* xxxxx */
|
xfer_acc = xaccGetXferQIFAccount (acc, qifline);
|
||||||
split -> acc = xaccGetXferQIFAccount (acc, qifline);
|
xaccAccountInsertSplit (xfer_acc, split);
|
||||||
/* hack alert -- we should insert this split into
|
|
||||||
* the split account, and remove the L field */
|
/* set xfer account to NULL, so that we don't
|
||||||
|
* end up adding spurious splits */
|
||||||
|
xfer_acc = NULL;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
/* T == total */
|
/* T == total */
|
||||||
@ -746,12 +749,13 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
|
|||||||
/* for splits, $ records the part of the total for each split */
|
/* for splits, $ records the part of the total for each split */
|
||||||
if (split) {
|
if (split) {
|
||||||
double amt = xaccParseUSAmount (&qifline[1]);
|
double amt = xaccParseUSAmount (&qifline[1]);
|
||||||
|
amt = -amt;
|
||||||
xaccSplitSetValue (split, amt);
|
xaccSplitSetValue (split, amt);
|
||||||
} else {
|
} else {
|
||||||
/* Currently, it appears that the $ amount is a redundant
|
/* Currently, it appears that the $ amount is a redundant
|
||||||
* number that we can safely ignore. To get fancy,
|
* number that we can safely ignore. To get fancy,
|
||||||
* we use it to double-check the above work, since it
|
* we use it to double-check the above work, since it
|
||||||
* appears to always appear the last entry in the
|
* appears to always appear as the last entry in the
|
||||||
* transaction. Round things out to pennies, to
|
* transaction. Round things out to pennies, to
|
||||||
* handle round-off errors.
|
* handle round-off errors.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user