Now the QR code decoding result is shown at the form.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 19 Jul 2017 22:02:11 +0000 (00:02 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 19 Jul 2017 22:02:11 +0000 (00:02 +0200)
qtapp/barcode2cash/mainwindow.cpp
qtapp/barcode2cash/mainwindow.h
qtapp/barcode2cash/mainwindow.ui

index ac9a2a2f2ba0ba4c00df2e4857afd3c7d139bbf3..0b086599b8d1f9a80199748f52d7997fa36632f3 100644 (file)
@@ -3,6 +3,38 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 
+
+/// converts a string like "123,45" (comma as decimal point) to 12345.
+bool cashstr_to_currencycent(QString cash, CurrencyCent& cent) {
+    bool ok;
+    cent = cash.replace(",", "").toInt(&ok);
+    return ok;
+}
+
+
+/// returns true if the decoding was successful
+bool decode_rksv(const QString& rksv_string, RksvParts& rksv_parts) {
+    // https://github.com/a-sit-plus/at-registrierkassen-mustercode/releases/download/1.2-DOK/2016-09-05-Detailfragen-RKSV-V1.2.pdf
+    auto parts = rksv_string.split("_");
+    if (parts.size() != 14) return false; // QR code found but not RKSV
+    if (!parts.takeFirst().isEmpty()) return false;
+    rksv_parts.rlat = parts.takeFirst();
+    if (!rksv_parts.rlat.startsWith("R1-")) return false; // e.g. "R1-AT1"
+    rksv_parts.device_id = parts.takeFirst(); // e.g. "603002101"
+    rksv_parts.receipt_id = parts.takeFirst(); // e.g. "1/603002101/691/10340"
+    rksv_parts.date_time = QDateTime::fromString(parts.takeFirst(), "yyyy-MM-ddThh:mm:ss");
+    if (!rksv_parts.date_time.isValid()) return false;
+    for (int i = 0; i != RksvParts::cash_count; ++i) {
+        if (!cashstr_to_currencycent(parts.takeFirst(), rksv_parts.cash[i])) return false;
+    }
+    rksv_parts.counter = parts.takeFirst(); // e.g. "9IY7hV1mTqhVd4bii4gIhw=="
+    rksv_parts.cert_serial = parts.takeFirst();  // e.g. "5660C34F"
+    rksv_parts.sig_prev = parts.takeFirst(); // e.g. "I8/Wa2TZWgw="
+    rksv_parts.sig = parts.takeFirst(); // e.g."eSmlrKimgzbtYBJXq0MzwmgI3fBDL+NfSjzfFCCdcZuoHC+LET8BGvmVGWAwmNSZnDD2tCewJ7AooQc0Bt0HcQ=="
+    return true;
+}
+
+
 bool checkCameraAvailability()
 {
     if (QCameraInfo::availableCameras().count() > 0)
@@ -46,6 +78,23 @@ MainWindow::~MainWindow() {
 }
 
 
+void MainWindow::updateRksv(const RksvParts& rksv) {
+    ui->le_rlat->setText(rksv.rlat);
+    ui->le_device_id->setText(rksv.device_id);
+    ui->le_receipt_id->setText(rksv.receipt_id);
+    ui->dte_date_time->setDateTime(rksv.date_time);
+    ui->le_counter->setText(rksv.counter);
+    ui->le_cert_serial->setText(rksv.cert_serial);
+    ui->le_sig_prev->setText(rksv.sig_prev);
+    ui->le_sig->setText(rksv.sig);
+    for (int i = 0; i != RksvParts::cash_count; ++i) {
+        QString text = tr("%1").arg(double(rksv.cash[i]) / 100);
+        QTableWidgetItem* item = new QTableWidgetItem(text);
+        ui->twCash->setItem(i, 0, item);
+    }
+}
+
+
 void MainWindow::updateCameraInfo() {
     ui->labCameraReady->setText(imageCapture->isReadyForCapture() ? "ready" : "not ready");
 }
@@ -79,25 +128,11 @@ void MainWindow::analyze() {
         for (auto resit = results.symbol_begin(); resit != results.symbol_end(); ++ resit) {
             if (resit->get_type() == zbar::ZBAR_QRCODE) {
                 QString qrcode_data = QString::fromStdString(resit->get_data());
-                // https://github.com/a-sit-plus/at-registrierkassen-mustercode/releases/download/1.2-DOK/2016-09-05-Detailfragen-RKSV-V1.2.pdf
-                auto parts = qrcode_data.split("_");
-                if (parts.size() != 14) continue; // QR code found but not RKSV
-                parts.takeFirst();
-                auto rlat = parts.takeFirst();
-                auto device_id = parts.takeFirst();
-                auto receipt_id = parts.takeFirst();
-                auto date_time = parts.takeFirst();
-                auto cash0 = parts.takeFirst();
-                auto cash1 = parts.takeFirst();
-                auto cash2 = parts.takeFirst();
-                auto cash3 = parts.takeFirst();
-                auto cash4 = parts.takeFirst();
-                auto counter = parts.takeFirst();
-                auto cert_serial = parts.takeFirst();
-                auto sig_prev = parts.takeFirst();
-                auto sig = parts.takeFirst();
-
-                break;
+                RksvParts rksv_parts;
+                if (decode_rksv(qrcode_data, rksv_parts)) {
+                    updateRksv(rksv_parts);
+                    break;
+                }
             }
         }
     }
index 3157f87c4467acd94139cde583641f1a8fa6db98..f73bdbd1fca97354716f49b7338a2b6f2f6fb7e6 100644 (file)
@@ -5,12 +5,31 @@
 #include <QCameraInfo>
 #include <QCameraImageCapture>
 #include <QCameraViewfinder>
+#include <QDateTime>
 
 
 namespace Ui {
 class MainWindow;
 }
 
+
+using CurrencyCent = signed long;
+
+
+struct RksvParts {
+    QString rlat;
+    QString device_id;
+    QString receipt_id;
+    QDateTime date_time;
+    static constexpr int cash_count = 5;
+    CurrencyCent cash[cash_count];
+    QString counter;
+    QString cert_serial;
+    QString sig_prev;
+    QString sig;
+};
+
+
 class MainWindow : public QMainWindow
 {
     Q_OBJECT
@@ -24,6 +43,7 @@ private:
 
     QCamera* camera = nullptr;
     QCameraImageCapture* imageCapture = nullptr;
+    void updateRksv(const RksvParts& rksv);
 
 public slots:
     void updateCameraInfo();
index ff9fbd6fc304de07785a0f2e1d5212177976ee86..b4bffd93794f80fc877e171d2723b97fe06ee6b2 100644 (file)
@@ -7,52 +7,63 @@
     <x>0</x>
     <y>0</y>
     <width>457</width>
-    <height>350</height>
+    <height>390</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>MainWindow</string>
   </property>
   <widget class="QWidget" name="centralWidget">
-   <layout class="QHBoxLayout" name="horizontalLayout_3">
+   <layout class="QVBoxLayout" name="verticalLayout_3">
     <item>
-     <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
+     <layout class="QHBoxLayout" name="horizontalLayout_4">
       <item>
-       <layout class="QHBoxLayout" name="horizontalLayout">
+       <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
         <item>
-         <widget class="QPushButton" name="pbCapture">
-          <property name="text">
-           <string>Capture</string>
-          </property>
-         </widget>
+         <layout class="QHBoxLayout" name="horizontalLayout">
+          <item>
+           <widget class="QPushButton" name="pbCapture">
+            <property name="text">
+             <string>Capture</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QLabel" name="labCameraReady">
+            <property name="text">
+             <string>TextLabel</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </item>
         <item>
-         <widget class="QLabel" name="labCameraReady">
-          <property name="text">
-           <string>TextLabel</string>
-          </property>
-         </widget>
+         <widget class="QCameraViewfinder" name="viewFinder" native="true"/>
         </item>
        </layout>
       </item>
       <item>
-       <widget class="QCameraViewfinder" name="viewFinder" native="true"/>
-      </item>
-     </layout>
-    </item>
-    <item>
-     <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
-      <item>
-       <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
         <item>
-         <widget class="QPushButton" name="pbAnalyze">
-          <property name="text">
-           <string>Analyze</string>
-          </property>
-         </widget>
+         <layout class="QHBoxLayout" name="horizontalLayout_2">
+          <item>
+           <widget class="QPushButton" name="pbAnalyze">
+            <property name="text">
+             <string>Analyze</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QLabel" name="labAnalyzeResult">
+            <property name="text">
+             <string>TextLabel</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
         </item>
         <item>
-         <widget class="QLabel" name="labAnalyzeResult">
+         <widget class="QLabel" name="labAnalyzeImage">
           <property name="text">
            <string>TextLabel</string>
           </property>
         </item>
        </layout>
       </item>
-      <item>
-       <widget class="QLabel" name="labAnalyzeImage">
-        <property name="text">
-         <string>TextLabel</string>
-        </property>
-       </widget>
-      </item>
      </layout>
     </item>
+    <item>
+     <widget class="QFrame" name="frame">
+      <property name="frameShape">
+       <enum>QFrame::StyledPanel</enum>
+      </property>
+      <property name="frameShadow">
+       <enum>QFrame::Raised</enum>
+      </property>
+      <layout class="QHBoxLayout" name="horizontalLayout_3">
+       <item>
+        <layout class="QFormLayout" name="formLayout">
+         <item row="0" column="0">
+          <widget class="QLabel" name="lab_rlat">
+           <property name="text">
+            <string>Rlat</string>
+           </property>
+           <property name="buddy">
+            <cstring>le_rlat</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="1">
+          <widget class="QLineEdit" name="le_rlat"/>
+         </item>
+         <item row="1" column="0">
+          <widget class="QLabel" name="lab_device_id">
+           <property name="text">
+            <string>Device ID</string>
+           </property>
+           <property name="buddy">
+            <cstring>le_device_id</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1">
+          <widget class="QLineEdit" name="le_device_id"/>
+         </item>
+         <item row="2" column="0">
+          <widget class="QLabel" name="lab_receipt_id">
+           <property name="text">
+            <string>Receipt ID</string>
+           </property>
+           <property name="buddy">
+            <cstring>le_receipt_id</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="2" column="1">
+          <widget class="QLineEdit" name="le_receipt_id"/>
+         </item>
+         <item row="3" column="0">
+          <widget class="QLabel" name="lab_date_time">
+           <property name="text">
+            <string>Date</string>
+           </property>
+           <property name="buddy">
+            <cstring>dte_date_time</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="3" column="1">
+          <widget class="QDateTimeEdit" name="dte_date_time">
+           <property name="displayFormat">
+            <string>yyyy-MM-dd hh:mm:ss</string>
+           </property>
+          </widget>
+         </item>
+         <item row="4" column="0">
+          <widget class="QLabel" name="lab_counter">
+           <property name="text">
+            <string>Counter</string>
+           </property>
+           <property name="buddy">
+            <cstring>le_counter</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="4" column="1">
+          <widget class="QLineEdit" name="le_counter"/>
+         </item>
+         <item row="5" column="0">
+          <widget class="QLabel" name="lab_cert_serial">
+           <property name="text">
+            <string>Cert Serial</string>
+           </property>
+           <property name="buddy">
+            <cstring>le_cert_serial</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="5" column="1">
+          <widget class="QLineEdit" name="le_cert_serial"/>
+         </item>
+         <item row="6" column="0">
+          <widget class="QLabel" name="lab_sig_prev">
+           <property name="text">
+            <string>Sig Prev</string>
+           </property>
+           <property name="buddy">
+            <cstring>le_sig_prev</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="6" column="1">
+          <widget class="QLineEdit" name="le_sig_prev"/>
+         </item>
+         <item row="7" column="0">
+          <widget class="QLabel" name="lab_sig">
+           <property name="text">
+            <string>Sig</string>
+           </property>
+           <property name="buddy">
+            <cstring>le_sig</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="7" column="1">
+          <widget class="QLineEdit" name="le_sig"/>
+         </item>
+        </layout>
+       </item>
+       <item>
+        <widget class="QTableWidget" name="twCash">
+         <row>
+          <property name="text">
+           <string>0</string>
+          </property>
+         </row>
+         <row>
+          <property name="text">
+           <string>1</string>
+          </property>
+         </row>
+         <row>
+          <property name="text">
+           <string>2</string>
+          </property>
+         </row>
+         <row>
+          <property name="text">
+           <string>3</string>
+          </property>
+         </row>
+         <row>
+          <property name="text">
+           <string>4</string>
+          </property>
+         </row>
+         <column>
+          <property name="text">
+           <string>Cash</string>
+          </property>
+         </column>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
    </layout>
   </widget>
   <widget class="QMenuBar" name="menuBar">
    <container>1</container>
   </customwidget>
  </customwidgets>
+ <tabstops>
+  <tabstop>pbCapture</tabstop>
+  <tabstop>pbAnalyze</tabstop>
+  <tabstop>le_rlat</tabstop>
+  <tabstop>le_device_id</tabstop>
+  <tabstop>le_receipt_id</tabstop>
+  <tabstop>dte_date_time</tabstop>
+  <tabstop>le_counter</tabstop>
+  <tabstop>le_cert_serial</tabstop>
+  <tabstop>le_sig_prev</tabstop>
+  <tabstop>le_sig</tabstop>
+  <tabstop>twCash</tabstop>
+  <tabstop>lineEdit_9</tabstop>
+  <tabstop>lineEdit_10</tabstop>
+  <tabstop>lineEdit_11</tabstop>
+  <tabstop>dateTimeEdit_2</tabstop>
+  <tabstop>tableWidget_2</tabstop>
+  <tabstop>lineEdit_12</tabstop>
+  <tabstop>lineEdit_13</tabstop>
+  <tabstop>lineEdit_14</tabstop>
+  <tabstop>lineEdit_8</tabstop>
+ </tabstops>
  <resources/>
  <connections>
   <connection>