calculation break, is, is decimal
This commit is contained in:
+61
-13
@@ -152,14 +152,42 @@ QString cBooking::information()
|
|||||||
return(m_information);
|
return(m_information);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint32 cBooking::pauseSecs()
|
||||||
|
{
|
||||||
|
int w = totalWork();
|
||||||
|
int p = totalPause();
|
||||||
|
|
||||||
|
if(w < 21600)
|
||||||
|
return(0);
|
||||||
|
|
||||||
|
if(p < 1800)
|
||||||
|
return(1800-p);
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
QTime cBooking::pause()
|
QTime cBooking::pause()
|
||||||
{
|
{
|
||||||
return(QTime(0, 0, 0));
|
return(QTime(0, 0, 0).addSecs(pauseSecs()));
|
||||||
|
}
|
||||||
|
|
||||||
|
qint32 cBooking::istSecs()
|
||||||
|
{
|
||||||
|
int w = totalWork();
|
||||||
|
int p = totalPause();
|
||||||
|
|
||||||
|
if(w < 21600)
|
||||||
|
return(w);
|
||||||
|
|
||||||
|
if(p < 1800)
|
||||||
|
return(w - (1800-p));
|
||||||
|
|
||||||
|
return(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
QTime cBooking::ist()
|
QTime cBooking::ist()
|
||||||
{
|
{
|
||||||
return(QTime(0, 0, 0));
|
return(QTime(0, 0, 0).addSecs(istSecs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cBooking::setSoll()
|
void cBooking::setSoll()
|
||||||
@@ -228,7 +256,9 @@ QString cBooking::currentDiffString()
|
|||||||
|
|
||||||
qreal cBooking::hoursDecimal()
|
qreal cBooking::hoursDecimal()
|
||||||
{
|
{
|
||||||
return(0);
|
int w = istSecs();
|
||||||
|
|
||||||
|
return(static_cast<qreal>(w)/3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cBooking::save()
|
bool cBooking::save()
|
||||||
@@ -293,16 +323,16 @@ bool cBooking::save()
|
|||||||
" );");
|
" );");
|
||||||
|
|
||||||
query.bindValue(":datum", date());
|
query.bindValue(":datum", date());
|
||||||
query.bindValue(":kommt1", kommt1());
|
bind(query, ":kommt1", kommt1());
|
||||||
query.bindValue(":geht1", geht1());
|
bind(query, ":geht1", geht1());
|
||||||
query.bindValue(":kommt2", kommt2());
|
bind(query, ":kommt2", kommt2());
|
||||||
query.bindValue(":geht2", geht2());
|
bind(query, ":geht2", geht2());
|
||||||
query.bindValue(":kommt3", kommt3());
|
bind(query, ":kommt3", kommt3());
|
||||||
query.bindValue(":geht3", geht3());
|
bind(query, ":geht3", geht3());
|
||||||
query.bindValue(":kommt4", kommt4());
|
bind(query, ":kommt4", kommt4());
|
||||||
query.bindValue(":geht4", geht4());
|
bind(query, ":geht4", geht4());
|
||||||
query.bindValue(":kommt5", kommt5());
|
bind(query, ":kommt5", kommt5());
|
||||||
query.bindValue(":geht5", geht5());
|
bind(query, ":geht5", geht5());
|
||||||
query.bindValue(":code", code());
|
query.bindValue(":code", code());
|
||||||
query.bindValue(":information", information());
|
query.bindValue(":information", information());
|
||||||
|
|
||||||
@@ -316,6 +346,24 @@ bool cBooking::save()
|
|||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cBooking::bind(QSqlQuery& query, const QString& variable, const QTime& time)
|
||||||
|
{
|
||||||
|
if(time == QTime(0, 0, 0))
|
||||||
|
query.bindValue(variable, QVariant(QVariant::Time));
|
||||||
|
else
|
||||||
|
query.bindValue(variable, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cBooking::totalWork()
|
||||||
|
{
|
||||||
|
return(kommt1().secsTo(geht1()) + kommt2().secsTo(geht2()) + kommt3().secsTo(geht3()) + kommt4().secsTo(geht4()) + kommt5().secsTo(geht5()));
|
||||||
|
}
|
||||||
|
|
||||||
|
int cBooking::totalPause()
|
||||||
|
{
|
||||||
|
return(geht1().secsTo(kommt2()) + geht2().secsTo(kommt3()) + geht3().secsTo(kommt4()) + geht4().secsTo(kommt5()));
|
||||||
|
}
|
||||||
|
|
||||||
bool cBookingList::load()
|
bool cBookingList::load()
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
|
#include <QSqlQuery>
|
||||||
|
|
||||||
|
|
||||||
class cBooking : public QObject
|
class cBooking : public QObject
|
||||||
{
|
{
|
||||||
@@ -54,8 +56,10 @@ public:
|
|||||||
void setInformation(const QString& information);
|
void setInformation(const QString& information);
|
||||||
QString information();
|
QString information();
|
||||||
|
|
||||||
|
qint32 pauseSecs();
|
||||||
QTime pause();
|
QTime pause();
|
||||||
|
|
||||||
|
qint32 istSecs();
|
||||||
QTime ist();
|
QTime ist();
|
||||||
|
|
||||||
void setSoll();
|
void setSoll();
|
||||||
@@ -89,6 +93,11 @@ private:
|
|||||||
QString m_information;
|
QString m_information;
|
||||||
QTime m_soll;
|
QTime m_soll;
|
||||||
qint32 m_prevDiff;
|
qint32 m_prevDiff;
|
||||||
|
|
||||||
|
void bind(QSqlQuery& query, const QString& variable, const QTime& time);
|
||||||
|
|
||||||
|
int totalWork();
|
||||||
|
int totalPause();
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(cBooking*)
|
Q_DECLARE_METATYPE(cBooking*)
|
||||||
|
|||||||
+48
-16
@@ -111,16 +111,17 @@ void cMonthlyView::setDate(const QDate& date)
|
|||||||
items[COL_PUBLIC_HOLIDAY]->setText(m_publicHoliday.name(date1));
|
items[COL_PUBLIC_HOLIDAY]->setText(m_publicHoliday.name(date1));
|
||||||
items[COL_DAY2]->setText(date1.toString("dd dddd"));
|
items[COL_DAY2]->setText(date1.toString("dd dddd"));
|
||||||
|
|
||||||
items[COL_COME1]->setText(lpBooking->kommt1().toString("hh:mm:ss"));
|
setText(items[COL_COME1], lpBooking->kommt1());
|
||||||
items[COL_GO1]->setText(lpBooking->geht1().toString("hh:mm:ss"));
|
setText(items[COL_COME1], lpBooking->kommt1());
|
||||||
items[COL_COME2]->setText(lpBooking->kommt2().toString("hh:mm:ss"));
|
setText(items[COL_GO1], lpBooking->geht1());
|
||||||
items[COL_GO2]->setText(lpBooking->geht2().toString("hh:mm:ss"));
|
setText(items[COL_COME2], lpBooking->kommt2());
|
||||||
items[COL_COME3]->setText(lpBooking->kommt3().toString("hh:mm:ss"));
|
setText(items[COL_GO2], lpBooking->geht2());
|
||||||
items[COL_GO3]->setText(lpBooking->geht3().toString("hh:mm:ss"));
|
setText(items[COL_COME3], lpBooking->kommt3());
|
||||||
items[COL_COME4]->setText(lpBooking->kommt4().toString("hh:mm:ss"));
|
setText(items[COL_GO3], lpBooking->geht3());
|
||||||
items[COL_GO4]->setText(lpBooking->geht4().toString("hh:mm:ss"));
|
setText(items[COL_COME4], lpBooking->kommt4());
|
||||||
items[COL_COME5]->setText(lpBooking->kommt5().toString("hh:mm:ss"));
|
setText(items[COL_GO4], lpBooking->geht4());
|
||||||
items[COL_GO5]->setText(lpBooking->geht5().toString("hh:mm:ss"));
|
setText(items[COL_COME5], lpBooking->kommt5());
|
||||||
|
setText(items[COL_GO5], lpBooking->geht5());
|
||||||
items[COL_BREAK]->setText(lpBooking->pause().toString("hh:mm:ss"));
|
items[COL_BREAK]->setText(lpBooking->pause().toString("hh:mm:ss"));
|
||||||
items[COL_CODE]->setText(lpBooking->code());
|
items[COL_CODE]->setText(lpBooking->code());
|
||||||
items[COL_IS]->setText(lpBooking->ist().toString("hh:mm:ss"));
|
items[COL_IS]->setText(lpBooking->ist().toString("hh:mm:ss"));
|
||||||
@@ -128,7 +129,7 @@ void cMonthlyView::setDate(const QDate& date)
|
|||||||
items[COL_DIFF]->setText(lpBooking->diffString());
|
items[COL_DIFF]->setText(lpBooking->diffString());
|
||||||
items[COL_INFORMATION]->setText(lpBooking->information());
|
items[COL_INFORMATION]->setText(lpBooking->information());
|
||||||
items[COL_CURRENT]->setText(lpBooking->currentDiffString());
|
items[COL_CURRENT]->setText(lpBooking->currentDiffString());
|
||||||
items[COL_HOURS_DEC]->setText(QString::number(lpBooking->hoursDecimal()));
|
items[COL_HOURS_DEC]->setText(QString::number(lpBooking->hoursDecimal(), 'f', 2));
|
||||||
|
|
||||||
items[COL_DAY1]->setTextAlignment(Qt::AlignRight);
|
items[COL_DAY1]->setTextAlignment(Qt::AlignRight);
|
||||||
items[COL_PUBLIC_HOLIDAY]->setTextAlignment(Qt::AlignHCenter);
|
items[COL_PUBLIC_HOLIDAY]->setTextAlignment(Qt::AlignHCenter);
|
||||||
@@ -156,13 +157,13 @@ void cMonthlyView::setDate(const QDate& date)
|
|||||||
{
|
{
|
||||||
if(date1.dayOfWeek() >= 6 || m_publicHoliday.isPublicHoliday(date1))
|
if(date1.dayOfWeek() >= 6 || m_publicHoliday.isPublicHoliday(date1))
|
||||||
{
|
{
|
||||||
items[z]->setData(QVariant::fromValue(true), Qt::UserRole+1);
|
items[z]->setData(QVariant::fromValue(true), DATA_HOLIDAY);
|
||||||
items[z]->setBackground(weekend);
|
items[z]->setBackground(weekend);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
items[z]->setData(QVariant::fromValue(false), Qt::UserRole+1);
|
items[z]->setData(QVariant::fromValue(false), DATA_HOLIDAY);
|
||||||
|
|
||||||
items[z]->setData(QVariant::fromValue(lpBooking), Qt::UserRole+2);
|
items[z]->setData(QVariant::fromValue(lpBooking), DATA_BOOKING);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lpMonthlyListModel->appendRow(items);
|
m_lpMonthlyListModel->appendRow(items);
|
||||||
@@ -194,7 +195,7 @@ void cMonthlyView::onTimeChanged(const int day, const int field, const QTime& ti
|
|||||||
if(!lpItem)
|
if(!lpItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cBooking* lpBooking = lpItem->data(Qt::UserRole+2).value<cBooking*>();
|
cBooking* lpBooking = lpItem->data(DATA_BOOKING).value<cBooking*>();
|
||||||
if(!lpBooking)
|
if(!lpBooking)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -203,42 +204,52 @@ void cMonthlyView::onTimeChanged(const int day, const int field, const QTime& ti
|
|||||||
case COL_COME1:
|
case COL_COME1:
|
||||||
lpBooking->setKommt1(time);
|
lpBooking->setKommt1(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_GO1:
|
case COL_GO1:
|
||||||
lpBooking->setGeht1(time);
|
lpBooking->setGeht1(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_COME2:
|
case COL_COME2:
|
||||||
lpBooking->setKommt2(time);
|
lpBooking->setKommt2(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_GO2:
|
case COL_GO2:
|
||||||
lpBooking->setGeht2(time);
|
lpBooking->setGeht2(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_COME3:
|
case COL_COME3:
|
||||||
lpBooking->setKommt3(time);
|
lpBooking->setKommt3(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_GO3:
|
case COL_GO3:
|
||||||
lpBooking->setGeht3(time);
|
lpBooking->setGeht3(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_COME4:
|
case COL_COME4:
|
||||||
lpBooking->setKommt4(time);
|
lpBooking->setKommt4(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_GO4:
|
case COL_GO4:
|
||||||
lpBooking->setGeht4(time);
|
lpBooking->setGeht4(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_COME5:
|
case COL_COME5:
|
||||||
lpBooking->setKommt5(time);
|
lpBooking->setKommt5(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
case COL_GO5:
|
case COL_GO5:
|
||||||
lpBooking->setGeht5(time);
|
lpBooking->setGeht5(time);
|
||||||
lpBooking->save();
|
lpBooking->save();
|
||||||
|
recalculate(day, field);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,7 +260,7 @@ void cMonthlyView::onTextChanged(const int day, const int field, const QString&
|
|||||||
if(!lpItem)
|
if(!lpItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cBooking* lpBooking = lpItem->data(Qt::UserRole+2).value<cBooking*>();
|
cBooking* lpBooking = lpItem->data(DATA_BOOKING).value<cBooking*>();
|
||||||
if(!lpBooking)
|
if(!lpBooking)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -295,3 +306,24 @@ void cMonthlyView::setBackground(const int day, const QString& code)
|
|||||||
lpItem->setBackground(brush);
|
lpItem->setBackground(brush);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cMonthlyView::setText(QStandardItem* lpItem, const QTime& time)
|
||||||
|
{
|
||||||
|
if(time == QTime(0, 0, 0))
|
||||||
|
lpItem->setText("");
|
||||||
|
else
|
||||||
|
lpItem->setText(time.toString("hh:mm:ss"));
|
||||||
|
}
|
||||||
|
|
||||||
|
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* lpDecItem = m_lpMonthlyListModel->item(day-1, COL_HOURS_DEC);
|
||||||
|
|
||||||
|
cBooking* lpBooking = lpPauseItem->data(DATA_BOOKING).value<cBooking*>();
|
||||||
|
|
||||||
|
lpPauseItem->setText(lpBooking->pause().toString("hh:mm:ss"));
|
||||||
|
lpIstItem->setText(lpBooking->ist().toString("hh:mm:ss"));
|
||||||
|
lpDecItem->setText(QString::number(lpBooking->hoursDecimal(), 'f', 2));
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ private:
|
|||||||
cBookingList* m_lpBookingList;
|
cBookingList* m_lpBookingList;
|
||||||
|
|
||||||
void setBackground(const int day, const QString& code);
|
void setBackground(const int day, const QString& code);
|
||||||
|
void setText(QStandardItem* lpItem, const QTime& time);
|
||||||
|
|
||||||
|
void recalculate(int day, int field);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onTimeChanged(const int day, const int field, const QTime& time);
|
void onTimeChanged(const int day, const int field, const QTime& time);
|
||||||
|
|||||||
@@ -27,6 +27,9 @@
|
|||||||
#define COL_HOURS_DEC 19
|
#define COL_HOURS_DEC 19
|
||||||
#define COL_DAY2 20
|
#define COL_DAY2 20
|
||||||
|
|
||||||
|
#define DATA_HOLIDAY (Qt::UserRole+1)
|
||||||
|
#define DATA_BOOKING (Qt::UserRole+2)
|
||||||
|
|
||||||
#define COLOR_GLEITZEIT QColor(191, 191, 255)
|
#define COLOR_GLEITZEIT QColor(191, 191, 255)
|
||||||
#define COLOR_URLAUB QColor(127, 127, 255)
|
#define COLOR_URLAUB QColor(127, 127, 255)
|
||||||
#define COLOR_SONDERURLAUB QColor(127, 127, 255)
|
#define COLOR_SONDERURLAUB QColor(127, 127, 255)
|
||||||
|
|||||||
Reference in New Issue
Block a user