File indexing completed on 2024-05-12 16:45:20

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 /** @file
0007  * This file is a test script.
0008  *
0009  * @author Stephane MANKOWSKI / Guillaume DE BURE
0010  */
0011 #include "skgtestmacro.h"
0012 #include "skgbankincludes.h"
0013 #include "skgimportexportmanager.h"
0014 
0015 /**
0016  * The main function of the unit test
0017  * @param argc the number of arguments
0018  * @param argv the list of arguments
0019  */
0020 int main(int argc, char** argv)
0021 {
0022     Q_UNUSED(argc)
0023     Q_UNUSED(argv)
0024 
0025     // Init test
0026     SKGINITTEST(true)
0027 
0028     QDate now = QDate::currentDate();
0029 
0030     {
0031         // Test import SKGImportExportManager::CSV skrooge
0032         SKGDocumentBank document1;
0033         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0034 
0035         SKGError err;
0036         {
0037             // Scope of the transaction
0038             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_CSV"), err)
0039             SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.csv")));
0040             impmissing.setAutomaticApplyRules(true);
0041             SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false)
0042 
0043             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/skrooge_partial.csv"));
0044             SKGTEST(QStringLiteral("imp1:getImportMimeTypeFilter"), imp1.getImportMimeTypeFilter().split('\n').count(), 2);
0045             SKGTEST(QStringLiteral("imp1:getExportMimeTypeFilter"), imp1.getExportMimeTypeFilter().split('\n').count(), 2);
0046 
0047             SKGImportExportManager generic;
0048             SKGTEST(QStringLiteral("SKGImportExportManager().getImportMimeTypeFilter"), generic.getImportMimeTypeFilter().split('\n').count(), 19);
0049             SKGTEST(QStringLiteral("SKGImportExportManager().getExportMimeTypeFilter"), generic.getExportMimeTypeFilter().split('\n').count(), 11);
0050             imp1.setCodec(QLatin1String(""));
0051             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0052         }
0053         SKGAccountObject account;
0054         SKGTESTERROR(QStringLiteral("ACCOUNT.getObjectByName"), SKGNamedObject::getObjectByName(&document1, QStringLiteral("v_account"), QStringLiteral("Courant steph"), account), true)
0055         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0056         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-935"))
0057         SKGTEST(QStringLiteral("document1:getCategoryForPayee"), document1.getCategoryForPayee(QStringLiteral("Anthony Hopkins"), false), QStringLiteral("Entertain > Movie"))
0058         SKGTEST(QStringLiteral("document1:getCategoryForPayee"), document1.getCategoryForPayee(QStringLiteral("NOT FOUND")), QLatin1String(""))
0059     }
0060 
0061     {
0062         // Test import QIF 1
0063         SKGDocumentBank document1;
0064         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0065         SKGBankObject bank(&document1);
0066         SKGAccountObject account;
0067         SKGUnitObject unit_euro(&document1);
0068         SKGError err;
0069         {
0070             // Scope of the transaction
0071             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_INIT"), err)
0072 
0073             // Creation bank
0074             SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true)
0075             SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true)
0076 
0077             // Creation account
0078             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account), true)
0079             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account.setName(QStringLiteral("Courant steph")), true)
0080             SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account.setNumber(QStringLiteral("12345P")), true)
0081             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true)
0082 
0083             // Creation unit
0084             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true)
0085             SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true)
0086 
0087             // Creation unitvalue
0088             SKGUnitValueObject unit_euro_val1;
0089             SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true)
0090             SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true)
0091             SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(now), true)
0092             SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
0093         }
0094 
0095         {
0096             // Scope of the transaction
0097             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_CSV"), err)
0098             // Date;Libelle;Libelle complementaire;Montant;Sens;Numero de cheque
0099             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/coopanet.csv"));
0100             QMap<QString, QString> parameters = imp1.getImportParameters();
0101             parameters[QStringLiteral("automatic_search_header")] = 'N';
0102             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|comment||amount|sign|number");
0103             imp1.setImportParameters(parameters);
0104             SKGTESTERROR(QStringLiteral("QIF.setDefaultAccount"), imp1.setDefaultAccount(&account), true)
0105             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0106         }
0107         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0108         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-680.28"))
0109     }
0110 
0111     {
0112         // Test import bankperfect
0113         SKGDocumentBank document1;
0114         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0115         SKGBankObject bank(&document1);
0116         SKGAccountObject account1;
0117         SKGAccountObject account2;
0118         SKGUnitObject unit_euro(&document1);
0119         SKGError err;
0120         {
0121             // Scope of the transaction
0122             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_INIT"), err)
0123 
0124             // Creation bank
0125             SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true)
0126             SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true)
0127 
0128             // Creation account
0129             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account1), true)
0130             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account1.setName(QStringLiteral("Courant steph")), true)
0131             SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account1.setNumber(QStringLiteral("12345P")), true)
0132             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account1.save(), true)
0133 
0134             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account2), true)
0135             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account2.setName(QStringLiteral("PEL")), true)
0136             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account2.save(), true)
0137 
0138             // Creation unit
0139             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true)
0140             SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true)
0141 
0142             // Creation unitvalue
0143             SKGUnitValueObject unit_euro_val1;
0144             SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true)
0145             SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true)
0146             SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(now), true)
0147             SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
0148         }
0149 
0150         {
0151             // Scope of the transaction
0152             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_BP_CSV"), err)
0153             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/bankperfect.csv"));
0154             SKGTESTERROR(QStringLiteral("QIF.setDefaultAccount"), imp1.setDefaultAccount(&account1), true)
0155             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0156         }
0157 
0158         {
0159             // Scope of the transaction
0160             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_BP_CSV"), err)
0161             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/bankperfect2.csv"));
0162             SKGTESTERROR(QStringLiteral("QIF.setDefaultAccount"), imp1.setDefaultAccount(&account2), true)
0163             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0164 
0165             int NbOperationsMerged = 0;
0166             SKGTESTERROR(QStringLiteral("imp1.findAndGroupTransfers"), imp1.findAndGroupTransfers(NbOperationsMerged), true)
0167             SKGTEST(QStringLiteral("imp1:NbOperationsMerged"), NbOperationsMerged, 6)
0168         }
0169         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account1.load(), true)
0170         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account1.getCurrentAmount()), QStringLiteral("2624.071111"))
0171 
0172         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account2.load(), true)
0173         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account2.getCurrentAmount()), QStringLiteral("1500"))
0174 
0175         SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportcsv/bankperfect.csv"));
0176         SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), exp1.exportFile(), true)
0177 
0178         {
0179             SKGStringListList oTable;
0180             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QStringLiteral("d_DATEMONTH"), QStringLiteral("t_CATEGORY"), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0181             QStringList dump = SKGServices::tableToDump(oTable, SKGServices::DUMP_TEXT);
0182             int nbl = dump.count();
0183             for (int i = 0; i < nbl; ++i) {
0184                 SKGTRACE << dump.at(i) << SKGENDL;
0185             }
0186         }
0187         {
0188             SKGStringListList oTable;
0189             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QLatin1String(""), QStringLiteral("t_CATEGORY"), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0190             QStringList dump = SKGServices::tableToDump(oTable, SKGServices::DUMP_TEXT);
0191             int nbl = dump.count();
0192             for (int i = 0; i < nbl; ++i) {
0193                 SKGTRACE << dump.at(i) << SKGENDL;
0194             }
0195         }
0196         {
0197             SKGStringListList oTable;
0198             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QStringLiteral("d_DATEWEEK"), QLatin1String(""), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0199             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QStringLiteral("d_DATEQUARTER"), QLatin1String(""), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0200             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QStringLiteral("d_DATESEMESTER"), QLatin1String(""), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0201             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QStringLiteral("d_DATEYEAR"), QLatin1String(""), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0202             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QStringLiteral("d_date"), QLatin1String(""), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0203             SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), document1.getConsolidatedView(QStringLiteral("v_operation_display"), QStringLiteral("d_DATEMONTH"), QLatin1String(""), QStringLiteral("f_CURRENTAMOUNT"), QStringLiteral("SUM"), QLatin1String(""), oTable), true)
0204             QStringList dump = SKGServices::tableToDump(oTable, SKGServices::DUMP_TEXT);
0205             int nbl = dump.count();
0206             for (int i = 0; i < nbl; ++i) {
0207                 SKGTRACE << dump.at(i) << SKGENDL;
0208             }
0209         }
0210     }
0211 
0212     {
0213         // Test import skrooge
0214         SKGDocumentBank document1;
0215         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0216         SKGError err;
0217         {
0218             // Scope of the transaction
0219             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKROOGE_CSV"), err)
0220             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportcsv/bankperfect.csv"));
0221             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0222         }
0223 
0224         SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportcsv/bankperfect2.csv"));
0225         SKGTESTERROR(QStringLiteral("SKGImportExportManager::CSV.exportFile"), exp1.exportFile(), true)
0226     }
0227 
0228     {
0229         // Test import skrooge+optimization
0230         SKGDocumentBank document1;
0231         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0232         SKGError err;
0233         {
0234             // Scope of the transaction
0235             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_OPTIM"), err)
0236             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/bankperfect.csv"));
0237             SKGTESTERROR(QStringLiteral("OPTIM.importFile"), imp1.importFile(), true)
0238         }
0239 
0240         SKGTESTERROR(QStringLiteral("OPTIM.undoRedoTransaction"), document1.undoRedoTransaction(SKGDocument::UNDOLASTSAVE), true)
0241     }
0242 
0243     {
0244         // Test import skrooge in double to check merge
0245         SKGDocumentBank document1;
0246         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0247         SKGError err;
0248         {
0249             // Scope of the transaction
0250             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0251             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/remi_1.csv"));
0252             SKGTESTERROR(QStringLiteral("OPTIM.importFile"), imp1.importFile(), true)
0253         }
0254         {
0255             // Scope of the transaction
0256             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0257             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/remi_1.csv"));
0258             SKGTESTERROR(QStringLiteral("OPTIM.importFile"), imp1.importFile(), true)
0259         }
0260 
0261         SKGAccountObject account(&document1);
0262         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.setName(QStringLiteral("remi 1")), true)
0263         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0264         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-767.26"))
0265     }
0266     {
0267         // Test import 2638120
0268         SKGDocumentBank document1;
0269         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0270         SKGError err;
0271         {
0272             // Scope of the transaction
0273             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0274             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/XXXXXXMxxxXXXXXXX.csv"));
0275             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0276         }
0277 
0278         SKGAccountObject account(&document1);
0279         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.setName(QStringLiteral("XXXXXXMxxxXXXXXXX")), true)
0280         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0281         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("8114.26"))
0282     }
0283     {
0284         // Test import 206894
0285         SKGDocumentBank document1;
0286         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0287         SKGError err;
0288         {
0289             // Scope of the transaction
0290             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0291             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/206894.csv"));
0292             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0293         }
0294 
0295         SKGAccountObject account(&document1);
0296         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.setName(QStringLiteral("206894")), true)
0297         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0298         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-2986.39"))
0299     }
0300     {
0301         // Test import 397055
0302         SKGDocumentBank document1;
0303         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0304         SKGError err;
0305         {
0306             // Scope of the transaction
0307             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0308             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/397055.csv"));
0309             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0310         }
0311 
0312         SKGAccountObject account(&document1);
0313         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.setName(QStringLiteral("397055")), true)
0314         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0315         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("50"))
0316     }
0317     {
0318         // Test import with tabulation
0319         SKGDocumentBank document1;
0320         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0321         SKGError err;
0322         {
0323             // Scope of the transaction
0324             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0325             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/mutual fund.csv"));
0326             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0327         }
0328 
0329 
0330         SKGAccountObject account(&document1);
0331         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.setName(QStringLiteral("Janus Twenty Fund")), true)
0332         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0333         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("24.51428572"))
0334     }
0335 
0336     {
0337         // Test import shares with original amount
0338         SKGDocumentBank document1;
0339         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0340         SKGError err;
0341         {
0342             // Scope of the transaction
0343             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0344             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/209705.csv"));
0345             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0346         }
0347         {
0348             // Scope of the transaction
0349             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0350             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/209705_2.csv"));
0351             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0352         }
0353         {
0354             // Scope of the transaction
0355             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0356             SKGImportExportManager imp1(&document1);
0357 
0358             int out = 0;
0359             SKGTESTERROR(QStringLiteral("CSV.findAndGroupTransfers"), imp1.findAndGroupTransfers(out), true)
0360             SKGTEST(QStringLiteral("CSV:nb"), out, 2)
0361         }
0362 
0363         SKGObjectBase::SKGListSKGObjectBase grouped;
0364         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getObjects(QStringLiteral("operation"), QStringLiteral("i_group_id!=0"), grouped), true)
0365         SKGTEST(QStringLiteral("CSV:grouped.count"), grouped.count(), 2)
0366     }
0367 
0368     {
0369         // Test import transactions split and grouped
0370         SKGAccountObject la;
0371         SKGDocumentBank document1;
0372         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0373         SKGError err;
0374         {
0375             // Scope of the transaction
0376             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0377             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/compte.csv"));
0378             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0379 
0380             SKGObjectBase::SKGListSKGObjectBase banks;
0381             SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getObjects(QStringLiteral("bank"), QLatin1String(""), banks), true)
0382             SKGBankObject bank(banks.at(0));
0383             bank.setName(QStringLiteral("bp"));
0384             bank.save();
0385         }
0386 
0387         SKGObjectBase::SKGListSKGObjectBase grouped;
0388         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getObjects(QStringLiteral("operation"), QLatin1String(""), grouped), true)
0389         SKGTEST(QStringLiteral("CSV:grouped.count"), grouped.count(), 4)
0390         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getObjects(QStringLiteral("operation"), QStringLiteral("i_group_id!=0"), grouped), true)
0391         SKGTEST(QStringLiteral("CSV:grouped.count"), grouped.count(), 2)
0392 
0393         SKGObjectBase::SKGListSKGObjectBase result;
0394         SKGTESTERROR(QStringLiteral("DOC.getObjects"), document1.getObjects(QStringLiteral("account"), QStringLiteral("t_name='PEL'"), result), true)
0395         SKGTEST(QStringLiteral("DOC.getObjects.count"), result.count(), 1)
0396         if (result.count() != 0) {
0397             la = result.at(0);
0398         }
0399 
0400         {
0401             // Scope of the transaction
0402             SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_CSV"), err)
0403             SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportcsv/export_all.csv"));
0404             SKGTESTERROR(QStringLiteral("QIF.exportFile"), exp1.exportFile(), true)
0405         }
0406         {
0407             // Scope of the transaction
0408             SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_CSV"), err)
0409             SKGImportExportManager exp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportcsv/export_la.csv"));
0410             QMap<QString, QString> params;
0411             params[QStringLiteral("uuid_of_selected_accounts_or_operations")] = la.getUniqueID();
0412             exp1.setExportParameters(params);
0413             SKGTESTERROR(QStringLiteral("QIF.exportFile"), exp1.exportFile(), true)
0414         }
0415     }
0416 
0417     {
0418         // Test import mmex
0419         SKGDocumentBank document1;
0420         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0421         SKGError err;
0422         {
0423             // Scope of the transaction
0424             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0425             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/mmex.csv"));
0426             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0427         }
0428 
0429         int nb = 0;
0430         SKGTESTERROR(QStringLiteral("CATEGORY.getNbObjects"), document1.getNbObjects(QStringLiteral("category"), QStringLiteral("t_fullname='Alimentation > Restaurant'"), nb), true)
0431         SKGTEST(QStringLiteral("CATEGORY:nb"), nb, 1)
0432 
0433         SKGAccountObject account(&document1);
0434         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("mmex")), true)
0435         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0436         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1418.44"))
0437     }
0438     {
0439         // Test import mmex
0440         SKGDocumentBank document1;
0441         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0442         SKGError err;
0443         {
0444             // Scope of the transaction
0445             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0446             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/mmex_no_header.csv"));
0447             QMap<QString, QString> parameters = imp1.getImportParameters();
0448             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0449             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|comment|sign|amount|category");
0450             parameters[QStringLiteral("automatic_search_header")] = 'N';
0451             parameters[QStringLiteral("header_position")] = '0';
0452             imp1.setImportParameters(parameters);
0453             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0454         }
0455 
0456 
0457         SKGAccountObject account(&document1);
0458         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("mmex no header")), true)
0459         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0460         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1418.44"))
0461     }
0462     {
0463         // 263263
0464         SKGDocumentBank document1;
0465         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0466         SKGError err;
0467         {
0468             // Scope of the transaction
0469             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0470             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/263263.csv"));
0471             QMap<QString, QString> parameters = imp1.getImportParameters();
0472             parameters[QStringLiteral("mapping_debit")] = QStringLiteral("kreditrente");
0473             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0474             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date||number|sign|comment|amount|amount");
0475             parameters[QStringLiteral("automatic_search_header")] = 'N';
0476             parameters[QStringLiteral("header_position")] = '1';
0477             imp1.setImportParameters(parameters);
0478             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0479         }
0480 
0481         SKGAccountObject account(&document1);
0482         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("263263")), true)
0483         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0484         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("800.09"))
0485     }
0486     {
0487         // CREDIT-DEBIT
0488         SKGDocumentBank document1;
0489         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0490         SKGError err;
0491         {
0492             // Scope of the transaction
0493             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0494             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/credit-debit.csv"));
0495             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0496         }
0497 
0498         SKGAccountObject account(&document1);
0499         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("credit debit")), true)
0500         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0501         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1500"))
0502     }
0503     {
0504         // BACKSLASHES
0505         SKGDocumentBank document1;
0506         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0507         SKGError err;
0508         {
0509             // Scope of the transaction
0510             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0511             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/backslashes.csv"));
0512             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0513         }
0514 
0515         SKGAccountObject account(&document1);
0516         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("backslashes")), true)
0517         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0518         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1000"))
0519     }
0520     {
0521         // MULTILINE
0522         SKGDocumentBank document1;
0523         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0524         SKGError err;
0525         {
0526             // Scope of the transaction
0527             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0528             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/multiline.csv"));
0529             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0530         }
0531 
0532         SKGAccountObject account(&document1);
0533         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("multiline")), true)
0534         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0535         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("3000"))
0536     }
0537 
0538     {
0539         // MULTILINE
0540         SKGDocumentBank document1;
0541         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0542         SKGError err;
0543         {
0544             // Scope of the transaction
0545             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0546             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/non_numerical_amount.csv"));
0547             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0548         }
0549 
0550         SKGAccountObject account(&document1);
0551         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("non numerical amount")), true)
0552         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0553         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-119.56"))
0554     }
0555 
0556     {
0557         // Test import 320112
0558         SKGDocumentBank document1;
0559         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0560         SKGError err;
0561         {
0562             // Scope of the transaction
0563             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0564             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/320112.csv"));
0565             QMap<QString, QString> parameters = imp1.getImportParameters();
0566             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0567             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|mode|payee|comment|amount");
0568             imp1.setImportParameters(parameters);
0569             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0570         }
0571 
0572         SKGAccountObject account(&document1);
0573         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("320112")), true)
0574         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0575         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("6.13"))
0576     }
0577 
0578     {
0579         // Test import date DDMMMYYYY
0580         SKGDocumentBank document1;
0581         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0582         SKGError err;
0583         {
0584             // Scope of the transaction
0585             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0586             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/date_DDMMMYYYY.csv"));
0587             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0588         }
0589 
0590         document1.dump(DUMPOPERATION | DUMPACCOUNT);
0591         SKGAccountObject account(&document1);
0592         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("date DDMMMYYYY")), true)
0593         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0594         SKGTEST(QStringLiteral("ACCOUNT:getAmount"), SKGServices::doubleToString(account.getAmount(QDate(2004, 12, 31))), QStringLiteral("35"))
0595     }
0596 
0597     {
0598         // Test import separator tab
0599         SKGDocumentBank document1;
0600         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0601         SKGError err;
0602         {
0603             // Scope of the transaction
0604             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0605             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/tabs.csv"));
0606             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0607         }
0608     }
0609 
0610     {
0611         // Test import separator comma
0612         SKGDocumentBank document1;
0613         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0614         SKGError err;
0615         {
0616             // Scope of the transaction
0617             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0618             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/commas.csv"));
0619             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0620         }
0621     }
0622 
0623 
0624     {
0625         // BUG 406488
0626         //
0627         // "Date","Type","Number","Payee","Withdrawal (-)","Amount"
0628         SKGDocumentBank document1;
0629         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0630         SKGError err;
0631         {
0632             // Scope of the transaction
0633             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0634             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/406488.csv"));
0635             QMap<QString, QString> parameters = imp1.getImportParameters();
0636             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0637             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|mode|number|payee|amount|amount");
0638             imp1.setImportParameters(parameters);
0639             SKGError err = imp1.importFile();
0640             SKGTESTERROR(QStringLiteral("CSV.importFile"), err, false)
0641             SKGTEST(QStringLiteral("CSV:error message"), err.getMessage(), QStringLiteral("Invalid number of columns in line 2. Expected 6. Found 1."))
0642         }
0643     }
0644 
0645     {
0646         // Test import separator comma
0647         SKGDocumentBank document1;
0648         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0649         SKGError err;
0650         {
0651             // Scope of the transaction
0652             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0653             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/349961.csv"));
0654             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0655         }
0656         int nb = 0;
0657         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getNbObjects(QStringLiteral("operation"), QLatin1String(""), nb), true)
0658         SKGTEST(QStringLiteral("CSV:nb transactions"), nb, 1)
0659         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getNbObjects(QStringLiteral("suboperation"), QStringLiteral("d_date='2015-07-07'"), nb), true)
0660         SKGTEST(QStringLiteral("CSV:nb subtransactions 2015-07-07"), nb, 1)
0661         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getNbObjects(QStringLiteral("suboperation"), QStringLiteral("d_date='2015-07-08'"), nb), true)
0662         SKGTEST(QStringLiteral("CSV:nb subtransactions 2015-07-08"), nb, 1)
0663         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getNbObjects(QStringLiteral("suboperation"), QStringLiteral("d_date='2015-07-09'"), nb), true)
0664         SKGTEST(QStringLiteral("CSV:nb subtransactions 2015-07-09"), nb, 1)
0665     }
0666 
0667     {
0668         // Test import separator comma
0669         SKGDocumentBank document1;
0670         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0671         SKGError err;
0672         {
0673             // Scope of the transaction
0674             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0675             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/362231.csv"));
0676             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0677         }
0678         int nb = 0;
0679         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getNbObjects(QStringLiteral("operation"), QStringLiteral("d_date!='0000-00-00'"), nb), true)
0680         SKGTEST(QStringLiteral("CSV:nb operation"), nb, 1)
0681         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getNbObjects(QStringLiteral("suboperation"), QStringLiteral("d_date='2016-05-15'"), nb), true)
0682         SKGTEST(QStringLiteral("CSV:nb subtransactions 2016-05-15"), nb, 1)
0683         SKGTESTERROR(QStringLiteral("CSV.getObjects"), document1.getNbObjects(QStringLiteral("suboperation"), QStringLiteral("d_date='2016-05-20'"), nb), true)
0684         SKGTEST(QStringLiteral("CSV:nb subtransactions 2016-05-20"), nb, 1)
0685     }
0686 
0687     {
0688         // 381562
0689         SKGDocumentBank document1;
0690         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0691         SKGBankObject bank(&document1);
0692         SKGAccountObject account;
0693         SKGUnitObject unit_euro(&document1);
0694         SKGError err;
0695         {
0696             // Scope of the transaction
0697             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_INIT"), err)
0698 
0699             // Creation bank
0700             SKGTESTERROR(QStringLiteral("BANK:setName"), bank.setName(QStringLiteral("CREDIT COOP")), true)
0701             SKGTESTERROR(QStringLiteral("BANK:save"), bank.save(), true)
0702 
0703             // Creation account
0704             SKGTESTERROR(QStringLiteral("BANK:addAccount"), bank.addAccount(account), true)
0705             SKGTESTERROR(QStringLiteral("ACCOUNT:setName"), account.setName(QStringLiteral("Courant steph")), true)
0706             SKGTESTERROR(QStringLiteral("ACCOUNT:setNumber"), account.setNumber(QStringLiteral("DE00 1234 5678 9012 3456 78")), true)
0707             SKGTESTERROR(QStringLiteral("ACCOUNT:save"), account.save(), true)
0708 
0709             // Creation unit
0710             SKGTESTERROR(QStringLiteral("UNIT:setName"), unit_euro.setName(QStringLiteral("euro")), true)
0711             SKGTESTERROR(QStringLiteral("UNIT:save"), unit_euro.save(), true)
0712 
0713             // Creation unitvalue
0714             SKGUnitValueObject unit_euro_val1;
0715             SKGTESTERROR(QStringLiteral("UNIT:addUnitValue"), unit_euro.addUnitValue(unit_euro_val1), true)
0716             SKGTESTERROR(QStringLiteral("UNITVALUE:setQuantity"), unit_euro_val1.setQuantity(1), true)
0717             SKGTESTERROR(QStringLiteral("UNITVALUE:setDate"), unit_euro_val1.setDate(now), true)
0718             SKGTESTERROR(QStringLiteral("UNITVALUE:save"), unit_euro_val1.save(), true)
0719         }
0720 
0721         {
0722             // Scope of the transaction
0723             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_CSV"), err)
0724             // Date;Libelle;Libelle complementaire;Montant;Sens;Numero de cheque
0725             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/DE00 1234 5678 9012 3456 78.csv"));
0726             QMap<QString, QString> parameters = imp1.getImportParameters();
0727             parameters[QStringLiteral("automatic_search_header")] = 'N';
0728             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|comment||amount|sign|number");
0729             imp1.setImportParameters(parameters);
0730             SKGTESTERROR(QStringLiteral("imp1.importFile"), imp1.importFile(), true)
0731         }
0732         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0733         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-680.28"))
0734     }
0735 
0736     {
0737         // Test 411958
0738         SKGDocumentBank document1;
0739         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0740         SKGError err;
0741         {
0742             // Scope of the transaction
0743             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0744             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/411958.csv"));
0745             QMap<QString, QString> parameters = imp1.getImportParameters();
0746             parameters[QStringLiteral("mapping_date")] = QStringLiteral("^Buchungstag");
0747             parameters[QStringLiteral("mapping_payee")] = QStringLiteral("^payee|^tiers|^.*Zahlungspflichtiger");
0748             parameters[QStringLiteral("mapping_comment")] = QStringLiteral("^comment|^libell?|^d?tail|^info|^Vorgang.*");
0749             parameters[QStringLiteral("mapping_amount")] = QStringLiteral("^value|^amount|^valeur|^montant|^credit|^debit|^Umsatz");
0750             parameters[QStringLiteral("mapping_account")] = QStringLiteral("^Konto");
0751             parameters[QStringLiteral("mapping_sign")] = QStringLiteral("^sign|^sens");
0752             parameters[QStringLiteral("mapping_unit")] = QStringLiteral("^Währung");
0753             parameters[QStringLiteral("mapping_debit")] = QStringLiteral("^S");
0754             parameters[QStringLiteral("automatic_search_columns")] = 'Y';
0755             parameters[QStringLiteral("automatic_search_header")] = 'Y';
0756             imp1.setImportParameters(parameters);
0757 
0758             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0759         }
0760 
0761         SKGAccountObject account(&document1);
0762         SKGTESTERROR(QStringLiteral("ACCOUNT.setName"), account.setName(QStringLiteral("411958")), true)
0763         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0764         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("658.88"))
0765     }
0766 
0767     {
0768         // Test import with footer
0769         SKGDocumentBank document1;
0770         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0771         SKGError err;
0772         {
0773             // Scope of the transaction
0774             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0775             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/footer.csv"));
0776             QMap<QString, QString> parameters = imp1.getImportParameters();
0777             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0778             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|mode|payee|amount|");
0779             imp1.setImportParameters(parameters);
0780             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0781         }
0782 
0783         SKGAccountObject account(&document1);
0784         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.setName(QStringLiteral("footer")), true)
0785         SKGTESTERROR(QStringLiteral("ACCOUNT.load"), account.load(), true)
0786         SKGTEST(QStringLiteral("ACCOUNT:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-2"))
0787     }
0788 
0789     {
0790         // Test import separator comma
0791         SKGDocumentBank document1;
0792         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0793         SKGError err;
0794         {
0795             // Scope of the transaction
0796             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0797             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/commas_2.csv"));
0798             QMap<QString, QString> parameters = imp1.getImportParameters();
0799             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0800             parameters[QStringLiteral("header_position")] = QStringLiteral("1");
0801             parameters[QStringLiteral("columns_positions")] = QStringLiteral("|date||payee|amount||||mode");
0802             imp1.setImportParameters(parameters);
0803             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0804         }
0805     }
0806 
0807     {
0808         // Test import BUG 420557
0809         SKGDocumentBank document1;
0810         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0811         SKGError err;
0812         {
0813             // Scope of the transaction
0814             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0815             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/420557_1.csv"));
0816             QMap<QString, QString> parameters = imp1.getImportParameters();
0817             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0818             parameters[QStringLiteral("header_position")] = QStringLiteral("1");
0819             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|account|idgroup|idtransaction|value|unit");
0820             imp1.setImportParameters(parameters);
0821             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0822         }
0823 
0824         int nb = 0;
0825         SKGTESTERROR(QStringLiteral("OPERATION.getNbObjects"), document1.getNbObjects(QStringLiteral("operation"), QStringLiteral("i_group_id=1"), nb), true)
0826         SKGTEST(QStringLiteral("OPERATION:nb"), nb, 2)
0827     }
0828 
0829     {
0830         // Test import BUG 420557
0831         SKGDocumentBank document1;
0832         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0833         SKGError err;
0834         {
0835             // Scope of the transaction
0836             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT"), err)
0837             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/420557_2.csv"));
0838             QMap<QString, QString> parameters = imp1.getImportParameters();
0839             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0840             parameters[QStringLiteral("header_position")] = QStringLiteral("1");
0841             parameters[QStringLiteral("columns_positions")] = QStringLiteral("date|account|idgroup|idtransaction|value|unit");
0842             imp1.setImportParameters(parameters);
0843             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0844         }
0845 
0846         int nb = 0;
0847         SKGTESTERROR(QStringLiteral("OPERATION.getNbObjects"), document1.getNbObjects(QStringLiteral("operation"), QStringLiteral("i_group_id=1"), nb), true)
0848         SKGTEST(QStringLiteral("OPERATION:nb"), nb, 2)
0849     }
0850 
0851     {
0852         // 421302
0853         SKGDocumentBank document1;
0854         SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
0855         SKGError err;
0856         {
0857             // Create an account without number
0858             SKGBEGINTRANSACTION(document1, QStringLiteral("CREATE_ACCOUNT"), err)
0859             SKGTESTERROR(QStringLiteral("DOC.addOrModifyAccount"), document1.addOrModifyAccount(QStringLiteral("COURANT"), QStringLiteral("5823485"), QStringLiteral("BANK")), true)
0860             SKGObjectBase account;
0861             SKGTESTERROR(QStringLiteral("DOC.getObject"), document1.getObject(QStringLiteral("v_account"), QStringLiteral("t_name='COURANT'"), account), true)
0862             SKGTESTERROR(QStringLiteral("ACCOUNT.setProperty"), account.setProperty(QStringLiteral("alias"), QStringLiteral("XXXX485")), true)
0863         }
0864         {
0865             // Scope of the transaction
0866             SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_OFX"), err)
0867             SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportcsv/XXXX485.csv"));
0868             QMap<QString, QString> parameters = imp1.getImportParameters();
0869             parameters[QStringLiteral("automatic_search_columns")] = 'N';
0870             parameters[QStringLiteral("header_position")] = QStringLiteral("1");
0871             parameters[QStringLiteral("columns_positions")] = QStringLiteral("|date||payee|amount||||mode");
0872             imp1.setImportParameters(parameters);
0873             SKGTESTERROR(QStringLiteral("CSV.importFile"), imp1.importFile(), true)
0874             document1.dump(DUMPACCOUNT | DUMPPARAMETERS);
0875             int nb2 = 0;
0876             SKGTESTERROR(QStringLiteral("imp1.getNbObjects"), document1.getNbObjects(QStringLiteral("account"), QString(), nb2), true)
0877             SKGTEST(QStringLiteral("ACCOUNT:nb"), SKGServices::intToString(nb2), QStringLiteral("1"))
0878         }
0879     }
0880     // End test
0881     SKGENDTEST()
0882 }  // NOLINT(readability/fn_size)