Relatório de pesos por tempo trabalhado
Opened this issue · 1 comments
vitormattos commented
Retorno necessário por cooperado:
- tax_number
- peso: deve se definir a faixa de peso para cada quantidade de horas trabalhadas
A query deve considerar:
- Total de horas trabalhadas nos últimos X anos em projetos que possuem vat_id para todos que trabalharam no mês X
vitormattos commented
SELECT JSON_ARRAYAGG(
JSON_OBJECT(
'weight', weight,
'tax_number', tax_number
)
) AS result
FROM (
SELECT
u.alias,
uptn.value AS tax_number,
SUM(TIMESTAMPDIFF(SECOND, t.start_time, t.end_time) / 3600) / 8 AS total_work_days,
CASE
WHEN SUM(TIMESTAMPDIFF(SECOND, t.start_time, t.end_time) / 3600) / 8 >= 260*2 THEN 5 -- 2 anos
WHEN SUM(TIMESTAMPDIFF(SECOND, t.start_time, t.end_time) / 3600) / 8 >= 260 THEN 4 -- 1 ano
WHEN SUM(TIMESTAMPDIFF(SECOND, t.start_time, t.end_time) / 3600) / 8 >= 100 THEN 3
WHEN SUM(TIMESTAMPDIFF(SECOND, t.start_time, t.end_time) / 3600) / 8 >= 50 THEN 2
ELSE 1
END AS weight
FROM kimai2_timesheet t
JOIN kimai2_projects p ON p.id = t.project_id
JOIN kimai2_customers c ON c.id = p.customer_id
JOIN kimai2_users u ON u.id = t.user
JOIN kimai2_user_preferences uptn ON uptn.user_id = u.id AND uptn.name = 'tax_number'
WHERE c.id NOT IN (18, 22)
AND t.user IN (SELECT t.user FROM kimai2_timesheet t WHERE t.end_time >= '2024-08-01 23:59:59' AND t.end_time <= NOW())
GROUP BY u.alias, uptn.value
ORDER BY weight, uptn.value
) AS aggregated_data;