<?php
class BonVers {
    private $conn;
    private $table_name = "bons_vers";

    public $num_vers;
    public $date_vers;
    public $periode_p;
    public $operateur;
    public $type_vehicule;
    public $mt_ttc;
    public $obs;
    public $creer_par;
    public $date_creer;

    public function __construct($db) {
        $this->conn = $db;
    }

    public function checkPeriodeExistence($operateur, $periode) {
        $query = "SELECT COUNT(*) FROM " . $this->table_name . " WHERE operateur = ? AND periode_p = ?";
        $stmt = $this->conn->prepare($query);
        $stmt->bindParam(1, $operateur);
        $stmt->bindParam(2, $periode);
        $stmt->execute();
        $count = $stmt->fetchColumn();
        return $count > 0;
    }

    public function create() {
        $query = "INSERT INTO " . $this->table_name . " 
                  SET num_vers = :num_vers,
                      date_vers = :date_vers,
                      periode_p = :periode_p,
                      operateur = :operateur,
                      type_vehicule = :type_vehicule,
                      mt_ttc = :mt_ttc,
                      obs = :obs,
                      creer_par = :creer_par,
                      date_creer = :date_creer";

        $stmt = $this->conn->prepare($query);

        $stmt->bindParam(":num_vers", $this->num_vers);
        $stmt->bindParam(":date_vers", $this->date_vers);
        $stmt->bindParam(":periode_p", $this->periode_p);
        $stmt->bindParam(":operateur", $this->operateur);
        $stmt->bindParam(":type_vehicule", $this->type_vehicule);
        $stmt->bindParam(":mt_ttc", $this->mt_ttc);
        $stmt->bindParam(":obs", $this->obs);
        $stmt->bindParam(":creer_par", $this->creer_par);
        $stmt->bindParam(":date_creer", $this->date_creer);

        return $stmt->execute();
    }
}
?>