int MyMoneyForecast::daysToZeroBalance(const MyMoneyAccount& acc) { dailyBalances balance; //Check if acc is not a forecast account, return -1 if(!isForecastAccount(acc)) { return -2; } balance = m_accountList[acc.id()]; if (acc.accountGroup() == MyMoneyAccount::Asset) { for (QDate it_day = QDate::currentDate() ; it_day <= forecastEndDate(); ) { if ( balance[it_day] < MyMoneyMoney ( 0, 1 ) ) { return QDate::currentDate().daysTo(it_day); } it_day = it_day.addDays(1); } } else if (acc.accountGroup() == MyMoneyAccount::Liability) { for (QDate it_day = QDate::currentDate() ; it_day <= forecastEndDate(); ) { if ( balance[it_day] > MyMoneyMoney ( 0, 1 ) ) { return QDate::currentDate().daysTo(it_day); } it_day = it_day.addDays(1); } } return -1; }
MyMoneySplit::MyMoneySplit(const QDomElement& node) : MyMoneyObject(node, false), MyMoneyKeyValueContainer(node.elementsByTagName("KEYVALUEPAIRS").item(0).toElement()) { if ("SPLIT" != node.tagName()) throw MYMONEYEXCEPTION("Node was not SPLIT"); clearId(); m_payee = QStringEmpty(node.attribute("payee")); QDomNodeList nodeList = node.elementsByTagName("TAG"); for (int i = 0; i < nodeList.count(); i++) m_tagList << QStringEmpty(nodeList.item(i).toElement().attribute("id")); m_reconcileDate = stringToDate(QStringEmpty(node.attribute("reconciledate"))); m_action = QStringEmpty(node.attribute("action")); m_reconcileFlag = static_cast<MyMoneySplit::reconcileFlagE>(node.attribute("reconcileflag").toInt()); m_memo = QStringEmpty(node.attribute("memo")); m_value = MyMoneyMoney(QStringEmpty(node.attribute("value"))); m_shares = MyMoneyMoney(QStringEmpty(node.attribute("shares"))); m_price = MyMoneyMoney(QStringEmpty(node.attribute("price"))); m_account = QStringEmpty(node.attribute("account")); m_number = QStringEmpty(node.attribute("number")); m_bankID = QStringEmpty(node.attribute("bankid")); }
Weboob::Account Weboob::getAccount(QString backend, QString accid, QString max) { Weboob::Account acc; QVariantList args; args << backend; args << accid; args << max; QMap<QString, QVariant> result = this->execute("get_transactions", args).toMap(); acc.id = result["id"].toString(); acc.name = result["name"].toString(); acc.balance = MyMoneyMoney(result["balance"].toInt(), 100); acc.type = (Weboob::Account::type_t)result["type"].toInt(); QList<QVariant> list = result["transactions"].toList(); for (QListIterator<QVariant> it(list); it.hasNext();) { QMap<QString, QVariant> params = it.next().toMap(); Weboob::Transaction tr; tr.id = params["id"].toString(); tr.date = QDate::fromString(params["date"].toString(), "yyyy-MM-dd"); tr.rdate = QDate::fromString(params["rdate"].toString(), "yyyy-MM-dd"); tr.type = (Weboob::Transaction::type_t)params["type"].toInt(); tr.raw = params["raw"].toString(); tr.category = params["category"].toString(); tr.label = params["label"].toString(); tr.amount = MyMoneyMoney(params["amount"].toInt(), 100); acc.transactions.append(tr); } return acc; }
void MyMoneySplitTest::testSetFunctions() { m->setAccountId("Account"); m->setMemo("Memo"); m->setReconcileDate(QDate(1, 2, 3)); m->setReconcileFlag(MyMoneySplit::Cleared); m->setShares(MyMoneyMoney(1234, 100)); m->setValue(MyMoneyMoney(3456, 100)); m->setId("MyID"); m->setPayeeId("Payee"); QList<QString> tagIdList; tagIdList << "Tag"; m->setTagIdList(tagIdList); m->setAction("Action"); m->setTransactionId("TestTransaction"); m->setValue("Key", "Value"); QVERIFY(m->accountId() == "Account"); QVERIFY(m->memo() == "Memo"); QVERIFY(m->reconcileDate() == QDate(1, 2, 3)); QVERIFY(m->reconcileFlag() == MyMoneySplit::Cleared); QVERIFY(m->shares() == MyMoneyMoney(1234, 100)); QVERIFY(m->value() == MyMoneyMoney(3456, 100)); QVERIFY(m->id() == "MyID"); QVERIFY(m->payeeId() == "Payee"); QVERIFY(m->tagIdList() == tagIdList); QVERIFY(m->action() == "Action"); QVERIFY(m->transactionId() == "TestTransaction"); QVERIFY(m->value("Key") == "Value"); }
void MyMoneySplitTest::testValue() { m->setValue(MyMoneyMoney(1, 100)); m->setShares(MyMoneyMoney(2, 100)); QVERIFY(m->value("EUR", "EUR") == MyMoneyMoney(1, 100)); QVERIFY(m->value("EUR", "USD") == MyMoneyMoney(2, 100)); }
bool kMyMoneyEdit::eventFilter(QObject * /* o */ , QEvent *e) { bool rc = false; // we want to catch some keys that are usually handled by // the base class (e.g. '+', '-', etc.) if (e->type() == QEvent::KeyPress) { QKeyEvent *k = static_cast<QKeyEvent *>(e); rc = true; switch (k->key()) { case Qt::Key_Plus: case Qt::Key_Minus: if (m_edit->hasSelectedText()) { m_edit->cut(); } if (m_edit->text().length() == 0) { rc = false; break; } // in case of '-' we do not enter the calculator when // the current position is the beginning and there is // no '-' sign at the first position. if (k->key() == Qt::Key_Minus) { if (m_edit->cursorPosition() == 0 && m_edit->text()[0] != '-') { rc = false; break; } } // otherwise, tricky fall through here! case Qt::Key_Slash: case Qt::Key_Asterisk: case Qt::Key_Percent: if (m_edit->hasSelectedText()) { // remove the selected text m_edit->cut(); } calculatorOpen(k); break; default: rc = false; break; } } else if (e->type() == QEvent::FocusOut) { if (!m_edit->text().isEmpty() || !allowEmpty) ensureFractionalPart(); if (MyMoneyMoney(m_edit->text()) != MyMoneyMoney(m_text) && !m_calculator->isVisible()) { emit valueChanged(m_edit->text()); } m_text = m_edit->text(); } return rc; }
MyMoneyMoney MyMoneyForecast::calculateAccountTrend(const MyMoneyAccount& acc, int trendDays) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyTransactionFilter filter; MyMoneyMoney netIncome; QDate startDate; QDate openingDate = acc.openingDate(); //validate arguments if(trendDays < 1) { throw new MYMONEYEXCEPTION("Illegal arguments when calling calculateAccountTrend. trendDays must be higher than 0"); } //If it is a new account, we don't take into account the first day //because it is usually a weird one and it would mess up the trend if(openingDate.daysTo(QDate::currentDate())<trendDays){ startDate = (acc.openingDate()).addDays(1); } else { startDate = QDate::currentDate().addDays(-trendDays); } //get all transactions for the period filter.setDateFilter(startDate, QDate::currentDate()); if(acc.accountGroup() == MyMoneyAccount::Income || acc.accountGroup() == MyMoneyAccount::Expense) { filter.addCategory(acc.id()); } else { filter.addAccount(acc.id()); } filter.setReportAllSplits(false); QValueList<MyMoneyTransaction> transactions = file->transactionList(filter); QValueList<MyMoneyTransaction>::const_iterator it_t = transactions.begin(); //add all transactions for that account for(; it_t != transactions.end(); ++it_t ) { const QValueList<MyMoneySplit>& splits = (*it_t).splits(); QValueList<MyMoneySplit>::const_iterator it_s = splits.begin(); for(; it_s != splits.end(); ++it_s ) { if(!(*it_s).shares().isZero()) { if(acc.id()==(*it_s).accountId()) netIncome += (*it_s).value(); } } } //calculate trend of the account in the past period MyMoneyMoney accTrend; //don't take into account the first day of the account if(openingDate.daysTo(QDate::currentDate())<trendDays) { accTrend = netIncome/MyMoneyMoney(openingDate.daysTo(QDate::currentDate())-1,1); } else { accTrend = netIncome/MyMoneyMoney(trendDays,1); } return accTrend; }
void MyMoneySplitTest::testWriteXML() { MyMoneySplit s; s.setPayeeId("P000001"); QList<QString> tagIdList; tagIdList << "G000001"; s.setTagIdList(tagIdList); s.setShares(MyMoneyMoney(96379, 100)); s.setValue(MyMoneyMoney(96379, 1000)); s.setAccountId("A000076"); s.setNumber("124"); s.setBankID("SPID"); s.setAction(MyMoneySplit::ActionDeposit); s.setReconcileFlag(MyMoneySplit::Reconciled); QDomDocument doc("TEST"); QDomElement el = doc.createElement("SPLIT-CONTAINER"); doc.appendChild(el); s.writeXML(doc, el); QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); QDomElement splitContainer = doc.documentElement(); QCOMPARE(splitContainer.tagName(), QLatin1String("SPLIT-CONTAINER")); QCOMPARE(splitContainer.childNodes().size(), 1); QVERIFY(splitContainer.childNodes().at(0).isElement()); QDomElement split = splitContainer.childNodes().at(0).toElement(); QCOMPARE(split.tagName(), QLatin1String("SPLIT")); QCOMPARE(split.attribute("payee"), QLatin1String("P000001")); QCOMPARE(split.attribute("reconcileflag"), QLatin1String("2")); QCOMPARE(split.attribute("shares"), QLatin1String("96379/100")); QCOMPARE(split.attribute("reconciledate"), QString()); QCOMPARE(split.attribute("action"), QLatin1String("Deposit")); QCOMPARE(split.attribute("bankid"), QLatin1String("SPID")); QCOMPARE(split.attribute("account"), QLatin1String("A000076")); QCOMPARE(split.attribute("number"), QLatin1String("124")); QCOMPARE(split.attribute("value"), QLatin1String("96379/1000")); QCOMPARE(split.attribute("memo"), QString()); QCOMPARE(split.attribute("id"), QString()); QCOMPARE(split.childNodes().size(), 1); QVERIFY(split.childNodes().at(0).isElement()); QDomElement tag = split.childNodes().at(0).toElement(); QCOMPARE(tag.tagName(), QLatin1String("TAG")); QCOMPARE(tag.attribute("id"), QLatin1String("G000001")); QCOMPARE(tag.childNodes().size(), 0); QString ref = QString( "<!DOCTYPE TEST>\n" "<SPLIT-CONTAINER>\n" " <SPLIT payee=\"P000001\" reconcileflag=\"2\" shares=\"96379/100\" reconciledate=\"\" action=\"Deposit\" bankid=\"SPID\" account=\"A000076\" number=\"124\" value=\"96379/1000\" memo=\"\" id=\"\">\n" " <TAG id=\"G000001\"/>\n" " </SPLIT>\n" "</SPLIT-CONTAINER>\n"); }
void MyMoneySplitTest::testSetValue() { QVERIFY(m->value().isZero()); QVERIFY(m->shares().isZero()); m->setValue(MyMoneyMoney(1, 100), "EUR", "EUR"); QVERIFY(m->value() == MyMoneyMoney(1, 100)); QVERIFY(m->shares().isZero()); m->setValue(MyMoneyMoney(3, 100), "EUR", "USD"); QVERIFY(m->value() == MyMoneyMoney(1, 100)); QVERIFY(m->shares() == MyMoneyMoney(3, 100)); }
void MyMoneyPriceTest::testConstructor() { MyMoneyPrice n(QString("from"), QString("to"), QDate(2005, 9, 23), MyMoneyMoney(1, 3), QString("MySource")); QVERIFY(n.isValid() == true); QVERIFY(n.from() == QString("from")); QVERIFY(n.to() == QString("to")); QVERIFY(n.date() == QDate(2005, 9, 23)); QVERIFY(n.source() == QString("MySource")); QVERIFY(n.rate("to") == MyMoneyMoney(1, 3)); }
void MyMoneyAccountTest::addReconciliation() { MyMoneyAccount a; QVERIFY(a.addReconciliation(QDate(2011, 1, 2), MyMoneyMoney(123, 100)) == true); QVERIFY(a.reconciliationHistory().count() == 1); QVERIFY(a.addReconciliation(QDate(2011, 2, 1), MyMoneyMoney(456, 100)) == true); QVERIFY(a.reconciliationHistory().count() == 2); QVERIFY(a.addReconciliation(QDate(2011, 2, 1), MyMoneyMoney(789, 100)) == true); QVERIFY(a.reconciliationHistory().count() == 2); QVERIFY(a.reconciliationHistory().values().last() == MyMoneyMoney(789, 100)); }
void MyMoneySplitTest::testIsAutoCalc() { QVERIFY(m->isAutoCalc() == false); m->setValue(MyMoneyMoney::autoCalc); QVERIFY(m->isAutoCalc() == true); m->setShares(MyMoneyMoney::autoCalc); QVERIFY(m->isAutoCalc() == true); m->setValue(MyMoneyMoney()); QVERIFY(m->isAutoCalc() == true); m->setShares(MyMoneyMoney(1, 100)); QVERIFY(m->isAutoCalc() == false); }
void MyMoneyBalanceCacheTest::testInsert() { m->insert("A000001", QDate(2010, 9, 16), MyMoneyMoney(10, 100)); // The next 2 lines have the same date and account. // This is intentional to see that the balance for that // account and date gets overwritten. m->insert("A000001", QDate(2010, 9, 18), MyMoneyMoney(15, 100)); m->insert("A000001", QDate(2010, 9, 18), MyMoneyMoney(20, 100)); m->insert("A000002", QDate(2010, 9, 17), MyMoneyMoney(30, 100)); m->insert("A000002", QDate(2010, 9, 19), MyMoneyMoney(40, 100)); }
void MyMoneySplitTest::testReadXML() { MyMoneySplit s; QString ref_ok = QString( "<!DOCTYPE TEST>\n" "<SPLIT-CONTAINER>\n" " <SPLIT payee=\"P000001\" reconciledate=\"\" shares=\"96379/100\" action=\"Deposit\" bankid=\"SPID\" number=\"124\" reconcileflag=\"2\" memo=\"MyMemo\" value=\"96379/1000\" account=\"A000076\">\n" " <TAG id=\"G000001\"/>\n" " </SPLIT>\n" "</SPLIT-CONTAINER>\n"); QString ref_false = QString( "<!DOCTYPE TEST>\n" "<SPLIT-CONTAINER>\n" " <SPLITS payee=\"P000001\" reconciledate=\"\" shares=\"96379/100\" action=\"Deposit\" bankid=\"SPID\" number=\"124\" reconcileflag=\"2\" memo=\"\" value=\"96379/1000\" account=\"A000076\" />\n" " <TAG id=\"G000001\"/>\n" "</SPLIT-CONTAINER>\n"); QDomDocument doc; QDomElement node; doc.setContent(ref_false); node = doc.documentElement().firstChild().toElement(); try { s = MyMoneySplit(node); QFAIL("Missing expected exception"); } catch (const MyMoneyException &) { } doc.setContent(ref_ok); node = doc.documentElement().firstChild().toElement(); try { s = MyMoneySplit(node); QVERIFY(s.id().isEmpty()); QVERIFY(s.payeeId() == "P000001"); QList<QString> tagIdList; tagIdList << "G000001"; QVERIFY(s.tagIdList() == tagIdList); QVERIFY(s.reconcileDate() == QDate()); QVERIFY(s.shares() == MyMoneyMoney(96379, 100)); QVERIFY(s.value() == MyMoneyMoney(96379, 1000)); QVERIFY(s.number() == "124"); QVERIFY(s.bankID() == "SPID"); QVERIFY(s.reconcileFlag() == MyMoneySplit::Reconciled); QVERIFY(s.action() == MyMoneySplit::ActionDeposit); QVERIFY(s.accountId() == "A000076"); QVERIFY(s.memo() == "MyMemo"); } catch (const MyMoneyException &) { } }
void MyMoneyPriceTest::testValidity() { QString emptyId; MyMoneyPrice n1(emptyId, QString("to"), QDate(2005, 9, 23), MyMoneyMoney(1, 3), QString("MySource")); MyMoneyPrice n2(QString("from"), emptyId, QDate(2005, 9, 23), MyMoneyMoney(1, 3), QString("MySource")); MyMoneyPrice n3(QString("from"), QString("to"), QDate(), MyMoneyMoney(1, 3), QString("MySource")); MyMoneyPrice n4(QString("from"), QString("to"), QDate(2005, 9, 23), MyMoneyMoney(1, 3), QString("MySource")); QVERIFY(n1.isValid() == false); QVERIFY(n2.isValid() == false); QVERIFY(n3.isValid() == false); QVERIFY(n4.isValid() == true); }
MyMoneyMoney MyMoneyForecast::accountWeightedMovingAverage(const MyMoneyAccount &acc, const int trendDay, const int totalWeight) { MyMoneyMoney balanceVariation; for(int it_terms = 0, weight = 1; (trendDay+(accountsCycle()*it_terms)) <= historyDays(); ++it_terms, ++weight) //sum for each term multiplied by weight { MyMoneyMoney balanceBefore = m_accountListPast[acc.id()][historyStartDate().addDays(trendDay+(accountsCycle()*it_terms)-2)]; //get balance for the day before MyMoneyMoney balanceAfter = m_accountListPast[acc.id()][historyStartDate().addDays(trendDay+(accountsCycle()*it_terms)-1)]; balanceVariation += ( (balanceAfter - balanceBefore) * MyMoneyMoney(weight, 1) ); //add the balance variation between days multiplied by its weight } //calculate average of the variations return (balanceVariation / MyMoneyMoney(totalWeight, 1)).convert(10000); }
onlineTask* sepaOnlineTransferImpl::createFromSqlDatabase(QSqlDatabase connection, const QString& onlineJobId) const { Q_ASSERT(!onlineJobId.isEmpty()); Q_ASSERT(connection.isOpen()); QSqlQuery query = QSqlQuery( "SELECT originAccount, value, purpose, endToEndReference, beneficiaryName, beneficiaryIban, " " beneficiaryBic, textKey, subTextKey FROM kmmSepaOrders WHERE id = ?", connection ); query.bindValue(0, onlineJobId); if (query.exec() && query.next()) { sepaOnlineTransferImpl* task = new sepaOnlineTransferImpl(); task->setOriginAccount(query.value(0).toString()); task->setValue(MyMoneyMoney(query.value(1).toString())); task->setPurpose(query.value(2).toString()); task->setEndToEndReference(query.value(3).toString()); task->_textKey = query.value(7).toUInt(); task->_subTextKey = query.value(8).toUInt(); payeeIdentifiers::ibanBic beneficiary; beneficiary.setOwnerName(query.value(4).toString()); beneficiary.setIban(query.value(5).toString()); beneficiary.setBic(query.value(6).toString()); task->_beneficiaryAccount = beneficiary; return task; } return 0; }
sepaOnlineTransfer* sepaOnlineTransferImpl::createFromXml(const QDomElement& element) const { sepaOnlineTransferImpl* task = new sepaOnlineTransferImpl(); task->setOriginAccount(element.attribute("originAccount", QString())); task->setValue(MyMoneyMoney(QStringEmpty(element.attribute("value", QString())))); task->_textKey = element.attribute("textKey", QString().setNum(defaultTextKey)).toUShort(); task->_subTextKey = element.attribute("subTextKey", QString().setNum(defaultSubTextKey)).toUShort(); task->setPurpose(element.attribute("purpose", QString())); task->setEndToEndReference(element.attribute("endToEndReference", QString())); payeeIdentifiers::ibanBic beneficiary; payeeIdentifiers::ibanBic* beneficiaryPtr = 0; QDomElement beneficiaryEl = element.firstChildElement("beneficiary"); if (!beneficiaryEl.isNull()) { beneficiaryPtr = beneficiary.createFromXml(beneficiaryEl); } if (beneficiaryPtr == 0) { task->_beneficiaryAccount = beneficiary; } else { task->_beneficiaryAccount = *beneficiaryPtr; } delete beneficiaryPtr; return task; }
MyMoneyMoney ReportAccount::deepCurrencyPrice(const QDate& date, bool exactDate) const { DEBUG_ENTER(Q_FUNC_INFO); MyMoneyMoney result(1, 1); MyMoneyFile* file = MyMoneyFile::instance(); MyMoneySecurity undersecurity = file->security(currencyId()); if (! undersecurity.isCurrency()) { const MyMoneyPrice &price = file->price(undersecurity.id(), undersecurity.tradingCurrency(), date, exactDate); if (price.isValid()) { result = price.rate(undersecurity.tradingCurrency()); DEBUG_OUTPUT(QString("Converting under %1 to deep %2, price on %3 is %4") .arg(undersecurity.name()) .arg(file->security(undersecurity.tradingCurrency()).name()) .arg(date.toString()) .arg(result.toDouble())); } else { DEBUG_OUTPUT(QString("No price to convert under %1 to deep %2 on %3") .arg(undersecurity.name()) .arg(file->security(undersecurity.tradingCurrency()).name()) .arg(date.toString())); result = MyMoneyMoney(); } } return result; }
void MyMoneyBalanceCacheTest::testCacheItem() { MyMoneyBalanceCacheItem item(MyMoneyMoney(10, 100), QDate(2010, 9, 18)); MyMoneyBalanceCacheItem invalid(MyMoneyMoney::minValue, QDate()); //MyMoneyBalanceCacheItem noarg; QVERIFY(item.balance() == MyMoneyMoney(10, 100)); QVERIFY(item.date() == QDate(2010, 9, 18)); QVERIFY(item.isValid()); QVERIFY(! invalid.isValid()); //QVERIFY(! noarg.isValid()); }
MyMoneyMoney PivotCell::calculateRunningSum(const MyMoneyMoney& runningSum) { MyMoneyMoney::operator += (runningSum); MyMoneyMoney::operator = ((*this * m_stockSplit) + m_postSplit); m_postSplit = MyMoneyMoney(); m_stockSplit = MyMoneyMoney::ONE; return *this; }
MyMoneyMoney MyMoneyForecast::accountAverageBalance(const MyMoneyAccount& acc) { MyMoneyMoney totalBalance; for(int f_day = 1; f_day <= forecastDays() ; ++f_day) { totalBalance += forecastBalance(acc, f_day); } return totalBalance / MyMoneyMoney( forecastDays(), 1); }
void TransactionMatcher::checkTransaction(const MyMoneyTransaction& tm, const MyMoneyTransaction& ti, const MyMoneySplit& si, QPair<MyMoneyTransaction, MyMoneySplit>& lastMatch, TransactionMatcher::autoMatchResultE& result, int variation) const { Q_UNUSED(ti); const QValueList<MyMoneySplit>& splits = tm.splits(); QValueList<MyMoneySplit>::const_iterator it_s; for(it_s = splits.begin(); it_s != splits.end(); ++it_s) { MyMoneyMoney upper((*it_s).shares()); MyMoneyMoney lower(upper); if((variation > 0) && (variation < 100)) { lower = lower - (lower.abs() * MyMoneyMoney(variation, 100)); upper = upper + (upper.abs() * MyMoneyMoney(variation, 100)); } // we only check for duplicates / matches if the sign // of the amount for this split is identical if((si.shares() >= lower) && (si.shares() <= upper)) { // check for duplicate (we can only do that, if we have a bankID) if(!si.bankID().isEmpty()) { if((*it_s).bankID() == si.bankID()) { lastMatch = QPair<MyMoneyTransaction, MyMoneySplit>(tm, *it_s); result = matchedDuplicate; break; } // in case the stored split already has a bankid // assigned, it must be a different one and therefore // will certainly not match if(!(*it_s).bankID().isEmpty()) continue; } // check if this is the one that matches if((*it_s).accountId() == si.accountId() && (si.shares() >= lower) && (si.shares() <= upper) && !(*it_s).isMatched()) { if(tm.postDate() == ti.postDate()) { lastMatch = QPair<MyMoneyTransaction, MyMoneySplit>(tm, *it_s); result = matchedExact; } else if(result != matchedExact) { lastMatch = QPair<MyMoneyTransaction, MyMoneySplit>(tm, *it_s); result = matched; } } } } }
MyMoneyMoney searchHTML(const QString& _html, const QString& _search) { QRegExp re(QString("%1[<>/td]*([\\-.0-9,]*)").arg(_search)); re.search(_html); QString found = re.cap(1); found.remove(','); return MyMoneyMoney(found.toDouble()); }
void MyMoneyForecast::addFutureTransactions(void) { MyMoneyTransactionFilter filter; MyMoneyFile* file = MyMoneyFile::instance(); // collect and process all transactions that have already been entered but // are located in the future. filter.setDateFilter(forecastStartDate(), forecastEndDate()); filter.setReportAllSplits(false); QValueList<MyMoneyTransaction> transactions = file->transactionList(filter); QValueList<MyMoneyTransaction>::const_iterator it_t = transactions.begin(); for(; it_t != transactions.end(); ++it_t ) { const QValueList<MyMoneySplit>& splits = (*it_t).splits(); QValueList<MyMoneySplit>::const_iterator it_s = splits.begin(); for(; it_s != splits.end(); ++it_s ) { if(!(*it_s).shares().isZero()) { MyMoneyAccount acc = file->account((*it_s).accountId()); if(isForecastAccount(acc)) { dailyBalances balance; balance = m_accountList[acc.id()]; //if it is income, the balance is stored as negative number if(acc.accountType() == MyMoneyAccount::Income) { balance[(*it_t).postDate()] += ((*it_s).shares() * MyMoneyMoney(-1, 1)); } else { balance[(*it_t).postDate()] += (*it_s).shares(); } m_accountList[acc.id()] = balance; } } } } #if 0 QFile trcFile("forecast.csv"); trcFile.open(IO_WriteOnly); QTextStream s(&trcFile); { s << "Already present transactions\n"; QMap<QString, dailyBalances>::Iterator it_a; QMap<QString, QString>::ConstIterator it_n; for(it_n = m_nameIdx.begin(); it_n != m_nameIdx.end(); ++it_n) { MyMoneyAccount acc = file->account(*it_n); it_a = m_accountList.find(*it_n); s << "\"" << acc.name() << "\","; for(int i = 0; i < 90; ++i) { s << "\"" << (*it_a)[i].formatMoney("") << "\","; } s << "\n"; } } #endif }
void KNewLoanWizard::resetCalculator() { m_loanAmountPage->resetCalculator(); m_interestPage->resetCalculator(); m_durationPage->resetCalculator(); m_paymentPage->resetCalculator(); m_finalPaymentPage->resetCalculator(); setField("additionalCost", MyMoneyMoney().formatMoney(m_account.fraction(MyMoneyFile::instance()->security(m_account.currencyId())))); }
/** * Set the values based on the @param security */ void KInvestmentDetailsWizardPage::init2(const MyMoneySecurity& security) { MyMoneySecurity tradingCurrency = MyMoneyFile::instance()->currency(security.tradingCurrency()); m_investmentSymbol->setText(security.tradingSymbol()); m_tradingMarket->setCurrentIndex(m_tradingMarket->findText(security.tradingMarket(), Qt::MatchExactly)); m_fraction->setValue(MyMoneyMoney(security.smallestAccountFraction(), 1)); m_tradingCurrencyEdit->setSecurity(tradingCurrency); m_investmentIdentification->setText(security.value("kmm-security-id")); }
void KNewAccountDlg::loadKVP(const QString& key, kMyMoneyEdit* widget) { if(!widget) return; if(m_account.value(key).isEmpty()) { widget->clearText(); } else { widget->setValue(MyMoneyMoney(m_account.value(key))); } }
void MyMoneyBudgetTest::addMonthlyToMonthly() { MyMoneyBudget::AccountGroup a0, a1; a0.setBudgetLevel(MyMoneyBudget::AccountGroup::eMonthly); a1.setBudgetLevel(MyMoneyBudget::AccountGroup::eMonthly); MyMoneyBudget::PeriodGroup period; period.setStartDate(QDate(2010, 1, 1)); period.setAmount(MyMoneyMoney(100, 1)); a0.addPeriod(QDate(2010, 1, 1), period); a1.addPeriod(QDate(2010, 1, 1), period); a0 += a1; QVERIFY(a0.budgetLevel() == MyMoneyBudget::AccountGroup::eMonthly); QVERIFY(a1.budgetLevel() == MyMoneyBudget::AccountGroup::eMonthly); QVERIFY(a0.getPeriods().count() == 1); QVERIFY(a1.getPeriods().count() == 1); QVERIFY(a0.balance() == MyMoneyMoney(200, 1)); QVERIFY(a1.balance() == MyMoneyMoney(100, 1)); }
void MyMoneyAccountTest::reconciliationHistory() { MyMoneyAccount a; QVERIFY(a.reconciliationHistory().isEmpty() == true); QVERIFY(a.addReconciliation(QDate(2011, 1, 2), MyMoneyMoney(123, 100)) == true); QVERIFY(a.reconciliationHistory()[QDate(2011, 1, 2)] == MyMoneyMoney(123, 100)); QVERIFY(a.reconciliationHistory()[QDate(2011, 1, 1)] == MyMoneyMoney()); QVERIFY(a.reconciliationHistory()[QDate(2011, 1, 3)] == MyMoneyMoney()); QVERIFY(a.addReconciliation(QDate(2011, 2, 1), MyMoneyMoney(456, 100)) == true); QVERIFY(a.reconciliationHistory()[QDate(2011, 1, 2)] == MyMoneyMoney(123, 100)); QVERIFY(a.reconciliationHistory()[QDate(2011, 1, 1)] == MyMoneyMoney()); QVERIFY(a.reconciliationHistory()[QDate(2011, 1, 3)] == MyMoneyMoney()); QVERIFY(a.reconciliationHistory()[QDate(2011, 2, 1)] == MyMoneyMoney(456, 100)); QVERIFY(a.reconciliationHistory().count() == 2); }