Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relatório de pesos por tempo trabalhado #127

Open
vitormattos opened this issue Sep 6, 2024 · 1 comment
Open

Relatório de pesos por tempo trabalhado #127

vitormattos opened this issue Sep 6, 2024 · 1 comment

Comments

@vitormattos
Copy link
Member

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
Copy link
Member Author

vitormattos commented Oct 1, 2024

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant