Exemple #1
0
Environment::Environment(const EnvironmentURL &url) :
    archivePath(fs::system_complete(getEnvironmentPath(url + ".sky"))),
    fileArchive(archivePath),
    workerRunning(false),
    loadError(false),
    loadProgress(0),
    url(url) {
  if (url == "NULL") {
    appLog("Creating null environment.", LogOrigin::Engine);
    workerThread = std::thread([&]() { loadNullMap(); });
  } else {
    appLog("Creating environment " + inQuotes(url)
               + " with environment file " + archivePath.string(),
           LogOrigin::Engine);

    workerRunning = true;
    workerThread = std::thread([&]() {
      fileArchive.load();
      if (const auto dir = fileArchive.getResult()) {
        if (const auto mapPath = dir->getTopFile("map.json")) {
          loadMap(mapPath.get());
        } else {
          appLog(describeComponentMissing(Component::Map), LogOrigin::Error);
          loadError = true;
        }
      } else {
        appLog("Could not open environment archive at path "
                   + archivePath.string(), LogOrigin::Error);
        loadError = true;
      }

      workerRunning = false;
    });
  }
}
bool FileCSV::Save(const wxString& fileName)
{
    // Make sure file exists
    if (fileName.IsEmpty())
    {
        mmErrorDialogs::InvalidFile(pParentWindow_);
        return false;
    }

    // Open file
    wxTextFile txtFile(fileName);
    if (!txtFile.Create())
    {
        mmErrorDialogs::MessageError(pParentWindow_, _("Unable to create file."), _("Universal CSV Import"));
        return false;
    }

    // Store lines
    for (auto rowIt : itemsTable_)
    {
        wxString line;
        for (auto itemIt : rowIt)
        {
            if (!line.IsEmpty())
                line += delimiter_;
            line += inQuotes(itemIt.value, delimiter_);
        }
        txtFile.AddLine(line);
    }

    // Save the file.
    if (!txtFile.Write(wxTextFileType_None, encoding_))
    {
        mmErrorDialogs::MessageError(pParentWindow_, _("Could not save file."), _("Export error"));
        return false;
    }
    txtFile.Close();
    return true;
}
const wxString mmExportTransaction::getTransactionCSV(const Model_Checking::Full_Data & full_tran, int accountID, const wxString& dateMask)
{
    bool out = full_tran.ACCOUNTID == accountID;

    const wxString delimit = Model_Infotable::instance().GetStringInfo("DELIMITER", mmex::DEFDELIMTER);

    wxString buffer = "";
    int trans_id = full_tran.id();
    const wxString& accountName = (!out ? full_tran.PAYEENAME : full_tran.ACCOUNTNAME);
    wxString categ = full_tran.m_splits.empty() ? full_tran.CATEGNAME : "";
    wxString transNum = full_tran.TRANSACTIONNUMBER;
    wxString notes = (full_tran.NOTES);
    notes.Replace("''", "'");
    notes.Replace("\n", "\\n");

    if (Model_Checking::type(full_tran) == Model_Checking::TRANSFER)
    {
        categ = "[" + (!out ? full_tran.ACCOUNTNAME : full_tran.PAYEENAME) + "]";

        //Transaction number used to make transaction unique
        // to proper merge transfer records
        if (transNum.IsEmpty() && notes.IsEmpty())
            transNum = wxString::Format("#%i", full_tran.id());
    }

    if (!full_tran.m_splits.empty())
    {
        for (const auto &split_entry : full_tran.m_splits)
        {
            double value = split_entry.SPLITTRANSAMOUNT;
            if (Model_Checking::type(full_tran) == Model_Checking::WITHDRAWAL)
                value = -value;
            const wxString split_amount = wxString() << value;

            const wxString split_categ = Model_Category::full_name(split_entry.CATEGID, split_entry.SUBCATEGID);

            buffer << trans_id << delimit
                   << inQuotes(accountName, delimit) << delimit
                   << inQuotes(mmGetDateForDisplay(Model_Checking::TRANSDATE(full_tran)), delimit) << delimit
                   << inQuotes(full_tran.PAYEENAME, delimit) << delimit
                   << full_tran.STATUS << delimit
                   << full_tran.TRANSCODE << delimit
                   << inQuotes(split_categ, delimit) << delimit
                   << inQuotes(split_amount, delimit) << delimit
                   << "" << delimit
                   << inQuotes(notes, delimit)
                   << "\n";
        }

    }
    else
    {
        buffer << trans_id << delimit
               << inQuotes(accountName, delimit) << delimit
               << inQuotes(mmGetDateForDisplay(Model_Checking::TRANSDATE(full_tran)), delimit) << delimit
               << inQuotes(full_tran.PAYEENAME, delimit) << delimit
               << full_tran.STATUS << delimit
               << full_tran.TRANSCODE << delimit
               << inQuotes(categ, delimit) << delimit
               << Model_Checking::balance(full_tran, (out ? full_tran.ACCOUNTID : full_tran.TOACCOUNTID)) << delimit
               << "" << delimit
               << inQuotes(notes, delimit)
               << "\n";
    }
    return buffer;
}