Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

aqfinance / src / fox / lib / modules / accounts / fm_accaccpage.cpp @ 242027ca

History | View | Annotate | Download (20.1 KB)

1
/****************************************************************************
2
 * This file is part of the project AqFinance.
3
 * AqFinance (c) by 2009 Martin Preuss, all rights reserved.
4
 *
5
 * The license for this file can be found in the file COPYING which you
6
 * should have received along with this file.
7
 ****************************************************************************/
8

    
9

    
10
#ifdef HAVE_CONFIG_H
11
# include <config.h>
12
#endif
13

    
14

    
15
#include "fm_accaccpage.hpp"
16
#include "fm_accpage.hpp"
17
#include "ff_accounttree.hpp"
18
#include "ff_app.hpp"
19
#include "ff_editaccount.hpp"
20
#include "ff_selectbankacc.hpp"
21

    
22
#include <gwen-gui-fox16/theme.h>
23

    
24
#include <gwenhywfar/debug.h>
25
#include <gwenhywfar/i18n.h>
26

    
27

    
28
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
29

    
30

    
31

    
32
FXDEFMAP(FM_AccountAccPage) FM_AccountAccPageMap[]= {
33
  FXMAPFUNC(SEL_COMMAND, FM_AccountAccPage::ID_BUTTON_ADDACCOUNT,
34
            FM_AccountAccPage::onCmdAddAccount),
35
  FXMAPFUNC(SEL_COMMAND, FM_AccountAccPage::ID_BUTTON_EDITACCOUNT,
36
            FM_AccountAccPage::onCmdEditAccount),
37
  FXMAPFUNC(SEL_COMMAND, FM_AccountAccPage::ID_BUTTON_DELACCOUNT,
38
            FM_AccountAccPage::onCmdDelAccount),
39
  FXMAPFUNC(SEL_COMMAND, FM_AccountAccPage::ID_BUTTON_WRITEXML,
40
            FM_AccountAccPage::onCmdWriteXml),
41

    
42
  FXMAPFUNC(SEL_COMMAND, FM_AccountAccPage::ID_BUTTON_RECALC,
43
            FM_AccountAccPage::onCmdRecalc),
44

    
45
  FXMAPFUNC(SEL_CHANGED, FM_AccountAccPage::ID_ACCOUNT_TREE,
46
            FM_AccountAccPage::onTreeChanged),
47
  FXMAPFUNC(SEL_DOUBLECLICKED, FM_AccountAccPage::ID_ACCOUNT_TREE,
48
            FM_AccountAccPage::onTreeCommand),
49
  FXMAPFUNC(SEL_RIGHTBUTTONPRESS, FM_AccountAccPage::ID_ACCOUNT_TREE,
50
            FM_AccountAccPage::onTreeRightBtnPress),
51
  FXMAPFUNC(SEL_CHANGED, FM_AccountAccPage::ID_MATCHER,
52
            FM_AccountAccPage::onChgMatcher),
53

    
54
  FXMAPFUNC(SEL_COMMAND, FM_AccountAccPage::ID_ASSIGN_BANK_ACCOUNT,
55
            FM_AccountAccPage::onCmdAssignBankingAccount),
56
};
57

    
58

    
59

    
60
FXIMPLEMENT(FM_AccountAccPage, FF_ModTabPage, FM_AccountAccPageMap, ARRAYNUMBER(FM_AccountAccPageMap))
61

    
62

    
63

    
64

    
65

    
66

    
67
FM_AccountAccPage::FM_AccountAccPage(const FXString &pageId,
68
                                     FM_AccountPage *mainPage,
69
                                     FXuint opts,
70
                                     FXint x, FXint y, FXint w, FXint h)
71
:FF_ModTabPage(pageId, mainPage, opts, x, y, w, h)
72
, m_mainPage(mainPage)
73
, m_accountTree(NULL)
74
, m_accounts(NULL)
75
{
76
  FXVerticalFrame *vf;
77
  FXHorizontalFrame *hf;
78

    
79
  flags|=FLAG_ENABLED|FLAG_SHOWN;
80

    
81
  vf=new FXVerticalFrame(this, LAYOUT_FILL_X|LAYOUT_FILL_Y);
82
  hf=new FXHorizontalFrame(vf, LAYOUT_FILL_X);
83
  new FXLabel(hf, I18N("Filter"), NULL, LABEL_NORMAL | JUSTIFY_LEFT);
84
  m_matcher=new FXTextField(hf, 64, this, ID_MATCHER, TEXTFIELD_NORMAL);
85

    
86
  hf=new FXHorizontalFrame(vf, LAYOUT_FILL_X | LAYOUT_FILL_Y);
87
  m_accountTree=new FF_AccountTree(hf, this, ID_ACCOUNT_TREE,
88
                                   LAYOUT_SIDE_LEFT |
89
                                   LAYOUT_FILL_X | LAYOUT_FILL_Y |
90
                                   FOLDINGLIST_EXTENDEDSELECT |
91
                                   FOLDINGLIST_SHOWS_LINES |
92
                                   FOLDINGLIST_SHOWS_BOXES |
93
                                   FOLDINGLIST_ROOT_BOXES |
94
                                   FRAME_SUNKEN|FRAME_THICK);
95
}
96

    
97

    
98

    
99

    
100
FM_AccountAccPage::FM_AccountAccPage()
101
:FF_ModTabPage()
102
, m_mainPage(NULL)
103
, m_accountTree(NULL)
104
, m_accounts(NULL)
105
{
106
}
107

    
108

    
109

    
110
FM_AccountAccPage::~FM_AccountAccPage()
111
{
112
  AE_Account_Tree_free(m_accounts);
113
}
114

    
115

    
116

    
117
void FM_AccountAccPage::init(GWEN_DB_NODE *db)
118
{
119
  GWEN_DB_NODE *dbT;
120

    
121
  DBG_INFO(0, "Init");
122
  dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "accountPage");
123
  if (dbT) {
124
    int i;
125
    int sortByColumn;
126
    int sortUp;
127

    
128
    sortByColumn=GWEN_DB_GetIntValue(dbT, "sortByColumn", 0, -1);
129
    sortUp=GWEN_DB_GetIntValue(dbT, "sortUp", 0, 0);
130

    
131
    for (i=0; i<m_accountTree->getNumHeaders(); i++) {
132
      int j=GWEN_DB_GetIntValue(dbT, "columns", i, m_accountTree->getHeaderSize(i));
133
      m_accountTree->setHeaderSize(i, j);
134
      if (i==sortByColumn) {
135
        if (sortUp)
136
          m_accountTree->setHeaderArrowDir(i, TRUE);
137
        else
138
          m_accountTree->setHeaderArrowDir(i, FALSE);
139
      }
140
    }
141
  }
142
}
143

    
144

    
145

    
146
void FM_AccountAccPage::fini(GWEN_DB_NODE *db)
147
{
148
  GWEN_DB_NODE *dbT;
149
  int i;
150

    
151
  DBG_INFO(0, "Fini");
152
  dbT=GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_OVERWRITE_GROUPS, "accountPage");
153
  GWEN_DB_SetIntValue(dbT, GWEN_DB_FLAGS_OVERWRITE_VARS, "sortByColumn", -1);
154
  for (i=0; i<m_accountTree->getNumHeaders(); i++) {
155
    FXbool b;
156

    
157
    GWEN_DB_SetIntValue(dbT, GWEN_DB_FLAGS_DEFAULT, "columns",
158
                        m_accountTree->getHeaderSize(i));
159
    b=m_accountTree->getHeaderArrowDir(i);
160
    if (b!=MAYBE) {
161
      GWEN_DB_SetIntValue(dbT, GWEN_DB_FLAGS_OVERWRITE_VARS, "sortByColumn", i);
162
      if (b==TRUE)
163
        GWEN_DB_SetIntValue(dbT, GWEN_DB_FLAGS_OVERWRITE_VARS, "sortUp", 1);
164
      else
165
        GWEN_DB_SetIntValue(dbT, GWEN_DB_FLAGS_OVERWRITE_VARS, "sortUp", 0);
166
    }
167
  }
168
}
169

    
170

    
171

    
172
void FM_AccountAccPage::dump(int indent)
173
{
174
  int i;
175

    
176
  for (i=0; i<indent; i++)
177
    fprintf(stderr, " ");
178
  fprintf(stderr, "FM_AccountView: %d/%d %d/%d (%d %d)\n",
179
          getX(),
180
          getY(),
181
          getWidth(),
182
          getHeight(),
183
          getDefaultWidth(),
184
          getDefaultHeight());
185

    
186
  m_accountTree->dump(indent+2);
187
}
188

    
189

    
190

    
191
long FM_AccountAccPage::onCmdAddAccount(FXObject *, FXSelector, void *)
192
{
193
  FF_App *app;
194
  AE_BOOK *b;
195

    
196
  app=dynamic_cast<FF_App *>(getApp());
197
  b=app->getBook();
198
  if (b) {
199
    AE_ACCOUNT *pacc;
200
    AE_ACCOUNT *acc;
201

    
202
    acc=AE_Account_new();
203
    pacc=m_accountTree->getCurrentAccount();
204
    if (pacc)
205
      AE_Account_SetParentId(acc, AE_Account_GetId(pacc));
206
    else
207
      AE_Account_SetParentId(acc, 0);
208
    if (FF_EditAccount::editAccount(app, this, I18N("Add Account"), acc)) {
209
      int rv;
210

    
211
      rv=AE_Book_AddAccount(b, AE_Book_TableType_Account, acc, 1);
212
      if (rv<0) {
213
        DBG_ERROR(0, "Unable to add account (%d)", rv);
214
      }
215
      else {
216
        AE_RULE_LIST *rules;
217

    
218
        rules=AE_Account_GetRules(acc);
219
        if (rules) {
220
          AE_RULE *r;
221

    
222
          r=AE_Rule_List_First(rules);
223
          while (r) {
224
            /* rule is new, create */
225
            AE_Rule_SetOwnerType(r, AE_Book_TableType_Account);
226
            AE_Rule_SetOwnerId(r, AE_Account_GetId(acc));
227
            rv=AE_Book_AddRule(b, AE_Book_TableType_Rule, r, 1);
228
            if (rv<0) {
229
              DBG_ERROR(0, "here (%d)", rv);
230
            }
231
            r=AE_Rule_List_Next(r);
232
          }
233
        }
234
      }
235
      app->signalDbReload(AE_Book_TableType_Account);
236
    }
237
    AE_Account_free(acc);
238
  }
239

    
240
  return 1;
241
}
242

    
243

    
244

    
245
long FM_AccountAccPage::onCmdEditAccount(FXObject *, FXSelector, void *)
246
{
247
  AE_ACCOUNT *acc;
248

    
249
  acc=m_accountTree->getCurrentAccount();
250
  if (acc) {
251
    FF_App *app;
252
    AE_BOOK *b;
253
    app=dynamic_cast<FF_App *>(getApp());
254
    b=app->getBook();
255
    if (b) {
256
      if (FF_EditAccount::editAccount(app, this, I18N("Edit Account"), acc)) {
257
        int rv;
258

    
259
        rv=AE_Book_WriteAccount(b, AE_Book_TableType_Account, acc, 1);
260
        if (rv<0) {
261
          DBG_ERROR(0, "Unable to write account (%d)", rv);
262
        }
263
        else {
264
          AE_RULE_LIST *rules;
265

    
266
          rules=AE_Account_GetRules(acc);
267
          if (rules) {
268
            AE_RULE *r;
269

    
270
            r=AE_Rule_List_First(rules);
271
            while (r) {
272
              if (AE_Rule_GetId(r)) {
273
                /* rule exists, check whether is has been deleted or modified */
274
                if (AE_Rule_GetRuntimeFlags(r) & AE_RULE_RTFLAGS_DELETED) {
275
                  rv=AE_Book_DeleteRule(b, AE_Book_TableType_Rule, r, 1);
276
                  if (rv<0) {
277
                    DBG_ERROR(0, "here (%d)", rv);
278
                  }
279
                }
280
                else if (AE_Rule_GetRuntimeFlags(r) & AE_RULE_RTFLAGS_MODIFIED) {
281
                  rv=AE_Book_WriteRule(b, AE_Book_TableType_Rule, r, 1);
282
                  if (rv<0) {
283
                    DBG_ERROR(0, "here (%d)", rv);
284
                  }
285
                }
286
              }
287
              else {
288
                /* rule is new, create */
289
                AE_Rule_SetOwnerType(r, AE_Book_TableType_Account);
290
                AE_Rule_SetOwnerId(r, AE_Account_GetId(acc));
291
                rv=AE_Book_AddRule(b, AE_Book_TableType_Rule, r, 1);
292
                if (rv<0) {
293
                  DBG_ERROR(0, "here (%d)", rv);
294
                }
295
              }
296
              r=AE_Rule_List_Next(r);
297
            }
298
          }
299
        }
300
        app->signalDbReload(AE_Book_TableType_Account);
301
      }
302
    }
303
  }
304
  return 1;
305
}
306

    
307

    
308

    
309
long FM_AccountAccPage::onCmdDelAccount(FXObject *, FXSelector, void *)
310
{
311
  AE_ACCOUNT *acc;
312

    
313
  acc=m_accountTree->getCurrentAccount();
314
  if (acc) {
315
    FF_App *app;
316
    AE_BOOK *b;
317
    app=dynamic_cast<FF_App *>(getApp());
318
    b=app->getBook();
319
    if (b) {
320
      FXuint res;
321

    
322
      res=FXMessageBox::question(this, MBOX_YES_NO,
323
                                 I18N("Delete Account"),
324
                                 "%s",
325
                                 I18N("Are you sure you want to delete the selected "
326
                                      "account?"));
327
      if (res!=MBOX_CLICKED_YES) {
328
        DBG_ERROR(0, "Aborted");
329
      }
330
      else {
331
        app->deleteAccount(AE_Account_GetId(acc));
332
        app->signalDbReload(AE_Book_TableType_Account);
333
      }
334
    }
335
  }
336
  return 1;
337
}
338

    
339

    
340

    
341
long FM_AccountAccPage::onCmdWriteXml(FXObject *, FXSelector, void *)
342
{
343
  AE_ACCOUNT *acc;
344

    
345
  acc=m_accountTree->getCurrentAccount();
346
  if (acc) {
347
    FF_App *app;
348
    AE_BOOK *b;
349
    AQDB_ID aid;
350

    
351
    aid=AE_Account_GetId(acc);
352
    app=dynamic_cast<FF_App *>(getApp());
353
    b=app->getBook();
354
    if (b) {
355
      FXString fname;
356

    
357
      fname=FXFileDialog::getSaveFilename(this,
358
                                          I18N("Select Name of XML File"),
359
                                          "",
360
                                          I18N("All Files (*)\nXML Files (*.xml)"));
361
      if (!fname.empty()) {
362
        AE_ACCOUNT_TREE *at;
363
        int rv;
364

    
365
        at=AE_Account_Tree_new();
366
        rv=AE_Book_ReadAccountTree(b, AE_Book_TableType_Account, at);
367
        if (rv<0) {
368
          DBG_ERROR(0, "here (%d)", rv);
369
          AE_Account_Tree_free(at);
370
          FXMessageBox::error(this, MBOX_OK,
371
                              I18N("Database Error"),
372
                              I18N("Error reading account tree from database (%d)"), rv);
373
          return 1;
374
        }
375

    
376
        acc=AE_Account_Tree_GetById(at, aid);
377
        if (acc) {
378
          GWEN_XMLNODE *root;
379
          GWEN_XMLNODE *nh;
380

    
381
          root=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "accounts");
382
          nh=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "xml");
383
          GWEN_XMLNode_AddHeader(root, nh);
384

    
385
          AE_Book_WriteAccountTreeXml(b, at, acc, root);
386

    
387
          rv=GWEN_XMLNode_WriteFile(root, fname.text(),
388
                                    GWEN_XML_FLAGS_DEFAULT |
389
                                    GWEN_XML_FLAGS_SIMPLE |
390
                                    GWEN_XML_FLAGS_HANDLE_HEADERS);
391
          if (rv<0) {
392
            GWEN_XMLNode_free(root);
393
            AE_Account_Tree_free(at);
394
            FXMessageBox::error(this, MBOX_OK,
395
                                I18N("File Error"),
396
                                I18N("Error writing XML file: %d"), rv);
397
            return 1;
398
          }
399
          GWEN_XMLNode_free(root);
400
        }
401
        else {
402
          FXMessageBox::error(this, MBOX_OK,
403
                              I18N("Database Error"),
404
                              "%s",
405
                              I18N("Account not found in database. "
406
                                   "Maybe the account was deleted by another process?"));
407
        }
408
        AE_Account_Tree_free(at);
409
      }
410
    }
411
  }
412

    
413
  return 1;
414
}
415

    
416

    
417

    
418
long FM_AccountAccPage::onCmdRecalc(FXObject *, FXSelector, void *)
419
{
420
  FF_App *app;
421
  AE_BOOK *b;
422

    
423
  app=dynamic_cast<FF_App *>(getApp());
424
  b=app->getBook();
425
  if (b) {
426
    AE_ACCOUNT_TREE *at;
427
    int rv;
428

    
429
    at=AE_Account_Tree_new();
430
    rv=AE_Book_ReadAccountTree(b, AE_Book_TableType_Account, at);
431
    if (rv<0) {
432
      DBG_ERROR(0, "here (%d)", rv);
433
      FXMessageBox::error(this, MBOX_OK,
434
                          I18N("Database Error"),
435
                          I18N("Error reading accounts from database (%d)"),
436
                          rv);
437
      AE_Account_Tree_free(at);
438
    }
439
    else {
440
      rv=AE_Book_ReadAccountTreeBalances(b, at);
441
      if (rv<0) {
442
        DBG_ERROR(0, "here (%d)", rv);
443
        FXMessageBox::error(this, MBOX_OK,
444
                            I18N("Database Error"),
445
                            I18N("Error reading account balances from database (%d)"),
446
                            rv);
447
        AE_Account_Tree_free(at);
448
      }
449
      else {
450
        AE_Account_Tree_ClearBalances(at);
451
        rv=AE_Book_CalcAccountTreeBalances(b, at);
452
        if (rv<0) {
453
          DBG_ERROR(0, "Error calculating account balances");
454
          FXMessageBox::error(this, MBOX_OK,
455
                              I18N("Database Error"),
456
                              I18N("Error calculating accounts balances (%d)"),
457
                              rv);
458
        }
459
        else {
460
          rv=AE_Book_WriteAccountTreeBalances(b, at, 1);
461
          if (rv<0) {
462
            FXMessageBox::error(this, MBOX_OK,
463
                                I18N("Database Error"),
464
                                I18N("Error writing account balances to database (%d)"),
465
                                rv);
466
          }
467
        }
468
        AE_Account_Tree_free(at);
469

    
470
        /* update account tree */
471
        dbReload(AE_Book_TableType_Account);
472
      }
473
    }
474
  }
475
  return 1;
476
}
477

    
478

    
479

    
480

    
481
long FM_AccountAccPage::onTreeChanged(FXObject *, FXSelector, void *ptr)
482
{
483
  return 1;
484
}
485

    
486

    
487

    
488
long FM_AccountAccPage::onTreeCommand(FXObject *, FXSelector, void *ptr)
489
{
490
  if (ptr) {
491
    FF_AccountTreeItem *item=dynamic_cast<FF_AccountTreeItem *>((FXFoldingItem *) ptr);
492
    if (item)
493
      m_mainPage->openAccountPage(item->getAccount());
494
  }
495

    
496
  return 1;
497
}
498

    
499

    
500

    
501
long FM_AccountAccPage::onChgMatcher(FXObject *, FXSelector, void *ptr)
502
{
503
  rebuild();
504
  return 1;
505
}
506

    
507

    
508

    
509
long FM_AccountAccPage::onTreeRightBtnPress(FXObject *, FXSelector, void *ptr)
510
{
511
  FXEvent *event=(FXEvent *)ptr;
512
  AE_ACCOUNT *acc;
513

    
514
  acc=m_accountTree->getCurrentAccount();
515
  if (!event->moved) {
516
    FXMenuPane pmenu(this);
517
    FXMenuCommand *c;
518

    
519
    new FXMenuCommand(&pmenu, I18N("Add Account"), NULL, this, ID_BUTTON_ADDACCOUNT);
520

    
521
    c=new FXMenuCommand(&pmenu, I18N("Edit Account"), NULL, this, ID_BUTTON_EDITACCOUNT);
522
    if (!acc)
523
      c->disable();
524

    
525
    c=new FXMenuCommand(&pmenu, I18N("Delete Account"), NULL, this, ID_BUTTON_DELACCOUNT);
526
    if (!acc)
527
      c->disable();
528

    
529
    new FXMenuSeparator(&pmenu);
530
    c=new FXMenuCommand(&pmenu, I18N("Export Account Branch to XML"), NULL, this, ID_BUTTON_WRITEXML);
531
    if (!acc)
532
      c->disable();
533

    
534
    new FXMenuSeparator(&pmenu);
535
    c=new FXMenuCommand(&pmenu, I18N("Assign Online Account"), NULL,
536
                        this, ID_ASSIGN_BANK_ACCOUNT);
537
    if (!acc)
538
      c->disable();
539

    
540
    new FXMenuSeparator(&pmenu);
541
    c=new FXMenuCommand(&pmenu, I18N("Recalculate"), NULL, this, ID_BUTTON_RECALC);
542

    
543
    new FXMenuSeparator(&pmenu);
544
    new FXMenuCommand(&pmenu, I18N("Back"), NULL, &pmenu, ID_UNPOST);
545

    
546
    pmenu.create();
547
    pmenu.popup(NULL, event->root_x, event->root_y);
548
    getApp()->runModalWhileShown(&pmenu);
549
  }
550

    
551
  return 1;
552
}
553

    
554

    
555

    
556
long FM_AccountAccPage::onCmdAssignBankingAccount(FXObject *, FXSelector, void *ptr)
557
{
558
  AE_ACCOUNT *acc;
559

    
560
  acc=m_accountTree->getCurrentAccount();
561
  if (acc) {
562
    FF_App *app;
563
    AE_BOOK *b;
564
    app=dynamic_cast<FF_App *>(getApp());
565
    b=app->getBook();
566
    if (b) {
567
      AQDB_ID id;
568

    
569
      id=AE_Account_GetBankAccountId(acc);
570
      if (FF_SelectBankAccount::selectAccount(app,
571
                                              this,
572
                                              I18N("Assign Bank Account"),
573
                                              NULL,
574
                                              id)) {
575
        int rv;
576

    
577
        AE_Account_SetBankAccountId(acc, id);
578
        rv=AE_Book_WriteAccount(b, AE_Book_TableType_Account, acc, 1);
579
        if (rv<0) {
580
          DBG_ERROR(0, "Unable to add bank account (%d)", rv);
581
        }
582
        app->signalDbReload(AE_Book_TableType_Account);
583
      }
584
    }
585
  }
586
  return 1;
587
}
588

    
589

    
590

    
591
void FM_AccountAccPage::dbOpened(AE_BOOK *bk)
592
{
593
  dbReload(AE_Book_TableType_None);
594
}
595

    
596

    
597

    
598
void FM_AccountAccPage::dbClosing()
599
{
600
  m_accountTree->clearItems();
601
}
602

    
603

    
604

    
605
void FM_AccountAccPage::dbClosed()
606
{
607
}
608

    
609

    
610

    
611
void FM_AccountAccPage::rebuild()
612
{
613
  FF_App *app;
614

    
615
  app=dynamic_cast<FF_App *>(getApp());
616
  if (m_accounts) {
617
    AE_ACCOUNT *acc;
618
    AQDB_ID currentAccId=0;
619

    
620
    acc=m_accountTree->getCurrentAccount();
621
    if (acc)
622
      currentAccId=AE_Account_GetId(acc);
623

    
624
    m_accountTree->clearItems();
625
    m_accountTree->reload();
626

    
627
    FXString str=m_matcher->getText().simplify();
628

    
629
    /* select matching accounts */
630
    AE_Account_Tree_SelectMatching(m_accounts, str.text());
631
    m_accountTree->addSelectedAccounts(m_accounts, 0);
632

    
633
    /* expand and sort */
634
    m_accountTree->expandItems();
635
    m_accountTree->sort();
636

    
637
    if (currentAccId!=0) {
638
      FF_AccountTreeItem *item=m_accountTree->findAccountItem(currentAccId);
639
      if (item) {
640
        item->setSelected(true);
641
        m_accountTree->makeItemVisible(item);
642
        m_accountTree->setCurrentItem(item);
643
      }
644
    }
645

    
646
    if (1) {
647
      FXFoldingItem *fi;
648

    
649
      /* colorize */
650
      fi=m_accountTree->getFirstItem();
651
      while (fi) {
652
        FF_AccountTreeItem *item;
653

    
654
        item=dynamic_cast<FF_AccountTreeItem *>(fi);
655
        if (item) {
656
          AE_ACCOUNT *a;
657

    
658
          a=item->getAccount();
659
          if (a) {
660
            AE_ACCOUNT_GROUP gr;
661

    
662
            gr=AE_AccountType_GetGroup(AE_Account_GetType(a));
663
            switch (gr) {
664
            case AE_AccountGroup_Asset:
665
              item->setBackColor(app->getAccountColorAsset());
666
              item->setTextColor(m_accountTree->getTextColor());
667
              item->setUseOwnColors(TRUE);
668
              m_accountTree->updateItem(item);
669
              break;
670
            case AE_AccountGroup_Liability:
671
              item->setBackColor(app->getAccountColorLiability());
672
              item->setTextColor(m_accountTree->getTextColor());
673
              item->setUseOwnColors(TRUE);
674
              m_accountTree->updateItem(item);
675
              break;
676
            case AE_AccountGroup_Equity:
677
              item->setBackColor(app->getAccountColorEquity());
678
              item->setTextColor(m_accountTree->getTextColor());
679
              item->setUseOwnColors(TRUE);
680
              m_accountTree->updateItem(item);
681
              break;
682
            case AE_AccountGroup_Income:
683
              item->setBackColor(app->getAccountColorIncome());
684
              item->setTextColor(m_accountTree->getTextColor());
685
              item->setUseOwnColors(TRUE);
686
              m_accountTree->updateItem(item);
687
              break;
688
            case AE_AccountGroup_Expense:
689
              item->setBackColor(app->getAccountColorExpense());
690
              item->setTextColor(m_accountTree->getTextColor());
691
              item->setUseOwnColors(TRUE);
692
              m_accountTree->updateItem(item);
693
              break;
694
            default:
695
              break;
696
            }
697
          }
698
        }
699

    
700
        fi=fi->getBelow();
701
      }
702
    }
703
  }
704
}
705

    
706

    
707

    
708
void FM_AccountAccPage::dbReload(AE_BOOK_TABLE_TYPE tt)
709
{
710
  if (tt==AE_Book_TableType_Account ||
711
      tt==AE_Book_TableType_Split ||
712
      tt==AE_Book_TableType_AccountBalance ||
713
      tt==AE_Book_TableType_None) {
714
    FF_App *app;
715
    AE_BOOK *b;
716

    
717
    app=dynamic_cast<FF_App *>(getApp());
718
    b=app->getBook();
719
    if (b) {
720
      int rv;
721

    
722
      if (m_accounts)
723
        AE_Account_Tree_Clear(m_accounts);
724
      else
725
        m_accounts=AE_Account_Tree_new();
726
      rv=AE_Book_ReadAccountTree(b, AE_Book_TableType_Account, m_accounts);
727
      if (rv<0) {
728
        DBG_ERROR(0, "here (%d)", rv);
729
      }
730
      else {
731
        AE_Account_Tree_ClearBranchBalances(m_accounts);
732

    
733
        /* read account balances */
734
        rv=AE_Book_ReadAccountTreeBalances(b, m_accounts);
735
        if (rv<0) {
736
          DBG_ERROR(0, "here (%d)", rv);
737
        }
738

    
739
        /* calculate branch balances */
740
        AE_Account_Tree_CalcBranchBalances(m_accounts);
741
      }
742
    }
743
    rebuild();
744
  }
745
}
746

    
747

    
748

    
749
void FM_AccountAccPage::aboutToSendJobs()
750
{
751
}
752

    
753

    
754

    
755
void FM_AccountAccPage::enter()
756
{
757
}
758

    
759

    
760

    
761
void FM_AccountAccPage::leave()
762
{
763
}
764

    
765

    
766

    
767
void FM_AccountAccPage::reset()
768
{
769
}
770

    
771

    
772