eFinancialPlanner  V1.0 (proof of concept)
Personal Financial Planning based on Maslowian Portfolio Theory
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
currency.class.cpp
Go to the documentation of this file.
2 {
3  public:
4 
5  string entity;
6  string currency_name;
7  string currency_id;
8  //char symbol;
9 
10  string dropDown_currency(string defaultCurr = "EUR");
11  bool set_curr(string the_curr);
12  float to_curr(float amnt, string the_curr);
13  float conversion_factor(string from_curr, string to_curr);
14 };
15 
16 /*************************************
17  * dropDown_currency
18  *
19  * ***********************************/
20 string cls_currency::dropDown_currency(string defaultCurr)
21 {
22  string s;
23 
24  s = s + "<select required name=\"currency\">";
25  db.res = db.stmt->executeQuery("SELECT currency_id FROM " + oConfig.tbl_prefix + "_currencies;");
26  while (db.res->next())
27  {
28  s = s + "<option value=\"" + db.res->getString("currency_id") + "\"";
29  if (db.res->getString("currency_id") == defaultCurr) {s = s + " selected "; }
30  s = s + ">" + db.res->getString("currency_id") + "</option>";
31  }
32  s = s + "</select>";
33  return s;
34 }
35 
41 bool cls_currency::set_curr(string the_curr)
42 {
43  string s;
44  db_helper this_db;
45  //s = "SELECT COUNT(*) AS EXIST_NBR from " + oConfig.tbl_prefix + "_currencies WHERE currency_id = '" + the_curr + "';";
46  s = "SELECT currency_id FROM " + oConfig.tbl_prefix + "_currencies WHERE currency_id = '" + the_curr + "';";
47  this_db.res = this_db.stmt->executeQuery(s);
48  if(this_db.res->rowsCount() == 1)
49  {
50  this->currency_id = the_curr;
51  return true;
52  }
53  else
54  {
55  error_message = error_message + "<li>ERRNO3411</li>";
56  return false; //table not found ;-)
57  }
58  error_message = error_message + "<li>ERRNO3412</li>";
59  return false; //table not found ;-)
60 }
61 
67 inline float cls_currency::to_curr(float amnt, string to_curr)
68 {
69  if (to_curr == this->currency_id) { return amnt; }
70  db_helper this_db;
71  string s;
72 
74  s = "SELECT * FROM " + oConfig.tbl_prefix + "_currencies WHERE currency_id = '" + this->currency_id + "';";
75  this_db.res = this_db.stmt->executeQuery(s);
76  if (this_db.res->next())
77  {
78  amnt = amnt * atof(this_db.res->getString("eur_p_one").c_str());
79  }
80  else
81  {
82  error_message = error_message + "<li>ERRNO.C.1011: invalid start currency</li>";
83  return 0; //no currency
84  }
85 
87  if (to_curr != "EUR")
88  {
89  s = "SELECT * FROM " + oConfig.tbl_prefix + "_currencies WHERE currency_id = '" + to_curr + "';";
90  this_db.res = this_db.stmt->executeQuery(s);
91  if (this_db.res->next())
92  {
93  amnt = amnt * atof(this_db.res->getString("one_p_eur").c_str());
94  }
95  else
96  {
97  error_message = error_message + "<li>ERRNO.C.1010: invalid destiny currency in to_curr</li>";
98  return 0;
99  }
100  }
101 
103  return amnt;
104 }
105 
string currency_id
eg. EUR, USD, etc.
sql::ResultSet * res
sql::Statement * stmt
string error_message
global message variables
Definition: efp.cpp:132
string dropDown_currency(string defaultCurr="EUR")
const string tbl_prefix
tables start with "" + oConfig.tbl_prefix + "_" if the prefix is eg. "tbl" then we have "tbl_invesotr...
db_helper db
Definition: efp.cpp:183
bool set_curr(string the_curr)
string currency_name
float to_curr(float amnt, string the_curr)
config oConfig
mysql connection mysql connector from dev.mysql.com
Definition: efp.cpp:149
float conversion_factor(string from_curr, string to_curr)