calculation break, is, is decimal
This commit is contained in:
+61
-13
@@ -152,14 +152,42 @@ QString cBooking::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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
return(QTime(0, 0, 0));
|
||||
return(QTime(0, 0, 0).addSecs(istSecs()));
|
||||
}
|
||||
|
||||
void cBooking::setSoll()
|
||||
@@ -228,7 +256,9 @@ QString cBooking::currentDiffString()
|
||||
|
||||
qreal cBooking::hoursDecimal()
|
||||
{
|
||||
return(0);
|
||||
int w = istSecs();
|
||||
|
||||
return(static_cast<qreal>(w)/3600);
|
||||
}
|
||||
|
||||
bool cBooking::save()
|
||||
@@ -293,16 +323,16 @@ bool cBooking::save()
|
||||
" );");
|
||||
|
||||
query.bindValue(":datum", date());
|
||||
query.bindValue(":kommt1", kommt1());
|
||||
query.bindValue(":geht1", geht1());
|
||||
query.bindValue(":kommt2", kommt2());
|
||||
query.bindValue(":geht2", geht2());
|
||||
query.bindValue(":kommt3", kommt3());
|
||||
query.bindValue(":geht3", geht3());
|
||||
query.bindValue(":kommt4", kommt4());
|
||||
query.bindValue(":geht4", geht4());
|
||||
query.bindValue(":kommt5", kommt5());
|
||||
query.bindValue(":geht5", geht5());
|
||||
bind(query, ":kommt1", kommt1());
|
||||
bind(query, ":geht1", geht1());
|
||||
bind(query, ":kommt2", kommt2());
|
||||
bind(query, ":geht2", geht2());
|
||||
bind(query, ":kommt3", kommt3());
|
||||
bind(query, ":geht3", geht3());
|
||||
bind(query, ":kommt4", kommt4());
|
||||
bind(query, ":geht4", geht4());
|
||||
bind(query, ":kommt5", kommt5());
|
||||
bind(query, ":geht5", geht5());
|
||||
query.bindValue(":code", code());
|
||||
query.bindValue(":information", information());
|
||||
|
||||
@@ -316,6 +346,24 @@ bool cBooking::save()
|
||||
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()
|
||||
{
|
||||
QSqlQuery query;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QDate>
|
||||
#include <QTime>
|
||||
|
||||
#include <QSqlQuery>
|
||||
|
||||
|
||||
class cBooking : public QObject
|
||||
{
|
||||
@@ -54,8 +56,10 @@ public:
|
||||
void setInformation(const QString& information);
|
||||
QString information();
|
||||
|
||||
qint32 pauseSecs();
|
||||
QTime pause();
|
||||
|
||||
qint32 istSecs();
|
||||
QTime ist();
|
||||
|
||||
void setSoll();
|
||||
@@ -89,6 +93,11 @@ private:
|
||||
QString m_information;
|
||||
QTime m_soll;
|
||||
qint32 m_prevDiff;
|
||||
|
||||
void bind(QSqlQuery& query, const QString& variable, const QTime& time);
|
||||
|
||||
int totalWork();
|
||||
int totalPause();
|
||||
};
|
||||
|
||||
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_DAY2]->setText(date1.toString("dd dddd"));
|
||||
|
||||
items[COL_COME1]->setText(lpBooking->kommt1().toString("hh:mm:ss"));
|
||||
items[COL_GO1]->setText(lpBooking->geht1().toString("hh:mm:ss"));
|
||||
items[COL_COME2]->setText(lpBooking->kommt2().toString("hh:mm:ss"));
|
||||
items[COL_GO2]->setText(lpBooking->geht2().toString("hh:mm:ss"));
|
||||
items[COL_COME3]->setText(lpBooking->kommt3().toString("hh:mm:ss"));
|
||||
items[COL_GO3]->setText(lpBooking->geht3().toString("hh:mm:ss"));
|
||||
items[COL_COME4]->setText(lpBooking->kommt4().toString("hh:mm:ss"));
|
||||
items[COL_GO4]->setText(lpBooking->geht4().toString("hh:mm:ss"));
|
||||
items[COL_COME5]->setText(lpBooking->kommt5().toString("hh:mm:ss"));
|
||||
items[COL_GO5]->setText(lpBooking->geht5().toString("hh:mm:ss"));
|
||||
setText(items[COL_COME1], lpBooking->kommt1());
|
||||
setText(items[COL_COME1], lpBooking->kommt1());
|
||||
setText(items[COL_GO1], lpBooking->geht1());
|
||||
setText(items[COL_COME2], lpBooking->kommt2());
|
||||
setText(items[COL_GO2], lpBooking->geht2());
|
||||
setText(items[COL_COME3], lpBooking->kommt3());
|
||||
setText(items[COL_GO3], lpBooking->geht3());
|
||||
setText(items[COL_COME4], lpBooking->kommt4());
|
||||
setText(items[COL_GO4], lpBooking->geht4());
|
||||
setText(items[COL_COME5], lpBooking->kommt5());
|
||||
setText(items[COL_GO5], lpBooking->geht5());
|
||||
items[COL_BREAK]->setText(lpBooking->pause().toString("hh:mm:ss"));
|
||||
items[COL_CODE]->setText(lpBooking->code());
|
||||
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_INFORMATION]->setText(lpBooking->information());
|
||||
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_PUBLIC_HOLIDAY]->setTextAlignment(Qt::AlignHCenter);
|
||||
@@ -156,13 +157,13 @@ void cMonthlyView::setDate(const QDate& date)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
@@ -194,7 +195,7 @@ void cMonthlyView::onTimeChanged(const int day, const int field, const QTime& ti
|
||||
if(!lpItem)
|
||||
return;
|
||||
|
||||
cBooking* lpBooking = lpItem->data(Qt::UserRole+2).value<cBooking*>();
|
||||
cBooking* lpBooking = lpItem->data(DATA_BOOKING).value<cBooking*>();
|
||||
if(!lpBooking)
|
||||
return;
|
||||
|
||||
@@ -203,42 +204,52 @@ void cMonthlyView::onTimeChanged(const int day, const int field, const QTime& ti
|
||||
case COL_COME1:
|
||||
lpBooking->setKommt1(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_GO1:
|
||||
lpBooking->setGeht1(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_COME2:
|
||||
lpBooking->setKommt2(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_GO2:
|
||||
lpBooking->setGeht2(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_COME3:
|
||||
lpBooking->setKommt3(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_GO3:
|
||||
lpBooking->setGeht3(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_COME4:
|
||||
lpBooking->setKommt4(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_GO4:
|
||||
lpBooking->setGeht4(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_COME5:
|
||||
lpBooking->setKommt5(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
case COL_GO5:
|
||||
lpBooking->setGeht5(time);
|
||||
lpBooking->save();
|
||||
recalculate(day, field);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -249,7 +260,7 @@ void cMonthlyView::onTextChanged(const int day, const int field, const QString&
|
||||
if(!lpItem)
|
||||
return;
|
||||
|
||||
cBooking* lpBooking = lpItem->data(Qt::UserRole+2).value<cBooking*>();
|
||||
cBooking* lpBooking = lpItem->data(DATA_BOOKING).value<cBooking*>();
|
||||
if(!lpBooking)
|
||||
return;
|
||||
|
||||
@@ -295,3 +306,24 @@ void cMonthlyView::setBackground(const int day, const QString& code)
|
||||
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;
|
||||
|
||||
void setBackground(const int day, const QString& code);
|
||||
void setText(QStandardItem* lpItem, const QTime& time);
|
||||
|
||||
void recalculate(int day, int field);
|
||||
|
||||
private slots:
|
||||
void onTimeChanged(const int day, const int field, const QTime& time);
|
||||
|
||||
Reference in New Issue
Block a user