refs #5843 fix back
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Satorres 2023-09-20 11:58:36 +02:00
parent daf5b343fd
commit f60b6b84fe
9 changed files with 93 additions and 7 deletions

View File

@ -0,0 +1,86 @@
DELIMITER $$
$$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`timeBusiness_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME)
BEGIN
/**
* Horas que debe trabajar un empleado según contrato y día.
* @param vDatedFrom workerTimeControl
* @param vDatedTo workerTimeControl
* @table tmp.user(userFk)
* @return tmp.timeBusinessCalculate
*/
DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate;
CREATE TEMPORARY TABLE tmp.timeBusinessCalculate
(INDEX (departmentFk))
SELECT dated,
businessFk,
sub.id userFk,
departmentFk,
hourStart,
hourEnd,
timeTable,
timeWorkSeconds,
SEC_TO_TIME(timeWorkSeconds) timeWorkSexagesimal,
timeWorkSeconds / 3600 timeWorkDecimal,
timeWorkSeconds timeBusinessSeconds,
SEC_TO_TIME(timeWorkSeconds) timeBusinessSexagesimal,
timeWorkSeconds / 3600 timeBusinessDecimal,
name type,
permissionRate,
hoursWeek,
discountRate,
isAllowedToWork
FROM(SELECT t.dated,
b.id businessFk,
w.id,
b.departmentFk,
IF(bs.started = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(bs.started,5) ORDER BY bs.started ASC SEPARATOR ' - ')) hourStart ,
IF(bs.started = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(bs.ended,5) ORDER BY bs.ended ASC SEPARATOR ' - ')) hourEnd,
IF(bs.started = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(bs.started,5), " - ", LEFT(bs.ended,5) ORDER BY bs.ended ASC SEPARATOR ' - ')) timeTable,
IF(bs.started = NULL, 0, IFNULL(SUM(TIME_TO_SEC(bs.ended)) - SUM(TIME_TO_SEC(bs.started)), 0)) timeWorkSeconds,
at2.name,
at2.permissionRate,
at2.discountRate,
ct.hoursWeek hoursWeek,
at2.isAllowedToWork
FROM time t
LEFT JOIN business b ON t.dated BETWEEN b.started AND IFNULL(b.ended, vDatedTo)
LEFT JOIN worker w ON w.id = b.workerFk
JOIN tmp.`user` u ON u.userFK = w.id
LEFT JOIN workCenter wc ON wc.id = b.workcenterFK
LEFT JOIN calendarType ct ON ct.id = b.calendarTypeFk
LEFT JOIN businessSchedule bs ON bs.businessFk = b.id AND bs.weekday = WEEKDAY(t.dated) + 1
LEFT JOIN calendar c ON c.businessFk = b.id AND c.dated = t.dated
LEFT JOIN absenceType at2 ON at2.id = c.dayOffTypeFk
WHERE t.dated BETWEEN vDatedFrom AND vDatedTo
GROUP BY w.id, t.dated
)sub;
UPDATE tmp.timeBusinessCalculate t
LEFT JOIN businessSchedule bs ON bs.businessFk = t.businessFk
SET t.timeWorkSeconds = t.hoursWeek / 5 * 3600,
t.timeWorkSexagesimal = SEC_TO_TIME( t.hoursWeek / 5 * 3600),
t.timeWorkDecimal = t.hoursWeek / 5,
t.timeBusinessSeconds = t.hoursWeek / 5 * 3600,
t.timeBusinessSexagesimal = SEC_TO_TIME( t.hoursWeek / 5 * 3600),
t.timeBusinessDecimal = t.hoursWeek / 5
WHERE DAYOFWEEK(t.dated) IN(2,3,4,5,6) AND bs.id IS NULL ;
UPDATE tmp.timeBusinessCalculate t
SET t.timeWorkSeconds = t.timeWorkSeconds - (t.timeWorkSeconds * permissionRate) ,
t.timeWorkSexagesimal = SEC_TO_TIME ((t.timeWorkDecimal - (t.timeWorkDecimal * permissionRate)) * 3600),
t.timeWorkDecimal = t.timeWorkDecimal - (t.timeWorkDecimal * permissionRate)
WHERE permissionRate <> 0;
UPDATE tmp.timeBusinessCalculate t
JOIN calendarHolidays ch ON ch.dated = t.dated
JOIN business b ON b.id = t.businessFk
AND b.workcenterFk = ch.workcenterFk
SET t.timeWorkSeconds = 0,
t.timeWorkSexagesimal = 0,
t.timeWorkDecimal = 0,
t.permissionrate = 1,
t.type = 'Festivo'
WHERE t.type IS NULL;
END$$
DELIMITER ;

View File

@ -75,7 +75,7 @@ module.exports = Self => {
try { try {
const worker = await models.Worker.findOne({ const worker = await models.Worker.findOne({
where: {userFk: userId} where: {id: userId}
}, myOptions); }, myOptions);
const obsevationType = await models.ObservationType.findOne({ const obsevationType = await models.ObservationType.findOne({

View File

@ -9,7 +9,7 @@ module.exports = function(Self) {
let token = ctx.options.accessToken; let token = ctx.options.accessToken;
let userId = token && token.userId; let userId = token && token.userId;
Self.app.models.Worker.findOne({where: {userFk: userId}}, (err, user) => { Self.app.models.Worker.findOne({where: {id: userId}}, (err, user) => {
if (err) return next(err); if (err) return next(err);
ctx.instance.workerFk = user.id; ctx.instance.workerFk = user.id;
next(); next();

View File

@ -39,7 +39,7 @@ module.exports = Self => {
try { try {
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}, myOptions); const worker = await Self.app.models.Worker.findOne({where: {id: userId}}, myOptions);
const params = { const params = {
isOk: false, isOk: false,

View File

@ -53,7 +53,7 @@ module.exports = Self => {
if (!params.workerFk) { if (!params.workerFk) {
const worker = await models.Worker.findOne({ const worker = await models.Worker.findOne({
where: {userFk: userId} where: {id: userId}
}, myOptions); }, myOptions);
params.workerFk = worker.id; params.workerFk = worker.id;

View File

@ -43,7 +43,7 @@ module.exports = Self => {
fields: ['id', 'name', 'alertLevel', 'code'] fields: ['id', 'name', 'alertLevel', 'code']
}, myOptions); }, myOptions);
const worker = await models.Worker.findOne({where: {userFk: userId}}, myOptions); const worker = await models.Worker.findOne({where: {id: userId}}, myOptions);
const promises = []; const promises = [];
for (const id of ticketIds) { for (const id of ticketIds) {

View File

@ -10,7 +10,7 @@ module.exports = function(Self) {
Self.observe('before save', async function(ctx) { Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) { if (ctx.isNewInstance) {
const loopBackContext = LoopBackContext.getCurrentContext(); const loopBackContext = LoopBackContext.getCurrentContext();
const filter = {where: {userFk: loopBackContext.active.accessToken.userId}}; const filter = {where: {id: loopBackContext.active.accessToken.userId}};
const models = Self.app.models; const models = Self.app.models;
const worker = await models.Worker.findOne(filter); const worker = await models.Worker.findOne(filter);

View File

@ -54,7 +54,7 @@ module.exports = Self => {
const ticketList = await models.Ticket.find(filter, myOptions); const ticketList = await models.Ticket.find(filter, myOptions);
const fixingState = await models.State.findOne({where: {code: 'FIXING'}}, myOptions); const fixingState = await models.State.findOne({where: {code: 'FIXING'}}, myOptions);
const worker = await models.Worker.findOne({ const worker = await models.Worker.findOne({
where: {userFk: userId} where: {id: userId}
}, myOptions); }, myOptions);
await models.Ticket.rawSql('UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', [id], myOptions); await models.Ticket.rawSql('UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', [id], myOptions);