From ad9623f215ec090b4720f47dab24e3660a465ced Mon Sep 17 00:00:00 2001 From: Pierre-Benoit BLANC Date: Mon, 16 Jun 2025 21:30:15 +0200 Subject: [PATCH] Intial commit --- .$functionnal diagrams.drawio.bkp | 10 + .gitignore | 1 + budget.csv | 16 + budget.svg | 1411 +++++++++++++++++ config | 4 + diagrams/functionnal diagrams.drawio | 31 + libs/__pycache__/lib_csv.cpython-311.pyc | Bin 0 -> 219 bytes libs/__pycache__/lib_mariadb.cpython-311.pyc | Bin 0 -> 433 bytes .../lib_matplotlib.cpython-311.pyc | Bin 0 -> 264 bytes libs/lib_csv.py | 2 + libs/lib_mariadb.py | 8 + libs/lib_matplotlib.py | 4 + main.py | 238 +++ wp-config.php | 98 ++ 14 files changed, 1823 insertions(+) create mode 100644 .$functionnal diagrams.drawio.bkp create mode 100644 .gitignore create mode 100644 budget.csv create mode 100644 budget.svg create mode 100644 config create mode 100644 diagrams/functionnal diagrams.drawio create mode 100644 libs/__pycache__/lib_csv.cpython-311.pyc create mode 100644 libs/__pycache__/lib_mariadb.cpython-311.pyc create mode 100644 libs/__pycache__/lib_matplotlib.cpython-311.pyc create mode 100644 libs/lib_csv.py create mode 100644 libs/lib_mariadb.py create mode 100644 libs/lib_matplotlib.py create mode 100644 main.py create mode 100644 wp-config.php diff --git a/.$functionnal diagrams.drawio.bkp b/.$functionnal diagrams.drawio.bkp new file mode 100644 index 0000000..a455408 --- /dev/null +++ b/.$functionnal diagrams.drawio.bkp @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..21d0b89 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv/ diff --git a/budget.csv b/budget.csv new file mode 100644 index 0000000..37bb1f6 --- /dev/null +++ b/budget.csv @@ -0,0 +1,16 @@ +Etabli;0;1000 +Animation;0;1500 +Atelier;0;1000 +Cotisations;0;4000 +Dons;0;1000 +Quincaillerie;0;300 +Evenement;0;1000 +Location;0;1500 +Subvention;0;5000 +Services;1250;0 +Outillages;1500;0 +Fourniture animations;300;0 +Entretien local;2000;0 +Loyer;10500;0 +Assurances;250;0 +Fourniture évenement;500;0 \ No newline at end of file diff --git a/budget.svg b/budget.svg new file mode 100644 index 0000000..ae57408 --- /dev/null +++ b/budget.svg @@ -0,0 +1,1411 @@ + + + + + + + + 2025-06-15T14:55:20.889417 + image/svg+xml + + + Matplotlib v3.10.3, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/config b/config new file mode 100644 index 0000000..5d56a87 --- /dev/null +++ b/config @@ -0,0 +1,4 @@ +[path] +wp-config=wp-config.php +budget=budget.csv +save_directory=. \ No newline at end of file diff --git a/diagrams/functionnal diagrams.drawio b/diagrams/functionnal diagrams.drawio new file mode 100644 index 0000000..55318c8 --- /dev/null +++ b/diagrams/functionnal diagrams.drawio @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/__pycache__/lib_csv.cpython-311.pyc b/libs/__pycache__/lib_csv.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e95389659405b7c5f5dc1c9796b6a9d52612124f GIT binary patch literal 219 zcmZ3^%ge<81dsK6GUPxshyw#mP{wB=AY(d13PTEG4nr>0!_wS zoFSD3sVOd*$t8Z8Ot;udDho36(uV1 WERguX%*e=igF)s3HdMq0Q~>~+us8w$ literal 0 HcmV?d00001 diff --git a/libs/__pycache__/lib_mariadb.cpython-311.pyc b/libs/__pycache__/lib_mariadb.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3fd8ab21049457ab7818a9bd3c6d998ab6aa3ba4 GIT binary patch literal 433 zcma)0yH3L}6txoyRZ2zRFEWJuK*fwy)TJ9s<-~>rHF3Chhi)18hkgR;!UttVOe~SI zb?Utq>ClNQ`P_$&&pDsdX~3|)e&_ik_HSB-;(tSbhr^CZ_Q9T+C^;q^2>`K$5pGTa zNU{w;y>Bo&nN9FO+9$KHd2-Z6&q^&fYxMxv_}7Jvap-)`dFOdN?AQqc LkKfXI4$kEWYk^c( literal 0 HcmV?d00001 diff --git a/libs/__pycache__/lib_matplotlib.cpython-311.pyc b/libs/__pycache__/lib_matplotlib.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..86cac13f602765894b41b30dce2bce62a786d8ab GIT binary patch literal 264 zcmZ3^%ge<81dsK6GAuzfhyw#mP{wB|AY(d13PTEG4nr$Jn0|4}iNI3ui literal 0 HcmV?d00001 diff --git a/libs/lib_csv.py b/libs/lib_csv.py new file mode 100644 index 0000000..7a0e46c --- /dev/null +++ b/libs/lib_csv.py @@ -0,0 +1,2 @@ +from typing import TypedDict + diff --git a/libs/lib_mariadb.py b/libs/lib_mariadb.py new file mode 100644 index 0000000..50ee4e8 --- /dev/null +++ b/libs/lib_mariadb.py @@ -0,0 +1,8 @@ +def connect_db(): + + return test + + +def request_db(): + + return array \ No newline at end of file diff --git a/libs/lib_matplotlib.py b/libs/lib_matplotlib.py new file mode 100644 index 0000000..c3db667 --- /dev/null +++ b/libs/lib_matplotlib.py @@ -0,0 +1,4 @@ +from sankeyflow import Sankey +import matplotlib as mpt + + diff --git a/main.py b/main.py new file mode 100644 index 0000000..cb36a3a --- /dev/null +++ b/main.py @@ -0,0 +1,238 @@ +from libs import lib_mariadb as mdb +from libs import lib_csv as csv +from libs import lib_matplotlib as mtp +import configparser as cp +import os +from sankeyflow import Sankey +import matplotlib.pyplot as plt +import re +import datetime +import mariadb +import sys +node_central = 'total' + +class BudgetLine(): + + def __init__(self, desc:str, charge:int, revenue:int): + self.desc = desc + self.charge = charge + self.revenue = revenue + +class DBInfos(): + name:str + user:str + password:str + host:str + port:int + + +class Account(): + def __init__(self, label:str, number:int, tmp:int): + self.label = label + self.number = number + self.type = tmp + +def main(path_b:str, + path_wp:str, + save_dir:str): + budget=import_csv(path_b) + create_budget_sankey(budget,save_dir) + db_infos = get_db_infos(path_wp) + cursor = connect_mariadb(db_infos) + + + #connection à la db + # Lister les comptes qui m'intéressent + + # Pour chaque compte 7 puis 6 : + # - calculer somme entre le 1 er janvier et ajd + # - ajouter valeur dans flow et nodes + + +def create_accounting_sankey(cursor, save_dir): + nodes = NR = NC =[] + flows = [] + + # extraire le compte et la caisse au 1 er janvier de l'année + year = datetime.datetime.now().year + first_day = rf'{year}-01-01' + reserves = get_bank_reserves(cursor, first_day) + NR.append(('reserves', reserves, {'label_pos':'left'})) + + # lister les comptes de charges et produit + accounts = get_income_and_expense_accounts(cursor) + for a in accounts: + tot_deb, tot_cred = get_sum_of_operations( + cursor, + first_day, + a + ) + +def get_income_and_expense_accounts(cursor): + print("get_income_and_expense_accounts") + cursor.execute( + "SELECT account_number, label FROM llx_accounting_account WHERE reconcilable = 'PCG-BSC'" + ) + accounts = [] + for account_number, label in cursor: + tmp = str(account_number)[0] + if tmp == '6' or tmp == '7': + accounts.append(Account(label, account_number, int(tmp))) + + [print(f'account {a.number} / {a.label}') for a in accounts] + return accounts + + +def get_bank_reserves(cursor, date:str): + print('get_bank_reserves') + total = 0 + cursor.execute( + "SELECT piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit FROM llx_accounting_bookkeeping WHERE (numero_compte = ? OR numero_compte = ?) AND doc_date = ? AND code_journal = ?", + (5121, 5311, date, 'AN',) + ) + for debit, label_compte in cursor: + print(f'ajout de : {debit} provenant du compte {label_compte} au total') + total += debit + print(f'total = {total}') + return total + + +def connect_mariadb(db_infos:DBInfos): + try: + conn = mariadb.connect( + user="db_user", + password="db_user_passwd", + host="192.0.2.1", + port=3306, + database="employees" + + ) + except mariadb.Error as e: + print(f"Error connecting to MariaDB Platform: {e}") + sys.exit(1) + + # Get Cursor + return conn.cursor() + + +def import_csv(csv:str): + with open(csv, "r") as file: + content = file.read() + values = [] + for line in content.split('\n'): + tmp = line.split(';') + values.append( + BudgetLine( + desc=tmp[0], + charge=int(tmp[1]), + revenue=int(tmp[2]) + ) + ) + return values + + +def extract_value(content:str, param:str): + tmp = re.search(rf'define...{param}.+', content) + print('test') + if tmp is not None: + return tmp.group().split(',')[1].split('\'')[1] + else: + return "" + + +def get_sum_of_operations(cursor, date:str, account:Account): + tot_cred = tot_deb = 0 + cursor.execute( + "SELECT piece_num, numero_compte, label_compte, doc_date, code_journal, debit, credit FROM llx_accounting_bookkeeping WHERE numero_compte = ? AND doc_date >= ?", + (account.number, date) + ) + for debit, credit in cursor : + tot_cred += credit + tot_deb += debit + + print(f'pour le compte {account.number} : credit = {tot_cred} / debit = {tot_deb} à partir du {date}') + return tot_deb, tot_cred + + +def get_db_infos(path_wp:str): + with open(path_wp, "r") as file: + content = file.read() + db_infos = DBInfos() + db_infos.name = extract_value(content, 'DB_NAME') + db_infos.user = extract_value(content, 'DB_USER') + db_infos.password = extract_value(content, 'DB_PASSWORD') + db_infos.host = extract_value(content, 'DB_HOST') + db_infos.port = 3306 + return db_infos + + + +def get_budget_elements(budget:list[BudgetLine]): + nodes = [] + flows=[] + total = 0 + CL = [] + RL = [] + for line in budget: + charge = line.charge + desc = line.desc + revenue = line.revenue + if charge != 0 and revenue == 0: + total += charge + CL.append((desc, charge, {'label_pos':'right'})) + flows.append(('Total', desc, charge)) + + elif charge == 0 and revenue != 0: + RL.append((desc, revenue, {'label_pos':'left'})) + flows.append((desc, 'Total', revenue)) + + nodes = [ + RL, + [('Total', total)], + CL + ] + + return nodes, flows + + +def create_budget_sankey( + budget:list[BudgetLine], + save:str): + + nodes, flows = get_budget_elements(budget) + plt.figure(figsize=(25, 10), dpi=144) + s = Sankey( + flows=flows, + nodes=nodes, + node_opts=dict(label_format='{label}:{value}') + ) + s.draw() + path = os.path.join(save, 'budget.svg') + plt.savefig(path) + + +if __name__ == "__main__": + conf = cp.ConfigParser() + conf.read('config') + + path_b = conf['path']['budget'] + path_wp_config = conf['path']['wp-config'] + path_save = conf['path']['save_directory'] + + + + if os.path.exists(path_b) and os.path.exists(path_wp_config): + print("les 2 fichiers budget et wp-config ont été trouvé") + main(path_b, path_wp_config, path_save) + else : + if not os.path.exists(path_b) : + msg = "le chemin indiqué pour le paramètre budget dans le fichier config est incorrect. Le document a été supprimé ou déplacer. Merci de préciser un autre chemin" + print(msg) + print(f'budget = {path_b}') + if not os.path.exists(path_wp_config) : + msg = "le chemin indiqué pour le paramètre wp-config dans le fichier config est incorrect. Le document a été supprimé ou déplacer. Merci de préciser un autre chemin" + print(msg) + print(f'wp-config = {path_wp_config}') + + respo = input('Appuyer sur entrée pour terminer') + diff --git a/wp-config.php b/wp-config.php new file mode 100644 index 0000000..98b3d24 --- /dev/null +++ b/wp-config.php @@ -0,0 +1,98 @@ +fiPe,dnFuMb =Edb@F1#(nhKR*tOG8C5Jf!-:`l<2wPA&zjq4Q' ); +define( 'LOGGED_IN_KEY', 'rK`: X~U e%;Us(v6m3?U0[R_^7bWW%uH f%e] hm-m`,}J{pl&x8ZHAn_eEWv<:' ); +define( 'NONCE_KEY', 'x&zI;Mv1uQnLsyfof2KD$Ju:IU$z.whW&2:Of{X%}nKvbFT~iKNw;kT.NLy5OIb$' ); +define( 'AUTH_SALT', '$%lxK?!bXFCEi5bz{@(aUD ^Tu/x1%:6mTjk/:R8im%_WIN{rG3sFaoeSQ{naWZ(' ); +define( 'SECURE_AUTH_SALT', 's+j_oKuz^A-)f/c(R _)hg^C$$!f2;?oo@Z)5AngdCD.e#$gGO4*)BIG#/N}^{4.2 ]j0o_N' ); +define( 'NONCE_SALT', '3w!TulB~HmA26D{/Kb>Ai]>5K~z%,Sa&O*Usx-z$SKGP@(Lmu+i]8DrK, n;X?t;' ); + +/**#@-*/ + +/** + * WordPress database table prefix. + * + * You can have multiple installations in one database if you give each + * a unique prefix. Only numbers, letters, and underscores please! + */ +$table_prefix = 'bsc'; + +/** + * For developers: WordPress debugging mode. + * + * Change this to true to enable the display of notices during development. + * It is strongly recommended that plugin and theme developers use WP_DEBUG + * in their development environments. + * + * For information on other constants that can be used for debugging, + * visit the documentation. + * + * @link https://wordpress.org/documentation/article/debugging-in-wordpress/ + */ +define( 'WP_DEBUG', false ); + +/* Add any custom values between this line and the "stop editing" line. */ + + + +/* That's all, stop editing! Happy publishing. */ + +/** Absolute path to the WordPress directory. */ +if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', __DIR__ . '/' ); +} + +/** Sets up WordPress vars and included files. */ +require_once ABSPATH . 'wp-settings.php';