2011-07-02 16:39:32 +02:00
|
|
|
/*
|
|
|
|
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;
|
2011-07-04 20:23:00 +02:00
|
|
|
int minMonth = -1, minYear = -1;
|
|
|
|
unsigned int maxMonth = -1, maxYear = -1;
|
|
|
|
unsigned int month, year;
|
|
|
|
std::map<wxString, int>::iterator it;
|
2011-07-02 16:39:32 +02:00
|
|
|
|
2011-08-14 17:47:16 +02:00
|
|
|
if (!operations) return 0;
|
2011-07-02 16:39:32 +02:00
|
|
|
|
|
|
|
_accounts.clear();
|
|
|
|
_categories.clear();
|
|
|
|
_accountAmounts.clear();
|
|
|
|
|
|
|
|
for(i=0; i<(int)operations->size(); i++)
|
|
|
|
{
|
|
|
|
account = (*operations)[i].account;
|
|
|
|
category = (*operations)[i].category;
|
|
|
|
|
2011-07-04 20:23:00 +02:00
|
|
|
if (minYear == -1 || (int)(*operations)[i].year < minYear)
|
|
|
|
maxYear = minYear = (*operations)[i].year;
|
2011-07-02 16:39:32 +02:00
|
|
|
|
2011-07-04 20:23:00 +02:00
|
|
|
if (minMonth == -1 || ((int)(*operations)[i].month < minMonth && (int)(*operations)[i].year == minYear))
|
|
|
|
maxMonth = minMonth = (*operations)[i].month;
|
2011-07-02 16:39:32 +02:00
|
|
|
|
2011-07-04 20:23:00 +02:00
|
|
|
if ((*operations)[i].year > maxYear)
|
|
|
|
{
|
|
|
|
maxYear = (*operations)[i].year;
|
|
|
|
maxMonth = (*operations)[i].month;
|
2011-07-02 16:39:32 +02:00
|
|
|
}
|
|
|
|
|
2011-07-04 20:23:00 +02:00
|
|
|
if ((*operations)[i].month > maxMonth && (*operations)[i].year == maxYear)
|
|
|
|
maxMonth = (*operations)[i].month;
|
|
|
|
|
|
|
|
if (account.Length() && !_accounts.count(account))
|
|
|
|
_accounts[account]++;
|
|
|
|
|
2011-07-02 16:39:32 +02:00
|
|
|
if (category.Length() && !_categories.count(category))
|
|
|
|
_categories[category]++;
|
|
|
|
}
|
|
|
|
|
2011-07-04 20:23:00 +02:00
|
|
|
for(it=_accounts.begin(); it!=_accounts.end(); it++)
|
|
|
|
{
|
|
|
|
month = minMonth;
|
|
|
|
for (year = minYear; year <= maxYear; year++)
|
|
|
|
{
|
|
|
|
for (; !(month > maxMonth && year == maxYear) && month < 12; month++)
|
|
|
|
{
|
|
|
|
accountAmount.account = it->first;
|
|
|
|
accountAmount.month = month;
|
|
|
|
accountAmount.year = year;
|
|
|
|
|
|
|
|
_accountAmounts[accountAmount] = _kiss->GetAccountAmount(accountAmount.account, accountAmount.month, accountAmount.year);
|
|
|
|
}
|
|
|
|
month = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 16:39:32 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString ExportEngine::GetFileExt()
|
|
|
|
{
|
|
|
|
return wxGetTranslation(_longExt);
|
|
|
|
}
|
|
|
|
|