recalculate
This commit is contained in:
+29
-5
@@ -1,3 +1,4 @@
|
||||
#include "common.h"
|
||||
#include "cbooking.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
@@ -197,6 +198,11 @@ void cBooking::setSoll(const QTime& time)
|
||||
|
||||
QTime cBooking::soll()
|
||||
{
|
||||
if(code() == "G" ||
|
||||
code() == "K" ||
|
||||
code() == "U" ||
|
||||
code() == "SU")
|
||||
return(QTime(0, 0, 0));
|
||||
return(m_soll);
|
||||
}
|
||||
|
||||
@@ -364,9 +370,14 @@ int cBooking::totalPause()
|
||||
return(geht1().secsTo(kommt2()) + geht2().secsTo(kommt3()) + geht3().secsTo(kommt4()) + geht4().secsTo(kommt5()));
|
||||
}
|
||||
|
||||
bool cBookingList::load(cDailyWorkingList* lpDailyWorkingList)
|
||||
cBookingList::cBookingList(cPublicHoliday* lpPublicHoliday, cDailyWorkingList* lpDailyWorkingList) :
|
||||
m_lpPublicHoliday(lpPublicHoliday),
|
||||
m_lpDailyWorkingList(lpDailyWorkingList)
|
||||
{
|
||||
}
|
||||
|
||||
bool cBookingList::load()
|
||||
{
|
||||
m_lpDailyWorkingList = lpDailyWorkingList;
|
||||
QSqlQuery query;
|
||||
|
||||
query.prepare("SELECT datum, "
|
||||
@@ -391,10 +402,18 @@ bool cBookingList::load(cDailyWorkingList* lpDailyWorkingList)
|
||||
return(false);
|
||||
}
|
||||
|
||||
qint16 year = 0;
|
||||
|
||||
while(query.next())
|
||||
{
|
||||
cBooking* lpBooking = add(query.value("datum").toDate());
|
||||
|
||||
if(year != lpBooking->date().year())
|
||||
{
|
||||
year = static_cast<qint16>(lpBooking->date().year());
|
||||
m_lpPublicHoliday->setYear(year);
|
||||
}
|
||||
|
||||
if(lpBooking)
|
||||
{
|
||||
lpBooking->setKommt1(query.value("kommt1").toTime());
|
||||
@@ -410,9 +429,14 @@ bool cBookingList::load(cDailyWorkingList* lpDailyWorkingList)
|
||||
lpBooking->setCode(query.value("code").toString());
|
||||
lpBooking->setInformation(query.value("information").toString());
|
||||
|
||||
cDailyWorking* lpDailyWorking = m_lpDailyWorkingList->get(lpBooking->date());
|
||||
if(lpDailyWorking)
|
||||
lpBooking->setSoll(lpDailyWorking->soll(lpBooking->date().dayOfWeek()));
|
||||
if(!m_lpPublicHoliday->isPublicHoliday(lpBooking->date()))
|
||||
{
|
||||
cDailyWorking* lpDailyWorking = m_lpDailyWorkingList->get(lpBooking->date());
|
||||
if(lpDailyWorking)
|
||||
lpBooking->setSoll(lpDailyWorking->soll(static_cast<qint16>(lpBooking->date().dayOfWeek())));
|
||||
}
|
||||
else
|
||||
lpBooking->setSoll(QTime(0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@
|
||||
#define CBOOKING_H
|
||||
|
||||
|
||||
#include "cpublicholiday.h"
|
||||
#include "cdailyworking.h"
|
||||
|
||||
#include <QMetaType>
|
||||
@@ -107,11 +108,13 @@ Q_DECLARE_METATYPE(cBooking*)
|
||||
class cBookingList : public QList<cBooking*>
|
||||
{
|
||||
public:
|
||||
bool load(cDailyWorkingList* m_dailyWorkingList);
|
||||
explicit cBookingList(cPublicHoliday* lpPublicHoliday, cDailyWorkingList* lpDailyWorkingList);
|
||||
bool load();
|
||||
cBooking* add(const QDate& date);
|
||||
cBooking* find(const QDate& date);
|
||||
|
||||
private:
|
||||
cPublicHoliday* m_lpPublicHoliday;
|
||||
cDailyWorkingList* m_lpDailyWorkingList;
|
||||
};
|
||||
|
||||
|
||||
+4
-4
@@ -121,8 +121,8 @@ bool cDailyWorkingList::load()
|
||||
{
|
||||
QSqlQuery query;
|
||||
|
||||
query.prepare("SELECT datum, "
|
||||
" montag,"
|
||||
query.prepare("SELECT ab, "
|
||||
" montag, "
|
||||
" dienstag, "
|
||||
" mittwoch, "
|
||||
" donnerstag, "
|
||||
@@ -130,7 +130,7 @@ bool cDailyWorkingList::load()
|
||||
" samstag, "
|
||||
" sonntag "
|
||||
"FROM dailyWorking "
|
||||
"ORDER BY datum;");
|
||||
"ORDER BY ab;");
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
@@ -140,7 +140,7 @@ bool cDailyWorkingList::load()
|
||||
|
||||
while(query.next())
|
||||
{
|
||||
cDailyWorking* lpWorking = add(query.value("datum").toDate());
|
||||
cDailyWorking* lpWorking = add(query.value("ab").toDate());
|
||||
|
||||
if(lpWorking)
|
||||
{
|
||||
|
||||
+10
-4
@@ -16,19 +16,25 @@
|
||||
cMainWindow::cMainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::cMainWindow),
|
||||
m_lpMonthlyView(nullptr)
|
||||
m_lpMonthlyView(nullptr),
|
||||
m_lpBookingList(nullptr)
|
||||
{
|
||||
openDB();
|
||||
m_dailyWorkingList.load();
|
||||
m_bookingList.load(&m_dailyWorkingList);
|
||||
|
||||
m_lpBookingList = new cBookingList(&m_publicHoliday, &m_dailyWorkingList);
|
||||
m_lpBookingList->load();
|
||||
|
||||
initUI();
|
||||
|
||||
qDebug() << "count: " << m_bookingList.count();
|
||||
qDebug() << "count: " << m_lpBookingList->count();
|
||||
}
|
||||
|
||||
cMainWindow::~cMainWindow()
|
||||
{
|
||||
if(m_lpBookingList)
|
||||
delete m_lpBookingList;
|
||||
|
||||
if(m_db.isOpen())
|
||||
m_db.close();
|
||||
|
||||
@@ -68,7 +74,7 @@ void cMainWindow::initUI()
|
||||
if(iX != -1 && iY != -1)
|
||||
move(iX, iY);
|
||||
|
||||
m_lpMonthlyView = new cMonthlyView(QDate::currentDate(), &m_bookingList, this);
|
||||
m_lpMonthlyView = new cMonthlyView(QDate::currentDate(), &m_publicHoliday, m_lpBookingList, this);
|
||||
ui->m_lpMainTab->addTab(m_lpMonthlyView, "Monthly");
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "cmonthlyview.h"
|
||||
#include "cdailyworking.h"
|
||||
#include "cpublicholiday.h"
|
||||
#include "cbooking.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
@@ -28,8 +29,10 @@ private:
|
||||
Ui::cMainWindow* ui;
|
||||
cMonthlyView* m_lpMonthlyView;
|
||||
QSqlDatabase m_db;
|
||||
cPublicHoliday m_publicHoliday;
|
||||
cDailyWorkingList m_dailyWorkingList;
|
||||
cBookingList m_bookingList;
|
||||
cBookingList* m_lpBookingList;
|
||||
|
||||
|
||||
void initUI();
|
||||
void openDB();
|
||||
|
||||
+9
-5
@@ -6,10 +6,11 @@
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
cMonthlyView::cMonthlyView(const QDate& date, cBookingList* lpBookingList, QWidget *parent) :
|
||||
cMonthlyView::cMonthlyView(const QDate& date, cPublicHoliday *lpPublicHoliday, cBookingList* lpBookingList, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::cMonthlyView),
|
||||
m_loading(true),
|
||||
m_lpPublicHoliday(lpPublicHoliday),
|
||||
m_lpBookingList(lpBookingList)
|
||||
{
|
||||
m_code.insert(" ", tr(""));
|
||||
@@ -47,7 +48,7 @@ void cMonthlyView::setDate(const QDate& date)
|
||||
{
|
||||
m_loading = true;
|
||||
|
||||
m_publicHoliday.setYear(static_cast<qint16>(date.year()));
|
||||
m_lpPublicHoliday->setYear(static_cast<qint16>(date.year()));
|
||||
|
||||
m_lpMonthlyListModel->clear();
|
||||
|
||||
@@ -108,7 +109,7 @@ void cMonthlyView::setDate(const QDate& date)
|
||||
items.append(new QStandardItem);
|
||||
|
||||
items[COL_DAY1]->setText(date1.toString("dddd dd"));
|
||||
items[COL_PUBLIC_HOLIDAY]->setText(m_publicHoliday.name(date1));
|
||||
items[COL_PUBLIC_HOLIDAY]->setText(m_lpPublicHoliday->name(date1));
|
||||
items[COL_DAY2]->setText(date1.toString("dd dddd"));
|
||||
|
||||
setText(items[COL_COME1], lpBooking->kommt1());
|
||||
@@ -155,7 +156,7 @@ void cMonthlyView::setDate(const QDate& date)
|
||||
|
||||
for(int z = 0;z < items.count();z++)
|
||||
{
|
||||
if(date1.dayOfWeek() >= 6 || m_publicHoliday.isPublicHoliday(date1))
|
||||
if(date1.dayOfWeek() >= 6 || m_lpPublicHoliday->isPublicHoliday(date1))
|
||||
{
|
||||
items[z]->setData(QVariant::fromValue(true), DATA_HOLIDAY);
|
||||
items[z]->setBackground(weekend);
|
||||
@@ -168,7 +169,7 @@ void cMonthlyView::setDate(const QDate& date)
|
||||
|
||||
m_lpMonthlyListModel->appendRow(items);
|
||||
|
||||
if(date1.dayOfWeek() < 6 && !m_publicHoliday.isPublicHoliday(date1))
|
||||
if(date1.dayOfWeek() < 6 && !m_lpPublicHoliday->isPublicHoliday(date1))
|
||||
setBackground(date1.day(), lpBooking->code());
|
||||
}
|
||||
ui->m_lpMonthlyList->resizeColumnToContents(COL_DAY1);
|
||||
@@ -273,6 +274,7 @@ void cMonthlyView::onTextChanged(const int day, const int field, const QString&
|
||||
setBackground(day, code);
|
||||
lpBooking->setCode(code);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
}
|
||||
case COL_INFORMATION:
|
||||
@@ -319,6 +321,7 @@ void cMonthlyView::recalculate(int day, int /*field*/)
|
||||
{
|
||||
QStandardItem* lpPauseItem = m_lpMonthlyListModel->item(day-1, COL_BREAK);
|
||||
QStandardItem* lpIstItem = m_lpMonthlyListModel->item(day-1, COL_IS);
|
||||
QStandardItem* lpSollItem = m_lpMonthlyListModel->item(day-1, COL_SHOULD);
|
||||
QStandardItem* lpDecItem = m_lpMonthlyListModel->item(day-1, COL_HOURS_DEC);
|
||||
|
||||
cBooking* lpBooking = lpPauseItem->data(DATA_BOOKING).value<cBooking*>();
|
||||
@@ -326,4 +329,5 @@ void cMonthlyView::recalculate(int day, int /*field*/)
|
||||
lpPauseItem->setText(lpBooking->pause().toString("hh:mm:ss"));
|
||||
lpIstItem->setText(lpBooking->ist().toString("hh:mm:ss"));
|
||||
lpDecItem->setText(QString::number(lpBooking->hoursDecimal(), 'f', 2));
|
||||
lpSollItem->setText(lpBooking->soll().toString("hh:mm:ss"));
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ class cMonthlyView : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit cMonthlyView(const QDate& date, cBookingList* lpBookingList, QWidget *parent = nullptr);
|
||||
explicit cMonthlyView(const QDate& date, cPublicHoliday* lpPublicHoliday, cBookingList* lpBookingList, QWidget *parent = nullptr);
|
||||
~cMonthlyView();
|
||||
|
||||
void setDate(const QDate& date);
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
bool m_loading;
|
||||
QStandardItemModel* m_lpMonthlyListModel;
|
||||
QMap<QString, QString> m_code;
|
||||
cPublicHoliday m_publicHoliday;
|
||||
cPublicHoliday* m_lpPublicHoliday;
|
||||
cBookingList* m_lpBookingList;
|
||||
|
||||
void setBackground(const int day, const QString& code);
|
||||
|
||||
Reference in New Issue
Block a user