fetch( PDO::FETCH_ASSOC )['nb'];
echo "
NB CLIENTS DANS ca_client_motifs = ".$NBCAMOTIFSCLIENTS;
//$LOG .= "NB ca_client_motifs = ".$NBCAMOTIFSCLIENTS."\r\n";
if ($NBCAMOTIFSCLIENTS > 0) {
// NOMBRE TOTAL DE CLIENTS DANS ca_historique_client_motifs
$q = "SELECT count(id_client) as nb FROM ca_historique_client_motifs";
$r = excuteQuery($q);
$NBCACLIENTSHISTOAVANT = $r['stmt']->fetch( PDO::FETCH_ASSOC )['nb'];
echo "NB CLIENTS DANS ca_historique_client_motifs AVANT = ".$NBCACLIENTSHISTOAVANT;
//$LOG .= "NB CLIENTS DANS ca_historique_client_motifs AVANT = ".$NBCACLIENTSHISTOAVANT."\r\n";
$NBTOTALPREVU = ($NBCAMOTIFSCLIENTS + $NBCACLIENTSHISTOAVANT);
echo "TOTAL PREVU = ".$NBTOTALPREVU;
$LOG .= "NB_ca_client_motifs = ".$NBCAMOTIFSCLIENTS." | NB_ca_historique_client_motifs AVANT = ".$NBCACLIENTSHISTOAVANT." | TOTAL_PREVU = ".$NBTOTALPREVU."\r\n";
$q = "SELECT id, id_motif, id_client FROM ca_client_motifs ORDER BY id ASC";
$result = excuteQuery($q);
$r = $result['stmt'];
$n = $r->rowCount();
while($o = $r->fetchObject()) {
$q2 = 'INSERT INTO ca_historique_client_motifs (id_motif, id_client)
VALUES ('.intval($o->id_motif).', '.intval($o->id_client).') ';
$r2 = excuteQuery($q2);
}
//$LOG .= "INSERTION DANS ca_historique_client_motifs\r\n";
// #########################################################
// #########################################################
// VERIFICATIONS :
// NOMBRE TOTAL DE CLIENTS DANS ca_historique_client_motifs
$q = "SELECT count(id_client) as nb FROM ca_historique_client_motifs";
$r = excuteQuery($q);
$NBCACLIENTSHISTOAPRES = $r['stmt']->fetch( PDO::FETCH_ASSOC )['nb'];
echo "NB CLIENTS DANS ca_historique_client_motifs APRES = ".$NBCACLIENTSHISTOAPRES;
//$LOG .= "NB_ca_historique_client_motifs APRES = ".$NBCACLIENTSHISTOAPRES."\r\n";
echo "
NBCACLIENTSHISTOAVANT (".$NBCACLIENTSHISTOAVANT.") = NBCACLIENTSHISTOAPRES (".$NBCACLIENTSHISTOAPRES.")";
$LOG .= "NBCACLIENTSHISTOAVANT (".$NBCACLIENTSHISTOAVANT.") = NBCACLIENTSHISTOAPRES (".$NBCACLIENTSHISTOAPRES.")\r\n";
if ($NBCACLIENTSHISTOAPRES == $NBTOTALPREVU) {
echo "OK => DELETE de ca_client_motifs";
$q3 = "DELETE FROM ca_client_motifs";
$r3 = excuteQuery($q3);
$LOG .= "=> DELETE\r\n";
//$r3 = mysqli_query($GLOBALS['cnx'],$q3);
$q4 = 'SELECT MAX(id_client) nb FROM ca_historique_client_motifs';
$r4 = excuteQuery($q4);
$MAXID = $r4['stmt']->fetch( PDO::FETCH_ASSOC )['nb'];
$LOG .= "=> Max id_client dans ca_historique_client_motifs: ".$MAXID."\r\n";
$q4 = 'ALTER TABLE ca_client_motifs AUTO_INCREMENT='.($MAXID+1) ;
$r4 = excuteQuery($q4);
$LOG .= "=> AUTO_INCREMENT ca_client_motifs: ".($MAXID+1)."\r\n";
} else {
echo "PROBLEME DE CORRESPONDANCE : NBCACLIENTSHISTOAPRES != TOTAL PREVU";
$LOG .= "===> PROBLEME DE CORRESPONDANCE : NBCACLIENTSHISTOAPRES != TOTAL PREVU\r\n";
}
} else {
$q4 = 'SELECT MAX(id_client) nb FROM ca_historique_client_motifs';
$r4 = excuteQuery($q4);
$MAXID = $r4['stmt']->fetch( PDO::FETCH_ASSOC )['nb'];
$LOG .= "=> Max id_client dans ca_historique_client_motifs: ".$MAXID."\r\n";
$q4 = 'ALTER TABLE ca_client_motifs AUTO_INCREMENT='.($MAXID+1) ;
$r4 = excuteQuery($q4);
$LOG .= "=> AUTO_INCREMENT ca_client_motifs: ".($MAXID+1)."\r\n";
$LOG .= "=> Pas d' enregistrement...\r\n";
}
$timeend=microtime(true);
$time=$timeend-$timestart;
$page_load_time = number_format($time, 3);
$scriptStart = date("H:i:s", $timestart);
$scriptEnd = date("H:i:s", $timeend);
$timeLoad = $page_load_time;
$LOG .= "DUREE = ".$timeLoad." s\r\n";
echo "Debut du script: ".date("H:i:s", $timestart);
echo "
Fin du script: ".date("H:i:s", $timeend);
echo "
Script execute en " . $page_load_time . " sec";
$fp = fopen ("logs/cron_motifs.txt", "a+");
fwrite($fp, $LOG);
fclose ($fp);
?>