Add XMLImportEngine
Fix some bugs in ImportPanel and ImportEngines
This commit is contained in:
@@ -42,6 +42,10 @@ bool ExportEngine::SaveFile(std::vector<Operation>* operations)
|
||||
int i;
|
||||
wxString account, category;
|
||||
AccountAmount accountAmount;
|
||||
int minMonth = -1, minYear = -1;
|
||||
unsigned int maxMonth = -1, maxYear = -1;
|
||||
unsigned int month, year;
|
||||
std::map<wxString, int>::iterator it;
|
||||
|
||||
if (!operations) return NULL;
|
||||
|
||||
@@ -54,23 +58,45 @@ bool ExportEngine::SaveFile(std::vector<Operation>* operations)
|
||||
account = (*operations)[i].account;
|
||||
category = (*operations)[i].category;
|
||||
|
||||
accountAmount.account = account;
|
||||
accountAmount.month = (*operations)[i].month;
|
||||
accountAmount.year = (*operations)[i].year;
|
||||
if (minYear == -1 || (int)(*operations)[i].year < minYear)
|
||||
maxYear = minYear = (*operations)[i].year;
|
||||
|
||||
if (account.Length())
|
||||
if (minMonth == -1 || ((int)(*operations)[i].month < minMonth && (int)(*operations)[i].year == minYear))
|
||||
maxMonth = minMonth = (*operations)[i].month;
|
||||
|
||||
if ((*operations)[i].year > maxYear)
|
||||
{
|
||||
if (!_accounts.count(account))
|
||||
_accounts[account]++;
|
||||
|
||||
if (!_accountAmounts.count(accountAmount))
|
||||
_accountAmounts[accountAmount] = _kiss->GetAccountAmount(accountAmount.account, accountAmount.month, accountAmount.year);
|
||||
maxYear = (*operations)[i].year;
|
||||
maxMonth = (*operations)[i].month;
|
||||
}
|
||||
|
||||
if ((*operations)[i].month > maxMonth && (*operations)[i].year == maxYear)
|
||||
maxMonth = (*operations)[i].month;
|
||||
|
||||
if (account.Length() && !_accounts.count(account))
|
||||
_accounts[account]++;
|
||||
|
||||
if (category.Length() && !_categories.count(category))
|
||||
_categories[category]++;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,30 +22,10 @@
|
||||
|
||||
#include <model/model.h>
|
||||
#include <controller/KissCount.h>
|
||||
#include <model/AccountAmount.h>
|
||||
|
||||
class KissCount;
|
||||
|
||||
class AccountAmount {
|
||||
public:
|
||||
wxString account;
|
||||
int month;
|
||||
int year;
|
||||
bool operator()(const AccountAmount& x, const AccountAmount& y) const
|
||||
{
|
||||
long x1, y1;
|
||||
|
||||
if (x.account != y.account)
|
||||
{
|
||||
x.account.ToLong(&x1);
|
||||
y.account.ToLong(&y1);
|
||||
|
||||
return x1 < y1;
|
||||
}
|
||||
|
||||
return (x.year < y.year && x.month < y.month);
|
||||
}
|
||||
};
|
||||
|
||||
class ExportEngine {
|
||||
public:
|
||||
ExportEngine();
|
||||
|
||||
@@ -48,15 +48,16 @@ bool XMLExportEngine::SaveAccounts()
|
||||
account = _user->GetAccount(it->first);
|
||||
|
||||
ESCAPE_CHARS(account.name);
|
||||
ESCAPE_CHARS(account.number);
|
||||
|
||||
xmlTextWriterStartElement(_writer, (const xmlChar*) "account");
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "id", (const xmlChar*) account.id.utf8_str().data());
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "name", (const xmlChar*) account.name.utf8_str().data());
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "number", (const xmlChar*) account.number.utf8_str().data());
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "shared", (const xmlChar*) (account.shared ? "1" : "0"));
|
||||
// xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "shared", (const xmlChar*) (account.shared ? "1" : "0"));
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "blocked", (const xmlChar*) (account.blocked ? "1" : "0"));
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "default", (const xmlChar*) (account._default ? "1" : "0"));
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "is_owner", (const xmlChar*) (account.is_owner ? "1" : "0"));
|
||||
// xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "default", (const xmlChar*) (account._default ? "1" : "0"));
|
||||
// xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "is_owner", (const xmlChar*) (account.is_owner ? "1" : "0"));
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "virtual", (const xmlChar*) (account._virtual ? "1" : "0"));
|
||||
xmlTextWriterEndElement(_writer);
|
||||
}
|
||||
@@ -100,11 +101,11 @@ bool XMLExportEngine::SaveCategories()
|
||||
rgb = category.backcolor.Blue();
|
||||
rgb |= category.backcolor.Green() << 8;
|
||||
rgb |= category.backcolor.Red() << 16;
|
||||
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "backcolor", "%08X", rgb);
|
||||
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "backcolor", "0x%08X", rgb);
|
||||
rgb = category.forecolor.Blue();
|
||||
rgb |= category.forecolor.Green() << 8;
|
||||
rgb |= category.forecolor.Red() << 16;
|
||||
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "forecolor", "%08X", rgb);
|
||||
xmlTextWriterWriteFormatAttribute(_writer, (const xmlChar*) "forecolor", "0x%08X", rgb);
|
||||
xmlTextWriterWriteAttribute(_writer, (const xmlChar*) "fix_cost", (const xmlChar*) (category.fix_cost ? "1" : "0"));
|
||||
xmlTextWriterEndElement(_writer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user