Git commit 5cb879bb2701732ef01626de1a92862b7b42d6cf by Stephane Mankowski.
Committed on 17/10/2017 at 19:44.
Pushed by smankowski into branch 'master'.

Ledger export

M  +2    -2    doc/index.docbook
M  +34   -1    plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp

https://commits.kde.org/skrooge/5cb879bb2701732ef01626de1a92862b7b42d6cf

diff --git a/doc/index.docbook b/doc/index.docbook
index 91eb8181..9d16d00a 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -760,12 +760,12 @@
       
       <sect2 id="export_file">
        <title>Export all your data in one file</title>
-       <para>Using the menu <menuchoice><guimenu>File</guimenu> 
<guimenuitem>Export</guimenuitem></menuchoice>, a CSV, QIF, JSON, Kmymoney, 
IIF, Sqlite, Sqlcipher or XML file will be created, containing all operations 
in the current document. This is the option to choose if you need to export 
your data to another application.</para>
+       <para>Using the menu <menuchoice><guimenu>File</guimenu> 
<guimenuitem>Export</guimenuitem></menuchoice>, a CSV, QIF, JSON, Kmymoney, 
Ledger, IIF, Sqlite, Sqlcipher or XML file will be created, containing all 
operations in the current document. This is the option to choose if you need to 
export your data to another application.</para>
       </sect2>
       
       <sect2 id="export_partial_file">
        <title>Export partially your data in one file</title>
-       <para>If you select some accounts or some operations before using the 
menu <menuchoice><guimenu>File</guimenu> 
<guimenuitem>Export</guimenuitem></menuchoice>, a CSV, QIF, JSON, Kmymoney, 
IIF, Sqlite, Sqlcipher or XML file will be created, containing the selected 
accounts (with their operations) or the selected operation. This is the option 
to choose if you need to export your data to another application.</para>
+       <para>If you select some accounts or some operations before using the 
menu <menuchoice><guimenu>File</guimenu> 
<guimenuitem>Export</guimenuitem></menuchoice>, a CSV, QIF, JSON, Kmymoney, 
Ledger, IIF, Sqlite, Sqlcipher or XML file will be created, containing the 
selected accounts (with their operations) or the selected operation. This is 
the option to choose if you need to export your data to another 
application.</para>
       </sect2>
       
       <sect2 id="export_table">
diff --git a/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp 
b/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp
index 9bbd8842..01b00fb2 100644
--- a/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp
+++ b/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp
@@ -59,6 +59,29 @@ SKGError SKGImportPluginLedger::exportFile()
     if (!file.open(QIODevice::WriteOnly)) {
         err.setReturnCode(ERR_INVALIDARG).setMessage(i18nc("Error message",  
"Save file '%1' failed", m_importer->getFileName().toDisplayString()));
     } else {
+        auto listUUIDs = 
SKGServices::splitCSVLine(m_exportParameters.value(QStringLiteral("uuid_of_selected_accounts_or_operations")));
+
+        QString wc;
+        for (const auto& uuid : listUUIDs) {
+            auto items = SKGServices::splitCSVLine(uuid, '-');
+            if (items.at(1) == QStringLiteral("operation")) {
+                if (!wc.isEmpty()) {
+                    wc += QLatin1String(" AND ");
+                }
+                wc += " i_OPID=" + items.at(0);
+            } else if (items.at(1) == QStringLiteral("account")) {
+                if (!wc.isEmpty()) {
+                    wc += QLatin1String(" AND ");
+                }
+                wc += " rd_account_id=" + items.at(0);
+            }
+        }
+        if (wc.isEmpty()) {
+            wc = QStringLiteral("1=1");
+        }  else {
+            IFOKDO(err, m_importer->getDocument()->sendMessage(i18nc("An 
information message",  "Only selected accounts and operations have been 
exported")))
+        }
+
         QLocale en(QStringLiteral("en_EN"));
 
         QTextStream stream(&file);
@@ -95,7 +118,7 @@ SKGError SKGImportPluginLedger::exportFile()
 
         IFOK(err) {
             SKGObjectBase::SKGListSKGObjectBase operations;
-            err = 
m_importer->getDocument()->getObjects(QStringLiteral("v_operation"), 
QStringLiteral("t_template='N' ORDER BY d_date"), operations);
+            err = 
m_importer->getDocument()->getObjects(QStringLiteral("v_operation"), wc % 
QStringLiteral(" AND t_template='N' ORDER BY d_date"), operations);
             int nb = operations.count();
             IFOK(err) {
                 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" 
% i18nc("Export step", "Export operations"), nb);
@@ -136,6 +159,11 @@ SKGError SKGImportPluginLedger::exportFile()
                            << (number != 0 ? QStringLiteral(" (") % 
SKGServices::intToString(number) % ")" : QStringLiteral(""))
                            << QStringLiteral(" ") << payeeString
                            << endl;
+                    stream << "  ; Skrooge ID: " << op.getID() << endl;
+                    stream << "  ; Import ID: " << op.getImportID() << endl;
+                    for (const auto p : op.getProperties()) {
+                        stream << "  ; " << p << ": " << op.getProperty(p) << 
endl;
+                    }
                     stream << "  " << i18nc("The default category for the 
accounts for ledger export", "Account") << ':' << 
op.getAttribute(QStringLiteral("t_ACCOUNT"))
                            << "  " << qs
                            << endl;
@@ -160,10 +188,15 @@ SKGError SKGImportPluginLedger::exportFile()
 
                         stream << "  " << i18nc("The default category for the 
categories for ledger export", "Category") << ':' <<  catString
                                << "  " << qs;
+                        if (sop.getDate()!=op.getDate()) {
+                            stream << "  ; [=" << 
SKGServices::dateToSqlString(sop.getDate()).replace('-', '/') << "]";
+                        }
+
                         auto comment = sop.getComment();
                         if (!comment.isEmpty()) {
                             stream << "  ;comment=" << comment;
                         }
+                        stream << "  ; Skrooge ID: " << sop.getID();
                         stream << endl;
                     }
                     stream << endl;

Reply via email to