3928-worker.time-control_sendMail #1129
|
@ -12,13 +12,11 @@ module.exports = Self => {
|
|||
},
|
||||
{
|
||||
arg: 'week',
|
||||
type: 'number',
|
||||
required: true
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
arg: 'year',
|
||||
type: 'number',
|
||||
required: true
|
||||
type: 'number'
|
||||
}],
|
||||
returns: [{
|
||||
type: 'Object',
|
||||
|
@ -53,6 +51,26 @@ module.exports = Self => {
|
|||
return weekStart;
|
||||
}
|
||||
|
||||
function getTime(timeString) {
|
||||
const [hours, minutes, seconds] = timeString.split(':');
|
||||
return [parseInt(hours), parseInt(minutes), parseInt(seconds)];
|
||||
}
|
||||
|
||||
if (!args.week || !args.year) {
|
||||
const from = new Date();
|
||||
const to = new Date();
|
||||
|
||||
const time = await models.Time.findOne({
|
||||
where: {
|
||||
dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]}
|
||||
},
|
||||
order: 'week ASC'
|
||||
}, myOptions);
|
||||
|
||||
args.week = time.week;
|
||||
args.year = time.year;
|
||||
}
|
||||
|
||||
const started = getStartDateOfWeekNumber(args.week, args.year);
|
||||
started.setHours(0, 0, 0, 0);
|
||||
|
||||
|
@ -155,11 +173,12 @@ module.exports = Self => {
|
|||
|
||||
for (let day of days[index]) {
|
||||
if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null
|
||||
&& day.permissionRate ? day.permissionRate : true) {
|
||||
&& (day.permissionRate ? day.permissionRate : true)) {
|
||||
if (day.timeTable == null) {
|
||||
const timed = new Date(day.dated);
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(8)),
|
||||
timed: timed.setHours(8),
|
||||
manual: true,
|
||||
direction: 'in',
|
||||
isSendMail: true
|
||||
|
@ -168,7 +187,7 @@ module.exports = Self => {
|
|||
if (day.timeWorkDecimal >= 5) {
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(9)),
|
||||
timed: timed.setHours(9),
|
||||
manual: true,
|
||||
direction: 'middle',
|
||||
isSendMail: true
|
||||
|
@ -176,17 +195,17 @@ module.exports = Self => {
|
|||
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(9, 20)),
|
||||
timed: timed.setHours(9, 20),
|
||||
manual: true,
|
||||
direction: 'middle',
|
||||
isSendMail: true
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
const [hoursWork, minutesWork, secondsWork] = day.timeWorkSexagesimal.split(':');
|
||||
const [hoursWork, minutesWork, secondsWork] = getTime(day.timeWorkSexagesimal);
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(8 + parseInt(hoursWork), minutesWork, secondsWork)),
|
||||
timed: timed.setHours(8 + hoursWork, minutesWork, secondsWork),
|
||||
manual: true,
|
||||
direction: 'out',
|
||||
isSendMail: true
|
||||
|
@ -203,11 +222,11 @@ module.exports = Self => {
|
|||
let timeTableDecimalInSeconds = 0;
|
||||
for (let journey of journeys) {
|
||||
const start = new Date();
|
||||
const [startHours, startMinutes, startSeconds] = journey.start.split(':');
|
||||
const [startHours, startMinutes, startSeconds] = getTime(journey.start);
|
||||
start.setHours(startHours, startMinutes, startSeconds);
|
||||
|
||||
const end = new Date();
|
||||
const [endHours, endMinutes, endSeconds] = journey.end.split(':');
|
||||
const [endHours, endMinutes, endSeconds] = getTime(journey.end);
|
||||
end.setHours(endHours, endMinutes, endSeconds);
|
||||
|
||||
const result = (end - start) / 1000;
|
||||
|
@ -217,18 +236,19 @@ module.exports = Self => {
|
|||
for (let journey of journeys) {
|
||||
const timeTableDecimal = timeTableDecimalInSeconds / 3600;
|
||||
if (day.timeWorkDecimal == timeTableDecimal) {
|
||||
const [startHours, startMinutes, startSeconds] = journey.start.split(':');
|
||||
const timed = new Date(day.dated);
|
||||
const [startHours, startMinutes, startSeconds] = getTime(journey.start);
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(startHours, startMinutes, startSeconds)),
|
||||
timed: timed.setHours(startHours, startMinutes, startSeconds),
|
||||
manual: true,
|
||||
isSendMail: true
|
||||
}, myOptions);
|
||||
|
||||
const [endHours, endMinutes, endSeconds] = journey.end.split(':');
|
||||
const [endHours, endMinutes, endSeconds] = getTime(journey.end);
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(endHours, endMinutes, endSeconds)),
|
||||
timed: timed.setHours(endHours, endMinutes, endSeconds),
|
||||
manual: true,
|
||||
isSendMail: true
|
||||
}, myOptions);
|
||||
|
@ -237,22 +257,21 @@ module.exports = Self => {
|
|||
return curr.start < prev.start ? curr : prev;
|
||||
});
|
||||
if (journey == minStart) {
|
||||
const [startHours, startMinutes, startSeconds] = journey.start.split(':');
|
||||
const timed = new Date(day.dated);
|
||||
const [startHours, startMinutes, startSeconds] = getTime(journey.start);
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(startHours, startMinutes, startSeconds)),
|
||||
timed: timed.setHours(startHours, startMinutes, startSeconds),
|
||||
manual: true,
|
||||
isSendMail: true
|
||||
}, myOptions);
|
||||
|
||||
const [hoursWork, minutesWork, secondsWork] = day.timeWorkSexagesimal.split(':');
|
||||
const [hoursWork, minutesWork, secondsWork] = getTime(day.timeWorkSexagesimal);
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(
|
||||
parseInt(startHours) + parseInt(hoursWork),
|
||||
parseInt(startMinutes) + parseInt(minutesWork),
|
||||
parseInt(startSeconds) + parseInt(secondsWork)
|
||||
)),
|
||||
timed: timed.setHours(
|
||||
startHours + hoursWork, startMinutes + minutesWork, startSeconds + secondsWork
|
||||
),
|
||||
manual: true,
|
||||
isSendMail: true
|
||||
}, myOptions);
|
||||
|
@ -264,17 +283,18 @@ module.exports = Self => {
|
|||
return curr.start < prev.start ? curr : prev;
|
||||
});
|
||||
if (journey == minStart) {
|
||||
const [startHours, startMinutes, startSeconds] = journey.start.split(':');
|
||||
const timed = new Date(day.dated);
|
||||
const [startHours, startMinutes, startSeconds] = getTime(journey.start);
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(parseInt(startHours) + 1, startMinutes, startSeconds)),
|
||||
timed: timed.setHours(startHours + 1, startMinutes, startSeconds),
|
||||
manual: true,
|
||||
isSendMail: true
|
||||
}, myOptions);
|
||||
|
||||
await models.WorkerTimeControl.create({
|
||||
userFk: day.workerFk,
|
||||
timed: new Date(day.dated.setHours(parseInt(startHours) + 1, parseInt(startMinutes) + 20, startSeconds)),
|
||||
timed: timed.setHours(startHours + 1, startMinutes + 20, startSeconds),
|
||||
manual: true,
|
||||
isSendMail: true
|
||||
}, myOptions);
|
||||
|
@ -282,10 +302,11 @@ module.exports = Self => {
|
|||
}
|
||||
}
|
||||
|
||||
const timed = new Date(day.dated);
|
||||
const firstWorkerTimeControl = await models.WorkerTimeControl.findOne({
|
||||
where: {
|
||||
userFk: day.workerFk,
|
||||
timed: {between: [new Date(day.dated.setHours(0, 0, 0, 0)), new Date(day.dated.setHours(23, 59, 59, 999))]}
|
||||
timed: {between: [timed.setHours(0, 0, 0, 0), timed.setHours(23, 59, 59, 999)]}
|
||||
},
|
||||
order: 'timed ASC',
|
||||
limit: 1
|
||||
|
@ -296,7 +317,7 @@ module.exports = Self => {
|
|||
const lastWorkerTimeControl = await models.WorkerTimeControl.findOne({
|
||||
where: {
|
||||
userFk: day.workerFk,
|
||||
timed: {between: [new Date(day.dated.setHours(0, 0, 0, 0)), new Date(day.dated.setHours(23, 59, 59, 999))]}
|
||||
timed: {between: [timed.setHours(0, 0, 0, 0), timed.setHours(23, 59, 59, 999)]}
|
||||
},
|
||||
order: 'timed DESC',
|
||||
limit: 1
|
||||
|
|
Loading…
Reference in New Issue