port to use splits

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@391 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-01-07 21:41:49 +00:00
parent c4b1356ebf
commit a8c79c7d4c

View File

@ -580,9 +580,9 @@ xaccGetSecurityQIFAccount (Account *acc, char *qifline)
* Return: first new line after end of transaction * * Return: first new line after end of transaction *
\********************************************************************/ \********************************************************************/
#define XACC_ACTION(q,x) \ #define XACC_ACTION(q,x) \
if (!strncmp (&qifline[1], q, strlen(q))) { \ if (!strncmp (&qifline[1], q, strlen(q))) { \
trans->action = XtNewString(x); \ trans->credit_split.action = XtNewString(x); \
} else } else
@ -600,18 +600,13 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
double adjust = 0.0; double adjust = 0.0;
if (!acc) return NULL; if (!acc) return NULL;
trans = mallocTransaction ();
qifline = xaccReadQIFLine (fd); qifline = xaccReadQIFLine (fd);
if (!qifline) return NULL;
if (!qifline) {
xaccRemoveTransaction ((Account *) trans->debit, trans);
xaccRemoveTransaction ((Account *) trans->credit_split.acc, trans);
freeTransaction (trans);
return NULL;
}
if ('!' == qifline [0]) return qifline; if ('!' == qifline [0]) return qifline;
trans = mallocTransaction ();
/* scan for transaction date, description, type */ /* scan for transaction date, description, type */
while (qifline) { while (qifline) {
/* D == date */ /* D == date */
@ -628,7 +623,7 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
/* I == share price */ /* I == share price */
if ('I' == qifline [0]) { if ('I' == qifline [0]) {
trans -> share_price = xaccParseQIFAmount (&qifline[1]); trans -> credit_split.share_price = xaccParseQIFAmount (&qifline[1]);
} else } else
/* L == name of acount from which transfer occured */ /* L == name of acount from which transfer occured */
@ -672,7 +667,7 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
if ('O' == qifline [0]) { if ('O' == qifline [0]) {
double pute; double pute;
adjust = xaccParseQIFAmount (&qifline[1]); adjust = xaccParseQIFAmount (&qifline[1]);
pute = (trans->damount) * (trans->share_price); pute = (trans->credit_split.damount) * (trans->credit_split.share_price);
if (isneg) pute = -pute; if (isneg) pute = -pute;
printf ("QIF Warning: Adjustment of %.2f to amount %.2f not handled \n", adjust, pute); printf ("QIF Warning: Adjustment of %.2f to amount %.2f not handled \n", adjust, pute);
@ -685,8 +680,8 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
/* Q == number of shares */ /* Q == number of shares */
if ('Q' == qifline [0]) { if ('Q' == qifline [0]) {
trans -> damount = xaccParseQIFAmount (&qifline[1]); trans -> credit_split.damount = xaccParseQIFAmount (&qifline[1]);
if (isneg) trans -> damount = - (trans->damount); if (isneg) trans -> credit_split.damount = - (trans->credit_split.damount);
got_share_quantity = 1; got_share_quantity = 1;
} else } else
@ -698,6 +693,7 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
split -> damount = 0.0; /* amount is double */ split -> damount = 0.0; /* amount is double */
split -> share_price= 1.0; /* share_price is double */ split -> share_price= 1.0; /* share_price is double */
split -> reconciled = NREC; /* reconciled is byte */ split -> reconciled = NREC; /* reconciled is byte */
split -> parent = trans; /* parent transaction */
split -> acc = (struct _account *) xaccGetXferQIFAccount (acc, qifline); split -> acc = (struct _account *) xaccGetXferQIFAccount (acc, qifline);
xaccAppendSplit (trans, split); xaccAppendSplit (trans, split);
@ -710,8 +706,8 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
if ('T' == qifline [0]) { if ('T' == qifline [0]) {
/* ignore T for stock transactions, since T is a dollar amount */ /* ignore T for stock transactions, since T is a dollar amount */
if (0 == got_share_quantity) { if (0 == got_share_quantity) {
trans -> damount = xaccParseQIFAmount (&qifline[1]); trans -> credit_split.damount = xaccParseQIFAmount (&qifline[1]);
if (isneg) trans -> damount = - (trans->damount); if (isneg) trans -> credit_split.damount = - (trans->credit_split.damount);
} }
} else } else
@ -743,7 +739,7 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
double parse, pute; double parse, pute;
int got, wanted; int got, wanted;
parse = xaccParseQIFAmount (&qifline[1]); parse = xaccParseQIFAmount (&qifline[1]);
pute = (trans->damount) * (trans->share_price); pute = (trans->credit_split.damount) * (trans->credit_split.share_price);
if (isneg) pute = -pute; if (isneg) pute = -pute;
wanted = (int) (100.0 * parse + 0.5); wanted = (int) (100.0 * parse + 0.5);
@ -773,16 +769,14 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
* if we see something else, assume the worst, free the last * if we see something else, assume the worst, free the last
* transaction, and return */ * transaction, and return */
if ('!' == qifline[0]) { if ('!' == qifline[0]) {
xaccRemoveTransaction ((Account *) trans->debit, trans);
xaccRemoveTransaction ((Account *) trans->credit_split.acc, trans);
freeTransaction (trans); freeTransaction (trans);
return qifline; return qifline;
} }
XACC_PREP_NULL_STRING (trans->num); XACC_PREP_NULL_STRING (trans->num);
XACC_PREP_NULL_STRING (trans->credit_split.memo);
XACC_PREP_NULL_STRING (trans->description); XACC_PREP_NULL_STRING (trans->description);
XACC_PREP_NULL_STRING (trans->action); XACC_PREP_NULL_STRING (trans->credit_split.memo);
XACC_PREP_NULL_STRING (trans->credit_split.action);
/* fundamentally differnt handling for securities and non-securities */ /* fundamentally differnt handling for securities and non-securities */
@ -792,15 +786,20 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
* then it is a defacto transfer between the brokerage account * then it is a defacto transfer between the brokerage account
* and the stock account. */ * and the stock account. */
if (share_xfer) { if (share_xfer) {
if (!split) {
split = xaccMallocSplit ();
xaccAppendSplit (trans, split);
}
/* Insert the transaction into the main brokerage /* Insert the transaction into the main brokerage
* account as a debit, unless an alternate account * account as a debit, unless an alternate account
* was specified. */ * was specified. */
if (xfer_acc) { if (xfer_acc) {
trans->debit = (struct _account *) xfer_acc; split->acc = (struct _account *) xfer_acc;
insertTransaction (xfer_acc, trans); xaccInsertSplit (xfer_acc, split);
} else { } else {
trans->debit = (struct _account *) acc; split->acc = (struct _account *) acc;
insertTransaction (acc, trans); xaccInsertSplit (acc, split);
} }
/* normally, the security account is pointed at by /* normally, the security account is pointed at by
@ -808,7 +807,7 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
* But, just in case its missing, avoid a core dump */ * But, just in case its missing, avoid a core dump */
if (sub_acc) { if (sub_acc) {
trans->credit_split.acc = (struct _account *) sub_acc; trans->credit_split.acc = (struct _account *) sub_acc;
insertTransaction (sub_acc, trans); xaccInsertSplit (sub_acc, split);
} }
} else { } else {
@ -820,10 +819,10 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
* main account gets it */ * main account gets it */
if (xfer_acc) { if (xfer_acc) {
trans->credit_split.acc = (struct _account *) xfer_acc; trans->credit_split.acc = (struct _account *) xfer_acc;
insertTransaction (xfer_acc, trans); xaccInsertSplit (xfer_acc, &(trans->credit_split));
} else { } else {
trans->credit_split.acc = (struct _account *) acc; trans->credit_split.acc = (struct _account *) acc;
insertTransaction( acc, trans ); xaccInsertSplit (acc, &(trans->credit_split));
} }
} }
@ -831,13 +830,17 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
/* if we are here, its not a security, but an ordinary account */ /* if we are here, its not a security, but an ordinary account */
/* if a transfer account was specified, it is the debited account */ /* if a transfer account was specified, it is the debited account */
if (xfer_acc) { if (xfer_acc) {
trans->debit = (struct _account *) xfer_acc; if (!split) {
insertTransaction (xfer_acc, trans); split = xaccMallocSplit ();
xaccAppendSplit (trans, split);
}
split->acc = (struct _account *) xfer_acc;
xaccInsertSplit (xfer_acc, split);
} }
/* the transaction itself appears as a credit */ /* the transaction itself appears as a credit */
trans->credit_split.acc = (struct _account *) acc; trans->credit_split.acc = (struct _account *) acc;
insertTransaction( acc, trans ); xaccInsertSplit (acc, &(trans->credit_split));
} }
return qifline; return qifline;