Add ImportPanel
Throw exception when category/account are not found in User Fix a bug in GrisbiImportEngine with QDate::fromString Try to search an account also with its name Remove categories number limit (only used for pie color)
This commit is contained in:
parent
a590409f8f
commit
7440c632dd
1
Makefile
1
Makefile
|
@ -7,7 +7,6 @@ BIN_DIR=$(DESTDIR)$(ROOT_DIR)"/bin/"
|
||||||
QT_PACKAGES="QtCore QtGui QtSql QtXml"
|
QT_PACKAGES="QtCore QtGui QtSql QtXml"
|
||||||
CXXFLAGS=`pkg-config --cflags $(QT_PACKAGES)`
|
CXXFLAGS=`pkg-config --cflags $(QT_PACKAGES)`
|
||||||
CXXFLAGS+=-Wall -Isrc -ggdb -fPIC
|
CXXFLAGS+=-Wall -Isrc -ggdb -fPIC
|
||||||
CXXFLAGS+=-I/usr/include/libxml2
|
|
||||||
CXXFLAGS+=-DRESSOURCES_ROOT="\"$(SHARE_DIR)\""
|
CXXFLAGS+=-DRESSOURCES_ROOT="\"$(SHARE_DIR)\""
|
||||||
# For developpers
|
# For developpers
|
||||||
#CXXFLAGS+=-DRESSOURCES_ROOT="\"./ressources/\""
|
#CXXFLAGS+=-DRESSOURCES_ROOT="\"./ressources/\""
|
||||||
|
|
|
@ -546,22 +546,15 @@ QString KissCount::GetImportEngineExtensions()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportEngine* KissCount::GetImportEngine(QString path, QString filter)
|
ImportEngine* KissCount::GetImportEngine(QString path)
|
||||||
{
|
{
|
||||||
std::vector<ImportEngine*>::iterator it;
|
std::vector<ImportEngine*>::iterator it;
|
||||||
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
|
std::vector<ImportEngine*>* importEngines = KissCount::GetImportEngines();
|
||||||
QString tmp;
|
|
||||||
|
|
||||||
for(it=importEngines->begin(); it!=importEngines->end(); it++)
|
for(it=importEngines->begin(); it!=importEngines->end(); it++)
|
||||||
{
|
{
|
||||||
if (filter == (*it)->GetFileExt())
|
if ((*it)->HandleFile(path, _user, _db, this))
|
||||||
{
|
return *it;
|
||||||
tmp = path;
|
|
||||||
if (!tmp.endsWith((*it)->GetShortExt()))
|
|
||||||
tmp += (*it)->GetShortExt();
|
|
||||||
if ((*it)->HandleFile(path, _user, _db, this))
|
|
||||||
return *it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -125,7 +125,7 @@ public:
|
||||||
static void UnRegisterImportEngine(ImportEngine* engine);
|
static void UnRegisterImportEngine(ImportEngine* engine);
|
||||||
|
|
||||||
QString GetImportEngineExtensions();
|
QString GetImportEngineExtensions();
|
||||||
ImportEngine* GetImportEngine(QString path, QString filter);
|
ImportEngine* GetImportEngine(QString path);
|
||||||
|
|
||||||
static void RegisterExportEngine(ExportEngine* engine);
|
static void RegisterExportEngine(ExportEngine* engine);
|
||||||
static void UnRegisterExportEngine(ExportEngine* engine);
|
static void UnRegisterExportEngine(ExportEngine* engine);
|
||||||
|
|
|
@ -80,7 +80,7 @@ QString User::GetCategoryName(int catId)
|
||||||
return _("Unknown") ;
|
return _("Unknown") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int User::GetCategoryId(const QString& catName)
|
int User::GetCategoryId(const QString& catName) throw (CategoryNotFound)
|
||||||
{
|
{
|
||||||
std::vector<Category>::iterator it;
|
std::vector<Category>::iterator it;
|
||||||
Category cat;
|
Category cat;
|
||||||
|
@ -92,7 +92,7 @@ int User::GetCategoryId(const QString& catName)
|
||||||
if ( _db->LoadCategory(0, catName, cat))
|
if ( _db->LoadCategory(0, catName, cat))
|
||||||
return cat.id;
|
return cat.id;
|
||||||
|
|
||||||
return 0 ;
|
throw CategoryNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QFont User::GetCategoryFont(int catId)
|
const QFont User::GetCategoryFont(int catId)
|
||||||
|
@ -158,24 +158,24 @@ QString User::GetAccountName(int accountId)
|
||||||
return _("Unknown") ;
|
return _("Unknown") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int User::GetAccountId(const QString& accountName)
|
int User::GetAccountId(const QString& accountName) throw (AccountNotFound)
|
||||||
{
|
{
|
||||||
std::vector<Account>::iterator it;
|
std::vector<Account>::iterator it;
|
||||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||||
if (it->name == accountName)
|
if (it->name == accountName)
|
||||||
return it->id;
|
return it->id;
|
||||||
|
|
||||||
return 0 ;
|
throw AccountNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
int User::GetAccountIdFromAccountNumber(const QString& accountNumber)
|
int User::GetAccountIdFromAccountNumber(const QString& accountNumber) throw (AccountNotFound)
|
||||||
{
|
{
|
||||||
std::vector<Account>::iterator it;
|
std::vector<Account>::iterator it;
|
||||||
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
for (it=_accounts.begin(); it !=_accounts.end(); it++)
|
||||||
if (it->number == accountNumber)
|
if (it->number == accountNumber)
|
||||||
return it->id;
|
return it->id;
|
||||||
|
|
||||||
return 0 ;
|
throw AccountNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::AddAccount(Account& ac)
|
void User::AddAccount(Account& ac)
|
||||||
|
|
|
@ -52,10 +52,11 @@ public:
|
||||||
std::map<QString, ImportPattern> _importPatterns;
|
std::map<QString, ImportPattern> _importPatterns;
|
||||||
|
|
||||||
class AccountNotFound {};
|
class AccountNotFound {};
|
||||||
|
class CategoryNotFound {};
|
||||||
|
|
||||||
Category GetCategory(int catId);
|
Category GetCategory(int catId);
|
||||||
QString GetCategoryName(int catId);
|
QString GetCategoryName(int catId);
|
||||||
int GetCategoryId(const QString& catName);
|
int GetCategoryId(const QString& catName) throw (CategoryNotFound);
|
||||||
const QFont GetCategoryFont(int catId);
|
const QFont GetCategoryFont(int catId);
|
||||||
void AddCategory(const Category& cat);
|
void AddCategory(const Category& cat);
|
||||||
void UpdateCategory(const Category& cat);
|
void UpdateCategory(const Category& cat);
|
||||||
|
@ -64,8 +65,8 @@ public:
|
||||||
|
|
||||||
Account GetAccount(int accountId) throw (AccountNotFound);
|
Account GetAccount(int accountId) throw (AccountNotFound);
|
||||||
QString GetAccountName(int accountId);
|
QString GetAccountName(int accountId);
|
||||||
int GetAccountId(const QString& accountName);
|
int GetAccountId(const QString& accountName) throw (AccountNotFound);
|
||||||
int GetAccountIdFromAccountNumber(const QString& accountNumber);
|
int GetAccountIdFromAccountNumber(const QString& accountNumber) throw (AccountNotFound);
|
||||||
void AddAccount(Account& ac);
|
void AddAccount(Account& ac);
|
||||||
void UpdateAccount(Account& ac);
|
void UpdateAccount(Account& ac);
|
||||||
void DeleteAccount(Account& ac);
|
void DeleteAccount(Account& ac);
|
||||||
|
|
|
@ -110,7 +110,7 @@ void GrisbiImportEngine::LoadOperation(const QXmlAttributes& attrs)
|
||||||
|
|
||||||
op.account = _accounts[attrs.value("Ac").toInt()];
|
op.account = _accounts[attrs.value("Ac").toInt()];
|
||||||
|
|
||||||
date.fromString(attrs.value("Dt"), "MM/%dd/%yyyy");
|
date = QDate::fromString(attrs.value("Dt"), "MM/dd/yyyy");
|
||||||
op.day = date.day();
|
op.day = date.day();
|
||||||
op.month = date.month();
|
op.month = date.month();
|
||||||
op.year = date.year();
|
op.year = date.year();
|
||||||
|
|
|
@ -93,7 +93,6 @@ bool XMLImportEngine::startElement (const QString& namespaceURI, const QString&
|
||||||
void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
|
void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
QString account_number, name;
|
|
||||||
Account ac;
|
Account ac;
|
||||||
static int unknownAccount = 0;
|
static int unknownAccount = 0;
|
||||||
|
|
||||||
|
@ -101,7 +100,7 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
|
||||||
|
|
||||||
ac.name = attrs.value("name");
|
ac.name = attrs.value("name");
|
||||||
ac.id = id = attrs.value("id").toInt();
|
ac.id = id = attrs.value("id").toInt();
|
||||||
ac.number = account_number = attrs.value("number");
|
ac.number = attrs.value("number");
|
||||||
ac.blocked = (attrs.value("blocked") == "1");
|
ac.blocked = (attrs.value("blocked") == "1");
|
||||||
ac._virtual = (attrs.value("virtual") == "1");
|
ac._virtual = (attrs.value("virtual") == "1");
|
||||||
ac.hidden = (attrs.value("hidden") == "1");
|
ac.hidden = (attrs.value("hidden") == "1");
|
||||||
|
@ -113,10 +112,21 @@ void XMLImportEngine::LoadAccount(const QXmlAttributes& attrs)
|
||||||
ac.shared = false;
|
ac.shared = false;
|
||||||
ac.is_owner = true;
|
ac.is_owner = true;
|
||||||
|
|
||||||
if (account_number.size())
|
if (ac.number.size())
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
_accounts[ac.id] = _user->GetAccountIdFromAccountNumber(account_number);
|
_accounts[ac.id] = _user->GetAccountIdFromAccountNumber(ac.number);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (User::AccountNotFound)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ac.name.size())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
_accounts[ac.id] = _user->GetAccountId(ac.name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (User::AccountNotFound)
|
catch (User::AccountNotFound)
|
||||||
|
|
|
@ -81,7 +81,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
|
||||||
_categoriesIndexes[categoryIt->name] = i;
|
_categoriesIndexes[categoryIt->name] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
|
nbCategories = user->GetCategoriesNumber();
|
||||||
|
// nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
|
||||||
|
|
||||||
_pie = new KDChart::Widget();
|
_pie = new KDChart::Widget();
|
||||||
_pie->setType( KDChart::Widget::Pie );
|
_pie->setType( KDChart::Widget::Pie );
|
||||||
|
@ -107,7 +108,8 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, pare
|
||||||
legend->setText( i, _categories[i] );
|
legend->setText( i, _categories[i] );
|
||||||
_dataset->setData(_dataset->index(i, 0, QModelIndex()), _categories[i]);
|
_dataset->setData(_dataset->index(i, 0, QModelIndex()), _categories[i]);
|
||||||
_dataset->setData(_dataset->index(i, 1, QModelIndex()), 0.0);
|
_dataset->setData(_dataset->index(i, 1, QModelIndex()), 0.0);
|
||||||
_dataset->setData(_dataset->index(i, 0, QModelIndex()), wxUI::categoryColors[i], Qt::DecorationRole);
|
if (i < wxUI::MAX_CATEGORY)
|
||||||
|
_dataset->setData(_dataset->index(i, 0, QModelIndex()), wxUI::categoryColors[i], Qt::DecorationRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
_pie->setMaximumSize( 200, 400 );
|
_pie->setMaximumSize( 200, 400 );
|
||||||
|
|
440
src/view/ImportPanel.cpp
Normal file
440
src/view/ImportPanel.cpp
Normal file
|
@ -0,0 +1,440 @@
|
||||||
|
/*
|
||||||
|
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 <QMessageBox>
|
||||||
|
|
||||||
|
#include "ImportPanel.hpp"
|
||||||
|
#include "grid/ChoiceDelegate.hpp"
|
||||||
|
|
||||||
|
ImportPanel::ImportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent)
|
||||||
|
{
|
||||||
|
QVBoxLayout *vbox = new QVBoxLayout;
|
||||||
|
QVBoxLayout *vbox2 = new QVBoxLayout;
|
||||||
|
QHBoxLayout *hbox = new QHBoxLayout;
|
||||||
|
_hbox = new QHBoxLayout;
|
||||||
|
QPushButton* buttonOpen;
|
||||||
|
QGroupBox* staticAccount = new QGroupBox(_("Unresolved accounts"));
|
||||||
|
QGroupBox* staticCategory = new QGroupBox(_("Unresolved categories"));
|
||||||
|
|
||||||
|
setLayout(vbox);
|
||||||
|
|
||||||
|
_fileTxt = new QLineEdit;
|
||||||
|
buttonOpen = new QPushButton("...");
|
||||||
|
|
||||||
|
connect(buttonOpen, SIGNAL(clicked()), this, SLOT(OnFile()));
|
||||||
|
connect(_fileTxt, SIGNAL(returnPressed()), this, SLOT(OnFileEnter()));
|
||||||
|
|
||||||
|
_buttonLoadOperations = new QPushButton(_("Load operations"));
|
||||||
|
_buttonLoadOperations->setEnabled(false);
|
||||||
|
connect(_buttonLoadOperations, SIGNAL(clicked()), this, SLOT(OnLoadOperations()));
|
||||||
|
|
||||||
|
_buttonIntegrate = new QPushButton(_("Integrate operations"));
|
||||||
|
_buttonIntegrate->setEnabled(false);
|
||||||
|
connect(_buttonIntegrate, SIGNAL(clicked()), this, SLOT(OnIntegrate()));
|
||||||
|
|
||||||
|
_checkSaveImportPatterns = new QCheckBox(_("Save import patterns"));
|
||||||
|
|
||||||
|
hbox->addWidget(_fileTxt);
|
||||||
|
hbox->addWidget(buttonOpen);
|
||||||
|
hbox->addWidget(_buttonLoadOperations);
|
||||||
|
hbox->addWidget(_buttonIntegrate);
|
||||||
|
hbox->addWidget(_checkSaveImportPatterns);
|
||||||
|
|
||||||
|
vbox->addLayout(hbox);
|
||||||
|
|
||||||
|
_accountsGrid = new QTableWidget(0, 3);
|
||||||
|
_accountsGrid->verticalHeader()->setHidden(true);
|
||||||
|
QStringList labels;
|
||||||
|
labels << _("File account") << _("Account name") << _("Internal account");
|
||||||
|
_accountsGrid->setHorizontalHeaderLabels(labels);
|
||||||
|
_accountsGrid->resizeColumnsToContents();
|
||||||
|
|
||||||
|
_categoriesGrid = new QTableWidget(0, 3);
|
||||||
|
_categoriesGrid->verticalHeader()->setHidden(true);
|
||||||
|
labels.clear();
|
||||||
|
labels << _("File category") << _("Category name") << _("Internal category");
|
||||||
|
_categoriesGrid->setHorizontalHeaderLabels(labels);
|
||||||
|
_categoriesGrid->resizeColumnsToContents();
|
||||||
|
|
||||||
|
{
|
||||||
|
QVBoxLayout *vbox = new QVBoxLayout;
|
||||||
|
vbox->addWidget(_accountsGrid);
|
||||||
|
staticAccount->setLayout(vbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
vbox2->addWidget(staticAccount);
|
||||||
|
|
||||||
|
{
|
||||||
|
QVBoxLayout *vbox = new QVBoxLayout;
|
||||||
|
vbox->addWidget(_categoriesGrid);
|
||||||
|
staticCategory->setLayout(vbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
vbox2->addWidget(staticCategory);
|
||||||
|
|
||||||
|
_operationsGrid = new GridAccount(kiss, this, false, false, false);
|
||||||
|
connect(_operationsGrid, SIGNAL(cellChanged(int, int)), this, SLOT(OnOperationModified(int, int)));
|
||||||
|
|
||||||
|
_hbox->addLayout(vbox2);
|
||||||
|
_hbox->addWidget(_operationsGrid);
|
||||||
|
|
||||||
|
vbox->addLayout(_hbox);
|
||||||
|
|
||||||
|
layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
KissPanel* ImportPanel::CreatePanel()
|
||||||
|
{
|
||||||
|
return new ImportPanel(_kiss, _wxUI);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPushButton* ImportPanel::GetButton()
|
||||||
|
{
|
||||||
|
if (!_KissButton)
|
||||||
|
{
|
||||||
|
_KissButton = new QPushButton(QIcon(IMPORT_ICON), "", this);
|
||||||
|
_KissButton->setFixedSize(128, 128);
|
||||||
|
_KissButton->setIconSize(QSize(128, 128));
|
||||||
|
}
|
||||||
|
|
||||||
|
return _KissButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ImportPanel::GetToolTip()
|
||||||
|
{
|
||||||
|
return _("Import");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportPanel::OnShow()
|
||||||
|
{
|
||||||
|
_wxUI->setWindowTitle(_("KissCount - Import"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportPanel::OnFile()
|
||||||
|
{
|
||||||
|
QString path;
|
||||||
|
|
||||||
|
path = QFileDialog::getOpenFileName(0, _("Choose a database to open"), "", _kiss->GetImportEngineExtensions());
|
||||||
|
|
||||||
|
if (!path.size())
|
||||||
|
return;
|
||||||
|
|
||||||
|
_fileTxt->setText(path);
|
||||||
|
|
||||||
|
ProcessFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportPanel::OnFileEnter()
|
||||||
|
{
|
||||||
|
ProcessFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportPanel::ProcessFile()
|
||||||
|
{
|
||||||
|
User* user = _kiss->GetUser();
|
||||||
|
int i;
|
||||||
|
QString* userAccounts;
|
||||||
|
std::map<int, int> resolvedAccounts;
|
||||||
|
QString* userCategories;
|
||||||
|
std::map<int, int> resolvedCategories;
|
||||||
|
QTableWidgetItem* item;
|
||||||
|
|
||||||
|
QString path = _fileTxt->text();
|
||||||
|
|
||||||
|
_buttonLoadOperations->setEnabled(false);
|
||||||
|
_buttonIntegrate->setEnabled(false);
|
||||||
|
_accountsGrid->setRowCount(0);
|
||||||
|
_categoriesGrid->setRowCount(0);
|
||||||
|
_operationsGrid->setRowCount(0);
|
||||||
|
|
||||||
|
_importEngine = _kiss->GetImportEngine(path);
|
||||||
|
|
||||||
|
if (!_importEngine)
|
||||||
|
{
|
||||||
|
QMessageBox::critical(0, _("Error"), _("Any engine can process this file !"));
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
_importEngine->ParseFile(_unresolvedAccounts, _unresolvedCategories);
|
||||||
|
|
||||||
|
if (_unresolvedAccounts.size())
|
||||||
|
{
|
||||||
|
int nb_accounts = user->GetAccountsNumber();
|
||||||
|
userAccounts = new QString[nb_accounts+1];
|
||||||
|
|
||||||
|
userAccounts[0] = _("Create one");
|
||||||
|
|
||||||
|
for(i=0; i<nb_accounts; i++)
|
||||||
|
userAccounts[i+1] = user->_accounts[i].name;
|
||||||
|
|
||||||
|
ChoiceDelegate* accountEditor = new ChoiceDelegate(this, userAccounts, nb_accounts+1);
|
||||||
|
_accountsGrid->setItemDelegateForColumn(2, accountEditor);
|
||||||
|
|
||||||
|
_buttonLoadOperations->setEnabled(true);
|
||||||
|
|
||||||
|
_accountsGrid->setRowCount(_unresolvedAccounts.size());
|
||||||
|
|
||||||
|
for (i=0; i<(int)_unresolvedAccounts.size(); i++)
|
||||||
|
{
|
||||||
|
item = new QTableWidgetItem(_unresolvedAccounts[i].number);
|
||||||
|
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
||||||
|
_accountsGrid->setItem(i, 0, item);
|
||||||
|
_accountsGrid->setItem(i, 1, new QTableWidgetItem(_unresolvedAccounts[i].name));
|
||||||
|
_accountsGrid->setItem(i, 2, new QTableWidgetItem(userAccounts[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
_accountsGrid->resizeColumnsToContents();
|
||||||
|
_accountsGrid->layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_unresolvedCategories.size())
|
||||||
|
{
|
||||||
|
int nb_categories = user->GetCategoriesNumber();
|
||||||
|
userCategories = new QString[nb_categories+1];
|
||||||
|
|
||||||
|
userCategories[0] = _("Create one");
|
||||||
|
|
||||||
|
for(i=0; i<nb_categories; i++)
|
||||||
|
userCategories[i+1] = user->_categories[i].name;
|
||||||
|
|
||||||
|
ChoiceDelegate* categoryEditor = new ChoiceDelegate(this, userCategories, nb_categories+1);
|
||||||
|
_categoriesGrid->setItemDelegateForColumn(2, categoryEditor);
|
||||||
|
|
||||||
|
_buttonLoadOperations->setEnabled(true);
|
||||||
|
|
||||||
|
_categoriesGrid->setRowCount(_unresolvedCategories.size());
|
||||||
|
|
||||||
|
for (i=0; i<(int)_unresolvedCategories.size(); i++)
|
||||||
|
{
|
||||||
|
item = new QTableWidgetItem(_unresolvedCategories[i].name);
|
||||||
|
item->setFlags(item->flags() & ~Qt::ItemIsEditable);
|
||||||
|
_categoriesGrid->setItem(i, 0, item);
|
||||||
|
_categoriesGrid->setItem(i, 1, new QTableWidgetItem(""));
|
||||||
|
_categoriesGrid->setItem(i, 2, new QTableWidgetItem(userCategories[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
_categoriesGrid->resizeColumnsToContents();
|
||||||
|
_categoriesGrid->layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_unresolvedAccounts.size() && !_unresolvedCategories.size())
|
||||||
|
{
|
||||||
|
OnLoadOperations();
|
||||||
|
}
|
||||||
|
layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportPanel::OnLoadOperations()
|
||||||
|
{
|
||||||
|
int i, nbAccounts=0, nbCategories=0;
|
||||||
|
User* user = _kiss->GetUser();
|
||||||
|
Account account;
|
||||||
|
Category category;
|
||||||
|
std::map<int, int> accounts;
|
||||||
|
std::map<int, int> categories;
|
||||||
|
int oldid;
|
||||||
|
|
||||||
|
for(i=0; i<_accountsGrid->rowCount(); i++)
|
||||||
|
{
|
||||||
|
if (_accountsGrid->item(i, 2)->text() == _("Create one"))
|
||||||
|
nbAccounts++;
|
||||||
|
else
|
||||||
|
accounts[_accountsGrid->item(i, 0)->text().toInt()] =
|
||||||
|
user->GetAccountId(_accountsGrid->item(i, 1)->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<_categoriesGrid->rowCount(); i++)
|
||||||
|
{
|
||||||
|
if (_categoriesGrid->item(i, 2)->text() == _("Create one"))
|
||||||
|
nbCategories++;
|
||||||
|
else
|
||||||
|
categories[_categoriesGrid->item(i, 0)->text().toInt()] =
|
||||||
|
user->GetAccountId(_categoriesGrid->item(i, 1)->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbAccounts || nbCategories)
|
||||||
|
{
|
||||||
|
QString message, v;
|
||||||
|
|
||||||
|
if (nbAccounts)
|
||||||
|
{
|
||||||
|
message += v.sprintf(_("%d accounts").toStdString().c_str(), nbAccounts);
|
||||||
|
if (nbCategories) message += _(" and ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbCategories)
|
||||||
|
message += v.sprintf(_("%d categories").toStdString().c_str(), nbCategories);
|
||||||
|
|
||||||
|
message += _(" will be created, is it ok ?");
|
||||||
|
|
||||||
|
if (QMessageBox::question(0, "KissCount", message, QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(i=0; i<_accountsGrid->rowCount(); i++)
|
||||||
|
{
|
||||||
|
if (_accountsGrid->item(i, 2)->text() == _("Create one"))
|
||||||
|
{
|
||||||
|
account = _unresolvedAccounts[i] ;
|
||||||
|
if (_accountsGrid->item(i, 1)->text().length())
|
||||||
|
account.name = _accountsGrid->item(i, 1)->text();
|
||||||
|
else
|
||||||
|
account.name = _accountsGrid->item(i, 0)->text();
|
||||||
|
account.number = _accountsGrid->item(i, 0)->text();
|
||||||
|
|
||||||
|
oldid = account.id;
|
||||||
|
_resolvedAccounts[oldid] = accounts[_accountsGrid->item(i, 0)->text().toInt()] = _kiss->AddAccount(account);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_accountsGrid->setRowCount(0);
|
||||||
|
|
||||||
|
for(i=0; i<_categoriesGrid->rowCount(); i++)
|
||||||
|
{
|
||||||
|
if (_categoriesGrid->item(i, 2)->text() == _("Create one"))
|
||||||
|
{
|
||||||
|
category = _unresolvedCategories[i] ;
|
||||||
|
if (_categoriesGrid->item(i, 1)->text().length())
|
||||||
|
category.name = _categoriesGrid->item(i, 1)->text();
|
||||||
|
else
|
||||||
|
category.name = _categoriesGrid->item(i, 0)->text();
|
||||||
|
|
||||||
|
oldid = category.id;
|
||||||
|
_resolvedCategories[oldid] = categories[_categoriesGrid->item(i, 0)->text().toInt()] = category.id = _kiss->AddCategory(category);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_categoriesGrid->setRowCount(0);
|
||||||
|
|
||||||
|
_wxUI->NeedReload();
|
||||||
|
}
|
||||||
|
|
||||||
|
_operations = _importEngine->GetOperations(accounts, categories);
|
||||||
|
|
||||||
|
if (_operations->size())
|
||||||
|
{
|
||||||
|
_hbox->removeWidget(_operationsGrid);
|
||||||
|
delete _operationsGrid;
|
||||||
|
_operationsGrid = new GridAccount(_kiss, this, false, false, false);
|
||||||
|
_hbox->addWidget(_operationsGrid);
|
||||||
|
|
||||||
|
_operationsGrid->LoadOperations(_operations, 0, 0);
|
||||||
|
_buttonIntegrate->setEnabled(true);
|
||||||
|
|
||||||
|
_buttonLoadOperations->setEnabled(false);
|
||||||
|
|
||||||
|
layout();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::information(0, "KissCount", _("No operation found into this file"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportPanel::OnIntegrate()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
std::map<int, int> mapid;
|
||||||
|
int oldid, account;
|
||||||
|
bool update;
|
||||||
|
std::map<AccountAmount, double, AccountAmount> accountAmounts;
|
||||||
|
std::map<AccountAmount, double, AccountAmount>::iterator it;
|
||||||
|
double amount;
|
||||||
|
|
||||||
|
if (!_operations->size()) return;
|
||||||
|
|
||||||
|
if (QMessageBox::question(0, "KissCount", _("Are you sure want to integrate these operations ?"), QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_buttonIntegrate->setEnabled(false);
|
||||||
|
|
||||||
|
for(i=0; i<(int)_operations->size(); i++)
|
||||||
|
{
|
||||||
|
oldid = (*_operations)[i].id;
|
||||||
|
_kiss->AddOperation((*_operations)[i], false);
|
||||||
|
mapid[oldid] = (*_operations)[i].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0; i<(int)_operations->size(); i++)
|
||||||
|
{
|
||||||
|
update = false;
|
||||||
|
|
||||||
|
if ((*_operations)[i].parent)
|
||||||
|
{
|
||||||
|
(*_operations)[i].parent = mapid[(*_operations)[i].parent];
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*_operations)[i].transfert)
|
||||||
|
{
|
||||||
|
(*_operations)[i].transfert = mapid[(*_operations)[i].transfert];
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (update)
|
||||||
|
_kiss->UpdateOperation((*_operations)[i], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
accountAmounts = _importEngine->GetAccountAmounts();
|
||||||
|
|
||||||
|
for(it=accountAmounts.begin(); it!=accountAmounts.end(); it++)
|
||||||
|
{
|
||||||
|
account = it->first.account;
|
||||||
|
|
||||||
|
if (_resolvedAccounts.count(account))
|
||||||
|
account = _resolvedAccounts[account];
|
||||||
|
|
||||||
|
amount = _kiss->GetAccountAmount(account, it->first.month, it->first.year);
|
||||||
|
|
||||||
|
if (!amount)
|
||||||
|
_kiss->SetAccountAmount(account, it->first.month, it->first.year, it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_checkSaveImportPatterns->checkState() == Qt::Checked)
|
||||||
|
_kiss->UpdateImportPattern();
|
||||||
|
|
||||||
|
_operations->clear();
|
||||||
|
_operationsGrid->ClearGrid();
|
||||||
|
|
||||||
|
QMessageBox::information(0, "KissCount", _("Operations successfully imported"));
|
||||||
|
|
||||||
|
_wxUI->NeedReload();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImportPanel::OnOperationModified(int row, int col)
|
||||||
|
{
|
||||||
|
static bool update = false;
|
||||||
|
|
||||||
|
if (col != GridAccount::DESCRIPTION &&
|
||||||
|
col != GridAccount::CATEGORY &&
|
||||||
|
col != GridAccount::ACCOUNT)
|
||||||
|
return ;
|
||||||
|
|
||||||
|
if (update) return;
|
||||||
|
|
||||||
|
update = true;
|
||||||
|
|
||||||
|
_operationsGrid->ClearGrid();
|
||||||
|
|
||||||
|
if (_importEngine->UpdatePattern(row-1) > 1)
|
||||||
|
_operationsGrid->LoadOperations(_operations, 0, 0);
|
||||||
|
|
||||||
|
layout();
|
||||||
|
|
||||||
|
update = false;
|
||||||
|
}
|
68
src/view/ImportPanel.hpp
Normal file
68
src/view/ImportPanel.hpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
Copyright 2010-2012 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef IMPORTPANEL_H
|
||||||
|
#define IMPORTPANEL_H
|
||||||
|
|
||||||
|
#include <QtGui>
|
||||||
|
|
||||||
|
#include "view.hpp"
|
||||||
|
#include <model/model.hpp>
|
||||||
|
#include <model/import/ImportEngine.hpp>
|
||||||
|
|
||||||
|
#include "grid/GridAccount.hpp"
|
||||||
|
|
||||||
|
class ImportPanel: public KissPanel
|
||||||
|
{
|
||||||
|
Q_OBJECT;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ImportPanel(KissCount* kiss, wxUI *parent);
|
||||||
|
|
||||||
|
KissPanel* CreatePanel();
|
||||||
|
QPushButton* GetButton();
|
||||||
|
QString GetToolTip();
|
||||||
|
void OnShow();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void OnFile();
|
||||||
|
void OnFileEnter();
|
||||||
|
void OnLoadOperations();
|
||||||
|
void OnIntegrate();
|
||||||
|
void OnOperationModified(int row, int col);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHBoxLayout *_hbox;
|
||||||
|
QTableWidget* _accountsGrid, *_categoriesGrid;
|
||||||
|
QLineEdit* _fileTxt;
|
||||||
|
GridAccount* _operationsGrid;
|
||||||
|
ImportEngine* _importEngine;
|
||||||
|
QPushButton* _buttonLoadOperations, *_buttonIntegrate;
|
||||||
|
QCheckBox *_checkSaveImportPatterns;
|
||||||
|
std::vector<Operation>* _operations;
|
||||||
|
|
||||||
|
std::vector<Account> _unresolvedAccounts;
|
||||||
|
std::vector<Category> _unresolvedCategories;
|
||||||
|
std::map<int, int> _resolvedAccounts;
|
||||||
|
std::map<int, int> _resolvedCategories;
|
||||||
|
|
||||||
|
void ProcessFile();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -135,7 +135,8 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent),
|
||||||
_vbox3->addWidget(_account);
|
_vbox3->addWidget(_account);
|
||||||
_vbox3->addWidget(_statsGrid);
|
_vbox3->addWidget(_statsGrid);
|
||||||
|
|
||||||
nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
|
nbCategories = user->GetCategoriesNumber();
|
||||||
|
// nbCategories = (user->GetCategoriesNumber() <= wxUI::MAX_CATEGORY) ? user->GetCategoriesNumber() : wxUI::MAX_CATEGORY;
|
||||||
|
|
||||||
_categoriesValues = new double[user->GetCategoriesNumber()];
|
_categoriesValues = new double[user->GetCategoriesNumber()];
|
||||||
for(i=0; i<user->GetCategoriesNumber(); i++)
|
for(i=0; i<user->GetCategoriesNumber(); i++)
|
||||||
|
@ -159,7 +160,8 @@ StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent),
|
||||||
{
|
{
|
||||||
_categoriesValues[i] = 0.0;
|
_categoriesValues[i] = 0.0;
|
||||||
_pie->setDataset(i, vec, _categories[i]);
|
_pie->setDataset(i, vec, _categories[i]);
|
||||||
_pie->pieDiagram()->setBrush(i, QBrush(wxUI::categoryColors[i]));
|
if (i < wxUI::MAX_CATEGORY)
|
||||||
|
_pie->pieDiagram()->setBrush(i, QBrush(wxUI::categoryColors[i]));
|
||||||
legend->setText(i, _categories[i]);
|
legend->setText(i, _categories[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +219,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
|
||||||
std::map<int, std::map<int, double> >::iterator accountYearIt;
|
std::map<int, std::map<int, double> >::iterator accountYearIt;
|
||||||
double total, non_fix;
|
double total, non_fix;
|
||||||
int account, size, i, a, b, percents, nbDays;
|
int account, size, i, a, b, percents, nbDays;
|
||||||
QString value;
|
QString value, v;
|
||||||
User* user = _kiss->GetUser();
|
User* user = _kiss->GetUser();
|
||||||
QDate date;
|
QDate date;
|
||||||
bool failed;
|
bool failed;
|
||||||
|
@ -372,7 +374,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
|
||||||
percents = ((double) (categoriesIt->second*100))/total;
|
percents = ((double) (categoriesIt->second*100))/total;
|
||||||
else
|
else
|
||||||
percents = 0;
|
percents = 0;
|
||||||
value = value.sprintf("%0.2lf (%02d%%)", categoriesIt->second, percents);
|
value = v.sprintf("%0.2lf (%02d%%)", categoriesIt->second, percents);
|
||||||
if (i)
|
if (i)
|
||||||
{
|
{
|
||||||
_statsGrid->setItem(_categoriesIndexes[categoriesIt->first]+1, 1, new QTableWidgetItem(value));
|
_statsGrid->setItem(_categoriesIndexes[categoriesIt->first]+1, 1, new QTableWidgetItem(value));
|
||||||
|
@ -394,7 +396,7 @@ void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearT
|
||||||
percents = ((double) (non_fix*100))/total;
|
percents = ((double) (non_fix*100))/total;
|
||||||
else
|
else
|
||||||
percents = 0;
|
percents = 0;
|
||||||
value = value.sprintf("%0.2lf (%02d%%)", non_fix, percents);
|
value = v.sprintf("%0.2lf (%02d%%)", non_fix, percents);
|
||||||
_statsGrid->setItem(1, 1, new QTableWidgetItem(value));
|
_statsGrid->setItem(1, 1, new QTableWidgetItem(value));
|
||||||
|
|
||||||
_statsGrid->resizeColumnsToContents();
|
_statsGrid->resizeColumnsToContents();
|
||||||
|
|
|
@ -27,8 +27,6 @@
|
||||||
#include "FormulaDelegate.hpp"
|
#include "FormulaDelegate.hpp"
|
||||||
#include "TabDelegate.hpp"
|
#include "TabDelegate.hpp"
|
||||||
|
|
||||||
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
|
|
||||||
|
|
||||||
#define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
#define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
||||||
{ \
|
{ \
|
||||||
if (!this->item(row, i)) setItem(row, i, new QTableWidgetItem("")); \
|
if (!this->item(row, i)) setItem(row, i, new QTableWidgetItem("")); \
|
||||||
|
@ -75,7 +73,6 @@ GridAccount::GridAccount(KissCount* kiss, QWidget *parent,
|
||||||
for(i=0; i<NUMBER_COLS_OPS; i++)
|
for(i=0; i<NUMBER_COLS_OPS; i++)
|
||||||
{
|
{
|
||||||
item = new QTableWidgetItem(colsName[i]);
|
item = new QTableWidgetItem(colsName[i]);
|
||||||
item->setText(colsName[i]);
|
|
||||||
item->setBackground(view::OWN_CYAN);
|
item->setBackground(view::OWN_CYAN);
|
||||||
item->setFont(font);
|
item->setFont(font);
|
||||||
SET_READ_ONLY(item);
|
SET_READ_ONLY(item);
|
||||||
|
|
|
@ -41,6 +41,8 @@ class GridAccount : public QTableWidget
|
||||||
public:
|
public:
|
||||||
class OperationNotFound {};
|
class OperationNotFound {};
|
||||||
|
|
||||||
|
enum {TREE, DESCRIPTION, OP_DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, OP_DELETE, CHECKED, NUMBER_COLS_OPS};
|
||||||
|
|
||||||
GridAccount(KissCount* kiss, QWidget *parent,
|
GridAccount(KissCount* kiss, QWidget *parent,
|
||||||
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
|
bool canAddOperation, bool setWeek, bool synchronizeWithDatabase);
|
||||||
~GridAccount();
|
~GridAccount();
|
||||||
|
|
|
@ -22,9 +22,8 @@
|
||||||
#include "AccountPanel.hpp"
|
#include "AccountPanel.hpp"
|
||||||
#include "SearchPanel.hpp"
|
#include "SearchPanel.hpp"
|
||||||
#include "PreferencesPanel.hpp"
|
#include "PreferencesPanel.hpp"
|
||||||
//#include "UsersDialog.hpp"
|
|
||||||
#include "StatsPanel.hpp"
|
#include "StatsPanel.hpp"
|
||||||
//#include "ImportPanel.hpp"
|
#include "ImportPanel.hpp"
|
||||||
#include "ExportPanel.hpp"
|
#include "ExportPanel.hpp"
|
||||||
|
|
||||||
#include "wxUI.hpp"
|
#include "wxUI.hpp"
|
||||||
|
@ -168,7 +167,7 @@ void wxUI::InitPanels()
|
||||||
ADD_PANEL(StatsPanel);
|
ADD_PANEL(StatsPanel);
|
||||||
ADD_PANEL(SearchPanel);
|
ADD_PANEL(SearchPanel);
|
||||||
ADD_PANEL(PreferencesPanel);
|
ADD_PANEL(PreferencesPanel);
|
||||||
// ADD_PANEL(ImportPanel, 4);
|
ADD_PANEL(ImportPanel);
|
||||||
ADD_PANEL(ExportPanel);
|
ADD_PANEL(ExportPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user