Ejemplo n.º 1
0
void KForecastView::loadBudgetView()
{
  MyMoneyFile* file = MyMoneyFile::instance();
  MyMoneyForecast forecast = KMyMoneyGlobalSettings::forecast();

  //get the settings from current page and calculate this year based on last year
  QDate historyEndDate = QDate(QDate::currentDate().year() - 1, 12, 31);
  QDate historyStartDate = historyEndDate.addDays(-m_accountsCycle->value() * m_forecastCycles->value());
  QDate forecastStartDate = QDate(QDate::currentDate().year(), 1, 1);
  QDate forecastEndDate = QDate::currentDate().addDays(m_forecastDays->value());
  forecast.setHistoryMethod(m_historyMethod->checkedId());

  MyMoneyBudget budget;
  forecast.createBudget(budget, historyStartDate, historyEndDate, forecastStartDate, forecastEndDate, false);

  m_budgetList->clear();
  m_budgetList->setIconSize(QSize(22, 22));
  m_budgetList->setSortingEnabled(true);
  m_budgetList->sortByColumn(0, Qt::AscendingOrder);

  //add columns
  QStringList headerLabels;
  headerLabels << i18n("Account");

  {
    QDate forecastStartDate = forecast.forecastStartDate();
    QDate forecastEndDate = forecast.forecastEndDate();

    //add cycle interval columns
    QDate f_date = forecastStartDate;
    for (; f_date <= forecastEndDate; f_date = f_date.addMonths(1)) {
      headerLabels << QDate::longMonthName(f_date.month());
    }
  }
  //add total column
  headerLabels << i18nc("Total balance", "Total");

  //set the columns
  m_budgetList->setHeaderLabels(headerLabels);

  //add default rows
  addTotalRow(m_budgetList, forecast);
  addIncomeExpenseRows(forecast);

  //load income and expense budget accounts
  loadAccounts(forecast, file->income(), m_incomeItem, eBudget);
  loadAccounts(forecast, file->expense(), m_expenseItem, eBudget);

  adjustHeadersAndResizeToContents(m_budgetList);
}
void KMyMoneyAccountTreeForecast::showBudget(MyMoneyForecast& forecast)
{
  QDate forecastStartDate = forecast.forecastStartDate();
  QDate forecastEndDate = forecast.forecastEndDate();

  //add cycle interval columns
  QDate f_date = forecastStartDate;
  for(; f_date <= forecastEndDate; f_date = f_date.addMonths(1)) {
    QString columnName =  QDate::longMonthName(f_date.month());
    addColumn(columnName, -1);
  }
  //add total column
  addColumn(i18n("Total"), -1);


  //align columns
  for(int i = 1; i < columns(); ++i) {
    setColumnAlignment(i, Qt::AlignRight);
  }
}
Ejemplo n.º 3
0
void KForecastView::updateBudget(QTreeWidgetItem *item)
{
  MyMoneySecurity currency;
  MyMoneyMoney tAmountMM;

  MyMoneyForecast forecast = item->data(0, ForecastRole).value<MyMoneyForecast>();

  MyMoneyFile* file = MyMoneyFile::instance();
  int it_c = 1; // iterator for the columns of the listview
  QDate forecastDate = forecast.forecastStartDate();

  MyMoneyAccount account = item->data(0, AccountRole).value<MyMoneyAccount>();

  if (account.isInvest()) {
    MyMoneySecurity underSecurity = file->security(account.currencyId());
    currency = file->security(underSecurity.tradingCurrency());
  } else {
    currency = file->security(account.currencyId());
  }

  //iterate columns
  for (; forecastDate <= forecast.forecastEndDate(); forecastDate = forecastDate.addMonths(1), ++it_c) {
    MyMoneyMoney amountMM;
    amountMM = forecast.forecastBalance(account, forecastDate);
    if (account.accountType() == MyMoneyAccount::Expense)
      amountMM = -amountMM;

    tAmountMM += amountMM;
    setAmount(item, it_c, amountMM);
    setValue(item, it_c, amountMM, forecastDate);
    showAmount(item, it_c, amountMM, currency);
  }

  //set total column
  setAmount(item, it_c, tAmountMM);
  setValue(item, it_c, tAmountMM, forecast.forecastEndDate());
  showAmount(item, it_c, tAmountMM, currency);
}