3928-worker.time-control_sendMail #1129

Merged
joan merged 26 commits from 3928-worker.time-control_sendMail into dev 2022-11-11 07:30:09 +00:00
1 changed files with 50 additions and 29 deletions
Showing only changes of commit 273a8cd7c7 - Show all commits

View File

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