Grégory Soutadé
521596abd5
Add Documentation Add KissCount URL into about Add Fix, non fix, both criteria into search Fix a bug (modifying language and go to another panel than main)
109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
/*
|
|
Copyright 2010 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 DATABASE_H
|
|
#define DATABASE_H
|
|
|
|
#include <stdio.h>
|
|
#include <fstream>
|
|
#include <list>
|
|
#include <wx/wxsqlite3.h>
|
|
#include <wx/wx.h>
|
|
#include <sha1.h>
|
|
|
|
#include "model.h"
|
|
#include "../controller/KissCount.h"
|
|
|
|
#define BDD_FILE "kc.bdd"
|
|
#define INIT_SCRIPT "init.sql"
|
|
|
|
enum {BOTH, FIX_OP, NON_FIX_OP};
|
|
|
|
class KissCount;
|
|
class User;
|
|
|
|
class Database
|
|
{
|
|
public:
|
|
Database(const char* filename, KissCount* kiss);
|
|
|
|
std::list<wxString> GetUsers();
|
|
bool IsValidUser(const wxString& user, const wxString& password);
|
|
|
|
User* LoadUser(const wxString& name);
|
|
void LoadYear(User* user, int year);
|
|
|
|
void UpdateOperation(Operation& op);
|
|
wxString AddOperation(User* user, Operation& op);
|
|
void DeleteOperation(Operation& op);
|
|
void DeleteOperations(User* user, int month, int year);
|
|
bool LoadOperation(User* user, const wxString& id);
|
|
double MetaAmount(const wxString& id);
|
|
double MetaPositiveAmount(const wxString& id);
|
|
|
|
double GetAccountAmount(const wxString& id, int month, int year);
|
|
void SetAccountAmount(int month, int year, const wxString& accountId, double amount);
|
|
|
|
wxString AddAccount(User* user, Account& ac);
|
|
void UpdateAccount(Account& ac);
|
|
void DeleteAccount(User* user, Account& ac);
|
|
void AddSharedAccount(Account& ac, const wxString& granted);
|
|
void RemoveSharedAccount(Account& ac, const wxString& granted);
|
|
|
|
wxString AddCategory(User* user, Category& category);
|
|
void UpdateCategory(Category& category);
|
|
void DeleteCategory(User* user, Category& category);
|
|
bool LoadCategory(const wxString& id, const wxString& name, Category& category);
|
|
|
|
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
|
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
|
|
|
void ChangePassword(User* user, const wxString& password);
|
|
bool UserExists(const wxString& name);
|
|
void ChangeName(User* user, const wxString& name);
|
|
void NewUser(const wxString& name);
|
|
|
|
void UpdatePreference(User* user, const wxString& preference);
|
|
|
|
std::vector<Operation>* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo,
|
|
wxString* amountFrom, wxString* amountTo,
|
|
std::vector<wxString> categories, int Fix, std::vector<wxString> accounts, bool wildcards);
|
|
|
|
void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo,
|
|
const wxString& yearTo, std::map<wxString, std::map<int, std::map<int, double> > >* accountAmounts,
|
|
std::map<wxString, double>* categories);
|
|
|
|
void KillMe(User* user);
|
|
bool GetOperation(const wxString& id, Operation* op);
|
|
std::map<wxString, wxString> getSharedAccountOwners(const wxString& account);
|
|
wxString getSharedAccountOwner(const wxString& account);
|
|
|
|
std::map<wxString, double>* GetNotChecked(User* user, int month, int year);
|
|
|
|
private:
|
|
KissCount* _kiss;
|
|
wxSQLite3Database _db;
|
|
|
|
void CreateDatabase();
|
|
wxString HashPassword(const wxString& password);
|
|
void LinkOrUnlinkOperation(Operation& op);
|
|
};
|
|
|
|
#endif
|