1 /*******************************************************
2  Copyright (C) 2006 Madhan Kanagavel
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  ********************************************************/
18 
19 
20 #include "mmOption.h"
21 #include "import_export/univcsvdialog.h"
22 #include "constants.h"
23 #include "singleton.h"
24 #include "model/Model_Infotable.h"
25 #include "model/Model_Setting.h"
26 #include "model/Model_Account.h"
27 
28 //----------------------------------------------------------------------------
mmOptions()29 mmOptions::mmOptions()
30 :   dateFormat_(mmex::DEFDATEFORMAT)
31     , language_("english")
32     , databaseUpdated_(false)
33 {}
34 
35 //----------------------------------------------------------------------------
instance()36 mmOptions& mmOptions::instance()
37 {
38     return Singleton<mmOptions>::instance();
39 }
40 
41 //----------------------------------------------------------------------------
LoadInfotableOptions()42 void mmOptions::LoadInfotableOptions()
43 {
44     dateFormat_ = Model_Infotable::instance().DateFormat();
45     userNameString_ = Model_Infotable::instance().GetStringInfo("USERNAME", "");
46 
47     financialYearStartDayString_   = Model_Infotable::instance().GetStringInfo("FINANCIAL_YEAR_START_DAY", "1");
48     financialYearStartMonthString_ = Model_Infotable::instance().GetStringInfo("FINANCIAL_YEAR_START_MONTH", "7");
49 }
50 
51 //----------------------------------------------------------------------------
mmIniOptions()52 mmIniOptions::mmIniOptions()
53 : html_font_size_(3)
54 , budgetFinancialYears_(false)
55 , budgetIncludeTransfers_(false)
56 , budgetSetupWithoutSummaries_(false)
57 , budgetReportWithSummaries_(true)
58 , ignoreFutureTransactions_(false)
59 , transPayeeSelectionNone_(0)
60 , transCategorySelectionNone_(0)
61 , transStatusReconciled_(0)
62 , transDateDefault_(0)
63 {}
64 
instance()65 mmIniOptions& mmIniOptions::instance()
66 {
67     return Singleton<mmIniOptions>::instance();
68 }
69 
loadOptions()70 void mmIniOptions::loadOptions()
71 {
72     html_font_size_   = Model_Setting::instance().HtmlFontSize();
73 
74     budgetFinancialYears_           = Model_Setting::instance().BudgetFinancialYears();
75     budgetIncludeTransfers_         = Model_Setting::instance().BudgetIncludeTransfers();
76     budgetSetupWithoutSummaries_    = Model_Setting::instance().BudgetSetupWithoutSummary();
77     budgetReportWithSummaries_      = Model_Setting::instance().BudgetSummaryWithoutCategory();
78     ignoreFutureTransactions_       = Model_Setting::instance().IgnoreFutureTransactions();
79 
80     // Read the preference as a string and convert to int
81     transPayeeSelectionNone_ = Model_Setting::instance().GetIntSetting("TRANSACTION_PAYEE_NONE", 0);
82 
83     // For the category selection, default behavior should remain that the last category used for the payee is selected.
84     //  This is item 1 (0-indexed) in the list.
85     transCategorySelectionNone_ = Model_Setting::instance().GetIntSetting("TRANSACTION_CATEGORY_NONE", 1);
86     transStatusReconciled_      = Model_Setting::instance().GetIntSetting("TRANSACTION_STATUS_RECONCILED", 0);
87     transDateDefault_           = Model_Setting::instance().GetIntSetting("TRANSACTION_DATE_DEFAULT", 0);
88 }
89 
account_image_id(int account_id)90 int mmIniOptions::account_image_id(int account_id)
91 {
92     int selectedImage = Model_Infotable::instance().GetIntInfo(wxString::Format("ACC_IMAGE_ID_%i", account_id), 99);
93     //TODO: What size of the images spool?
94     if (selectedImage > 0 && selectedImage < 99)
95         return selectedImage;
96 
97     selectedImage = 9;
98     int t = 0, s = 0;
99     wxString acctStatus = "Open";
100     Model_Account::TYPE acctType = Model_Account::CHECKING;
101     bool favorite = true;
102 
103     Model_Account::Data* account = Model_Account::instance().get(account_id);
104     if (account)
105     {
106         acctType = Model_Account::type(account);
107         acctStatus = account->STATUS;
108         favorite = Model_Account::FAVORITEACCT(account);
109     }
110 
111     if (acctStatus == "Closed")
112         s = 2;
113     else if (favorite)
114         s = 1;
115 
116     if (acctType == Model_Account::TERM)
117         t = 3;
118     else if (acctType == Model_Account::INVESTMENT)
119         t = 6;
120     else if (acctType == Model_Account::CREDIT_CARD)
121         t = 9;
122 
123     selectedImage += t + s;
124 
125     return selectedImage;
126 }
127 
128