<?php
class Employee {

    public static function getEmployee() {
        $query = "SELECT * FROM employes".ID_GARAGE;
        $statement = Connection::getStatement($query);
        $statement->execute();
        return $statement->fetchAll();
    }
    
    public static function getVendeur() {
        $query = "SELECT employes".ID_GARAGE.".NoClient, clients.Nom, clients.Prenom FROM employes".ID_GARAGE." JOIN clients ON employes".ID_GARAGE.".NoClient=clients.NoClient ORDER BY clients.Nom";
        $statement = Connection::getStatement($query);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getMecano() {
        $query = "SELECT employes".ID_GARAGE.".NoClient, clients.Prenom FROM employes".ID_GARAGE.", clients WHERE employes".ID_GARAGE.".Actif = 1 AND employes".ID_GARAGE.".HeureAtelier > 0 AND employes".ID_GARAGE.".NoClient = clients.NoClient ORDER BY clients.Prenom";
        $statement = Connection::getStatement($query);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getActifEmployee() {
        $query = "SELECT * FROM employes".ID_GARAGE." WHERE Actif=1";
        $statement = Connection::getStatement($query);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getActifEmployeeByClient($noClient) {
        $query = "SELECT * FROM employes".ID_GARAGE." WHERE NoClient=:client AND Actif = 1";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":client", $noClient);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getEmployeeByClient($noClient) {
        $query = "SELECT * FROM employes".ID_GARAGE." WHERE NoClient=:client";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":client", $noClient);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getHeureEmployeeByClient($noClient) {
        $query = "SELECT HeureAtelier FROM employes".ID_GARAGE." WHERE NoClient = :client";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":client", $noClient);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getSumByActifEmployee() {
        $query = "SELECT SUM(HeureAtelier) FROM employes".ID_GARAGE." WHERE Actif = 1";
        $statement = Connection::getStatement($query);
        $statement->execute();
        return $statement->fetch();
    }
}