Index: kmymoney/reports/querytable.cpp =================================================================== --- kmymoney/reports/querytable.cpp +++ kmymoney/reports/querytable.cpp @@ -544,41 +544,65 @@ const QList tagIdList = (*it_split).tagIdList(); //convert to base currency - if (m_config.isConvertCurrency()) { - xr = (splitAcc.deepCurrencyPrice((*it_transaction).postDate()) * splitAcc.baseCurrencyPrice((*it_transaction).postDate())).reduce(); - } else { - xr = (splitAcc.deepCurrencyPrice((*it_transaction).postDate())).reduce(); - } + if (m_config.isConvertCurrency()) + xr = splitAcc.baseCurrencyPrice((*it_transaction).postDate()); + else + xr = MyMoneyMoney::ONE; if (splitAcc.isInvest()) { // use the institution of the parent for stock accounts institution = splitAcc.parent().institutionId(); MyMoneyMoney shares = (*it_split).shares(); qA["action"] = (*it_split).action(); - qA["shares"] = shares.isZero() ? "" : (*it_split).shares().toString(); - qA["price"] = shares.isZero() ? "" : xr.convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())).toString(); + qA["shares"] = shares.isZero() ? "" : shares.toString(); + qA["price"] = shares.isZero() ? "" : ((*it_split).price() * xr).convert(MyMoneyMoney::precToDenom(KMyMoneyGlobalSettings::pricePrecision())).toString(); - if (((*it_split).action() == MyMoneySplit::ActionBuyShares) && (*it_split).shares().isNegative()) + if (((*it_split).action() == MyMoneySplit::ActionBuyShares) && shares.isNegative()) qA["action"] = "Sell"; qA["investaccount"] = splitAcc.parent().name(); } if (it_split == myBegin) { include_me = m_config.includes(splitAcc); - a_fullname = splitAcc.fullName(); - a_memo = (*it_split).memo(); - - transaction_text = m_config.match(&(*it_split)); + if (include_me) + // track accts that will need opening and closing balances + //FIXME in some cases it will show the opening and closing + //balances but no transactions if the splits are all filtered out -- asoliverez + accts.insert(splitAcc.id(), splitAcc); - qA["price"] = xr.toString(); qA["account"] = splitAcc.name(); qA["accountid"] = splitAcc.id(); qA["topaccount"] = splitAcc.topParentName(); + if (splitAcc.isInvest()) { + MyMoneySplit assetAccountSplit; + QList feeSplits; + QList interestSplits; + MyMoneySecurity currency; + MyMoneySecurity security; + MyMoneySplit::investTransactionTypeE transactionType; + KMyMoneyUtils::dissectTransaction((*it_transaction), (*it_split), assetAccountSplit, feeSplits, interestSplits, security, currency, transactionType); + if (!(assetAccountSplit == MyMoneySplit())) { + splitAcc = assetAccountSplit.accountId(); // switch over from stock split to asset split because amount in stock split doesn't take fees into account + for (it_split = splits.begin(); it_split != splits.end(); ++it_split) { + if ((*it_split) == assetAccountSplit) { + myBegin = it_split; // set myBegin to asset split, so stock split can be listed in details under splits + break; + } + } + } + } else + qA["price"] = ((*it_split).price() * xr).toString(); + + a_fullname = splitAcc.fullName(); + a_memo = (*it_split).memo(); + + transaction_text = m_config.match(&(*it_split)); + qA["institution"] = institution.isEmpty() ? i18n("No Institution") : file->institution(institution).name(); @@ -602,7 +626,7 @@ qA["memo"] = a_memo; - qA["value"] = (((*it_split).shares()) * xr).convert(fraction).toString(); + qA["value"] = ((*it_split).value() * xr).convert(fraction).toString(); qS["reconciledate"] = qA["reconciledate"]; qS["reconcileflag"] = qA["reconcileflag"]; @@ -617,7 +641,7 @@ if (loan_special_case) { // put the principal amount in the "value" column and convert to lowest fraction - qA["value"] = ((-(*it_split).shares()) * xr).convert(fraction).toString(); + qA["value"] = (-(*it_split).value() * xr).convert(fraction).toString(); qA["rank"] = '0'; qA["split"] = ""; @@ -628,28 +652,22 @@ // add the "summarized" split transaction // this is the sub-total of the split detail // convert to lowest fraction - qA["value"] = ((*it_split).shares() * xr).convert(fraction).toString(); qA["rank"] = '0'; qA["category"] = i18n("[Split Transaction]"); qA["topcategory"] = i18nc("Split transaction", "Split"); qA["categorytype"] = i18nc("Split transaction", "Split"); m_rows += qA; } } - - // track accts that will need opening and closing balances - //FIXME in some cases it will show the opening and closing - //balances but no transactions if the splits are all filtered out -- asoliverez - accts.insert(splitAcc.id(), splitAcc); } } else { if (include_me) { if (loan_special_case) { - MyMoneyMoney value = ((-(* it_split).shares()) * xr).convert(fraction); + MyMoneyMoney value = (-(* it_split).value() * xr).convert(fraction); if ((*it_split).action() == MyMoneySplit::ActionAmortization) { // put the payment in the "payment" column and convert to lowest fraction @@ -687,7 +705,7 @@ qA["value"] = ""; //convert to lowest fraction - qA["split"] = ((-(*it_split).shares()) * xr).convert(fraction).toString(); + qA["split"] = (-(*it_split).value() * xr).convert(fraction).toString(); qA["rank"] = '1'; } else { //this applies when the transaction has only 2 splits, or each split is going to be @@ -702,9 +720,9 @@ // if the currency of the split is different from the currency of the main split, then convert to the currency of the main split MyMoneyMoney ieXr(xr); if (!m_config.isConvertCurrency() && splitAcc.currency().id() != myBeginCurrency) { - ieXr = (xr * splitAcc.foreignCurrencyPrice(myBeginCurrency, (*it_transaction).postDate())).reduce(); + ieXr = xr * splitAcc.foreignCurrencyPrice(myBeginCurrency, (*it_transaction).postDate()); } - qA["value"] = ((-(*it_split).shares()) * ieXr).convert(fraction).toString(); + qA["value"] = (-(*it_split).value() * ieXr).convert(fraction).toString(); } qA["rank"] = '0'; } @@ -760,10 +778,11 @@ } } - if (m_config.includes(splitAcc) && use_transfers) { + if (m_config.includes(splitAcc) && use_transfers && + !(splitAcc.isInvest() && include_me)) { // otherwise stock split is displayed twice in report if (! splitAcc.isIncomeExpense()) { //multiply by currency and convert to lowest fraction - qS["value"] = ((*it_split).shares() * xr).convert(fraction).toString(); + qS["value"] = ((*it_split).value() * xr).convert(fraction).toString(); qS["rank"] = '0';