Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Clé primaire partout (#858)
Browse files Browse the repository at this point in the history
* Add PK for all tables

* Applicative schema OK

* azertyuiop
  • Loading branch information
prytoegrian authored Oct 24, 2019
1 parent 69a9e52 commit 5d433dd
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 26 deletions.
63 changes: 63 additions & 0 deletions App/Patchs/Maj/1.14.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# Add an int PK on config_appli
#
ALTER TABLE conges_appli MODIFY appli_variable varchar(100) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '';
ALTER TABLE conges_appli DROP PRIMARY KEY;
ALTER TABLE conges_appli ADD appli_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE conges_appli ADD INDEX appli_variable (appli_variable);
#
# Add an int PK on config_appli
#
ALTER TABLE conges_config MODIFY conf_nom varchar(100) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '';
ALTER TABLE conges_config DROP PRIMARY KEY;
ALTER TABLE conges_config ADD config_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE conges_config ADD INDEX conf_nom (conf_nom);
#
# Add an int PK on conges_echange_rtt
#
ALTER TABLE conges_echange_rtt MODIFY e_login varbinary(99) NOT NULL DEFAULT '';
ALTER TABLE conges_echange_rtt DROP PRIMARY KEY;
ALTER TABLE conges_echange_rtt ADD e_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE conges_echange_rtt ADD INDEX login_date (e_login, e_date_jour);
#
# Add an int PK on conges_jours_feries
#
ALTER TABLE conges_jours_feries MODIFY jf_date date NOT NULL DEFAULT '0000-00-00';
ALTER TABLE conges_jours_feries DROP PRIMARY KEY;
ALTER TABLE conges_jours_feries ADD jf_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE conges_jours_feries ADD INDEX jf_date (jf_date);
#
# Add an int PK on conges_periode
#
ALTER TABLE conges_periode MODIFY p_num int(5) unsigned NOT NULL;
ALTER TABLE conges_periode DROP PRIMARY KEY;
ALTER TABLE conges_periode ADD p_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE conges_periode ADD INDEX p_num (p_num);
#
# Add an int PK on conges_jours_fermeture
#
ALTER TABLE conges_jours_fermeture ADD id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;

#
# Add an int PK on conges_solde_edition
#
ALTER TABLE conges_solde_edition ADD id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;

#
# Add an int PK on conges_mail
#
ALTER TABLE conges_mail ADD mail_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
#
# Add an int PK on conges_solde_user
#
ALTER TABLE conges_solde_user MODIFY su_login varbinary(99) NOT NULL DEFAULT '';
ALTER TABLE conges_solde_user DROP PRIMARY KEY;
ALTER TABLE conges_solde_user ADD su_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE conges_solde_user ADD INDEX login_abs (su_login, su_abs_id);
#
# Add an int PK on conges_users
#
ALTER TABLE conges_users MODIFY u_login varbinary(99) NOT NULL DEFAULT '';
ALTER TABLE conges_users DROP PRIMARY KEY;
ALTER TABLE conges_users ADD u_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT FIRST;
ALTER TABLE conges_users ADD INDEX u_login (u_login);
34 changes: 18 additions & 16 deletions App/ProtoControllers/HautResponsable/ClotureExercice.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,34 @@ private static function updateSoldesEmploye($employe, $typeConges, $comment, \in
{
$return = true;
$soldesEmploye = \App\ProtoControllers\Utilisateur::getSoldesEmploye($sql, $config, $employe);
foreach ($typeConges as $idType => $libelle) {
$soldeRestant = $soldesEmploye[$idType]['su_solde'];
$soldeFutur = $soldesEmploye[$idType]['su_nb_an'];
// Si le solde est négatif, on le déduit du futur solde
if (0 > $soldeRestant) {
$soldeFutur = $soldeFutur + $soldeRestant;
} elseif ($config->isReliquatsAutorise()) {
if (!static::setReliquatEmploye($employe, $idType, $soldeRestant, $sql, $config)) {
if (!empty($soldesEmploye)) {
foreach ($typeConges as $idType => $libelle) {
$soldeRestant = $soldesEmploye[$idType]['su_solde'];
$soldeFutur = $soldesEmploye[$idType]['su_nb_an'];
// Si le solde est négatif, on le déduit du futur solde
if (0 > $soldeRestant) {
$soldeFutur = $soldeFutur + $soldeRestant;
} elseif ($config->isReliquatsAutorise()) {
if (!static::setReliquatEmploye($employe, $idType, $soldeRestant, $sql, $config)) {
$return = false;
break;
}
}
if (!static::setSoldeEmploye($employe, $idType, $soldeFutur, $sql)) {
$return = false;
break;
}
$today = date("Y-m-d");
insert_dans_periode($employe, $today, "am", $today, "am", $soldeFutur, $comment, $idType, "ajout", 0);
}
if (!static::setSoldeEmploye($employe, $idType, $soldeFutur, $sql)) {
$return = false;
break;
}
$today = date("Y-m-d");
insert_dans_periode($employe, $today, "am", $today, "am", $soldeFutur, $comment, $idType, "ajout", 0);
}

return $return;
}

private static function setSoldeEmploye($employe, $idType, $soldeFutur, \includes\SQL $sql)
{
$req = 'UPDATE conges_solde_user
$req = 'UPDATE conges_solde_user
SET su_solde = ' . $soldeFutur .
' WHERE su_login = "' . $sql->quote($employe) .
'" AND su_abs_id = ' . intval($idType) . ';';
Expand Down Expand Up @@ -130,7 +132,7 @@ public static function updateDateLimiteReliquats($annee, &$error, \includes\SQL
$JourMois = explode("-", $LimiteReliquats);
$dateLimite = $annee . "-" . $JourMois[1] . "-" . $JourMois[0];
$req = 'UPDATE conges_appli
SET appli_valeur = \'' . $dateLimite . '\'
SET appli_valeur = \'' . $dateLimite . '\'
WHERE appli_variable=\'date_limite_reliquats\';';
$sql->query($req);

Expand Down
4 changes: 2 additions & 2 deletions config/Fonctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ public static function commit_ajout(&$tab_new_values)
while ($resultat1 = $ReqLog_users->fetch_array()) {
$current_login=$resultat1["u_login"];

$req_insert2="INSERT INTO conges_solde_user (su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) " .
"VALUES ('$current_login', $new_abs_id, 0, 0, 0) ";
$req_insert2="INSERT INTO conges_solde_user (su_id, su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) " .
"VALUES (DEFAULT, '$current_login', $new_abs_id, 0, 0, 0) ";
\includes\SQL::query($req_insert2);
}
}
Expand Down
6 changes: 6 additions & 0 deletions edition/Fonctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1175,13 +1175,19 @@ private static function enregistrement_edition($login)
// recup du tableau des types de conges (seulement les conges)
$tab_type_cong=recup_tableau_types_conges();
foreach ($tab_type_cong as $id_abs => $libelle) {
if (!isset($tab_solde_user[$id_abs])) {
continue;
}
$sql_insert_2 = "INSERT INTO conges_solde_edition
SET se_id_edition=$new_edition_id, se_id_absence=$id_abs, se_solde=$tab_solde_user[$id_abs] ";
$result_insert_2 = \includes\SQL::query($sql_insert_2);
}
if ($config->isCongesExceptionnelsActive()) {
$tab_type_conges_exceptionnels=recup_tableau_types_conges_exceptionnels();
foreach ($tab_type_conges_exceptionnels as $id_abs => $libelle) {
if (!isset($tab_solde_user[$id_abs])) {
continue;
}
$sql_insert_3 = "INSERT INTO conges_solde_edition SET se_id_edition=$new_edition_id, se_id_absence=$id_abs, se_solde=$tab_solde_user[$id_abs] ";
$result_insert_3 = \includes\SQL::query($sql_insert_3);
}
Expand Down
8 changes: 4 additions & 4 deletions hr/hr_ajout_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,24 @@ function insertSoldeUtilisateur(array $data, \includes\SQL $sql) : bool
$typeAbsencesConges = \App\ProtoControllers\Conge::getTypesAbsences($sql, 'conges');

foreach ($typeAbsencesConges as $typeId => $info) {
$valuesStd[] = "('" . $data['login'] . "' ,"
$valuesStd[] = "(DEFAULT, '" . $data['login'] . "' ,"
. $typeId . ", "
. $data['joursAn'][$typeId] . ", "
. $data['soldes'][$typeId] . ", "
. $data['reliquats'][$typeId] . ")" ;
}
$req = "INSERT INTO conges_solde_user (su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) VALUES " . implode(",", $valuesStd);
$req = "INSERT INTO conges_solde_user (su_id, su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) VALUES " . implode(",", $valuesStd);
$returnStd = $sql->query($req);
$returnExc = 1;
if ($config->isCongesExceptionnelsActive()) {
$typeAbsencesExceptionnels = \App\ProtoControllers\Conge::getTypesAbsences($sql, 'conges_exceptionnels');
foreach ($typeAbsencesExceptionnels as $typeId => $info) {
$valuesExc[] = "('" . $data['login'] . "' ,"
$valuesExc[] = "(DEFAULT, '" . $data['login'] . "' ,"
. $typeId . ", 0, "
. $data['soldes'][$typeId] . ", 0)" ;

}
$req = "INSERT INTO conges_solde_user (su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) VALUES " . implode(",", $valuesExc);
$req = "INSERT INTO conges_solde_user (su_id, su_login, su_abs_id, su_nb_an, su_solde, su_reliquat) VALUES " . implode(",", $valuesExc);
$returnExc = $sql->query($req);
}

Expand Down
8 changes: 4 additions & 4 deletions utilisateur/Fonctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1001,8 +1001,8 @@ private static function echange_absence_rtt($onglet, $new_debut_string, $new_fin
}
else // sinon : on insert
{
$sql1 = "INSERT into conges_echange_rtt (e_login, e_date_jour, e_absence, e_presence, e_comment)
VALUES ('".$_SESSION['userlogin']."','$new_debut','$nouvelle_absence_date_1', '$nouvelle_presence_date_1', '$new_comment')" ;
$sql1 = "INSERT into conges_echange_rtt (e_id, e_login, e_date_jour, e_absence, e_presence, e_comment)
VALUES (DEFAULT, '".$_SESSION['userlogin']."','$new_debut','$nouvelle_absence_date_1', '$nouvelle_presence_date_1', '$new_comment')" ;
}
$result1 = \includes\SQL::query($sql1);

Expand All @@ -1022,8 +1022,8 @@ private static function echange_absence_rtt($onglet, $new_debut_string, $new_fin
}
else // sinon: on insert
{
$sql2 = "INSERT into conges_echange_rtt (e_login, e_date_jour, e_absence, e_presence, e_comment)
VALUES ('".$_SESSION['userlogin']."','$new_fin','$nouvelle_absence_date_2', '$nouvelle_presence_date_2', '$new_comment')" ;
$sql2 = "INSERT into conges_echange_rtt (e_id, e_login, e_date_jour, e_absence, e_presence, e_comment)
VALUES (DEFAULT, '".$_SESSION['userlogin']."','$new_fin','$nouvelle_absence_date_2', '$nouvelle_presence_date_2', '$new_comment')" ;
}
$result2 = \includes\SQL::query($sql2);

Expand Down

0 comments on commit 5d433dd

Please sign in to comment.