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

@@ -12,11 +12,17 @@ mongoose.plugin(schema => {
schema.options.usePushEach = true
});
var ObjectId = mongoose.Types.ObjectId;
const { ObjectID } = require('mongodb');
const HoursSchema = new Schema({
idapp: {
type: String,
},
userId: { type: Schema.Types.ObjectId, ref: 'User' },
userId: {
type: String
},
descr: {
type: String,
},
@@ -55,6 +61,127 @@ module.exports.findAllIdApp = async function (idapp) {
return await Hours.find(myfind);
};
module.exports.correggiHours = async function (idapp) {
const myfind = { idapp };
const myarr = await Hours.find(myfind);
for (const rec of myarr) {
rec.userId = rec.userId.toString();
let ris = await Hours.findOneAndUpdate({ _id: rec._id }, { $set: { userId: rec.userId } }, { new: false } );
if (!!ris) {
console.log('ris', ris);
}
}
};
module.exports.getHoursByIdCat = async function (idapp, userId, idCat, date_start, date_end) {
const myfind = [
{
$match: {
idapp,
userId,
date: { $gte: new Date(date_start), $lte: new Date(date_end) },
todoId: idCat
}
},
{
$group:
{
_id: "$todoId",
totalAmount: {
$sum: "$hours"
},
count: {
$sum: 1
}
}
}
];
try {
const ris = await Hours.aggregate(myfind);
if (ris.length > 0) {
return ris[0].totalAmount;
} else {
return 0;
}
} catch (e) {
console.log('e', e);
return 0;
}
};
module.exports.getTotalHoursByDate = async function (idapp, userId, date) {
const myfind = [
{
$match: {
idapp,
userId,
hours: { $gt: 0 },
date:
{
$gte: new Date(tools.getstrDateYYYY_MM_DD(date)),
$lte: new Date(tools.getstrDateYYYY_MM_DD(tools.AddDate(date, 1)))
}
},
},
{
$group:
{
_id: { $dateToString: { format: "%Y-%m-%d", date: "$date" } },
totalAmount: {
$sum: "$hours"
},
count: {
$sum: 1
}
}
}
]
;
try {
const ris = await Hours.aggregate(myfind);
if (ris.length > 0) {
return ris[0].totalAmount;
} else {
return 0;
}
} catch (e) {
console.log('e', e);
return 0;
}
}
;
module.exports.getHoursByDate = async function (idapp, userId, date) {
const mystr = tools.getstrDateYYYY_MM_DD(date);
// console.log(mystr);
const myfind =
{
idapp,
userId,
hours: { $gt: 0 },
date: {
$gte: new Date(tools.getstrDateYYYY_MM_DD(date)),
$lte: new Date(tools.getstrDateYYYY_MM_DD(tools.AddDate(date, 1)))
}
};
try {
return await Hours.find(myfind);
} catch (e) {
console.log('e', e);
return 0;
}
};
module.exports.calculateHoursTodo = async function (idtodo) {
const Hours = this;
@@ -93,6 +220,5 @@ module.exports.calculateHoursTodo = async function (idtodo) {
return 0;
}
}
;
};

View File

@@ -131,6 +131,9 @@ var ProjectSchema = new mongoose.Schema({
privacywrite: {
type: String
},
tipovisu: {
type: Number,
},
deleted: {
type: Boolean,
default: false,
@@ -178,6 +181,37 @@ ProjectSchema.statics.findProjectByUserId = function (userId, idproj) {
}
};
ProjectSchema.statics.findColorsByProject = async function (idproj) {
const Project = this;
let finito = false;
let idparent = idproj;
let colori = {};
while (!finito) {
let rec = await Project.findOne({ '_id': idparent });
if (!rec)
break;
if (rec) {
colori.themebgcolor = rec.themebgcolor;
colori.themecolor = rec.themecolor
}
if (!rec.themebgcolor && !rec.themecolor) {
// Cerca nel progetto ereditato
idparent = rec.id_parent
} else {
break;
}
}
return colori;
};
ProjectSchema.statics.findAllProjByUserId = async function (userId, idapp) {
var Project = this;

View File

@@ -1272,7 +1272,7 @@ UserSchema.statics.getusersManagers = async function (idapp) {
UserSchema.statics.getusersRespList = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.resplist': true }, { _id:1, username: 1, name: 1, surname: 1 })
return await User.find({ idapp, 'profile.resplist': true }, { _id: 1, username: 1, name: 1, surname: 1 })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -1283,7 +1283,7 @@ UserSchema.statics.getusersRespList = async function (idapp) {
UserSchema.statics.getusersWorkersList = async function (idapp) {
const User = this;
return await User.find({ idapp, 'profile.workerslist': true }, { _id:1, username: 1, name: 1, surname: 1 })
return await User.find({ idapp, 'profile.workerslist': true }, { _id: 1, username: 1, name: 1, surname: 1 })
.then((arrrec) => {
return (!!arrrec) ? arrrec : null;
}).catch((e) => {
@@ -1892,6 +1892,18 @@ UserSchema.statics.getUsersZoom = async function (idapp) {
return await User.count(myfind);
};
UserSchema.statics.getUsersResidenti = async function (idapp) {
const User = this;
const myfind = {
idapp,
$or: [{ deleted: { $exists: false } }, { deleted: { $exists: true, $eq: false } }],
'profile.socioresidente': { $exists: true, $eq: true }
};
return await User.find(myfind, {username: 1, name: 1, surname: 1});
};
UserSchema.statics.getSaw_and_Accepted = async function (idapp) {
const User = this;