2010-07-14 16:25:19 +02:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-07-14 16:22:02 +02:00
|
|
|
#include "GridAccount.h"
|
|
|
|
|
|
|
|
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
|
|
|
{ \
|
|
|
|
SetCellBackgroundColour(row, i, color); \
|
|
|
|
}
|
|
|
|
|
|
|
|
GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxGrid(parent, id),
|
|
|
|
_fixCosts(0), _week1(0), _week2(0), _week3(0), _week4(0), _kiss(kiss)
|
|
|
|
{
|
|
|
|
wxBitmap deleteBitmap(wxT(DELETE_ICON));
|
|
|
|
wxBitmap checkedBitmap(wxT(CHECKED_ICON));
|
|
|
|
DEFAULT_FONT(font);
|
|
|
|
int i;
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
std::vector<Account>::iterator accountIt;
|
|
|
|
std::vector<Category>::iterator categoryIt;
|
|
|
|
|
|
|
|
CreateGrid(1, NUMBER_COLS_OPS);
|
|
|
|
SetColLabelSize(0);
|
|
|
|
SetRowLabelSize(0);
|
|
|
|
|
|
|
|
SetColSize (0, GetColSize(0)*3);
|
|
|
|
SetDefaultCellFont(font);
|
|
|
|
|
|
|
|
font.SetWeight(wxFONTWEIGHT_BOLD);
|
|
|
|
wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), wxT(""), wxT("")};
|
|
|
|
for(i=0; i<NUMBER_COLS_OPS; i++)
|
|
|
|
{
|
|
|
|
SetCellValue(0, i, colsName[i]);
|
|
|
|
SetCellBackgroundColour(0, i, OWN_CYAN);
|
|
|
|
SetCellFont(0, i, font);
|
|
|
|
SetReadOnly(0, i, true);
|
|
|
|
SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
|
|
|
}
|
|
|
|
SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(deleteBitmap));
|
|
|
|
SetCellRenderer(0, CHECKED, new wxGridCellBitmapRenderer(checkedBitmap));
|
|
|
|
|
|
|
|
_accounts = new wxString[user->GetAccountsNumber()];
|
|
|
|
for (i=0,
|
|
|
|
accountIt = user->_accounts.begin();
|
|
|
|
accountIt != user->_accounts.end();
|
|
|
|
accountIt++, i++)
|
|
|
|
_accounts[i] = accountIt->name;
|
|
|
|
|
|
|
|
_categories = new wxString[user->GetCategoriesNumber()] ;
|
|
|
|
for(i=0, categoryIt = user->_categories.begin();
|
|
|
|
categoryIt != user->_categories.end();
|
|
|
|
categoryIt++, i++)
|
|
|
|
{
|
|
|
|
_categories[i] = categoryIt->name ;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GridAccount::~GridAccount()
|
|
|
|
{
|
|
|
|
delete[] _categories;
|
|
|
|
delete[] _accounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPen GridAccount::GetColGridLinePen (int col)
|
|
|
|
{return wxPen(*wxBLACK, 1, wxSOLID);}
|
|
|
|
|
|
|
|
wxPen GridAccount::GetRowGridLinePen (int row) {
|
|
|
|
if (row == 0 || row == _fixCosts ||
|
|
|
|
row == _week1 ||
|
|
|
|
row == _week2 ||
|
|
|
|
row == _week3 ||
|
|
|
|
row == _week4)
|
|
|
|
return wxPen(*wxBLACK, 1, wxSOLID);
|
|
|
|
|
|
|
|
return GetCellBackgroundColour(row, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridAccount::SetWeek(int week, int line) {
|
|
|
|
switch (week) {
|
|
|
|
case 1: _week1 = line; break;
|
|
|
|
case 2: _week2 = line; break;
|
|
|
|
case 3: _week3 = line; break;
|
|
|
|
case 4: _week4 = line; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear)
|
|
|
|
{
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
int r, g, b;
|
|
|
|
wxColour color;
|
2010-07-17 12:33:39 +02:00
|
|
|
wxDateTime curDate;
|
|
|
|
|
|
|
|
curDate.SetToCurrent();
|
2010-07-14 16:22:02 +02:00
|
|
|
|
|
|
|
if (!op && !user->_accounts.size()) return;
|
|
|
|
|
|
|
|
InsertRows(line, 1);
|
|
|
|
|
2010-07-14 18:56:07 +02:00
|
|
|
SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(wxID_ANY, 2));
|
|
|
|
SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(wxID_ANY, 2));
|
2010-07-14 16:22:02 +02:00
|
|
|
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false);
|
|
|
|
SetCellEditor(line, ACCOUNT, accountEditor);
|
|
|
|
wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false);
|
|
|
|
SetCellEditor(line, CATEGORY, categoryEditor);
|
|
|
|
|
|
|
|
if (fix)
|
|
|
|
{
|
|
|
|
SetCellValue(line, CATEGORY, _("Fix"));
|
|
|
|
SetReadOnly(line, CATEGORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (op)
|
|
|
|
{
|
|
|
|
SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year));
|
|
|
|
SetCellValue(line, DESCRIPTION, op->description);
|
|
|
|
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
|
|
|
|
if (op->amount < 0)
|
|
|
|
SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount));
|
|
|
|
else
|
|
|
|
SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount));
|
|
|
|
SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
|
|
|
|
if (!fix)
|
|
|
|
SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
|
|
|
|
SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
|
|
|
|
SetCellEditor(line, DELETE, new wxGridCellBoolEditor ());
|
|
|
|
SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
|
|
|
|
SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ());
|
|
|
|
|
|
|
|
color = user->GetCategory(op->category).color;
|
|
|
|
|
|
|
|
if (op->checked)
|
|
|
|
{
|
|
|
|
r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ;
|
|
|
|
g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ;
|
|
|
|
b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ;
|
|
|
|
color.Set(r, g, b, color.Alpha());
|
|
|
|
SetCellValue(line, CHECKED, wxT("1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
SET_ROW_COLOR(line, color);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
2010-07-17 12:33:39 +02:00
|
|
|
if (curDate.GetMonth() == curMonth &&
|
|
|
|
curDate.GetYear() == curYear)
|
|
|
|
{
|
|
|
|
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear));
|
|
|
|
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
|
|
|
|
2010-07-14 16:22:02 +02:00
|
|
|
if (fix)
|
|
|
|
SET_ROW_COLOR(line, OWN_YELLOW)
|
|
|
|
else
|
|
|
|
SET_ROW_COLOR(line, OWN_GREEN);
|
|
|
|
SetReadOnly(line, CHECKED, true);
|
|
|
|
SetReadOnly(line, DELETE, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
|
|
|
SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
|
|
|
SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
|
|
|
|
|
|
|
Layout();
|
|
|
|
SetMinSize(GetMinSize());
|
|
|
|
}
|