37 OfxTransactionContainer::OfxTransactionContainer(
LibofxContext *p_libofx_context,
OfxGenericContainer *para_parentcontainer, std::string para_tag_identifier):
42 memset(&data, 0,
sizeof(data));
45 while (tmp_parentcontainer != NULL && tmp_parentcontainer->
type !=
"STATEMENT")
47 tmp_parentcontainer = tmp_parentcontainer->parentcontainer;
49 if (tmp_parentcontainer != NULL)
55 parent_statement = NULL;
56 message_out(
ERROR,
"Unable to find the enclosing statement container this transaction");
58 if (parent_statement != NULL && parent_statement->data.account_id_valid ==
true)
60 ASSIGN_STRNCPY(data.account_id, std::string(parent_statement->data.account_id));
63 OfxTransactionContainer::~OfxTransactionContainer()
70 if (data.unique_id_valid ==
true && MainContainer != NULL)
72 data.security_data_ptr = MainContainer->find_security(data.unique_id);
73 if (data.security_data_ptr != NULL)
75 data.security_data_valid =
true;
78 libofx_context->transactionCallback(data);
85 if (MainContainer != NULL)
87 return MainContainer->add_container(
this);
99 if (identifier ==
"DTPOSTED")
103 else if (identifier ==
"DTUSER")
107 else if (identifier ==
"DTAVAIL")
111 else if (identifier ==
"FITID")
115 else if (identifier ==
"CORRECTFITID")
119 else if (identifier ==
"CORRECTACTION")
121 data.fi_id_correction_action_valid =
true;
122 if (value ==
"REPLACE")
124 data.fi_id_correction_action = REPLACE;
126 else if (value ==
"DELETE")
128 data.fi_id_correction_action = DELETE;
132 data.fi_id_correction_action_valid =
false;
135 else if ((identifier ==
"SRVRTID") || (identifier ==
"SRVRTID2"))
139 else if (identifier ==
"MEMO" || identifier ==
"MEMO2")
143 else if (identifier ==
"CURRENCY")
145 ASSIGN(data.amounts_are_foreign_currency,
false);
147 else if (identifier ==
"ORIGCURRENCY")
149 ASSIGN(data.amounts_are_foreign_currency,
true);
158 void OfxTransactionContainer::add_account(OfxAccountData * account_data)
160 if (account_data->account_id_valid ==
true)
162 data.account_ptr = account_data;
163 ASSIGN_STRNCPY(data.account_id, std::string(account_data->account_id));
171 OfxBankTransactionContainer::OfxBankTransactionContainer(
LibofxContext *p_libofx_context,
OfxGenericContainer *para_parentcontainer, std::string para_tag_identifier):
178 if ( identifier ==
"TRNTYPE")
180 data.transactiontype_valid =
true;
181 if (value ==
"CREDIT")
183 data.transactiontype = OFX_CREDIT;
185 else if (value ==
"DEBIT")
187 data.transactiontype = OFX_DEBIT;
189 else if (value ==
"INT")
191 data.transactiontype = OFX_INT;
193 else if (value ==
"DIV")
195 data.transactiontype = OFX_DIV;
197 else if (value ==
"FEE")
199 data.transactiontype = OFX_FEE;
201 else if (value ==
"SRVCHG")
203 data.transactiontype = OFX_SRVCHG;
205 else if (value ==
"DEP")
207 data.transactiontype = OFX_DEP;
209 else if (value ==
"ATM")
211 data.transactiontype = OFX_ATM;
213 else if (value ==
"POS")
215 data.transactiontype = OFX_POS;
217 else if (value ==
"XFER")
219 data.transactiontype = OFX_XFER;
221 else if (value ==
"CHECK")
223 data.transactiontype = OFX_CHECK;
225 else if (value ==
"PAYMENT")
227 data.transactiontype = OFX_PAYMENT;
229 else if (value ==
"CASH")
231 data.transactiontype = OFX_CASH;
233 else if (value ==
"DIRECTDEP")
235 data.transactiontype = OFX_DIRECTDEP;
237 else if (value ==
"DIRECTDEBIT")
239 data.transactiontype = OFX_DIRECTDEBIT;
241 else if (value ==
"REPEATPMT")
243 data.transactiontype = OFX_REPEATPMT;
245 else if (value ==
"OTHER")
247 data.transactiontype = OFX_OTHER;
251 data.transactiontype_valid =
false;
254 else if (identifier ==
"TRNAMT")
257 ASSIGN(data.units, -data.amount);
258 ASSIGN(data.unitprice, 1.00);
260 else if (identifier ==
"CHECKNUM")
264 else if (identifier ==
"REFNUM")
268 else if (identifier ==
"SIC")
270 ASSIGN(data.standard_industrial_code, atoi(value.c_str()));
272 else if ((identifier ==
"PAYEEID") || (identifier ==
"PAYEEID2"))
276 else if (identifier ==
"NAME")
292 OfxInvestmentTransactionContainer::OfxInvestmentTransactionContainer(
LibofxContext *p_libofx_context,
OfxGenericContainer *para_parentcontainer, std::string para_tag_identifier):
296 ASSIGN(data.transactiontype, OFX_OTHER);
298 data.invtransactiontype_valid =
true;
299 if (para_tag_identifier ==
"BUYDEBT")
301 data.invtransactiontype = OFX_BUYDEBT;
303 else if (para_tag_identifier ==
"BUYMF")
305 data.invtransactiontype = OFX_BUYMF;
307 else if (para_tag_identifier ==
"BUYOPT")
309 data.invtransactiontype = OFX_BUYOPT;
311 else if (para_tag_identifier ==
"BUYOTHER")
313 data.invtransactiontype = OFX_BUYOTHER;
315 else if (para_tag_identifier ==
"BUYSTOCK")
317 data.invtransactiontype = OFX_BUYSTOCK;
319 else if (para_tag_identifier ==
"CLOSUREOPT")
321 data.invtransactiontype = OFX_CLOSUREOPT;
323 else if (para_tag_identifier ==
"INCOME")
325 data.invtransactiontype = OFX_INCOME;
327 else if (para_tag_identifier ==
"INVEXPENSE")
329 data.invtransactiontype = OFX_INVEXPENSE;
331 else if (para_tag_identifier ==
"JRNLFUND")
333 data.invtransactiontype = OFX_JRNLFUND;
335 else if (para_tag_identifier ==
"JRNLSEC")
337 data.invtransactiontype = OFX_JRNLSEC;
339 else if (para_tag_identifier ==
"MARGININTEREST")
341 data.invtransactiontype = OFX_MARGININTEREST;
343 else if (para_tag_identifier ==
"REINVEST")
345 data.invtransactiontype = OFX_REINVEST;
347 else if (para_tag_identifier ==
"RETOFCAP")
349 data.invtransactiontype = OFX_RETOFCAP;
351 else if (para_tag_identifier ==
"SELLDEBT")
353 data.invtransactiontype = OFX_SELLDEBT;
355 else if (para_tag_identifier ==
"SELLMF")
357 data.invtransactiontype = OFX_SELLMF;
359 else if (para_tag_identifier ==
"SELLOPT")
361 data.invtransactiontype = OFX_SELLOPT;
363 else if (para_tag_identifier ==
"SELLOTHER")
365 data.invtransactiontype = OFX_SELLOTHER;
367 else if (para_tag_identifier ==
"SELLSTOCK")
369 data.invtransactiontype = OFX_SELLSTOCK;
371 else if (para_tag_identifier ==
"SPLIT")
373 data.invtransactiontype = OFX_SPLIT;
375 else if (para_tag_identifier ==
"TRANSFER")
377 data.invtransactiontype = OFX_TRANSFER;
379 else if (para_tag_identifier ==
"INVBANKTRAN")
381 data.invtransactiontype = OFX_INVBANKTRAN;
385 message_out(
ERROR,
"This should not happen, " + para_tag_identifier +
" is an unknown investment transaction type");
386 data.invtransactiontype_valid =
false;
392 if (identifier ==
"UNIQUEID")
396 else if (identifier ==
"UNIQUEIDTYPE")
400 else if (identifier ==
"UNITS")
404 else if (identifier ==
"UNITPRICE")
408 else if (identifier ==
"MKTVAL")
412 else if (identifier ==
"TOTAL")
416 else if (identifier ==
"CURRATE")
420 else if (identifier ==
"CURSYM")
424 else if (identifier ==
"DTSETTLE")
428 else if (identifier ==
"DTTRADE")
432 else if (identifier ==
"COMMISSION")
436 else if (identifier ==
"FEES")
440 else if (identifier ==
"OLDUNITS")
444 else if (identifier ==
"NEWUNITS")
448 else if (identifier ==
"ACCRDINT")
452 else if (identifier ==
"AVGCOSTBASIS")
456 else if (identifier ==
"BUYTYPE" || identifier ==
"OPTBUYTYPE")
460 ASSIGN(data.buy_type, data.OFX_BUY_TYPE_BUY);
462 else if (value ==
"BUYTOCOVER")
464 ASSIGN(data.buy_type, data.OFX_BUY_TYPE_BUYTOCOVER);
466 else if (value ==
"BUYTOOPEN")
468 ASSIGN(data.buy_type, data.OFX_BUY_TYPE_BUYTOOPEN);
470 else if (value ==
"BUYTOCLOSE")
472 ASSIGN(data.buy_type, data.OFX_BUY_TYPE_BUYTOCLOSE);
475 else if (identifier ==
"DENOMINATOR")
479 else if (identifier ==
"DTPAYROLL")
483 else if (identifier ==
"DTPURCHASE")
487 else if (identifier ==
"GAIN")
491 else if (identifier ==
"FRACCASH")
495 else if (identifier ==
"INCOMETYPE")
497 if (value ==
"CGLONG")
499 ASSIGN(data.income_type, data.OFX_CGLONG);
501 else if (value ==
"CGSHORT")
503 ASSIGN(data.income_type, data.OFX_CGSHORT);
505 else if (value ==
"DIV")
507 ASSIGN(data.income_type, data.OFX_DIVIDEND);
509 else if (value ==
"INTEREST")
511 ASSIGN(data.income_type, data.OFX_INTEREST);
513 else if (value ==
"MISC")
515 ASSIGN(data.income_type, data.OFX_MISC);
518 else if (identifier ==
"INV401KSOURCE")
520 if (value ==
"PRETAX")
522 ASSIGN(data.inv_401k_source, data.OFX_401K_SOURCE_PRETAX);
524 else if (value ==
"AFTERTAX")
526 ASSIGN(data.inv_401k_source, data.OFX_401K_SOURCE_AFTERTAX);
528 else if (value ==
"MATCH")
530 ASSIGN(data.inv_401k_source, data.OFX_401K_SOURCE_MATCH);
532 else if (value ==
"PROFITSHARING")
534 ASSIGN(data.inv_401k_source, data.OFX_401K_SOURCE_PROFITSHARING);
536 else if (value ==
"ROLLOVER")
538 ASSIGN(data.inv_401k_source, data.OFX_401K_SOURCE_ROLLOVER);
540 else if (value ==
"OTHERVEST")
542 ASSIGN(data.inv_401k_source, data.OFX_401K_SOURCE_OTHERVEST);
544 else if (value ==
"OTHERNONVEST")
546 ASSIGN(data.inv_401k_source, data.OFX_401K_SOURCE_OTHERNONVEST);
549 else if (identifier ==
"LOAD")
553 else if (identifier ==
"LOANID")
557 else if (identifier ==
"LOANINTEREST")
561 else if (identifier ==
"LOANPRINCIPAL")
565 else if (identifier ==
"MARKDOWN")
569 else if (identifier ==
"MARKUP")
573 else if (identifier ==
"NUMERATOR")
577 else if (identifier ==
"OPTACTION")
579 if (value ==
"EXERCISE")
581 ASSIGN(data.opt_action, data.OFX_OPTACTION_EXERCISE);
583 else if (value ==
"ASSIGN")
585 ASSIGN(data.opt_action, data.OFX_OPTACTION_ASSIGN);
587 else if (value ==
"EXPIRE")
589 ASSIGN(data.opt_action, data.OFX_OPTACTION_EXPIRE);
592 else if (identifier ==
"PENALTY")
596 else if (identifier ==
"POSTYPE")
600 ASSIGN(data.pos_type, data.OFX_POSTYPE_LONG);
602 else if (value ==
"SHORT")
604 ASSIGN(data.pos_type, data.OFX_POSTYPE_SHORT);
607 else if (identifier ==
"PRIORYEARCONTRIB")
611 ASSIGN(data.prior_year_contrib,
true);
613 else if (value ==
"N")
615 ASSIGN(data.prior_year_contrib,
false);
618 else if (identifier ==
"RELFITID")
622 else if (identifier ==
"RELTYPE")
624 if (value ==
"SPREAD")
626 ASSIGN(data.related_type, data.OFX_RELTYPE_SPREAD);
628 else if (value ==
"STRADDLE")
630 ASSIGN(data.related_type, data.OFX_RELTYPE_STRADDLE);
632 else if (value ==
"NONE")
634 ASSIGN(data.related_type, data.OFX_RELTYPE_NONE);
636 else if (value ==
"OTHER")
638 ASSIGN(data.related_type, data.OFX_RELTYPE_OTHER);
641 else if (identifier ==
"SECURED")
643 if (value ==
"NAKED")
645 ASSIGN(data.option_secured, data.OFX_SECURED_NAKED);
647 else if (value ==
"COVERED")
649 ASSIGN(data.option_secured, data.OFX_SECURED_COVERED);
652 else if (identifier ==
"SELLREASON")
656 ASSIGN(data.sell_reason, data.OFX_SELLREASON_CALL);
658 else if (value ==
"SELL")
660 ASSIGN(data.sell_reason, data.OFX_SELLREASON_SELL);
662 else if (value ==
"MATURITY")
664 ASSIGN(data.sell_reason, data.OFX_SELLREASON_MATURITY);
667 else if (identifier ==
"SELLTYPE" || identifier ==
"OPTSELLTYPE")
671 ASSIGN(data.sell_type, data.OFX_SELL_TYPE_SELL);
673 else if (value ==
"SELLSHORT")
675 ASSIGN(data.sell_type, data.OFX_SELL_TYPE_SELLSHORT);
677 else if (value ==
"SELLTOOPEN")
679 ASSIGN(data.sell_type, data.OFX_SELL_TYPE_SELLTOOPEN);
681 else if (value ==
"SELLTOCLOSE")
683 ASSIGN(data.sell_type, data.OFX_SELL_TYPE_SELLTOCLOSE);
686 else if (identifier ==
"SHPERCTRCT")
690 else if (identifier ==
"STATEWITHHOLDING")
694 else if (identifier ==
"SUBACCTFROM")
698 ASSIGN(data.subacct_from, data.OFX_SUBACCT_CASH);
700 else if (value ==
"MARGIN")
702 ASSIGN(data.subacct_from, data.OFX_SUBACCT_MARGIN);
704 else if (value ==
"SHORT")
706 ASSIGN(data.subacct_from, data.OFX_SUBACCT_SHORT);
708 else if (value ==
"OTHER")
710 ASSIGN(data.subacct_from, data.OFX_SUBACCT_OTHER);
713 else if (identifier ==
"SUBACCTFUND")
717 ASSIGN(data.subacct_funding, data.OFX_SUBACCT_CASH);
719 else if (value ==
"MARGIN")
721 ASSIGN(data.subacct_funding, data.OFX_SUBACCT_MARGIN);
723 else if (value ==
"SHORT")
725 ASSIGN(data.subacct_funding, data.OFX_SUBACCT_SHORT);
727 else if (value ==
"OTHER")
729 ASSIGN(data.subacct_funding, data.OFX_SUBACCT_OTHER);
732 else if (identifier ==
"SUBACCTSEC")
736 ASSIGN(data.subacct_security, data.OFX_SUBACCT_CASH);
738 else if (value ==
"MARGIN")
740 ASSIGN(data.subacct_security, data.OFX_SUBACCT_MARGIN);
742 else if (value ==
"SHORT")
744 ASSIGN(data.subacct_security, data.OFX_SUBACCT_SHORT);
746 else if (value ==
"OTHER")
748 ASSIGN(data.subacct_security, data.OFX_SUBACCT_OTHER);
751 else if (identifier ==
"SUBACCTTO")
755 ASSIGN(data.subacct_to, data.OFX_SUBACCT_CASH);
757 else if (value ==
"MARGIN")
759 ASSIGN(data.subacct_to, data.OFX_SUBACCT_MARGIN);
761 else if (value ==
"SHORT")
763 ASSIGN(data.subacct_to, data.OFX_SUBACCT_SHORT);
765 else if (value ==
"OTHER")
767 ASSIGN(data.subacct_to, data.OFX_SUBACCT_OTHER);
770 else if (identifier ==
"TAXES")
774 else if (identifier ==
"TAXEXEMPT")
778 ASSIGN(data.tax_exempt,
true);
780 else if (value ==
"N")
782 ASSIGN(data.tax_exempt,
false);
785 else if (identifier ==
"TFERACTION")
789 ASSIGN(data.transfer_action, data.OFX_TFERACTION_IN);
791 else if (value ==
"OUT")
793 ASSIGN(data.transfer_action, data.OFX_TFERACTION_OUT);
796 else if (identifier ==
"UNITTYPE")
798 if (value ==
"SHARES")
800 ASSIGN(data.unit_type, data.OFX_UNITTYPE_SHARES);
802 else if (value ==
"CURRENCY")
804 ASSIGN(data.unit_type, data.OFX_UNITTYPE_CURRENCY);
807 else if (identifier ==
"WITHHOLDING")
812 else if ( identifier ==
"TRNTYPE")
814 data.transactiontype_valid =
true;
815 if (value ==
"CREDIT")
817 data.transactiontype = OFX_CREDIT;
819 else if (value ==
"DEBIT")
821 data.transactiontype = OFX_DEBIT;
823 else if (value ==
"INT")
825 data.transactiontype = OFX_INT;
827 else if (value ==
"DIV")
829 data.transactiontype = OFX_DIV;
831 else if (value ==
"FEE")
833 data.transactiontype = OFX_FEE;
835 else if (value ==
"SRVCHG")
837 data.transactiontype = OFX_SRVCHG;
839 else if (value ==
"DEP")
841 data.transactiontype = OFX_DEP;
843 else if (value ==
"ATM")
845 data.transactiontype = OFX_ATM;
847 else if (value ==
"POS")
849 data.transactiontype = OFX_POS;
851 else if (value ==
"XFER")
853 data.transactiontype = OFX_XFER;
855 else if (value ==
"CHECK")
857 data.transactiontype = OFX_CHECK;
859 else if (value ==
"PAYMENT")
861 data.transactiontype = OFX_PAYMENT;
863 else if (value ==
"CASH")
865 data.transactiontype = OFX_CASH;
867 else if (value ==
"DIRECTDEP")
869 data.transactiontype = OFX_DIRECTDEP;
871 else if (value ==
"DIRECTDEBIT")
873 data.transactiontype = OFX_DIRECTDEBIT;
875 else if (value ==
"REPEATPMT")
877 data.transactiontype = OFX_REPEATPMT;
879 else if (value ==
"OTHER")
881 data.transactiontype = OFX_OTHER;
885 data.transactiontype_valid =
false;
888 else if (identifier ==
"TRNAMT")
891 ASSIGN(data.units, -data.amount);
892 ASSIGN(data.unitprice, 1.00);
894 else if (identifier ==
"CHECKNUM")
898 else if (identifier ==
"REFNUM")
902 else if (identifier ==
"SIC")
904 ASSIGN(data.standard_industrial_code, atoi(value.c_str()));
906 else if ((identifier ==
"PAYEEID") || (identifier ==
"PAYEEID2"))
910 else if (identifier ==
"NAME")
virtual int add_to_main_tree()
Add this container to the main tree.
time_t ofxdate_to_time_t(const std::string &ofxdate)
Convert a C++ string containing a time in OFX format to a C time_t.
A generic container for an OFX SGML element. Every container inherits from OfxGenericContainer.
virtual void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
Represents a generic transaction.
int message_out(OfxMsgType error_type, const std::string message)
Message output function.
void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
double ofxamount_to_double(const std::string ofxamount)
Convert OFX amount of money to double float.
Various simple functions for type conversion & al.
Represents a statement for either a bank account or a credit card account.
void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.
#define ASSIGN_STRNCPY(DEST, VALUE)
LibOFX internal object code.
Message IO functionality.
The root container. Created by the <OFX> OFX element or by the export functions.
#define ASSIGN(DEST, VALUE)
virtual int gen_event()
Generate libofx.h events.
virtual void add_attribute(const std::string identifier, const std::string value)
Add data to a container object.