Good evening everyone, I have a table conge (id_conge, number_day, year, id_employe) I would like to insert data but I want each employee take for each year 20 days he can not take more than 20 days each year.
Here is my code:
public function create(conge $conge){
$this->makes();
$id_employe=$_POST['id_employe'];
$number_day=$_POST['number_day'];
$nb_jours = $this->pdo->query('SELECT nombre_jour FROM conge WHERE id_employe = '.$id_employe.' AND number_day= '.$number_day);
$nb_conge = 0;
// Calcul du total pour chaque congés de l'année
foreach($nb_jours as $jour) {
$nb_conge = $nb_conge+$jour;
}
if ($nb_conge <= 20) {
$this->st=$this->pdo->prepare("insert into conge values(:id_conge,:number_day,:year,:id_employe)");
$this->st->bindvalue(':id_conge',$conge->getid_conge(),pdo::PARAM_INT );
$this->st->bindvalue(':number_day',$conge->getnumber_day(),pdo::PARAM_INT );
$this->st->bindvalue(':year',$conge->getyear(),pdo::PARAM_INT );
$this->st->bindvalue(':id_employe',$conge->getid_employe(),pdo::PARAM_INT );
$exe=$this->st->execute();
}else{
echo("erreur echec");
}
}}
And thank you