00001 #include <QDebug>
00002 #include "dataaccount.h"
00003 #include "datahash.h"
00004 #include "datadefinitions.h"
00005
00006 DataBasicAccount::DataBasicAccount()
00007 {
00008 }
00009
00010 bool DataBasicAccount::loadDataNode(const QDomNode data)
00011 {
00012 bool ok;
00013 nameValue = data.toElement().attribute("name");
00014 accountNumberValue = data.toElement().attribute("number").toInt(&ok);
00015 if(!ok)
00016 {
00017
00018 qDebug() << "Error loading XML: Couldn't convert number of account!";
00019 return false;
00020 }
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 return true;
00031 }
00032
00033 QDomElement DataBasicAccount::saveDataNode(QDomDocument *xml, bool displayName)
00034 {
00035 QDomElement account = xml->createElement("account");
00036
00037 QString normalized = normalizedAccountNumber(accountNumberValue);
00038 account.setAttribute("number", normalized);
00039
00040
00041 if(displayName)
00042 {
00043 account.setAttribute("name", nameValue);
00044 }
00045 return account;
00046 }
00047
00048 void DataBasicAccount::hash(unsigned int &startValue)
00049 {
00050
00051
00052 DataHash::hash(&accountNumberValue, sizeof(accountNumberValue), startValue);
00053 }
00054
00055
00056
00057 bool DataAccount::loadDataNode(const QDomNode data)
00058 {
00059 bool ok;
00060
00061 if(DataBasicAccount::loadDataNode(data))
00062 {
00063
00064 date = data.toElement().attribute("date");
00065 debitValue = data.toElement().attribute("debit").toDouble(&ok);
00066 if(ok)
00067 {
00068 creditValue = data.toElement().attribute("credit").toDouble(&ok);
00069 }
00070
00071 if(!ok)
00072 {
00073 qDebug() << "Error loading XML: Couldn't convert opening stock of account!";
00074 }
00075 return ok;
00076 }
00077 else
00078 {
00079 return false;
00080 }
00081 }
00082
00083 QDomElement DataAccount::saveDataNode(QDomDocument *xml)
00084 {
00085
00086
00087 QDomElement account = DataBasicAccount::saveDataNode(xml, false);
00088
00089 account.setAttribute("date", date);
00090 account.setAttribute("debit", QString::number(debitValue, 'f', 2));
00091 account.setAttribute("credit", QString::number(creditValue, 'f', 2));
00092
00093 return account;
00094 }
00095
00096 void DataAccount::hash(unsigned int &startValue)
00097 {
00098
00099
00100 DataBasicAccount::hash(startValue);
00101 DataHash::hash(&debitValue, sizeof(debitValue), startValue);
00102 DataHash::hash(&creditValue, sizeof(creditValue), startValue);
00103 }
00104
00105 DataAccount::DataAccount(): DataBasicAccount()
00106 {
00107 }
00108
00109
00110
00111 void DataTableAccount::hash(unsigned int &startValue)
00112 {
00113 DataBasicAccount::hash(startValue);
00114 qDebug() << "Warning: You can't hash a table account (Kontenplan-Konto)";
00115 }
00116
00117 bool DataTableAccount::loadDataNode(const QDomNode data)
00118 {
00119 if(DataBasicAccount::loadDataNode(data))
00120 {
00121 accountDescription = data.toElement().attribute("description");
00122 return true;
00123 }
00124 else
00125 {
00126 return false;
00127 }
00128 }
00129
00130 QDomElement DataTableAccount::saveDataNode(QDomDocument *xml)
00131 {
00132 QDomElement account = DataBasicAccount::saveDataNode(xml);
00133 account.setAttribute("description", accountDescription);
00134 return account;
00135 }
00136
00137 DataTableAccount::DataTableAccount(): DataBasicAccount()
00138 {
00139 }