[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kmymoney] kmymoney: BUG:319801 - Fix losing track of check number if check number sequence is inter
From:       Allan Anderson <agander93 () gmail ! com>
Date:       2014-01-26 10:53:19
Message-ID: E1W7NL5-00066s-0r () scm ! kde ! org
[Download RAW message or body]

Git commit 1dede8b9dfb550b3a26e4fc0ade208788c877b2c by Allan Anderson.
Committed on 26/01/2014 at 10:49.
Pushed by allananderson into branch 'master'.

BUG:319801 - Fix losing track of check number if check number sequence is interrupted.
REVIEW:115302

M  +16   -8    kmymoney/dialogs/transactioneditor.cpp
M  +7    -1    kmymoney/dialogs/transactioneditor.h
M  +14   -0    kmymoney/kmymoneyutils.cpp
M  +6    -0    kmymoney/kmymoneyutils.h

http://commits.kde.org/kmymoney/1dede8b9dfb550b3a26e4fc0ade208788c877b2c

diff --git a/kmymoney/dialogs/transactioneditor.cpp b/kmymoney/dialogs/transactioneditor.cpp
index 26e7672..3c148d8 100644
--- a/kmymoney/dialogs/transactioneditor.cpp
+++ b/kmymoney/dialogs/transactioneditor.cpp
@@ -605,14 +605,7 @@ bool TransactionEditor::enterTransactions(QString& newId, bool askForSchedule, b
             t = (*it_ts);
 
             // if a new transaction has a valid number, keep it with the account
-            QString number;
-            if (!(*it_ts).splits().isEmpty())
-              number = (*it_ts).splits().front().number();
-            if (!number.isEmpty()) {
-              m_account.setValue("lastNumberUsed", number);
-              file->modifyAccount(m_account);
-            }
-
+            keepNewNumber((*it_ts));
           } else {
             // turn object creation on, so that moving the focus does
             // not screw up the dialog that might be popping up
@@ -627,6 +620,9 @@ bool TransactionEditor::enterTransactions(QString& newId, bool askForSchedule, b
           emit lastPostDateUsed((*it_ts).postDate());
         } else {
           // modify existing transaction
+          // its number might have been edited
+          // bearing in mind it could contain alpha characters
+          keepNewNumber((*it_ts));
           file->modifyTransaction(*it_ts);
         }
       }
@@ -722,6 +718,18 @@ bool TransactionEditor::enterTransactions(QString& newId, bool askForSchedule, b
   return storeTransactions;
 }
 
+void TransactionEditor::keepNewNumber(const MyMoneyTransaction& tr)
+{
+  MyMoneyFile* file = MyMoneyFile::instance();
+  if (!tr.splits().isEmpty()) {
+    const quint64 num64 = KMyMoneyUtils::numericPart(tr.splits().front().number());
+    if (num64 > 0) {
+      m_account.setValue("lastNumberUsed", tr.splits().front().number());
+      file->modifyAccount(m_account);
+    }
+  }
+}
+
 void TransactionEditor::resizeForm(void)
 {
   // force resizeing of the columns in the form
diff --git a/kmymoney/dialogs/transactioneditor.h b/kmymoney/dialogs/transactioneditor.h
index 25705a0..db86832 100644
--- a/kmymoney/dialogs/transactioneditor.h
+++ b/kmymoney/dialogs/transactioneditor.h
@@ -310,8 +310,14 @@ protected:
   KMyMoneyRegister::Action                          m_initialAction;
   bool                                              m_openEditSplits;
   bool                                              m_memoChanged;
-};
 
+ private:
+  /**
+  *  If a new or an edited transaction has a valid number, keep it with the account
+  */
+  void keepNewNumber(const MyMoneyTransaction& tr);
+
+};
 
 class StdTransactionEditor : public TransactionEditor
 {
diff --git a/kmymoney/kmymoneyutils.cpp b/kmymoney/kmymoneyutils.cpp
index 7058557..e89528e 100644
--- a/kmymoney/kmymoneyutils.cpp
+++ b/kmymoney/kmymoneyutils.cpp
@@ -374,6 +374,20 @@ QString KMyMoneyUtils::nextCheckNumber(const MyMoneyAccount& acc)
   return number;
 }
 
+quint64 KMyMoneyUtils::numericPart(const QString & num)
+{
+  quint64 num64 = 0;
+  QRegExp exp(QString("(.*\\D)?(0*)(\\d+)(\\D.*)?"));
+  if (exp.indexIn(num) != -1) {
+    QString arg1 = exp.cap(1);
+    QString arg2 = exp.cap(2);
+    QString arg3 = QString::number(exp.cap(3).toULongLong());
+    QString arg4 = exp.cap(4);
+    num64 = QString("%2%3").arg(arg2).arg(arg3).toULongLong();
+  }
+  return num64;
+}
+
 QString KMyMoneyUtils::reconcileStateToString(MyMoneySplit::reconcileFlagE flag, bool text)
 {
   QString txt;
diff --git a/kmymoney/kmymoneyutils.h b/kmymoney/kmymoneyutils.h
index f64a55e..a899121 100644
--- a/kmymoney/kmymoneyutils.h
+++ b/kmymoney/kmymoneyutils.h
@@ -353,6 +353,12 @@ public:
   static QString nextCheckNumber(const MyMoneyAccount& acc);
 
   /**
+  * remove any non-numeric characters from check number
+  * to allow validity check
+  */
+  static quint64 numericPart(const QString & num);
+
+  /**
     * Returns the text representing the reconcile flag. If @a text is @p true
     * then the full text will be returned otherwise a short form (usually one character).
     */
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic