Imported existing sources
This commit is contained in:
BIN
images/refresh.png
Normal file
BIN
images/refresh.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
BIN
images/report.png
Normal file
BIN
images/report.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
36
reportsplugin.cpp
Normal file
36
reportsplugin.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include "reportsplugin.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QLocale>
|
||||||
|
#include <QStatusBar>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
#include "reportswidget.h"
|
||||||
|
|
||||||
|
ReportsPlugin::ReportsPlugin(QObject *parent) :
|
||||||
|
ZeiterfassungPlugin(parent)
|
||||||
|
{
|
||||||
|
qDebug() << "called";
|
||||||
|
|
||||||
|
static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations"));
|
||||||
|
|
||||||
|
if(m_translator.load(QLocale(), QStringLiteral("reportsplugin"), QStringLiteral("_"), dir))
|
||||||
|
{
|
||||||
|
if(!QCoreApplication::installTranslator(&m_translator))
|
||||||
|
{
|
||||||
|
qWarning() << "could not install translation reportsplugin";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning() << "could not load translation reportsplugin";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportsPlugin::attachTo(MainWindow &mainWindow)
|
||||||
|
{
|
||||||
|
mainWindow.statusBar()->addPermanentWidget(new ReportsWidget(mainWindow));
|
||||||
|
}
|
24
reportsplugin.h
Normal file
24
reportsplugin.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
|
#include "zeiterfassungplugin.h"
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
|
|
||||||
|
class Q_DECL_EXPORT ReportsPlugin : public ZeiterfassungPlugin
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PLUGIN_METADATA(IID "dbsoftware.zeiterfassung.plugin/1.0" FILE "reportsplugin.json")
|
||||||
|
Q_INTERFACES(ZeiterfassungPlugin)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ReportsPlugin(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
// ZeiterfassungPlugin interface
|
||||||
|
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTranslator m_translator;
|
||||||
|
};
|
0
reportsplugin.json
Normal file
0
reportsplugin.json
Normal file
22
reportsplugin.pro
Normal file
22
reportsplugin.pro
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
QT += core network gui widgets
|
||||||
|
|
||||||
|
DBLIBS += zeiterfassungcore zeiterfassunggui
|
||||||
|
|
||||||
|
TARGET = reportsplugin
|
||||||
|
|
||||||
|
HEADERS += reportsplugin.h \
|
||||||
|
reportswidget.h
|
||||||
|
|
||||||
|
SOURCES += reportsplugin.cpp \
|
||||||
|
reportswidget.cpp
|
||||||
|
|
||||||
|
FORMS +=
|
||||||
|
|
||||||
|
RESOURCES += reportsplugin_resources.qrc
|
||||||
|
|
||||||
|
TRANSLATIONS += translations/reportsplugin_en.ts \
|
||||||
|
translations/reportsplugin_de.ts
|
||||||
|
|
||||||
|
OTHER_FILES += reportsplugin.json
|
||||||
|
|
||||||
|
include(../plugin.pri)
|
6
reportsplugin_resources.qrc
Normal file
6
reportsplugin_resources.qrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/zeiterfassung/plugins/reportsplugin">
|
||||||
|
<file>images/refresh.png</file>
|
||||||
|
<file>images/report.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
150
reportswidget.cpp
Normal file
150
reportswidget.cpp
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
#include "reportswidget.h"
|
||||||
|
|
||||||
|
#include <QStatusBar>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QToolBar>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QStringBuilder>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
#include "zeiterfassungapi.h"
|
||||||
|
|
||||||
|
ReportsWidget::ReportsWidget(MainWindow &mainWindow) :
|
||||||
|
QLabel(&mainWindow),
|
||||||
|
m_mainWindow(mainWindow)
|
||||||
|
{
|
||||||
|
connect(&m_mainWindow, &MainWindow::dateChanged, this, &ReportsWidget::dateChanged);
|
||||||
|
connect(&m_mainWindow, &MainWindow::refreshEverything, this, &ReportsWidget::refresh);
|
||||||
|
|
||||||
|
setFrameShape(QFrame::Panel);
|
||||||
|
setFrameShadow(QFrame::Sunken);
|
||||||
|
|
||||||
|
m_actionRefreshReport = new QAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/reportsplugin/images/refresh.png")),
|
||||||
|
tr("Refresh report"), this);
|
||||||
|
connect(m_actionRefreshReport, &QAction::triggered, this, &ReportsWidget::refresh);
|
||||||
|
m_mainWindow.menuView()->addAction(m_actionRefreshReport);
|
||||||
|
|
||||||
|
m_actionOpenReport = new QAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/reportsplugin/images/report.png")),
|
||||||
|
tr("Open report"), this);
|
||||||
|
connect(m_actionOpenReport, &QAction::triggered, this, &ReportsWidget::openReport);
|
||||||
|
m_mainWindow.menuTools()->addAction(m_actionOpenReport);
|
||||||
|
|
||||||
|
m_mainWindow.toolBar()->addAction(m_actionOpenReport);
|
||||||
|
|
||||||
|
dateChanged(m_mainWindow.date());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportsWidget::dateChanged(const QDate &date)
|
||||||
|
{
|
||||||
|
if(!date.isValid())
|
||||||
|
{
|
||||||
|
qWarning() << "invalid date" << date;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto monthBegin = QDate(date.year(), date.month(), 1);
|
||||||
|
if(monthBegin != m_date)
|
||||||
|
{
|
||||||
|
m_date = monthBegin;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportsWidget::refresh()
|
||||||
|
{
|
||||||
|
if(!m_date.isValid())
|
||||||
|
{
|
||||||
|
qWarning() << "invalid date" << m_date;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setText(tr("Balance: %0, Holidays: %1").arg(tr("???")).arg(tr("???")));
|
||||||
|
|
||||||
|
m_actionRefreshReport->setEnabled(false);
|
||||||
|
m_actionOpenReport->setEnabled(false);
|
||||||
|
|
||||||
|
m_reply = m_mainWindow.erfassung().doGetReport(m_mainWindow.userInfo().userId, m_date);
|
||||||
|
connect(m_reply.get(), &ZeiterfassungReply::finished, this, &ReportsWidget::finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportsWidget::finished()
|
||||||
|
{
|
||||||
|
if(!m_reply->success())
|
||||||
|
{
|
||||||
|
m_date = QDate();
|
||||||
|
QMessageBox::warning(this, tr("Could not load report!"), tr("Could not load report!") % "\n\n" % m_reply->message());
|
||||||
|
goto after;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto content = m_reply->content();
|
||||||
|
|
||||||
|
QString balance;
|
||||||
|
|
||||||
|
{
|
||||||
|
static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)"));
|
||||||
|
auto match = regex.match(content);
|
||||||
|
if(match.hasMatch())
|
||||||
|
{
|
||||||
|
balance = match.captured(2);
|
||||||
|
if(balance.endsWith(QChar('-')))
|
||||||
|
{
|
||||||
|
balance.chop(1);
|
||||||
|
balance = QChar('-') % balance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
balance = tr("n/a");
|
||||||
|
qWarning() << "balance not found in PDF";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString holidays;
|
||||||
|
|
||||||
|
{
|
||||||
|
static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +(\\-?[0-9]+\\.[0-9]+) +(\\-?[0-9]+\\.[0-9]+)"));
|
||||||
|
auto match = regex.match(content);
|
||||||
|
if(match.hasMatch())
|
||||||
|
holidays = match.captured(2);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
holidays = tr("n/a");
|
||||||
|
qWarning() << "holidays not found in PDF";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setText(tr("Balance: %0, Holidays: %1").arg(balance).arg(holidays));
|
||||||
|
|
||||||
|
{
|
||||||
|
QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("reportXXXXXX.pdf")));
|
||||||
|
file.setAutoRemove(false);
|
||||||
|
if(!file.open())
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Could not write report!"), tr("Could not write report!") % "\n\n" % file.errorString());
|
||||||
|
goto after;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(content);
|
||||||
|
|
||||||
|
m_url = QUrl::fromLocalFile(file.fileName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_actionOpenReport->setEnabled(true);
|
||||||
|
|
||||||
|
after:
|
||||||
|
m_actionRefreshReport->setEnabled(true);
|
||||||
|
m_reply = Q_NULLPTR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportsWidget::openReport()
|
||||||
|
{
|
||||||
|
if(!QDesktopServices::openUrl(m_url))
|
||||||
|
QMessageBox::warning(this, tr("Could not launch your default PDF viewer!"), tr("Could not launch your default PDF viewer!"));
|
||||||
|
}
|
36
reportswidget.h
Normal file
36
reportswidget.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
#include "replies/getreportreply.h"
|
||||||
|
|
||||||
|
class QAction;
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
|
|
||||||
|
class ReportsWidget : public QLabel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ReportsWidget(MainWindow &mainWindow);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void dateChanged(const QDate &date);
|
||||||
|
void refresh();
|
||||||
|
void finished();
|
||||||
|
void openReport();
|
||||||
|
|
||||||
|
private:
|
||||||
|
MainWindow &m_mainWindow;
|
||||||
|
|
||||||
|
QAction *m_actionOpenReport;
|
||||||
|
QAction *m_actionRefreshReport;
|
||||||
|
|
||||||
|
QDate m_date;
|
||||||
|
QUrl m_url;
|
||||||
|
|
||||||
|
std::unique_ptr<GetReportReply> m_reply;
|
||||||
|
};
|
49
translations/reportsplugin_de.ts
Normal file
49
translations/reportsplugin_de.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1" language="de_DE">
|
||||||
|
<context>
|
||||||
|
<name>ReportsWidget</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="28"/>
|
||||||
|
<source>Refresh report</source>
|
||||||
|
<translation>Auswertung aktualisieren</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="33"/>
|
||||||
|
<source>Open report</source>
|
||||||
|
<translation>Auswertung öffnen</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="66"/>
|
||||||
|
<source>???</source>
|
||||||
|
<translation>???</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="66"/>
|
||||||
|
<location filename="../reportswidget.cpp" line="122"/>
|
||||||
|
<source>Balance: %0, Holidays: %1</source>
|
||||||
|
<translation>Gleitzeit: %0, Urlaub: %1</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="80"/>
|
||||||
|
<source>Could not load report!</source>
|
||||||
|
<translation>Konnte Auswertung nicht laden!</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="103"/>
|
||||||
|
<location filename="../reportswidget.cpp" line="117"/>
|
||||||
|
<source>n/a</source>
|
||||||
|
<translation>n/v</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="129"/>
|
||||||
|
<source>Could not write report!</source>
|
||||||
|
<translation>Konnte Auswertung nicht abspeichern!</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="149"/>
|
||||||
|
<source>Could not launch your default PDF viewer!</source>
|
||||||
|
<translation>Konnte Standard-PDF-Viewer nicht öffnen!</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
</TS>
|
49
translations/reportsplugin_en.ts
Normal file
49
translations/reportsplugin_en.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!DOCTYPE TS>
|
||||||
|
<TS version="2.1" language="en_US">
|
||||||
|
<context>
|
||||||
|
<name>ReportsWidget</name>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="28"/>
|
||||||
|
<source>Refresh report</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="33"/>
|
||||||
|
<source>Open report</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="66"/>
|
||||||
|
<source>???</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="66"/>
|
||||||
|
<location filename="../reportswidget.cpp" line="122"/>
|
||||||
|
<source>Balance: %0, Holidays: %1</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="80"/>
|
||||||
|
<source>Could not load report!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="103"/>
|
||||||
|
<location filename="../reportswidget.cpp" line="117"/>
|
||||||
|
<source>n/a</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="129"/>
|
||||||
|
<source>Could not write report!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<location filename="../reportswidget.cpp" line="149"/>
|
||||||
|
<source>Could not launch your default PDF viewer!</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
|
</TS>
|
Reference in New Issue
Block a user