Compare commits
22 Commits
474fb451cb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcd073c82a | ||
|
|
6110bb4cad | ||
|
|
44bccfc692 | ||
|
|
5fc5065b6e | ||
|
|
24c3342ec1 | ||
|
|
b0aaec1c91 | ||
|
|
61b873ae4f | ||
|
|
8e8136a818 | ||
|
|
093df5de53 | ||
|
|
603b76e1aa | ||
|
|
6f9290dfaa | ||
|
|
cc2ee726c0 | ||
|
|
d812ff0a69 | ||
|
|
cb7337dd4f | ||
|
|
a545400b27 | ||
|
|
c696199ee6 | ||
|
|
1f031e427a | ||
|
|
b3c7a26e3b | ||
|
|
be0fde7439 | ||
|
|
5a988b4f59 | ||
|
|
843f30d82e | ||
|
|
c52ec9ae7a |
48
api/credits.php
Normal file
48
api/credits.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Donne tous les parents d'un item, comme parents.php
|
||||||
|
* Rajoute une jointure sur les crédits
|
||||||
|
* Cela permet de r&écupérer le montant, et la réalisation
|
||||||
|
* Le montant est affecté directement à l'item
|
||||||
|
* La réalisation est la somem des crédits des enfants de l'item
|
||||||
|
*/
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try{
|
||||||
|
$pdo = new PDO('sqlite:../data/base.sqlite');
|
||||||
|
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // ERRMODE_WARNING | ERRMODE_EXCEPTION | ERRMODE_SILENT
|
||||||
|
} catch(Exception $e) {
|
||||||
|
echo "Impossible d'accéder à la base de données SQLite : ".$e->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$where_clause = 'WHERE 1 = 1 ';
|
||||||
|
$where_clause .= 'AND item = '.$_REQUEST['item'];
|
||||||
|
|
||||||
|
$sql = '
|
||||||
|
WITH arbre (id, level, path, realisation) AS(
|
||||||
|
SELECT parent, 0, '['|| tree.parent || ']', (SELECT SUM(montant) FROM credit WHERE item in (SELECT item FROM tree st WHERE st.parent = tree.parent))
|
||||||
|
FROM tree
|
||||||
|
WHERE_CLAUSE
|
||||||
|
UNION ALL
|
||||||
|
SELECT parent, arbre.level+1, arbre.path||'['||tree.parent||']',(SELECT SUM(montant) FROM credit WHERE item in (SELECT item FROM tree st WHERE st.parent = tree.parent))
|
||||||
|
FROM tree
|
||||||
|
INNER JOIN arbre ON arbre.id = tree.item
|
||||||
|
) SELECT arbre.*, item.code, item.title, credit.montant FROM arbre
|
||||||
|
INNER JOIN item ON arbre.id = item.id
|
||||||
|
LEFT JOIN credit ON credit.item = item.id
|
||||||
|
ORDER BY path
|
||||||
|
';
|
||||||
|
|
||||||
|
$query = $pdo->prepare(str_replace('WHERE_CLAUSE',$where_clause,$sql));
|
||||||
|
$query->execute();
|
||||||
|
echo json_encode( $query->fetchAll(PDO::FETCH_ASSOC));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO : Cumuler les réalisatiosn sur les parents lorsque ceux-ci n'en n'ont pas
|
||||||
|
*/
|
||||||
|
|
||||||
|
?>
|
||||||
39
api/get.php
Normal file
39
api/get.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try{
|
||||||
|
$pdo = new PDO('sqlite:../data/base.sqlite');
|
||||||
|
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // ERRMODE_WARNING | ERRMODE_EXCEPTION | ERRMODE_SILENT
|
||||||
|
} catch(Exception $e) {
|
||||||
|
echo "Impossible d'accéder à la base de données SQLite : ".$e->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$where_clause = 'WHERE 1 = 1';
|
||||||
|
//$where_clause .= ' AND path LIKE "%[1]%"';
|
||||||
|
|
||||||
|
$sql = '
|
||||||
|
WITH arbre (parent, id, link, code, name, level, path) AS (
|
||||||
|
SELECT 0, id, link, code, libelle, 0, "{" || plugin || "} [" || id || "]"
|
||||||
|
FROM v_items_tree WHERE parent IS NULL
|
||||||
|
UNION ALL
|
||||||
|
SELECT
|
||||||
|
v_items_tree.parent,
|
||||||
|
v_items_tree.id,
|
||||||
|
v_items_tree.link,
|
||||||
|
v_items_tree.code,
|
||||||
|
v_items_tree.libelle,
|
||||||
|
arbre.level+1,
|
||||||
|
arbre.path || " {" || v_items_tree.rank || "} [" || v_items_tree.id || "]"
|
||||||
|
FROM v_items_tree
|
||||||
|
INNER JOIN arbre ON v_items_tree.parent=arbre.id
|
||||||
|
) SELECT parent, id, link, code, name,level,path FROM arbre WHERE_CLAUSE ORDER BY path
|
||||||
|
';
|
||||||
|
|
||||||
|
$query = $pdo->prepare(str_replace('WHERE_CLAUSE',$where_clause,$sql));
|
||||||
|
$query->execute();
|
||||||
|
echo json_encode( $query->fetchAll(PDO::FETCH_ASSOC));
|
||||||
|
|
||||||
|
?>
|
||||||
35
api/parents.php
Normal file
35
api/parents.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
try{
|
||||||
|
$pdo = new PDO('sqlite:../data/base.sqlite');
|
||||||
|
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||||
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // ERRMODE_WARNING | ERRMODE_EXCEPTION | ERRMODE_SILENT
|
||||||
|
} catch(Exception $e) {
|
||||||
|
echo "Impossible d'accéder à la base de données SQLite : ".$e->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
$where_clause = 'WHERE 1 = 1 ';
|
||||||
|
$where_clause .= 'AND item = '.$_REQUEST['item'];
|
||||||
|
|
||||||
|
$sql = '
|
||||||
|
WITH arbre (id,level, path) AS(
|
||||||
|
SELECT parent, 0, '['|| tree.parent || ']'
|
||||||
|
FROM tree
|
||||||
|
WHERE_CLAUSE
|
||||||
|
UNION ALL
|
||||||
|
SELECT parent, arbre.level+1, arbre.path||'['||tree.parent||']'
|
||||||
|
FROM tree
|
||||||
|
INNER JOIN arbre ON arbre.id = tree.item
|
||||||
|
) SELECT arbre.*, item.code, item.title FROM arbre
|
||||||
|
INNER JOIN item ON arbre.id = item.id
|
||||||
|
ORDER BY path DESC
|
||||||
|
';
|
||||||
|
|
||||||
|
$query = $pdo->prepare(str_replace('WHERE_CLAUSE',$where_clause,$sql));
|
||||||
|
$query->execute();
|
||||||
|
echo json_encode( $query->fetchAll(PDO::FETCH_ASSOC));
|
||||||
|
|
||||||
|
?>
|
||||||
64
bin/import_01_collectivites.php
Normal file
64
bin/import_01_collectivites.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('smeti_db.inc.php');
|
||||||
|
|
||||||
|
SMETI_db::init();
|
||||||
|
|
||||||
|
$libelle = 'Collectivités';
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'COLL';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/01_COLLECTIVITES.json"), true);
|
||||||
|
$counter = 0;
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
$counter += 1;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$code = $element['collcod'];
|
||||||
|
SMETI_db::$libelle = $element['collnom'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
|
||||||
|
// Ajouter un lien
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
|
||||||
|
// Le rattacher à la racine
|
||||||
|
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
|
||||||
|
|
||||||
|
?>
|
||||||
108
bin/import_02_budgets.php
Normal file
108
bin/import_02_budgets.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
$libelle = 'Budgets';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'BUDG';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/02_BUDGETS.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
$counter += 1;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 1;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter le budget
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = $element['colbcodbud'];
|
||||||
|
SMETI_db::$libelle = $element['colbnom'];
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
107
bin/import_03_services.php
Normal file
107
bin/import_03_services.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
$libelle = 'Services';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'SERV';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/03_SERVICES.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
$counter += 1;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 1;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter le service
|
||||||
|
SMETI_db::$code = $element['servcod'];
|
||||||
|
SMETI_db::$libelle = $element['servcod'];
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
107
bin/import_07_programmes.php
Normal file
107
bin/import_07_programmes.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
$libelle = 'Programmes';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'PROG';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/07_PROGRAMMES.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
$counter += 1;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 1;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter le programme
|
||||||
|
SMETI_db::$code = $element['prognum'];
|
||||||
|
SMETI_db::$libelle = $element['proglib'];
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
157
bin/import_08_enveloppes.php
Normal file
157
bin/import_08_enveloppes.php
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
$libelle = 'Enveloppes';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'ENVE';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/08_ENVELOPPES.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
$counter += 1;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index-1])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 2;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
|
||||||
|
// Rajouter un élément vide dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-t-on changé de Catégorie de famille ?
|
||||||
|
if ($element['enveann'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// Dépiler
|
||||||
|
$pile_index -= 1;
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = 'ENVEAN'.$pile_code[$pile_index].$element['enveann'];
|
||||||
|
SMETI_db::$libelle = 'Millésime '. $element['enveann'];
|
||||||
|
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();
|
||||||
|
// Empiler
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['enveann'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = $element['envecod'];
|
||||||
|
SMETI_db::$libelle = $element['envelib'];
|
||||||
|
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();
|
||||||
|
|
||||||
|
SMETI_db::$parent = SMETI_db::$child;
|
||||||
|
// Rajouer un phasage par année
|
||||||
|
for ($i=0;$i<$element['envenbrann'];$i++)
|
||||||
|
{
|
||||||
|
$phasage = $element['enveann']+$i;
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = $element['envecod'].$phasage;
|
||||||
|
SMETI_db::$libelle = $element['envecod'].' Phasage '.$phasage;;
|
||||||
|
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::$req3->execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
142
bin/import_09_marches.php
Normal file
142
bin/import_09_marches.php
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
$libelle = 'Marchés';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'MARC';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/09_MARCHES.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
$counter += 1;
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// On ne reprend pas les vieux marchés
|
||||||
|
if (($element['marcdatlim']/10000) < 2019) continue;
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index-1])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 2;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
|
||||||
|
// Rajouter un élément vide dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-t-on changé de Catégorie de famille ?
|
||||||
|
if ($element['marcann'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// Dépiler
|
||||||
|
$pile_index -= 1;
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = 'MARC'.$pile_code[$pile_index].$element['marcann'];
|
||||||
|
SMETI_db::$libelle = 'Marchés '.$element['marcann'];
|
||||||
|
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();
|
||||||
|
// Empiler
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['marcann'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = sprintf("%04d%06d",$element['marcnum'],$element['marcnum']);
|
||||||
|
SMETI_db::$libelle = $element['marcobj'];
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
140
bin/import_10_ncmp.php
Normal file
140
bin/import_10_ncmp.php
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
$libelle = 'Familles achats';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'NCMP';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/10_NOMCMP.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index-1])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 2;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
|
||||||
|
// Rajouter un élément vide dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-t-on changé de Catégorie de famille ?
|
||||||
|
if ($element['mpcacod'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// Dépiler
|
||||||
|
$pile_index -= 1;
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = 'MPCA'.$pile_code[$pile_index].$element['mpcacod'];
|
||||||
|
SMETI_db::$libelle = $element['mpnclib'];
|
||||||
|
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();
|
||||||
|
// Empiler
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['mpcacod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
if ($element['mpnccod'] == "") continue;
|
||||||
|
|
||||||
|
// Rajouter la famille
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = $element['mpnccod'];
|
||||||
|
SMETI_db::$libelle = $element['mpnclib'];
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
240
bin/import_11_chapitres.php
Normal file
240
bin/import_11_chapitres.php
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
$libelle = 'Instructions Comptables';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'INSC';
|
||||||
|
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();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$libelle = 'Toutes Instructions';
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'INSCGLOB';
|
||||||
|
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;
|
||||||
|
|
||||||
|
$libelle = 'Chapitres';
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'INSCGLOBCHAP';
|
||||||
|
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/04_CHAPITRES.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
|
||||||
|
$chapitres = [];
|
||||||
|
$chapitres[] = ['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($chapitres);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($chapitres[$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();
|
||||||
|
|
||||||
|
$chapitres[] = [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;
|
||||||
|
$counter = 0;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
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;
|
||||||
|
// Conserver l'instruction dans un tableau
|
||||||
|
$instructions[] = [SMETI_db::$code, SMETI_db::$item];
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
?>
|
||||||
202
bin/import_12_fonctions.php
Normal file
202
bin/import_12_fonctions.php
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
return tri_chap_1($a , $b);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
$nb_coll = count($coll);
|
||||||
|
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);
|
||||||
|
$nb_instructions = count($instructions);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
// Se positonner sur l'instruction globale
|
||||||
|
for($i=0;$i<$nb_instructions;$i++)
|
||||||
|
if ($instructions[$i][0] == 'INSCGLOB')
|
||||||
|
break;
|
||||||
|
if ($i == $nb_instructions) 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
|
||||||
|
$fonctions = [];
|
||||||
|
$fonctions[] = ['BIDON','BIDON'];
|
||||||
|
$record = 0;
|
||||||
|
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[] = [$element['code'], SMETI_db::$libelle, SMETI_db::$item];
|
||||||
|
$record += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
$nb_fonctions = count($fonctions);
|
||||||
|
|
||||||
|
usort($shipments,'tri_chap_2');
|
||||||
|
$counter = 0;
|
||||||
|
$record = 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])
|
||||||
|
{
|
||||||
|
// Se positonner sur l'instruction
|
||||||
|
for($i=0;$i<$nb_instructions;$i++)
|
||||||
|
if ($instructions[$i][0] == $element['instruction'])
|
||||||
|
break;
|
||||||
|
if ($i == $nb_instructions) continue;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = $instructions[$i][0];
|
||||||
|
$pile_item[$pile_index] = $instructions[$i][1];
|
||||||
|
|
||||||
|
// Rajouter un item pour les fonctions dans cette instruction
|
||||||
|
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<$nb_fonctions;$i++)
|
||||||
|
if ($fonctions[$i][0] == 'C'.$element['code'])
|
||||||
|
break;
|
||||||
|
if ($i == $nb_fonctions) continue;
|
||||||
|
|
||||||
|
// Rajouter un lien vers la fonction
|
||||||
|
SMETI_db::$item = $fonctions[$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'];
|
||||||
|
$record += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
?>
|
||||||
10
bin/init_db.sh
Executable file
10
bin/init_db.sh
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
rm -f ../data/$1
|
||||||
|
sqlite3 ../data/$1 < ../data/SQL/init.sql
|
||||||
|
for script in import_??_*.php
|
||||||
|
do
|
||||||
|
php $script ../data/$1
|
||||||
|
if [ $? -ne 0 ];
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
110
bin/smeti_db.inc.php
Normal file
110
bin/smeti_db.inc.php
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
function clearLine()
|
||||||
|
{
|
||||||
|
echo "\033[2K\r";
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceOut($str)
|
||||||
|
{
|
||||||
|
$numNewLines = substr_count($str, "\n");
|
||||||
|
echo chr(27) . "[0G"; // Set cursor to first column
|
||||||
|
echo $str;
|
||||||
|
echo chr(27) . "[" . $numNewLines ."A"; // Set cursor up x lines
|
||||||
|
}
|
||||||
|
|
||||||
|
function progressBar($n, $m)
|
||||||
|
{
|
||||||
|
static $maxsize = 80;
|
||||||
|
static $linesize = 0;
|
||||||
|
static $even = 0;
|
||||||
|
|
||||||
|
if (0 == ($linesize % $maxsize))
|
||||||
|
{
|
||||||
|
$even = 1 - $even;
|
||||||
|
$linesize = 0;
|
||||||
|
echo chr(27) . "[0G";
|
||||||
|
printf('[ %010d / %010d ] ', $n, $m);
|
||||||
|
}
|
||||||
|
|
||||||
|
$linesize += 1;
|
||||||
|
|
||||||
|
if ($even == 1) echo '.';
|
||||||
|
else echo 'X';
|
||||||
|
}
|
||||||
|
|
||||||
|
class SMETI_db
|
||||||
|
{
|
||||||
|
static $plugin = 0;
|
||||||
|
static $libelle = '';
|
||||||
|
static $item = 0;
|
||||||
|
static $code = '';
|
||||||
|
static $link = 0;
|
||||||
|
static $child = 0;
|
||||||
|
static $parent = 0;
|
||||||
|
static $rank = 0;
|
||||||
|
|
||||||
|
static $pdo;
|
||||||
|
static $req0;
|
||||||
|
static $req1;
|
||||||
|
static $req2;
|
||||||
|
static $req3;
|
||||||
|
|
||||||
|
static function init($pdo_cn_string = 'sqlite:../data/base.sqlite')
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
self::$pdo = new PDO($pdo_cn_string);
|
||||||
|
self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||||
|
self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // ERRMODE_WARNING | ERRMODE_EXCEPTION | ERRMODE_SILENT
|
||||||
|
} catch(Exception $e) {
|
||||||
|
echo "Impossible d'accéder à la base de données SQLite : ".$e->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
self::$req0 = self::$pdo->prepare('INSERT INTO plugins(libelle) VALUES(:libelle)');
|
||||||
|
self::$req0->bindParam('libelle', self::$libelle, PDO::PARAM_STR);
|
||||||
|
|
||||||
|
self::$req1 = self::$pdo->prepare('INSERT INTO items(plugin, code, libelle) VALUES(:plugin, :code, :libelle)');
|
||||||
|
self::$req1->bindParam('plugin', self::$plugin, PDO::PARAM_INT);
|
||||||
|
self::$req1->bindParam('code', self::$code, PDO::PARAM_STR);
|
||||||
|
self::$req1->bindParam('libelle', self::$libelle, PDO::PARAM_STR);
|
||||||
|
|
||||||
|
self::$req2 = self::$pdo->prepare('INSERT INTO links(link, item) VALUES(:link, :item)');
|
||||||
|
self::$req2->bindParam('link', self::$link, PDO::PARAM_INT);
|
||||||
|
self::$req2->bindParam('item', self::$item, PDO::PARAM_INT);
|
||||||
|
|
||||||
|
self::$req3 = self::$pdo->prepare('INSERT INTO nodes(child, parent, rank) VALUES(:child, :parent, :rank)');
|
||||||
|
self::$req3->bindParam('child', self::$child, PDO::PARAM_INT);
|
||||||
|
self::$req3->bindParam('parent', self::$parent, PDO::PARAM_INT);
|
||||||
|
self::$req3->bindParam('rank', self::$rank, PDO::PARAM_INT);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function removePlugin($plugin_name)
|
||||||
|
{
|
||||||
|
$select_clause="SELECT id FROM plugins WHERE libelle = '$plugin_name'";
|
||||||
|
// Parce que je n'ai pas réussi à faire correctement marcher le DELETE CASCADE !
|
||||||
|
self::$pdo->exec("DELETE FROM nodes WHERE parent IN (SELECT DISTINCT id FROM v_items WHERE plugin IN ( $select_clause ))");
|
||||||
|
self::$pdo->exec("DELETE FROM nodes WHERE child IN (SELECT DISTINCT id FROM v_items WHERE plugin IN ( $select_clause ))");
|
||||||
|
self::$pdo->exec("DELETE FROM links WHERE item IN (SELECT DISTINCT id FROM items WHERE plugin IN ( $select_clause ))");
|
||||||
|
self::$pdo->exec("DELETE FROM links WHERE link = 1 AND id IN ( SELECT id FROM v_items_tree WHERE parent IS NULL)");
|
||||||
|
self::$pdo->exec("DELETE FROM items WHERE plugin IN ( $select_clause)");
|
||||||
|
self::$pdo->exec("DELETE FROM plugins WHERE libelle = '$plugin_name' ");
|
||||||
|
// Parce que je n'ai pas réussi à faire correctement marcher le DELETE CASCADE !
|
||||||
|
self::$pdo->exec('VACUUM');
|
||||||
|
}
|
||||||
|
|
||||||
|
static function addPlugin($plugin_name)
|
||||||
|
{
|
||||||
|
self::$libelle = $plugin_name;
|
||||||
|
self::$req0->execute();
|
||||||
|
self::$plugin = self::$pdo->lastInsertId();
|
||||||
|
}
|
||||||
|
|
||||||
|
static function setCurPlugin($plugin_name)
|
||||||
|
{
|
||||||
|
$sql = self::$pdo->prepare("SELECT id FROM plugins WHERE libelle = '$plugin_name'");
|
||||||
|
$sql->execute();
|
||||||
|
$row = $sql->fetch(PDO::FETCH_NUM);
|
||||||
|
self::$plugin = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
47
css/carets.css
Normal file
47
css/carets.css
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
.ul_no_list {
|
||||||
|
list-style-type: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret {
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-user-select: none; /* Safari 3.1+ */
|
||||||
|
-moz-user-select: none; /* Firefox 2+ */
|
||||||
|
-ms-user-select: none; /* IE 10+ */
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret::before {
|
||||||
|
content: "\25B6";
|
||||||
|
color: black;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret-down::before {
|
||||||
|
-ms-transform: rotate(90deg); /* IE 9 */
|
||||||
|
-webkit-transform: rotate(90deg); /* Safari */'
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret_gris {
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-user-select: none; /* Safari 3.1+ */
|
||||||
|
-moz-user-select: none; /* Firefox 2+ */
|
||||||
|
-ms-user-select: none; /* IE 10+ */
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caret_gris::before {
|
||||||
|
content: "\25B6";
|
||||||
|
color: grey;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nested {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
102
css/niveaux.css
Normal file
102
css/niveaux.css
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
.niveau_0 {
|
||||||
|
background-color: #c0392b;
|
||||||
|
font-weight: bold;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_1 {
|
||||||
|
background-color: #e74c3c ;
|
||||||
|
font-weight: normal;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_2 {
|
||||||
|
background-color: #9b59b6;
|
||||||
|
font-weight: normal;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_3 {
|
||||||
|
background-color: #8e44ad;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_4 {
|
||||||
|
background-color: #2980b9;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_5 {
|
||||||
|
background-color: #3498DB;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_6 {
|
||||||
|
background-color: #1ABC9C;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_7 {
|
||||||
|
background-color: #16A085;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_8 {
|
||||||
|
background-color: #27AE60;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_9 {
|
||||||
|
background-color: #2ECC71;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_10 {
|
||||||
|
background-color: #F1C40F;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_11 {
|
||||||
|
background-color: #F39C12;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_12 {
|
||||||
|
background-color: #E67E22;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_13 {
|
||||||
|
background-color: #D35400;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_14 {
|
||||||
|
background-color: #ECF0F1;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_15 {
|
||||||
|
background-color: #BDC3C7;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_16 {
|
||||||
|
background-color: #95A5A6;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_20 {
|
||||||
|
background-color: #7F8C8D;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_21 {
|
||||||
|
background-color: #34495E;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.niveau_22 {
|
||||||
|
background-color: #2C3E50;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
1
data/.gitignore
vendored
Normal file
1
data/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.sqlite
|
||||||
BIN
data/base.sqlite
BIN
data/base.sqlite
Binary file not shown.
12
index.html
12
index.html
@@ -11,7 +11,11 @@
|
|||||||
|
|
||||||
<h2>SMETI store ITEMS</h2>
|
<h2>SMETI store ITEMS</h2>
|
||||||
|
|
||||||
<ul class="ul_no_list" id="smeti_list"></ul>
|
<!--<ul class="ul_no_list" id="smeti_list"></ul>-->
|
||||||
|
|
||||||
|
<div id="smeti_list">
|
||||||
|
Loading data ...
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
/*
|
/*
|
||||||
@@ -39,9 +43,15 @@ function afficherArbre()
|
|||||||
var heritage = [ 'XXX' ];
|
var heritage = [ 'XXX' ];
|
||||||
var m14_ul = [ document.getElementById('smeti_list') ];
|
var m14_ul = [ document.getElementById('smeti_list') ];
|
||||||
var m14_span = [ null ];
|
var m14_span = [ null ];
|
||||||
|
var ul = document.createElement('ul');
|
||||||
|
|
||||||
while(m14_ul[0].firstChild) m14_ul[0].removeChild(m14_ul[0].firstChild);
|
while(m14_ul[0].firstChild) m14_ul[0].removeChild(m14_ul[0].firstChild);
|
||||||
|
|
||||||
|
// Ajouter la racine des UL
|
||||||
|
ul.setAttribute('class','ul_no_list');
|
||||||
|
m14_ul[m14_ul.length-1].appendChild(ul);
|
||||||
|
m14_ul.push(ul);
|
||||||
|
|
||||||
liste_instructions.forEach(function(element){
|
liste_instructions.forEach(function(element){
|
||||||
// if (element.instruction != 'M14') return true;
|
// if (element.instruction != 'M14') return true;
|
||||||
// if (element.type != courant) return true;
|
// if (element.type != courant) return true;
|
||||||
|
|||||||
35
scripts/main.js
Normal file
35
scripts/main.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
var styles = [ 'niveau_10', 'niveau_9', 'niveau_5', 'niveau_19'];
|
||||||
|
|
||||||
|
$( document ).ready(function() {
|
||||||
|
|
||||||
|
$.getJSON( "api/get.php", function( data ) {
|
||||||
|
|
||||||
|
var div = document.getElementById('TREE');
|
||||||
|
var tbl = document.createElement("table");
|
||||||
|
var tblBody = document.createElement("tbody");
|
||||||
|
|
||||||
|
data.forEach(function(element){
|
||||||
|
var tr = document.createElement('tr');
|
||||||
|
var td = null;
|
||||||
|
|
||||||
|
td = document.createElement('td');
|
||||||
|
td.appendChild(document.createTextNode(element.code));
|
||||||
|
tr.appendChild(td);
|
||||||
|
|
||||||
|
td = document.createElement('td');
|
||||||
|
td.appendChild(document.createTextNode(element.name));
|
||||||
|
tr.appendChild(td);
|
||||||
|
|
||||||
|
tr.setAttribute('class',styles[element.level % styles.length]);
|
||||||
|
tblBody.appendChild(tr);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
tbl.appendChild(tblBody);
|
||||||
|
|
||||||
|
div.appendChild(tbl);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user