-- TimeTrack Pro - Requetes sauvegardees
-- Note: A creer manuellement dans Access ou via VBA

-- ============================================================
-- qry_TempsByProjet
-- Total des heures par projet
-- ============================================================
SELECT
    p.Nom AS Projet,
    c.Nom AS Client,
    SUM(t.Duree) AS TotalHeures,
    SUM(t.Duree * p.TauxHoraire) AS Montant
FROM (tbl_Clients c
    INNER JOIN tbl_Projets p ON c.ClientID = p.ClientID)
    INNER JOIN tbl_Temps t ON p.ProjetID = t.ProjetID
GROUP BY p.Nom, c.Nom
ORDER BY c.Nom, p.Nom;

-- ============================================================
-- qry_TempsByClient
-- Total des heures par client
-- ============================================================
SELECT
    c.Nom AS Client,
    COUNT(DISTINCT p.ProjetID) AS NbProjets,
    SUM(t.Duree) AS TotalHeures,
    SUM(t.Duree * p.TauxHoraire) AS Montant
FROM (tbl_Clients c
    INNER JOIN tbl_Projets p ON c.ClientID = p.ClientID)
    INNER JOIN tbl_Temps t ON p.ProjetID = t.ProjetID
GROUP BY c.Nom
ORDER BY c.Nom;

-- ============================================================
-- qry_ProjetsActifs
-- Liste des projets actifs avec client
-- ============================================================
SELECT
    p.ProjetID,
    p.Nom AS Projet,
    c.Nom AS Client,
    p.TauxHoraire,
    p.DateCreation
FROM tbl_Clients c
    INNER JOIN tbl_Projets p ON c.ClientID = p.ClientID
WHERE p.Actif = True
ORDER BY c.Nom, p.Nom;

-- ============================================================
-- qry_TempsRecent
-- Entrees de temps des 30 derniers jours
-- ============================================================
SELECT
    t.Date,
    c.Nom AS Client,
    p.Nom AS Projet,
    t.Duree,
    t.Description,
    t.Duree * p.TauxHoraire AS Montant
FROM (tbl_Clients c
    INNER JOIN tbl_Projets p ON c.ClientID = p.ClientID)
    INNER JOIN tbl_Temps t ON p.ProjetID = t.ProjetID
WHERE t.Date >= Date() - 30
ORDER BY t.Date DESC;

-- ============================================================
-- qry_TempsMoisCourant
-- Entrees du mois en cours
-- ============================================================
SELECT
    t.Date,
    c.Nom AS Client,
    p.Nom AS Projet,
    t.Duree,
    t.Description,
    t.Duree * p.TauxHoraire AS Montant
FROM (tbl_Clients c
    INNER JOIN tbl_Projets p ON c.ClientID = p.ClientID)
    INNER JOIN tbl_Temps t ON p.ProjetID = t.ProjetID
WHERE Year(t.Date) = Year(Date()) AND Month(t.Date) = Month(Date())
ORDER BY t.Date DESC;
