<?php
class Stock {
    public static function getStockByNoArticleRR($noArticleRR) {
        $query = "SELECT * FROM stock".ID_GARAGE." WHERE NoArticleRR = :noarticlerr";
        $statement = Connection::getStatement($query);
        $statement->bindParam(":noarticlerr", $noArticleRR);
        $statement->execute();
        return $statement->fetch();
    }

    public static function updateFieldByNoArticleRR($field, $value, $noArticleRR) {
        if(!is_null($value) && !empty($value)) {
            $query = "UPDATE stock".ID_GARAGE." SET ".$field . "= :value WHERE NoArticleRR = :noarticlerr";
            $statement = Connection::getStatement($query);
            $statement->bindParam(":noarticlerr", $noArticleRR);
            $statement->bindParam(":value", $value);
            return $statement->execute();
        }
        return true;
    }

    public static function insertField($field, $value, $noArticleRR) {
        if(!is_null($value) && !empty($value)) {
            $query = "INSERT INTO stock".ID_GARAGE." (NoArticleRR, ".$field.") VALUES (:noarticlerr, :value)";
            $statement = Connection::getStatement($query);
            $statement->bindParam(":noarticlerr", $noArticleRR);
            $statement->bindParam(":value", $value);
        } else {
            $query = "INSERT INTO stock".ID_GARAGE." (NoArticleRR) VALUES (:noarticlerr)";
            $statement = Connection::getStatement($query);
            $statement->bindParam(":noarticlerr", $noArticleRR);
        }
        
        return $statement->execute();
    }
}