Grégory Soutadé
ec3fa8d7d5
Remove "Operating expenses" default category and add "Car" in replacement
197 lines
4.9 KiB
C++
197 lines
4.9 KiB
C++
/*
|
|
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 "GrisbiImportEngine.h"
|
|
|
|
static GrisbiImportEngine grisbiImportEngine;
|
|
|
|
void GrisbiImportEngine::LoadAccount(GrisbiImportEngine* _this, const char** attrs)
|
|
{
|
|
int i;
|
|
wxString account_number, name, id, key;
|
|
Account ac;
|
|
|
|
for (i=0; attrs[i]; i+=2)
|
|
{
|
|
if (!strcmp(attrs[i], "Name"))
|
|
name = wxString(attrs[i+1], wxConvUTF8);
|
|
|
|
else if (!strcmp(attrs[i], "Number"))
|
|
id = wxString(attrs[i+1], wxConvUTF8);
|
|
|
|
else if (!strcmp(attrs[i], "Bank_account_number"))
|
|
account_number = wxString(attrs[i+1], wxConvUTF8);
|
|
|
|
else if (!strcmp(attrs[i], "Key"))
|
|
key = wxString(attrs[i+1], wxConvUTF8);
|
|
}
|
|
|
|
account_number += key;
|
|
|
|
for (i=0; i<(int)_this->_user->_accounts.size(); i++)
|
|
{
|
|
if (_this->_user->_accounts[i].number == account_number)
|
|
{
|
|
_this->_accounts[id] = _this->_user->_accounts[i].id;
|
|
return;
|
|
}
|
|
}
|
|
|
|
_this->_accounts[id] = wxT("unknown-") + account_number;
|
|
ac.number = account_number;
|
|
ac.name = name;
|
|
_this->_unresolvedAccounts.push_back(ac);
|
|
}
|
|
|
|
void GrisbiImportEngine::LoadCategory(GrisbiImportEngine* _this, const char** attrs)
|
|
{
|
|
wxString name, id;
|
|
int i;
|
|
|
|
for (i=0; attrs[i]; i+=2)
|
|
{
|
|
if (!strcmp(attrs[i], "Na"))
|
|
name = wxString(attrs[i+1], wxConvUTF8);
|
|
|
|
else if (!strcmp(attrs[i], "Nb"))
|
|
id = wxString(attrs[i+1], wxConvUTF8);
|
|
}
|
|
|
|
for (i=0; i<(int)_this->_user->_categories.size(); i++)
|
|
{
|
|
if (_this->_user->_categories[i].name == name)
|
|
{
|
|
_this->_categories[id] = _this->_user->_categories[i].id;
|
|
return;
|
|
}
|
|
}
|
|
|
|
_this->_categories[id] = wxT("unknown-") + id;
|
|
_this->_unresolvedCategories.push_back(name);
|
|
}
|
|
|
|
void GrisbiImportEngine::LoadOperation(GrisbiImportEngine* _this, const char** attrs)
|
|
{
|
|
int i;
|
|
static int id=0;
|
|
Operation op;
|
|
wxString amount;
|
|
wxDateTime date;
|
|
|
|
op.id = wxString::Format(wxT("%d"), ++id);
|
|
op.parent = wxT("");
|
|
op.account = wxT("0");
|
|
op.category = wxT("0");
|
|
op.fix_cost = false;
|
|
op.checked = false;
|
|
op.transfert = wxT("");
|
|
op.formula = wxT("");
|
|
op.meta = false;
|
|
op._virtual = false;
|
|
|
|
for (i=0; attrs[i]; i+=2)
|
|
{
|
|
if (!strcmp(attrs[i], "Ac"))
|
|
op.account = _this->_accounts[wxString(attrs[i+1], wxConvUTF8)];
|
|
|
|
else if (!strcmp(attrs[i], "Dt"))
|
|
{
|
|
date.ParseFormat(wxString(attrs[i+1], wxConvUTF8), wxT("%m/%d/%Y"));
|
|
op.day = date.GetDay();
|
|
op.month = date.GetMonth();
|
|
op.year = date.GetYear();
|
|
}
|
|
|
|
else if (!strcmp(attrs[i], "Am"))
|
|
{
|
|
amount = wxString(attrs[i+1], wxConvUTF8);
|
|
amount.ToDouble(&op.amount);
|
|
}
|
|
|
|
else if (!strcmp(attrs[i], "Ca"))
|
|
op.category = _this->_categories[wxString(attrs[i+1], wxConvUTF8)];
|
|
|
|
else if (!strcmp(attrs[i], "No"))
|
|
op.description = wxString(attrs[i+1], wxConvUTF8);
|
|
}
|
|
|
|
_this->_operations.push_back(op);
|
|
_this->_descriptions[op.id] = op.description;
|
|
|
|
_this->MatchPattern(op.description, op);
|
|
}
|
|
|
|
void GrisbiImportEngine::GrisbiStartElement(void* user_data, const xmlChar* name_, const xmlChar** attrs_)
|
|
{
|
|
GrisbiImportEngine* _this = (GrisbiImportEngine*) user_data;
|
|
static char first = 0;
|
|
int i;
|
|
const char** attrs = (const char**) attrs_;
|
|
const char* name = (const char*) name_;
|
|
|
|
if (!first && strcmp(name, "Grisbi"))
|
|
{
|
|
throw "Invalid file !";
|
|
}
|
|
else
|
|
first = 1;
|
|
|
|
if (!strcmp(name, "General"))
|
|
{
|
|
for (i=0; attrs[i]; i+=2)
|
|
{
|
|
if (!strcmp(attrs[i], "File_version") && strcmp(attrs[i+1], "0.6.0") < 0)
|
|
throw "Unsupported version !";
|
|
|
|
else if (!strcmp(attrs[i], "Crypt_file") && !strcmp(attrs[i+1], "1"))
|
|
throw "Crypted file !";
|
|
}
|
|
}
|
|
|
|
else if (!strcmp(name, "Account"))
|
|
LoadAccount(_this, attrs);
|
|
|
|
else if (!strcmp(name, "Category"))
|
|
LoadCategory(_this, attrs);
|
|
|
|
else if (!strcmp(name, "Transaction"))
|
|
LoadOperation(_this, attrs);
|
|
}
|
|
|
|
GrisbiImportEngine::GrisbiImportEngine()
|
|
{
|
|
KissCount::RegisterImportEngine(this);
|
|
|
|
_shortExt = wxT("gsb");
|
|
_longExt = _("Grisbi files (*.gsb)|*.gsb");
|
|
|
|
_sax.startElement = GrisbiStartElement ;
|
|
}
|
|
|
|
GrisbiImportEngine::~GrisbiImportEngine()
|
|
{
|
|
}
|
|
|
|
bool GrisbiImportEngine::HandleFile(const wxString& path, User* user, Database* db, KissCount* kiss)
|
|
{
|
|
if (!ImportEngine::HandleFile(path, user, db, kiss)) return false;
|
|
|
|
return xmlSAXUserParseFile(&_sax, this, path.mb_str()) >= 0;
|
|
}
|