Blob Blame History Raw
From 5796089e8cc2b9951ce8e32cfb87f7a1dd9d9f20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Wojni=C5=82owicz?=
 <lukasz.wojnilowicz@gmail.com>
Date: Sat, 18 Jun 2016 19:22:23 +0200
Subject: [PATCH 11/22] Fix importing fees with comma as decimal separator

BUG: 363954
REVIEW: 128100
---
 kmymoney/plugins/csvimport/investprocessing.cpp | 32 ++++++++++++++++---------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/kmymoney/plugins/csvimport/investprocessing.cpp b/kmymoney/plugins/csvimport/investprocessing.cpp
index 7562c73..49fc81d 100644
--- a/kmymoney/plugins/csvimport/investprocessing.cpp
+++ b/kmymoney/plugins/csvimport/investprocessing.cpp
@@ -1368,19 +1368,29 @@ int InvestProcessing::processInvestLine(const QString& inBuffer)
     }
 
     else if (m_columnTypeList[i] == "fee") {      //                Fee Col
-      MyMoneyMoney amount;
-      double percent = m_columnList[i].toDouble();// fee val or percent
-      if (percent > 0.00) {
-        if (m_csvDialog->m_wiz->m_pageInvestment->ui->checkBoxInv_feeType->isChecked()) {      //   fee is percent
-          //have to use amountCol as amount field may not yet have been processed
-          txt = inBuffer.section(m_fieldDelimiterCharacter, m_amountColumn, m_amountColumn);
-          amount = MyMoneyMoney(txt);
-          percent *= amount.toDouble() / 100;//               as percentage
+      txt = m_columnList[i];
+      txt = txt.remove('"');
+      if (txt.contains(')')) {
+        txt = '-' + txt.remove(QRegExp("[()]"));   //            Mark as -ve
+      }
+      newTxt = m_parse->possiblyReplaceSymbol(txt);
+      MyMoneyMoney fee = MyMoneyMoney(newTxt);
+      if (m_csvDialog->m_wiz->m_pageInvestment->ui->checkBoxInv_feeType->isChecked() &&
+        fee.toDouble() > 0.00 ) {      //   fee is percent
+        txt = m_columnList[m_amountColumn];
+        txt = txt.remove('"');
+        if (txt.contains(')')) {
+          txt = '-' +  txt.remove(QRegExp("[()]"));   //            Mark as -ve
         }
-        txt.setNum(percent, 'f', 4);
-        m_trInvestData.fee = MyMoneyMoney(percent);
-        m_tempBuffer +=  'O' + txt + '\n';//                  fee amount
+        newTxt = m_parse->possiblyReplaceSymbol(txt);
+        MyMoneyMoney amount = MyMoneyMoney(newTxt);
+        fee *= amount / MyMoneyMoney(100) ;//               as percentage
       }
+      fee.abs();
+      m_trInvestData.fee =  fee;
+      txt.setNum(fee.toDouble(), 'f', 4);
+      newTxt = m_parse->possiblyReplaceSymbol(txt);
+      m_tempBuffer +=  'O' + newTxt + '\n';//                  fee amount
     }
 
     else if (m_columnTypeList[i] == "symbol") { //                Symbol Col
-- 
2.7.4