<?php
class LogMVTPieces {
    public static function insertNowWithCurrentUser($noArticle, $nb, $montant, $noCommande) {
        $query = "INSERT INTO logmvtpieces".ID_GARAGE." (`NoArticle`, `Nb`, `Montant`, `NoCommande`, `Date`, `Personne`) VALUES (:noarticle, :nb, :montant, :nocommande, NOW(), :personne)";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":noarticle", $noArticle);
        $statement->bindParam(":nb", $nb);
        $statement->bindParam(":montant", $montant);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->bindParam(":personne", $_SESSION['lg_user']);
        $statement->execute();
        return $statement->fetch();
    }

    public static function getByNoCommande($noCommande) {
        $query = "SELECT * FROM logmvtpieces".ID_GARAGE." WHERE NoCommande = :nocommande ORDER BY Date";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":nocommande", $noCommande);
        $statement->execute();
        return $statement->fetchAll();
    }

    public static function getByLesserMontantAndPeriod($montant, $start, $end) {
        $query = "SELECT * FROM logmvtpieces".ID_GARAGE." WHERE Montant < :montant AND Date >= :start AND Date <= :end ORDER BY Date";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":montant", $montant);
        $statement->bindParam(":start", $start);
        $statement->bindParam(":end", $end);
        $statement->execute();
        return $statement->fetchAll();
    }

    
    
    
}