|
|
<?php
|
|
|
|
|
|
function tri_chap_1($a , $b)
|
|
|
{
|
|
|
if ('S'.$a['code'] < 'S'.$b['code']) return -1;
|
|
|
if ('S'.$a['code'] > 'S'.$b['code']) return 1;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
function tri_chap_2($a , $b)
|
|
|
{
|
|
|
if ('S'.$a['instruction'] < 'S'.$b['instruction']) return -1;
|
|
|
if ('S'.$a['instruction'] > 'S'.$b['instruction']) return 1;
|
|
|
|
|
|
if ('S'.$a['code'] < 'S'.$b['code']) return -1;
|
|
|
if ('S'.$a['code'] > 'S'.$b['code']) return 1;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
require_once('smeti_db.inc.php');
|
|
|
|
|
|
SMETI_db::init();
|
|
|
|
|
|
// Activer le plugin
|
|
|
$libelle = 'Instructions Comptables';
|
|
|
echo "Plugin courant : '$libelle' ";
|
|
|
SMETI_db::setCurPlugin($libelle);
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
echo 'Chargement collectivités ';
|
|
|
$sql = SMETI_db::$pdo->prepare("SELECT code, item, libelle FROM v_items WHERE plugin = ( SELECT id FROM plugins WHERE libelle = 'Collectivités' )");
|
|
|
$sql->execute();
|
|
|
$coll = $sql->fetchAll(PDO::FETCH_NUM);
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
echo 'Chargement instructions comptables ';
|
|
|
$sql = SMETI_db::$pdo->prepare("SELECT code, id, libelle FROM v_items_tree WHERE parent in ( SELECT id FROM v_items WHERE code = 'INSC' )");
|
|
|
$sql->execute();
|
|
|
$instructions = $sql->fetchAll(PDO::FETCH_NUM);
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
// Se positonner sur l'instruction globale
|
|
|
$n = count($instructions);
|
|
|
for($i=0;$i<$n;$i++)
|
|
|
if ($instructions[$i][0] == 'INSCGLOB')
|
|
|
break;
|
|
|
if ($i == $n) die;
|
|
|
|
|
|
$pile_index = 0;
|
|
|
$pile_code[$pile_index] = $instructions[$i][0];
|
|
|
$pile_item[$pile_index] = $instructions[$i][1];
|
|
|
|
|
|
$libelle = 'Fonctions';
|
|
|
echo "Ajout d'une racine: '$libelle' ";
|
|
|
// Ajouter un item
|
|
|
SMETI_db::$libelle = $libelle;
|
|
|
SMETI_db::$code = 'INSCGLOBFONC';
|
|
|
SMETI_db::$req1->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Ajouter un lien sur cet item
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$item;
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = SMETI_db::$code;
|
|
|
$pile_item[$pile_index] = SMETI_db::$item;
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
|
|
|
echo 'Chargement des données (première passe)'.PHP_EOL;
|
|
|
$counter = 0;
|
|
|
$shipments = json_decode(file_get_contents("../data/json/BMO/05_FONCTIONS.json"), true);
|
|
|
$nb_shipments = count($shipments);
|
|
|
usort($shipments,'tri_chap_1');
|
|
|
// On conserve les chapitres dans un tableau
|
|
|
// Ils seront réutilisés plus tard
|
|
|
$foncitons = [];
|
|
|
$fonctions[] = ['BIDON','BIDON'];
|
|
|
foreach($shipments as $element)
|
|
|
{
|
|
|
// Gestion d'une barre de progression
|
|
|
progressBar($counter, $nb_shipments);
|
|
|
$counter += 1;
|
|
|
// Gestion d'une barre de progression
|
|
|
|
|
|
// On ne tient pas compte des données incorrectes
|
|
|
if (!isset($element['code'])) continue;
|
|
|
if (!isset($element['libelle'])) continue;
|
|
|
|
|
|
$n = count($fonctions);
|
|
|
for($i=0;$i<$n;$i++)
|
|
|
if ($fonctions[$i][0] == $element['code'])
|
|
|
break;
|
|
|
if ($i == $n)
|
|
|
{
|
|
|
// Rajouter un item
|
|
|
SMETI_db::$code = $element['code'];
|
|
|
SMETI_db::$libelle = $element['libelle'];
|
|
|
SMETI_db::$req1->execute();
|
|
|
// Rajouter un lien
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
|
|
|
$fonctions[] = [SMETI_db::$code, SMETI_db::$libelle, SMETI_db::$item];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Enlever la barre de progression
|
|
|
clearLine();
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
// Enlever la barre de progression
|
|
|
|
|
|
echo 'Chargement des données (deuxième passe)'.PHP_EOL;
|
|
|
|
|
|
// Décliner par instruction
|
|
|
// Commencer par empiler deux valeurs vides
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = '';
|
|
|
$pile_item[$pile_index] = 0;
|
|
|
|
|
|
usort($shipments,'tri_chap_2');
|
|
|
$n = count($fonctions);
|
|
|
$counter = 0;
|
|
|
foreach($shipments as $element)
|
|
|
{
|
|
|
// Gestion d'une barre de progression
|
|
|
progressBar($counter, $nb_shipments);
|
|
|
$counter += 1;
|
|
|
// Gestion d'une barre de progression
|
|
|
|
|
|
if (!isset($element['code'])) continue;
|
|
|
if (!isset($element['libelle'])) continue;
|
|
|
|
|
|
if ('INSC'.$element['instruction'] != $pile_code[$pile_index-1])
|
|
|
{
|
|
|
// Se positonner sur l'instruction globale
|
|
|
$n = count($instructions);
|
|
|
for($i=0;$i<$n;$i++)
|
|
|
if ($instructions[$i][0] == 'INSC'.$element['instruction'])
|
|
|
break;
|
|
|
if ($i == $n) die;
|
|
|
|
|
|
$pile_index = 0;
|
|
|
$pile_code[$pile_index] = $instructions[$i][0];
|
|
|
$pile_item[$pile_index] = $instructions[$i][1];
|
|
|
|
|
|
// Rajouter un item pour les chapitres
|
|
|
SMETI_db::$code = 'FONC'.$element['instruction'];
|
|
|
SMETI_db::$libelle = 'Fonctions '. $element['instruction'];
|
|
|
SMETI_db::$req1->execute();
|
|
|
// Rajouter un lien
|
|
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$link = 0;
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
$pile_index += 1;
|
|
|
$pile_code[$pile_index] = SMETI_db::$code;
|
|
|
$pile_item[$pile_index] = SMETI_db::$child;
|
|
|
$last ='';
|
|
|
}
|
|
|
|
|
|
if ($element['code'] == $last) continue;
|
|
|
for($i=0;$i<$n;$i++)
|
|
|
if ($fonctions[$i][0] == $element['code'])
|
|
|
break;
|
|
|
if ($i == $n) continue;
|
|
|
|
|
|
// Rajouter un lien vers le chapitre
|
|
|
SMETI_db::$item = $chapitres[$i][2];
|
|
|
SMETI_db::$link = 1;
|
|
|
SMETI_db::$req2->execute();
|
|
|
// Rajouter un noeud
|
|
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
|
|
SMETI_db::$parent = $pile_item[$pile_index];
|
|
|
SMETI_db::$req3->execute();
|
|
|
|
|
|
// NB : on pourrait s'en passer en plaçant le chapitre dans la pile
|
|
|
$last = $element['code'];
|
|
|
}
|
|
|
|
|
|
// Enlever la barre de progression
|
|
|
clearLine();
|
|
|
echo 'OK'.PHP_EOL;
|
|
|
// Enlever la barre de progression
|
|
|
|
|
|
?>
|