From 9d7d34079b771cf19cd57d7d966cd9b680e22be5 Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Fri, 6 Mar 2020 13:59:36 +0100 Subject: [PATCH] added salery and timesheet --- cmainwindow.cpp | 4 +- cmonthlybooking.cpp | 40 ++++- cmonthlybooking.h | 9 ++ cmonthlyview.cpp | 204 +++++++++++++++++++++++ cmonthlyview.h | 10 ++ cmonthlyview.ui | 387 +++++++++++++++++++++++++++----------------- 6 files changed, 505 insertions(+), 149 deletions(-) diff --git a/cmainwindow.cpp b/cmainwindow.cpp index 168914a..8632dd4 100644 --- a/cmainwindow.cpp +++ b/cmainwindow.cpp @@ -165,7 +165,9 @@ void cMainWindow::openDB() query.prepare("CREATE TABLE monthlyBooking " "( " " datum DATE PRIMARY KEY UNIQUE, " - " ueberstunden INTEGER " + " ueberstunden INTEGER, " + " salery BLOB, " + " timesheet BLOB " ");"); if(!query.exec()) diff --git a/cmonthlybooking.cpp b/cmonthlybooking.cpp index 21e12d9..070335f 100644 --- a/cmonthlybooking.cpp +++ b/cmonthlybooking.cpp @@ -27,6 +27,26 @@ qint32 cMonthlyBooking::ueberstunden() return(m_ueberstunden); } +void cMonthlyBooking::setSalery(const QByteArray& salery) +{ + m_salery = salery; +} + +QByteArray cMonthlyBooking::salery() +{ + return(m_salery); +} + +void cMonthlyBooking::setTimesheet(const QByteArray& timesheet) +{ + m_timesheet = timesheet; +} + +QByteArray cMonthlyBooking::timesheet() +{ + return(m_timesheet); +} + bool cMonthlyBooking::save() { QSqlQuery query; @@ -42,21 +62,29 @@ bool cMonthlyBooking::save() if(query.next()) query.prepare("UPDATE monthlyBooking " - "SET ueberstunden=:ueberstunden " + "SET ueberstunden=:ueberstunden, " + " salery=:salery, " + " timesheet=:timesheet " "WHERE datum=:datum;"); else query.prepare("INSERT INTO monthlyBooking ( " " datum, " - " ueberstunden " + " ueberstunden, " + " salery, " + " timesheet " " ) " "VALUES " " ( " " :datum, " - " :ueberstunden " + " :ueberstunden, " + " :salery, " + " :timesheet " " );"); query.bindValue(":datum", date()); query.bindValue(":ueberstunden", ueberstunden()); + query.bindValue(":salery", salery()); + query.bindValue(":timesheet", timesheet()); if(!query.exec()) { @@ -73,7 +101,9 @@ bool cMonthlyBookingList::load() QSqlQuery query; query.prepare("SELECT datum, " - " ueberstunden " + " ueberstunden, " + " salery, " + " timesheet " "FROM monthlyBooking " "ORDER BY datum;"); @@ -90,6 +120,8 @@ bool cMonthlyBookingList::load() if(lpBooking) { lpBooking->setUeberstunden(query.value("ueberstunden").toInt()); + lpBooking->setSalery(query.value("salery").toByteArray()); + lpBooking->setTimesheet(query.value("timesheet").toByteArray()); } } diff --git a/cmonthlybooking.h b/cmonthlybooking.h index 03af2ce..af8c020 100644 --- a/cmonthlybooking.h +++ b/cmonthlybooking.h @@ -7,6 +7,7 @@ #include #include #include +#include class cMonthlyBooking : public QObject @@ -21,11 +22,19 @@ public: void setUeberstunden(qint32 ueberstunden); qint32 ueberstunden(); + void setSalery(const QByteArray& salery); + QByteArray salery(); + + void setTimesheet(const QByteArray& timesheet); + QByteArray timesheet(); + bool save(); private: QDate m_date; qint32 m_ueberstunden; + QByteArray m_salery; + QByteArray m_timesheet; signals: diff --git a/cmonthlyview.cpp b/cmonthlyview.cpp index c4565ab..583a6ed 100644 --- a/cmonthlyview.cpp +++ b/cmonthlyview.cpp @@ -3,7 +3,12 @@ #include "common.h" +#include #include +#include +#include +#include +#include #include @@ -58,6 +63,16 @@ cMonthlyView::cMonthlyView(const QDate& date, cMonthlyBookingList* lpMonthlyBook connect(ui->m_lpMonth, &QDateEdit::dateChanged, this, &cMonthlyView::onDateChanged); connect(ui->m_lpUeberstunden, &QLineEdit::textChanged, this, &cMonthlyView::onUeberstundenChanged); + + connect(ui->m_lpTimesheetView, &QPushButton::clicked, this, &cMonthlyView::onTimesheetView); + connect(ui->m_lpTimesheetDownload, &QPushButton::clicked, this, &cMonthlyView::onTimesheetDownload); + connect(ui->m_lpTimesheetReplace, &QPushButton::clicked, this, &cMonthlyView::onTimesheetReplace); + connect(ui->m_lpTimesheetDelete, &QPushButton::clicked, this, &cMonthlyView::onTimesheetDelete); + + connect(ui->m_lpSaleryView, &QPushButton::clicked, this, &cMonthlyView::onSaleryView); + connect(ui->m_lpSaleryDownload, &QPushButton::clicked, this, &cMonthlyView::onSaleryDownload); + connect(ui->m_lpSaleryReplace, &QPushButton::clicked, this, &cMonthlyView::onSaleryReplace); + connect(ui->m_lpSaleryDelete, &QPushButton::clicked, this, &cMonthlyView::onSaleryDelete); } void cMonthlyView::setDate(const QDate& date) @@ -207,6 +222,7 @@ void cMonthlyView::setDate(const QDate& date) ui->m_lpResturlaubLabel->setText(QString(tr("Resturlaub %1:")).arg(date.addMonths(-1).toString("MMMM yyyy"))); ui->m_lpUeberstunden->setText(secs2String(m_lpMonthlyBooking->ueberstunden(), 3)); + updatePDF(); displaySummary(); m_loading = false; @@ -214,6 +230,9 @@ void cMonthlyView::setDate(const QDate& date) cMonthlyView::~cMonthlyView() { + for(int x = 0;x < m_temporaryFileList.count();x++) + QFile::remove(m_temporaryFileList[x]); + delete ui; } @@ -334,6 +353,162 @@ void cMonthlyView::onUeberstundenChanged(const QString& string) displaySummary(); } +void cMonthlyView::onTimesheetView() +{ + if(m_lpMonthlyBooking->timesheet().isEmpty()) + return; + + QTemporaryFile file("XXXXXX.pdf"); + + file.setAutoRemove(false); + + if(!file.open()) + return; + + file.write(m_lpMonthlyBooking->timesheet()); + file.close(); + + m_temporaryFileList.append(file.fileName()); + + QDesktopServices::openUrl(QUrl("file:"+file.fileName())); +} + +void cMonthlyView::onTimesheetDownload() +{ + if(m_lpMonthlyBooking->timesheet().isEmpty()) + return; + + QSettings settings; + QString path = settings.value("timesheet/lastFolderSave", QVariant::fromValue(QDir::homePath())).toString(); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save Timesheet"), path, tr("PDF Files (*.pdf)")); + + if(fileName.isEmpty()) + return; + + QFileInfo fileInfo(fileName); + settings.setValue("timesheet/lastFolderSave", QVariant::fromValue(fileInfo.path())); + + QFile file(fileName); + + if(!file.open(QIODevice::WriteOnly)) + return; + + file.write(m_lpMonthlyBooking->timesheet()); + file.close(); +} + +void cMonthlyView::onTimesheetReplace() +{ + QSettings settings; + QString path = settings.value("timesheet/lastFolder", QVariant::fromValue(QDir::homePath())).toString(); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Timesheet"), path, tr("PDF Files (*.pdf)")); + + if(fileName.isEmpty()) + return; + + QFileInfo fileInfo(fileName); + settings.setValue("timesheet/lastFolder", QVariant::fromValue(fileInfo.path())); + + QFile file(fileName); + if(!file.open(QIODevice::ReadOnly)) + return; + + QByteArray data = file.readAll(); + file.close(); + + m_lpMonthlyBooking->setTimesheet(data); + m_lpMonthlyBooking->save(); + updatePDF(); +} + +void cMonthlyView::onTimesheetDelete() +{ + if(QMessageBox::question(this, tr("Delete Timesheet"), tr("Are you sure you want to delete the timesheet?")) == QMessageBox::No) + return; + + m_lpMonthlyBooking->setTimesheet(QByteArray()); + m_lpMonthlyBooking->save(); + updatePDF(); +} + +void cMonthlyView::onSaleryView() +{ + if(m_lpMonthlyBooking->salery().isEmpty()) + return; + + QTemporaryFile file("XXXXXX.pdf"); + + file.setAutoRemove(false); + + if(!file.open()) + return; + + file.write(m_lpMonthlyBooking->salery()); + file.close(); + + m_temporaryFileList.append(file.fileName()); + + QDesktopServices::openUrl(QUrl("file:"+file.fileName())); +} + +void cMonthlyView::onSaleryDownload() +{ + if(m_lpMonthlyBooking->salery().isEmpty()) + return; + + QSettings settings; + QString path = settings.value("salery/lastFolderSave", QVariant::fromValue(QDir::homePath())).toString(); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save Salery"), path, tr("PDF Files (*.pdf)")); + + if(fileName.isEmpty()) + return; + + QFileInfo fileInfo(fileName); + settings.setValue("salery/lastFolderSave", QVariant::fromValue(fileInfo.path())); + + QFile file(fileName); + + if(!file.open(QIODevice::WriteOnly)) + return; + + file.write(m_lpMonthlyBooking->salery()); + file.close(); +} + +void cMonthlyView::onSaleryReplace() +{ + QSettings settings; + QString path = settings.value("salery/lastFolder", QVariant::fromValue(QDir::homePath())).toString(); + QString fileName = QFileDialog::getOpenFileName(this, tr("Open Salery"), path, tr("PDF Files (*.pdf)")); + + if(fileName.isEmpty()) + return; + + QFileInfo fileInfo(fileName); + settings.setValue("salery/lastFolder", QVariant::fromValue(fileInfo.path())); + + QFile file(fileName); + if(!file.open(QIODevice::ReadOnly)) + return; + + QByteArray data = file.readAll(); + file.close(); + + m_lpMonthlyBooking->setSalery(data); + m_lpMonthlyBooking->save(); + updatePDF(); +} + +void cMonthlyView::onSaleryDelete() +{ + if(QMessageBox::question(this, tr("Delete Salery"), tr("Are you sure you want to delete the salery?")) == QMessageBox::No) + return; + + m_lpMonthlyBooking->setSalery(QByteArray()); + m_lpMonthlyBooking->save(); + updatePDF(); +} + void cMonthlyView::setBackground(const int day, const QString& code) { QBrush brush; @@ -441,3 +616,32 @@ void cMonthlyView::displaySummary() ui->m_lpSonderurlaub->setText(QString::number(su)); ui->m_lpTraining->setText(QString::number(t)); } + +void cMonthlyView::updatePDF() +{ + if(m_lpMonthlyBooking->salery().isEmpty()) + { + ui->m_lpSaleryView->setEnabled(false); + ui->m_lpSaleryDownload->setEnabled(false); + ui->m_lpSaleryDelete->setEnabled(false); + } + else + { + ui->m_lpSaleryView->setEnabled(true); + ui->m_lpSaleryDownload->setEnabled(true); + ui->m_lpSaleryDelete->setEnabled(true); + } + + if(m_lpMonthlyBooking->timesheet().isEmpty()) + { + ui->m_lpTimesheetView->setEnabled(false); + ui->m_lpTimesheetDownload->setEnabled(false); + ui->m_lpTimesheetDelete->setEnabled(false); + } + else + { + ui->m_lpTimesheetView->setEnabled(true); + ui->m_lpTimesheetDownload->setEnabled(true); + ui->m_lpTimesheetDelete->setEnabled(true); + } +} diff --git a/cmonthlyview.h b/cmonthlyview.h index 250a5fc..8e77147 100644 --- a/cmonthlyview.h +++ b/cmonthlyview.h @@ -40,12 +40,14 @@ private: QDate m_date; cMonthlyBooking* m_lpMonthlyBooking; QRegExpValidator* m_lpValidator; + QStringList m_temporaryFileList; void setBackground(const int day, const QString& code); void setText(QStandardItem* lpItem, const QTime& time); void recalculate(int day, int field); void displaySummary(); + void updatePDF(); private slots: void onPrevMonth(); @@ -54,6 +56,14 @@ private slots: void onTextChanged(const int day, const int field, const QString& text); void onDateChanged(const QDate& date); void onUeberstundenChanged(const QString& string); + void onTimesheetView(); + void onTimesheetDownload(); + void onTimesheetReplace(); + void onTimesheetDelete(); + void onSaleryView(); + void onSaleryDownload(); + void onSaleryReplace(); + void onSaleryDelete(); }; #endif // CMONTHLYVIEW_H diff --git a/cmonthlyview.ui b/cmonthlyview.ui index e508660..42ee877 100644 --- a/cmonthlyview.ui +++ b/cmonthlyview.ui @@ -116,11 +116,68 @@ - - - + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + - Sonderurlaub + SOLL: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Krank + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Gleitzeit + + + + + + + Resturlaub: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -140,16 +197,6 @@ - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - @@ -160,50 +207,17 @@ - - + + - SOLL: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - + + - Übertrag: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - - - Übertrag nächster Monat: + ausbezahlte Überstunden: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -220,20 +234,109 @@ - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - + + + + + + Timesheet + + + + + + + + view + + + + + + + download + + + + + + + replace + + + + + + + delete + + + + + + + + + + + + Salery + + + + + + + + view + + + + + + + download + + + + + + + replace + + + + + + + delete + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - - + + - ausbezahlte Überstunden: + Saldo: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -257,18 +360,8 @@ - - - - Übertrag Urlaub: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - + + @@ -281,23 +374,6 @@ - - - - Gleitzeit - - - - - - - IST: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -314,39 +390,6 @@ - - - - Saldo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - @@ -357,10 +400,54 @@ - - + + - Resturlaub: + Sonderurlaub + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + + + + + Übertrag nächster Monat: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Übertrag: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -377,27 +464,39 @@ - - + + - + Übertrag Urlaub: - - - - - - Krank - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + IST: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + +