[Kmymoney-devel] Calculation next check number

Hilarius Warwinkel hilarius.warwinkel at live.com
Sat Jan 14 17:22:07 UTC 2012





I'd like to post a patch for the calculation of the next check number in the Transaction Editor form.
When
 you enter eg. "2012.001" as a check number, the next check number will 
be ""2012.2" in the current version (4.6.90-8be3581932).
The patch makes the next check number "2012.002".

----------- CUT HERE ----
--- /home/hw/kmymoney2/kmymoney-orig/kmymoney/kmymoneyutils.cpp    2012-01-14 13:27:17.029665048 +0100
+++ /home/hw/kmymoney2/kmymoney/kmymoney/kmymoneyutils.cpp    2012-01-14 17:14:38.643054307 +0100
@@ -354,9 +354,17 @@
 {
   // determine next check number
   QString number;
-  QRegExp exp(QString("(.*\\D)?(\\d+)(\\D.*)?"));
+  QRegExp exp(QString("(.*\\D)?(0*)(\\d+)(\\D.*)?"));
   if (exp.indexIn(acc.value("lastNumberUsed")) != -1) {
-    number = QString("%1%2%3").arg(exp.cap(1)).arg(exp.cap(2).toULongLong() + 1).arg(exp.cap(3));
+    QString arg1 = exp.cap(1);
+    QString arg2 = exp.cap(2);
+    long    arg3 = exp.cap(3).toULongLong() + 1;
+    QString arg4 = exp.cap(4);
+   
 if (arg2.length() > 0 && arg1.length() + arg2.length() + 
QString::number(arg3).length() + arg4.length() != 
acc.value("lastNumberUsed").length())
+    {
+      // new string is bigger than old one -> remove one preceding zero

+      arg2 = arg2.mid(1);

+    }
+    number = QString("%1%2%3%4").arg(arg1).arg(arg2).arg(arg3).arg(arg4);
   } else {
     number = '1';
   }
----------- CUT HERE ----

Kind regards,

HW
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kmymoney-devel/attachments/20120114/44abd58e/attachment.html>


More information about the KMyMoney-devel mailing list