2024-11-22 23:26:42 +03:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "./ui_mainwindow.h"
|
|
|
|
#include "check/check.h"
|
2024-11-28 00:28:37 +03:00
|
|
|
#include "exceptions/ofdrequestexception.h"
|
2024-11-22 23:26:42 +03:00
|
|
|
#include "goods/goods.h"
|
|
|
|
#include "outputdialog.h"
|
|
|
|
#include "adjustpicturedialog.h"
|
|
|
|
#include "settingsdialog.h"
|
2024-11-24 19:07:28 +03:00
|
|
|
#include "solvecaptchadialog.h"
|
2024-11-22 23:26:42 +03:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include "image/checkimage.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include <opencv2/objdetect.hpp>
|
|
|
|
#include <opencv2/imgcodecs.hpp>
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
|
|
|
#include <opencv2/imgproc/imgproc.hpp>
|
|
|
|
#include <zbar.h>
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
|
|
ui->setupUi(this);
|
|
|
|
this->setupStoresList();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() { delete ui; }
|
|
|
|
|
|
|
|
void MainWindow::setupStoresList() {
|
|
|
|
parser = *(new Parser());
|
|
|
|
|
|
|
|
std::vector<std::string> modules_names = parser.search_modules();
|
|
|
|
|
|
|
|
for (std::string name : modules_names) {
|
|
|
|
StoreModule m(name);
|
|
|
|
std::wstring module_name = m.get_name();
|
|
|
|
|
|
|
|
QString s = QString::fromStdWString(module_name);
|
|
|
|
ui->storeType->addItem(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-24 19:07:28 +03:00
|
|
|
std::string MainWindow::makeRequestToOfd(std::string captcha) {
|
|
|
|
std::string checkContent = Net().fetch_check_data_from_ofdru(
|
|
|
|
ui->fn_edit->text().toStdString(),
|
|
|
|
ui->fd_edit->text().toStdString(),
|
|
|
|
ui->fi_edit->text().toStdString(),
|
|
|
|
ui->dateTimeEdit->dateTime().toString(Qt::ISODate).toStdString(),
|
|
|
|
ui->fundIncomeCombo->currentIndex() + 1,
|
|
|
|
// In the request to ofd.ru, total is in a strange format, like a string of a format where 2 last digits represent decimal part of a number.
|
|
|
|
ui->total_edit->text().toDouble() * 100,
|
|
|
|
captcha);
|
|
|
|
|
2024-11-25 04:07:56 +03:00
|
|
|
return checkContent;
|
2024-11-24 19:07:28 +03:00
|
|
|
}
|
|
|
|
|
2024-11-22 23:26:42 +03:00
|
|
|
void MainWindow::on_parseButton_clicked() {
|
|
|
|
QString s;
|
2024-11-24 19:07:28 +03:00
|
|
|
switch (ui->tabWidget->currentIndex()) {
|
2024-11-22 23:26:42 +03:00
|
|
|
case 0:
|
|
|
|
s = ui->checkContent->toPlainText();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
s = ui->checkContentFromImage->toPlainText();
|
|
|
|
break;
|
2024-11-24 19:07:28 +03:00
|
|
|
case 2:
|
|
|
|
Net().get_captcha_from_ofdru();
|
2024-11-27 01:46:36 +03:00
|
|
|
|
2024-11-28 00:28:37 +03:00
|
|
|
std::string solved_captcha = "";
|
|
|
|
bool success = true;
|
|
|
|
bool is_captcha_solved = true;
|
|
|
|
|
|
|
|
do {
|
|
|
|
SolveCaptchaDialog dialog = SolveCaptchaDialog(this, &solved_captcha);
|
|
|
|
dialog.exec();
|
|
|
|
is_captcha_solved = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
std::string check_content = makeRequestToOfd(solved_captcha);
|
|
|
|
check = parseOfdRuAnswer(check_content);
|
|
|
|
} catch(OfdRequestException e) {
|
|
|
|
success = false;
|
|
|
|
if (!strcmp(e.what(), "Incorrect captcha")) {
|
|
|
|
is_captcha_solved = false;
|
|
|
|
QMessageBox infoDialog;
|
2024-12-01 15:01:55 +03:00
|
|
|
infoDialog.setText(tr("Captcha was not solved correctly!"));
|
2024-11-28 00:28:37 +03:00
|
|
|
infoDialog.setIcon(QMessageBox::Critical);
|
2024-12-01 15:01:55 +03:00
|
|
|
infoDialog.setWindowTitle(tr("Captcha is incorrect"));
|
2024-11-28 00:28:37 +03:00
|
|
|
infoDialog.exec();
|
|
|
|
break;
|
|
|
|
} else if (!strcmp(e.what(), "Does not exist")) {
|
|
|
|
QMessageBox infoDialog;
|
2024-12-01 15:01:55 +03:00
|
|
|
infoDialog.setText(tr("Check not found. Please, ensure correctness of entered data."));
|
2024-11-28 00:28:37 +03:00
|
|
|
infoDialog.setIcon(QMessageBox::Critical);
|
2024-12-01 15:01:55 +03:00
|
|
|
infoDialog.setWindowTitle(tr("Check was not found"));
|
2024-11-28 00:28:37 +03:00
|
|
|
infoDialog.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!is_captcha_solved);
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
OutputDialog d = OutputDialog(this, check);
|
|
|
|
d.exec();
|
|
|
|
}
|
|
|
|
|
2024-11-24 19:07:28 +03:00
|
|
|
return;
|
2024-11-22 23:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring check_plaintext = s.toStdWString();
|
|
|
|
parser.set_module(parser.search_modules()[0]);
|
|
|
|
|
|
|
|
std::vector<Goods> c = parser.parse(check_plaintext);
|
|
|
|
|
|
|
|
if (c.size() == 0) {
|
2024-12-04 04:35:51 +03:00
|
|
|
QMessageBox infoDialog;
|
|
|
|
infoDialog.setText(tr("An error has occured. Check was matched incorrectly. Vector sizes are different. Please, contact the developer."));
|
|
|
|
infoDialog.setIcon(QMessageBox::Critical);
|
|
|
|
infoDialog.setWindowTitle(tr("Error in parsing"));
|
|
|
|
infoDialog.exec();
|
2024-11-22 23:26:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& g : c) {
|
|
|
|
check.add_goods(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputDialog d = OutputDialog(this, check);
|
|
|
|
d.show();
|
|
|
|
d.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_storeType_currentIndexChanged(int index) {
|
|
|
|
std::string module = parser.search_modules()[index];
|
|
|
|
parser.set_module(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_preferencesButton_clicked() {
|
|
|
|
SettingsDialog s = SettingsDialog();
|
|
|
|
s.show();
|
|
|
|
s.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_chooseImageButton_ofd_clicked() {
|
|
|
|
QString filename = QFileDialog::getOpenFileName();
|
|
|
|
|
2024-12-02 14:12:03 +03:00
|
|
|
if (filename == "") {
|
|
|
|
QMessageBox infoDialog;
|
|
|
|
infoDialog.setText(tr("Please, select a picture where QR code that contains info about check is present"));
|
|
|
|
infoDialog.setIcon(QMessageBox::Critical);
|
|
|
|
infoDialog.setWindowTitle(tr("Picture was not selected"));
|
|
|
|
infoDialog.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-22 23:26:42 +03:00
|
|
|
std::string new_text = "Selected: " + filename.toStdString();
|
|
|
|
ui->pathLabel_ofd->setText(QString::fromStdString(new_text));
|
|
|
|
|
|
|
|
AdjustPictureDialog dialog = AdjustPictureDialog(this, filename.toStdString());
|
|
|
|
connect(&dialog, &AdjustPictureDialog::decodedData, this, &MainWindow::onDecodedData);
|
|
|
|
dialog.exec();
|
|
|
|
|
|
|
|
ui->picture_ofd->setPixmap(QPixmap(filename));
|
|
|
|
ui->picture_ofd->setScaledContents(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onDecodedData(std::string data) {
|
|
|
|
std::string delimiter = "&";
|
|
|
|
std::vector<std::string> dataSplit = split(data, delimiter);
|
|
|
|
|
|
|
|
std::cout << data << std::endl;
|
|
|
|
|
|
|
|
ui->fn_edit->setText(QString::fromStdString(dataSplit[2]));
|
|
|
|
ui->fd_edit->setText(QString::fromStdString(dataSplit[3]));
|
|
|
|
ui->fi_edit->setText(QString::fromStdString(dataSplit[4]));
|
|
|
|
|
|
|
|
QString extractedDateTime = QString::fromStdString(split(dataSplit[0], "=")[1]);
|
|
|
|
QDateTime datetime = QDateTime::fromString(extractedDateTime, "yyyyMMddThhmm");
|
|
|
|
ui->dateTimeEdit->setDateTime(datetime);
|
|
|
|
|
2024-11-24 19:07:28 +03:00
|
|
|
int type = std::stoi(split(dataSplit[5], "=")[1]);
|
|
|
|
ui->fundIncomeCombo->setCurrentIndex(type - 1);
|
|
|
|
|
|
|
|
std::string total = split(dataSplit[1], "=")[1];
|
|
|
|
|
|
|
|
ui->total_edit->setText(QString::fromStdString(total));
|
2024-11-22 23:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::on_chooseImageButton_ocr_clicked()
|
|
|
|
{
|
|
|
|
QString filename = QFileDialog::getOpenFileName();
|
|
|
|
|
2024-12-02 14:12:03 +03:00
|
|
|
if (filename == "") {
|
|
|
|
QMessageBox infoDialog;
|
|
|
|
infoDialog.setText(tr("Please, select a picture to scan"));
|
|
|
|
infoDialog.setIcon(QMessageBox::Critical);
|
|
|
|
infoDialog.setWindowTitle(tr("Picture was not selected"));
|
|
|
|
infoDialog.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-22 23:26:42 +03:00
|
|
|
std::string new_text = "Selected: " + filename.toStdString();
|
|
|
|
ui->pathLabel_ocr->setText(QString::fromStdString(new_text));
|
|
|
|
|
|
|
|
CheckImage i(filename.toStdString());
|
|
|
|
std::string parsed = i.parse_text();
|
|
|
|
|
|
|
|
ui->picture_ocr->setPixmap(QPixmap(filename));
|
|
|
|
ui->picture_ocr->setScaledContents(true);
|
|
|
|
ui->checkContentFromImage->setPlainText(QString::fromStdString(parsed));
|
|
|
|
}
|
|
|
|
|