From 6f825ee3bc75988c68af1d63b551cf59030e8da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 29 Jul 2022 17:03:31 +0200 Subject: [PATCH] #3530 Eliminar uso de person --- db/dump/structure.sql | 911 ++++++++++++++++++++---------------------- 1 file changed, 425 insertions(+), 486 deletions(-) diff --git a/db/dump/structure.sql b/db/dump/structure.sql index e97ee3626..f4124011e 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -4849,170 +4849,148 @@ DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `indicatorsUpdate`(vDated DATE) BEGIN - DECLARE oneYearBefore DATE DEFAULT TIMESTAMPADD(YEAR,-1,vDated); - DECLARE twoMonthsBefore DATE DEFAULT TIMESTAMPADD(DAY,-60,vDated); - DECLARE oneMonthBefore DATE DEFAULT TIMESTAMPADD(DAY,-30,vDated); - DECLARE vWeek INT; - - REPLACE indicators(updated) + DECLARE oneYearBefore DATE DEFAULT TIMESTAMPADD(YEAR,-1, vDated); + DECLARE twoMonthsBefore DATE DEFAULT TIMESTAMPADD(DAY,-60, vDated); + DECLARE oneMonthBefore DATE DEFAULT TIMESTAMPADD(DAY,-30, vDated); + DECLARE vWeek INT; + + REPLACE indicators(updated) VALUES(vDated); - - -- Ventas totales del ultimo año + + -- Ventas totales del ultimo año UPDATE indicators - SET lastYearSales = - ( - SELECT SUM(importe + recargo) - FROM bs.ventas v - JOIN vn2008.empresa e ON e.id = v.empresa_id - JOIN vn2008.empresa_grupo eg ON eg.empresa_grupo_id = e.empresa_grupo - WHERE fecha BETWEEN oneYearBefore AND vDated - AND eg.grupo = 'Verdnatura' + SET lastYearSales = + (SELECT SUM(importe + recargo) + FROM ventas v + JOIN vn2008.empresa e ON e.id = v.empresa_id + JOIN vn2008.empresa_grupo eg ON eg.empresa_grupo_id = e.empresa_grupo + WHERE fecha BETWEEN oneYearBefore AND vDated + AND eg.grupo = 'Verdnatura' ) WHERE updated = vDated; - - -- Greuge total acumulado + + -- Greuge total acumulado UPDATE indicators - SET totalGreuge = - ( - SELECT SUM(amount) - FROM vn.greuge - WHERE shipped <= vDated + SET totalGreuge = + (SELECT SUM(amount) + FROM vn.greuge + WHERE shipped <= vDated ) WHERE updated = vDated; - - -- Tasa de morosidad con respecto a las ventas del último mes + + -- Tasa de morosidad con respecto a las ventas del último mes UPDATE indicators - SET latePaymentRate = - (SELECT SUM(amount) FROM bi.defaulters WHERE date = vDated and amount > 0) - / - ( SELECT SUM(importe + recargo) FROM bs.ventas WHERE fecha BETWEEN oneMonthBefore AND vDated) + SET latePaymentRate = + (SELECT SUM(amount) + FROM bi.defaulters + WHERE date = vDated AND amount > 0) + / + (SELECT SUM(importe + recargo) + FROM ventas + WHERE fecha BETWEEN oneMonthBefore AND vDated) WHERE updated = vDated; - + -- Número de trabajadores activos - UPDATE indicators - SET countEmployee = - ( SELECT CAST(SUM(hours_week) / 40 AS DECIMAL (10 , 2 )) - FROM - postgresql.business AS b - JOIN postgresql.profile p ON p.profile_id = b.provider_id - JOIN postgresql.person pe ON pe.person_id = p.person_id - LEFT JOIN - postgresql.business_labour AS bl ON bl.business_id = b.business_id - LEFT JOIN - postgresql.calendar_labour_type AS cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id - WHERE - (vDated BETWEEN b.date_start AND b.date_end OR (b.date_end IS NULL AND b.date_start <= vDated)) - AND pe.name = 'VERDNATURA LEVANTE SL' + UPDATE indicators + SET countEmployee = + (SELECT CAST(SUM(cl.hours_week) / 40 AS DECIMAL (10, 2)) + FROM postgresql.business b + JOIN postgresql.business_labour bl ON bl.business_id = b.business_id + JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id + WHERE vDated BETWEEN b.date_start AND IFNULL(b.date_end, vDated) + AND b.companyCodeFk = 'VNL' ) WHERE updated = vDated; -- Maná medio acumulado por comercial - UPDATE indicators - SET averageMana = - (SELECT avg(used) - FROM bs.mana_spellers + UPDATE indicators + SET averageMana = + (SELECT AVG(amount) + FROM vn.workerMana ) WHERE updated = vDated; - + -- Número de clientes que han comprado en los últimos 30 dias - UPDATE indicators - SET lastMonthActiveClients = + UPDATE indicators + SET lastMonthActiveClients = (SELECT COUNT(DISTINCT t.clientFk) FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated ) - WHERE updated = vDated; - - -- Número de clientes que no han comprado en los últimos 30 dias, pero compraron en los 30 anteriores - UPDATE indicators - SET lastMonthLostClients = + WHERE updated = vDated; + + -- Número de clientes que no han comprado en los últimos 30 dias, pero compraron en los 30 anteriores + UPDATE indicators + SET lastMonthLostClients = (SELECT COUNT(lm.clientFk) FROM - ( - SELECT DISTINCT t.clientFk + (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated ) cm RIGHT JOIN - ( - SELECT DISTINCT t.clientFk + (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped >= twoMonthsBefore AND t.shipped < oneMonthBefore ) lm ON lm.clientFk = cm.clientFk - WHERE cm.clientFk IS NULL + WHERE cm.clientFk IS NULL ) - WHERE updated = vDated; - - -- Número de clientes que han comprado en los últimos 30 dias, pero no compraron en los 30 anteriores - UPDATE indicators - SET lastMonthNewClients = + WHERE updated = vDated; + + -- Número de clientes que han comprado en los últimos 30 dias, pero no compraron en los 30 anteriores + UPDATE indicators + SET lastMonthNewClients = (SELECT COUNT(cm.clientFk) FROM - ( - SELECT DISTINCT t.clientFk + (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated ) cm LEFT JOIN - ( - SELECT DISTINCT t.clientFk + (SELECT DISTINCT t.clientFk FROM vn.ticket t WHERE t.shipped >= twoMonthsBefore AND t.shipped < oneMonthBefore ) lm ON lm.clientFk = cm.clientFk - WHERE lm.clientFk IS NULL + WHERE lm.clientFk IS NULL ) - WHERE updated = vDated; - - -- Porcentaje de autopedidos sobre los pedidos totales - UPDATE indicators - SET lastMonthWebBuyingRate = - ( SELECT (SUM(source_app != '') - SUM(source_app = 'TPV')) / SUM(source_app != '') - FROM hedera.`order` - WHERE date_send BETWEEN oneMonthBefore AND vDated - ) - WHERE updated = vDated; - - /* - -- Indicadores de producción - UPDATE indicators i - JOIN productionIndicators pi ON pi.dated = i.updated - SET i.productionHours = pi.productionHours, - i.dailyWorkersCost = pi.dailyWorkersCost, - i.volumeM3 = pi.volumeM3, - i.salesValue = pi.salesValue, - i.valueM3 = pi.valueM3, - i.hoursM3 = pi.hoursM3, - i.workerCostM3 = pi.workerCostM3, - i.salesWorkersCostRate = pi.salesWorkersCostRate - WHERE updated BETWEEN oneMonthBefore AND vDated; - */ + WHERE updated = vDated; - -- CAP Para el calculo de las ventas agrupado por semanas - - SELECT week + -- Porcentaje de autopedidos sobre los pedidos totales + UPDATE indicators + SET lastMonthWebBuyingRate = + (SELECT (SUM(source_app != '') - SUM(source_app = 'TPV')) / SUM(source_app != '') + FROM hedera.`order` + WHERE date_send BETWEEN oneMonthBefore AND vDated + ) + WHERE updated = vDated; + + -- Cálculo de las ventas agrupado por semanas + SELECT week INTO vWeek FROM vn.time - WHERE dated=vDated INTO vWeek; - - TRUNCATE `bs`.`salesByWeek`; - - INSERT INTO `bs`.`salesByWeek` (week,year,sales) - SELECT `t`.`week` AS `week`,`t`.`year` AS `year`, SUM(`v`.`importe` + `v`.`recargo`) AS `sales` - FROM `bs`.`ventas` `v` - LEFT JOIN `vn`.`time` `t` ON `t`.`dated` = fecha - GROUP BY `t`.`week` , `t`.`year` - ORDER BY `t`.`week` , `t`.`year`; - - -- CAP Indicador Ventas semana actual - UPDATE indicators i - JOIN `bs`.`salesByWeek` s ON s.week= vWeek AND s.year = YEAR(vDated) + WHERE dated = vDated; + + TRUNCATE salesByWeek; + + INSERT INTO salesByWeek (week, year, sales) + SELECT t.week, t.year, SUM(v.importe + v.recargo) sales + FROM ventas v + LEFT JOIN vn.time t ON t.dated = fecha + GROUP BY t.week, t.year + ORDER BY t.week, t.year; + + -- Indicador Ventas semana actual + UPDATE indicators i + JOIN salesByWeek s ON s.week= vWeek + AND s.year = YEAR(vDated) SET i.thisWeekSales = s.sales - WHERE updated = vDated; - - -- CAP indicador ventas semana actual en el año pasado - UPDATE indicators i - JOIN `bs`.`salesByWeek` s ON s.week= vWeek AND s.year = YEAR(vDated)-1 + WHERE updated = vDated; + + -- Indicador ventas semana actual en el año pasado + UPDATE indicators i + JOIN salesByWeek s ON s.week = vWeek + AND s.year = YEAR(vDated)-1 SET i.lastYearWeekSales = s.sales WHERE updated = vDated; @@ -6900,7 +6878,6 @@ BEGIN /** * Carga los datos de la plantilla de trabajadores, altas y bajas en la tabla workerLabourDataByMonth para facilitar el cálculo del gráfico en grafana. * Se carga el día 21 de cada mes, elimina los registros del último año y los vuelve a calcular - * */ DECLARE vFristDay DATE; DECLARE vLastDay DATE; @@ -6941,9 +6918,8 @@ BEGIN INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato LEFT JOIN (SELECT w.workerFk FROM vn.workerLabour w @@ -6951,25 +6927,24 @@ BEGIN AND wl.workerFk = w.workerFk WHERE w.started BETWEEN vFristDay AND vLastDay AND wl.ended )sub ON sub.workerFk = w.workerFk - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND w.started BETWEEN vFristDay AND vLastDay AND sub.workerFk IS NULL - AND NOT p.isFreelance; + AND NOT w.isFreelance; -- Bajas periodo INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato LEFT JOIN (SELECT started, workerFk FROM vn.workerLabour) wl ON wl.started >= w.ended AND wl.workerFk = w.workerFk - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND w.ended BETWEEN vFristDay AND vLastDay AND wl.started IS NULL - AND NOT p.isFreelance; + AND NOT w.isFreelance; -- Anterior al periodo SET vLastDay = LAST_DAY(DATE_SUB(vFristDay, INTERVAL 1 DAY)); @@ -6977,26 +6952,24 @@ BEGIN INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) - AND NOT p.isFreelance; + AND NOT w.isFreelance; -- Discapacidad INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) - AND p.isDisable - AND NOT p.isFreelance; + AND w.isDisable + AND NOT w.isFreelance; END LOOP; CLOSE vCursor; @@ -21042,21 +21015,20 @@ BEGIN IF(co.country IN ('España', 'España exento'), 1,IF(co.isUeeMember = 1, 2, 4)), IFNULL(s.taxTypeSageFk, 0), n.Nacion, - IFNULL(con.Telefono, ''), - IFNULL(con.Movil, ''), + IFNULL(sc.phone, ''), + IFNULL(sc.mobile, ''), IFNULL(s.transactionTypeSageFk, 0), IFNULL(s.withholdingSageFk, '0'), - IFNULL(SUBSTR(con.email, 1, (COALESCE(NULLIF(LOCATE(',', con.email), 0), 99) - 1)), ''), + IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''), IFNULL(iban, '') FROM vn.supplier s - JOIN providerLastThreeMonths pl ON pl.supplierFk = s.id + JOIN supplierLastThreeMonths pl ON pl.supplierFk = s.id LEFT JOIN vn.country co ON co.id = s.countryFk LEFT JOIN Naciones n ON n.countryFk = co.id LEFT JOIN vn.province p ON p.id = s.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id - LEFT JOIN vn2008.Relaciones r ON r.Id_Proveedor = s.id + LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id - LEFT JOIN vn2008.Contactos con ON con.Id_Contacto = r.Id_Contacto JOIN vn.company c ON c.id = pl.companyFk WHERE c.id = vCompanyFk AND s.isActive AND @@ -85349,7 +85321,6 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN - /** * Horas que debe trabajar un empleado según contrato y día. * @param vDatedFrom workerTimeControl @@ -85357,7 +85328,6 @@ BEGIN * @table tmp.user(userFk) * @return tmp.timeBusinessCalculate */ - DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate; CREATE TEMPORARY TABLE tmp.timeBusinessCalculate @@ -85374,7 +85344,7 @@ BEGIN timeWorkSeconds timeBusinessSeconds, SEC_TO_TIME(timeWorkSeconds) timeBusinessSexagesimal, timeWorkSeconds / 3600 timeBusinessDecimal, - type, + name type, permissionRate, hoursWeek, discountRate, @@ -85387,27 +85357,26 @@ BEGIN IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) hourEnd, IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.start,5), " - ", LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) timeTable, IF(j.start = NULL, 0, IFNULL(SUM(TIME_TO_SEC(j.end)) - SUM(TIME_TO_SEC(j.start)),0)) timeWorkSeconds, - cs.type, - cs.permissionRate, - cs.discountRate, + at2.name, + at2.permissionRate, + at2.discountRate, cl.hours_week hoursWeek, - cs.isAllowedToWork - FROM vn.time t - LEFT JOIN postgresql.business b ON t.dated BETWEEN b.date_start AND ifnull(b.date_end, vDatedTo ) - LEFT JOIN postgresql.profile AS pr ON b.client_id = pr.profile_id - LEFT JOIN postgresql.person AS p ON pr.person_id = p.person_id - LEFT JOIN vn.worker AS w ON p.id_trabajador = w.id + at2.isAllowedToWork + FROM time t + LEFT JOIN postgresql.business b ON t.dated BETWEEN b.date_start AND IFNULL(b.date_end, vDatedTo ) + LEFT JOIN postgresql.profile pr ON b.client_id = pr.profile_id + LEFT JOIN worker w ON w.id = pr.workerFk JOIN tmp.`user` u ON u.userFK = w.userFK - JOIN postgresql.business_labour AS bl ON b.business_id = bl.business_id - LEFT JOIN postgresql.business_labour_payroll AS bp ON bl.business_id = bp.business_id - LEFT JOIN postgresql.professional_category AS pc ON bl.professional_category_id = pc.professional_category_id - LEFT JOIN postgresql.workcenter AS wc ON bl.workcenter_id = wc.workcenter_id - LEFT JOIN postgresql.calendar_labour_type AS cl ON bl.calendar_labour_type_id = cl.calendar_labour_type_id - LEFT JOIN postgresql.journey AS j ON j.business_id = b.business_id and j.day_id=WEEKDAY(t.dated)+1 - LEFT JOIN postgresql.calendar_employee ce ON ce.business_id=b.business_id and ce.date = t.dated - LEFT JOIN postgresql.calendar_state cs ON cs.calendar_state_id = ce.calendar_state_id + JOIN postgresql.business_labour bl ON b.business_id = bl.business_id + LEFT JOIN postgresql.business_labour_payroll bp ON bl.business_id = bp.business_id + LEFT JOIN postgresql.professional_category pc ON bl.professional_category_id = pc.professional_category_id + LEFT JOIN workCenter wc ON bl.workcenter_id = wc.id + LEFT JOIN postgresql.calendar_labour_type cl ON bl.calendar_labour_type_id = cl.calendar_labour_type_id + LEFT JOIN postgresql.journey j ON j.business_id = b.business_id AND j.day_id=WEEKDAY(t.dated)+1 + LEFT JOIN postgresql.calendar_employee ce ON ce.business_id=b.business_id AND ce.date = t.dated + LEFT JOIN absenceType at2 ON at2.id = ce.calendar_state_id WHERE t.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY w.userFk,dated + GROUP BY w.userFk,dated )sub; UPDATE tmp.timeBusinessCalculate t @@ -85427,7 +85396,7 @@ BEGIN WHERE permissionRate <> 0; UPDATE tmp.timeBusinessCalculate t - JOIN vn.calendarHolidays ch ON ch.dated = t.dated + JOIN calendarHolidays ch ON ch.dated = t.dated JOIN postgresql.business_labour bl ON bl.business_id = t.businessFk AND bl.workcenter_id = ch.workcenterFk SET t.timeWorkSeconds = 0, t.timeWorkSexagesimal = 0, @@ -85503,17 +85472,16 @@ BEGIN SELECT DISTINCT w.userFk FROM postgresql.business AS b LEFT JOIN postgresql.profile AS pr ON pr.profile_id = b.client_id - LEFT JOIN postgresql.person AS p ON p.person_id = pr.person_id LEFT JOIN postgresql.business_labour AS bl ON b.business_id = bl.business_id - LEFT JOIN vn.worker AS w ON p.id_trabajador = w.id - LEFT JOIN vn.department AS d ON bl.department_id = d.id - WHERE ((b.date_start BETWEEN vDatedFrom AND vDatedTo OR b.date_end BETWEEN vDatedFrom AND vDatedTo) OR - (b.date_end IS NULL AND b.date_start <= vDatedTo) OR - (b.date_start <= vDatedFrom AND b.date_end >= vDatedTo) - ) AND bl.department_id = vDepartmentFk + LEFT JOIN worker AS w ON w.id = pr.workerFk + LEFT JOIN department AS d ON bl.department_id = d.id + WHERE (b.date_start BETWEEN vDatedFrom AND vDatedTo + OR IFNULL(b.date_end, vDatedTo) BETWEEN vDatedFrom AND vDatedTo + OR (b.date_start <= vDatedFrom AND b.date_end >= vDatedTo) + ) AND bl.department_id = vDepartmentFk ORDER BY b.date_end DESC; - CALL vn.timeBusiness_calculate(vDatedFrom, vDatedTo); + CALL timeBusiness_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; @@ -85949,17 +85917,16 @@ BEGIN SELECT DISTINCT w.userFk FROM postgresql.business AS b LEFT JOIN postgresql.profile AS pr ON pr.profile_id = b.client_id - LEFT JOIN postgresql.person AS p ON p.person_id = pr.person_id LEFT JOIN postgresql.business_labour AS bl ON b.business_id = bl.business_id - LEFT JOIN vn.worker AS w ON p.id_trabajador = w.id - LEFT JOIN vn.department AS d ON bl.department_id = d.id - WHERE ((b.date_start BETWEEN vDatedFrom AND vDatedTo OR b.date_end BETWEEN vDatedFrom AND vDatedTo) OR - (b.date_end IS NULL AND b.date_start <= vDatedTo) OR - (b.date_start <= vDatedFrom AND b.date_end >= vDatedTo) + LEFT JOIN worker AS w ON w.id = pr.workerFk + LEFT JOIN department AS d ON bl.department_id = d.id + WHERE (b.date_start BETWEEN vDatedFrom AND vDatedTo + OR IFNULL(b.date_end, vDatedTo) BETWEEN vDatedFrom AND vDatedTo + OR (b.date_start <= vDatedFrom AND b.date_end >= vDatedTo) ) AND bl.department_id = vDepartmentFk ORDER BY b.date_end DESC; - CALL vn.timeControl_calculate(vDatedFrom, vDatedTo); + CALL timeControl_calculate(vDatedFrom, vDatedTo); DROP TEMPORARY TABLE tmp.`user`; @@ -87359,18 +87326,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `workerCalendar_calculateYear` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCalendar_calculateYear`(vYear INT, vWorkerFk INT) -BEGIN +/*!50003 DROP PROCEDURE IF EXISTS `BEGIN /** * Calcula los días y horas de vacaciones en función de un trabajador y año @@ -87379,7 +87335,6 @@ BEGIN * @param vWorkerFk * @return tmp.workerCalendarCalculateYear (days, hours, daysEnjoyed, hoursEnjoyed) */ - DECLARE vDone BOOL; DECLARE vBusinessFk INT; @@ -87387,9 +87342,8 @@ BEGIN SELECT b.business_id FROM postgresql.business b LEFT JOIN postgresql.profile AS pr ON pr.profile_id = b.client_id - LEFT JOIN postgresql.person AS p ON p.person_id = pr.person_id WHERE vYear BETWEEN YEAR(b.date_start) AND IFNULL(YEAR(b.date_end), vYear ) - AND p.id_trabajador = vWorkerFk; + AND pr.workerFk = vWorkerFk; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -87445,19 +87399,21 @@ DELIMITER ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCreate`( - vFirstname VARCHAR(50), - vSurnames VARCHAR(50), - vWorkerCode CHAR(3), - vBossFk INT, - vUserFk INT + vFirstname VARCHAR(50), + vLastName VARCHAR(50), + vCode CHAR(3), + vBossFk INT, + vUserFk INT, + vFi VARCHAR(15) , + vBirth DATE ) BEGIN /** * Create new worker * */ - INSERT INTO worker(id, code, firstName, lastName, userFk, bossFk) - VALUES (vUserFk, vWorkerCode, vFirstname, vSurnames, vUserFk, vBossFk); + INSERT INTO worker(id, code, firstName, lastName, userFk, bossFk, fi, birth) + VALUES (vUserFk, vCode, vFirstname, vLastName, vUserFk, vBossFk, vFi, vBirth); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -87559,30 +87515,24 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.workerDepartmentByDate; CREATE TEMPORARY TABLE tmp.workerDepartmentByDate ENGINE = MEMORY - SELECT - w.userFk, - p.name, - p.firstname, - d.name AS department, - d.id as departmentFk, + SELECT w.userFk, + w.lastName name, + w.firstName firstname, + d.name department, + d.id departmentFk, b.date_start, d.isProduction, - CAST(12 * blp.importepactado / clt.hours_week / 52 AS DECIMAL(10,2)) as costeHora , - p.nif - - FROM postgresql.person p - JOIN postgresql.profile pr ON p.person_id = pr.person_id + CAST(12 * blp.importepactado / clt.hours_week / 52 AS DECIMAL(10,2)) costeHora, + w.fi nif + FROM postgresql.profile pr JOIN postgresql.business b ON b.client_id = pr.profile_id JOIN postgresql.business_labour bl ON bl.business_id = b.business_id JOIN postgresql.calendar_labour_type clt ON clt.calendar_labour_type_id = bl.calendar_labour_type_id JOIN postgresql.business_labour_payroll blp ON blp.business_id = b.business_id - JOIN vn.department d ON d.id = bl.department_id - JOIN vn.worker w ON w.id = p.id_trabajador - WHERE b.date_start <= vDate AND IFNULL(b.date_end,'3000-01-01') > vDate - ; - - -- SELECT * FROM tmp.workerDepartmentByDate; - + JOIN department d ON d.id = bl.department_id + JOIN worker w ON w.id = pr.workerFk + WHERE b.date_start <= vDate + AND (b.date_end > vDate OR b.date_end IS NULL); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -87646,20 +87596,19 @@ BEGIN DECLARE rs CURSOR FOR SELECT a.id - FROM ((SELECT * FROM (select date_end,date_start,business_id, client_id - FROM postgresql.business - ORDER BY client_id, date_end IS NULL DESC , date_end DESC) - c GROUP BY client_id) c - INNER JOIN postgresql.business b ON c.client_id = b.client_id AND c.business_id = b.business_id - INNER JOIN postgresql.profile pr ON b.client_id = pr.profile_id - INNER JOIN postgresql.person p ON pr.person_id = p.person_id - - INNER JOIN vn.worker w ON p.id_trabajador = w.id) - INNER JOIN account.account a ON w.userFk = a.id - WHERE ((b.date_end) IS NOT NULL - AND (b.date_end) < CURDATE() - AND (b.date_end) > TIMESTAMPADD(DAY, -70,CURDATE()) ); - + FROM (SELECT client_id, business_id + FROM (SELECT business_id, client_id + FROM postgresql.business + ORDER BY client_id, date_end IS NULL DESC , date_end DESC + LIMIT 10000000000000000000)sub + GROUP BY client_id)sub2 + JOIN postgresql.business b ON sub2.client_id = b.client_id AND sub2.business_id = b.business_id + JOIN postgresql.profile pr ON b.client_id = pr.profile_id + JOIN account.account a ON pr.workerFk = a.id + WHERE b.date_end IS NOT NULL + AND b.date_end < CURDATE() + AND b.date_end > TIMESTAMPADD(DAY, -70, CURDATE()); + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN rs; @@ -89026,134 +88975,130 @@ proc: BEGIN * @return Retorna si encuentra un problema 'odd','maxTimeWork','breakDay','breakWeek' ; * En caso de tener algun problema retorna el primero que encuentra */ - DECLARE vLastIn DATETIME ; - DECLARE vLastOut DATETIME ; - DECLARE vDayWorkMax INT; - DECLARE vDayBreak INT; - DECLARE vWeekBreak INT ; + DECLARE vLastIn DATETIME ; + DECLARE vLastOut DATETIME ; + DECLARE vDayWorkMax INT; + DECLARE vDayBreak INT; + DECLARE vWeekBreak INT ; DECLARE vWeekScope INT; - DECLARE vDayStayMax INT; - DECLARE vProblem VARCHAR(20) DEFAULT NULL; - DECLARE vTimedWorked INT; - DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL; - DECLARE vDepartmentFk INT; - DECLARE vTo VARCHAR(50) DEFAULT NULL; - DECLARE vUserName VARCHAR(50) DEFAULT NULL; - DECLARE vBody VARCHAR(255) DEFAULT NULL; - + DECLARE vDayStayMax INT; + DECLARE vProblem VARCHAR(20) DEFAULT NULL; + DECLARE vTimedWorked INT; + DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL; + DECLARE vDepartmentFk INT; + DECLARE vTo VARCHAR(50) DEFAULT NULL; + DECLARE vUserName VARCHAR(50) DEFAULT NULL; + DECLARE vBody VARCHAR(255) DEFAULT NULL; + SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax FROM workerTimeControlParams; - SELECT MAX(timed) INTO vLastIn + SELECT MAX(timed) INTO vLastIn FROM workerTimeControl - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'in'; - - SELECT MAX(timed) INTO vLastOut + + SELECT MAX(timed) INTO vLastOut FROM workerTimeControl - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'out'; - - SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo + + SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo FROM account.user u - WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); - + WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); + SELECT CONCAT(firstName,' ',lastName) INTO vUserName FROM worker w - WHERE w.id = vUserFk; - - - IF UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA - - -- VERIFICAR DESCANSO DIARIO + WHERE w.id = vUserFk; + + + IF UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA + + -- VERIFICAR DESCANSO DIARIO IF UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN - SELECT "Descansos 12 h" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + SELECT "Descansos 12 h" AS problem; + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 12 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - END IF; - - -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ + LEAVE proc; + END IF; + + -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ IF (SELECT MOD(COUNT(*),2) -- <>0 FROM workerTimeControl WHERE userFk = vUserFk AND timed >= vLastIn ) THEN SELECT "Dias con fichadas impares" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; - - -- VERIFICAR VACACIONES - SELECT cs.type INTO vCalendarStateType + + -- VERIFICAR VACACIONES + SELECT at2.name INTO vCalendarStateType FROM postgresql.calendar_employee ce JOIN postgresql.business b USING(business_id) JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN postgresql.calendar_state cs USING(calendar_state_id) - JOIN worker w ON w.id = p.id_trabajador - WHERE ce.date = CURDATE() - AND cs.isAllowedToWork = FALSE - AND w.userFk = vUserFk + JOIN absenceType at2 ON at2.id = ce.calendar_state_id + WHERE ce.date = CURDATE() + AND at2.isAllowedToWork = FALSE + AND pr.workerFk = vUserFk LIMIT 1; - - IF(LENGTH(vCalendarStateType)) THEN + + IF(LENGTH(vCalendarStateType)) THEN SELECT vCalendarStateType AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - - END IF; - - - -- VERIFICAR CONTRATO EN VIGOR - IF (SELECT COUNT(*) + LEAVE proc; + + END IF; + + + -- VERIFICAR CONTRATO EN VIGOR + IF (SELECT COUNT(*) FROM postgresql.business b JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN worker w ON w.id = p.id_trabajador - WHERE w.userFk = vUserFk + WHERE pr.workerFk = vUserFk AND b.date_start <= vDated AND IFNULL(b.date_end,vDated) >= vDated ) = 0 THEN - SELECT "No hay un contrato en vigor" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + SELECT "No hay un contrato en vigor" AS problem; + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; - + END IF; - -- VERIFICAR DESCANSO SEMANAL + -- VERIFICAR DESCANSO SEMANAL SET @vHasBreakWeek:= FALSE; SET @vLastTimed:= UNIX_TIMESTAMP((NOW() - INTERVAL vWeekScope SECOND)); - + DROP TEMPORARY TABLE IF EXISTS tmp.trash; CREATE TEMPORARY TABLE tmp.trash - SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, + SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, @vLastTimed:= UNIX_TIMESTAMP(timed) FROM workerTimeControl WHERE timed>= (NOW() - INTERVAL vWeekScope SECOND) AND userFk= vUserFk AND direction IN ('in','out') ORDER BY timed ASC; - + IF UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA SELECT "Descansos 36 h" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 36 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; - DROP TEMPORARY TABLE tmp.trash; - - ELSE -- DIA ACTUAL + DROP TEMPORARY TABLE tmp.trash; + + ELSE -- DIA ACTUAL -- VERIFICA QUE EL TIEMPO EFECTIVO NO SUPERE EL MÁXIMO SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(NOW()), 0) INTO vTimedWorked @@ -89162,17 +89107,17 @@ proc: BEGIN AND timed >= vLastIn ORDER BY timed; - IF vTimedWorked > vDayWorkMax THEN - SELECT "Jornadas" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + IF vTimedWorked > vDayWorkMax THEN + SELECT "Jornadas" AS problem; + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Jornadas") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; END IF; - - -- VERIFICAR DEPARTAMENTO + + -- VERIFICAR DEPARTAMENTO /* IF vTabletFk IS NOT NULL THEN SELECT wtcu.departmentFk INTO vDepartmentFk FROM workerTimeControlUserInfo wtcu @@ -89182,7 +89127,7 @@ proc: BEGIN WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk ) = 0 THEN SELECT "No perteneces a este departamento." AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; @@ -90345,7 +90290,8 @@ BEGIN DECLARE vPermissionRate DECIMAL(5,2); DECLARE vIsTeleworking BOOL; DECLARE vIsTeleworkingOld BOOL; - + DECLARE vError BOOL DEFAULT FALSE; + DECLARE vCursor CURSOR FOR SELECT CONCAT(u.name, '@verdnatura.es'), u.id, tb.dated, tb.timeWorkDecimal, LEFT(tb.timeWorkSexagesimal,5) timeWorkSexagesimal, tb.timeTable, tc.timeWorkDecimal timeWorkedDecimal, LEFT(tc.timeWorkSexagesimal,5) timeWorkedSexagesimal, tb.type, tb.businessFk,tb.permissionRate, d.isTeleworking @@ -90353,8 +90299,9 @@ BEGIN JOIN user u ON u.id = tb.userFk JOIN department d ON d.id = tb.departmentFk JOIN postgresql.business b ON b.business_id = tb.businessFk - JOIN company c ON c.id = b.provider_id LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated + LEFT JOIN worker w ON w.id = u.id + LEFT JOIN `user` u2 ON u2.id = w.bossFk JOIN (SELECT tb.userFk, SUM(IF(tb.type IS NULL, IF(tc.timeWorkDecimal > 0, FALSE, IF(tb.timeWorkDecimal > 0, TRUE, FALSE)), @@ -90366,17 +90313,28 @@ BEGIN )sub ON sub.userFk = u.id WHERE d.hasToRefill AND IFNULL(vWorkerFk,u.id) = u.id AND - c.code = 'VNL' + b.companyCodeFk = 'VNL' ORDER BY u.id, tb.dated; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + SET vError = TRUE; + + INSERT INTO tmp.error(workerFk) + SELECT vWorkerFk; + END; + DROP TABLE IF EXISTS tmp.timeControlCalculate; DROP TABLE IF EXISTS tmp.timeBusinessCalculate; DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate; DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate1; DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate1; + DROP TEMPORARY TABLE IF EXISTS tmp.error; + + CREATE TEMPORARY TABLE tmp.error (workerFk INT); SELECT CONCAT (MIN(dated), ' 00:00:00'), CONCAT (MAX(dated), ' 23:59:59') INTO vStarted, vEnded FROM time @@ -90419,6 +90377,9 @@ proc: LOOP LEAVE proc; END IF; + START TRANSACTION; + SET vError = FALSE; + IF vTimeWorkDecimal>0 AND vTimeWorkedDecimal IS NULL AND IFNULL(vPermissionRate, TRUE) THEN IF vTimeTable IS NULL THEN INSERT INTO workerTimeControl (userFk, timed, manual, direction, isSendMail) @@ -90516,9 +90477,10 @@ proc: LOOP FETCH vCursor INTO vReceiver, vWorkerFk, vDated, vTimeWorkDecimal, vTimeWorkSexagesimal, vTimeTable, vTimeWorkedDecimal, vTimeWorkedSexagesimal, vAbsenceType, vBusinessFk, vPermissionRate, vIsTeleworking; IF vWorkerFk <> vWorkerFkOld OR vDone THEN - SELECT CONCAT( IFNULL(nif, ''), ' - ', firstName, ' ', name ) INTO vWorkerInfo - FROM postgresql.person - WHERE id_trabajador = vWorkerFkOld; + SELECT CONCAT_WS(' ', fi, firstName, surnames) INTO vWorkerInfo + FROM person + WHERE workerFk = vWorkerFkOld; + SET vHeader = CONCAT("


", vWorkerInfo , "

@@ -90548,7 +90510,7 @@ proc: LOOP
"); - IF vIsTeleworkingOld THEN + IF vIsTeleworkingOld AND NOT vError THEN CALL mail_insert( vReceiverOld, 'timecontrol@verdnatura.es', @@ -90558,6 +90520,8 @@ proc: LOOP INSERT IGNORE INTO workerTimeControlMail (workerFk, year, week) VALUES(vWorkerFkOld, vYear, vWeek); + ELSE + ROLLBACK; END IF; SET vBody = ''; @@ -90566,13 +90530,24 @@ proc: LOOP SET vIsTeleworkingOld = vIsTeleworking; SET vReceiverOld = vReceiver; END IF; + COMMIT; END LOOP; CLOSE vCursor; - + + INSERT INTO mail (receiver, replyTo, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', vWeek, ' año ', vYear) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM tmp.error e + JOIN worker w ON w.id = e.workerFk + JOIN user u ON u.id = w.bossFk + GROUP BY w.bossFk; + DROP TABLE tmp.timeControlCalculate; DROP TABLE tmp.timeBusinessCalculate; DROP TABLE tmp.timeControlCalculate1; DROP TABLE tmp.timeBusinessCalculate1; + DROP TABLE tmp.error; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -90785,172 +90760,136 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerWeekControl`(vUserFk INT, vDated DATE, vTabletFk VARCHAR(100)) BEGIN - -/* Devuelve la cantidad de descansos de 12h y de 36 horas que ha disfrutado el trabajador -* en la semana inmediatamente anterior a la fecha que pasa como parámetro. -* -* UPDATED PAK 2019/09/02 -* PENDING REVIEW +/* +* Devuelve la cantidad de descansos de 12h y de 36 horas que ha disfrutado el trabajador +* en la semana inmediatamente anterior a la fecha que pasa como parámetro. +* UPDATED PAK 2019/09/02 +* PENDING REVIEW */ + DECLARE vDescansos12h INT; + DECLARE vDescansos36h INT; + DECLARE vJornadas INT; + DECLARE vImpares INT; + DECLARE vHasSignedToday BOOLEAN; + DECLARE v12hoursInMinutes INT DEFAULT 719; + DECLARE v36hoursInMinutes INT DEFAULT 2159; + DECLARE vCantWork VARCHAR(50) DEFAULT ''; + DECLARE vDepartmentFk INT; + DECLARE isEnabled BOOLEAN DEFAULT TRUE; -DECLARE vDescansos12h INT; -DECLARE vDescansos36h INT; -DECLARE vJornadas INT; -DECLARE vImpares INT; -DECLARE vHasSignedToday BOOLEAN; -DECLARE v12hoursInMinutes INT DEFAULT 719; -DECLARE v36hoursInMinutes INT DEFAULT 2159; -DECLARE vCantWork VARCHAR(50) DEFAULT ''; -DECLARE vDepartmentFk INT; -DECLARE isEnabled BOOLEAN DEFAULT TRUE; + SELECT COUNT(*) INTO vHasSignedToday + FROM workerTimeControl WHERE timed >= vDated AND userFk = vUserFk; + SET @day := 0; + SET @lastTimed := NOW(); -SELECT COUNT(*) INTO vHasSignedToday - FROM vn.workerTimeControl WHERE timed >= vDated AND userFk = vUserFk; - -SET @day := 0; -SET @lastTimed := NOW(); - -SELECT SUM(IF(interval_in_minutes >= v12hoursInMinutes,1,0)), SUM(FLOOR(interval_in_minutes/ v36hoursInMinutes)) , SUM(jornadas) - INTO vDescansos12h, vDescansos36h, vJornadas - FROM - ( - SELECT fichada_anterior, fichada_actual, interval_in_minutes, jornadas - FROM - ( - SELECT @lastTimed fichada_anterior, - timed, - CAST(time_to_sec(timediff(timed,@lastTimed )) / 60 AS UNSIGNED) as interval_in_minutes, - IF(day(timed) != @day, 1, 0) as jornadas, - @day := day(timed) dia_del_mes, - @lastTimed := timed fichada_actual - FROM - ( - SELECT day(timed) as dayNumber, dayname(timed) as dayName, timed - FROM - (SELECT TIMESTAMPADD(DAY, -11, NOW()) as timed, vUserFk as userFk -- Fichada virtual para los en los que no se ha trabajado la semana anterior - UNION ALL - SELECT timed, userFk - FROM vn.workerTimeControl wtc - WHERE userFk = vUserFk - AND timed >= TIMESTAMPADD(DAY, -10,vDated) - UNION ALL - SELECT IF(vHasSignedToday, '2000-01-01 00:00', NOW()) as timed, vUserFk - ) sub4 - ORDER BY timed - ) sub - - ) sub2 - WHERE fichada_actual >= TIMESTAMPADD(WEEK, -1, vDated) - ) sub3 ; - -SELECT IFNULL(SUM(impar),0) into vImpares -FROM ( - SELECT day(timed) as dayNumber, - count(*) mod 2 as impar - FROM vn.workerTimeControl wtc - WHERE userFk = vUserFk - AND timed >= TIMESTAMPADD(WEEK, -1,vDated) AND timed < vDated - GROUP BY dayNumber - ) sub; - --- Vacaciones -SELECT cs.type INTO vCantWork - FROM postgresql.calendar_employee ce - JOIN postgresql.business b USING(business_id) - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN postgresql.calendar_state cs USING(calendar_state_id) - JOIN vn.worker w ON w.id = p.id_trabajador - WHERE ce.date = CURDATE() - AND cs.isAllowedToWork = FALSE - AND w.userFk = vUserFk - LIMIT 1; - --- Contrato en vigor -SELECT IF(COUNT(*),vCantWork,'Sin contrato') INTO vCantWork - FROM postgresql.business b - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN vn.worker w ON w.id = p.id_trabajador - WHERE w.userFk = vUserFk - AND b.date_start <= vDated - AND IFNULL(b.date_end,vDated) >= vDated; - --- Departamento si vTabletFk es 0 no hacemos comprobacion (Madrid y Vilassar) -IF vTabletFk <> '0' THEN --- 1 Obtener el departamento del usuario - SELECT wtcu.departmentFk INTO vDepartmentFk - FROM vn.workerTimeControlUserInfo wtcu - WHERE wtcu.userFk = vUserFk; --- 2 Comprobar si la tablet pertenece al departamento - SELECT COUNT(td.tabletFk) INTO isEnabled - FROM vn.tabletDepartment td - WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk; - -END IF; - - - -IF vJornadas IS NOT NULL THEN - - SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis - - UNION ALL - - SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, IF(vDescansos12h >= vJornadas, 'Correcto','Error: 1 por jornada') as Análisis - - UNION ALL - - SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, IF(vDescansos36h / 2 >= FLOOR(vJornadas/10), 'Correcto','Error: mínimo 2 cada 14 dias') as Análisis - - UNION ALL - - SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, IF(vImpares = 0, 'Correcto','Error') as Análisis - - UNION ALL - - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, - '' as Cantidad, - IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + SELECT SUM(IF(interval_in_minutes >= v12hoursInMinutes,1,0)), SUM(FLOOR(interval_in_minutes/ v36hoursInMinutes)) , SUM(jornadas) + INTO vDescansos12h, vDescansos36h, vJornadas + FROM + ( + SELECT fichada_anterior, fichada_actual, interval_in_minutes, jornadas + FROM + ( + SELECT @lastTimed fichada_anterior, + timed, + CAST(time_to_sec(timediff(timed,@lastTimed )) / 60 AS UNSIGNED) as interval_in_minutes, + IF(day(timed) != @day, 1, 0) as jornadas, + @day := day(timed) dia_del_mes, + @lastTimed := timed fichada_actual + FROM + ( + SELECT day(timed) as dayNumber, dayname(timed) as dayName, timed + FROM + (SELECT TIMESTAMPADD(DAY, -11, NOW()) as timed, vUserFk as userFk -- Fichada virtual para los en los que no se ha trabajado la semana anterior + UNION ALL + SELECT timed, userFk + FROM vn.workerTimeControl wtc + WHERE userFk = vUserFk + AND timed >= TIMESTAMPADD(DAY, -10,vDated) + UNION ALL + SELECT IF(vHasSignedToday, '2000-01-01 00:00', NOW()) as timed, vUserFk + ) sub4 + ORDER BY timed + ) sub - UNION ALL + ) sub2 + WHERE fichada_actual >= TIMESTAMPADD(WEEK, -1, vDated) + ) sub3 ; - SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis - - ; + SELECT IFNULL(SUM(impar),0) into vImpares + FROM ( + SELECT day(timed) as dayNumber, + count(*) mod 2 as impar + FROM vn.workerTimeControl wtc + WHERE userFk = vUserFk + AND timed >= TIMESTAMPADD(WEEK, -1,vDated) AND timed < vDated + GROUP BY dayNumber + ) sub; -ELSE - - - SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis - - UNION ALL - - SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, 'Correcto' as Análisis - - UNION ALL - - SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, 'Correcto' as Análisis - - UNION ALL - - SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, 'Correcto' as Análisis + -- Vacaciones + SELECT at2.name INTO vCantWork + FROM postgresql.calendar_employee ce + JOIN postgresql.business b USING(business_id) + JOIN postgresql.profile pr ON pr.profile_id = b.client_id + JOIN absenceType at2 ON at2.id = ce.calendar_state_id + WHERE ce.date = CURDATE() + AND at2.isAllowedToWork = FALSE + AND pr.workerFk = vUserFk + LIMIT 1; - UNION ALL - - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, - '' as Cantidad, IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis - - UNION ALL - - SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis - ; - -END IF; + -- Contrato en vigor + SELECT IF(COUNT(*),vCantWork,'Sin contrato') INTO vCantWork + FROM postgresql.business b + JOIN postgresql.profile pr ON pr.profile_id = b.client_id + WHERE pr.workerFk = vUserFk + AND b.date_start <= vDated + AND IFNULL(b.date_end,vDated) >= vDated; + + -- Departamento si vTabletFk es 0 no hacemos comprobacion (Madrid y Vilassar) + IF vTabletFk <> '0' THEN + -- 1 Obtener el departamento del usuario + SELECT wtcu.departmentFk INTO vDepartmentFk + FROM workerTimeControlUserInfo wtcu + WHERE wtcu.userFk = vUserFk; + -- 2 Comprobar si la tablet pertenece al departamento + SELECT COUNT(td.tabletFk) INTO isEnabled + FROM tabletDepartment td + WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk; + + END IF; + + IF vJornadas IS NOT NULL THEN + + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis + UNION ALL + SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, IF(vDescansos12h >= vJornadas, 'Correcto','Error: 1 por jornada') as Análisis + UNION ALL + SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, IF(vDescansos36h / 2 >= FLOOR(vJornadas/10), 'Correcto','Error: mínimo 2 cada 14 dias') as Análisis + UNION ALL + SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, IF(vImpares = 0, 'Correcto','Error') as Análisis + UNION ALL + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, + IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + UNION ALL + SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; + ELSE + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis + UNION ALL + SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + UNION ALL + SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -94308,7 +94247,7 @@ USE `bs`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `bajasLaborales` AS select `p`.`firstname` AS `firstname`,`p`.`name` AS `name`,`b`.`business_id` AS `business_id`,max(`ce`.`date`) AS `lastDate`,max(ifnull(`b`.`date_end`,curdate())) AS `endContract`,`cs`.`type` AS `type`,cast(count(0) as decimal(10,0)) AS `dias`,`w`.`userFk` AS `userFk` from (((((`postgresql`.`calendar_employee` `ce` join `postgresql`.`business` `b` on((`b`.`business_id` = `ce`.`business_id`))) join `postgresql`.`profile` `pr` on((`pr`.`profile_id` = `b`.`client_id`))) join `postgresql`.`person` `p` on((`p`.`person_id` = `pr`.`person_id`))) join `postgresql`.`calendar_state` `cs` on((`cs`.`calendar_state_id` = `ce`.`calendar_state_id`))) join `vn`.`worker` `w` on((`w`.`id` = `p`.`id_trabajador`))) where ((`ce`.`date` >= (curdate() + interval -(1) year)) and (`cs`.`type` not in ('Vacaciones','Vacaciones 1/2 día','Compensar','Festivo'))) group by `p`.`firstname`,`p`.`name`,`cs`.`type` having (`endContract` >= curdate()) */; +/*!50001 VIEW `bajasLaborales` AS SELECT `w`.`firstName` AS `firstname`, `w`.`lastName` AS `name`, `b`.`business_id` AS `business_id`, MAX(`ce`.`date`) AS `lastDate`, MAX(IFNULL(`b`.`date_end`, CURDATE())) AS `endContract`, `at`.`name` AS `type`, CAST(COUNT(0) AS DECIMAL (10 , 0 )) AS `dias`, `w`.`id` AS `userFk` FROM ((((`postgresql`.`calendar_employee` `ce` JOIN `postgresql`.`business` `b` ON ((`b`.`business_id` = `ce`.`business_id`))) JOIN `postgresql`.`profile` `pr` ON ((`pr`.`profile_id` = `b`.`client_id`))) JOIN `vn`.`worker` `w` ON ((`w`.`id` = `pr`.`workerFk`))) JOIN `vn`.`absenceType` `at` ON ((`at`.`id` = `ce`.`calendar_state_id`))) WHERE ((`ce`.`date` >= (CURDATE() + INTERVAL -(1) YEAR)) AND (`at`.`name` NOT IN ('Vacaciones' , 'Vacaciones 1/2 día', 'Compensar', 'Festivo'))) GROUP BY w.firstName , w.lastName , at.name HAVING (endContract >= CURDATE()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95237,11 +95176,11 @@ USE `sage`; /*!50001 SET collation_connection = @saved_col_connection */; -- --- Final view structure for view `providerLastThreeMonths` +-- Final view structure for view `supplierLastThreeMonths` -- -/*!50001 DROP TABLE IF EXISTS `providerLastThreeMonths`*/; -/*!50001 DROP VIEW IF EXISTS `providerLastThreeMonths`*/; +/*!50001 DROP TABLE IF EXISTS `supplierLastThreeMonths `*/; +/*!50001 DROP VIEW IF EXISTS `supplierLastThreeMonths`*/; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; @@ -95250,7 +95189,7 @@ USE `sage`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `providerLastThreeMonths` AS select `vn`.`invoiceIn`.`supplierFk` AS `supplierFk`,`vn`.`invoiceIn`.`companyFk` AS `companyFk` from `vn`.`invoiceIn` where (`vn`.`invoiceIn`.`issued` > (curdate() - interval 3 month)) union select `vn`.`payment`.`supplierFk` AS `supplierFk`,`vn`.`payment`.`companyFk` AS `companyFk` from `vn`.`payment` where (`vn`.`payment`.`received` > (curdate() + interval -(3) month)) */; +/*!50001 VIEW `supplierLastThreeMonths` AS SELECT `vn`.`invoiceIn`.`supplierFk` AS `supplierFk`, `vn`.`invoiceIn`.`companyFk` AS `companyFk` FROM `vn`.`invoiceIn` WHERE (`vn`.`invoiceIn`.`issued` > (CURDATE() - INTERVAL 3 MONTH)) UNION SELECT `vn`.`payment`.`supplierFk` AS `supplierFk`, `vn`.`payment`.`companyFk` AS `companyFk` FROM `vn`.`payment` WHERE (`vn`.`payment`.`received` > (CURDATE() + INTERVAL -(3) MONTH)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97136,7 +97075,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `personMedia` AS select `p`.`id_trabajador` AS `workerFk`,`m`.`value` AS `mediaValue` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `po` on((`po`.`person_id` = `p`.`person_id`))) join `postgresql`.`profile_media` `pom` on((`pom`.`profile_id` = `po`.`profile_id`))) join `postgresql`.`media` `m` on((`m`.`media_id` = `pom`.`media_id`))) join `postgresql`.`media_type` `mt` on((`mt`.`media_type_id` = `m`.`media_type_id`))) where (`mt`.`name` = 'movil personal') */; +/*!50001 VIEW `personMedia` AS SELECT `po`.`workerFk` AS `workerFk`, `m`.`value` AS `mediaValue` FROM (((`postgresql`.`profile` `po` JOIN `postgresql`.`profile_media` `pom` ON ((`pom`.`profile_id` = `po`.`profile_id`))) JOIN `postgresql`.`media` `m` ON ((`m`.`media_id` = `pom`.`media_id`))) JOIN `postgresql`.`media_type` `mt` ON ((`mt`.`media_type_id` = `m`.`media_type_id`))) WHERE (`mt`.`name` = 'movil personal') */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97459,7 +97398,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `salesPersonSince` AS select `p`.`id_trabajador` AS `workerFk`,min(`b`.`date_start`) AS `started` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) left join `postgresql`.`business` `b` on((`pr`.`profile_id` = `b`.`client_id`))) left join `postgresql`.`business_labour` `bl` on((`b`.`business_id` = `bl`.`business_id`))) join `postgresql`.`professional_category` `pc` on((`pc`.`professional_category_id` = `bl`.`professional_category_id`))) where (`pc`.`category_name` = 'Aux ventas') group by `p`.`id_trabajador` */; +/*!50001 VIEW `salesPersonSince` AS SELECT `pr`.`workerFk` AS `workerFk`, MIN(`b`.`date_start`) AS `started` FROM (((`postgresql`.`profile` `pr` LEFT JOIN `postgresql`.`business` `b` ON ((`pr`.`profile_id` = `b`.`client_id`))) LEFT JOIN `postgresql`.`business_labour` `bl` ON ((`b`.`business_id` = `bl`.`business_id`))) JOIN `postgresql`.`professional_category` `pc` ON ((`pc`.`professional_category_id` = `bl`.`professional_category_id`))) WHERE (`pc`.`category_name` = 'Aux ventas') GROUP BY `pr`.`workerFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97877,7 +97816,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerBusinessDated` AS select `t`.`dated` AS `dated`,`b`.`business_id` AS `business_id`,`w`.`id` AS `workerFk` from ((((`vn`.`time` `t` left join `postgresql`.`business` `b` on((`t`.`dated` between `b`.`date_start` and ifnull(`b`.`date_end`,curdate())))) left join `postgresql`.`profile` `pr` on((`b`.`client_id` = `pr`.`profile_id`))) left join `postgresql`.`person` `p` on((`pr`.`person_id` = `p`.`person_id`))) left join `vn`.`worker` `w` on((`p`.`id_trabajador` = `w`.`id`))) where (`t`.`dated` > (curdate() + interval -(2) year)) */; +/*!50001 VIEW `workerBusinessDated` AS SELECT `t`.`dated` AS `dated`, `b`.`business_id` AS `business_id`, `pr`.`workerFk` AS `workerFk` FROM ((`vn`.`time` `t` LEFT JOIN `postgresql`.`business` `b` ON ((`t`.`dated` BETWEEN `b`.`date_start` AND IFNULL(`b`.`date_end`, CURDATE())))) LEFT JOIN `postgresql`.`profile` `pr` ON ((`b`.`client_id` = `pr`.`profile_id`))) WHERE (`t`.`dated` > (CURDATE() + INTERVAL -(2) YEAR)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97896,7 +97835,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerCalendar` AS select `ce`.`business_id` AS `businessFk`,`p`.`id_trabajador` AS `workerFk`,`ce`.`calendar_state_id` AS `absenceTypeFk`,`ce`.`date` AS `dated` from (((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) join `postgresql`.`business` `b` on((`b`.`client_id` = `pr`.`profile_id`))) join `postgresql`.`calendar_employee` `ce` on((`ce`.`business_id` = `b`.`business_id`))) */; +/*!50001 VIEW `workerCalendar` AS SELECT `ce`.`business_id` AS `businessFk`, `pr`.`workerFk` AS `workerFk`, `ce`.`calendar_state_id` AS `absenceTypeFk`, `ce`.`date` AS `dated` FROM ((`postgresql`.`profile` `pr` JOIN `postgresql`.`business` `b` ON ((`b`.`client_id` = `pr`.`profile_id`))) JOIN `postgresql`.`calendar_employee` `ce` ON ((`ce`.`business_id` = `b`.`business_id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97915,7 +97854,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerDepartment` AS select `p`.`id_trabajador` AS `workerFk`,`d`.`id` AS `departmentFk` from (((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) left join (`postgresql`.`business` `b` left join `postgresql`.`business_labour` `bl` on((`b`.`business_id` = `bl`.`business_id`))) on((`pr`.`profile_id` = `b`.`client_id`))) join `vn`.`department` `d` on((`d`.`id` = `bl`.`department_id`))) where ((isnull(`b`.`date_end`) and (`b`.`date_start` <= curdate())) or ((`b`.`date_end` >= curdate()) and (`b`.`date_start` <= curdate()))) */; +/*!50001 VIEW `workerDepartment` AS SELECT `pr`.`workerFk` AS `workerFk`, `bl`.`department_id` AS `departmentFk` FROM (`postgresql`.`profile` `pr` LEFT JOIN (`postgresql`.`business` `b` LEFT JOIN `postgresql`.`business_labour` `bl` ON ((`b`.`business_id` = `bl`.`business_id`))) ON ((`pr`.`profile_id` = `b`.`client_id`))) WHERE ((ISNULL(`b`.`date_end`) AND (`b`.`date_start` <= CURDATE())) OR ((`b`.`date_end` >= CURDATE()) AND (`b`.`date_start` <= CURDATE()))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97953,7 +97892,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerLabour` AS select `b`.`business_id` AS `businessFk`,`p`.`id_trabajador` AS `workerFk`,`bl`.`workcenter_id` AS `workCenterFk`,`b`.`date_start` AS `started`,`b`.`date_end` AS `ended`,`d`.`id` AS `departmentFk`,`b`.`payedHolidays` AS `payedHolidays` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) join `postgresql`.`business` `b` on((`b`.`client_id` = `pr`.`profile_id`))) join `postgresql`.`business_labour` `bl` on((`b`.`business_id` = `bl`.`business_id`))) join `vn`.`department` `d` on((`d`.`id` = `bl`.`department_id`))) order by `b`.`date_start` desc */; +/*!50001 VIEW `workerLabour` AS SELECT `b`.`business_id` AS `businessFk`, `pr`.`workerFk` AS `workerFk`, `bl`.`workcenter_id` AS `workCenterFk`, `b`.`date_start` AS `started`, `b`.`date_end` AS `ended`, `d`.`id` AS `departmentFk`, `b`.`payedHolidays` AS `payedHolidays` FROM (((`postgresql`.`profile` `pr` JOIN `postgresql`.`business` `b` ON ((`b`.`client_id` = `pr`.`profile_id`))) JOIN `postgresql`.`business_labour` `bl` ON ((`b`.`business_id` = `bl`.`business_id`))) JOIN `vn`.`department` `d` ON ((`d`.`id` = `bl`.`department_id`))) ORDER BY `b`.`date_start` DESC */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97991,7 +97930,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerMedia` AS select `p`.`id_trabajador` AS `workerFk`,`m`.`value` AS `mediaValue` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `po` on((`po`.`person_id` = `p`.`person_id`))) join `postgresql`.`profile_media` `pom` on((`pom`.`profile_id` = `po`.`profile_id`))) join `postgresql`.`media` `m` on((`m`.`media_id` = `pom`.`media_id`))) join `postgresql`.`media_type` `mt` on((`mt`.`media_type_id` = `m`.`media_type_id`))) where (`mt`.`name` = 'movil empresa') */; +/*!50001 VIEW `workerMedia` AS SELECT `po`.`workerFk` AS `workerFk`, `m`.`value` AS `mediaValue` FROM (((`postgresql`.`profile` `po` JOIN `postgresql`.`profile_media` `pom` ON ((`pom`.`profile_id` = `po`.`profile_id`))) JOIN `postgresql`.`media` `m` ON ((`m`.`media_id` = `pom`.`media_id`))) JOIN `postgresql`.`media_type` `mt` ON ((`mt`.`media_type_id` = `m`.`media_type_id`))) WHERE (`mt`.`name` = 'movil empresa') */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */;