ajout import focnitons step 1
This commit is contained in:
@@ -56,5 +56,9 @@ foreach($shipments as $element)
|
||||
SMETI_db::$child = SMETI_db::$item;
|
||||
SMETI_db::$req3->execute();
|
||||
}
|
||||
// Enlever la barre de progression
|
||||
clearLine();
|
||||
echo 'OK'.PHP_EOL;
|
||||
// Enlever la barre de progression
|
||||
|
||||
?>
|
||||
|
||||
@@ -71,8 +71,13 @@ SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||
SMETI_db::$link = 0;
|
||||
SMETI_db::$req2->execute();
|
||||
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||
// Positionner ce lien comme parent
|
||||
SMETI_db::$parent = SMETI_db::$item;
|
||||
// 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;
|
||||
|
||||
$libelle = 'Chapitres';
|
||||
@@ -86,8 +91,13 @@ SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||
SMETI_db::$link = 0;
|
||||
SMETI_db::$req2->execute();
|
||||
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||
// Positionner ce lien comme parent
|
||||
SMETI_db::$parent = SMETI_db::$item;
|
||||
// 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;
|
||||
@@ -135,15 +145,15 @@ foreach($shipments as $element)
|
||||
|
||||
// Enlever la barre de progression
|
||||
clearLine();
|
||||
echo 'OK'.PHP_EOL;
|
||||
// Enlever la barre de progression
|
||||
|
||||
echo 'OK'.PHP_EOL;
|
||||
echo 'Chargement des données (deuxième passe)'.PHP_EOL;
|
||||
$counter = 0;
|
||||
|
||||
// Décliner par instruction
|
||||
// Commencer par empiler deux valeurs vides
|
||||
$pile_index += 1;
|
||||
$pile_index = 1;
|
||||
$pile_code[$pile_index] = '';
|
||||
$pile_item[$pile_index] = 0;
|
||||
|
||||
@@ -181,7 +191,7 @@ foreach($shipments as $element)
|
||||
SMETI_db::$req3->execute();
|
||||
$pile_index += 1;
|
||||
$pile_code[$pile_index] = SMETI_db::$code;
|
||||
$pile_item[$pile_index] = SMETI_db::$item;
|
||||
$pile_item[$pile_index] = SMETI_db::$child;
|
||||
// Conserver l'instruction dans un tableau
|
||||
$instructions[] = [SMETI_db::$code, SMETI_db::$item];
|
||||
|
||||
@@ -201,7 +211,7 @@ foreach($shipments as $element)
|
||||
SMETI_db::$req3->execute();
|
||||
$pile_index += 1;
|
||||
$pile_code[$pile_index] = SMETI_db::$code;
|
||||
$pile_item[$pile_index] = SMETI_db::$item;
|
||||
$pile_item[$pile_index] = SMETI_db::$child;
|
||||
$last ='';
|
||||
}
|
||||
|
||||
206
bin/import_12_fonctions.php
Normal file
206
bin/import_12_fonctions.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?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();
|
||||
|
||||
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 ($intructions[$i][0] == 'INSCGLOB')
|
||||
break;
|
||||
$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
|
||||
|
||||
die;
|
||||
|
||||
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;
|
||||
|
||||
$pile_index += 1;
|
||||
$pile_code[$pile_index] = '';
|
||||
$pile_item[$pile_index] = 0;
|
||||
|
||||
usort($shipments,'tri_chap_2');
|
||||
$n = count($chapitres);
|
||||
$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 ($element['instruction'] != $pile_code[$pile_index-1])
|
||||
{
|
||||
$pile_index = 0;
|
||||
|
||||
// Rajouter un item pour l'instruction
|
||||
SMETI_db::$code = $element['instruction'];
|
||||
SMETI_db::$libelle = 'Instruction '. $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;
|
||||
|
||||
$code = 'CHAP'.$element['instruction'];
|
||||
$libelle = 'Chapitres '.$element['instruction'];
|
||||
// Rajouter un item pour les chapitres
|
||||
SMETI_db::$code = 'CHAP'.$element['instruction'];
|
||||
SMETI_db::$libelle = 'Chapitres '. $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 ($chapitres[$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
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user