00001 #include <QDomText>
00002 #include <QColor>
00003 #include <QDebug>
00004
00005 #include "costtypemodel.h"
00006 #include "../Calculations/costtypecalculation.h"
00007 #include "../Data/datadefinitions.h"
00008 #include "owncapitalcalculationmodel.h"
00009
00010 CostTypeModel::CostTypeModel(uint id, uint type, QString name, QObject *parent) : QAbstractTableModel(parent), AbstractModel(id, type, name)
00011 {
00012
00013 lastid = 0;
00014
00015
00016 revenues = 0;
00017
00018
00019 refreshSums();
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 }
00034
00035 void CostTypeModel::setOwnCapitalModel(QPointer<OwnCapitalCalculationModel> owncapital)
00036 {
00037 ownCapitalModel = owncapital;
00038 }
00039
00040 QDomElement CostTypeModel::documentNode()
00041 {
00042 QDomDocument doc;
00043
00044 QDomElement costtype = doc.createElement("CostType");
00045
00046 QDomElement rowid = doc.createElement("lastrowid");
00047 QDomText text = doc.createTextNode(QString::number(lastid));
00048 rowid.appendChild(text);
00049 costtype.appendChild(rowid);
00050
00051 QDomElement data = doc.createElement("data");
00052 costtype.appendChild(data);
00053
00054 for(int i = 0; i < entries.count(); i++)
00055 {
00056 if(!entries.value(i).value(CostTypeColumns::Type).startsWith("sum"))
00057 {
00058 QDomElement position = doc.createElement("position");
00059 position.setAttribute("name", entries.value(i).value(CostTypeColumns::PositionName));
00060 position.setAttribute("rowid", entries.value(i).value(CostTypeColumns::RowID));
00061 position.setAttribute("type", entries.value(i).value(CostTypeColumns::Type));
00062 position.setAttribute("associationid", entries.value(i).value(CostTypeColumns::AssociationID));
00063 position.setAttribute("costtype", entries.value(i).value(CostTypeColumns::CostType));
00064
00065 QDomElement editinformation = doc.createElement("edit");
00066 QDomText edit = doc.createTextNode(entries.value(i).value(CostTypeColumns::EditInformation));
00067 editinformation.appendChild(edit);
00068 position.appendChild(editinformation);
00069
00070 QDomElement table = doc.createElement("table");
00071
00072 QDomElement pal = doc.createElement("pal");
00073 QDomText paltext = doc.createTextNode(entries.value(i).value(CostTypeColumns::PalValue));
00074 pal.appendChild(paltext);
00075
00076 table.appendChild(pal);
00077
00078
00079 QDomElement transition = doc.createElement("transition");
00080 QDomText transitiontext = doc.createTextNode(entries.value(i).value(CostTypeColumns::TransitionValue));
00081 transition.appendChild(transitiontext);
00082
00083 table.appendChild(transition);
00084
00085
00086 QDomElement costs = doc.createElement("costs");
00087 QDomText coststext = doc.createTextNode(entries.value(i).value(CostTypeColumns::Costs));
00088 costs.appendChild(coststext);
00089
00090 table.appendChild(costs);
00091
00092 position.appendChild(table);
00093
00094 data.appendChild(position);
00095 }
00096 }
00097
00098 QDomElement file = doc.createElement("file");
00099 file.setAttribute("type", "costtype");
00100 file.setAttribute("name", fileName());
00101 file.setAttribute("fileid", fileId());
00102
00103 if(!ownCapitalModel.isNull())
00104 {
00105 costtype.appendChild(ownCapitalModel->dataNode());
00106 }
00107
00108 file.appendChild(costtype);
00109
00110 return file;
00111 }
00112
00113 bool CostTypeModel::loadDocument(const QDomElement file)
00114 {
00115
00116 QDomNode costtypes = file.firstChild();
00117 while(!costtypes.isNull())
00118 {
00119 QDomElement costtype = costtypes.toElement();
00120 if(costtype.tagName() == "CostType")
00121 {
00122 QDomNode elements = costtype.firstChild();
00123 while(!elements.isNull())
00124 {
00125 QDomElement element = elements.toElement();
00126 if(element.tagName() == "lastrowid")
00127 {
00128 QDomNode lastrowid = element.firstChild();
00129
00130 bool ok = true;
00131
00132
00133 lastid = lastrowid.nodeValue().toUInt(&ok);
00134 if(!ok)
00135 {
00136
00137 lastid = 0;
00138 }
00139 }
00140 else if(element.tagName() == "data")
00141 {
00142 QDomNode positions = element.firstChild();
00143 while(!positions.isNull())
00144 {
00145 QDomElement position = positions.toElement();
00146
00147 QString pal = "";
00148 QString transition = "";
00149 QString costs = "";
00150 QString editoptions = "";
00151
00152 if(position.tagName() == "position")
00153 {
00154 QDomNode tables = position.firstChild();
00155 while(!tables.isNull())
00156 {
00157 QDomElement table = tables.toElement();
00158
00159 if(table.tagName() == "table")
00160 {
00161 QDomNode values = table.firstChild();
00162 while(!values.isNull())
00163 {
00164 QDomElement value = values.toElement();
00165
00166 if(value.tagName() == "pal")
00167 {
00168 QDomNode palnode = value.firstChild();
00169
00170 pal = palnode.nodeValue();
00171 }
00172 else if(value.tagName() == "transition")
00173 {
00174 QDomNode transitionnode = value.firstChild();
00175
00176 transition = transitionnode.nodeValue();
00177 }
00178 else if(value.tagName() == "costs")
00179 {
00180 QDomNode costsnode = value.firstChild();
00181
00182 costs = costsnode.nodeValue();
00183 }
00184
00185 values = values.nextSibling();
00186 }
00187 }
00188 else if(table.tagName() == "edit")
00189 {
00190 QDomNode editnode = table.firstChild();
00191
00192 editoptions = editnode.nodeValue();
00193 }
00194
00195 tables = tables.nextSibling();
00196 }
00197
00198 addEditEntry(position.attribute("name", ""), pal, transition, costs, position.attribute("costtype", ""), position.attribute("type", "").toInt(), editoptions, position.attribute("rowid", "").toInt(), position.attribute("associationid", "").toInt());
00199 }
00200
00201 positions = positions.nextSibling();
00202 }
00203 }
00204 else if(element.tagName() == "owncapital")
00205 {
00206 emit sendingOwnCapitalNode(element);
00207 }
00208 elements = elements.nextSibling();
00209 }
00210 }
00211 costtypes = costtypes.nextSibling();
00212 }
00213 return true;
00214 }
00215
00216 int CostTypeModel::rowCount(const QModelIndex &parent) const
00217 {
00218 Q_UNUSED(parent);
00219 return entries.size();
00220 }
00221
00222 int CostTypeModel::columnCount(const QModelIndex &parent) const
00223 {
00224 Q_UNUSED(parent);
00225 return 9;
00226 }
00227
00228 QVariant CostTypeModel::data(const QModelIndex &index, int role) const
00229 {
00230 if(!index.isValid())
00231 {
00232 return QVariant();
00233 }
00234
00235 if(index.row() >= entries.size() || index.row() < 0)
00236 {
00237 return QVariant();
00238 }
00239 if(role == Qt::BackgroundRole)
00240 {
00241 if(index.row() == rowCount(QModelIndex()) -1)
00242 {
00243 double result = entries.value(index.row()).value(CostTypeColumns::Costs).toDouble();
00244 QColor c;
00245 if(result == 0)
00246 {
00247
00248 c.setNamedColor("#5CB3FF");
00249 return c;
00250 }
00251 else if(result < 0)
00252 {
00253
00254 if(revenues == 0)
00255 {
00256 c.setNamedColor("#FF0000");
00257 }
00258 else
00259 {
00260 double value = getCompleteSum();
00261 if(value > 0)
00262 {
00263 double res = 100 - revenues / value * 100;
00264 qDebug()<<"res: " << res;
00265
00266 if(res > 50)
00267 {
00268
00269 c.setNamedColor("#FF0000");
00270 }
00271 else if(res > 40)
00272 {
00273
00274 c.setNamedColor("#F62817");
00275 }
00276 else if(res > 30)
00277 {
00278
00279 c.setNamedColor("#F76541");
00280 }
00281 else if(res > 20)
00282 {
00283
00284 c.setNamedColor("#E56717");
00285 }
00286 else if(res > 10)
00287 {
00288
00289 c.setNamedColor("#F88017");
00290 }
00291 else
00292 {
00293
00294 c.setNamedColor("#FBB117");
00295 }
00296 }
00297 else
00298 {
00299 c.setNamedColor("#FBB117");
00300 }
00301 }
00302 return c;
00303 }
00304 else
00305 {
00306
00307 c.setNamedColor("#adff7b");
00308 return c;
00309 }
00310 }
00311 else if(index.row() == rowCount(QModelIndex()) - 2 || index.row() == rowCount(QModelIndex()) -3)
00312 {
00313
00314 QColor c;
00315 c.setNamedColor("#eaeaea");
00316 return c;
00317 }
00318 }
00319 if(role == Qt::DisplayRole)
00320 {
00321 QStringList pair = entries.value(index.row());
00322 if(index.column() >= 0 && index.column() <= 8)
00323 {
00324 return pair.value(index.column());
00325 }
00326 }
00327 return QVariant();
00328 }
00329
00330 QStringList CostTypeModel::data(const int row) const
00331 {
00332 return entries.value(row);
00333 }
00334
00335 QStringList CostTypeModel::dataFromRowId(const int row) const
00336 {
00337 for(int i = 0; i < entries.count(); i++)
00338 {
00339 if(entries.value(i).value(CostTypeColumns::RowID).toInt() == row)
00340 {
00341 return entries.value(i);
00342 }
00343 }
00344 return QStringList();
00345 }
00346
00347 int CostTypeModel::rowFromRowId(const int row) const
00348 {
00349 for(int i = 0; i < entries.count(); i++)
00350 {
00351 if(entries.value(i).value(CostTypeColumns::RowID).toInt() == row)
00352 {
00353 return i;
00354 }
00355 }
00356 return -1;
00357 }
00358
00359 QVariant CostTypeModel::headerData(int section, Qt::Orientation orientation, int role) const
00360 {
00361 if(role != Qt::DisplayRole)
00362 {
00363 return QVariant();
00364 }
00365
00366 if(orientation == Qt::Horizontal)
00367 {
00368 CostTypeColumns *columns = new CostTypeColumns;
00369
00370 switch (section)
00371 {
00372 case 0:
00373 return columns->columnNames(CostTypeColumns::PositionName);
00374 case 1:
00375 return columns->columnNames(CostTypeColumns::PalValue);
00376 case 2:
00377 return columns->columnNames(CostTypeColumns::TransitionValue);
00378 case 3:
00379 return columns->columnNames(CostTypeColumns::Costs);
00380 case 4:
00381 return columns->columnNames(CostTypeColumns::CostType);
00382 case 5:
00383 return columns->columnNames(CostTypeColumns::Type);
00384 case 6:
00385 return columns->columnNames(CostTypeColumns::EditInformation);
00386 case 7:
00387 return columns->columnNames(CostTypeColumns::RowID);
00388 case 8:
00389 return columns->columnNames(CostTypeColumns::AssociationID);
00390 default:
00391 return QVariant();
00392 }
00393 }
00394 return QVariant();
00395 }
00396
00397 bool CostTypeModel::insertRows(int position, int rows, const QModelIndex &index)
00398 {
00399 Q_UNUSED(index);
00400 beginInsertRows(QModelIndex(), position, position + rows - 1);
00401
00402 int columncount = 9;
00403 for (int row = 0; row < rows; row++)
00404 {
00405 QStringList pair;
00406 for(int i = 0; i < columncount; i++)
00407 {
00408 if(i == columncount - 2)
00409 {
00410 pair << QString::number(lastid++);
00411 }
00412 else
00413 {
00414 pair << "";
00415 }
00416 }
00417 entries.insert(position, pair);
00418 }
00419
00420 endInsertRows();
00421 return true;
00422 }
00423
00424 bool CostTypeModel::removeRows(int position, int rows, const QModelIndex &index)
00425 {
00426 Q_UNUSED(index);
00427
00428 for (int row = 0; row < rows; ++row)
00429 {
00430
00431 int rowid = (entries.value(position).value(7)).toInt();
00432 removeRowById(rowid);
00433 }
00434
00435 return true;
00436 }
00437
00438 void CostTypeModel::removeRowById(int rowid)
00439 {
00440 for(int i = 0; i < entries.count(); i++)
00441 {
00442 if(entries.value(i).value(CostTypeColumns::RowID).toInt() == rowid)
00443 {
00444 beginRemoveRows(QModelIndex(), i, i);
00445
00446 int associated = (entries.value(i).value(CostTypeColumns::AssociationID)).toInt();
00447 entries.removeAt(i);
00448
00449 endRemoveRows();
00450
00451 emit rowRemoved(rowid);
00452
00453
00454 if(associated == -1)
00455 {
00456 emit changedDataUpdateProxies();
00457
00458 return;
00459 }
00460 else
00461 {
00462 emit changedDataUpdateProxies();
00463
00464 removeRowById(associated);
00465 i=0;
00466 }
00467 }
00468 }
00469 }
00470
00471 double CostTypeModel::getCompleteSum() const
00472 {
00473 double sum = 0;
00474 for(int i = 0; i < entries.size(); i++)
00475 {
00476 if(!entries.value(i).value(CostTypeColumns::Type).startsWith("sum"))
00477 {
00478 QStringList entry = entries.value(i);
00479 sum += entry.value(CostTypeColumns::Costs).toDouble();
00480 }
00481 }
00482 return sum;
00483 }
00484
00485 double CostTypeModel::getProfitLossSum()
00486 {
00487 double palsum = 0;
00488 for(int i = 0; i < entries.size(); i++)
00489 {
00490 if(!entries.value(i).value(CostTypeColumns::Type).startsWith("sum"))
00491 {
00492 QStringList entry = entries.value(i);
00493 palsum += entry.value(CostTypeColumns::PalValue).toDouble();
00494 }
00495 }
00496 return palsum;
00497 }
00498
00499 bool CostTypeModel::setData(const QModelIndex &index, const QVariant &value, int role)
00500 {
00501 if(index.isValid() && role == Qt::EditRole)
00502 {
00503 int row = index.row();
00504 QStringList p = entries.value(row);
00505
00506 if(index.column() >= 0 && index.column() <= 8)
00507 {
00508 p.replace(index.column(), value.toString());
00509 }
00510 else
00511 {
00512 return false;
00513 }
00514
00515 entries.replace(row, p);
00516 setModified(true);
00517 emit(dataChanged(index, index));
00518 return true;
00519 }
00520 return false;
00521 }
00522
00523 Qt::ItemFlags CostTypeModel::flags(const QModelIndex &index) const
00524 {
00525 if(!index.isValid())
00526 {
00527 return Qt::ItemIsEnabled;
00528 }
00529 return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
00530 }
00531
00532 QList<QStringList> CostTypeModel::getList()
00533 {
00534 return entries;
00535 }
00536
00537 bool CostTypeModel::isModified()
00538 {
00539 return modified;
00540 }
00541
00542 void CostTypeModel::setModified(bool b)
00543 {
00544 modified = b;
00545 }
00546
00547 void CostTypeModel::setLastRowId(uint rowid)
00548 {
00549 lastid = rowid;
00550 }
00551
00552 bool CostTypeModel::reassessValueBased(QString position, int ty, QString pal, QString replacementvalue, QString salvagevalue, QString usefuleconomiclife, int affectedRow, QModelIndexList affectedRows)
00553 {
00554 bool ok = true;
00555 pal.toDouble(&ok) && replacementvalue.toDouble(&ok) && salvagevalue.toDouble(&ok) && usefuleconomiclife.toDouble(&ok);
00556 if(!ok)
00557 {
00558 return false;
00559 }
00560 else
00561 {
00562 if(pal.toDouble() > 0 && replacementvalue.toDouble() > 0 && salvagevalue.toDouble() >= 0 && usefuleconomiclife.toDouble() >= 0)
00563 {
00564 QString result = CostTypeCalculation::reassessByAcquisitionValue(replacementvalue, salvagevalue, usefuleconomiclife);
00565 if(result != "")
00566 {
00567 QString palvalue = pal;
00568 QString transition = "";
00569 if((pal.toDouble() - result.toDouble()) <= 0)
00570 {
00571 transition = QString::number(-1 * (pal.toDouble() - result.toDouble()), 'f', 2);
00572 }
00573 else
00574 {
00575 transition = "-" + QString::number(pal.toDouble() - result.toDouble(), 'f', 2);
00576 }
00577 QString costs = QString::number(result.toDouble(), 'f', 2);
00578
00579 if(affectedRow == -1)
00580 {
00581
00582 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::Reassess, pal + ";" + replacementvalue + ";" + salvagevalue + ";" + usefuleconomiclife, lastid, -1);
00583 }
00584 else
00585 {
00586
00587 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::Reassess, pal + ";" + replacementvalue + ";" + salvagevalue + ";" + usefuleconomiclife, affectedRow, -1, true, affectedRows.value(0));
00588 }
00589 }
00590 return false;
00591 }
00592 else
00593 {
00594 return false;
00595 }
00596 }
00597 }
00598
00599 bool CostTypeModel::reassessIndexBased(QString position, int type, QString pal, QString decliningbalance, QString usefuleconomiclife, QString purchasePrice, QString purchaseIndex, QString currentIndex, int affectedRow, QModelIndexList affectedRows)
00600 {
00601 bool ok = true;
00602 pal.toDouble(&ok) && decliningbalance.toDouble(&ok) && usefuleconomiclife.toDouble(&ok);
00603 if(!ok)
00604 {
00605 return false;
00606 }
00607 else
00608 {
00609 if(pal.toDouble() > 0 && decliningbalance.toDouble() >= 0 && usefuleconomiclife.toDouble() >= 0)
00610 {
00611 QString result = CostTypeCalculation::reassessByIndex(purchasePrice, purchaseIndex, currentIndex);
00612 if(result != "")
00613 {
00614 if(affectedRow == -1)
00615 {
00616
00617 return reassessValueBased(position, type, pal, result, decliningbalance, usefuleconomiclife);
00618 }
00619 else
00620 {
00621
00622 return reassessValueBased(position, type, pal, result, decliningbalance, usefuleconomiclife, affectedRow, affectedRows);
00623 }
00624 }
00625 return true;
00626 }
00627 else
00628 {
00629 return false;
00630 }
00631 }
00632 }
00633
00634 bool CostTypeModel::delimitAmount(QString position, int ty, QString incomestatement, QString amounttodelimit, int affectedRow, QModelIndexList affectedRows)
00635 {
00636 bool ok;
00637 incomestatement.toDouble(&ok) && amounttodelimit.toDouble(&ok);
00638 if(!ok)
00639 {
00640 return false;
00641 }
00642 else
00643 {
00644 if(incomestatement.toDouble() > 0 && amounttodelimit.toDouble() >= 0)
00645 {
00646 QString result = CostTypeCalculation::delimitAmount(incomestatement, amounttodelimit);
00647 if(result != "")
00648 {
00649 QString palvalue = incomestatement;
00650 QString transition = "";
00651 if(incomestatement.toDouble() - result.toDouble() > 0)
00652 {
00653 transition = "-" + QString::number(incomestatement.toDouble() - result.toDouble(), 'f', 2);
00654 }
00655 else
00656 {
00657 transition = QString::number(incomestatement.toDouble() - result.toDouble(), 'f', 2);
00658 }
00659 QString costs = QString::number(result.toDouble(), 'f', 2);
00660
00661 if(affectedRow == -1)
00662 {
00663
00664 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::DelimitAmount, incomestatement + ";" + amounttodelimit, lastid, -1);
00665 }
00666 else
00667 {
00668
00669 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::DelimitAmount, incomestatement + ";" + amounttodelimit, affectedRow, -1, true, affectedRows.value(0));
00670 }
00671 }
00672 return false;
00673 }
00674 else
00675 {
00676 return false;
00677 }
00678 }
00679 }
00680
00681 bool CostTypeModel::acceptCosts(QString position, int ty, QString incomestatement, int affectedRow, QModelIndexList affectedRows)
00682 {
00683 bool ok;
00684 incomestatement.toDouble(&ok);
00685 if(!ok)
00686 {
00687 return false;
00688 }
00689 else
00690 {
00691 if(incomestatement.toDouble() >= 0)
00692 {
00693 QString result = incomestatement;
00694
00695 QString palvalue = incomestatement;
00696 QString transition = "0";
00697 QString costs = QString::number(result.toDouble(), 'f', 2);
00698
00699 if(affectedRow == -1)
00700 {
00701
00702 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::AcceptCosts, incomestatement, lastid, -1);
00703 }
00704 else
00705 {
00706
00707 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::AcceptCosts, incomestatement, affectedRow, -1, true, affectedRows.value(0));
00708 }
00709 }
00710 else
00711 {
00712 return false;
00713 }
00714 }
00715 }
00716
00717 bool CostTypeModel::normalize(QString position, int ty, QString averagecosts, QString actualcosts, int affectedRow, QModelIndexList affectedRows)
00718 {
00719 bool ok;
00720 averagecosts.toDouble(&ok) && actualcosts.toDouble(&ok);
00721 if(!ok)
00722 {
00723 return false;
00724 }
00725 else
00726 {
00727 if(averagecosts.toDouble() >= 0 && actualcosts.toDouble() >= 0)
00728 {
00729 QString result = CostTypeCalculation::normalize(averagecosts, actualcosts);
00730 if(result != "")
00731 {
00732 QString palvalue = actualcosts;
00733 QString transition = QString::number(result.toDouble() - actualcosts.toDouble(), 'f', 2);
00734 QString costs = QString::number(result.toDouble(), 'f', 2);
00735
00736 if(affectedRow == -1)
00737 {
00738
00739 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::Normalize, averagecosts + ";" + actualcosts, lastid, -1);
00740 }
00741 else
00742 {
00743
00744 return addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::Normalize, averagecosts + ";" + actualcosts, affectedRow, -1, true, affectedRows.value(0));
00745 }
00746 }
00747 return false;
00748 }
00749 else
00750 {
00751 return false;
00752 }
00753 }
00754 }
00755
00756 bool CostTypeModel::wages(QString position, int ty, QString wages, QString specialpayment, QString legaltaxes, QString paymentbyresult, QString directcostpart, QString nonwagelaborcosts, int affectedRow, QModelIndexList affectedRows)
00757 {
00758 bool ok;
00759 wages.toDouble(&ok) && specialpayment.toDouble(&ok) && legaltaxes.toDouble(&ok) && paymentbyresult.toDouble(&ok) && directcostpart.toDouble(&ok) && nonwagelaborcosts.toDouble(&ok);
00760 if(!ok || ((alreadyContainsRow("Sonderzahlungen") || alreadyContainsRow("Gesetzliche Lohnabgaben") || alreadyContainsRow("Einzelkostenentgelt") || alreadyContainsRow("Gemeinkostenentgelt") || alreadyContainsRow("Lohnnebenkosten") ) && affectedRow == -1))
00761 {
00762 return false;
00763 }
00764 else
00765 {
00766 if(wages.toDouble() > 0 && specialpayment.toDouble() >= 0 && legaltaxes.toDouble() >= 0 && paymentbyresult.toDouble() >= 0 && directcostpart.toDouble() >= 0 && nonwagelaborcosts.toDouble() >= 0)
00767 {
00768 QString palvalue = wages;
00769 QString transition = "-" + wages;
00770 QString result = "0";
00771
00772 double proz_leistungsloehne = paymentbyresult.toDouble();
00773 double leistungsloehne = wages.toDouble() * (proz_leistungsloehne / 100);
00774 double direkt = leistungsloehne *(directcostpart.toDouble() / 100);
00775 double lohnnebenkosten = leistungsloehne * (nonwagelaborcosts.toDouble() / 100);
00776
00777 QString editinformation = wages + ";" + specialpayment + ";" + legaltaxes + ";" + paymentbyresult + ";" + directcostpart + ";" + nonwagelaborcosts;
00778
00779 if(affectedRow == -1)
00780 {
00781 uint temp = lastid;
00782 temp++;
00783
00784 addEditEntry(position, "0", "+" + wages, wages, QString::number(ty), CostTypeActions::Wages, editinformation, lastid, temp);
00785
00786 temp++;
00787 addEditEntry(tr("Sonderzahlungen"), specialpayment, "-" + specialpayment, "0", QString::number(ty), CostTypeActions::Wages, editinformation, lastid, temp);
00788
00789 temp++;
00790 addEditEntry(tr("Gesetzliche Lohnabgaben"), legaltaxes, "-" + legaltaxes, "0", QString::number(ty), CostTypeActions::Wages, editinformation, lastid, temp);
00791
00792 temp++;
00793 addEditEntry(tr("Einzelkostenentgelt"), "0", QString::number(direkt), QString::number(direkt), QString::number(ty), CostTypeActions::Wages, editinformation, lastid, temp);
00794
00795 temp++;
00796 addEditEntry(tr("Gemeinkostenentgelt"), "0", QString::number(leistungsloehne - direkt), QString::number(leistungsloehne - direkt), QString::number(ty), CostTypeActions::Wages, editinformation, lastid, temp);
00797
00798 temp-=5;
00799 addEditEntry(tr("Lohnnebenkosten"), "0", QString::number(lohnnebenkosten), QString::number(lohnnebenkosten), QString::number(ty), CostTypeActions::Wages, editinformation, lastid, temp);
00800 }
00801 else
00802 {
00803 QStringList positionNames;
00804 positionNames<<data(affectedRows.value(0).row()).value(CostTypeColumns::PositionName);
00805 positionNames<<data(affectedRows.value(1).row()).value(CostTypeColumns::PositionName);
00806 positionNames<<data(affectedRows.value(2).row()).value(CostTypeColumns::PositionName);
00807 positionNames<<data(affectedRows.value(3).row()).value(CostTypeColumns::PositionName);
00808 positionNames<<data(affectedRows.value(4).row()).value(CostTypeColumns::PositionName);
00809 positionNames<<data(affectedRows.value(5).row()).value(CostTypeColumns::PositionName);
00810
00811 bool ok = true;
00812
00813 QString positionName = "Sonderzahlungen";
00814 ok &= positionNames.removeOne(positionName);
00815 positionName = "Gesetzliche Lohnabgaben";
00816 ok &= positionNames.removeOne(positionName);
00817 positionName = "Einzelkostenentgelt";
00818 ok &= positionNames.removeOne(positionName);
00819 positionName = "Gemeinkostenentgelt";
00820 ok &= positionNames.removeOne(positionName);
00821 positionName = "Lohnnebenkosten";
00822 ok &= positionNames.removeOne(positionName);
00823
00824 if(ok)
00825 {
00826 addEditEntry(positionNames.value(0), "0", "+" + wages, wages, QString::number(ty), CostTypeActions::Wages, editinformation, data(affectedRows.value(0).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(0).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(0));
00827 addEditEntry("Sonderzahlungen", specialpayment, "-" + specialpayment, "0", QString::number(ty), CostTypeActions::Wages, editinformation, data(affectedRows.value(1).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(1).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(1));
00828 addEditEntry("Gesetzliche Lohnabgaben", legaltaxes, "-" + legaltaxes, "0", QString::number(ty), CostTypeActions::Wages, editinformation, data(affectedRows.value(2).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(2).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(2));
00829 addEditEntry("Einzelkostenentgelt", "0", QString::number(direkt), QString::number(direkt), QString::number(ty), CostTypeActions::Wages, editinformation, data(affectedRows.value(3).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(3).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(3));
00830 addEditEntry("Gemeinkostenentgelt", "0", QString::number(leistungsloehne - direkt), QString::number(leistungsloehne - direkt), QString::number(ty), CostTypeActions::Wages, editinformation, data(affectedRows.value(4).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(4).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(4));
00831 addEditEntry("Lohnnebenkosten", "0", QString::number(lohnnebenkosten), QString::number(lohnnebenkosten), QString::number(ty), CostTypeActions::Wages, editinformation, data(affectedRows.value(5).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(5).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(5));
00832 }
00833 else
00834 {
00835
00836 return false;
00837 }
00838 }
00839 return true;
00840 }
00841 else
00842 {
00843 return false;
00844 }
00845 }
00846 }
00847
00848 bool CostTypeModel::incidentialInterest(QString position, int ty, QString incomestatement, int affectedRow, QModelIndexList affectedRows)
00849 {
00850 bool ok;
00851 incomestatement.toDouble(&ok);
00852 if(!ok || (alreadyContainsRow("Kalkulatorische Zinsen") && affectedRow == -1))
00853 {
00854 return false;
00855 }
00856 else
00857 {
00858 if(incomestatement.toDouble()>0)
00859 {
00860
00861 QString palvalue = incomestatement;
00862 QString transition = "-" + incomestatement;
00863 QString costs = "0.00";
00864
00865 if(affectedRow == -1)
00866 {
00867 int temp = lastid;
00868 temp++;
00869 addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=0;" + incomestatement, lastid, temp);
00870
00871
00872
00873 palvalue = "0";
00874 transition = QString::number(incomestatement.toDouble(), 'f', 2);
00875 costs = QString::number(incomestatement.toDouble(), 'f', 2);
00876
00877 temp--;
00878 addEditEntry("Kalkulatorische Zinsen", palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=0;" + incomestatement, lastid, temp);
00879
00880 }
00881 else
00882 {
00883 QStringList positionNames;
00884 positionNames<<data(affectedRows.value(0).row()).value(CostTypeColumns::PositionName);
00885 positionNames<<data(affectedRows.value(1).row()).value(CostTypeColumns::PositionName);
00886
00887 QString positionName = "Kalkulatorische Zinsen";
00888 if(positionNames.removeOne(positionName))
00889 {
00890 addEditEntry(positionNames.value(0), palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=0;" + incomestatement, data(affectedRows.value(0).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(0).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(0));
00891
00892
00893
00894 palvalue = "0";
00895 transition = QString::number(incomestatement.toDouble(), 'f', 2);
00896 costs = QString::number(incomestatement.toDouble(), 'f', 2);
00897
00898 addEditEntry("Kalkulatorische Zinsen", palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=0;" + incomestatement, data(affectedRows.value(1).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(1).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(1));
00899 }
00900 else
00901 {
00902 return false;
00903 }
00904 }
00905 return true;
00906 }
00907 else
00908 {
00909 return false;
00910 }
00911 }
00912 }
00913
00914 bool CostTypeModel::interestOnOwnBoundCapital(QString position, int ty, QString incomestatement, QString borrowed, QString owncapital, QString interestrate, int affectedRow, QModelIndexList affectedRows)
00915 {
00916 bool ok;
00917 borrowed.toDouble(&ok) && owncapital.toDouble(&ok) && interestrate.toDouble(&ok) && incomestatement.toDouble(&ok);
00918 if(!ok || (alreadyContainsRow("Kalkulatorische Zinsen") && affectedRow == -1))
00919 {
00920 return false;
00921 }
00922 else
00923 {
00924 if(borrowed.toDouble()>=0 && owncapital.toDouble()>=0 && interestrate.toDouble()>0 && incomestatement.toDouble()>=0)
00925 {
00926 QString erg = CostTypeCalculation::imputedInterestOnAppropriateSurplus(borrowed, owncapital, interestrate);
00927
00928 if(erg != "false")
00929 {
00930
00931 QString palvalue = incomestatement;
00932 QString transition = "-" + incomestatement;
00933 QString costs = "0.00";
00934
00935 if(affectedRow == -1)
00936 {
00937 int temp = lastid;
00938 temp++;
00939 addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=1;" + incomestatement + ";" + borrowed + ";" + owncapital + ";" + interestrate, lastid, temp);
00940
00941
00942
00943 palvalue = "0";
00944 transition = QString::number(erg.toDouble(), 'f', 2);
00945 costs = QString::number(erg.toDouble(), 'f', 2);
00946
00947 temp--;
00948 addEditEntry("Kalkulatorische Zinsen", palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=1;" + incomestatement + ";" + borrowed + ";" + owncapital + ";" + interestrate, lastid, temp);
00949
00950 }
00951 else
00952 {
00953 QStringList positionNames;
00954 positionNames<<data(affectedRows.value(0).row()).value(CostTypeColumns::PositionName);
00955 positionNames<<data(affectedRows.value(1).row()).value(CostTypeColumns::PositionName);
00956
00957 QString positionName = "Kalkulatorische Zinsen";
00958 if(positionNames.removeOne(positionName))
00959 {
00960 addEditEntry(positionNames.value(0), palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=1;" + incomestatement + ";" + borrowed + ";" + owncapital + ";" + interestrate, data(affectedRows.value(0).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(0).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(0));
00961
00962
00963
00964 palvalue = "0";
00965 transition = QString::number(erg.toDouble(), 'f', 2);
00966 costs = QString::number(erg.toDouble(), 'f', 2);
00967
00968 addEditEntry("Kalkulatorische Zinsen", palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=1;" + incomestatement + ";" + borrowed + ";" + owncapital + ";" + interestrate, data(affectedRows.value(1).row()).value(CostTypeColumns::RowID).toInt(), data(affectedRows.value(1).row()).value(CostTypeColumns::AssociationID).toInt(), true, affectedRows.value(1));
00969
00970 }
00971 else
00972 {
00973 return false;
00974 }
00975 }
00976 return true;
00977 }
00978 else
00979 {
00980 return false;
00981 }
00982 }
00983 else
00984 {
00985 return false;
00986 }
00987 }
00988 }
00989
00990 bool CostTypeModel::interestOnOperatingAssets(QString position, int ty, QString incomeStatement, QString interestRateOwnBoundCapital, QString operatingAssets, int affectedRow, QModelIndexList affectedRows)
00991 {
00992 bool ok;
00993 interestRateOwnBoundCapital.toDouble(&ok) && operatingAssets.toDouble(&ok) && incomeStatement.toDouble(&ok);
00994 if(!ok || (alreadyContainsRow("Kalkulatorische Zinsen") && affectedRow == -1))
00995 {
00996 return false;
00997 }
00998 else
00999 {
01000 if(interestRateOwnBoundCapital.toDouble() > 0 && operatingAssets.toDouble() >= 0 && incomeStatement.toDouble() >= 0)
01001 {
01002 QString erg = QString::number((operatingAssets.toDouble() * (interestRateOwnBoundCapital.toDouble()/100)), 'f', 2);
01003 if(erg != "false")
01004 {
01005
01006 QString palvalue = incomeStatement;
01007 QString transition = "-" + incomeStatement;
01008 QString costs = "0.00";
01009
01010 if(affectedRow == -1)
01011 {
01012
01013
01014 int temp = lastid;
01015 temp++;
01016 addEditEntry(position, palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=2;" + incomeStatement + ";" + interestRateOwnBoundCapital + ";" + operatingAssets, lastid, temp);
01017
01018
01019
01020 palvalue = "0";
01021 transition = QString::number(erg.toDouble(), 'f', 2);
01022 costs = QString::number(erg.toDouble(), 'f', 2);
01023 temp--;
01024 addEditEntry("Kalkulatorische Zinsen", palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=2;" + incomeStatement + ";" + interestRateOwnBoundCapital + ";" + operatingAssets, lastid, temp);
01025
01026 }
01027 else
01028 {
01029
01030
01031 int row1 = data(affectedRows.value(0).row()).value(8).toInt();
01032 int row2 = data(affectedRows.value(1).row()).value(8).toInt();
01033 QStringList positionNames;
01034 positionNames<<data(affectedRows.value(0).row()).value(CostTypeColumns::PositionName);
01035 positionNames<<data(affectedRows.value(1).row()).value(CostTypeColumns::PositionName);
01036
01037 QString positionName = "Kalkulatorische Zinsen";
01038 if(positionNames.removeOne(positionName))
01039 {
01040 addEditEntry(positionNames.value(0), palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=2;" + incomeStatement + ";" + interestRateOwnBoundCapital + ";" + operatingAssets, row1, row2, true, affectedRows.value(0));
01041
01042
01043
01044 palvalue = "0";
01045 transition = QString::number(erg.toDouble(), 'f', 2);
01046 costs = QString::number(erg.toDouble(), 'f', 2);
01047 addEditEntry(positionName, palvalue, transition, costs, QString::number(ty), CostTypeActions::CompleteCostsInterests, "type=2;" + incomeStatement + ";" + interestRateOwnBoundCapital + ";" + operatingAssets, row2, row1, true, affectedRows.value(1));
01048
01049 }
01050 else
01051 {
01052 return false;
01053 }
01054 }
01055 return true;
01056 }
01057 else
01058 {
01059 return false;
01060 }
01061 }
01062 else
01063 {
01064 return false;
01065 }
01066 }
01067 }
01068
01069 bool CostTypeModel::completeCostsEmployersSalary(QString position, int type, QString salarywithouttaxes, QString monthsforcalculation, QString riskpremium, int affectedRow, QModelIndexList affectedRows)
01070 {
01071 bool ok;
01072 salarywithouttaxes.toDouble(&ok) && monthsforcalculation.toInt(&ok) && riskpremium.toDouble(&ok);
01073 if(!ok)
01074 {
01075 return false;
01076 }
01077 else
01078 {
01079 if(salarywithouttaxes.toDouble() > 0 && monthsforcalculation.toInt() > 0 && riskpremium.toDouble() >= 0)
01080 {
01081 QString palvalue = "0";
01082 QString result = CostTypeCalculation::imputedEmployersSalary(salarywithouttaxes, monthsforcalculation, riskpremium);
01083 QString transition = result;
01084
01085 if(affectedRow == -1)
01086 {
01087
01088 addEditEntry(position, palvalue, transition, result, QString::number(type), CostTypeActions::CompleteCostsEmployerSalary, salarywithouttaxes + ";" + monthsforcalculation + ";" + riskpremium, lastid, -1);
01089 }
01090 else
01091 {
01092
01093 addEditEntry(position, palvalue, transition, result, QString::number(type), CostTypeActions::CompleteCostsEmployerSalary, salarywithouttaxes + ";" + monthsforcalculation + ";" + riskpremium, affectedRow, -1, true, affectedRows.value(0));
01094 }
01095 return true;
01096 }
01097 else
01098 {
01099 return false;
01100 }
01101 }
01102 }
01103
01104 bool CostTypeModel::alreadyContainsRow(QString position)
01105 {
01106 for(int rows = 0; rows < entries.count(); rows++)
01107 {
01108 if(entries.value(rows).contains(position))
01109 {
01110 qDebug()<<"Row already exists: " << position;
01111 return true;
01112 }
01113 }
01114 return false;
01115 }
01116
01117 bool CostTypeModel::addEditEntry(QString position, QString pal, QString transition, QString costs, QString costtype, int type, QString editoptions, int rowid, int associationid, bool editExistingRow, QModelIndex affectedRow)
01118 {
01119 QModelIndex i;
01120
01121 if(!editExistingRow)
01122 {
01123 if(!alreadyContainsRow(position))
01124 {
01125 int row = rowIdIndex("sum1");
01126 if(row != -1)
01127 {
01128 if(insertRows(row, 1, QModelIndex()))
01129 {
01130 i = index(row, CostTypeColumns::PositionName, QModelIndex());
01131 }
01132 }
01133 else
01134 {
01135 return false;
01136 }
01137 }
01138 else
01139 {
01140 return false;
01141 }
01142 }
01143 else
01144 {
01145 i = affectedRow;
01146 }
01147
01148 setData(i, position, Qt::EditRole);
01149
01150 i = index(i.row(), CostTypeColumns::PalValue, QModelIndex());
01151 setData(i, pal, Qt::EditRole);
01152
01153 i = index(i.row(), CostTypeColumns::TransitionValue, QModelIndex());
01154 setData(i, transition, Qt::EditRole);
01155
01156 i = index(i.row(), CostTypeColumns::Costs, QModelIndex());
01157 setData(i, costs, Qt::EditRole);
01158
01159 i = index(i.row(), CostTypeColumns::CostType, QModelIndex());
01160 setData(i, costtype, Qt::EditRole);
01161
01162 i = index(i.row(), CostTypeColumns::Type, QModelIndex());
01163 setData(i, QString::number(type), Qt::EditRole);
01164
01165 i = index(i.row(), CostTypeColumns::EditInformation, QModelIndex());
01166 setData(i, editoptions, Qt::EditRole);
01167
01168 i = index(i.row(), CostTypeColumns::RowID, QModelIndex());
01169 setData(i, QString::number(rowid), Qt::EditRole);
01170
01171 i = index(i.row(), CostTypeColumns::AssociationID, QModelIndex());
01172 setData(i, QString::number(associationid), Qt::EditRole);
01173
01174 refreshSums();
01175
01176 if(affectedRow.isValid())
01177 {
01178
01179 emit rowEdited(rowid);
01180 }
01181 return true;
01182 }
01183
01184
01185 bool CostTypeModel::searchModel(QString entry)
01186 {
01187
01188
01189 for(int i = 0; i < entries.size(); i++)
01190 {
01191 if(entries.value(i).value(CostTypeColumns::Type) == entry)
01192 {
01193 return true;
01194 }
01195 }
01196 return false;
01197 }
01198
01199 int CostTypeModel::rowIdIndex(QString row)
01200 {
01201 for(int i = 0; i < entries.size(); i++)
01202 {
01203 if(entries.value(i).value(CostTypeColumns::Type) == row)
01204 {
01205 return i;
01206 }
01207 }
01208 return -1;
01209 }
01210
01211 void CostTypeModel::refreshSums()
01212 {
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227 CostTypeRows *rows = new CostTypeRows();
01228
01229 if(!searchModel("sum1"))
01230 {
01231
01232 if(searchModel("sum2"))
01233 {
01234
01235
01236 int indexsum2 = rowIdIndex("sum2");
01237 if((indexsum2 - 1) < 0)
01238 {
01239
01240 if(insertRows(0, 1, QModelIndex()))
01241 {
01242 QModelIndex i = index(0, CostTypeColumns::PositionName, QModelIndex());
01243 setData(i, rows->costtyperows(CostTypeRows::Sum), Qt::EditRole);
01244 i = index(0, CostTypeColumns::Type, QModelIndex());
01245 setData(i, "sum1", Qt::EditRole);
01246 i = index(0, CostTypeColumns::AssociationID, QModelIndex());
01247 setData(i, "-1", Qt::EditRole);
01248
01249
01250 }
01251 else
01252 {
01253
01254 }
01255 }
01256 else
01257 {
01258
01259 if(insertRows(indexsum2, 1, QModelIndex()))
01260 {
01261 QModelIndex i = index(indexsum2, 0, QModelIndex());
01262 setData(i, rows->costtyperows(CostTypeRows::Sum), Qt::EditRole);
01263 i = index(indexsum2, 5, QModelIndex());
01264 setData(i, "sum1", Qt::EditRole);
01265 i = index(indexsum2, 8, QModelIndex());
01266 setData(i, "-1", Qt::EditRole);
01267
01268
01269 }
01270 }
01271 }
01272 else if(searchModel("sum3"))
01273 {
01274
01275
01276 int indexsum3 = rowIdIndex("sum3");
01277 if((indexsum3 -1) < 0)
01278 {
01279
01280
01281 if(insertRows(0, 1, QModelIndex()))
01282 {
01283 QModelIndex i = index(0, CostTypeColumns::PositionName, QModelIndex());
01284 setData(i, rows->costtyperows(CostTypeRows::Sum), Qt::EditRole);
01285 i = index(0, CostTypeColumns::Type, QModelIndex());
01286 setData(i, "sum1", Qt::EditRole);
01287 i = index(0, CostTypeColumns::AssociationID, QModelIndex());
01288 setData(i, "-1", Qt::EditRole);
01289
01290
01291 }
01292 }
01293 else
01294 {
01295
01296
01297 if(insertRows(indexsum3, 1, QModelIndex()))
01298 {
01299 QModelIndex i = index(indexsum3, 0, QModelIndex());
01300 setData(i, rows->costtyperows(CostTypeRows::Sum), Qt::EditRole);
01301 i = index(indexsum3, 5, QModelIndex());
01302 setData(i, "sum1", Qt::EditRole);
01303 i = index(indexsum3, 8, QModelIndex());
01304 setData(i, "-1", Qt::EditRole);
01305
01306
01307 }
01308 }
01309 }
01310 else
01311 {
01312
01313
01314 if(insertRows(rowCount(QModelIndex()), 1, QModelIndex()))
01315 {
01316 QModelIndex i = index(rowCount(QModelIndex()) - 1, 0, QModelIndex());
01317 setData(i, rows->costtyperows(CostTypeRows::Sum), Qt::EditRole);
01318 i = index(rowCount(QModelIndex()) - 1, 5, QModelIndex());
01319 setData(i, "sum1", Qt::EditRole);
01320 i = index(rowCount(QModelIndex()) - 1, 8, QModelIndex());
01321 setData(i, "-1", Qt::EditRole);
01322
01323
01324 }
01325 }
01326 }
01327
01328 int posSum1 = rowIdIndex("sum1");
01329 QModelIndex i = index(posSum1, 1, QModelIndex());
01330 double summe_guv = getProfitLossSum();
01331 setData(i, QString::number(summe_guv, 'f', 2), Qt::EditRole);
01332 i = index(posSum1, 3, QModelIndex());
01333 double summe = getCompleteSum();
01334 setData(i, QString::number(summe, 'f', 2), Qt::EditRole);
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348 if(!searchModel("sum2"))
01349 {
01350 if(searchModel("sum1"))
01351 {
01352
01353 int indexAfterSum1 = rowIdIndex("sum1") + 1;
01354 if(insertRows(rowIdIndex("sum1") + 1, 1, QModelIndex()))
01355 {
01356 i = index(indexAfterSum1, 0, QModelIndex());
01357 setData(i, rows->costtyperows(CostTypeRows::Revenues), Qt::EditRole);
01358 i = index(indexAfterSum1, 5, QModelIndex());
01359 setData(i, "sum2", Qt::EditRole);
01360 i = index(indexAfterSum1, 8, QModelIndex());
01361 setData(i, "-1", Qt::EditRole);
01362 }
01363 }
01364 else if(searchModel("sum3"))
01365 {
01366
01367 int indexsum3 = rowIdIndex("sum3");
01368 if((indexsum3 -1) < 0)
01369 {
01370 qDebug()<<"sum3 is the first element in the list";
01371 if(insertRows(0, 1, QModelIndex()))
01372 {
01373 i = index(0, CostTypeColumns::PositionName, QModelIndex());
01374 setData(i, rows->costtyperows(CostTypeRows::Revenues), Qt::EditRole);
01375 i = index(0, CostTypeColumns::Type, QModelIndex());
01376 setData(i, "sum2", Qt::EditRole);
01377 i = index(0, CostTypeColumns::AssociationID, QModelIndex());
01378 setData(i, "-1", Qt::EditRole);
01379 }
01380 }
01381 else
01382 {
01383
01384 if(insertRows(indexsum3, 1, QModelIndex()))
01385 {
01386 i = index(indexsum3, 0, QModelIndex());
01387 setData(i, rows->costtyperows(CostTypeRows::Revenues), Qt::EditRole);
01388 i = index(indexsum3, 5, QModelIndex());
01389 setData(i, "sum2", Qt::EditRole);
01390 i = index(indexsum3, 8, QModelIndex());
01391 setData(i, "-1", Qt::EditRole);
01392 }
01393 }
01394 }
01395 else
01396 {
01397
01398 if(insertRows(rowCount(QModelIndex()) - 1, 1, QModelIndex()))
01399 {
01400 i = index(rowCount(QModelIndex()) - 1, 0, QModelIndex());
01401 setData(i, rows->costtyperows(CostTypeRows::Revenues), Qt::EditRole);
01402 i = index(rowCount(QModelIndex()) - 1, 5, QModelIndex());
01403 setData(i, "sum2", Qt::EditRole);
01404 i = index(rowCount(QModelIndex()) - 1, 8, QModelIndex());
01405 setData(i, "-1", Qt::EditRole);
01406 }
01407 }
01408 }
01409 int posSum2 = rowIdIndex("sum2");
01410 i = index(posSum2, 3, QModelIndex());
01411 setData(i, QString::number(revenues, 'f', 2), Qt::EditRole);
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425 if(!searchModel("sum3"))
01426 {
01427 if(searchModel("sum2"))
01428 {
01429
01430 int indexsum2 = rowIdIndex("sum2");
01431 if(insertRows(indexsum2 + 1, 1, QModelIndex()))
01432 {
01433 i = index(indexsum2 + 1, 0, QModelIndex());
01434 setData(i, rows->costtyperows(CostTypeRows::Result), Qt::EditRole);
01435 i = index(indexsum2 + 1, 5, QModelIndex());
01436 setData(i, "sum3", Qt::EditRole);
01437 i = index(indexsum2 + 1, 8, QModelIndex());
01438 setData(i, "-1", Qt::EditRole);
01439 }
01440 }
01441 else if(searchModel("sum1"))
01442 {
01443
01444 int indexsum1 = rowIdIndex("sum1");
01445 if(insertRows(indexsum1 + 1, 1, QModelIndex()))
01446 {
01447 i = index(indexsum1 + 1, 0, QModelIndex());
01448 setData(i, rows->costtyperows(CostTypeRows::Result), Qt::EditRole);
01449 i = index(indexsum1 + 1, 5, QModelIndex());
01450 setData(i, "sum3", Qt::EditRole);
01451 i = index(indexsum1 + 1, 8, QModelIndex());
01452 setData(i, "-1", Qt::EditRole);
01453 }
01454 }
01455 else
01456 {
01457
01458 if(insertRows(rowCount(QModelIndex()) - 1, 1, QModelIndex()))
01459 {
01460 i = index(rowCount(QModelIndex())-1, 0, QModelIndex());
01461 setData(i, rows->costtyperows(CostTypeRows::Result), Qt::EditRole);
01462 i = index(rowCount(QModelIndex())-1, 5, QModelIndex());
01463 setData(i, "sum3", Qt::EditRole);
01464 i = index(rowCount(QModelIndex())-1, 8, QModelIndex());
01465 setData(i, "-1", Qt::EditRole);
01466 }
01467 }
01468 }
01469 int posSum3 = rowIdIndex("sum3");
01470 i = index(posSum3, 3, QModelIndex());
01471 setData(i, QString::number(revenues-summe, 'f', 2), Qt::EditRole);
01472
01473 qDebug()<<"PERFORMANCE: changedDataUpdateProxies";
01474 emit changedDataUpdateProxies();
01475 }