KissCount/src/model/export/ExportEngine.cpp

82 lines
2.0 KiB
C++
Raw Normal View History

/*
Copyright 2010-2011 Grégory Soutadé
This file is part of KissCount.
KissCount is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KissCount is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ExportEngine.h"
ExportEngine::ExportEngine()
{
}
ExportEngine::~ExportEngine()
{
}
bool ExportEngine::HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)
{
_path = path;
_user = user;
_db = db;
_kiss = kiss;
return path.EndsWith(_shortExt) || path.EndsWith(_shortExt.Upper());
}
bool ExportEngine::SaveFile(std::vector<Operation>* operations)
{
int i;
wxString account, category;
AccountAmount accountAmount;
if (!operations) return NULL;
_accounts.clear();
_categories.clear();
_accountAmounts.clear();
for(i=0; i<(int)operations->size(); i++)
{
account = (*operations)[i].account;
category = (*operations)[i].category;
accountAmount.account = account;
accountAmount.month = (*operations)[i].month;
accountAmount.year = (*operations)[i].year;
if (account.Length())
{
if (!_accounts.count(account))
_accounts[account]++;
if (!_accountAmounts.count(accountAmount))
_accountAmounts[accountAmount] = _kiss->GetAccountAmount(accountAmount.account, accountAmount.month, accountAmount.year);
}
if (category.Length() && !_categories.count(category))
_categories[category]++;
}
return true;
}
wxString ExportEngine::GetFileExt()
{
return wxGetTranslation(_longExt);
}