Доработка времени работы фабрики
This commit is contained in:
parent
de4b20a92b
commit
b24f135cf3
@ -14,7 +14,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-portlet__body p-4">
|
||||
<div class="m-widget16 h-100" style="display: grid; grid-template-rows: 1fr 1fr 1fr">
|
||||
<div class="m-widget16 h-100 grid-gar-1fr">
|
||||
<div class="row align-items-center" style="border-bottom: 1px solid #ebedf2">
|
||||
<div class="col-md-5">
|
||||
<h5 class="roboto text-center">За смену</h5>
|
||||
@ -23,25 +23,23 @@
|
||||
<span class=" roboto dark">
|
||||
Под нагрузкой
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-success roboto"
|
||||
id="dailyWO">
|
||||
0ч.
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-success roboto font-weight-bold"
|
||||
id="dailyWO">0 ч.</span>
|
||||
</div>
|
||||
<div class="m-widget16__item">
|
||||
<span class=" roboto">
|
||||
Без нагрузки
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-primary roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-primary roboto font-weight-bold"
|
||||
id="dailyWA">
|
||||
0ч.
|
||||
0 ч.
|
||||
</span>
|
||||
</div>
|
||||
<div class="m-widget16__item">
|
||||
<span class=" roboto">
|
||||
Не работала
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-danger roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-danger roboto font-weight-bold"
|
||||
id="dailyNW">
|
||||
0ч.
|
||||
</span>
|
||||
@ -50,7 +48,7 @@
|
||||
<span class=" roboto">
|
||||
Общее время работы
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-accent roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-accent roboto font-weight-bold"
|
||||
id="dailySUM">
|
||||
0ч.
|
||||
</span>
|
||||
@ -74,7 +72,7 @@
|
||||
<span class=" roboto">
|
||||
Под нагрузкой
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-success roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-success roboto font-weight-bold"
|
||||
id="weeklyWO">
|
||||
0ч.
|
||||
</span>
|
||||
@ -83,7 +81,7 @@
|
||||
<span class=" roboto">
|
||||
Без нагрузки
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-primary roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-primary roboto font-weight-bold"
|
||||
id="weeklyWA">
|
||||
0ч.
|
||||
</span>
|
||||
@ -92,7 +90,7 @@
|
||||
<span class=" roboto">
|
||||
Не работала
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-danger roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-danger roboto font-weight-bold"
|
||||
id="weeklyNW">
|
||||
0ч.
|
||||
</span>
|
||||
@ -101,7 +99,7 @@
|
||||
<span class=" roboto">
|
||||
Общее время работы
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-accent roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-accent roboto font-weight-bold"
|
||||
id="weeklySUM">
|
||||
0ч.
|
||||
</span>
|
||||
@ -125,7 +123,7 @@
|
||||
<span class=" roboto">
|
||||
Под нагрузкой
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-success roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-success roboto font-weight-bold"
|
||||
id="monthlyWO">
|
||||
0ч.
|
||||
</span>
|
||||
@ -134,7 +132,7 @@
|
||||
<span class=" roboto">
|
||||
Без нагрузки
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-primary roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-primary roboto font-weight-bold"
|
||||
id="monthlyWA">
|
||||
0ч.
|
||||
</span>
|
||||
@ -143,7 +141,7 @@
|
||||
<span class=" roboto">
|
||||
Не работала
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-danger roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-danger roboto font-weight-bold"
|
||||
id="monthlyNW">
|
||||
0ч.
|
||||
</span>
|
||||
@ -152,7 +150,7 @@
|
||||
<span class=" roboto">
|
||||
Общее время работы
|
||||
</span>
|
||||
<span class="m-widget16__price m--align-right m--font-accent roboto"
|
||||
<span class="m-widget16__price m--align-right m--font-accent roboto font-weight-bold"
|
||||
id="monthlySUM">
|
||||
0ч.
|
||||
</span>
|
||||
|
||||
@ -1,4 +1,73 @@
|
||||
(function () {
|
||||
|
||||
function parseDuration(durationStr) {
|
||||
// Разбиваем строку по символам времени
|
||||
const parts = durationStr.match(/\d+(?=DT|H|M|S)/g);
|
||||
let days = 0, hours = 0, minutes = 0, seconds = 0;
|
||||
|
||||
if (parts) {
|
||||
days = parseInt(parts[0]) || 0;
|
||||
hours = parseInt(parts[1]) || 0;
|
||||
minutes = parseInt(parts[2]) || 0;
|
||||
seconds = parseInt(parts[3]) || 0;
|
||||
}
|
||||
|
||||
return {
|
||||
days: days,
|
||||
hours: hours,
|
||||
minutes: minutes,
|
||||
seconds: seconds
|
||||
};
|
||||
}
|
||||
|
||||
function addDurations(duration1, duration2) {
|
||||
// Складываем соответствующие поля двух объектов длительности
|
||||
let totalSeconds = duration1.seconds + duration2.seconds;
|
||||
let totalMinutes = duration1.minutes + duration2.minutes;
|
||||
let totalHours = duration1.hours + duration2.hours;
|
||||
let totalDays = duration1.days + duration2.days;
|
||||
|
||||
// Учет переполнений
|
||||
if (totalSeconds >= 60) {
|
||||
totalMinutes += Math.floor(totalSeconds / 60);
|
||||
totalSeconds %= 60;
|
||||
}
|
||||
|
||||
if (totalMinutes >= 60) {
|
||||
totalHours += Math.floor(totalMinutes / 60);
|
||||
totalMinutes %= 60;
|
||||
}
|
||||
|
||||
if (totalHours >= 24) {
|
||||
totalDays += Math.floor(totalHours / 24);
|
||||
totalHours %= 24;
|
||||
}
|
||||
|
||||
return {
|
||||
days: totalDays,
|
||||
hours: totalHours,
|
||||
minutes: totalMinutes,
|
||||
seconds: totalSeconds
|
||||
};
|
||||
}
|
||||
|
||||
function makeTimeString(timeObj) {
|
||||
let timeString = ''
|
||||
if (timeObj.days !== 0) {
|
||||
timeString += `${timeObj.days} д. `
|
||||
}
|
||||
if (timeObj.hours !== 0) {
|
||||
timeString += `${timeObj.hours} ч. `
|
||||
}
|
||||
if (timeObj.minutes !== 0) {
|
||||
timeString += `${timeObj.minutes} м. `
|
||||
}
|
||||
if (timeString === '') {
|
||||
timeString = '0 ч. 0 м.'
|
||||
}
|
||||
return timeString
|
||||
}
|
||||
|
||||
const workTimeChartOptions = {
|
||||
chart: {
|
||||
type: 'donut',
|
||||
@ -34,30 +103,33 @@
|
||||
monthlyWorkChart.render();
|
||||
|
||||
function fetchWorkTime() {
|
||||
fetch('worktime/').then(response => {
|
||||
fetch('worktime/durations').then(response => {
|
||||
return response.json()
|
||||
}).then(json => {
|
||||
for (let item in json) {
|
||||
for (let status in json[item]) {
|
||||
let chartElement = document.querySelector(`#${item}${status}`)
|
||||
chartElement.textContent = json[item][status] + ' ч.'
|
||||
let timeObj = parseDuration(json[item][status])
|
||||
chartElement.textContent = makeTimeString(timeObj)
|
||||
}
|
||||
let chartElementSUM = document.querySelector(`#${item}SUM`)
|
||||
chartElementSUM.textContent = (json[item]['WO'] + json[item]['WA']).toFixed(0) + ' ч.'
|
||||
|
||||
let workedWO = json[item]['WO']
|
||||
let workedWA = json[item]['WA']
|
||||
let workedNW = json[item]['NW']
|
||||
let workedWO = parseDuration(json[item]['WO'])
|
||||
let workedWA = parseDuration(json[item]['WA'])
|
||||
let workedNW = parseDuration(json[item]['NW'])
|
||||
const sumObj = addDurations(workedWO, workedWA)
|
||||
const sumTimeString = makeTimeString(sumObj)
|
||||
const spanSum = document.querySelector(`#${item}SUM`)
|
||||
spanSum.textContent = sumTimeString
|
||||
|
||||
switch (item) {
|
||||
case 'daily':
|
||||
dailyWorkChart.updateSeries([workedWO, workedWA, workedNW])
|
||||
dailyWorkChart.updateSeries([workedWO.hours, workedWA.hours, workedNW.hours])
|
||||
break
|
||||
case 'weekly':
|
||||
weeklyWorkChart.updateSeries([workedWO, workedWA, workedNW])
|
||||
weeklyWorkChart.updateSeries([workedWO.hours, workedWA.hours, workedNW.hours])
|
||||
break
|
||||
case 'monthly':
|
||||
monthlyWorkChart.updateSeries([workedWO, workedWA, workedNW])
|
||||
monthlyWorkChart.updateSeries([workedWO.hours, workedWA.hours, workedNW.hours])
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user