-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemployee.cpp
More file actions
54 lines (44 loc) · 1.12 KB
/
employee.cpp
File metadata and controls
54 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "employee.h"
Employee::Employee()
{
}
double Employee::getSalary(QString name)
{
QSqlQuery query = db->getWorker(name);
query.next();
int year = query.value(2).toInt();
int month = query.value(3).toInt();
int day = query.value(4).toInt();
double base_salary = query.value(5).toDouble();
QDate startDate(year, month, day);
QDate todayDate = QDate::currentDate();
int experience = getYearsOfExpirience(startDate, todayDate);
double allowance = base_salary * 0.03 * (experience >= 10 ? 10 : experience);
double salary = allowance + base_salary;
return salary;
}
void Employee::setDB(DBManager* dbManager)
{
db = dbManager;
}
int Employee::getYearsOfExpirience(QDate startDate, QDate todayDate)
{
int years = todayDate.year() - startDate.year();
int months = todayDate.month() - startDate.month();
int days = todayDate.day() - startDate.day();
if(years > 0)
{
if(months <= 0)
{
years--;
}
else
{
if(days < 0)
{
years--;
}
}
}
return years;
}