-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
114 lines (99 loc) · 4.64 KB
/
scripts.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
async function login_check() {
let response;
response = await axios.get(`api/check`).then(response => {
return true;
}).catch(error => {
return false;
});
return response;
}
async function register_check() {
let response;
response = await axios.get(`api/register`).then(response => {
return false;
}).catch(error => {
return true;
});
return response;
}
function set_month_target(year, month, target) {
axios.post(`api/target/year/${year}/month/${month}/target/${target}`).then(response => {
return true;
}).catch(error => {
return false;
});
}
function set_working_days(year, month, target) {
axios.post(`api/working-days/year/${year}/month/${month}/working-days/${target}`).then(response => {
return true;
}).catch(error => {
return false;
});
}
function set_year_target(year, target) {
axios.post(`api/target/year/${year}/target/${target}`).then(response => {
return true;
}).catch(error => {
return false;
});
}
function update_stats(year, month) {
const month_target = document.getElementById('month-target');
const month_target_progressbar = document.getElementById('month-target-progressbar');
const year_target = document.getElementById('year-target');
const year_target_progressbar = document.getElementById('year-target-progressbar');
const working_days = document.getElementById('working-days');
const holidays = document.getElementById('holidays');
const sickleave = document.getElementById('sickleave');
const office_min = document.getElementById('office-actual-min');
const month_target_edit = document.getElementById('month-target-edit');
const year_target_edit = document.getElementById('year-target-edit');
const working_days_edit = document.getElementById('working-days-edit');
let calc = 0;
let calc_year = 0;
axios.get(`api/target/year/${year}/month/${month}`).then(response => {
month_target.innerText = response.data.data.month_target !== null ? response.data.data.month_target : "100";
month_target_edit.value = month_target.innerText;
year_target.innerText = response.data.data.year_target !== null ? response.data.data.year_target : "100";
year_target_edit.value = year_target.innerText;
working_days.innerText = response.data.data.working_days !== null ? response.data.data.working_days : "-";
working_days_edit.value = working_days.innerText;
holidays.innerText = response.data.data.holidays !== null ? response.data.data.holidays : "-";
sickleave.innerText = response.data.data.sickleave !== null ? response.data.data.sickleave : "-";
if (response.data.data.working_days !== null
&& response.data.data.office_days !== null
&& response.data.data.month_target !== null) {
calc = (response.data.data.office_days / (((response.data.data.working_days - (response.data.data.holidays + response.data.data.sickleave)) * response.data.data.month_target) / 100)) * 100;
office_min.innerText = response.data.data.office_days + "/" + (((response.data.data.working_days - (response.data.data.holidays + response.data.data.sickleave)) * response.data.data.month_target) / 100);
}
if (response.data.data.working_days_year !== null
&& response.data.data.office_days_year !== null
&& response.data.data.year_target !== null) {
calc_year = (response.data.data.office_days_year / (((response.data.data.working_days_year - (response.data.data.holidays_year + response.data.data.sickleave_year)) * response.data.data.year_target) / 100)) * 100;
}
if (calc >= 100) {
month_target_progressbar.classList.add("bg-success");
} else {
month_target_progressbar.classList.remove("bg-success");
}
if (calc >= 0 && calc <= 50) {
month_target_progressbar.classList.add("bg-warning");
} else {
month_target_progressbar.classList.remove("bg-warning");
}
month_target_progressbar.style.width = `${calc}%`;
if (calc_year >= 100) {
year_target_progressbar.classList.add("bg-success");
} else {
year_target_progressbar.classList.remove("bg-success");
}
if (calc_year >= 0 && calc_year <= 50) {
year_target_progressbar.classList.add("bg-warning");
} else {
year_target_progressbar.classList.remove("bg-warning");
}
year_target_progressbar.style.width = `${calc_year}%`;
}).catch(error => {
month_target.innerText = "No data";
});
}