Reportistica Ore 2

This commit is contained in:
Paolo Arena
2021-02-24 04:48:31 +01:00
parent 14a3292da2
commit 39c08afb95
13 changed files with 427 additions and 56 deletions

View File

@@ -1109,7 +1109,10 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
let bookedevent = [];
// let msgs = [];
const socioresidente = req.user.profile.socioresidente;
let socioresidente = false;
if (!!req.user)
socioresidente = req.user.profile.socioresidente;
if (userId !== '0') {
// LOGGED WITH USERID

View File

@@ -47,6 +47,8 @@ router.post('/', authenticate, (req, res) => {
.then(record => {
// tools.mylog('REC SAVED :', record.descr);
tools.sendNotificationToUser(todo.userId, titolo + ' ' + record.descr, record.descr, '/todo/' + todo.category, '', 'todo', [])
res.send({ record: record._doc });
/*

View File

@@ -0,0 +1,144 @@
const express = require('express');
const router = express.Router();
const tools = require('../tools/general');
const server_constants = require('../tools/server_constants');
const { authenticate } = require('../middleware/authenticate');
// var mongoose = require('mongoose');
const { Project } = require('../models/project');
const { Todo } = require('../models/todo');
const { User } = require('../models/user');
const shared_consts = require('../tools/shared_nodejs');
const Hours = require('../models/hours');
const _ = require('lodash');
const { ObjectID } = require('mongodb');
router.post('/load', authenticate, async (req, res) => {
const date_start = req.body.date_start;
const date_end = req.body.date_end;
const filter = req.body.filter;
const idapp = req.body.idapp;
// tools.mylog('GET REPORT : ');
// Ottieni la reportistica
// dei progetti
// degli utenti Residenti
// di tutta la settimana
try {
// Ottieni la lista dei Residenti
const listaResidenti = await User.getUsersResidenti(idapp);
// Extract all the projects of the userId only
const objprojects = await Project.getAllProjects('', idapp);
const arrhour = {};
let mydatets = tools.dateToEpoch(date_start)
let mydatets_end = tools.dateToEpoch(date_end)
for (const myuser of listaResidenti) {
arrhour[myuser.username] = [];
}
let totalacchours = [];
for (const myuser of listaResidenti) {
totalacchours[myuser.username] = 0;
}
while (mydatets <= mydatets_end) {
for (const myuser of listaResidenti) {
// for (const myproj of objprojects.arrproj) {
//let myhours = await Hours.getHoursByIdCat(idapp, myuser._id, myproj._id, date_start, date_end);
let mydate = new Date(mydatets);
let rechours = await Hours.getHoursByDate(idapp, myuser._id, mydate);
let ressum = await Hours.getTotalHoursByDate(idapp, myuser._id, mydate);
if (tools.isMonday(mydatets)) {
totalacchours[myuser.username] = 0;
}
if ((ressum > 0) || ((tools.isSunday(mydatets)) && totalacchours[myuser.username] > 0)) {
totalacchours[myuser.username] = totalacchours[myuser.username] + ressum;
const rectotal = {
totalhours: ressum,
totalacchours: 0,
date: tools.getstrDateYYYY_MM_DD(mydate),
}
if (tools.isSunday(mydatets)) {
rectotal.totalacchours = totalacchours[myuser.username];
}
if (tools.isBitActive(filter, shared_consts.REPORT_FILT_RESP)) {
rectotal.resp = '';
rectotal.viceResp = '';
}
arrhour[myuser.username].push(rectotal);
if (tools.isBitActive(filter, shared_consts.REPORT_FILT_ATTIVITA)) {
for (const rec of rechours) {
let myproj = await Project.findProjectByUserId('', rec.todoId);
let colors = {
themebgcolor: '',
themecolor: ''
}
if (!myproj) {
const mytodo = await Todo.findOne({ _id: rec.todoId });
if (!!mytodo) {
colors.themebgcolor = mytodo.themebgcolor;
colors.themecolor = mytodo.themecolor;
myproj = await Project.findProjectByUserId('', mytodo.category);
if (!themebgcolor && myproj) {
colors.themebgcolor = myproj.themebgcolor;
colors.themecolor = myproj.themecolor;
}
}
// E' un Todo, trova il proj
} else {
colors.themebgcolor = myproj.themebgcolor;
colors.themecolor = myproj.themecolor;
}
if (!colors.themebgcolor) {
if (myproj) {
colors = await Project.findColorsByProject(myproj._id);
}
}
if (myproj) {
const myrec = {
title: rec.hours + 'h - ' + myproj.descr,
details: myproj.longdescr,
date: tools.getstrDateYYYY_MM_DD(mydate),
bgcolor: colors.themebgcolor,
color: colors.themecolor
}
arrhour[myuser.username].push(myrec);
}
}
}
}
// }
}
mydatets += 86400000;
}
return res.send({ listaResidenti, arrhour });
} catch (e) {
console.log(e.message);
res.status(400).send(e);
}
});
module.exports = router;

View File

@@ -21,7 +21,7 @@ const _ = require('lodash');
const { ObjectID } = require('mongodb');
router.post('/', authenticate, (req, res) => {
router.post('/', authenticate, async (req, res) => {
var body = _.pick(req.body, tools.allfieldTodoWithId());
// tools.mylogshow('INPUT', body);
@@ -48,25 +48,44 @@ router.post('/', authenticate, (req, res) => {
console.log('RECORD NON VALIDO !?', req.body)
}
todo.save().then((writeresult) => {
let idobj = writeresult._id;
Todo.findById(idobj)
.then(record => {
// tools.mylog('REC SAVED :', record.descr);
let prevrec = null;
if (!!todo && todo._id)
prevrec = await Todo.findById(todo._id);
tools.sendNotificationToUser(todo.userId, 'Todo: ' + record.descr, record.descr, '/todo/' + todo.category, '', 'todo', [])
.then(ris => {
if (ris) {
res.send({ record });
} else {
// already sent the error on calling sendNotificationToUser
return todo.save()
.then((writeresult) => {
let idobj = writeresult._id;
return Todo.findById(idobj)
.then(record => {
// tools.mylog('REC SAVED :', record.descr);
let aggiorna = false;
let titolo = '';
if (prevrec) {
if (todo.completed_at !== prevrec.completed_at) {
aggiorna = true;
titolo = 'Attività Completata!'
}
})
})
}).catch((e) => {
console.log('ERRORE in TODO POST', e.message);
res.status(400).send(e);
});
} else {
aggiorna = true;
}
if (aggiorna) {
tools.sendNotificationToUser(todo.userId, titolo + ' ' + record.descr, record.descr, '/todo/' + todo.category, '', 'todo', [])
.then(ris => {
if (ris) {
return res.send({ record });
} else {
// already sent the error on calling sendNotificationToUser
}
})
}
})
}).catch((e) => {
console.log('ERRORE in TODO POST', e.message);
return res.status(400).send(e);
});
});
@@ -101,7 +120,7 @@ router.patch('/:id', authenticate, (req, res) => {
.then(objdatacalc => {
// tools.mylogshow(' TODO TO MODIFY: ', todo.descr, todo.expiring_at);
if (todo.userId !== String(req.user._id) && project.privacywrite === server_constants.Privacy.onlyme) {
if (todo.userId !== String(req.user._id) && todo.privacywrite === server_constants.Privacy.onlyme) {
// I'm trying to write something not mine!
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
}

View File

@@ -4,6 +4,7 @@ const router = express.Router();
const { User } = require('../models/user');
const { Nave } = require('../models/nave');
const { Flotta } = require('../models/flotta');
const Hours = require('../models/hours');
const { NavePersistente } = require('../models/navepersistente');
const { ListaIngresso } = require('../models/listaingresso');
const { Graduatoria } = require('../models/graduatoria');
@@ -752,6 +753,10 @@ async function eseguiDbOp(idapp, mydata, locale) {
telegrambot.sendMsgTelegramToTheAdmin(idapp, placca);
ris = { placca };*/
} else if (mydata.dbop === 'CorreggiTabHours') {
await Hours.correggiHours(idapp);
} else if (mydata.dbop === 'visuNave') {
mystr = await Nave.getNavePos(idapp, parseInt(mydata.riga), parseInt(mydata.col));