diff --git a/src/engine/AccInfo.c b/src/engine/AccInfo.c index 53af8454fa..957b852078 100644 --- a/src/engine/AccInfo.c +++ b/src/engine/AccInfo.c @@ -15,9 +15,10 @@ char *account_type_name[NUM_ACCOUNT_TYPES] = INCOME_STR, EXPENSE_STR, EQUITY_STR, - CHECKING_STR, - SAVINGS_STR, + CHECKING_STR, + SAVINGS_STR, MONEYMRKT_STR, - CREDITLINE_STR + CREDITLINE_STR, + CURRENCY_STR }; diff --git a/src/engine/AccInfo.h b/src/engine/AccInfo.h index d1fb2ad84b..9f7058af8b 100644 --- a/src/engine/AccInfo.h +++ b/src/engine/AccInfo.h @@ -89,13 +89,13 @@ enum MONEYMRKT = 12, CREDITLINE = 13, /* line of credit */ - /* CURRENCY = 20, */ + CURRENCY = 14, /* The currency account type indicates that the account is a currency trading * account. In many ways, a currency trading account is like a stock trading * account, where both quantities and prices are set. */ - NUM_ACCOUNT_TYPES = 14 + NUM_ACCOUNT_TYPES = 15 }; /* hack alert -- we need a better way of dealing with diff --git a/src/engine/Account.c b/src/engine/Account.c index bace24ec41..0eba99b3eb 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -674,7 +674,16 @@ xaccAccountSetType (Account *acc, int tip) if (!acc) return; CHECK (acc); - /* hack alert -- check for a valid type */ + /* After an account type has been set, it cannot be changed */ + if (-1 < acc->type) { + printf ("Error: xaccAccountSetType(): " + "the type of the account cannot be changed " + "after its been set! \n" + ); + return; + } + + /* hack alert -- check to make sure type is valid ... */ acc->type = tip; } @@ -682,7 +691,7 @@ void xaccAccountSetName (Account *acc, char *str) { char * tmp; - if (!acc) return; + if ((!acc) || (!str)) return; CHECK (acc); /* make strdup before freeing */ @@ -695,7 +704,7 @@ void xaccAccountSetDescription (Account *acc, char *str) { char * tmp; - if (!acc) return; + if ((!acc) || (!str)) return; CHECK (acc); /* make strdup before freeing */ @@ -717,6 +726,22 @@ xaccAccountSetNotes (Account *acc, char *str) acc->notes = tmp; } +void +xaccAccountSetCurrency (Account *acc, char *str) +{ + if ((!acc) || (!str)) return; + CHECK (acc); + + if (acc->currency) { + printf ("Error: xacAccountSetCurrency(): " + "the currency denomination of an account " + "cannot be changed!\n" + ); + return; + } + acc->currency = strdup (str); +} + /********************************************************************\ \********************************************************************/ @@ -762,6 +787,13 @@ xaccAccountGetNotes (Account *acc) return (acc->notes); } +char * +xaccAccountGetCurrency (Account *acc) +{ + if (!acc) return NULL; + return (acc->notes); +} + double xaccAccountGetBalance (Account *acc) { diff --git a/src/engine/Account.h b/src/engine/Account.h index 59baa2407d..682a175077 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -52,7 +52,7 @@ int xaccGetAccountID (Account *); /* * The xaccAccountInsertSplit() method will insert the indicated * split into the indicated account. If the split already - * belongs to anothe account, it will be removed from that + * belongs to another account, it will be removed from that * account first. */ void xaccAccountInsertSplit (Account *, Split *); @@ -101,11 +101,13 @@ void xaccAccountSetType (Account *, int); void xaccAccountSetName (Account *, char *); void xaccAccountSetDescription (Account *, char *); void xaccAccountSetNotes (Account *, char *); +void xaccAccountSetCurrency (Account *, char *); int xaccAccountGetType (Account *); char * xaccAccountGetName (Account *); char * xaccAccountGetDescription (Account *); char * xaccAccountGetNotes (Account *); +char * xaccAccountGetCurrency (Account *); AccountGroup * xaccAccountGetChildren (Account *); AccountGroup * xaccAccountGetParent (Account *);