const MyMoneyAccount& KNewAccountDlg::parentAccount(void) { if (!m_bSelectedParentAccount) { MyMoneyFile *file = MyMoneyFile::instance(); switch (m_account.accountGroup()) { case MyMoneyAccount::Asset: m_parentAccount = file->asset(); break; case MyMoneyAccount::Liability: m_parentAccount = file->liability(); break; case MyMoneyAccount::Income: m_parentAccount = file->income(); break; case MyMoneyAccount::Expense: m_parentAccount = file->expense(); break; case MyMoneyAccount::Equity: m_parentAccount = file->equity(); break; default: qDebug("Seems we have an account that hasn't been mapped to the top five"); if(m_categoryEditor) m_parentAccount = file->income(); else m_parentAccount = file->asset(); } } return m_parentAccount; }
void KForecastView::addTotalRow(QTreeWidget* forecastList, const MyMoneyForecast& forecast) { MyMoneyFile* file = MyMoneyFile::instance(); m_totalItem = new QTreeWidgetItem(forecastList); QFont font; font.setBold(true); m_totalItem->setFont(0, font); m_totalItem->setText(0, i18nc("Total balance", "Total")); m_totalItem->setIcon(0, file->asset().accountPixmap()); m_totalItem->setData(0, ForecastRole, QVariant::fromValue(forecast)); m_totalItem->setData(0, AccountRole, QVariant::fromValue(file->asset())); m_totalItem->setExpanded(true); }
void KForecastView::addAssetLiabilityRows(const MyMoneyForecast& forecast) { MyMoneyFile* file = MyMoneyFile::instance(); m_assetItem = new QTreeWidgetItem(m_totalItem); m_assetItem->setText(0, file->asset().name()); m_assetItem->setIcon(0, file->asset().accountPixmap()); m_assetItem->setData(0, ForecastRole, QVariant::fromValue(forecast)); m_assetItem->setData(0, AccountRole, QVariant::fromValue(file->asset())); m_assetItem->setExpanded(true); m_liabilityItem = new QTreeWidgetItem(m_totalItem); m_liabilityItem->setText(0, file->liability().name()); m_liabilityItem->setIcon(0, file->liability().accountPixmap()); m_liabilityItem->setData(0, ForecastRole, QVariant::fromValue(forecast)); m_liabilityItem->setData(0, AccountRole, QVariant::fromValue(file->liability())); m_liabilityItem->setExpanded(true); }
void KAccountTemplateSelector::Private::loadHierarchy(void) { m_templateHierarchy.clear(); QListViewItemIterator it(m_parent->m_groupList, QListViewItemIterator::Selected); QListViewItem* it_v; while((it_v = it.current()) != 0) { m_templates[it_v->text(2)].hierarchy(m_templateHierarchy); ++it; } // I need to think about this some more. The code works and shows // the current account hierarchy. It might be usefull, to show // existing accounts dimmed and the new ones in bold or so. #if 0 // add the hierarchy from the MyMoneyFile object QValueList<MyMoneyAccount> aList; QValueList<MyMoneyAccount>::const_iterator it_a; MyMoneyFile* file = MyMoneyFile::instance(); file->accountList(aList); if(aList.count() > 0) { m_templateHierarchy[file->accountToCategory(file->asset().id(), true)] = 0; m_templateHierarchy[file->accountToCategory(file->liability().id(), true)] = 0; m_templateHierarchy[file->accountToCategory(file->income().id(), true)] = 0; m_templateHierarchy[file->accountToCategory(file->expense().id(), true)] = 0; m_templateHierarchy[file->accountToCategory(file->equity().id(), true)] = 0; } for(it_a = aList.begin(); it_a != aList.end(); ++it_a) { m_templateHierarchy[file->accountToCategory((*it_a).id(), true)] = 0; } #endif m_parent->m_accountList->clear(); QMap<QString, QListViewItem*>::iterator it_m; QRegExp exp("(.*):(.*)"); for(it_m = m_templateHierarchy.begin(); it_m != m_templateHierarchy.end(); ++it_m) { if(exp.search(it_m.key()) == -1) { (*it_m) = new KListViewItem(m_parent->m_accountList, it_m.key()); } else { (*it_m) = hierarchyItem(exp.cap(1), exp.cap(2)); } (*it_m)->setOpen(true); } m_parent->m_description->clear(); if(m_parent->m_groupList->currentItem()) { m_parent->m_description->setText(m_templates[m_parent->m_groupList->currentItem()->text(2)].longDescription()); } }
void KForecastView::loadListView() { MyMoneyForecast forecast = KMyMoneyGlobalSettings::forecast(); MyMoneyFile* file = MyMoneyFile::instance(); //get the settings from current page forecast.setForecastDays(m_forecastDays->value()); forecast.setAccountsCycle(m_accountsCycle->value()); forecast.setBeginForecastDay(m_beginDay->value()); forecast.setForecastCycles(m_forecastCycles->value()); forecast.setHistoryMethod(m_historyMethod->checkedId()); forecast.doForecast(); m_forecastList->clear(); m_forecastList->setColumnCount(0); m_forecastList->setIconSize(QSize(22, 22)); m_forecastList->setSortingEnabled(true); m_forecastList->sortByColumn(0, Qt::AscendingOrder); //add columns QStringList headerLabels; headerLabels << i18n("Account"); //add cycle interval columns headerLabels << i18nc("Today's forecast", "Current"); for (int i = 1; i <= forecast.forecastDays(); ++i) { QDate forecastDate = QDate::currentDate().addDays(i); headerLabels << QLocale().toString(forecastDate, QLocale::LongFormat); } //add variation columns headerLabels << i18n("Total variation"); //set the columns m_forecastList->setHeaderLabels(headerLabels); //add default rows addTotalRow(m_forecastList, forecast); addAssetLiabilityRows(forecast); //load asset and liability forecast accounts loadAccounts(forecast, file->asset(), m_assetItem, eDetailed); loadAccounts(forecast, file->liability(), m_liabilityItem, eDetailed); adjustHeadersAndResizeToContents(m_forecastList); // add the fixed column only if the horizontal scroll bar is visible m_fixedColumnView.reset(m_forecastList->horizontalScrollBar()->isVisible() ? new FixedColumnTreeView(m_forecastList) : 0); }
bool MyMoneyTemplate::importTemplate(void(*callback)(int, int, const QString&)) { m_progressCallback = callback; bool rc = !m_accounts.isNull(); MyMoneyFile* file = MyMoneyFile::instance(); signalProgress(0, m_doc.elementsByTagName("account").count(), i18n("Loading template %1", m_source.url())); m_accountsRead = 0; while (rc == true && !m_accounts.isNull() && m_accounts.isElement()) { QDomElement childElement = m_accounts.toElement(); if (childElement.tagName() == "account" && childElement.attribute("name").isEmpty()) { ++m_accountsRead; MyMoneyAccount parent; switch (childElement.attribute("type").toUInt()) { case MyMoneyAccount::Asset: parent = file->asset(); break; case MyMoneyAccount::Liability: parent = file->liability(); break; case MyMoneyAccount::Income: parent = file->income(); break; case MyMoneyAccount::Expense: parent = file->expense(); break; case MyMoneyAccount::Equity: parent = file->equity(); break; default: KMessageBox::error(KMyMoneyUtils::mainWindow(), i18n("<p>Invalid top-level account type <b>%1</b> in template file <b>%2</b></p>", childElement.attribute("type"), m_source.prettyUrl())); rc = false; } if (rc == true) { rc = createAccounts(parent, childElement.firstChild()); } } else { rc = false; } m_accounts = m_accounts.nextSibling(); } signalProgress(-1, -1); return rc; }
void KNewAccountDlg::slotAccountTypeChanged(const QString& typeStr) { MyMoneyAccount::accountTypeE type; MyMoneyAccount::accountTypeE oldType; MyMoneyFile* file = MyMoneyFile::instance(); type = KMyMoneyUtils::stringToAccountType(typeStr); try { oldType = m_account.accountType(); if(oldType != type) { QString parentId; switch(MyMoneyAccount::accountGroup(type)) { case MyMoneyAccount::Asset: parentId = file->asset().id(); break; case MyMoneyAccount::Liability: parentId = file->liability().id(); break; case MyMoneyAccount::Expense: parentId = file->expense().id(); break; case MyMoneyAccount::Income: parentId = file->income().id(); break; default: qWarning("Unknown account group in KNewAccountDlg::slotAccountTypeChanged()"); break; } initParentWidget(parentId, QString()); m_account.setAccountType(type); } } catch(MyMoneyException *e) { delete e; qWarning("Unexpected exception in KNewAccountDlg::slotAccountTypeChanged()"); } }
void KForecastView::loadSummaryView() { MyMoneyForecast forecast = KMyMoneyGlobalSettings::forecast(); QList<MyMoneyAccount> accList; int dropMinimum; int dropZero; MyMoneyFile* file = MyMoneyFile::instance(); //get the settings from current page forecast.setForecastDays(m_forecastDays->value()); forecast.setAccountsCycle(m_accountsCycle->value()); forecast.setBeginForecastDay(m_beginDay->value()); forecast.setForecastCycles(m_forecastCycles->value()); forecast.setHistoryMethod(m_historyMethod->checkedId()); forecast.doForecast(); //add columns QStringList headerLabels; headerLabels << i18n("Account"); headerLabels << i18nc("Today's forecast", "Current"); //if beginning of forecast is today, set the begin day to next cycle to avoid repeating the first cycle int daysToBeginDay; if (QDate::currentDate() < forecast.beginForecastDate()) { daysToBeginDay = QDate::currentDate().daysTo(forecast.beginForecastDate()); } else { daysToBeginDay = forecast.accountsCycle(); } for (int i = 0; ((i*forecast.accountsCycle()) + daysToBeginDay) <= forecast.forecastDays(); ++i) { int intervalDays = ((i * forecast.accountsCycle()) + daysToBeginDay); headerLabels << i18np("1 day", "%1 days", intervalDays); } //add variation columns headerLabels << i18n("Total variation"); m_summaryList->clear(); //set the columns m_summaryList->setHeaderLabels(headerLabels); m_summaryList->setIconSize(QSize(22, 22)); m_summaryList->setSortingEnabled(true); m_summaryList->sortByColumn(0, Qt::AscendingOrder); //add default rows addTotalRow(m_summaryList, forecast); addAssetLiabilityRows(forecast); loadAccounts(forecast, file->asset(), m_assetItem, eSummary); loadAccounts(forecast, file->liability(), m_liabilityItem, eSummary); adjustHeadersAndResizeToContents(m_summaryList); //Add comments to the advice list m_adviceText->clear(); //Get all accounts of the right type to calculate forecast m_nameIdx.clear(); accList = forecast.accountList(); QList<MyMoneyAccount>::const_iterator accList_t = accList.constBegin(); for (; accList_t != accList.constEnd(); ++accList_t) { MyMoneyAccount acc = *accList_t; if (m_nameIdx[acc.id()] != acc.id()) { //Check if the account is there m_nameIdx[acc.id()] = acc.id(); } } QMap<QString, QString>::ConstIterator it_nc; for (it_nc = m_nameIdx.constBegin(); it_nc != m_nameIdx.constEnd(); ++it_nc) { const MyMoneyAccount& acc = file->account(*it_nc); MyMoneySecurity currency; //change currency to deep currency if account is an investment if (acc.isInvest()) { MyMoneySecurity underSecurity = file->security(acc.currencyId()); currency = file->security(underSecurity.tradingCurrency()); } else { currency = file->security(acc.currencyId()); } //Check if the account is going to be below zero or below the minimal balance in the forecast period QString minimumBalance = acc.value("minimumBalance"); MyMoneyMoney minBalance = MyMoneyMoney(minimumBalance); //Check if the account is going to be below minimal balance dropMinimum = forecast.daysToMinimumBalance(acc); //Check if the account is going to be below zero in the future dropZero = forecast.daysToZeroBalance(acc); // spit out possible warnings QString msg; // if a minimum balance has been specified, an appropriate warning will // only be shown, if the drop below 0 is on a different day or not present if (dropMinimum != -1 && !minBalance.isZero() && (dropMinimum < dropZero || dropZero == -1)) { switch (dropMinimum) { case -1: break; case 0: msg = QString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name()); msg += i18n("The balance of %1 is below the minimum balance %2 today.", acc.name(), MyMoneyUtils::formatMoney(minBalance, acc, currency)); msg += QString("</font>"); break; default: msg = QString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name()); msg += i18np("The balance of %2 will drop below the minimum balance %3 in %1 day.", "The balance of %2 will drop below the minimum balance %3 in %1 days.", dropMinimum - 1, acc.name(), MyMoneyUtils::formatMoney(minBalance, acc, currency)); msg += QString("</font>"); } if (!msg.isEmpty()) { m_adviceText->append(msg); } } // a drop below zero is always shown msg.clear(); switch (dropZero) { case -1: break; case 0: if (acc.accountGroup() == MyMoneyAccount::Asset) { msg = QString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name()); msg += i18n("The balance of %1 is below %2 today.", acc.name(), MyMoneyUtils::formatMoney(MyMoneyMoney(), acc, currency)); msg += QString("</font>"); break; } if (acc.accountGroup() == MyMoneyAccount::Liability) { msg = i18n("The balance of %1 is above %2 today.", acc.name(), MyMoneyUtils::formatMoney(MyMoneyMoney(), acc, currency)); break; } break; default: if (acc.accountGroup() == MyMoneyAccount::Asset) { msg = QString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name()); msg += i18np("The balance of %2 will drop below %3 in %1 day.", "The balance of %2 will drop below %3 in %1 days.", dropZero, acc.name(), MyMoneyUtils::formatMoney(MyMoneyMoney(), acc, currency)); msg += QString("</font>"); break; } if (acc.accountGroup() == MyMoneyAccount::Liability) { msg = i18np("The balance of %2 will raise above %3 in %1 day.", "The balance of %2 will raise above %3 in %1 days.", dropZero, acc.name(), MyMoneyUtils::formatMoney(MyMoneyMoney(), acc, currency)); break; } } if (!msg.isEmpty()) { m_adviceText->append(msg); } //advice about trends msg.clear(); MyMoneyMoney accCycleVariation = forecast.accountCycleVariation(acc); if (accCycleVariation < MyMoneyMoney()) { msg = QString("<font color=\"%1\">").arg(KMyMoneyGlobalSettings::listNegativeValueColor().name()); msg += i18n("The account %1 is decreasing %2 per cycle.", acc.name(), MyMoneyUtils::formatMoney(accCycleVariation, acc, currency)); msg += QString("</font>"); } if (!msg.isEmpty()) { m_adviceText->append(msg); } } m_adviceText->show(); }
void KNewAccountDlg::initParentWidget(QString parentId, const QString& accountId) { MyMoneyFile *file = MyMoneyFile::instance(); MyMoneyAccount liabilityAccount = file->liability(); MyMoneyAccount assetAccount = file->asset(); MyMoneyAccount expenseAccount = file->expense(); MyMoneyAccount incomeAccount = file->income(); MyMoneyAccount equityAccount = file->equity(); m_parentItem = 0; m_accountItem = 0; // Determine the parent account try { m_parentAccount = file->account(parentId); } catch (MyMoneyException *e) { m_bSelectedParentAccount = false; m_parentAccount = MyMoneyAccount(); if(m_account.accountType() != MyMoneyAccount::UnknownAccountType) { parentAccount(); parentId = m_parentAccount.id(); } delete e; } m_bSelectedParentAccount = true; // extract the account type from the combo box MyMoneyAccount::accountTypeE type; MyMoneyAccount::accountTypeE groupType; type = KMyMoneyUtils::stringToAccountType(typeCombo->currentText()); groupType = MyMoneyAccount::accountGroup(type); m_qlistviewParentAccounts->clear(); // Now scan all 4 account roots to load the list and mark the parent try { if (!m_categoryEditor) { if(groupType == MyMoneyAccount::Asset || type == MyMoneyAccount::Loan) { // Asset KMyMoneyAccountTreeBaseItem *assetTopLevelAccount = new KMyMoneyAccountTreeItem(m_qlistviewParentAccounts, assetAccount); if(m_parentAccount.id().isEmpty()) { m_parentAccount = assetAccount; parentId = m_parentAccount.id(); } if (parentId == assetAccount.id()) m_parentItem = assetTopLevelAccount; assetTopLevelAccount->setOpen(true); for ( QStringList::ConstIterator it = assetAccount.accountList().begin(); it != assetAccount.accountList().end(); ++it ) { MyMoneyAccount acc = file->account(*it); if(acc.isClosed()) continue; KMyMoneyAccountTreeBaseItem *accountItem = new KMyMoneyAccountTreeItem(assetTopLevelAccount, acc); if(parentId == acc.id()) { m_parentItem = accountItem; } else if(accountId == acc.id()) { if(m_isEditing) accountItem->setSelectable(false); m_accountItem = accountItem; } QStringList subAccounts = acc.accountList(); if (subAccounts.count() >= 1) { showSubAccounts(subAccounts, accountItem, parentId, acc.id()); } } } if(groupType == MyMoneyAccount::Liability) { // Liability KMyMoneyAccountTreeBaseItem *liabilityTopLevelAccount = new KMyMoneyAccountTreeItem(m_qlistviewParentAccounts, liabilityAccount); if(m_parentAccount.id().isEmpty()) { m_parentAccount = liabilityAccount; parentId = m_parentAccount.id(); } if (parentId == liabilityAccount.id()) m_parentItem = liabilityTopLevelAccount; liabilityTopLevelAccount->setOpen(true); for ( QStringList::ConstIterator it = liabilityAccount.accountList().begin(); it != liabilityAccount.accountList().end(); ++it ) { MyMoneyAccount acc = file->account(*it); if(acc.isClosed()) continue; KMyMoneyAccountTreeBaseItem *accountItem = new KMyMoneyAccountTreeItem(liabilityTopLevelAccount, acc); if(parentId == acc.id()) { m_parentItem = accountItem; } else if(accountId == acc.id()) { if(m_isEditing) accountItem->setSelectable(false); m_accountItem = accountItem; } QStringList subAccounts = acc.accountList(); if (subAccounts.count() >= 1) { showSubAccounts(subAccounts, accountItem, parentId, acc.id()); } } } } else { if(groupType == MyMoneyAccount::Income) { // Income KMyMoneyAccountTreeBaseItem *incomeTopLevelAccount = new KMyMoneyAccountTreeItem(m_qlistviewParentAccounts, incomeAccount); if(m_parentAccount.id().isEmpty()) { m_parentAccount = incomeAccount; parentId = m_parentAccount.id(); } if (parentId == incomeAccount.id()) m_parentItem = incomeTopLevelAccount; incomeTopLevelAccount->setOpen(true); for ( QStringList::ConstIterator it = incomeAccount.accountList().begin(); it != incomeAccount.accountList().end(); ++it ) { KMyMoneyAccountTreeBaseItem *accountItem = new KMyMoneyAccountTreeItem(incomeTopLevelAccount, file->account(*it)); QString id = file->account(*it).id(); if(parentId == id) { m_parentItem = accountItem; } else if(accountId == id) { if(m_isEditing) accountItem->setSelectable(false); m_accountItem = accountItem; } QStringList subAccounts = file->account(*it).accountList(); if (subAccounts.count() >= 1) { showSubAccounts(subAccounts, accountItem, parentId, accountId); } } } if(groupType == MyMoneyAccount::Expense) { // Expense KMyMoneyAccountTreeBaseItem *expenseTopLevelAccount = new KMyMoneyAccountTreeItem(m_qlistviewParentAccounts, expenseAccount); if(m_parentAccount.id().isEmpty()) { m_parentAccount = expenseAccount; parentId = m_parentAccount.id(); } if (parentId == expenseAccount.id()) m_parentItem = expenseTopLevelAccount; expenseTopLevelAccount->setOpen(true); for ( QStringList::ConstIterator it = expenseAccount.accountList().begin(); it != expenseAccount.accountList().end(); ++it ) { KMyMoneyAccountTreeBaseItem *accountItem = new KMyMoneyAccountTreeItem(expenseTopLevelAccount, file->account(*it)); QString id = file->account(*it).id(); if(parentId == id) { m_parentItem = accountItem; } else if(accountId == id) { if(m_isEditing) accountItem->setSelectable(false); m_accountItem = accountItem; } QStringList subAccounts = file->account(*it).accountList(); if (subAccounts.count() >= 1) { showSubAccounts(subAccounts, accountItem, parentId, accountId); } } } } } catch (MyMoneyException *e) { qDebug("Exception in assets account refresh: %s", e->what().latin1()); delete e; } m_qlistviewParentAccounts->setColumnWidth(0, m_qlistviewParentAccounts->width()); if (m_parentItem) { m_subAccountLabel->setText(i18n("Is a sub account of %1").arg(m_parentAccount.name())); m_parentItem->setOpen(true); m_qlistviewParentAccounts->setSelected(m_parentItem, true); } m_qlistviewParentAccounts->setEnabled(true); }