File indexing completed on 2024-06-16 04:47:19
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 Skrooge plugin for GSB import / export. 0008 * 0009 * @author Stephane MANKOWSKI / Guillaume DE BURE 0010 */ 0011 #include "skgimportplugingsb.h" 0012 0013 #include <kcompressiondevice.h> 0014 #include <klocalizedstring.h> 0015 #include <kpluginfactory.h> 0016 0017 #include "skgbankincludes.h" 0018 #include "skgimportexportmanager.h" 0019 #include "skgobjectbase.h" 0020 #include "skgpayeeobject.h" 0021 #include "skgservices.h" 0022 #include "skgtraces.h" 0023 0024 /** 0025 * This plugin factory. 0026 */ 0027 K_PLUGIN_CLASS_WITH_JSON(SKGImportPluginGsb, "metadata.json") 0028 0029 SKGImportPluginGsb::SKGImportPluginGsb(QObject* iImporter, const QVariantList& iArg) 0030 : SKGImportPlugin(iImporter) 0031 { 0032 SKGTRACEINFUNC(10) 0033 Q_UNUSED(iArg) 0034 } 0035 0036 SKGImportPluginGsb::~SKGImportPluginGsb() 0037 = default; 0038 0039 bool SKGImportPluginGsb::isImportPossible() 0040 { 0041 SKGTRACEINFUNC(10) 0042 return (m_importer->getDocument() == nullptr ? true : m_importer->getFileNameExtension() == QStringLiteral("GSB")); 0043 } 0044 0045 SKGError SKGImportPluginGsb::importFile() 0046 { 0047 if (m_importer->getDocument() == nullptr) { 0048 return SKGError(ERR_ABORT, i18nc("Error message", "Invalid parameters")); 0049 } 0050 SKGError err; 0051 SKGTRACEINFUNCRC(2, err) 0052 0053 // Initialisation 0054 // Open file 0055 KCompressionDevice file(m_importer->getLocalFileName(), KCompressionDevice::GZip); 0056 if (!file.open(QIODevice::ReadOnly)) { 0057 err.setReturnCode(ERR_INVALIDARG).setMessage(i18nc("Error message", "Open file '%1' failed", m_importer->getFileName().toDisplayString())); 0058 } else { 0059 QDomDocument doc; 0060 0061 // Set the file without uncompression 0062 QString errorMsg; 0063 int errorLine = 0; 0064 int errorCol = 0; 0065 bool contentOK = doc.setContent(file.readAll(), &errorMsg, &errorLine, &errorCol); 0066 file.close(); 0067 0068 // Get root 0069 QDomElement docElem = doc.documentElement(); 0070 0071 if (!contentOK) { 0072 err.setReturnCode(ERR_ABORT).setMessage(i18nc("Error message", "%1-%2: '%3'", errorLine, errorCol, errorMsg)); 0073 } else { 0074 // Check version 0075 QDomElement general = docElem.firstChildElement(QStringLiteral("General")); 0076 if (general.isNull()) { 0077 err.setReturnCode(ERR_ABORT).setMessage(i18nc("Error message", "Bad version of Grisbi document. Version must be >= 0.6.0")); 0078 contentOK = false; 0079 } 0080 } 0081 0082 if (!contentOK) { 0083 err.addError(ERR_INVALIDARG, i18nc("Error message", "Invalid XML content in file '%1'", m_importer->getFileName().toDisplayString())); 0084 } else { 0085 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import %1 file", "GSB"), 10); 0086 0087 QMap<QString, SKGUnitObject> mapIdUnit; 0088 QMap<QString, SKGBankObject> mapIdBank; 0089 QMap<QString, SKGAccountObject> mapIdAccount; 0090 QMap<QString, SKGCategoryObject> mapIdCategory; 0091 QMap<QString, SKGOperationObject> mapIdOperation; 0092 QMap<QString, SKGPayeeObject> mapIdPayee; 0093 QMap<QString, QString> mapIdMode; 0094 QMap<QString, QString> mapIdBudgetCat; 0095 0096 // Step 1-Create units 0097 IFOK(err) { 0098 QDomNodeList currencyList = docElem.elementsByTagName(QStringLiteral("Currency")); 0099 int nb = currencyList.count(); 0100 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import units"), nb); 0101 for (int i = 0; !err && i < nb; ++i) { 0102 // Get account object 0103 QDomElement currency = currencyList.at(i).toElement(); 0104 0105 // Creation of the units 0106 SKGUnitObject unitObj(m_importer->getDocument()); 0107 IFOKDO(err, unitObj.setName(getAttribute(currency, QStringLiteral("Na")))) 0108 IFOKDO(err, unitObj.setSymbol(getAttribute(currency, QStringLiteral("Co")))) 0109 IFOKDO(err, unitObj.setNumberDecimal(SKGServices::stringToInt(getAttribute(currency, QStringLiteral("Fl"))))) 0110 IFOKDO(err, unitObj.save()) 0111 0112 mapIdUnit[getAttribute(currency, QStringLiteral("Nb"))] = unitObj; 0113 0114 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0115 } 0116 0117 SKGENDTRANSACTION(m_importer->getDocument(), err) 0118 } 0119 IFOKDO(err, m_importer->getDocument()->stepForward(1)) 0120 0121 // Step 2-Create banks 0122 IFOK(err) { 0123 QDomNodeList bankList = docElem.elementsByTagName(QStringLiteral("Bank")); 0124 int nb = bankList.count(); 0125 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import banks"), nb); 0126 for (int i = 0; !err && i < nb; ++i) { 0127 // Get account object 0128 QDomElement bank = bankList.at(i).toElement(); 0129 0130 // Creation of the banks 0131 SKGBankObject bankObj(m_importer->getDocument()); 0132 IFOKDO(err, bankObj.setName(getAttribute(bank, QStringLiteral("Na")))) 0133 IFOKDO(err, bankObj.setNumber(getAttribute(bank, QStringLiteral("BIC")))) 0134 IFOKDO(err, bankObj.save()) 0135 0136 mapIdBank[getAttribute(bank, QStringLiteral("Nb"))] = bankObj; 0137 0138 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0139 } 0140 0141 SKGENDTRANSACTION(m_importer->getDocument(), err) 0142 } 0143 IFOKDO(err, m_importer->getDocument()->stepForward(2)) 0144 0145 // Step 3-Create accounts 0146 SKGBankObject bankDefault(m_importer->getDocument()); 0147 IFOKDO(err, bankDefault.setName(QStringLiteral("GRISBI"))) 0148 IFOKDO(err, bankDefault.save()) 0149 IFOK(err) { 0150 QDomNodeList accountList = docElem.elementsByTagName(QStringLiteral("Account")); 0151 int nb = accountList.count(); 0152 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import accounts"), nb); 0153 for (int i = 0; !err && i < nb; ++i) { 0154 // Get account object 0155 QDomElement account = accountList.at(i).toElement(); 0156 0157 // Creation of the account 0158 SKGAccountObject accountObj; 0159 SKGBankObject bank = mapIdBank[getAttribute(account, QStringLiteral("Bank"))]; 0160 if (!bank.exist()) { 0161 bank = bankDefault; 0162 } 0163 IFOKDO(err, bank.addAccount(accountObj)) 0164 IFOKDO(err, accountObj.setName(getAttribute(account, QStringLiteral("Name")))) 0165 IFOKDO(err, accountObj.setNumber(getAttribute(account, QStringLiteral("Bank_account_number")))) 0166 IFOKDO(err, accountObj.setComment(getAttribute(account, QStringLiteral("Comment")))) 0167 IFOKDO(err, accountObj.setAgencyAddress(getAttribute(account, QStringLiteral("Owner_address")))) 0168 IFOKDO(err, accountObj.setMinLimitAmount(SKGServices::stringToDouble(getAttribute(account, QStringLiteral("Minimum_authorised_balance"))))) 0169 IFOKDO(err, accountObj.minLimitAmountEnabled(accountObj.getMinLimitAmount() != 0.0)) 0170 IFOKDO(err, accountObj.setClosed(getAttribute(account, QStringLiteral("Closed_account")) != QStringLiteral("0"))) 0171 IFOKDO(err, accountObj.save()) 0172 IFOKDO(err, accountObj.setInitialBalance(SKGServices::stringToDouble(getAttribute(account, QStringLiteral("Initial_balance"))), mapIdUnit[getAttribute(account, QStringLiteral("Currency"))])) 0173 0174 mapIdAccount[getAttribute(account, QStringLiteral("Number"))] = accountObj; 0175 0176 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0177 } 0178 0179 SKGENDTRANSACTION(m_importer->getDocument(), err) 0180 } 0181 IFOKDO(err, m_importer->getDocument()->stepForward(3)) 0182 0183 // Step 4-Get payees 0184 IFOK(err) { 0185 QDomNodeList partyList = docElem.elementsByTagName(QStringLiteral("Party")); 0186 int nb = partyList.count(); 0187 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import payees"), nb); 0188 for (int i = 0; !err && i < nb; ++i) { 0189 // Get payee object 0190 QDomElement party = partyList.at(i).toElement(); 0191 SKGPayeeObject payeeObject; 0192 err = SKGPayeeObject::createPayee(m_importer->getDocument(), getAttribute(party, QStringLiteral("Na")), payeeObject); 0193 mapIdPayee[getAttribute(party, QStringLiteral("Nb"))] = payeeObject; 0194 0195 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0196 } 0197 0198 SKGENDTRANSACTION(m_importer->getDocument(), err) 0199 } 0200 IFOKDO(err, m_importer->getDocument()->stepForward(4)) 0201 0202 // Step 5-Get payement mode 0203 IFOK(err) { 0204 QDomNodeList paymentList = docElem.elementsByTagName(QStringLiteral("Payment")); 0205 int nb = paymentList.count(); 0206 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import payment mode"), nb); 0207 for (int i = 0; !err && i < nb; ++i) { 0208 // Get mode object 0209 QDomElement payment = paymentList.at(i).toElement(); 0210 mapIdMode[getAttribute(payment, QStringLiteral("Number"))] = getAttribute(payment, QStringLiteral("Name")); 0211 0212 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0213 } 0214 0215 SKGENDTRANSACTION(m_importer->getDocument(), err) 0216 } 0217 IFOKDO(err, m_importer->getDocument()->stepForward(5)) 0218 0219 // Step 6-Create categories 0220 IFOK(err) { 0221 QDomNodeList categoryList = docElem.elementsByTagName(QStringLiteral("Category")); 0222 int nb = categoryList.count(); 0223 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import categories"), nb); 0224 for (int i = 0; !err && i < nb; ++i) { 0225 // Get account object 0226 QDomElement category = categoryList.at(i).toElement(); 0227 0228 // Creation of the categories 0229 SKGCategoryObject catObj(m_importer->getDocument()); 0230 IFOKDO(err, catObj.setName(getAttribute(category, QStringLiteral("Na")))) 0231 IFOKDO(err, catObj.save()) 0232 0233 QString id = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(category, QStringLiteral("Nb")))); 0234 mapIdCategory[id] = catObj; 0235 0236 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0237 } 0238 0239 SKGENDTRANSACTION(m_importer->getDocument(), err) 0240 } 0241 IFOKDO(err, m_importer->getDocument()->stepForward(6)) 0242 0243 // Step 7-Create subcategories 0244 IFOK(err) { 0245 QDomNodeList categoryList = docElem.elementsByTagName(QStringLiteral("Sub_category")); 0246 int nb = categoryList.count(); 0247 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import categories"), nb); 0248 for (int i = 0; !err && i < nb; ++i) { 0249 // Get account object 0250 QDomElement category = categoryList.at(i).toElement(); 0251 0252 // Creation of the subcategories 0253 SKGCategoryObject catParentObj = mapIdCategory[SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(category, QStringLiteral("Nbc"))))]; 0254 SKGCategoryObject catObj; 0255 IFOKDO(err, catParentObj.addCategory(catObj)) 0256 IFOKDO(err, catObj.setName(getAttribute(category, QStringLiteral("Na")))) 0257 IFOKDO(err, catObj.save()) 0258 0259 QString id = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(category, QStringLiteral("Nbc"))) + SKGServices::stringToInt(getAttribute(category, QStringLiteral("Nb")))); 0260 mapIdCategory[id] = catObj; 0261 0262 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0263 } 0264 0265 SKGENDTRANSACTION(m_importer->getDocument(), err) 0266 } 0267 IFOKDO(err, m_importer->getDocument()->stepForward(7)) 0268 0269 // Step 8-Index of budget categories 0270 IFOK(err) { 0271 QDomNodeList budgetaryList = docElem.elementsByTagName(QStringLiteral("Budgetary")); 0272 int nb = budgetaryList.count(); 0273 for (int i = 0; !err && i < nb; ++i) { 0274 // Get account object 0275 QDomElement budgetary = budgetaryList.at(i).toElement(); 0276 QString id = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(budgetary, QStringLiteral("Nb")))); 0277 mapIdBudgetCat[id] = getAttribute(budgetary, QStringLiteral("Na")); 0278 } 0279 } 0280 IFOK(err) { 0281 QDomNodeList budgetaryList = docElem.elementsByTagName(QStringLiteral("Sub_budgetary")); 0282 int nb = budgetaryList.count(); 0283 for (int i = 0; !err && i < nb; ++i) { 0284 // Get account object 0285 QDomElement budgetary = budgetaryList.at(i).toElement(); 0286 QString id1 = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(budgetary, QStringLiteral("Nb")))); 0287 QString id = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(budgetary, QStringLiteral("Nbb"))) + SKGServices::stringToInt(getAttribute(budgetary, QStringLiteral("Nb")))); 0288 mapIdBudgetCat[id] = mapIdBudgetCat[id1] % OBJECTSEPARATOR % getAttribute(budgetary, QStringLiteral("Na")); 0289 } 0290 } 0291 IFOKDO(err, m_importer->getDocument()->stepForward(8)) 0292 0293 // Step 9-Create transaction 0294 IFOK(err) { 0295 QDomNodeList transactionList = docElem.elementsByTagName(QStringLiteral("Transaction")); 0296 int nb = transactionList.count(); 0297 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import transactions"), nb); 0298 for (int i = 0; !err && i < nb; ++i) { 0299 // Get account object 0300 QDomElement transaction = transactionList.at(i).toElement(); 0301 0302 // Creation of the transaction 0303 SKGOperationObject opObj; 0304 QString parentOpId = getAttribute(transaction, QStringLiteral("Mo")); 0305 if (parentOpId == QStringLiteral("0")) { 0306 SKGAccountObject account = mapIdAccount[getAttribute(transaction, QStringLiteral("Ac"))]; 0307 IFOKDO(err, account.addOperation(opObj, true)) 0308 IFOKDO(err, opObj.setDate(QDate::fromString(getAttribute(transaction, QStringLiteral("Dt")), QStringLiteral("MM/dd/yyyy")))) 0309 IFOKDO(err, opObj.setUnit(mapIdUnit[ getAttribute(transaction, QStringLiteral("Cu"))])) 0310 IFOKDO(err, opObj.setPayee(mapIdPayee[ getAttribute(transaction, QStringLiteral("Pa"))])) 0311 IFOKDO(err, opObj.setMode(mapIdMode[getAttribute(transaction, QStringLiteral("Pn"))])) 0312 IFOKDO(err, opObj.setNumber(getAttribute(transaction, QStringLiteral("Pc")))) 0313 IFOKDO(err, opObj.setComment(getAttribute(transaction, QStringLiteral("No")))) 0314 IFOKDO(err, opObj.setImported(true)) 0315 IFOKDO(err, opObj.setImportID("GSB-" % getAttribute(transaction, QStringLiteral("Nb")))) 0316 IFOKDO(err, opObj.setStatus(getAttribute(transaction, QStringLiteral("Re")) == QStringLiteral("0") ? SKGOperationObject::NONE : SKGOperationObject::CHECKED)) 0317 IFOKDO(err, opObj.setGroupOperation(mapIdOperation[getAttribute(transaction, QStringLiteral("Trt"))])) 0318 IFOKDO(err, opObj.save()) 0319 } else { 0320 opObj = mapIdOperation[parentOpId]; 0321 } 0322 0323 // Budgetary allocation 0324 IFOK(err) { 0325 int sbu = SKGServices::stringToInt(getAttribute(transaction, QStringLiteral("Sbu"))); 0326 QString id = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(transaction, QStringLiteral("Bu"))) + qMax(sbu, 0)); 0327 QString buCat = mapIdBudgetCat[id]; 0328 if (!buCat.isEmpty()) { 0329 err = opObj.setProperty(i18nc("Noun", "Budgetary allocation"), buCat); 0330 IFOKDO(err, opObj.save()) 0331 } 0332 } 0333 0334 if (getAttribute(transaction, QStringLiteral("Br")) == QStringLiteral("0")) { 0335 SKGSubOperationObject subObj; 0336 IFOKDO(err, opObj.addSubOperation(subObj)) 0337 QString id = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(transaction, QStringLiteral("Ca"))) + SKGServices::stringToInt(getAttribute(transaction, QStringLiteral("Sca")))); 0338 IFOKDO(err, subObj.setCategory(mapIdCategory[id])) 0339 IFOKDO(err, subObj.setComment(getAttribute(transaction, QStringLiteral("No")))) 0340 IFOKDO(err, subObj.setQuantity(SKGServices::stringToDouble(getAttribute(transaction, QStringLiteral("Am"))))) 0341 IFOKDO(err, subObj.save()) 0342 } 0343 0344 // Fiscal year 0345 IFOK(err) { 0346 QString fiscalYear = getAttribute(transaction, QStringLiteral("Vo")); 0347 if (!fiscalYear.isEmpty()) { 0348 err = opObj.setProperty(i18nc("Noun", "Fiscal year"), fiscalYear); 0349 IFOKDO(err, opObj.save()) 0350 } 0351 } 0352 0353 if (parentOpId == QStringLiteral("0")) { 0354 mapIdOperation[getAttribute(transaction, QStringLiteral("Nb"))] = opObj; 0355 } 0356 0357 if (!err && i % 500 == 0) { 0358 err = m_importer->getDocument()->executeSqliteOrder(QStringLiteral("ANALYZE")); 0359 } 0360 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0361 } 0362 0363 SKGENDTRANSACTION(m_importer->getDocument(), err) 0364 } 0365 IFOKDO(err, m_importer->getDocument()->stepForward(9)) 0366 0367 // Step 10-Create scheduled transaction 0368 IFOK(err) { 0369 QDomNodeList scheduledList = docElem.elementsByTagName(QStringLiteral("Scheduled")); 0370 int nb = scheduledList.count(); 0371 err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Import step", "Import scheduled transactions"), nb); 0372 for (int i = 0; !err && i < nb; ++i) { 0373 // Get account object 0374 QDomElement transaction = scheduledList.at(i).toElement(); 0375 0376 // Creation of the transaction 0377 SKGAccountObject account = mapIdAccount[getAttribute(transaction, QStringLiteral("Ac"))]; 0378 SKGOperationObject opObj; 0379 IFOKDO(err, account.addOperation(opObj, true)) 0380 QDate firstDate = QDate::fromString(getAttribute(transaction, QStringLiteral("Dt")), QStringLiteral("MM/dd/yyyy")); 0381 IFOKDO(err, opObj.setDate(firstDate)) 0382 IFOKDO(err, opObj.setUnit(mapIdUnit[ getAttribute(transaction, QStringLiteral("Cu"))])) 0383 IFOKDO(err, opObj.setPayee(mapIdPayee[ getAttribute(transaction, QStringLiteral("Pa"))])) 0384 IFOKDO(err, opObj.setMode(mapIdMode[getAttribute(transaction, QStringLiteral("Pn"))])) 0385 IFOKDO(err, opObj.setNumber(getAttribute(transaction, QStringLiteral("Pc")))) 0386 IFOKDO(err, opObj.setComment(getAttribute(transaction, QStringLiteral("No")))) 0387 IFOKDO(err, opObj.setImported(true)) 0388 IFOKDO(err, opObj.setImportID("GSB-" % getAttribute(transaction, QStringLiteral("Nb")))) 0389 IFOKDO(err, opObj.setTemplate(true)) 0390 IFOKDO(err, opObj.save()) 0391 0392 SKGSubOperationObject subObj; 0393 IFOKDO(err, opObj.addSubOperation(subObj)) 0394 QString id = SKGServices::intToString(10000 * SKGServices::stringToInt(getAttribute(transaction, QStringLiteral("Ca"))) + SKGServices::stringToInt(getAttribute(transaction, QStringLiteral("Sca")))); 0395 IFOKDO(err, subObj.setCategory(mapIdCategory[id])) 0396 IFOKDO(err, subObj.setComment(getAttribute(transaction, QStringLiteral("No")))) 0397 IFOKDO(err, subObj.setQuantity(SKGServices::stringToDouble(getAttribute(transaction, QStringLiteral("Am"))))) 0398 IFOKDO(err, subObj.save()) 0399 0400 QString Tra = getAttribute(transaction, QStringLiteral("Tra")); 0401 if (Tra != QStringLiteral("0")) { 0402 // This is a transfer 0403 SKGOperationObject opObj2; 0404 IFOKDO(err, opObj.duplicate(opObj2, opObj.getDate(), true)) 0405 IFOKDO(err, opObj2.setImported(true)) 0406 IFOKDO(err, opObj2.setImportID("GSB-" % getAttribute(transaction, QStringLiteral("Nb")) % "_TR")) 0407 IFOKDO(err, opObj2.save()) 0408 0409 SKGObjectBase::SKGListSKGObjectBase subObjs2; 0410 IFOKDO(err, opObj2.getSubOperations(subObjs2)) 0411 if (!err && !subObjs2.isEmpty()) { 0412 SKGSubOperationObject subObj2(subObjs2.at(0)); 0413 err = subObj2.setQuantity(-subObj.getQuantity()); 0414 IFOKDO(err, subObj2.save()) 0415 } 0416 0417 // Group transactions 0418 IFOKDO(err, opObj.setGroupOperation(opObj2)) 0419 IFOKDO(err, opObj.save()) 0420 } 0421 0422 // Create the schedule 0423 SKGRecurrentOperationObject recuObj; 0424 IFOKDO(err, opObj.addRecurrentOperation(recuObj)) 0425 IFOKDO(err, recuObj.setAutoWriteDays(0)) 0426 IFOKDO(err, recuObj.autoWriteEnabled(getAttribute(transaction, QStringLiteral("Au")) != QStringLiteral("0"))) 0427 IFOK(err) { 0428 // text_frequency [] = { _("Once"), _("Weekly"), _("Monthly"), _("two months"), ("trimester"), _("Yearly"), _("Custom"), nullptr }; 0429 int occu = 1; 0430 SKGRecurrentOperationObject::PeriodUnit period = SKGRecurrentOperationObject::DAY; 0431 QString Pe = getAttribute(transaction, QStringLiteral("Pe")); 0432 if (Pe == QStringLiteral("0")) { 0433 period = SKGRecurrentOperationObject::MONTH; 0434 IFOKDO(err, recuObj.timeLimit(true)) 0435 IFOKDO(err, recuObj.setTimeLimit(1)) 0436 0437 } else if (Pe == QStringLiteral("1")) { 0438 period = SKGRecurrentOperationObject::WEEK; 0439 } else if (Pe == QStringLiteral("2")) { 0440 period = SKGRecurrentOperationObject::MONTH; 0441 } else if (Pe == QStringLiteral("3")) { 0442 occu = 2; 0443 period = SKGRecurrentOperationObject::MONTH; 0444 } else if (Pe == QStringLiteral("4")) { 0445 occu = 3; 0446 period = SKGRecurrentOperationObject::MONTH; 0447 } else if (Pe == QStringLiteral("5")) { 0448 period = SKGRecurrentOperationObject::YEAR; 0449 } else if (Pe == QStringLiteral("6")) { 0450 // text_frequency_user [] = { _("Days"), _("Weeks"), _("Months"), _("Years"), nullptr }; 0451 occu = SKGServices::stringToInt(getAttribute(transaction, QStringLiteral("Pep"))); 0452 QString Pei = getAttribute(transaction, QStringLiteral("Pei")); 0453 if (Pei == QStringLiteral("0")) { 0454 period = SKGRecurrentOperationObject::DAY; 0455 } else if (Pei == QStringLiteral("1")) { 0456 period = SKGRecurrentOperationObject::WEEK; 0457 } else if (Pei == QStringLiteral("2")) { 0458 period = SKGRecurrentOperationObject::MONTH; 0459 } else { 0460 period = SKGRecurrentOperationObject::YEAR; 0461 } 0462 } 0463 0464 IFOKDO(err, recuObj.setPeriodUnit(period)) 0465 IFOKDO(err, recuObj.setPeriodIncrement(occu)) 0466 0467 QString Dtl = getAttribute(transaction, QStringLiteral("Dtl")); 0468 if (!err && !Dtl.isEmpty()) { 0469 IFOKDO(err, recuObj.timeLimit(true)) 0470 IFOKDO(err, recuObj.setTimeLimit(QDate::fromString(Dtl, QStringLiteral("MM/dd/yyyy")))) 0471 } 0472 } 0473 IFOKDO(err, recuObj.save()) 0474 0475 if (!err && i % 500 == 0) { 0476 err = m_importer->getDocument()->executeSqliteOrder(QStringLiteral("ANALYZE")); 0477 } 0478 IFOKDO(err, m_importer->getDocument()->stepForward(i + 1)) 0479 } 0480 0481 SKGENDTRANSACTION(m_importer->getDocument(), err) 0482 } 0483 IFOKDO(err, m_importer->getDocument()->stepForward(10)) 0484 0485 SKGENDTRANSACTION(m_importer->getDocument(), err) 0486 0487 IFOKDO(err, m_importer->getDocument()->executeSqliteOrder(QStringLiteral("ANALYZE"))) 0488 } 0489 } 0490 0491 return err; 0492 } 0493 0494 0495 QString SKGImportPluginGsb::getAttribute(const QDomElement& iElement, const QString& iAttribute) 0496 { 0497 QString val = iElement.attribute(iAttribute); 0498 if (val == QStringLiteral("(null)")) { 0499 val = QString(); 0500 } 0501 return val; 0502 } 0503 QString SKGImportPluginGsb::getMimeTypeFilter() const 0504 { 0505 return "*.gsb|" % i18nc("A file format", "Grisbi file"); 0506 } 0507 0508 #include <skgimportplugingsb.moc>