本文整理汇总了C++中MyMoneyFile::addTransaction方法的典型用法代码示例。如果您正苦于以下问题:C++ MyMoneyFile::addTransaction方法的具体用法?C++ MyMoneyFile::addTransaction怎么用?C++ MyMoneyFile::addTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyMoneyFile
的用法示例。
在下文中一共展示了MyMoneyFile::addTransaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void InvTransactionHelper::init( const QDate& _date, const QString& _action, MyMoneyMoney _shares, MyMoneyMoney _price, const QString& _stockaccountid, const QString& _transferid, const QString& _categoryid )
{
MyMoneyFile* file = MyMoneyFile::instance();
MyMoneyAccount stockaccount = file->account(_stockaccountid);
MyMoneyMoney value = _shares * _price;
setPostDate(_date);
setCommodity("USD");
MyMoneySplit s1;
s1.setValue(value);
s1.setAccountId(_stockaccountid);
if ( _action == MyMoneySplit::ActionReinvestDividend )
{
s1.setShares(_shares);
s1.setAction(MyMoneySplit::ActionReinvestDividend);
MyMoneySplit s2;
s2.setAccountId(_categoryid);
s2.setShares(-value);
s2.setValue(-value);
addSplit(s2);
}
else if ( _action == MyMoneySplit::ActionDividend || _action == MyMoneySplit::ActionYield )
{
s1.setAccountId(_categoryid);
s1.setShares(-value);
s1.setValue(-value);
// Split 2 will be the zero-amount investment split that serves to
// mark this transaction as a cash dividend and note which stock account
// it belongs to.
MyMoneySplit s2;
s2.setValue(0);
s2.setShares(0);
s2.setAction(_action);
s2.setAccountId(_stockaccountid);
addSplit(s2);
MyMoneySplit s3;
s3.setAccountId(_transferid);
s3.setShares(value);
s3.setValue(value);
addSplit(s3);
}
else if ( _action == MyMoneySplit::ActionBuyShares )
{
s1.setShares(_shares);
s1.setAction(MyMoneySplit::ActionBuyShares);
MyMoneySplit s3;
s3.setAccountId(_transferid);
s3.setShares(-value);
s3.setValue(-value);
addSplit(s3);
}
addSplit(s1);
//kdDebug(2) << "created transaction, now adding..." << endl;
MyMoneyFileTransaction ft;
file->addTransaction(*this);
//kdDebug(2) << "updating price..." << endl;
// update the price, while we're here
QString stockid = stockaccount.currencyId();
QString basecurrencyid = file->baseCurrency().id();
MyMoneyPrice price = file->price( stockid, basecurrencyid, _date, true );
if ( !price.isValid() )
{
MyMoneyPrice newprice( stockid, basecurrencyid, _date, _price, "test" );
file->addPrice(newprice);
}
ft.commit();
//kdDebug(2) << "successfully added " << id() << endl;
}