From d9fca88af32d00cd22d8de78138cf44d245cb75f Mon Sep 17 00:00:00 2001 From: leca Date: Fri, 30 Aug 2024 05:03:32 +0300 Subject: [PATCH] Output to csv, started work on OFD module --- CMakeLists.txt | 16 +++ CMakeLists.txt.user | 52 ++++----- main.cpp | 10 ++ mainwindow.cpp | 3 +- mainwindow.h | 1 - ofd/module.cpp | 24 +++++ ofd/module.h | 18 ++++ ofd/ofd.cpp | 62 +++++++++++ ofd/ofd.h | 22 ++++ output/output_options.cpp | 61 +++++++++++ output/output_options.h | 57 ++++++++++ outputdialog.cpp | 124 ++++++++++++++++++++-- outputdialog.h | 22 +++- outputdialog.ui | 218 +++++++++++++++++++++++--------------- parser/module.cpp | 29 ++--- parser/module.h | 14 +-- parser/parser.cpp | 4 +- parser/parser.h | 3 +- settings.h | 5 +- utils/utils.cpp | 15 +++ utils/utils.h | 9 ++ 21 files changed, 606 insertions(+), 163 deletions(-) create mode 100644 ofd/module.cpp create mode 100644 ofd/module.h create mode 100644 ofd/ofd.cpp create mode 100644 ofd/ofd.h create mode 100644 output/output_options.cpp create mode 100644 output/output_options.h create mode 100644 utils/utils.cpp create mode 100644 utils/utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a46284..5404532 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,12 +44,18 @@ else() parser/module.h parser/module.cpp settings.h outputdialog.h outputdialog.cpp outputdialog.ui + output/output_options.h output/output_options.cpp + ofd/ofd.h ofd/ofd.cpp + ofd/module.h ofd/module.cpp + utils/utils.h utils/utils.cpp ) endif() endif() target_link_libraries(checks-parser PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) + + # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. @@ -74,3 +80,13 @@ install(TARGETS checks-parser if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(checks-parser) endif() + +include(FetchContent) +FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git + GIT_TAG 3b15fa82ea74739b574d705fea44959b58142eb8) +FetchContent_MakeAvailable(cpr) +target_link_libraries(checks-parser PRIVATE cpr::cpr) + + +find_package(KF${QT_VERSION_MAJOR}WidgetsAddons) +target_link_libraries(checks-parser PRIVATE KF${QT_VERSION_MAJOR}::WidgetsAddons) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 06071b1..d48a13b 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -104,12 +104,12 @@ -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} 0 /home/leca/projects/qt/checks-parser/build/Desktop-Debug @@ -161,12 +161,12 @@ -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} /home/leca/projects/qt/checks-parser/build/Desktop-Release @@ -215,12 +215,12 @@ -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} /home/leca/projects/qt/checks-parser/build/Desktop-RelWithDebInfo @@ -269,12 +269,12 @@ -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} 0 /home/leca/projects/qt/checks-parser/build/Desktop-Profile @@ -324,12 +324,12 @@ -DCMAKE_BUILD_TYPE:STRING=MinSizeRel -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} /home/leca/projects/qt/checks-parser/build/Desktop-MinSizeRel diff --git a/main.cpp b/main.cpp index 17dfc6c..907b6ea 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,7 @@ #include "mainwindow.h" +#include "ofd/ofd.h" +#include "utils/utils.h" +#include #include @@ -7,5 +10,12 @@ int main(int argc, char *argv[]) { MainWindow w; w.show(); + OFD ofd; + std::vector ofds = ofd.search_ofds(); + + for (OFDModule o : ofds) { + std::cout << to_utf8(o.get_name()) << ": " << to_utf8(o.get_url()) << std::endl; + } + return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 4ac1f45..821abe6 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -22,7 +22,7 @@ void MainWindow::setupStoresList() { std::vector modules_names = parser.search_modules(); for (std::string name : modules_names) { - Module m(name); + StoreModule m(name); std::wstring module_name = m.get_name(); QString s = QString::fromStdWString(module_name); @@ -66,6 +66,7 @@ void MainWindow::on_parseButton_clicked() { } OutputDialog *d = new OutputDialog(this, check); + d->show(); d->exec(); } diff --git a/mainwindow.h b/mainwindow.h index 5725330..e0ce513 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -19,7 +19,6 @@ class MainWindow : public QMainWindow { Parser parser; public: - MainWindow(QWidget *parent = nullptr); ~MainWindow(); void setupStoresList(); diff --git a/ofd/module.cpp b/ofd/module.cpp new file mode 100644 index 0000000..834ec21 --- /dev/null +++ b/ofd/module.cpp @@ -0,0 +1,24 @@ +#include "module.h" + +#include +#include +#include "../utils/utils.h" + +OFDModule::OFDModule() {} + +OFDModule::OFDModule(std::string path) { + this->path = path; + + std::ifstream settings_file(path); + nlohmann::json settings = nlohmann::json::parse(settings_file); + + this->name = from_utf8(settings["name"]); + this->url = from_utf8(settings["url"]); +} + +std::wstring OFDModule::get_name() { + return this->name; +} +std::wstring OFDModule::get_url() { + return this->url; +} diff --git a/ofd/module.h b/ofd/module.h new file mode 100644 index 0000000..09bdfcd --- /dev/null +++ b/ofd/module.h @@ -0,0 +1,18 @@ +#ifndef OFD_MODULE_H +#define OFD_MODULE_H + +#include + +class OFDModule { + std::string path; + std::wstring name; + std::wstring url; +public: + OFDModule(std::string); + OFDModule(); + + std::wstring get_name(); + std::wstring get_url(); +}; + +#endif // OFDMODULE_H diff --git a/ofd/ofd.cpp b/ofd/ofd.cpp new file mode 100644 index 0000000..d349e96 --- /dev/null +++ b/ofd/ofd.cpp @@ -0,0 +1,62 @@ +#include "ofd.h" +#include "../settings.h" +#include "../utils/utils.h" +#include +#include +#include +#include +#include + +OFD::OFD() {} + +OFD::OFD(std::string path) { this->module = OFDModule(path); }; + +std::vector OFD::search_ofds() { + std::vector result{}; + + std::string path = std::string(std::getenv("HOME")) + "/" + OFDS_MODULES_DIR; + std::filesystem::directory_entry modules_dir(path); + + if (!modules_dir.exists()) { + std::filesystem::create_directories(path); + std::cout << "No modules directory found. Created one at " << path + << std::endl; + std::cout << "Please, download modules to that directory from my git." + << std::endl; + } + + for (auto file : std::filesystem::directory_iterator(path)) { + result.push_back(file.path()); + } + + return result; +} + +void OFD::set_module(std::string path) { this->module = OFDModule(path); } + +std::string OFD::get_check_data(std::string fn, std::string fd, + std::string fp) { + //curl 'https://ofd.beeline.ru/api/ofdcheck/checkf?fn=7281440701327430&fp=2518183888&fd=25955&format=4' \ + -H 'Accept: application/json, text/plain, */*' \ + -H 'Accept-Language: en-US,en;q=0.9,eo;q=0.8,ru;q=0.7' \ + -H 'Authorization: bearer null' \ + -H 'Connection: keep-alive' \ + -H 'Content-Type: application/json' \ + -H 'DNT: 1' \ + -H 'Referer: https://ofd.beeline.ru/check-order?fn=7281440701327430&fp=2518183888&fd=25955' \ + -H 'Sec-Fetch-Dest: empty' \ + -H 'Sec-Fetch-Mode: cors' \ + -H 'Sec-Fetch-Site: same-origin' \ + -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36' \ + -H 'sec-ch-ua: "Chromium";v="127", "Not)A;Brand";v="99"' \ + -H 'sec-ch-ua-mobile: ?0' \ + -H 'sec-ch-ua-platform: "Linux"' + + cpr::Response r = + cpr::Get(cpr::Url{to_utf8(module.get_url())}, + cpr::Parameters{{"fn", fn}, {"fd", fd}, {"fp", fp}}); + + std::cout << r.text << std::endl; + + return r.text; +} diff --git a/ofd/ofd.h b/ofd/ofd.h new file mode 100644 index 0000000..3516d4f --- /dev/null +++ b/ofd/ofd.h @@ -0,0 +1,22 @@ +#ifndef OFD_H +#define OFD_H + +#include +#include +#include "module.h" + +class OFD { + + OFDModule module; + +public: + OFD(); + OFD(std::string); + + std::vector search_ofds(); + + void set_module(std::string); + + std::string get_check_data(std::string, std::string, std::string); +}; +#endif // OFD_H diff --git a/output/output_options.cpp b/output/output_options.cpp new file mode 100644 index 0000000..e416dd3 --- /dev/null +++ b/output/output_options.cpp @@ -0,0 +1,61 @@ +#include "output_options.h" + +OutputOptions::OutputOptions() {} + +void OutputOptions::add_or_update_column(Column &column) { + if (column_exist(column.type)) { + update_column(column, find_column(column.type)); + } else { + this->order.push_back(column); + } +} + +void OutputOptions::update_column(Column& column, unsigned short index) { + this->order[index] = column; +} + +void OutputOptions::remove_column(unsigned short index) { + this->order.erase(this->order.begin() + index); +} +void OutputOptions::remove_column(ColumnType t) { + this->order.erase(this->order.begin() + find_column(t)); +} + +unsigned short OutputOptions::find_column(ColumnType t) { + for (unsigned short i = 0; i < this->order.size(); i++) { + if (this->order[i].type == t) + return i; + } + + return -1; +} + +bool OutputOptions::column_exist(ColumnType t) { + for (unsigned short i = 0; i < this->order.size(); i++) { + if (this->order[i].type == t) + return true; + } + return false; +} + +Column& OutputOptions::get_column (ColumnType t){ + return this->order[find_column(t)]; +} + +std::vector& OutputOptions::get_columns() { + return this->order; +} + +void OutputOptions::set_print_header(bool value) { this->print_header = value; } +bool OutputOptions::get_print_header() { return this->print_header; } + +void OutputOptions::set_print_total(bool value) { this->print_total = value; } +bool OutputOptions::get_print_total() { return this->print_total; } + +OutputFormat OutputOptions::get_output_format() { return this->format; } +void OutputOptions::set_output_format(OutputFormat format) { + this->format = format; +} + +void OutputOptions::set_path(std::string path) { this->path = path; } +std::string &OutputOptions::get_path() { return this->path; } diff --git a/output/output_options.h b/output/output_options.h new file mode 100644 index 0000000..78ee716 --- /dev/null +++ b/output/output_options.h @@ -0,0 +1,57 @@ +#ifndef OUTPUT_OPTIONS_H +#define OUTPUT_OPTIONS_H + +#include +#include + +enum class ColumnType { + goods_name, + goods_price_per_unit, + goods_quantity, + goods_net_weight, + goods_total +}; + +struct Column { // Example: + ColumnType type; // goods_name + std::string name; // "Товар" + unsigned int position; // "0" <-- 0 = "A", 1 = "B", etc.. column letter in + // table processor (i.e. excel or libreoffice) +} typedef Column; + +enum class OutputFormat { csv, ods, xlsx, plaintext } typedef OutputFormat; + +class OutputOptions { + + std::vector order; + bool print_header; + bool print_total; + OutputFormat format; + std::string path; + +public: + OutputOptions(); + + void add_or_update_column(Column &); + void update_column(Column&, unsigned short); + void remove_column(unsigned short); + void remove_column(ColumnType); + unsigned short find_column(ColumnType); + bool column_exist(ColumnType); + Column& get_column(ColumnType); + std::vector& get_columns(); + + void set_print_header(bool); + bool get_print_header(); + + void set_print_total(bool); + bool get_print_total(); + + void set_output_format(OutputFormat); + OutputFormat get_output_format(); + + void set_path(std::string); + std::string &get_path(); +}; + +#endif // OUTPUT_OPTIONS_H diff --git a/outputdialog.cpp b/outputdialog.cpp index 76d96bf..3265088 100644 --- a/outputdialog.cpp +++ b/outputdialog.cpp @@ -1,15 +1,119 @@ -#include "outputdialog.h" -#include "ui_outputdialog.h" -#include -#include -#include "check/check.h" +// TODO: refactor that shit with custom qt widget(line edit + combo box) -OutputDialog::OutputDialog(QWidget *parent, Check check) - : QDialog(parent), ui(new Ui::OutputDialog) { +#include "outputdialog.h" +#include "check/check.h" +#include "output/output_options.h" +#include "ui_outputdialog.h" +#include +#include +#include +#include + +OutputDialog::OutputDialog(QWidget *parent, Check &check) + : QDialog(parent), ui(new Ui::OutputDialog), check(check), + options(*(new OutputOptions())) { ui->setupUi(this); - for (auto goods : check.get_goods()) { - std::cout << "From dialog:" << goods.get_name() << std::endl; - } } OutputDialog::~OutputDialog() { delete ui; } + +bool compare_position(Column &c1, Column &c2) { + return c1.position < c2.position; +} + +void OutputDialog::on_buttonBox_accepted() { + std::ofstream output_file(this->options.get_path()); + + for (int i = 0; i < ui->tableWidget->rowCount(); i ++) { + int position = ui->tableWidget->item(i, 0)->text().toInt(); + std::string name = ui->tableWidget->item(i, 1)->text().toStdString(); + + Column c; + c.type = static_cast(i); + c.position = position; + c.name = name; + + this->options.add_or_update_column(c); + } + + std::sort(this->options.get_columns().begin(), + this->options.get_columns().end(), compare_position); + + if (options.get_print_header()) { + for (auto& column : this->options.get_columns()) { + output_file << column.name + << (column.position == this->options.get_columns().size() + ? "" + : ","); + } + output_file << std::endl; + } + + for (auto goods : this->check.get_goods()) { + for (auto& column : this->options.get_columns()) { + std::string output_str; + + switch (column.type) { + case ColumnType::goods_name: + output_str = goods.get_name(); + break; + case ColumnType::goods_price_per_unit: + output_str = std::to_string(goods.get_price_per_unit()); + break; + case ColumnType::goods_quantity: + output_str = std::to_string(goods.get_quantity()); + break; + case ColumnType::goods_net_weight: + output_str = "TODO"; + // TODO + break; + case ColumnType::goods_total: + output_str = std::to_string(goods.calculate_total_price()); + break; + } + + if (column.position != this->options.get_columns().size()) { + output_str += ","; + } else { + output_str += "\n"; + } + output_file << output_str; + } + } + + if (this->options.get_print_total()) { + output_file << "Total: " << std::to_string(check.calculae_total_price()); + } + + output_file.close(); +} + +void update_settings(OutputOptions &options, ColumnType t, std::string name, + int value) { + Column column; + column.type = t; + column.name = name; + column.position = value; + + if (value) { + options.add_or_update_column(column); + } else { + options.remove_column(t); + } +} + +void OutputDialog::on_chooseFileButton_clicked() { + QString filename = QFileDialog::getSaveFileName(); + std::cout << filename.toStdString() << std::endl; + this->options.set_path(filename.toStdString()); + ui->pathLabel->setText("Path to export: " + filename); +} + +void OutputDialog::on_printHeaderCheckBox_stateChanged(int value) { + this->options.set_print_header(value); +} + +void OutputDialog::on_printTotalCheckBox_stateChanged(int value) { + this->options.set_print_total(value); +} + diff --git a/outputdialog.h b/outputdialog.h index 955e7e1..27664cd 100644 --- a/outputdialog.h +++ b/outputdialog.h @@ -1,21 +1,35 @@ #ifndef OUTPUTDIALOG_H #define OUTPUTDIALOG_H -#include #include "check/check.h" +#include "output/output_options.h" +#include +#include namespace Ui { class OutputDialog; } -class OutputDialog : public QDialog -{ +class OutputDialog : public QDialog { Q_OBJECT + OutputOptions options; + Check ✓ + + public: - explicit OutputDialog(QWidget *parent = nullptr, Check = Check()); + explicit OutputDialog(QWidget *parent = nullptr, Check & = *(new Check())); ~OutputDialog(); +private slots: + void on_buttonBox_accepted(); + + void on_chooseFileButton_clicked(); + + void on_printHeaderCheckBox_stateChanged(int arg1); + + void on_printTotalCheckBox_stateChanged(int arg1); + private: Ui::OutputDialog *ui; }; diff --git a/outputdialog.ui b/outputdialog.ui index 609d185..fc0fcac 100644 --- a/outputdialog.ui +++ b/outputdialog.ui @@ -6,8 +6,8 @@ 0 0 - 602 - 436 + 586 + 431 @@ -29,108 +29,152 @@ QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok - - - - 60 - 20 - 261 - 26 - - - - - ods - - - - - csv - - - - - xlsx (Not implemented) - - - - + 10 20 - 45 - 21 + 271 + 18 - Format + Path to export: - + + + + 290 + 20 + 80 + 26 + + + + Choose + + + 10 50 - 441 - 191 + 111 + 24 - - Columns + + Print header - - - - 0 - 20 - 441 - 171 - + + + + + 10 + 130 + 321 + 181 + + + + + Goods name - - - - - - - - - - - - - - Price - - - - - - - Net weight - - - - - - - Quantity - - - - - - - Name - - - - - - - - + + + + Goods price + + + + + Goods quantity + + + + + Goods net weight + + + + + Goods total + + + + + position + + + + + name + + + + + 1 + + + + + Name + + + + + 2 + + + + + Price + + + + + 3 + + + + + Quantity + + + + + 4 + + + + + Net weight + + + + + 5 + + + + + Total price + + + + + + + 10 + 90 + 111 + 24 + + + + Print total + diff --git a/parser/module.cpp b/parser/module.cpp index 293d46b..ebdc002 100644 --- a/parser/module.cpp +++ b/parser/module.cpp @@ -1,26 +1,13 @@ #include "module.h" -#include "../settings.h" -#include #include -#include -#include #include #include #include +#include "../utils/utils.h" -std::string to_utf8(std::wstring wide_string) { - static std::wstring_convert> utf8_conv; - return utf8_conv.to_bytes(wide_string); -} +StoreModule::StoreModule() {} -std::wstring from_utf8(std::string string) { - static std::wstring_convert> utf8_conv; - return utf8_conv.from_bytes(string); -} - -Module::Module() {} - -Module::Module(std::string path) { +StoreModule::StoreModule(std::string path) { std::ifstream settings_file(path); nlohmann::json settings = nlohmann::json::parse(settings_file); @@ -42,7 +29,7 @@ Module::Module(std::string path) { #endif } -std::vector Module::parse_name(std::wstring str) { +std::vector StoreModule::parse_name(std::wstring str) { std::vector result; std::wregex r(this->goods_name_regex, std::regex::collate); @@ -54,7 +41,7 @@ std::vector Module::parse_name(std::wstring str) { return result; } -std::vector Module::parse_price(std::wstring str) { +std::vector StoreModule::parse_price(std::wstring str) { std::vector result; std::wregex r(this->goods_price_regex, std::regex::collate); @@ -66,7 +53,7 @@ std::vector Module::parse_price(std::wstring str) { return result; } -std::vector Module::parse_quantity(std::wstring str) { +std::vector StoreModule::parse_quantity(std::wstring str) { std::vector result; std::wregex r(this->goods_quantity_regex, std::regex::collate); @@ -77,7 +64,7 @@ std::vector Module::parse_quantity(std::wstring str) { return result; } -std::wstring Module::trim_check(std::wstring& check) { +std::wstring StoreModule::trim_check(std::wstring& check) { unsigned int start_pos; unsigned int end_pos; @@ -103,4 +90,4 @@ std::wstring Module::trim_check(std::wstring& check) { return check; } -std::wstring Module::get_name() { return this->name; } +std::wstring StoreModule::get_name() { return this->name; } diff --git a/parser/module.h b/parser/module.h index 99c61de..664cc66 100644 --- a/parser/module.h +++ b/parser/module.h @@ -1,10 +1,10 @@ -#ifndef MODULE_H -#define MODULE_H +#ifndef STORE_MODULE_H +#define STORE_MODULE_H #include -#include +#include -class Module { +class StoreModule { std::string path; std::wstring name; std::wstring goods_name_regex; @@ -13,8 +13,8 @@ class Module { std::wstring check_start_regex; std::wstring check_end_regex; public: - Module(std::string); - Module(); + StoreModule(std::string); + StoreModule(); std::vector parse_name(std::wstring); std::vector parse_price(std::wstring); @@ -25,4 +25,4 @@ public: std::wstring get_name(); }; -#endif // MODULE_H +#endif // STORE_MODULE_H diff --git a/parser/parser.cpp b/parser/parser.cpp index 8bef01f..49218b7 100644 --- a/parser/parser.cpp +++ b/parser/parser.cpp @@ -7,7 +7,7 @@ Parser::Parser() {} std::vector Parser::search_modules() { - std::string path = std::string(std::getenv("HOME")) + "/" + MODULES_DIR; + std::string path = std::string(std::getenv("HOME")) + "/" + STORES_MODULES_DIR; std::filesystem::directory_entry modules_dir(path); if (!modules_dir.exists()) { @@ -27,7 +27,7 @@ std::vector Parser::search_modules() { return modules_files; } -void Parser::set_module(std::string path) { module = Module(path); } +void Parser::set_module(std::string path) { module = StoreModule(path); } std::vector Parser::parse(std::wstring check_plaintext) { std::vector result; diff --git a/parser/parser.h b/parser/parser.h index d97fd25..8b9daf7 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -1,7 +1,6 @@ #ifndef PARSER_H #define PARSER_H -#include #include "module.h" #include #include @@ -9,7 +8,7 @@ class Parser { - Module module; + StoreModule module; public: Parser(); diff --git a/settings.h b/settings.h index 7ad05b3..9677971 100644 --- a/settings.h +++ b/settings.h @@ -1,7 +1,8 @@ #ifndef SETTINGS_H #define SETTINGS_H -#define MODULES_DIR ".local/share/checks_parser/modules" -#define DEBUG +#define OFDS_MODULES_DIR ".local/share/checks_parser/modules/ofd" +#define STORES_MODULES_DIR ".local/share/checks_parser/modules/stores" +// #define DEBUG #endif // SETTINGS_H diff --git a/utils/utils.cpp b/utils/utils.cpp new file mode 100644 index 0000000..262f8d2 --- /dev/null +++ b/utils/utils.cpp @@ -0,0 +1,15 @@ +#include "utils.h" + +#include +#include +#include + +std::string to_utf8(std::wstring wide_string) { + static std::wstring_convert> utf8_conv; + return utf8_conv.to_bytes(wide_string); +} + +std::wstring from_utf8(std::string string) { + static std::wstring_convert> utf8_conv; + return utf8_conv.from_bytes(string); +} diff --git a/utils/utils.h b/utils/utils.h new file mode 100644 index 0000000..39324c0 --- /dev/null +++ b/utils/utils.h @@ -0,0 +1,9 @@ +#ifndef UTILS_H +#define UTILS_H + +#include + +std::string to_utf8(std::wstring wide_string); +std::wstring from_utf8(std::string string); + +#endif // UTILS_H